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