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