changeset 124:6dae98ac9af4

Better way to draw borders.
author Mikhail Kryshen <mikhail@kryshen.net>
date Fri, 06 Apr 2012 20:49:21 +0400
parents 7b22c6d585f4
children 11f2030257f9
files src/net/kryshen/indyvon/layers.clj
diffstat 1 files changed, 16 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/net/kryshen/indyvon/layers.clj	Fri Apr 06 20:48:30 2012 +0400
+++ b/src/net/kryshen/indyvon/layers.clj	Fri Apr 06 20:49:21 2012 +0400
@@ -25,7 +25,8 @@
    (java.lang.ref SoftReference)
    (java.awt Font Cursor Image Toolkit Point)
    java.awt.image.ImageObserver
-   (java.awt.geom AffineTransform Point2D$Double)
+   (java.awt.geom AffineTransform Rectangle2D$Double Point2D$Double
+                  Path2D Path2D$Double)
    (java.awt.font FontRenderContext TextLayout)
    java.util.concurrent.TimeUnit
    (com.google.common.cache Cache CacheBuilder CacheLoader)))
@@ -83,22 +84,21 @@
   "Decorate layer with a border."
   ([content]
      (border content 1))
-  ([content width]
-     (border content width 0))
-  ([content width gap]
-     (let [layer (padding content (+ width gap))]
+  ([content thikness]
+     (border content thikness 0))
+  ([content thikness gap]
+     (let [layer (padding content (+ thikness gap))
+           t (double thikness)]
        (decorate-layer layer [_]
-         (let [bw (int width)
-               w (int *width*)
-               h (int *height*)
-               iw (- w bw)
-               ih (- h bw)]
-           (with-color :border-color
-             (doto *graphics*
-               (.fillRect 0 0 iw bw)
-               (.fillRect iw 0 bw ih)
-               (.fillRect bw ih iw bw)
-               (.fillRect 0 bw bw ih))))
+         (with-color :border-color
+           (let [w (double *width*)
+                 h (double *height*)
+                 outer (Rectangle2D$Double. 0.0 0.0 w h)
+                 inner (Rectangle2D$Double. t t (- w t t) (- h t t))]
+             (.fill *graphics*
+                    (doto (Path2D$Double. Path2D/WIND_EVEN_ODD)
+                      (.append outer false)
+                      (.append inner false)))))
          (render! layer)))))
 
 ;; TODO: opacity and blur.