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 diff
1.1 --- a/src/net/kryshen/indyvon/component.clj Thu Aug 19 20:20:21 2010 +0400 1.2 +++ b/src/net/kryshen/indyvon/component.clj Thu Aug 19 20:33:37 2010 +0400 1.3 @@ -23,19 +23,19 @@ 1.4 width (.width size) 1.5 height (.height size)] 1.6 (.clearRect graphics 0 0 width height) 1.7 - (let [bounds (Bounds. 0 0 width height)] 1.8 - (binding [*graphics* graphics 1.9 - *font-context* (.getFontRenderContext graphics) 1.10 - *initial-transform* (.getTransform graphics) 1.11 - *inverse-initial-transform* 1.12 - (-> graphics .getTransform .createInverse) 1.13 - *target* component 1.14 - *event-dispatcher* event-dispatcher 1.15 - *update* #(.repaint component) 1.16 - *bounds* bounds 1.17 - *clip* (Rectangle2D$Double. 0 0 width height)] 1.18 - (render! layer) 1.19 - (commit event-dispatcher))))) 1.20 + (binding [*graphics* graphics 1.21 + *font-context* (.getFontRenderContext graphics) 1.22 + *initial-transform* (.getTransform graphics) 1.23 + *inverse-initial-transform* 1.24 + (-> graphics .getTransform .createInverse) 1.25 + *target* component 1.26 + *event-dispatcher* event-dispatcher 1.27 + *update* #(.repaint component) 1.28 + *width* width 1.29 + *height* height 1.30 + *clip* (Rectangle2D$Double. 0 0 width height)] 1.31 + (render! layer) 1.32 + (commit event-dispatcher)))) 1.33 1.34 (defn preferred-size [component layer] 1.35 (binding [*target* component
2.1 --- a/src/net/kryshen/indyvon/core.clj Thu Aug 19 20:20:21 2010 +0400 2.2 +++ b/src/net/kryshen/indyvon/core.clj Thu Aug 19 20:33:37 2010 +0400 2.3 @@ -14,7 +14,8 @@ 2.4 (def ^Graphics2D *graphics*) 2.5 (def ^FontRenderContext *font-context*) 2.6 (def ^Component *target*) 2.7 -(def *bounds*) 2.8 +(def *width*) 2.9 +(def *height*) 2.10 (def ^Shape *clip*) 2.11 (def *update*) 2.12 (def *event-dispatcher*) 2.13 @@ -131,18 +132,19 @@ 2.14 2.15 (defn ^Graphics2D create-graphics 2.16 ([] 2.17 - (create-graphics 0 0 (:width *bounds*) (:height *bounds*))) 2.18 + (create-graphics 0 0 *width* *height*)) 2.19 ([x y w h] 2.20 (apply-theme (.create *graphics* x y w h) *theme*))) 2.21 2.22 (defmacro with-bounds [x y w h & body] 2.23 - `(let [bounds# (Bounds. (+ ~x (:x *bounds*)) 2.24 - (+ ~y (:y *bounds*)) ~w ~h) 2.25 - clip# (clip ~x ~y ~w ~h)] 2.26 + `(let [x# ~x, y# ~y 2.27 + w# ~w, h# ~h 2.28 + clip# (clip x# y# w# h#)] 2.29 (when clip# 2.30 - (let [graphics# (create-graphics ~x ~y ~w ~h)] 2.31 + (let [graphics# (create-graphics x# y# w# h#)] 2.32 (try 2.33 - (binding [*bounds* bounds# 2.34 + (binding [*width* w# 2.35 + *height* h# 2.36 *clip* clip# 2.37 *graphics* graphics#] 2.38 ~@body)
3.1 --- a/src/net/kryshen/indyvon/demo.clj Thu Aug 19 20:20:21 2010 +0400 3.2 +++ b/src/net/kryshen/indyvon/demo.clj Thu Aug 19 20:33:37 2010 +0400 3.3 @@ -22,7 +22,7 @@ 3.4 (with-handlers layer 3.5 (doto *graphics* 3.6 (.setColor Color/RED) 3.7 - (.fillRect 0 0 (:width *bounds*) (:height *bounds*))) 3.8 + (.fillRect 0 0 *width* *height*)) 3.9 (:mouse-entered e (println e)) 3.10 (:mouse-exited e (println e)) 3.11 (:mouse-moved e (println e)))) 3.12 @@ -36,7 +36,7 @@ 3.13 (render! [layer] 3.14 (doto *graphics* 3.15 (.setColor Color/YELLOW) 3.16 - (.fillRect 0 0 (:width *bounds*) (:height *bounds*))) 3.17 + (.fillRect 0 0 *width* *height*)) 3.18 (with-rotate 0.5 0 0 3.19 (draw! layer1b 10 5)) 3.20 (draw! layer1 55 5)) 3.21 @@ -74,7 +74,7 @@ 3.22 ;;(*update*) 3.23 (doto *graphics* 3.24 (.setColor (rand-nth [Color/BLACK Color/BLUE Color/RED])) 3.25 - (.drawLine 0 0 (:width *bounds*) (:height *bounds*))) 3.26 + (.drawLine 0 0 *width* *height*)) 3.27 (draw! layer2 15 20) 3.28 (draw! layer3 100 100 80 50) 3.29 (draw! fps))
4.1 --- a/src/net/kryshen/indyvon/layers.clj Thu Aug 19 20:20:21 2010 +0400 4.2 +++ b/src/net/kryshen/indyvon/layers.clj Thu Aug 19 20:33:37 2010 +0400 4.3 @@ -51,8 +51,8 @@ 4.4 (render! [l] 4.5 (draw! content 4.6 left top 4.7 - (- (:width *bounds*) left right) 4.8 - (- (:height *bounds*) top bottom))) 4.9 + (- *width* left right) 4.10 + (- *height* top bottom))) 4.11 (layer-size [l] 4.12 (let [s (layer-size content)] 4.13 (Size. (+ (:width s) left right) 4.14 @@ -67,12 +67,12 @@ 4.15 ([content width gap] 4.16 (let [layer (padding content (+ width gap))] 4.17 (decorate-layer layer [_] 4.18 - (let [w (:width *bounds*) 4.19 - h (:height *bounds*)] 4.20 - (with-color (:border-color *theme*) 4.21 - (doseq [i (range 0 width)] 4.22 - (.drawRect *graphics* i i (- w 1 i i) (- h 1 i i)))) 4.23 - (render! layer)))))) 4.24 + (with-color (:border-color *theme*) 4.25 + (doseq [i (range 0 width)] 4.26 + (.drawRect *graphics* i i 4.27 + (- *width* 1 i i) 4.28 + (- *height* 1 i i)))) 4.29 + (render! layer))))) 4.30 4.31 (defn panel 4.32 "Opaque layer using theme's alt-back-color." 4.33 @@ -82,8 +82,7 @@ 4.34 (let [layer (padding content gap)] 4.35 (decorate-layer layer [_] 4.36 (with-color (:alt-back-color *theme*) 4.37 - (.fillRect *graphics* 0 0 4.38 - (:width *bounds*) (:height *bounds*))) 4.39 + (.fillRect *graphics* 0 0 *width* *height*)) 4.40 (render! layer))))) 4.41 4.42 (defn- re-split [^java.util.regex.Pattern re s] 4.43 @@ -125,8 +124,8 @@ 4.44 (let [lines (re-split #"\r\n|\n|\r|\u0085|\u2028|\u2029" text)] 4.45 (reify Layer 4.46 (render! [layer] 4.47 - (let [w (:width *bounds*) 4.48 - h (:height *bounds*) 4.49 + (let [w *width* 4.50 + h *height* 4.51 font (.getFont *graphics*) 4.52 layouts (layout-text lines font *font-context*) 4.53 y (align-y (text-height layouts) h v-align)] 4.54 @@ -185,29 +184,27 @@ 4.55 Layer 4.56 (render! [layer] 4.57 (with-handlers layer 4.58 - (let [anchor (anchor content h-align v-align) 4.59 - width (:width *bounds*) 4.60 - height (:height *bounds*)] 4.61 + (let [anchor (anchor content h-align v-align)] 4.62 + (dosync 4.63 + (alter x + (align-x *width* @last-width h-align)) 4.64 + (alter y + (align-y *height* @last-height v-align)) 4.65 + (ref-set last-width *width*) 4.66 + (ref-set last-height *height*)) 4.67 + (draw! content (- 0 @x (:x anchor)) (- 0 @y (:y anchor)))) 4.68 + (:mouse-pressed e 4.69 (dosync 4.70 - (alter x + (align-x width @last-width h-align)) 4.71 - (alter y + (align-y height @last-height v-align)) 4.72 - (ref-set last-width width) 4.73 - (ref-set last-height height)) 4.74 - (draw! content (- 0 @x (:x anchor)) (- 0 @y (:y anchor)))) 4.75 - (:mouse-pressed e 4.76 - (dosync 4.77 - (ref-set fix-x (:x-on-screen e)) 4.78 - (ref-set fix-y (:y-on-screen e))) 4.79 - (->> Cursor/MOVE_CURSOR Cursor. (.setCursor *target*))) 4.80 - (:mouse-released e 4.81 - (->> Cursor/DEFAULT_CURSOR Cursor. (.setCursor *target*))) 4.82 - (:mouse-dragged e 4.83 - (dosync 4.84 - (alter x + (- @fix-x (:x-on-screen e))) 4.85 - (alter y + (- @fix-y (:y-on-screen e))) 4.86 - (ref-set fix-x (:x-on-screen e)) 4.87 - (ref-set fix-y (:y-on-screen e))) 4.88 - (*update*)))) 4.89 + (ref-set fix-x (:x-on-screen e)) 4.90 + (ref-set fix-y (:y-on-screen e))) 4.91 + (->> Cursor/MOVE_CURSOR Cursor. (.setCursor *target*))) 4.92 + (:mouse-released e 4.93 + (->> Cursor/DEFAULT_CURSOR Cursor. (.setCursor *target*))) 4.94 + (:mouse-dragged e 4.95 + (dosync 4.96 + (alter x + (- @fix-x (:x-on-screen e))) 4.97 + (alter y + (- @fix-y (:y-on-screen e))) 4.98 + (ref-set fix-x (:x-on-screen e)) 4.99 + (ref-set fix-y (:y-on-screen e))) 4.100 + (*update*)))) 4.101 (layer-size [layer] (layer-size content)))))) 4.102 4.103 ;;