Mercurial > hg > indyvon
changeset 55:6adbc03a52cb
Replace *bounds* with *width* and *height*.
author | Mikhail Kryshen <mikhail@kryshen.net> |
---|---|
date | Thu, 19 Aug 2010 20:33:37 +0400 |
parents | 1d2dfe5026a8 |
children | 87400ec6d433 |
files | src/net/kryshen/indyvon/component.clj src/net/kryshen/indyvon/core.clj src/net/kryshen/indyvon/demo.clj src/net/kryshen/indyvon/layers.clj |
diffstat | 4 files changed, 56 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/src/net/kryshen/indyvon/component.clj Thu Aug 19 20:20:21 2010 +0400 +++ b/src/net/kryshen/indyvon/component.clj Thu Aug 19 20:33:37 2010 +0400 @@ -23,19 +23,19 @@ width (.width size) height (.height size)] (.clearRect graphics 0 0 width height) - (let [bounds (Bounds. 0 0 width height)] - (binding [*graphics* graphics - *font-context* (.getFontRenderContext graphics) - *initial-transform* (.getTransform graphics) - *inverse-initial-transform* - (-> graphics .getTransform .createInverse) - *target* component - *event-dispatcher* event-dispatcher - *update* #(.repaint component) - *bounds* bounds - *clip* (Rectangle2D$Double. 0 0 width height)] - (render! layer) - (commit event-dispatcher))))) + (binding [*graphics* graphics + *font-context* (.getFontRenderContext graphics) + *initial-transform* (.getTransform graphics) + *inverse-initial-transform* + (-> graphics .getTransform .createInverse) + *target* component + *event-dispatcher* event-dispatcher + *update* #(.repaint component) + *width* width + *height* height + *clip* (Rectangle2D$Double. 0 0 width height)] + (render! layer) + (commit event-dispatcher)))) (defn preferred-size [component layer] (binding [*target* component
--- a/src/net/kryshen/indyvon/core.clj Thu Aug 19 20:20:21 2010 +0400 +++ b/src/net/kryshen/indyvon/core.clj Thu Aug 19 20:33:37 2010 +0400 @@ -14,7 +14,8 @@ (def ^Graphics2D *graphics*) (def ^FontRenderContext *font-context*) (def ^Component *target*) -(def *bounds*) +(def *width*) +(def *height*) (def ^Shape *clip*) (def *update*) (def *event-dispatcher*) @@ -131,18 +132,19 @@ (defn ^Graphics2D create-graphics ([] - (create-graphics 0 0 (:width *bounds*) (:height *bounds*))) + (create-graphics 0 0 *width* *height*)) ([x y w h] (apply-theme (.create *graphics* x y w h) *theme*))) (defmacro with-bounds [x y w h & body] - `(let [bounds# (Bounds. (+ ~x (:x *bounds*)) - (+ ~y (:y *bounds*)) ~w ~h) - clip# (clip ~x ~y ~w ~h)] + `(let [x# ~x, y# ~y + w# ~w, h# ~h + clip# (clip x# y# w# h#)] (when clip# - (let [graphics# (create-graphics ~x ~y ~w ~h)] + (let [graphics# (create-graphics x# y# w# h#)] (try - (binding [*bounds* bounds# + (binding [*width* w# + *height* h# *clip* clip# *graphics* graphics#] ~@body)
--- a/src/net/kryshen/indyvon/demo.clj Thu Aug 19 20:20:21 2010 +0400 +++ b/src/net/kryshen/indyvon/demo.clj Thu Aug 19 20:33:37 2010 +0400 @@ -22,7 +22,7 @@ (with-handlers layer (doto *graphics* (.setColor Color/RED) - (.fillRect 0 0 (:width *bounds*) (:height *bounds*))) + (.fillRect 0 0 *width* *height*)) (:mouse-entered e (println e)) (:mouse-exited e (println e)) (:mouse-moved e (println e)))) @@ -36,7 +36,7 @@ (render! [layer] (doto *graphics* (.setColor Color/YELLOW) - (.fillRect 0 0 (:width *bounds*) (:height *bounds*))) + (.fillRect 0 0 *width* *height*)) (with-rotate 0.5 0 0 (draw! layer1b 10 5)) (draw! layer1 55 5)) @@ -74,7 +74,7 @@ ;;(*update*) (doto *graphics* (.setColor (rand-nth [Color/BLACK Color/BLUE Color/RED])) - (.drawLine 0 0 (:width *bounds*) (:height *bounds*))) + (.drawLine 0 0 *width* *height*)) (draw! layer2 15 20) (draw! layer3 100 100 80 50) (draw! fps))
--- a/src/net/kryshen/indyvon/layers.clj Thu Aug 19 20:20:21 2010 +0400 +++ b/src/net/kryshen/indyvon/layers.clj Thu Aug 19 20:33:37 2010 +0400 @@ -51,8 +51,8 @@ (render! [l] (draw! content left top - (- (:width *bounds*) left right) - (- (:height *bounds*) top bottom))) + (- *width* left right) + (- *height* top bottom))) (layer-size [l] (let [s (layer-size content)] (Size. (+ (:width s) left right) @@ -67,12 +67,12 @@ ([content width gap] (let [layer (padding content (+ width gap))] (decorate-layer layer [_] - (let [w (:width *bounds*) - h (:height *bounds*)] - (with-color (:border-color *theme*) - (doseq [i (range 0 width)] - (.drawRect *graphics* i i (- w 1 i i) (- h 1 i i)))) - (render! layer)))))) + (with-color (:border-color *theme*) + (doseq [i (range 0 width)] + (.drawRect *graphics* i i + (- *width* 1 i i) + (- *height* 1 i i)))) + (render! layer))))) (defn panel "Opaque layer using theme's alt-back-color." @@ -82,8 +82,7 @@ (let [layer (padding content gap)] (decorate-layer layer [_] (with-color (:alt-back-color *theme*) - (.fillRect *graphics* 0 0 - (:width *bounds*) (:height *bounds*))) + (.fillRect *graphics* 0 0 *width* *height*)) (render! layer))))) (defn- re-split [^java.util.regex.Pattern re s] @@ -125,8 +124,8 @@ (let [lines (re-split #"\r\n|\n|\r|\u0085|\u2028|\u2029" text)] (reify Layer (render! [layer] - (let [w (:width *bounds*) - h (:height *bounds*) + (let [w *width* + h *height* font (.getFont *graphics*) layouts (layout-text lines font *font-context*) y (align-y (text-height layouts) h v-align)] @@ -185,29 +184,27 @@ Layer (render! [layer] (with-handlers layer - (let [anchor (anchor content h-align v-align) - width (:width *bounds*) - height (:height *bounds*)] + (let [anchor (anchor content h-align v-align)] + (dosync + (alter x + (align-x *width* @last-width h-align)) + (alter y + (align-y *height* @last-height v-align)) + (ref-set last-width *width*) + (ref-set last-height *height*)) + (draw! content (- 0 @x (:x anchor)) (- 0 @y (:y anchor)))) + (:mouse-pressed e (dosync - (alter x + (align-x width @last-width h-align)) - (alter y + (align-y height @last-height v-align)) - (ref-set last-width width) - (ref-set last-height height)) - (draw! content (- 0 @x (:x anchor)) (- 0 @y (:y anchor)))) - (:mouse-pressed e - (dosync - (ref-set fix-x (:x-on-screen e)) - (ref-set fix-y (:y-on-screen e))) - (->> Cursor/MOVE_CURSOR Cursor. (.setCursor *target*))) - (:mouse-released e - (->> Cursor/DEFAULT_CURSOR Cursor. (.setCursor *target*))) - (:mouse-dragged e - (dosync - (alter x + (- @fix-x (:x-on-screen e))) - (alter y + (- @fix-y (:y-on-screen e))) - (ref-set fix-x (:x-on-screen e)) - (ref-set fix-y (:y-on-screen e))) - (*update*)))) + (ref-set fix-x (:x-on-screen e)) + (ref-set fix-y (:y-on-screen e))) + (->> Cursor/MOVE_CURSOR Cursor. (.setCursor *target*))) + (:mouse-released e + (->> Cursor/DEFAULT_CURSOR Cursor. (.setCursor *target*))) + (:mouse-dragged e + (dosync + (alter x + (- @fix-x (:x-on-screen e))) + (alter y + (- @fix-y (:y-on-screen e))) + (ref-set fix-x (:x-on-screen e)) + (ref-set fix-y (:y-on-screen e))) + (*update*)))) (layer-size [layer] (layer-size content)))))) ;;