Skip to content

Commit

Permalink
defapplet takes :size instead of :width, :height
Browse files Browse the repository at this point in the history
  • Loading branch information
rosado committed Sep 5, 2009
1 parent dc2ed14 commit 23c425c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/example2.clj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
;; Now we just need to define an applet:

(defapplet example2 :title "An example."
:setup setup :draw draw :width 200 :height 200)
:setup setup :draw draw :size [200 200])

(run example2)

Expand Down
4 changes: 2 additions & 2 deletions src/rosado/processing.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
;; to an instance of processing.core.PApplet
(def #^PApplet *applet*)

(def #^{:private true} toupper (memfn toUpperCase))
(def toupper (memfn toUpperCase))

(defn- tosymb [kw]
(defn tosymb [kw]
(-> kw name toupper symbol))

(defn abs-int [n] (PApplet/abs (int n)))
Expand Down
12 changes: 7 additions & 5 deletions src/rosado/processing/applet.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns rosado.processing.applet
(:use [rosado.processing])
(:use [rosado.processing :except (size)])
(:import (javax.swing JFrame)))

(defn- bind-applets
Expand All @@ -14,7 +14,7 @@
"Define an applet. Takes an app-name and a map of options."
[app-name & opts]
(let [options (assoc (apply hash-map opts) :name (str app-name))
fns (dissoc options :name :title :height :width)
fns (dissoc options :name :title :size)
methods (reduce bind-applets {} fns)]
`(def ~app-name
(let [frame# (atom nil)
Expand All @@ -30,12 +30,14 @@
[applet & interactive?]
(.init applet)
(let [m (.meta applet)
width (or (:width m) 200)
height (or (:height m) 200)
[width height & mode] (or (:size m) [200 200])
mode (if-let [kw (first mode)]
(tosymb kw)
JAVA2D)
close-op (if (first interactive?)
JFrame/DISPOSE_ON_CLOSE
JFrame/EXIT_ON_CLOSE)]
(.size applet width height)
(.size applet width height mode)
(reset! (:frame m)
(doto (JFrame. (or (:title m) (:name m)))
(.setDefaultCloseOperation close-op)
Expand Down

0 comments on commit 23c425c

Please sign in to comment.