Make non-macro entity functions swappable with the macro versions
This commit is contained in:
@@ -54,18 +54,21 @@
|
|||||||
; textures
|
; textures
|
||||||
|
|
||||||
(defn texture*
|
(defn texture*
|
||||||
[img]
|
[arg]
|
||||||
(cond
|
(u/create-entity
|
||||||
(string? img)
|
(cond
|
||||||
(-> ^String img Texture. TextureRegion.)
|
(string? arg)
|
||||||
(map? img)
|
(-> ^String arg Texture. TextureRegion.)
|
||||||
(TextureRegion. ^TextureRegion (:object img))
|
(map? arg)
|
||||||
:else
|
(TextureRegion. ^TextureRegion (:object arg))
|
||||||
img))
|
:else
|
||||||
|
arg)))
|
||||||
|
|
||||||
(defmacro texture
|
(defmacro texture
|
||||||
[img & options]
|
[arg & options]
|
||||||
`(u/create-entity (u/calls! ^TextureRegion (texture* ~img) ~@options)))
|
`(let [entity# (texture* ~arg)]
|
||||||
|
(u/calls! ^TextureRegion (:object entity#) ~@options)
|
||||||
|
entity#))
|
||||||
|
|
||||||
(defmacro animation
|
(defmacro animation
|
||||||
[duration textures & args]
|
[duration textures & args]
|
||||||
@@ -76,9 +79,9 @@
|
|||||||
|
|
||||||
(defn animation->texture
|
(defn animation->texture
|
||||||
([{:keys [total-time]} ^Animation animation]
|
([{:keys [total-time]} ^Animation animation]
|
||||||
(u/create-entity (.getKeyFrame animation total-time true)))
|
(texture* (.getKeyFrame animation total-time true)))
|
||||||
([{:keys [total-time]} ^Animation animation is-looping?]
|
([{:keys [total-time]} ^Animation animation is-looping?]
|
||||||
(u/create-entity (.getKeyFrame animation total-time is-looping?))))
|
(texture* (.getKeyFrame animation total-time is-looping?))))
|
||||||
|
|
||||||
; interop
|
; interop
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
[com.badlogic.gdx.scenes.scene2d.ui ButtonGroup CheckBox Dialog
|
[com.badlogic.gdx.scenes.scene2d.ui ButtonGroup CheckBox Dialog
|
||||||
HorizontalGroup Image ImageButton ImageTextButton Label Skin Slider
|
HorizontalGroup Image ImageButton ImageTextButton Label Skin Slider
|
||||||
Table TextButton TextField VerticalGroup WidgetGroup]
|
Table TextButton TextField VerticalGroup WidgetGroup]
|
||||||
[com.badlogic.gdx.scenes.scene2d.utils ActorGestureListener
|
[com.badlogic.gdx.scenes.scene2d.utils ActorGestureListener Align
|
||||||
ChangeListener ClickListener DragListener FocusListener
|
ChangeListener ClickListener DragListener FocusListener
|
||||||
NinePatchDrawable SpriteDrawable TextureRegionDrawable
|
NinePatchDrawable SpriteDrawable TextureRegionDrawable
|
||||||
TiledDrawable]))
|
TiledDrawable]))
|
||||||
@@ -33,90 +33,114 @@
|
|||||||
[path & options]
|
[path & options]
|
||||||
`(u/calls! ^Skin (Skin. (.internal ^Files (Gdx/files) ~path)) ~@options))
|
`(u/calls! ^Skin (Skin. (.internal ^Files (Gdx/files) ~path)) ~@options))
|
||||||
|
|
||||||
|
(defmacro align
|
||||||
|
[key]
|
||||||
|
`(u/static-field-lower :scenes :scene2d :utils :Align ~key))
|
||||||
|
|
||||||
; widgets
|
; widgets
|
||||||
|
|
||||||
(defn check-box*
|
(defn check-box*
|
||||||
[^String text arg]
|
[^String text arg]
|
||||||
(CheckBox. text arg))
|
(u/create-entity (CheckBox. text arg)))
|
||||||
|
|
||||||
(defmacro check-box
|
(defmacro check-box
|
||||||
[text arg & options]
|
[text arg & options]
|
||||||
`(u/create-entity (u/calls! ^CheckBox (check-box* ~text ~arg) ~@options)))
|
`(let [entity# (check-box* ~text ~arg)]
|
||||||
|
(u/calls! ^CheckBox (:object entity#) ~@options)
|
||||||
|
entity#))
|
||||||
|
|
||||||
(defn image*
|
(defn image*
|
||||||
[arg]
|
[arg]
|
||||||
(cond
|
(u/create-entity
|
||||||
(map? arg)
|
(cond
|
||||||
(Image. ^TextureRegion (:object arg))
|
(map? arg)
|
||||||
(string? arg)
|
(Image. ^TextureRegion (:object arg))
|
||||||
(Image. (Texture. ^String arg))
|
(string? arg)
|
||||||
:else
|
(Image. (Texture. ^String arg))
|
||||||
(Image. arg)))
|
:else
|
||||||
|
(Image. arg))))
|
||||||
|
|
||||||
(defmacro image
|
(defmacro image
|
||||||
[arg & options]
|
[arg & options]
|
||||||
`(u/create-entity (u/calls! ^Image (image* ~arg) ~@options)))
|
`(let [entity# (image* ~arg)]
|
||||||
|
(u/calls! ^Image (:object entity#) ~@options)
|
||||||
|
entity#))
|
||||||
|
|
||||||
(defn image-button*
|
(defn image-button*
|
||||||
[arg]
|
[arg]
|
||||||
(ImageButton. arg))
|
(u/create-entity (ImageButton. arg)))
|
||||||
|
|
||||||
(defmacro image-button
|
(defmacro image-button
|
||||||
[arg & options]
|
[arg & options]
|
||||||
`(u/create-entity (u/calls! ^ImageButton (image-button* ~arg) ~@options)))
|
`(let [entity# (image-button* ~arg)]
|
||||||
|
(u/calls! ^ImageButton (:object entity#) ~@options)
|
||||||
|
entity#))
|
||||||
|
|
||||||
(defn image-text-button*
|
(defn image-text-button*
|
||||||
[^String text arg]
|
[^String text arg]
|
||||||
(ImageTextButton. text arg))
|
(u/create-entity (ImageTextButton. text arg)))
|
||||||
|
|
||||||
(defmacro image-text-button
|
(defmacro image-text-button
|
||||||
[text arg & options]
|
[text arg & options]
|
||||||
`(u/create-entity (u/calls! ^ImageTextButton (image-text-button* ~text ~arg)
|
`(let [entity# (image-text-button* ~text ~arg)]
|
||||||
~@options)))
|
(u/calls! ^ImageTextButton (:object entity#) ~@options)
|
||||||
|
entity#))
|
||||||
|
|
||||||
(defn label*
|
(defn label*
|
||||||
[^String text arg]
|
[^String text arg]
|
||||||
(if (isa? (type arg) Color)
|
(u/create-entity
|
||||||
(Label. text (style :label (bitmap-font) arg))
|
(if (isa? (type arg) Color)
|
||||||
(Label. text arg)))
|
(Label. text (style :label (bitmap-font) arg))
|
||||||
|
(Label. text arg))))
|
||||||
|
|
||||||
(defmacro label
|
(defmacro label
|
||||||
[text arg & options]
|
[text arg & options]
|
||||||
`(u/create-entity (u/calls! ^Label (label* ~text ~arg) ~@options)))
|
`(let [entity# (label* ~text ~arg)]
|
||||||
|
(u/calls! ^Label (:object entity#) ~@options)
|
||||||
|
entity#))
|
||||||
|
|
||||||
(defn slider*
|
(defn slider*
|
||||||
[{:keys [min max step vertical?]
|
[{:keys [min max step vertical?]
|
||||||
:or {min 0 max 10 step 1 vertical? false}}
|
:or {min 0 max 10 step 1 vertical? false}}
|
||||||
arg]
|
arg]
|
||||||
(Slider. (float min) (float max) (float step) vertical? arg))
|
(u/create-entity
|
||||||
|
(Slider. (float min) (float max) (float step) vertical? arg)))
|
||||||
|
|
||||||
(defmacro slider
|
(defmacro slider
|
||||||
[attrs arg & options]
|
[attrs arg & options]
|
||||||
`(u/create-entity (u/calls! ^Slider (slider* ~attrs ~arg) ~@options)))
|
`(let [entity# (slider* ~attrs ~arg)]
|
||||||
|
(u/calls! ^Slider (:object entity#) ~@options)
|
||||||
|
entity#))
|
||||||
|
|
||||||
(defn text-button*
|
(defn text-button*
|
||||||
[^String text arg]
|
[^String text arg]
|
||||||
(TextButton. text arg))
|
(u/create-entity (TextButton. text arg)))
|
||||||
|
|
||||||
(defmacro text-button
|
(defmacro text-button
|
||||||
[text arg & options]
|
[text arg & options]
|
||||||
`(u/create-entity (u/calls! ^TextButton (text-button* ~text ~arg) ~@options)))
|
`(let [entity# (text-button* ~text ~arg)]
|
||||||
|
(u/calls! ^TextButton (:object entity#) ~@options)
|
||||||
|
entity#))
|
||||||
|
|
||||||
(defn text-field*
|
(defn text-field*
|
||||||
[^String text arg]
|
[^String text arg]
|
||||||
(TextField. text arg))
|
(u/create-entity (TextField. text arg)))
|
||||||
|
|
||||||
(defmacro text-field
|
(defmacro text-field
|
||||||
[text arg & options]
|
[text arg & options]
|
||||||
`(u/create-entity (u/calls! ^TextField (text-field* ~text ~arg) ~@options)))
|
`(let [entity# (text-field* ~text ~arg)]
|
||||||
|
(u/calls! ^TextField (:object entity#) ~@options)
|
||||||
|
entity#))
|
||||||
|
|
||||||
(defn dialog*
|
(defn dialog*
|
||||||
[text arg]
|
[text arg]
|
||||||
(Dialog. text arg))
|
(u/create-entity (Dialog. text arg)))
|
||||||
|
|
||||||
(defmacro dialog
|
(defmacro dialog
|
||||||
[text arg & options]
|
[text arg & options]
|
||||||
`(u/create-entity (u/calls! ^Dialog (dialog* ~text ~arg) ~@options)))
|
`(let [entity# (dialog* ~text ~arg)]
|
||||||
|
(u/calls! ^Dialog (:object entity#) ~@options)
|
||||||
|
entity#))
|
||||||
|
|
||||||
; groups
|
; groups
|
||||||
|
|
||||||
@@ -137,26 +161,42 @@
|
|||||||
(add-to-group! [group children])
|
(add-to-group! [group children])
|
||||||
group)
|
group)
|
||||||
|
|
||||||
|
(defn ^:private init-group
|
||||||
|
[^WidgetGroup group children]
|
||||||
|
(-> (doto group
|
||||||
|
(.setFillParent true))
|
||||||
|
u/create-entity
|
||||||
|
(add! children)))
|
||||||
|
|
||||||
|
(defn horizontal*
|
||||||
|
[children]
|
||||||
|
(init-group (HorizontalGroup.) children))
|
||||||
|
|
||||||
|
(defn vertical*
|
||||||
|
[children]
|
||||||
|
(init-group (VerticalGroup.) children))
|
||||||
|
|
||||||
|
(defn table*
|
||||||
|
[children]
|
||||||
|
(init-group (Table.) children))
|
||||||
|
|
||||||
(defmacro horizontal
|
(defmacro horizontal
|
||||||
[children & options]
|
[children & options]
|
||||||
`(-> (u/calls! ^HorizontalGroup (HorizontalGroup.) ~@options)
|
`(let [entity# (horizontal* ~children)]
|
||||||
(doto (.setFillParent true))
|
(u/calls! ^HorizontalGroup (:object entity#) ~@options)
|
||||||
u/create-entity
|
entity#))
|
||||||
(add! ~children)))
|
|
||||||
|
|
||||||
(defmacro vertical
|
(defmacro vertical
|
||||||
[children & options]
|
[children & options]
|
||||||
`(-> (u/calls! ^VerticalGroup (VerticalGroup.) ~@options)
|
`(let [entity# (vertical* ~children)]
|
||||||
(doto (.setFillParent true))
|
(u/calls! ^VerticalGroup (:object entity#) ~@options)
|
||||||
u/create-entity
|
entity#))
|
||||||
(add! ~children)))
|
|
||||||
|
|
||||||
(defmacro table
|
(defmacro table
|
||||||
[children & options]
|
[children & options]
|
||||||
`(-> (u/calls! ^Table (Table.) ~@options)
|
`(let [entity# (table* ~children)]
|
||||||
(doto (.setFillParent true))
|
(u/calls! ^Table (:object entity#) ~@options)
|
||||||
u/create-entity
|
entity#))
|
||||||
(add! ~children)))
|
|
||||||
|
|
||||||
; listeners
|
; listeners
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user