changeset 148:613bd4ac1bc0

Panel has background color argument.
author Mikhail Kryshen <mikhail@kryshen.net>
date Thu, 25 Apr 2013 04:01:33 +0400
parents 7c982d2ee9f3
children 79bd47e3120a
files src/net/kryshen/indyvon/core.clj src/net/kryshen/indyvon/layers.clj
diffstat 2 files changed, 20 insertions(+), 23 deletions(-) [+]
line diff
     1.1 --- a/src/net/kryshen/indyvon/core.clj	Thu Apr 25 04:01:31 2013 +0400
     1.2 +++ b/src/net/kryshen/indyvon/core.clj	Thu Apr 25 04:01:33 2013 +0400
     1.3 @@ -438,19 +438,16 @@
     1.4    `(binding [*theme* (merge *theme* ~theme)]
     1.5       ~@body))
     1.6  
     1.7 -(defmacro with-color
     1.8 -  [color-or-keyword & body]
     1.9 -  (let [color-form (if (keyword? color-or-keyword)
    1.10 -                     `(~color-or-keyword *theme*)
    1.11 -                     color-or-keyword)]
    1.12 -    `(let [color# ~color-form
    1.13 -           g# *graphics*
    1.14 -           old-color# (.getColor g#)]
    1.15 -       (try
    1.16 -         (.setColor g# color#)
    1.17 -         ~@body
    1.18 -         (finally
    1.19 -          (.setColor g# old-color#))))))
    1.20 +(defmacro with-color [color-or-key & body]
    1.21 +  `(let [color# ~color-or-key
    1.22 +         color# (get *theme* color# color#)
    1.23 +         g# *graphics*
    1.24 +         old-color# (.getColor g#)]
    1.25 +     (try
    1.26 +       (.setColor g# color#)
    1.27 +       ~@body
    1.28 +       (finally
    1.29 +         (.setColor g# old-color#)))))
    1.30  
    1.31  (defmacro with-stroke [stroke & body]
    1.32    `(let [g# *graphics*
     2.1 --- a/src/net/kryshen/indyvon/layers.clj	Thu Apr 25 04:01:31 2013 +0400
     2.2 +++ b/src/net/kryshen/indyvon/layers.clj	Thu Apr 25 04:01:33 2013 +0400
     2.3 @@ -47,6 +47,9 @@
     2.4  
     2.5  (def empty-layer (->Empty))
     2.6  
     2.7 +;; TODO: change argument order for decorators, content should be the
     2.8 +;; last.
     2.9 +
    2.10  (defn padding
    2.11    "Decorates layer adding padding."
    2.12    ([content pad]
    2.13 @@ -109,17 +112,14 @@
    2.14                              y x shadow-y shadow-x))))))
    2.15  
    2.16  (defn panel
    2.17 -  "Opaque layer using theme's alt-back-color."
    2.18 +  "Opaque layer using theme's alt-back-color or a custom background color."
    2.19    ([content]
    2.20 -     (panel content 0))
    2.21 -  ([content gap]
    2.22 -     (panel content gap gap gap gap))
    2.23 -  ([content top left bottom right]
    2.24 -     (let [layer (padding content top left bottom right)]
    2.25 -       (decorate-layer layer [_]
    2.26 -         (with-color :alt-back-color
    2.27 -           (.fill *graphics* (Rectangle2D$Double. 0.0 0.0 *width* *height*)))
    2.28 -         (render! layer)))))
    2.29 +     (panel :alt-back-color content))
    2.30 +  ([back-color content]
    2.31 +     (decorate-layer content [_]
    2.32 +       (with-color back-color
    2.33 +         (.fill *graphics* (Rectangle2D$Double. 0.0 0.0 *width* *height*)))
    2.34 +       (render! content))))
    2.35  
    2.36  (defn hbox
    2.37    "Creates layer that draws the specified content layers placing them