changeset 35:0d593970cb76

Separate namespace for demo and experiments.
author Mikhail Kryshen <mikhail@kryshen.net>
date Thu, 08 Jul 2010 06:02:12 +0400
parents 6975b9a71eec
children 5413b188d112
files project.clj src/indyvon/component.clj src/indyvon/demo.clj
diffstat 3 files changed, 91 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/project.clj	Thu Jul 08 05:27:54 2010 +0400
+++ b/project.clj	Thu Jul 08 06:02:12 2010 +0400
@@ -5,4 +5,5 @@
   :dev-dependencies [[leiningen/lein-swank "1.2.0-SNAPSHOT"]]
   :namespaces [indyvon.core
                indyvon.layers
-               indyvon.component])
+               indyvon.component
+               indyvon.demo])
--- a/src/indyvon/component.clj	Thu Jul 08 05:27:54 2010 +0400
+++ b/src/indyvon/component.clj	Thu Jul 08 06:02:12 2010 +0400
@@ -50,80 +50,3 @@
        (.setBackground panel (:back-color *theme*))
        (listen! event-dispatcher panel)
        panel)))
-
-(comment
-  (do
-    (def frame (JFrame. "Test"))
-    
-    (def layer1
-         (reify
-          Layer
-          (render! [layer opts]
-             (with-handlers layer
-               (doto *graphics*
-                 (.setColor Color/RED)
-                 (.fillRect 0 0 (:width *bounds*) (:height *bounds*)))
-               (:mouse-entered e (println e))
-               (:mouse-exited e (println e))
-               (:mouse-moved e (println e))))
-          (size [layer opts] (Size. 30 20))))
-    
-    (def layer1b (border-layer layer1 2 3))
-    
-    (def layer2
-         (reify
-          Layer
-          (render! [layer opts]
-             (doto *graphics*
-               (.setColor Color/YELLOW)
-               (.fillRect 0 0 (:width *bounds*) (:height *bounds*)))
-             (draw! layer1b [10 5])
-             (draw! layer1 [55 5]))
-          (size [layer opts] (Size. 70 65))))
-    
-    (def layer3
-         (border-layer (text-layer "Sample\ntext" :right :center)))
-
-    (defn fps-layer [fps]
-      (border-layer (text-layer (format "%.1f" fps) :right :bottom) 0 5))
-    
-    (def fps
-         (let [update-interval 0.1
-               frames (ref 0)
-               last (ref 0)
-               fl (ref (fps-layer 0.0))]
-           (reify
-            Layer
-            (render! [layer opts]
-               (render! @fl nil)
-               (dosync
-                (alter frames + 1)
-                (let [time (System/currentTimeMillis)
-                      elapsed (/ (- time @last) 1000.0)]
-                  (when (> elapsed update-interval)
-                    (ref-set fl (fps-layer (/ @frames elapsed)))
-                    (ref-set frames 0)
-                    (ref-set last time)))))
-            (size [layer opts] (size @fl nil)))))
-    
-    (def layer
-         (reify Layer
-           (render! [layer opts]
-             (*update*)
-             (doto *graphics*
-               (.setColor (rand-nth [Color/BLACK Color/BLUE Color/RED]))
-               (.drawLine 0 0 (:width *bounds*) (:height *bounds*)))
-             (draw! layer2 [15 20])
-             (draw! layer3 [100 100 80 50])
-             (render! fps nil))
-           (size [layer opts] (Size. 400 300))))
-    
-    (doto frame
-      (.addWindowListener
-       (proxy [java.awt.event.WindowAdapter] []
-         (windowClosing [event] (.dispose frame))))
-      (.. (getContentPane) (add (make-jpanel (viewport layer))))
-      (.pack)
-      (.setVisible true))
-    )
-  )
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/indyvon/demo.clj	Thu Jul 08 06:02:12 2010 +0400
@@ -0,0 +1,89 @@
+;;
+;; Copyright (C) 2010 Mikhail Kryshen <mikhail@kryshen.net>
+;;
+;; This file is part of Indyvon.
+;;
+
+(ns indyvon.demo
+  (:gen-class)
+  (:use indyvon.core
+        indyvon.layers
+        indyvon.component)
+  (:import (indyvon.core Size Bounds)
+           (java.awt Graphics2D Component Dimension Color)
+           (javax.swing JFrame JPanel)))
+
+(def frame (JFrame. "Test"))
+
+(def layer1
+     (reify
+      Layer
+      (render! [layer opts]
+         (with-handlers layer
+           (doto *graphics*
+             (.setColor Color/RED)
+             (.fillRect 0 0 (:width *bounds*) (:height *bounds*)))
+           (:mouse-entered e (println e))
+           (:mouse-exited e (println e))
+           (:mouse-moved e (println e))))
+      (size [layer opts] (Size. 30 20))))
+
+(def layer1b (border-layer layer1 2 3))
+
+(def layer2
+     (reify
+      Layer
+      (render! [layer opts]
+         (doto *graphics*
+           (.setColor Color/YELLOW)
+           (.fillRect 0 0 (:width *bounds*) (:height *bounds*)))
+         (draw! layer1b [10 5])
+         (draw! layer1 [55 5]))
+      (size [layer opts] (Size. 70 65))))
+
+(def layer3
+     (border-layer (text-layer "Sample\ntext" :right :center)))
+
+(defn fps-layer [fps]
+  (border-layer (text-layer (format "%.1f" fps) :right :bottom) 0 5))
+
+(def fps
+     (let [update-interval 0.1
+           frames (ref 0)
+           last (ref 0)
+           fl (ref (fps-layer 0.0))]
+       (reify
+        Layer
+        (render! [layer opts]
+           (render! @fl nil)
+           (dosync
+            (alter frames + 1)
+            (let [time (System/currentTimeMillis)
+                  elapsed (/ (- time @last) 1000.0)]
+              (when (> elapsed update-interval)
+                (ref-set fl (fps-layer (/ @frames elapsed)))
+                (ref-set frames 0)
+                (ref-set last time)))))
+        (size [layer opts] (size @fl nil)))))
+
+(def layer
+     (reify
+      Layer
+      (render! [layer opts]
+         (*update*)
+         (doto *graphics*
+           (.setColor (rand-nth [Color/BLACK Color/BLUE Color/RED]))
+           (.drawLine 0 0 (:width *bounds*) (:height *bounds*)))
+         (draw! layer2 [15 20])
+         (draw! layer3 [100 100 80 50])
+         (render! fps nil))
+      (size [layer opts] (Size. 400 300))))
+
+(defn -main []
+  (doto frame
+    (.addWindowListener
+     (proxy [java.awt.event.WindowAdapter] []
+       (windowClosing [event] (.dispose frame))))
+    (.. (getContentPane) (add (make-jpanel (viewport layer))))
+    (.pack)
+    (.setVisible true)))