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