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 wrap: on
line diff
--- a/src/net/kryshen/indyvon/core.clj Fri Apr 06 19:19:13 2012 +0400 +++ b/src/net/kryshen/indyvon/core.clj Fri Apr 06 20:48:30 2012 +0400 @@ -161,6 +161,32 @@ (anchor-y [_ v-align h] (* sy (anchor-y geometry v-align (/ h sy))))) +;; (defn ^:private to-integer +;; ^long [align x] +;; (if (integer? x) +;; x +;; (let [x (double x)] +;; (Math/round +;; (case align +;; (:top :left) (Math/floor x) +;; :center x +;; (:bottom :right) (Math/ceil x)))))) + +;; (defrecord IntegerGeometry [geometry] +;; Geometry +;; (width [_] +;; (to-integer :right (width geometry))) +;; (width [_ h] +;; (to-integer :right (width geometry h))) +;; (height [_] +;; (to-integer :bottom (height geometry))) +;; (height [_ w] +;; (to-integer :bottom (height geometry w))) +;; (anchor-x [_ h-align w] +;; (to-integer h-align (anchor-x geometry h-align w))) +;; (anchor-y [_ v-align h] +;; (to-integer v-align (anchor-y geometry v-align h)))) + ;; TODO: modifiers (defrecord MouseEvent [id when x y x-on-screen y-on-screen button wheel-rotation]) @@ -346,14 +372,14 @@ (defn- ^Graphics2D create-graphics ([] (apply-theme (.create *graphics*) *theme*)) - ([x y w h] + ([^long x ^long y ^long w ^long h] (apply-theme (.create *graphics* x y w h) *theme*))) (defn- with-bounds-noclip* [x y w h f & args] (let [graphics (create-graphics)] (try - (.translate graphics (int x) (int y)) + (.translate graphics (double x) (double y)) (binding [*width* w *height* h *clipped* false @@ -364,17 +390,21 @@ (defn with-bounds* [x y w h f & args] - (when-let [clip (clip x y w h)] - (let [graphics (create-graphics x y w h)] - (try - (binding [*width* w - *height* h - *clip* clip - *clipped* true - *graphics* graphics] - (apply f args)) - (finally - (.dispose graphics)))))) + (let [x (long x) + y (long y) + w (long w) + h (long h)] + (when-let [clip (clip x y w h)] + (let [^Graphics2D graphics (create-graphics x y w h)] + (try + (binding [*width* w + *height* h + *clip* clip + *clipped* true + *graphics* graphics] + (apply f args)) + (finally + (.dispose graphics))))))) (defmacro with-bounds [x y w h & body]