1682
|
1 |
"{ Package: 'stx:libview2' }"
|
|
2 |
|
|
3 |
View subclass:#PluggableView
|
|
4 |
instanceVariableNames:'redrawAction buttonPressAction keyPressAction'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Views-Basic'
|
|
8 |
!
|
|
9 |
|
|
10 |
!PluggableView class methodsFor:'documentation'!
|
|
11 |
|
|
12 |
documentation
|
|
13 |
"
|
|
14 |
a view for which the redraw, button and key-actions can be plugged as
|
|
15 |
blocks.
|
|
16 |
Mostly useful for little examples (where we dont want to add a full-blown class
|
|
17 |
for.
|
|
18 |
|
|
19 |
[author:]
|
|
20 |
Claus Gittinger (cg@alan)
|
|
21 |
|
|
22 |
[instance variables:]
|
|
23 |
|
|
24 |
[class variables:]
|
|
25 |
|
|
26 |
[see also:]
|
|
27 |
|
|
28 |
"
|
|
29 |
!
|
|
30 |
|
|
31 |
examples
|
|
32 |
"
|
|
33 |
|
|
34 |
a simple lissajous figure
|
|
35 |
[exBegin]
|
|
36 |
|v|
|
|
37 |
|
1683
|
38 |
v := PluggableView new.
|
|
39 |
v viewBackground:Color black.
|
1682
|
40 |
v redrawAction:[
|
|
41 |
|offsX offsY scaleX scaleY|
|
|
42 |
|
1683
|
43 |
scaleX := v width - 10 // 2.
|
|
44 |
scaleY := v height - 10 // 2.
|
|
45 |
offsX := v width // 2.
|
|
46 |
offsY := v height // 2.
|
1682
|
47 |
|
|
48 |
0 to:360 do:[:degrees |
|
|
49 |
|radians x y|
|
|
50 |
|
|
51 |
radians := degrees degreesToRadians.
|
|
52 |
x := (radians * 3 ) cos.
|
|
53 |
y := (radians * 5 ) sin.
|
|
54 |
|
|
55 |
x := x * scaleX + offsX.
|
|
56 |
y := y * scaleY + offsY.
|
|
57 |
v atX:x y:y put:Color red.
|
|
58 |
].
|
|
59 |
].
|
1683
|
60 |
v open.
|
1682
|
61 |
[exEnd]
|
|
62 |
"
|
|
63 |
! !
|
|
64 |
|
|
65 |
!PluggableView methodsFor:'accessing'!
|
|
66 |
|
|
67 |
buttonPressAction:something
|
|
68 |
"set the value of the instance variable 'buttonPressAction' (automatically generated)"
|
|
69 |
|
|
70 |
buttonPressAction := something.
|
|
71 |
!
|
|
72 |
|
|
73 |
keyPressAction:something
|
|
74 |
"set the value of the instance variable 'keyPressAction' (automatically generated)"
|
|
75 |
|
|
76 |
keyPressAction := something.
|
|
77 |
!
|
|
78 |
|
|
79 |
redrawAction:something
|
|
80 |
"set the value of the instance variable 'redrawAction' (automatically generated)"
|
|
81 |
|
|
82 |
redrawAction := something.
|
|
83 |
! !
|
|
84 |
|
|
85 |
!PluggableView methodsFor:'events'!
|
|
86 |
|
|
87 |
buttonPress:button x:x y:y
|
|
88 |
buttonPressAction notNil ifTrue:[
|
|
89 |
buttonPressAction value:button value:(x @ y)
|
|
90 |
]
|
|
91 |
!
|
|
92 |
|
|
93 |
keyPress:key x:x y:y
|
|
94 |
keyPressAction notNil ifTrue:[
|
|
95 |
keyPressAction value:key value:(x @ y)
|
|
96 |
]
|
|
97 |
!
|
|
98 |
|
|
99 |
redraw
|
|
100 |
super redraw.
|
|
101 |
redrawAction notNil ifTrue:[
|
|
102 |
redrawAction value
|
|
103 |
]
|
1683
|
104 |
!
|
|
105 |
|
|
106 |
sizeChanged:how
|
|
107 |
super sizeChanged:how.
|
|
108 |
self clear.
|
|
109 |
self redraw.
|
1682
|
110 |
! !
|
|
111 |
|
|
112 |
!PluggableView class methodsFor:'documentation'!
|
|
113 |
|
|
114 |
version
|
1683
|
115 |
^ '$Header: /cvs/stx/stx/libview2/PluggableView.st,v 1.2 2003-01-09 16:58:22 cg Exp $'
|
1682
|
116 |
! !
|