diff --git a/src/play_clj/core_2d.clj b/src/play_clj/core_2d.clj index 96a1f26..3f68c79 100644 --- a/src/play_clj/core_2d.clj +++ b/src/play_clj/core_2d.clj @@ -70,6 +70,10 @@ (u/calls! ^TextureRegion (:object entity#) ~@options) entity#)) +(defmacro texture! + [entity k & options] + `(u/call! ^TextureRegion (:object ~entity) ~k ~@options)) + (defmacro animation [duration textures & args] `(Animation. ~duration @@ -82,9 +86,3 @@ (texture* (.getKeyFrame animation total-time true))) ([{:keys [total-time]} ^Animation animation is-looping?] (texture* (.getKeyFrame animation total-time is-looping?)))) - -; interop - -(defmacro texture! - [entity k & options] - `(u/call! ^TextureRegion (:object ~entity) ~k ~@options)) diff --git a/src/play_clj/ui.clj b/src/play_clj/ui.clj index 5c59858..0fe20e9 100644 --- a/src/play_clj/ui.clj +++ b/src/play_clj/ui.clj @@ -37,113 +37,6 @@ [key] `(u/static-field-lower :scenes :scene2d :utils :Align ~key)) -; widgets - -(defn check-box* - [^String text arg] - (u/create-entity (CheckBox. text arg))) - -(defmacro check-box - [text arg & options] - `(let [entity# (check-box* ~text ~arg)] - (u/calls! ^CheckBox (:object entity#) ~@options) - entity#)) - -(defn image* - [arg] - (u/create-entity - (cond - (map? arg) - (Image. ^TextureRegion (:object arg)) - (string? arg) - (Image. (Texture. ^String arg)) - :else - (Image. arg)))) - -(defmacro image - [arg & options] - `(let [entity# (image* ~arg)] - (u/calls! ^Image (:object entity#) ~@options) - entity#)) - -(defn image-button* - [arg] - (u/create-entity (ImageButton. arg))) - -(defmacro image-button - [arg & options] - `(let [entity# (image-button* ~arg)] - (u/calls! ^ImageButton (:object entity#) ~@options) - entity#)) - -(defn image-text-button* - [^String text arg] - (u/create-entity (ImageTextButton. text arg))) - -(defmacro image-text-button - [text arg & options] - `(let [entity# (image-text-button* ~text ~arg)] - (u/calls! ^ImageTextButton (:object entity#) ~@options) - entity#)) - -(defn label* - [^String text arg] - (u/create-entity - (if (isa? (type arg) Color) - (Label. text (style :label (bitmap-font) arg)) - (Label. text arg)))) - -(defmacro label - [text arg & options] - `(let [entity# (label* ~text ~arg)] - (u/calls! ^Label (:object entity#) ~@options) - entity#)) - -(defn slider* - [{:keys [min max step vertical?] - :or {min 0 max 10 step 1 vertical? false}} - arg] - (u/create-entity - (Slider. (float min) (float max) (float step) vertical? arg))) - -(defmacro slider - [attrs arg & options] - `(let [entity# (slider* ~attrs ~arg)] - (u/calls! ^Slider (:object entity#) ~@options) - entity#)) - -(defn text-button* - [^String text arg] - (u/create-entity (TextButton. text arg))) - -(defmacro text-button - [text arg & options] - `(let [entity# (text-button* ~text ~arg)] - (u/calls! ^TextButton (:object entity#) ~@options) - entity#)) - -(defn text-field* - [^String text arg] - (u/create-entity (TextField. text arg))) - -(defmacro text-field - [text arg & options] - `(let [entity# (text-field* ~text ~arg)] - (u/calls! ^TextField (:object entity#) ~@options) - entity#)) - -(defn dialog* - [text arg] - (u/create-entity (Dialog. text arg))) - -(defmacro dialog - [text arg & options] - `(let [entity# (dialog* ~text ~arg)] - (u/calls! ^Dialog (:object entity#) ~@options) - entity#)) - -; groups - (defmulti add-to-group! #(-> % first :object type) :default WidgetGroup) (defmethod add-to-group! WidgetGroup @@ -168,36 +61,189 @@ u/create-entity (add! children))) +; widgets + +(defn check-box* + [^String text arg] + (u/create-entity (CheckBox. text arg))) + +(defmacro check-box + [text arg & options] + `(let [entity# (check-box* ~text ~arg)] + (u/calls! ^CheckBox (:object entity#) ~@options) + entity#)) + +(defmacro check-box! + [entity k & options] + `(u/call! ^Checkbox (:object ~entity) ~k ~@options)) + +(defn dialog* + [text arg] + (u/create-entity (Dialog. text arg))) + +(defmacro dialog + [text arg & options] + `(let [entity# (dialog* ~text ~arg)] + (u/calls! ^Dialog (:object entity#) ~@options) + entity#)) + +(defmacro dialog! + [entity k & options] + `(u/call! ^Dialog (:object ~entity) ~k ~@options)) + (defn horizontal* [children] (create-group (HorizontalGroup.) children)) -(defn vertical* - [children] - (create-group (VerticalGroup.) children)) - -(defn table* - [children] - (create-group (Table.) children)) - (defmacro horizontal [children & options] `(let [entity# (horizontal* ~children)] (u/calls! ^HorizontalGroup (:object entity#) ~@options) entity#)) -(defmacro vertical - [children & options] - `(let [entity# (vertical* ~children)] - (u/calls! ^VerticalGroup (:object entity#) ~@options) +(defmacro horizontal! + [entity k & options] + `(u/call! ^HorizontalGroup (:object ~entity) ~k ~@options)) + +(defn image* + [arg] + (u/create-entity + (cond + (map? arg) + (Image. ^TextureRegion (:object arg)) + (string? arg) + (Image. (Texture. ^String arg)) + :else + (Image. arg)))) + +(defmacro image + [arg & options] + `(let [entity# (image* ~arg)] + (u/calls! ^Image (:object entity#) ~@options) entity#)) +(defmacro image! + [entity k & options] + `(u/call! ^Image (:object ~entity) ~k ~@options)) + +(defn image-button* + [arg] + (u/create-entity (ImageButton. arg))) + +(defmacro image-button + [arg & options] + `(let [entity# (image-button* ~arg)] + (u/calls! ^ImageButton (:object entity#) ~@options) + entity#)) + +(defmacro image-button! + [entity k & options] + `(u/call! ^ImageButton (:object ~entity) ~k ~@options)) + +(defn image-text-button* + [^String text arg] + (u/create-entity (ImageTextButton. text arg))) + +(defmacro image-text-button + [text arg & options] + `(let [entity# (image-text-button* ~text ~arg)] + (u/calls! ^ImageTextButton (:object entity#) ~@options) + entity#)) + +(defmacro image-text-button! + [entity k & options] + `(u/call! ^ImageTextButton (:object ~entity) ~k ~@options)) + +(defn label* + [^String text arg] + (u/create-entity + (if (isa? (type arg) Color) + (Label. text (style :label (bitmap-font) arg)) + (Label. text arg)))) + +(defmacro label + [text arg & options] + `(let [entity# (label* ~text ~arg)] + (u/calls! ^Label (:object entity#) ~@options) + entity#)) + +(defmacro label! + [entity k & options] + `(u/call! ^Label (:object ~entity) ~k ~@options)) + +(defn slider* + [{:keys [min max step vertical?] + :or {min 0 max 10 step 1 vertical? false}} + arg] + (u/create-entity + (Slider. (float min) (float max) (float step) vertical? arg))) + +(defmacro slider + [attrs arg & options] + `(let [entity# (slider* ~attrs ~arg)] + (u/calls! ^Slider (:object entity#) ~@options) + entity#)) + +(defmacro slider! + [entity k & options] + `(u/call! ^Slider (:object ~entity) ~k ~@options)) + +(defn table* + [children] + (create-group (Table.) children)) + (defmacro table [children & options] `(let [entity# (table* ~children)] (u/calls! ^Table (:object entity#) ~@options) entity#)) +(defmacro table! + [entity k & options] + `(u/call! ^Table (:object ~entity) ~k ~@options)) + +(defn text-button* + [^String text arg] + (u/create-entity (TextButton. text arg))) + +(defmacro text-button + [text arg & options] + `(let [entity# (text-button* ~text ~arg)] + (u/calls! ^TextButton (:object entity#) ~@options) + entity#)) + +(defmacro text-button! + [entity k & options] + `(u/call! ^TextButton (:object ~entity) ~k ~@options)) + +(defn text-field* + [^String text arg] + (u/create-entity (TextField. text arg))) + +(defmacro text-field + [text arg & options] + `(let [entity# (text-field* ~text ~arg)] + (u/calls! ^TextField (:object entity#) ~@options) + entity#)) + +(defmacro text-field! + [entity k & options] + `(u/call! ^TextField (:object ~entity) ~k ~@options)) + +(defn vertical* + [children] + (create-group (VerticalGroup.) children)) + +(defmacro vertical + [children & options] + `(let [entity# (vertical* ~children)] + (u/calls! ^VerticalGroup (:object entity#) ~@options) + entity#)) + +(defmacro vertical! + [entity k & options] + `(u/call! ^VerticalGroup (:object ~entity) ~k ~@options)) + ; listeners (defn ^:private gesture-listener @@ -286,49 +332,3 @@ (click-listener options execute-fn!) (drag-listener options execute-fn!) (focus-listener options execute-fn!)]) - -; interop - -(defmacro check-box! - [entity k & options] - `(u/call! ^Checkbox (:object ~entity) ~k ~@options)) - -(defmacro image-button! - [entity k & options] - `(u/call! ^ImageButton (:object ~entity) ~k ~@options)) - -(defmacro image-text-button! - [entity k & options] - `(u/call! ^ImageTextButton (:object ~entity) ~k ~@options)) - -(defmacro label! - [entity k & options] - `(u/call! ^Label (:object ~entity) ~k ~@options)) - -(defmacro slider! - [entity k & options] - `(u/call! ^Slider (:object ~entity) ~k ~@options)) - -(defmacro text-button! - [entity k & options] - `(u/call! ^TextButton (:object ~entity) ~k ~@options)) - -(defmacro text-field! - [entity k & options] - `(u/call! ^TextField (:object ~entity) ~k ~@options)) - -(defmacro dialog! - [entity k & options] - `(u/call! ^Dialog (:object ~entity) ~k ~@options)) - -(defmacro horizontal! - [entity k & options] - `(u/call! ^HorizontalGroup (:object ~entity) ~k ~@options)) - -(defmacro vertical! - [entity k & options] - `(u/call! ^VerticalGroup (:object ~entity) ~k ~@options)) - -(defmacro table! - [entity k & options] - `(u/call! ^Table (:object ~entity) ~k ~@options))