Mercurial > hg > indyvon
changeset 123:7b22c6d585f4
Convert bounds to integer when setting new clip.
author | Mikhail Kryshen <mikhail@kryshen.net> |
---|---|
date | Fri, 06 Apr 2012 20:48:30 +0400 |
parents | 17aa55059b07 |
children | 6dae98ac9af4 |
files | src/net/kryshen/indyvon/core.clj |
diffstat | 1 files changed, 43 insertions(+), 13 deletions(-) [+] |
line diff
1.1 --- a/src/net/kryshen/indyvon/core.clj Fri Apr 06 19:19:13 2012 +0400 1.2 +++ b/src/net/kryshen/indyvon/core.clj Fri Apr 06 20:48:30 2012 +0400 1.3 @@ -161,6 +161,32 @@ 1.4 (anchor-y [_ v-align h] 1.5 (* sy (anchor-y geometry v-align (/ h sy))))) 1.6 1.7 +;; (defn ^:private to-integer 1.8 +;; ^long [align x] 1.9 +;; (if (integer? x) 1.10 +;; x 1.11 +;; (let [x (double x)] 1.12 +;; (Math/round 1.13 +;; (case align 1.14 +;; (:top :left) (Math/floor x) 1.15 +;; :center x 1.16 +;; (:bottom :right) (Math/ceil x)))))) 1.17 + 1.18 +;; (defrecord IntegerGeometry [geometry] 1.19 +;; Geometry 1.20 +;; (width [_] 1.21 +;; (to-integer :right (width geometry))) 1.22 +;; (width [_ h] 1.23 +;; (to-integer :right (width geometry h))) 1.24 +;; (height [_] 1.25 +;; (to-integer :bottom (height geometry))) 1.26 +;; (height [_ w] 1.27 +;; (to-integer :bottom (height geometry w))) 1.28 +;; (anchor-x [_ h-align w] 1.29 +;; (to-integer h-align (anchor-x geometry h-align w))) 1.30 +;; (anchor-y [_ v-align h] 1.31 +;; (to-integer v-align (anchor-y geometry v-align h)))) 1.32 + 1.33 ;; TODO: modifiers 1.34 (defrecord MouseEvent [id when x y x-on-screen y-on-screen button 1.35 wheel-rotation]) 1.36 @@ -346,14 +372,14 @@ 1.37 (defn- ^Graphics2D create-graphics 1.38 ([] 1.39 (apply-theme (.create *graphics*) *theme*)) 1.40 - ([x y w h] 1.41 + ([^long x ^long y ^long w ^long h] 1.42 (apply-theme (.create *graphics* x y w h) *theme*))) 1.43 1.44 (defn- with-bounds-noclip* 1.45 [x y w h f & args] 1.46 (let [graphics (create-graphics)] 1.47 (try 1.48 - (.translate graphics (int x) (int y)) 1.49 + (.translate graphics (double x) (double y)) 1.50 (binding [*width* w 1.51 *height* h 1.52 *clipped* false 1.53 @@ -364,17 +390,21 @@ 1.54 1.55 (defn with-bounds* 1.56 [x y w h f & args] 1.57 - (when-let [clip (clip x y w h)] 1.58 - (let [graphics (create-graphics x y w h)] 1.59 - (try 1.60 - (binding [*width* w 1.61 - *height* h 1.62 - *clip* clip 1.63 - *clipped* true 1.64 - *graphics* graphics] 1.65 - (apply f args)) 1.66 - (finally 1.67 - (.dispose graphics)))))) 1.68 + (let [x (long x) 1.69 + y (long y) 1.70 + w (long w) 1.71 + h (long h)] 1.72 + (when-let [clip (clip x y w h)] 1.73 + (let [^Graphics2D graphics (create-graphics x y w h)] 1.74 + (try 1.75 + (binding [*width* w 1.76 + *height* h 1.77 + *clip* clip 1.78 + *clipped* true 1.79 + *graphics* graphics] 1.80 + (apply f args)) 1.81 + (finally 1.82 + (.dispose graphics))))))) 1.83 1.84 (defmacro with-bounds 1.85 [x y w h & body]