Rename input methods for consistency
This commit is contained in:
@@ -71,8 +71,8 @@
|
|||||||
:pause #(execute-fn! on-pause)
|
:pause #(execute-fn! on-pause)
|
||||||
:resize #(execute-fn! on-resize)
|
:resize #(execute-fn! on-resize)
|
||||||
:resume #(execute-fn! on-resume)
|
:resume #(execute-fn! on-resume)
|
||||||
:input (input* options execute-fn!)
|
:input-processor (input-processor options execute-fn!)
|
||||||
:gesture (gesture* options execute-fn!)}))
|
:gesture-detector (gesture-detector options execute-fn!)}))
|
||||||
|
|
||||||
(defmacro defscreen
|
(defmacro defscreen
|
||||||
[n & {:keys [] :as options}]
|
[n & {:keys [] :as options}]
|
||||||
@@ -97,8 +97,8 @@
|
|||||||
(let [add-inputs! (fn []
|
(let [add-inputs! (fn []
|
||||||
(input! :setInputProcessor (InputMultiplexer.))
|
(input! :setInputProcessor (InputMultiplexer.))
|
||||||
(doseq [screen screens]
|
(doseq [screen screens]
|
||||||
(add-input! (:input screen))
|
(add-input! (:input-processor screen))
|
||||||
(add-input! (:gesture screen))))
|
(add-input! (:gesture-detector screen))))
|
||||||
run-fn! (fn [k & args]
|
run-fn! (fn [k & args]
|
||||||
(doseq [screen screens]
|
(doseq [screen screens]
|
||||||
(apply (get screen k) args)))]
|
(apply (get screen k) args)))]
|
||||||
|
|||||||
@@ -43,80 +43,74 @@
|
|||||||
[key]
|
[key]
|
||||||
`(.isKeyPressed ^Input (Gdx/input) (get-keycode ~key)))
|
`(.isKeyPressed ^Input (Gdx/input) (get-keycode ~key)))
|
||||||
|
|
||||||
(defn input*
|
(defn- input-processor
|
||||||
[{:keys [key-down key-typed key-up mouse-moved
|
[{:keys [on-key-down on-key-typed on-key-up on-mouse-moved
|
||||||
scrolled touch-down touch-dragged touch-up]
|
on-scrolled on-touch-down on-touch-dragged on-touch-up]
|
||||||
:or {key-down dummy key-typed dummy key-up dummy mouse-moved dummy
|
:or {on-key-down dummy on-key-typed dummy
|
||||||
scrolled dummy touch-down dummy touch-dragged dummy touch-up dummy}}
|
on-key-up dummy on-mouse-moved dummy
|
||||||
|
on-scrolled dummy on-touch-down dummy
|
||||||
|
on-touch-dragged dummy on-touch-up dummy}}
|
||||||
execute-fn!]
|
execute-fn!]
|
||||||
(reify InputProcessor
|
(reify InputProcessor
|
||||||
(keyDown [this k]
|
(keyDown [this k]
|
||||||
(execute-fn! key-down :keycode k)
|
(execute-fn! on-key-down :keycode k)
|
||||||
false)
|
false)
|
||||||
(keyTyped [this c]
|
(keyTyped [this c]
|
||||||
(execute-fn! key-typed :character c)
|
(execute-fn! on-key-typed :character c)
|
||||||
false)
|
false)
|
||||||
(keyUp [this k]
|
(keyUp [this k]
|
||||||
(execute-fn! key-up :keycode k)
|
(execute-fn! on-key-up :keycode k)
|
||||||
false)
|
false)
|
||||||
(mouseMoved [this sx sy]
|
(mouseMoved [this sx sy]
|
||||||
(execute-fn! mouse-moved :screen-x sx :screen-y sy)
|
(execute-fn! on-mouse-moved :screen-x sx :screen-y sy)
|
||||||
false)
|
false)
|
||||||
(scrolled [this a]
|
(scrolled [this a]
|
||||||
(execute-fn! scrolled :amount a)
|
(execute-fn! on-scrolled :amount a)
|
||||||
false)
|
false)
|
||||||
(touchDown [this sx sy p b]
|
(touchDown [this sx sy p b]
|
||||||
(execute-fn! touch-down :screen-x sx :screen-y sy :pointer p :button b)
|
(execute-fn! on-touch-down :screen-x sx :screen-y sy :pointer p :button b)
|
||||||
false)
|
false)
|
||||||
(touchDragged [this sx sy p]
|
(touchDragged [this sx sy p]
|
||||||
(execute-fn! touch-dragged :screen-x sx :screen-y sy :pointer p)
|
(execute-fn! on-touch-dragged :screen-x sx :screen-y sy :pointer p)
|
||||||
false)
|
false)
|
||||||
(touchUp [this sx sy p b]
|
(touchUp [this sx sy p b]
|
||||||
(execute-fn! touch-up :screen-x sx :screen-y sy :pointer p :button b)
|
(execute-fn! on-touch-up :screen-x sx :screen-y sy :pointer p :button b)
|
||||||
false)))
|
false)))
|
||||||
|
|
||||||
(defmacro input
|
(defn- gesture-detector
|
||||||
[& args]
|
[{:keys [on-fling on-long-press on-pan on-pan-stop on-pinch on-tap on-zoom]
|
||||||
`(input* ~args (fn [func# & options#] (func# options#))))
|
:or {on-fling dummy on-long-press dummy on-pan dummy on-pan-stop dummy
|
||||||
|
on-pinch dummy on-tap dummy on-zoom dummy}}
|
||||||
(defn gesture*
|
|
||||||
[{:keys [fling long-press pan pan-stop pinch tap zoom]
|
|
||||||
:or {fling dummy long-press dummy pan dummy pan-stop dummy
|
|
||||||
pinch dummy tap dummy zoom dummy}}
|
|
||||||
execute-fn!]
|
execute-fn!]
|
||||||
(let [listener
|
(let [listener
|
||||||
(reify GestureDetector$GestureListener
|
(reify GestureDetector$GestureListener
|
||||||
(fling [this vx vy b]
|
(fling [this vx vy b]
|
||||||
(execute-fn! fling :velocity-x vx :velocity-y vy :button b)
|
(execute-fn! on-fling :velocity-x vx :velocity-y vy :button b)
|
||||||
false)
|
false)
|
||||||
(longPress [this x y]
|
(longPress [this x y]
|
||||||
(execute-fn! long-press :x x :y y)
|
(execute-fn! on-long-press :x x :y y)
|
||||||
false)
|
false)
|
||||||
(pan [this x y dx dy]
|
(pan [this x y dx dy]
|
||||||
(execute-fn! pan :x x :y y :delta-x dx :delta-y dy)
|
(execute-fn! on-pan :x x :y y :delta-x dx :delta-y dy)
|
||||||
false)
|
false)
|
||||||
(panStop [this x y p b]
|
(panStop [this x y p b]
|
||||||
(execute-fn! pan-stop :x x :y y :pointer p :button b)
|
(execute-fn! on-pan-stop :x x :y y :pointer p :button b)
|
||||||
false)
|
false)
|
||||||
(pinch [this ip1 ip2 p1 p2]
|
(pinch [this ip1 ip2 p1 p2]
|
||||||
(execute-fn! pinch
|
(execute-fn! on-pinch
|
||||||
:initial-pointer-1 ip1 :initial-pointer-2 ip2
|
:initial-pointer-1 ip1 :initial-pointer-2 ip2
|
||||||
:pointer1 p1 :pointer2 p2)
|
:pointer1 p1 :pointer2 p2)
|
||||||
false)
|
false)
|
||||||
(tap [this x y c b]
|
(tap [this x y c b]
|
||||||
(execute-fn! tap :x x :y y :count c :button b)
|
(execute-fn! on-tap :x x :y y :count c :button b)
|
||||||
false)
|
false)
|
||||||
(touchDown [this x y p b]
|
(touchDown [this x y p b]
|
||||||
false)
|
false)
|
||||||
(zoom [this id d]
|
(zoom [this id d]
|
||||||
(execute-fn! zoom :initial-distance id :distance d)
|
(execute-fn! on-zoom :initial-distance id :distance d)
|
||||||
false))]
|
false))]
|
||||||
(proxy [GestureDetector] [listener])))
|
(proxy [GestureDetector] [listener])))
|
||||||
|
|
||||||
(defmacro gesture
|
|
||||||
[& args]
|
|
||||||
`(gesture* ~args (fn [func# & options#] (func# options#))))
|
|
||||||
|
|
||||||
(defn add-input!
|
(defn add-input!
|
||||||
[^InputProcessor p]
|
[^InputProcessor p]
|
||||||
(.addProcessor ^InputMultiplexer (.getInputProcessor (Gdx/input)) p))
|
(.addProcessor ^InputMultiplexer (.getInputProcessor (Gdx/input)) p))
|
||||||
|
|||||||
Reference in New Issue
Block a user