This repository has been archived by the owner on Oct 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch defapplet to take an options hash. (work-in-progress)
- Loading branch information
1 parent
b25bb90
commit bf5877c
Showing
2 changed files
with
42 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,42 @@ | ||
(ns rosado.processing.applet | ||
(:use rosado.processing) | ||
(:use [rosado.processing] | ||
[clojure.contrib.java-utils :only [as-str]]) | ||
(:import (java.awt Frame))) | ||
|
||
(defn bind-applet [f] | ||
(fn [this & args] | ||
(binding [*applet* this] (apply f args)))) | ||
|
||
(defmacro defapplet | ||
[name title setup draw width height] | ||
`(do | ||
(def ~name | ||
(proxy [processing.core.PApplet] [] | ||
(setup [] | ||
(binding [*applet* ~'this] | ||
(size ~width ~height) | ||
(~setup))) | ||
(draw [] | ||
(binding [*applet* ~'this] | ||
(~draw))))) | ||
(defn ~(symbol (str "run-" name)) [] | ||
(.init ~name) | ||
(def ~(symbol (str name "-frame")) (doto (Frame. ~title) | ||
(.setSize ~width ~height) | ||
(.add ~name) | ||
(.pack) | ||
(.show)))) | ||
"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) | ||
;; TODO: fix this to automatically bind *applet* in fns | ||
;; methods (zipmap (map name (keys fns)) | ||
;; (map bind-applet (vals fns))) | ||
] | ||
`(def ~app-name | ||
(let [frame# (atom nil) | ||
prx# (proxy [processing.core.PApplet | ||
clojure.lang.IMeta] [] | ||
(meta [] (assoc ~options :frame frame#)))] | ||
(update-proxy prx# ~fns) | ||
prx#)))) | ||
|
||
(defn run [applet] | ||
(.init applet) | ||
(let [m (.meta applet) | ||
width (or (:width m) 200) | ||
height (or (:height m) 200)] | ||
(.size applet width height) | ||
(reset! (:frame m) | ||
(doto (Frame. (or (:title m) (:name m))) | ||
(.setSize width height) | ||
(.add applet) | ||
(.pack) | ||
(.show))))) | ||
|
||
(defn ~(symbol (str "stop-" name)) [] | ||
(.destroy ~name) | ||
(.hide ~(symbol (str name "-frame")))))) | ||
(defn stop [applet] | ||
(.destroy applet) | ||
(.hide @(:frame ^applet))) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rosado
Owner
|
I get the following problem:
What's the deal? I think there's a wonky reader macro going on here.