Refactor and fix interop bugs

This commit is contained in:
oakes
2014-01-11 01:58:08 -05:00
parent ee3fdab2fd
commit d623c580fb
5 changed files with 78 additions and 46 deletions

View File

@@ -19,7 +19,9 @@
OrthogonalTiledMapRenderer]
[com.badlogic.gdx.scenes.scene2d Actor Stage]
[com.badlogic.gdx.scenes.scene2d.ui ButtonGroup CheckBox Dialog
ImageButton ImageTextButton Label TextButton TextField]))
ImageButton ImageTextButton Label Skin Slider TextButton TextField]
[com.badlogic.gdx.scenes.scene2d.utils NinePatchDrawable
SpriteDrawable TextureRegionDrawable TiledDrawable]))
(defmulti create-entity class)

View File

@@ -73,37 +73,39 @@
(execute-fn! on-touch-up :screen-x sx :screen-y sy :pointer p :button b)
false)))
(defn- gesture-detector
(defn- gesture-listener
[{:keys [on-fling on-long-press on-pan on-pan-stop on-pinch on-tap on-zoom]}
execute-fn!]
(let [listener
(reify GestureDetector$GestureListener
(fling [this vx vy b]
(execute-fn! on-fling :velocity-x vx :velocity-y vy :button b)
false)
(longPress [this x y]
(execute-fn! on-long-press :x x :y y)
false)
(pan [this x y dx dy]
(execute-fn! on-pan :x x :y y :delta-x dx :delta-y dy)
false)
(panStop [this x y p b]
(execute-fn! on-pan-stop :x x :y y :pointer p :button b)
false)
(pinch [this ip1 ip2 p1 p2]
(execute-fn! on-pinch
:initial-pointer-1 ip1 :initial-pointer-2 ip2
:pointer1 p1 :pointer2 p2)
false)
(tap [this x y c b]
(execute-fn! on-tap :x x :y y :count c :button b)
false)
(touchDown [this x y p b]
false)
(zoom [this id d]
(execute-fn! on-zoom :initial-distance id :distance d)
false))]
(proxy [GestureDetector] [listener])))
(reify GestureDetector$GestureListener
(fling [this vx vy b]
(execute-fn! on-fling :velocity-x vx :velocity-y vy :button b)
false)
(longPress [this x y]
(execute-fn! on-long-press :x x :y y)
false)
(pan [this x y dx dy]
(execute-fn! on-pan :x x :y y :delta-x dx :delta-y dy)
false)
(panStop [this x y p b]
(execute-fn! on-pan-stop :x x :y y :pointer p :button b)
false)
(pinch [this ip1 ip2 p1 p2]
(execute-fn! on-pinch
:initial-pointer-1 ip1 :initial-pointer-2 ip2
:pointer1 p1 :pointer2 p2)
false)
(tap [this x y c b]
(execute-fn! on-tap :x x :y y :count c :button b)
false)
(touchDown [this x y p b]
false)
(zoom [this id d]
(execute-fn! on-zoom :initial-distance id :distance d)
false)))
(defn- gesture-detector
[options execute-fn!]
(proxy [GestureDetector] [(gesture-listener options execute-fn!)]))
(defn- add-input!
[^InputProcessor p]

View File

@@ -9,32 +9,33 @@
; render
(defmacro orthogonal-tiled-map!
[{:keys [renderer]} k & options]
`(utils/call! ^OrthogonalTiledMapRenderer ~renderer ~k ~@options))
[screen k & options]
`(utils/call! ^OrthogonalTiledMapRenderer (:renderer ~screen) ~k ~@options))
(defmacro isometric-tiled-map!
[{:keys [renderer]} k & options]
`(utils/call! ^IsometricTiledMapRenderer ~renderer ~k ~@options))
[screen k & options]
`(utils/call! ^IsometricTiledMapRenderer (:renderer ~screen) ~k ~@options))
(defmacro isometric-staggered-tiled-map!
[{:keys [renderer]} k & options]
`(utils/call! ^IsometricStaggeredTiledMapRenderer ~renderer ~k ~@options))
[screen k & options]
`(utils/call! ^IsometricStaggeredTiledMapRenderer (:renderer ~screen)
~k ~@options))
(defmacro hexagonal-tiled-map!
[{:keys [renderer]} k & options]
`(utils/call! ^HexagonalTiledMapRenderer ~renderer ~k ~@options))
[screen k & options]
`(utils/call! ^HexagonalTiledMapRenderer (:renderer ~screen) ~k ~@options))
(defmacro stage!
[{:keys [renderer]} k & options]
`(utils/call! ^Stage ~renderer ~k ~@options))
[screen k & options]
`(utils/call! ^Stage (:renderer ~screen) ~k ~@options))
(defmacro orthographic-camera!
[{:keys [camera]} k & options]
`(utils/call! ^OrthographicCamera ~camera ~k ~@options))
[screen k & options]
`(utils/call! ^OrthographicCamera (:camera ~screen) ~k ~@options))
(defmacro perspective-camera!
[{:keys [camera]} k & options]
`(utils/call! ^PerspectiveCamera ~camera ~k ~@options))
[screen k & options]
`(utils/call! ^PerspectiveCamera (:camera ~screen) ~k ~@options))
; global
@@ -84,6 +85,10 @@
[entity k & options]
`(utils/call! ^Label (:object ~entity) ~k ~@options))
(defmacro slider!
[entity k & options]
`(utils/call! ^Slider (:object ~entity) ~k ~@options))
(defmacro text-button!
[entity k & options]
`(utils/call! ^TextButton (:object ~entity) ~k ~@options))

View File

@@ -3,7 +3,7 @@
; rendering
(defn render!
[{:keys [renderer ^Camera camera]}]
[{:keys [renderer ^Camera camera delta-time]}]
(assert renderer)
(cond
(isa? (type renderer) BatchTiledMapRenderer)
@@ -11,7 +11,9 @@
(.setView camera)
.render)
(isa? (type renderer) Stage)
(.draw ^Stage renderer)))
(doto ^Stage renderer
(.act delta-time)
.draw)))
(defn tiled-map-layers
[{:keys [^BatchTiledMapRenderer renderer]}]

View File

@@ -7,6 +7,18 @@
(utils/key->class type) "Style."))
~@options))
(defmacro drawable
[type & options]
`(~(symbol (str utils/gdx-package ".scenes.scene2d.utils."
(utils/key->class type) "Drawable."))
~@options))
(defmacro skin
[path & options]
`(utils/calls! ^Skin (Skin. (files! :internal ~path)) ~@options))
; widgets
(defn check-box*
[^String text arg]
(CheckBox. text arg))
@@ -42,6 +54,15 @@
[text arg & options]
`(create-entity (utils/calls! ^Label (label* ~text ~arg) ~@options)))
(defn slider*
[min max step is-vert? arg]
(Slider. (float min) (float max) (float step) is-vert? arg))
(defmacro slider
[min max step is-vert? arg & options]
`(create-entity
(utils/calls! ^Slider (slider* ~min ~max ~step ~is-vert? ~arg) ~@options)))
(defn text-button*
[^String text arg]
(TextButton. text arg))