author | Jan Vrany <jan.vrany@labware.com> |
Mon, 26 Oct 2020 22:34:32 +0000 | |
branch | jv |
changeset 6247 | a1272bf7ae91 |
parent 4770 | 6634b540fea2 |
permissions | -rw-r--r-- |
2664 | 1 |
"{ Package: 'stx:libwidg2' }" |
2 |
||
4770
6634b540fea2
Added PluggableHierarchicalList to define ad-hoc tree models.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2668
diff
changeset
|
3 |
"{ NameSpace: Smalltalk }" |
6634b540fea2
Added PluggableHierarchicalList to define ad-hoc tree models.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2668
diff
changeset
|
4 |
|
2664 | 5 |
View subclass:#StrokeView |
2668 | 6 |
instanceVariableNames:'strokes currentStroke lastPoint clearButton clearLastButton |
7 |
strokeAction' |
|
2664 | 8 |
classVariableNames:'' |
9 |
poolDictionaries:'' |
|
10 |
category:'Views-Special' |
|
11 |
! |
|
12 |
||
13 |
!StrokeView class methodsFor:'documentation'! |
|
14 |
||
15 |
documentation |
|
16 |
" |
|
17 |
a simple view, which collects strokes. |
|
18 |
will eventually become a character-input method |
|
19 |
for non-latin languages. |
|
20 |
" |
|
21 |
! |
|
22 |
||
23 |
examples |
|
24 |
" |
|
25 |
|v| |
|
26 |
||
27 |
v := StrokeView open. |
|
28 |
v inspect. |
|
29 |
||
30 |
||
31 |
||
32 |
|v| |
|
33 |
||
2666 | 34 |
v := StrokeView openOnXScreenNamed:'bitsy:0'. ' my pda !!!! '. |
2664 | 35 |
v inspect. |
36 |
" |
|
37 |
! ! |
|
38 |
||
2668 | 39 |
!StrokeView methodsFor:'accessing'! |
40 |
||
41 |
strokeAction:something |
|
42 |
strokeAction := something. |
|
43 |
! ! |
|
44 |
||
2664 | 45 |
!StrokeView methodsFor:'button actions'! |
46 |
||
47 |
newStrokeSequence |
|
48 |
strokes removeAll. |
|
49 |
currentStroke := lastPoint := nil. |
|
50 |
self updateButtonStates. |
|
2668 | 51 |
self redraw. |
52 |
||
53 |
strokeAction notNil ifTrue:[ |
|
54 |
strokeAction value:strokes. |
|
55 |
] |
|
2664 | 56 |
! |
57 |
||
58 |
removeLastStroke |
|
59 |
strokes size > 0 ifTrue:[ |
|
60 |
strokes removeLast. |
|
61 |
]. |
|
62 |
||
63 |
currentStroke := lastPoint := nil. |
|
64 |
self updateButtonStates. |
|
2668 | 65 |
self redraw. |
66 |
||
67 |
strokeAction notNil ifTrue:[ |
|
68 |
strokeAction value:strokes. |
|
69 |
] |
|
2664 | 70 |
! |
71 |
||
72 |
updateButtonStates |
|
73 |
strokes isEmpty ifTrue:[ |
|
74 |
clearButton disable. |
|
75 |
clearLastButton disable. |
|
76 |
] ifFalse:[ |
|
77 |
clearButton enable. |
|
78 |
clearLastButton enable. |
|
79 |
] |
|
80 |
! ! |
|
81 |
||
82 |
!StrokeView methodsFor:'event handling'! |
|
83 |
||
84 |
buttonMotion:state x:x y:y |
|
85 |
|thisPoint| |
|
86 |
||
87 |
state == 0 ifTrue:[^ self]. |
|
88 |
||
89 |
thisPoint := x@y. |
|
90 |
currentStroke add:(LineSegment from:lastPoint to:thisPoint). |
|
91 |
||
2668 | 92 |
self paint:Color yellow. |
2664 | 93 |
self displayLineFrom:lastPoint to:thisPoint. |
94 |
||
95 |
lastPoint := thisPoint. |
|
96 |
! |
|
97 |
||
98 |
buttonPress:state x:x y:y |
|
99 |
currentStroke isNil ifTrue:[ |
|
100 |
currentStroke := OrderedCollection new. |
|
101 |
]. |
|
102 |
lastPoint := x@y. |
|
103 |
! |
|
104 |
||
105 |
buttonRelease:state x:x y:y |
|
106 |
currentStroke notNil ifTrue:[ |
|
107 |
strokes add:currentStroke. |
|
108 |
currentStroke := nil. |
|
109 |
self updateButtonStates. |
|
2668 | 110 |
self redrawStrokes. |
111 |
strokeAction notNil ifTrue:[ |
|
112 |
strokeAction value:strokes. |
|
113 |
] |
|
2664 | 114 |
]. |
115 |
! ! |
|
116 |
||
117 |
!StrokeView methodsFor:'initialization'! |
|
118 |
||
119 |
drawStroke:aStroke |
|
120 |
aStroke do:[:eachSegment | |
|
121 |
self displayLineFrom:(eachSegment start) to:(eachSegment end). |
|
122 |
]. |
|
123 |
! |
|
124 |
||
125 |
initialize |
|
126 |
super initialize. |
|
127 |
||
2668 | 128 |
self viewBackground:Color black. |
129 |
||
2664 | 130 |
strokes := OrderedCollection new. |
131 |
||
132 |
clearButton := self newButton2D. |
|
133 |
clearButton label:'Clear'. |
|
134 |
clearButton layout:(LayoutFrame |
|
135 |
leftFraction:0 offset:0 |
|
136 |
rightFraction:0.5 offset:0 |
|
137 |
topFraction:1 offset:-20 |
|
138 |
bottomFraction:1 offset:0). |
|
139 |
||
140 |
clearButton action:[ self newStrokeSequence ]. |
|
141 |
clearButton disable. |
|
142 |
||
143 |
clearLastButton := self newButton2D. |
|
144 |
clearLastButton label:'Undo'. |
|
145 |
clearLastButton layout:(LayoutFrame |
|
146 |
leftFraction:0.5 offset:0 |
|
147 |
rightFraction:1 offset:0 |
|
148 |
topFraction:1 offset:-20 |
|
149 |
bottomFraction:1 offset:0). |
|
150 |
||
151 |
clearLastButton action:[ self removeLastStroke ]. |
|
152 |
clearLastButton disable. |
|
153 |
! |
|
154 |
||
155 |
newButton2D |
|
156 |
|button| |
|
157 |
||
158 |
" |
|
159 |
Times Are a'Changing - |
|
160 |
now it takes more effort to setup a 2D button, |
|
161 |
than to set up a 3D one ;-)" |
|
162 |
||
163 |
button := Button in:self. |
|
164 |
button passiveLevel:0. |
|
165 |
button activeLevel:0. |
|
166 |
button borderWidth:1. |
|
167 |
button borderColor:(Color black). |
|
168 |
button foregroundColor:(Color black). |
|
169 |
button backgroundColor:(Color white). |
|
170 |
^ button |
|
171 |
! |
|
172 |
||
173 |
redraw |
|
174 |
self clear. |
|
2668 | 175 |
self redrawStrokes. |
176 |
! |
|
177 |
||
178 |
redrawStrokes |
|
179 |
self paint:Color cyan. |
|
2664 | 180 |
strokes do:[:eachStroke | |
181 |
self drawStroke:eachStroke |
|
182 |
]. |
|
2668 | 183 |
|
184 |
self paint:Color yellow. |
|
2664 | 185 |
currentStroke notNil ifTrue:[ |
186 |
self drawStroke:currentStroke |
|
187 |
]. |
|
188 |
! ! |
|
189 |
||
190 |
!StrokeView class methodsFor:'documentation'! |
|
191 |
||
192 |
version |
|
2668 | 193 |
^ '$Header: /cvs/stx/stx/libwidg2/StrokeView.st,v 1.3 2004-03-02 08:44:45 cg Exp $' |
2664 | 194 |
! ! |
4770
6634b540fea2
Added PluggableHierarchicalList to define ad-hoc tree models.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
2668
diff
changeset
|
195 |