view src/net/kryshen/indyvon/demo.clj @ 74:a823dd0c2736

LGPL3
author Mikhail Kryshen <mikhail@kryshen.net>
date Mon, 30 Aug 2010 20:04:21 +0400
parents 59e1810c0278
children ddfde9cce39a
line source
1 ;;
2 ;; Copyright 2010 Mikhail Kryshen <mikhail@kryshen.net>
3 ;;
4 ;; This file is part of Indyvon.
5 ;;
6 ;; Indyvon is free software: you can redistribute it and/or modify it
7 ;; under the terms of the GNU Lesser General Public License version 3
8 ;; only, as published by the Free Software Foundation.
9 ;;
10 ;; Indyvon is distributed in the hope that it will be useful, but
11 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;; Lesser General Public License for more details.
14 ;;
15 ;; You should have received a copy of the GNU Lesser General Public
16 ;; License along with Indyvon. If not, see
17 ;; <http://www.gnu.org/licenses/>.
18 ;;
20 (ns net.kryshen.indyvon.demo
21 (:gen-class)
22 (:use
23 (net.kryshen.indyvon core layers component))
24 (:import
25 (net.kryshen.indyvon.core Size)
26 (java.awt Color)
27 (javax.swing JFrame)))
29 (def layer1
30 (reify
31 Layer
32 (render! [layer]
33 (with-handlers layer
34 (doto *graphics*
35 (.setColor (rand-nth [Color/RED Color/ORANGE]))
36 (.fillRect 0 0 *width* *height*))
37 (:mouse-entered e (println e))
38 (:mouse-exited e (println e))
39 (:mouse-moved e (println e))))
40 (layer-size [layer]
41 (Size. 30 20))))
43 (def layer1b (border layer1 2 3))
45 (def layer2
46 (reify
47 Layer
48 (render! [layer]
49 (doto *graphics*
50 (.setColor Color/YELLOW)
51 (.fillRect 0 0 *width* *height*))
52 (with-rotate 0.5 0 0
53 (draw! layer1b 30 25))
54 (draw! layer1 55 5))
55 (layer-size [layer]
56 (Size. 70 65))))
58 (def layer2m (miniature layer2 30 30))
60 (def layer3 (border (text-layer "Sample\ntext" :right :center)))
62 (def layer
63 (reify
64 Layer
65 (render! [layer]
66 ;;(repaint)
67 (doto *graphics*
68 ;; Random color to see when repaint happens.
69 (.setColor (rand-nth [Color/BLACK Color/BLUE Color/RED]))
70 (.drawLine 0 0 *width* *height*)
71 (.drawLine *width* 0 0 *height*))
72 (draw! layer2 15 20)
73 (draw! layer2m 120 50)
74 (draw! layer3 100 100 80 50))
75 (layer-size [layer]
76 (Size. 400 300))))
78 (def vp (viewport layer))
80 (def root (fps-layer vp))
82 (defn show-frame [layer]
83 (doto (make-jframe "Test" layer)
84 (.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE)
85 (.setVisible true)))
87 (defn -main []
88 (println "Try to drag the viewport.")
89 (show-frame root)
90 (show-frame (fps-layer (viewport-miniature vp 80 60))))