diff --git a/src/doodler/core.clje b/src/doodler/core.clje index a0091a3..5087a62 100644 --- a/src/doodler/core.clje +++ b/src/doodler/core.clje @@ -37,11 +37,22 @@ ([r g b alpha] #erl[r g b alpha])) +(defn- save-current-stroke + "Save current stroke color vector in the internal state. It can be accessed using (current-stroke) function." + [color] + (set! *internal-state* (assoc *internal-state* :current-stroke color))) + +(defn current-stroke + [] + (:current-stroke *internal-state*)) + (defn stroke [& args] - (let [pen (wxDC/getPen *canvas*)] - (wxPen/setColour pen (apply color args)) - (wxDC/setPen *canvas* pen))) + (let [pen (wxDC/getPen *canvas*) + color (apply color args)] + (wxPen/setColour pen color) + (wxDC/setPen *canvas* pen) + (save-current-stroke color))) (defn stroke-weight [weight] @@ -56,11 +67,22 @@ (wxDC/setBackground *canvas* brush) (clear))) +(defn- save-current-fill + "Save current fill color vector in the internal state. It can be accessed using (current-fill) function." + [color] + (set! *internal-state* (assoc *internal-state* :current-fill color))) + (defn fill [& args] - (let [brush (wxDC/getBrush *canvas*)] - (wxBrush/setColour brush (apply color args)) - (wxDC/setBrush *canvas* brush))) + (let [brush (wxDC/getBrush *canvas*) + color (apply color args)] + (wxBrush/setColour brush color) + (wxDC/setBrush *canvas* brush) + (save-current-fill color))) + +(defn current-fill + [] + (:current-fill *internal-state*)) (defn arc [x y w h start end] @@ -75,9 +97,13 @@ #erl[(- x (erlang/div w 2)) (- y (erlang/div h 2))] #erl[w h])) +(defn line + ([p1 p2] (apply line (concat p1 p2))) + ([x1 y1 x2 y2] (wxDC/drawLine *canvas* #erl[x1 y1] #erl[x2 y2]))) + (defn point [x y] - (wxDC/drawPoint *canvas* (tuple x y))) + (wxDC/drawPoint *canvas* #erl[x y])) (defn random ([max] diff --git a/src/doodler/examples/shapes.clje b/src/doodler/examples/shapes.clje index b24455e..fbc7f1b 100644 --- a/src/doodler/examples/shapes.clje +++ b/src/doodler/examples/shapes.clje @@ -6,14 +6,22 @@ (d/frame-rate 10)) (defn draw [] + (d/background 200) + (d/stroke (rand-int 255)) (d/stroke-weight (rand-int 3)) (d/fill (rand-int 255)) + (d/ellipse 20 20 20 20) (d/arc 10 55 50 50 0.0 45.0) (d/rect 10 60 20 20) (d/rect 10 85 20 20 5) + (d/line 10 130 80 140) + (d/text "Hello world!" 10 110) + (d/text (str "Fill: " (d/current-fill)) 100 10) + (d/text (str "Stroke: " (d/current-stroke)) 100 30) + ) (d/defsketch sketch