| 1 |
;;; |
| 2 |
;;; Example Program for eusview users 1989.5.27 M.I. |
| 3 |
;;; |
| 4 |
;;; ex1 : not use of user frame class |
| 5 |
;;; : example of drawing |
| 6 |
;;; ex2 : define a user frame |
| 7 |
;;; : example for usage of itimer function |
| 8 |
;;; ex3 : define user panel, user canvas |
| 9 |
;;; : example for color manipulation |
| 10 |
;;; |
| 11 |
(defun ex1 (&rest msgs) |
| 12 |
(let ((Ex1 (instantiate sunview-frame)) p1 p2 b1 b2) |
| 13 |
(send-lexpr ex1 :init msgs) |
| 14 |
(setq P1 (instance sunview-panel :init Ex1 |
| 15 |
;;; :font "/usr/lib/fonts/fixedwidthfonts/screen.b.12" |
| 16 |
)) |
| 17 |
(setq B1 (instance |
| 18 |
panel-text-item :init P1 :title "Text item:" |
| 19 |
:nproc |
| 20 |
'(lambda (value item event) |
| 21 |
(send *C1* :drawtext value 10 20)))) |
| 22 |
(send P1 :fit-height) |
| 23 |
(setq P2 (instance sunview-panel :init Ex1)) |
| 24 |
(setq B2 (instance |
| 25 |
panel-choice-item :init P2 :title "Choice" :choices |
| 26 |
'(src clr xor set) :nproc |
| 27 |
'(lambda (value &optional item event) |
| 28 |
(case value |
| 29 |
(set (setq *ex1-op* Pix_set)) |
| 30 |
(xor (setq *ex1-op* (logxor pix_src pix_dst))) |
| 31 |
(src (setq *ex1-op* pix_src)) |
| 32 |
(clr (setq *ex1-op* pix_clr)))))) |
| 33 |
(send P2 :fit-height) |
| 34 |
(setq *ex1-op* pix_src) |
| 35 |
(setq *C1* (instance |
| 36 |
sunview-canvas :init Ex1 :x 0 |
| 37 |
:width (send ex1 :width) :height (send ex1 :height) |
| 38 |
:clicked-proc |
| 39 |
'(lambda (window movement button pos time) (send *c1* :clear)) |
| 40 |
:drag-started-proc |
| 41 |
'(lambda (window movement button pos time) |
| 42 |
(setq *start* pos)) |
| 43 |
:dragging-proc |
| 44 |
'(lambda (window movement button pos time) |
| 45 |
(send *C1* :drawline (vector-x *start*) (vector-y *start*) |
| 46 |
(vector-x pos) (vector-y pos) :color 1 |
| 47 |
:op *ex1-op*)))) |
| 48 |
(send *C1* :fit) |
| 49 |
(send Ex1 :show) |
| 50 |
ex1)) |
| 51 |
;;; |
| 52 |
(defclass ex2 |
| 53 |
:super sunview-frame |
| 54 |
:slots (P B C last-pos title period)) |
| 55 |
(defmethod ex2 |
| 56 |
(:moving-speed |
| 57 |
(v &optional item event) |
| 58 |
(setq period (/ v 100000.0)) |
| 59 |
(send self :set-itimer-period period)) |
| 60 |
(:move-me |
| 61 |
(&optional item event) |
| 62 |
(send self :set-itimer |
| 63 |
'(lambda (w type) |
| 64 |
(inc cnt) |
| 65 |
(let ((x (mod (round (+ (vector-x (w . last-pos)) 10)) 300)) |
| 66 |
(y (vector-y (w . last-pos)))) |
| 67 |
(send w :move-text w nil nil (floatvector x y) nil))) |
| 68 |
:period period)) |
| 69 |
(:stop-me (&optional item event) (send self :stop-itimer)) |
| 70 |
(:move-text (window movement button pos time) |
| 71 |
(send C :drawtext title |
| 72 |
(vector-x last-pos) (vector-y last-pos) :op pix_clr) |
| 73 |
(send C :drawtext title |
| 74 |
(vector-x pos) (vector-y pos) :op pix_src) |
| 75 |
(setq last-pos pos)) |
| 76 |
(:notify-function0 (&optional item event) (format t "item=~S~%" item)) |
| 77 |
(:notify-function1 (value &optional item event) |
| 78 |
(setq title (format nil "Move me(~s)." value))) |
| 79 |
(:click (window movement button pos time) |
| 80 |
(format t "movement=~s,button=~s,pos=~s,time=~s~%" |
| 81 |
movement button pos time)) |
| 82 |
(:init |
| 83 |
(&rest args) |
| 84 |
(send-super-lexpr :init args) |
| 85 |
(setq P (send self :create-subwindow sunview-panel |
| 86 |
;;; :font "/usr/lib/fonts/fixedwidthfonts/screen.b.12" |
| 87 |
)) |
| 88 |
;;; (setq B (send self :create-button :move-me :title "Move me")) |
| 89 |
(setq B (instance panel-button-item :init P |
| 90 |
:nproc :move-me :title "Move me")) |
| 91 |
(setq B (send self :create-button :stop-me :title "Stop me")) |
| 92 |
(setq B (send self :create-choice :notify-function1 |
| 93 |
:title "Choice item" :choices '(1 2 3) |
| 94 |
:value 1)) |
| 95 |
(setq B (send self :create-cycle :notify-function1 |
| 96 |
:title "Cycle item" :choices '(a b c))) |
| 97 |
(setq B (send self :create-toggle :notify-function1 |
| 98 |
:title "Toggle item" :choices '("=" "+" "-"))) |
| 99 |
(setq B (send self :create-slider :notify-function1 |
| 100 |
:title "Slider item" :min 0.2 :max 120.5 |
| 101 |
:value 10 :length 60)) |
| 102 |
(setq period 0.00001) |
| 103 |
(setq B (send self :create-slider :moving-speed |
| 104 |
:title "Speed" :min 1 :max 100000 |
| 105 |
:value 1 :length 60 :notify-level 'all)) |
| 106 |
(setq C (send self :create-subwindow sunview-canvas |
| 107 |
:x 0 :width (send self :width) |
| 108 |
:height (send self :height) :below P |
| 109 |
:clicked-proc :click :dragging-proc :move-text |
| 110 |
:resize-proc :print-size |
| 111 |
:repaint-proc :print-repaint)) |
| 112 |
(setq last-pos #f(50 50)) |
| 113 |
(setq title "Move me.") |
| 114 |
(send c :drawtext title 50 50) |
| 115 |
(setq cnt 0) |
| 116 |
(send self :show) |
| 117 |
self) |
| 118 |
(:print-repaint (&optional w p a) |
| 119 |
(format t "w=~s,p=~s,a=~s~%" w p a)) |
| 120 |
(:print-size (&optional c w h) |
| 121 |
(format t "c=~s,w=~s,h=~s~%" c w h))) |
| 122 |
;;; |
| 123 |
(defclass ex3-frame |
| 124 |
:super sunview-frame |
| 125 |
:slots |
| 126 |
(panel canvas) |
| 127 |
) |
| 128 |
(defmethod ex3-frame |
| 129 |
(:draw-triangle |
| 130 |
(window movement button pos time) |
| 131 |
(let ((op |
| 132 |
(case |
| 133 |
button |
| 134 |
(left (logior pix_src (pix_color 1))) |
| 135 |
(middle (logior pix_src (pix_color 2))) |
| 136 |
(right (logior pix_src (pix_color 3)))))) |
| 137 |
(send canvas :drawpolygon '(#f(20 10) #f(40 30) #f(20 50)) |
| 138 |
:op op))) |
| 139 |
(:size-show-color-boxes |
| 140 |
(&optional c width height) |
| 141 |
(do ((counter 1 (1+ counter))) |
| 142 |
((eq counter 4)) |
| 143 |
(send canvas :drawimage |
| 144 |
"" (* counter (/ width 5)) 10 (/ width 10) (/ height 2) |
| 145 |
:op (logior pix_src (pix_color counter))) |
| 146 |
(send canvas :drawtext |
| 147 |
(string counter) (+ (* counter (/ width 5)) 10) (/ height 2) |
| 148 |
:op (logxor pix_src pix_dst))) |
| 149 |
(setq cur-color 0)) |
| 150 |
(:show-color-boxes |
| 151 |
(&optional a b c) |
| 152 |
(send self :size-show-color-boxes a |
| 153 |
(send canvas :width) (send canvas :height))) |
| 154 |
(:init |
| 155 |
(&rest args) |
| 156 |
(send-super-lexpr :init args) |
| 157 |
(setq panel (send self :create-subwindow ex3-panel :vertical nil)) |
| 158 |
(setq canvas (send self :create-subwindow ex3-canvas |
| 159 |
:x 0 :below panel :height 60 |
| 160 |
:width (send panel :width) |
| 161 |
)) |
| 162 |
(send self :show) |
| 163 |
(setq (panel . canvas) canvas) |
| 164 |
(send canvas :cmsname (format nil "canvas~s" (unix:getpid))) |
| 165 |
(send panel :set-colors 4) |
| 166 |
(send canvas :show-color-boxes) |
| 167 |
self) |
| 168 |
) |
| 169 |
(defclass ex3-panel |
| 170 |
:super sunview-panel |
| 171 |
:slots ( |
| 172 |
color-item |
| 173 |
red-item green-item blue-item |
| 174 |
cur-color |
| 175 |
red green blue canvas |
| 176 |
) |
| 177 |
) |
| 178 |
(defmethod ex3-panel |
| 179 |
(:set-color |
| 180 |
(value &optional item event) |
| 181 |
(send red-item :value (elt red value)) |
| 182 |
(send green-item :value (elt green value)) |
| 183 |
(send blue-item :value (elt blue value)) |
| 184 |
(setq cur-color value)) |
| 185 |
(:set-colors |
| 186 |
(&optional (size (send canvas :cmssize))) |
| 187 |
(send canvas :put-colormap red green blue 0 size)) |
| 188 |
(:set-red (value &optional item event) |
| 189 |
(setf (aref red cur-color) value) |
| 190 |
(send self :set-colors)) |
| 191 |
(:set-green (value &optional item event) |
| 192 |
(setf (aref green cur-color) value) |
| 193 |
(send self :set-colors)) |
| 194 |
(:set-blue (value &optional item event) |
| 195 |
(setf (aref blue cur-color) value) |
| 196 |
(send self :set-colors)) |
| 197 |
(:init |
| 198 |
(&rest args) |
| 199 |
(send-super-lexpr :init args) |
| 200 |
(setq color-item |
| 201 |
(send self :create-choice :set-color :title "color index:" |
| 202 |
:choices '(0 1 2 3))) |
| 203 |
(setq red-item |
| 204 |
(send self :create-slider :set-red :title "red:" |
| 205 |
:min 0 :max 255 :length 60 :notify-level 'all)) |
| 206 |
(setq green-item |
| 207 |
(send self :create-slider :set-green :title "green:" |
| 208 |
:min 0 :max 255 :length 60 :notify-level 'all)) |
| 209 |
(setq blue-item |
| 210 |
(send self :create-slider :set-blue :title "blue:" |
| 211 |
:min 0 :max 255 :length 60 :notify-level 'all)) |
| 212 |
(setq red (concatenate string nil '(0 0 255 255))) |
| 213 |
(setq green (concatenate string nil '(0 255 0 192))) |
| 214 |
(setq blue (concatenate string nil '(255 0 0 192))) |
| 215 |
(setq cur-color 0) |
| 216 |
self) |
| 217 |
) |
| 218 |
;;; |
| 219 |
(defclass ex3-canvas |
| 220 |
:super sunview-canvas |
| 221 |
:slots |
| 222 |
() |
| 223 |
) |
| 224 |
(defmethod ex3-canvas |
| 225 |
(:draw-triangle |
| 226 |
(window movement button pos time) |
| 227 |
(let ((op |
| 228 |
(case |
| 229 |
button |
| 230 |
(left (logior pix_src (pix_color 1))) |
| 231 |
(middle (logior pix_src (pix_color 2))) |
| 232 |
(right (logior pix_src (pix_color 3)))))) |
| 233 |
(send self :drawpolygon '(#f(20 10) #f(40 30) #f(20 50)) |
| 234 |
:op op))) |
| 235 |
(:size-show-color-boxes |
| 236 |
(&optional c width height) |
| 237 |
(do ((counter 1 (1+ counter))) |
| 238 |
((eq counter 4)) |
| 239 |
(send self :drawimage |
| 240 |
"" (* counter (/ width 5)) 10 (/ width 10) (/ height 2) |
| 241 |
:op (logior pix_src (pix_color counter))) |
| 242 |
(send self :drawtext |
| 243 |
(string counter) (+ (* counter (/ width 5)) 10) (/ height 2) |
| 244 |
:op (logxor pix_src pix_dst))) |
| 245 |
(setq cur-color 0)) |
| 246 |
(:show-color-boxes |
| 247 |
(&optional a b c) |
| 248 |
(send self :size-show-color-boxes a |
| 249 |
(send self :width) (send self :height))) |
| 250 |
(:init |
| 251 |
(&rest args) |
| 252 |
(send-super-lexpr :init args) |
| 253 |
(send self :clicked-proc :draw-triangle) |
| 254 |
(send self :resize-proc :resize-show-color-boxes) |
| 255 |
(send self :repaint-proc :show-color-boxes) |
| 256 |
self)) |
| 257 |
(defun ex nil |
| 258 |
(setq *ex1* (ex1 nil :title "Ex1 : example for drawing" |
| 259 |
:x 200 :y 100 :width 500 :height 300)) |
| 260 |
(setq *ex2* (instance ex2 :init nil :title "Ex2 : Example for itimer" |
| 261 |
:y (send *ex1* :y) :right-of *ex1* |
| 262 |
:width 300 :height 300)) |
| 263 |
(setq *ex3* (instance ex3-frame :init nil :title "Ex3 : example for color" |
| 264 |
:x (send *ex1* :x) :width (send *ex1* :width) |
| 265 |
:below *ex1*)) |
| 266 |
;;; (setq *ex4* (instance ex3-frame :init nil :title "Ex4 : example for color" |
| 267 |
;;; :x (send *ex2* :x) :width (send *ex2* :width) |
| 268 |
;;; :below *ex2*)) |
| 269 |
) |
| 270 |
(format t "type (ex)~%") |