Mercurial > hg > indyvon
changeset 0:43e3358ca4d9
Initial.
author | Mikhail Kryshen <mikhail@kryshen.net> |
---|---|
date | Sun, 06 Jun 2010 06:03:38 +0400 |
parents | |
children | a93cfcf60f27 |
files | .hgignore README project.clj src/indyvon/component.clj src/indyvon/core.clj src/indyvon/layer.clj test/indyvon/core_test.clj |
diffstat | 7 files changed, 115 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Sun Jun 06 06:03:38 2010 +0400 @@ -0,0 +1,7 @@ +syntax: glob + +pom.xml +lib +classes +*.jar +*~
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README Sun Jun 06 06:03:38 2010 +0400 @@ -0,0 +1,15 @@ +# indyvon + +FIXME: write description + +## Usage + +FIXME: write + +## Installation + +FIXME: write + +## License + +FIXME: write
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/project.clj Sun Jun 06 06:03:38 2010 +0400 @@ -0,0 +1,5 @@ +(defproject indyvon "1.0.0-SNAPSHOT" + :description "FIXME: write" + :dependencies [[org.clojure/clojure "1.2.0-master-SNAPSHOT"] + [org.clojure/clojure-contrib "1.2.0-SNAPSHOT"]] + :dev-dependencies [[leiningen/lein-swank "1.2.0-SNAPSHOT"]])
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/indyvon/component.clj Sun Jun 06 06:03:38 2010 +0400 @@ -0,0 +1,17 @@ +;; (ns indyvon.component +;; (:use indyvon.layer) +;; (:import (java.awt Graphics Graphics2D)) +;; (:gen-class +;; :name indyvon.Component +;; :extends java.awt.Component +;; :constructor {[Layer] []} +;; :state layer +;; :init init-state)) + +;; (defn- init-state [layer] +;; [[] layer]) + +;; (defn -paint [this graphics]) + +;; (defn -update [this graphics] +;; (-paint this graphics))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/indyvon/core.clj Sun Jun 06 06:03:38 2010 +0400 @@ -0,0 +1,1 @@ +(ns indyvon.core)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/indyvon/layer.clj Sun Jun 06 06:03:38 2010 +0400 @@ -0,0 +1,64 @@ +(ns indyvon.layer + (:import (java.awt Component Graphics2D))) + +(def ^{:private true} *graphics*) +(def ^{:private true} *rx* 0) +(def ^{:private true} *ry* 0) + +(def *width*) +(def *height*) + +(def *lag*) + +(def *update-fn*) + +(defprotocol Layer + (render! [this]) + (size [this]) + (anchor [this])) + +(defn- translate [g x y w h clip] + (if clip + (.create g x y w h) + (doto (.create g) + (.translate x y)))) + +(defn render-layer! + "Render layer in a new graphics context." + ([layer] + (render-layer! layer 0 0 *width* *height*)) + ([layer x y] + (render-layer! layer x y true)) + ([layer x y clip] + (let [s (size layer)] + (render-layer! layer x y (.width s) (.height s) clip))) + ([layer x y w h] + (render-layer! layer x y w h true)) + ([layer x y w h clip] + (binding [*graphics* (translate *graphics* x y w h clip) + *rx* (+ *rx* x) + *ry* (+ *ry* y) + *width* w + *height* h] + (render! layer)))) + +(defn- make-update-fn [component] + (fn [] (.repaint component))) + +(defn make-component [layer] + (proxy [Component] [] + (update [g] (.paint this g)) + (paint [g] + (let [insets (.getInsets this) + top (.top insets) + left (.left insets) + bottom (.bottom insets) + right (.right insets) + size (.getSize this) + width (- (.width size) left right) + height (- (.height size) top bottom)] + (binding [*graphics* g + *update-fn* (make-update-fn this)] + (render-layer! layer top left width height false)))) + (getPreferredSize [] + (size layer))))