0
|
1 |
"
|
4
|
2 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
24
|
3 |
All Rights Reserved
|
0
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
49
|
13 |
'From Smalltalk/X, Version:2.10.5 on 30-apr-1995 at 1:46:33 am'!
|
|
14 |
|
0
|
15 |
Scroller subclass:#Slider
|
49
|
16 |
instanceVariableNames:'sliderHeight'
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Views-Interactors'
|
0
|
20 |
!
|
|
21 |
|
11
|
22 |
!Slider class methodsFor:'documentation'!
|
|
23 |
|
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
24
|
27 |
All Rights Reserved
|
0
|
28 |
|
11
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
!
|
0
|
37 |
|
11
|
38 |
version
|
|
39 |
"
|
71
|
40 |
$Header: /cvs/stx/stx/libwidg2/Slider.st,v 1.11 1995-08-30 18:06:44 claus Exp $
|
11
|
41 |
"
|
|
42 |
!
|
0
|
43 |
|
11
|
44 |
documentation
|
|
45 |
"
|
|
46 |
this class implements sliders - which are simply scrollers
|
49
|
47 |
with a constant thumbHeight. For details on actionBlocks and
|
|
48 |
MVC operation, see the documentation in Scroller.
|
11
|
49 |
"
|
48
|
50 |
!
|
|
51 |
|
|
52 |
examples
|
|
53 |
"
|
|
54 |
a slider with action block (ST/X style):
|
|
55 |
|
|
56 |
|top s|
|
|
57 |
|
|
58 |
top := StandardSystemView new extent:200@200.
|
|
59 |
s := Slider in:top.
|
|
60 |
s origin:(0.0@0.0) corner:(20@1.0).
|
|
61 |
s scrollAction:[:percent | Transcript show:'moved to: '; showCr:percent asFloat].
|
|
62 |
top open
|
|
63 |
|
|
64 |
|
49
|
65 |
same, horizontal:
|
|
66 |
|
|
67 |
|top s|
|
|
68 |
|
|
69 |
top := StandardSystemView new extent:200@200.
|
|
70 |
s := HorizontalSlider in:top.
|
|
71 |
s origin:(0.0@0.0) corner:(1.0@20).
|
|
72 |
s scrollAction:[:percent | Transcript show:'moved to: '; showCr:percent asFloat].
|
|
73 |
top open
|
|
74 |
|
|
75 |
|
|
76 |
with a range other than the default:
|
|
77 |
|
|
78 |
|top s|
|
|
79 |
|
|
80 |
top := StandardSystemView new extent:200@200.
|
|
81 |
s := Slider in:top.
|
|
82 |
s origin:(0.0@0.0) corner:(20@1.0).
|
|
83 |
s scrollAction:[:percent | Transcript show:'moved to: '; showCr:percent asFloat].
|
|
84 |
s start:-50 stop:50.
|
|
85 |
top open
|
|
86 |
|
|
87 |
|
48
|
88 |
using a model (ST-80 style):
|
49
|
89 |
(see the changing value in the inspector)
|
48
|
90 |
|
|
91 |
|top s m|
|
|
92 |
|
|
93 |
m := 0 asValue.
|
49
|
94 |
m inspect.
|
48
|
95 |
top := StandardSystemView new extent:200@200.
|
|
96 |
s := Slider in:top.
|
|
97 |
s origin:(0.0@0.0) corner:(20@1.0).
|
|
98 |
s model:m.
|
|
99 |
top open
|
|
100 |
|
|
101 |
|
|
102 |
reacting to changes from the model:
|
49
|
103 |
(look at and/or change value using 'self value:' in the inspector).
|
48
|
104 |
|
|
105 |
|top s m|
|
|
106 |
|
|
107 |
m := 0 asValue.
|
49
|
108 |
m inspect.
|
48
|
109 |
top := StandardSystemView new extent:200@200.
|
|
110 |
s := Slider in:top.
|
|
111 |
s origin:(0.0@0.0) corner:(20@1.0).
|
49
|
112 |
s model:m.
|
48
|
113 |
top open
|
|
114 |
|
|
115 |
|
|
116 |
using a different changeSelector:
|
|
117 |
|
|
118 |
|top s1 s2 m|
|
|
119 |
|
|
120 |
m := Plug new.
|
|
121 |
m respondTo:#value1: with:[:v | Transcript show:'scroller 1 moved to: '; showCr:v].
|
|
122 |
m respondTo:#value2: with:[:v | Transcript show:'scroller 2 moved to: '; showCr:v].
|
|
123 |
|
|
124 |
top := StandardSystemView new extent:200@200.
|
|
125 |
s1 := Slider in:top.
|
|
126 |
s1 origin:(0.0@0.0) corner:(20@1.0).
|
|
127 |
s1 thumbHeight:10. 'percent'.
|
|
128 |
s1 model:m; change:#value1:.
|
|
129 |
|
|
130 |
s2 := Slider in:top.
|
|
131 |
s2 origin:(30@0.0) corner:(50@1.0).
|
|
132 |
s2 thumbHeight:10. 'percent'.
|
|
133 |
s2 model:m; change:#value2:.
|
|
134 |
top open
|
62
|
135 |
|
|
136 |
|
|
137 |
another example:
|
|
138 |
|
|
139 |
|top redVal greenVal blueVal
|
|
140 |
colorVal upd s1 s2 s3 l|
|
|
141 |
|
|
142 |
redVal := 0 asValue.
|
|
143 |
greenVal := 0 asValue.
|
|
144 |
blueVal := 0 asValue.
|
|
145 |
|
|
146 |
upd := [colorVal value:(Color red:redVal value
|
|
147 |
green:greenVal value
|
|
148 |
blue:blueVal value)].
|
|
149 |
|
|
150 |
colorVal := (Color red:0 green:0 blue:0) asValue.
|
|
151 |
colorVal onChangeSend:#value to:[l backgroundColor:colorVal value].
|
|
152 |
|
|
153 |
redVal onChangeSend:#value to:upd.
|
|
154 |
greenVal onChangeSend:#value to:upd.
|
|
155 |
blueVal onChangeSend:#value to:upd.
|
|
156 |
|
|
157 |
top := StandardSystemView new extent:200@200.
|
|
158 |
top label:'Color mixer'.
|
|
159 |
|
|
160 |
s1 := Slider in:top.
|
|
161 |
s1 origin:(0.0@0.0) corner:(20@1.0).
|
|
162 |
s1 thumbHeight:10. 'percent'.
|
|
163 |
s1 model:redVal.
|
|
164 |
|
|
165 |
s2 := Slider in:top.
|
|
166 |
s2 origin:(30@0.0) corner:(50@1.0).
|
|
167 |
s2 thumbHeight:10. 'percent'.
|
|
168 |
s2 model:greenVal.
|
|
169 |
|
|
170 |
s3 := Slider in:top.
|
|
171 |
s3 origin:(60@0.0) corner:(80@1.0).
|
|
172 |
s3 thumbHeight:10. 'percent'.
|
|
173 |
s3 model:blueVal.
|
|
174 |
|
|
175 |
l := Label in:top.
|
|
176 |
l origin:90@0.0 corner:1.0@1.0.
|
|
177 |
l backgroundColor:Color black.
|
|
178 |
|
|
179 |
top open
|
|
180 |
|
|
181 |
|
|
182 |
the same setup, using action blocks:
|
|
183 |
|
|
184 |
|top red green blue
|
|
185 |
colorVal upd s1 s2 s3 labelModel l|
|
|
186 |
|
|
187 |
red := green := blue := 0.
|
|
188 |
|
|
189 |
top := StandardSystemView new extent:200@200.
|
|
190 |
top label:'Color mixer'.
|
|
191 |
|
|
192 |
s1 := Slider in:top.
|
|
193 |
s1 origin:(0.0@0.0) corner:(20@1.0).
|
|
194 |
s1 thumbHeight:10. 'percent'.
|
|
195 |
s1 action:[:percent | red := percent.
|
|
196 |
l backgroundColor:(Color red:red green:green blue:blue)].
|
|
197 |
|
|
198 |
s2 := Slider in:top.
|
|
199 |
s2 origin:(30@0.0) corner:(50@1.0).
|
|
200 |
s2 thumbHeight:10. 'percent'.
|
|
201 |
s2 action:[:percent | green := percent.
|
|
202 |
l backgroundColor:(Color red:red green:green blue:blue)].
|
|
203 |
|
|
204 |
s3 := Slider in:top.
|
|
205 |
s3 origin:(60@0.0) corner:(80@1.0).
|
|
206 |
s3 thumbHeight:10. 'percent'.
|
|
207 |
s3 action:[:percent | blue := percent.
|
|
208 |
l backgroundColor:(Color red:red green:green blue:blue)].
|
|
209 |
|
|
210 |
l := Label in:top.
|
|
211 |
l origin:90@0.0 corner:1.0@1.0.
|
|
212 |
l backgroundColor:Color black.
|
|
213 |
|
|
214 |
top open
|
48
|
215 |
"
|
11
|
216 |
! !
|
0
|
217 |
|
49
|
218 |
!Slider methodsFor:'private'!
|
0
|
219 |
|
49
|
220 |
percentFromAbs:absValue
|
|
221 |
"given a number of pixels, compute percentage"
|
8
|
222 |
|
49
|
223 |
|fullSize val|
|
24
|
224 |
|
49
|
225 |
(orientation == #vertical) ifTrue:[
|
|
226 |
fullSize := height
|
|
227 |
] ifFalse:[
|
|
228 |
fullSize := width
|
|
229 |
].
|
0
|
230 |
|
49
|
231 |
val := absValue / (fullSize - sliderHeight - (margin * 2)) * (rangeEnd - rangeStart).
|
|
232 |
val := val + rangeStart.
|
|
233 |
val < rangeStart ifTrue:[^ rangeStart].
|
|
234 |
val > rangeEnd ifTrue:[^ rangeEnd].
|
|
235 |
^ val
|
|
236 |
!
|
0
|
237 |
|
|
238 |
absFromPercent:percent
|
|
239 |
"given a percentage, compute number of pixels"
|
|
240 |
|
49
|
241 |
|fullSize|
|
0
|
242 |
|
49
|
243 |
(orientation == #vertical) ifTrue:[
|
|
244 |
fullSize := height
|
|
245 |
] ifFalse:[
|
|
246 |
fullSize := width
|
|
247 |
].
|
|
248 |
^ ((percent * (fullSize - sliderHeight - (margin * 2))) / 100) rounded
|
0
|
249 |
!
|
|
250 |
|
|
251 |
computeThumbFrame
|
|
252 |
"redefined, since the thumb-height stays constant"
|
|
253 |
|
49
|
254 |
|nh nw ny nx sz m|
|
0
|
255 |
|
|
256 |
thumbHeight := 0.
|
49
|
257 |
sz := (self absFromPercent:thumbOrigin) + margin.
|
|
258 |
m := margin + inset.
|
|
259 |
(orientation == #vertical) ifTrue:[
|
|
260 |
ny := sz.
|
|
261 |
nh := sliderHeight.
|
|
262 |
nx := m.
|
|
263 |
nw := width - (2 * nx).
|
|
264 |
] ifFalse:[
|
|
265 |
nx := sz.
|
|
266 |
nw := sliderHeight.
|
|
267 |
ny := m.
|
|
268 |
nh := height - (2 * ny).
|
|
269 |
].
|
|
270 |
|
0
|
271 |
"
|
|
272 |
do not create new Rectangle if its the same anyway
|
|
273 |
"
|
|
274 |
thumbFrame notNil ifTrue:[
|
24
|
275 |
(ny == thumbFrame top) ifTrue:[
|
|
276 |
(nx == thumbFrame left) ifTrue:[
|
|
277 |
(nh == thumbFrame height) ifTrue:[
|
|
278 |
(nw == thumbFrame width) ifTrue:[ ^ self]
|
|
279 |
]
|
|
280 |
]
|
|
281 |
]
|
0
|
282 |
].
|
|
283 |
thumbFrame := Rectangle left:nx top:ny width:nw height:nh
|
|
284 |
! !
|
49
|
285 |
|
|
286 |
!Slider methodsFor:'initialization'!
|
|
287 |
|
|
288 |
initStyle
|
|
289 |
super initStyle.
|
|
290 |
|
|
291 |
tallyMarks := StyleSheet at:'sliderNTallyMarks' default:1.
|
|
292 |
tallyLevel := StyleSheet at:'sliderTallyLevel' default:-1.
|
|
293 |
!
|
|
294 |
|
|
295 |
initialize
|
|
296 |
sliderHeight := (self verticalPixelPerMillimeter:10) rounded.
|
|
297 |
super initialize.
|
|
298 |
thumbHeight := 0.
|
|
299 |
! !
|
|
300 |
|
|
301 |
!Slider methodsFor:'forced scroll'!
|
|
302 |
|
|
303 |
pageUp
|
|
304 |
"ignored - a slider has no concept of page-wise scrolling"
|
|
305 |
|
|
306 |
^ self
|
|
307 |
!
|
|
308 |
|
|
309 |
pageDown
|
|
310 |
"ignored - a slider has no concept of page-wise scrolling"
|
|
311 |
|
|
312 |
^ self
|
|
313 |
! !
|
|
314 |
|
|
315 |
!Slider methodsFor:'accessing'!
|
|
316 |
|
|
317 |
thumbHeight
|
|
318 |
"redefined since a slider has no height - just origin"
|
|
319 |
|
|
320 |
^ nil
|
|
321 |
! !
|
|
322 |
|