diff --git a/.gitignore b/.gitignore index cc4bc942..cf422d0a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ pom.xml native .cake .lein-deps-sum +target diff --git a/README.md b/README.md index 0f6eedb7..6da96b40 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Quil requires Clojure 1.4.0 or higher, and other dependencies described in `proj [Leiningen](https://github.com/technomancy/leiningen) users simply need to add Quil as a dependency to their `project.clj`: - [quil "1.4.1"] + [quil "1.5.0"] Then to pull in all of Quil's silky goodness, just add the following to your `ns` declaration: diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 78230c70..df843389 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,3 +1,11 @@ +## 1.6.0 +_7th July 2012_ + +* Add `debug` fn for printing and forcing the current thread to sleep. +* Add `key-coded` for determining whether the currently pressed key is + _coded_ i.e. a special character. +* Add `key-as-keyword` for returning the currently pressed key as a keyword. + ## 1.5.0 _16th June 2012_ diff --git a/project.clj b/project.clj index 060e9030..cfe54fdd 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject quil "1.5.0" +(defproject quil "1.6.0" :description "(mix Processing Clojure)" :url "http://github.com/quil/quil" :mailing-list {:name "Quil Mailing List" diff --git a/src/quil/core.clj b/src/quil/core.clj index 513ce312..a1612d8b 100644 --- a/src/quil/core.clj +++ b/src/quil/core.clj @@ -2,7 +2,8 @@ ^{:doc "Wrappers and extensions around the core Processing.org API." :author "Roland Sadowski, Sam Aaron"} quil.core - (:import [processing.core PApplet PImage PGraphics PFont PConstants PShape]) + (:import [processing.core PApplet PImage PGraphics PFont PConstants PShape] + [java.awt.event KeyEvent]) (:require [clojure.set]) (:use [quil.version :only [QUIL-VERSION-STR]] [quil.util :only [int-like? resolve-constant-key length-of-longest-key gen-padding print-definition-list]] @@ -4373,3 +4374,79 @@ the visualisation. See sketch for the available options." [app-name & opts] `(defapplet ~app-name ~@opts)) + +(defn ^{:requires-bindings false + :processing-name nil + :category "Input" + :subcategory "Keyboard" + :added "1.6"} + key-coded? + "Returns true if char c is a 'coded' char i.e. it is necessary to + fetch the key-code as an integer and use that to determine the + specific key pressed. See key-keyword." + [c] + (= PConstants/CODED (int c))) + +(def ^{:private true} + KEY-CODES {KeyEvent/VK_UP :up + KeyEvent/VK_DOWN :down + KeyEvent/VK_LEFT :left + KeyEvent/VK_RIGHT :right + KeyEvent/VK_ALT :alt + KeyEvent/VK_CONTROL :control + KeyEvent/VK_SHIFT :shift + KeyEvent/VK_WINDOWS :command + KeyEvent/VK_META :command + KeyEvent/VK_F1 :f1 + KeyEvent/VK_F2 :f2 + KeyEvent/VK_F3 :f3 + KeyEvent/VK_F4 :f4 + KeyEvent/VK_F5 :f5 + KeyEvent/VK_F6 :f6 + KeyEvent/VK_F7 :f7 + KeyEvent/VK_F8 :f8 + KeyEvent/VK_F9 :f9 + KeyEvent/VK_F10 :f10 + KeyEvent/VK_F11 :f11 + KeyEvent/VK_F12 :f12 + KeyEvent/VK_F13 :f13 + KeyEvent/VK_F14 :f14 + KeyEvent/VK_F15 :f15 + KeyEvent/VK_F16 :f16 + KeyEvent/VK_F17 :f17 + KeyEvent/VK_F18 :f18 + KeyEvent/VK_F19 :f19 + KeyEvent/VK_F20 :f20 + KeyEvent/VK_F21 :f21 + KeyEvent/VK_F22 :f22 + KeyEvent/VK_F23 :f23 + KeyEvent/VK_F24 :f24}) + +(defn ^{:requires-bindings true + :processing-name nil + :category "Input" + :subcategory "Keyboard" + :added "1.6"} + key-as-keyword + "Returns a keyword representing the currently pressed key. Modifier + keys are represented as: :up, :down, :left, :right, :alt, :control, + :shift, :command, :f1-24" + [] + (let [key-char (raw-key) + code (key-code)] + (if (key-coded? key-char) + (get KEY-CODES code :unknown-key) + (keyword (str key-char))))) + +(defn + ^{:requires-bindings false + :processing-name nil + :category "Debugging" + :added "1.6"} + debug + "Prints msg and then sleeps the current thread for delay-ms. Useful + for debugging live running sketches. delay-ms defaults to 300. " + ([msg] (debug msg 300)) + ([msg delay-ms] + (println msg) + (Thread/sleep delay-ms)))