author | Claus Gittinger <cg@exept.de> |
Fri, 15 Sep 2017 12:42:36 +0200 | |
changeset 8177 | 481a5ef90d18 |
parent 7935 | 1d8d21aa47e7 |
child 8606 | 13735a803dc5 |
permissions | -rw-r--r-- |
5461 | 1 |
" |
7935 | 2 |
COPYRIGHT (c) 2009 by Claus Gittinger / eXept Software AG |
5461 | 3 |
All Rights Reserved |
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 |
"{ Package: 'stx:libview' }" |
|
13 |
||
6769 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
5461 | 16 |
AbstractBackground subclass:#GradientBackground |
6966 | 17 |
instanceVariableNames:'colors direction cachedForm usedLength' |
5461 | 18 |
classVariableNames:'' |
19 |
poolDictionaries:'' |
|
20 |
category:'Graphics-Support' |
|
21 |
! |
|
22 |
||
23 |
!GradientBackground class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
7935 | 27 |
COPYRIGHT (c) 2009 by Claus Gittinger / eXept Software AG |
5461 | 28 |
All Rights Reserved |
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
37 |
! |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
38 |
|
7935 | 39 |
documentation |
40 |
" |
|
41 |
instances of me can be installed as a viewBackground, |
|
42 |
and will draw a gradient background. |
|
43 |
I can be used as background of color-sliders (HUE, Light, saturation), |
|
44 |
or for nice looking splashscreens (which was the original motivation for that). |
|
45 |
||
46 |
More than 2 colors can be specified, all given colors will be visited |
|
47 |
with a gradient in between each. |
|
48 |
||
49 |
When a view's size changes, I can be configured to either re-adjust my gradient, |
|
50 |
so that always all colors are visited (but which leads to flicker, because with every |
|
51 |
resize, the full background needs a redraw), |
|
52 |
or to always use the screens size as a reference. |
|
53 |
In the later case, onle new exposed areas need to be redrawn, but only a partial range o colors |
|
54 |
is drawn. |
|
55 |
||
56 |
See the example, which demonstrates the resizing behavior. |
|
57 |
||
58 |
[author:] |
|
59 |
Claus Gittinger |
|
60 |
" |
|
61 |
! |
|
62 |
||
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
63 |
examples |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
64 |
" |
7078 | 65 |
demonstrates the various options, which control gradient the effect: |
6953 | 66 |
[exBegin] |
6966 | 67 |
|bg t c1 c2 c3 v1 v2 v3 v4 v5 v6 v7 v8 l1 l2 l3 l4 l5 l6 l7 l8| |
68 |
||
69 |
c1 := Color yellow. |
|
70 |
c2 := Color red. |
|
71 |
c3 := Color blue. |
|
72 |
||
73 |
t := TopView new. |
|
74 |
t width:800. |
|
75 |
t maxExtent:800@Display height. |
|
76 |
t minExtent:800@50. |
|
77 |
||
78 |
l1 := Label origin:0@0 extent:100@30 in:t. |
|
79 |
l2 := Label origin:100@0 extent:100@30 in:t. |
|
80 |
l3 := Label origin:200@0 extent:100@30 in:t. |
|
81 |
l4 := Label origin:300@0 extent:100@30 in:t. |
|
82 |
l5 := Label origin:400@0 extent:100@30 in:t. |
|
83 |
l6 := Label origin:500@0 extent:100@30 in:t. |
|
84 |
l7 := Label origin:600@0 extent:100@30 in:t. |
|
85 |
l8 := Label origin:700@0 extent:100@30 in:t. |
|
86 |
||
87 |
v1 := View origin:0@30 extent:100@1.0 in:t. |
|
88 |
v2 := View origin:100@30 extent:100@1.0 in:t. |
|
89 |
v3 := View origin:200@30 extent:100@1.0 in:t. |
|
90 |
v4 := View origin:300@30 extent:100@1.0 in:t. |
|
91 |
v5 := View origin:400@30 extent:100@1.0 in:t. |
|
92 |
v6 := View origin:500@30 extent:100@1.0 in:t. |
|
93 |
v7 := View origin:600@30 extent:100@1.0 in:t. |
|
94 |
v8 := View origin:700@30 extent:100@1.0 in:t. |
|
95 |
||
96 |
l1 label:'screen'; adjust:#center. |
|
97 |
bg := GradientBackground new color1:c1 color2:c2. |
|
98 |
v1 viewBackground:bg. |
|
99 |
||
100 |
l2 label:'100'; adjust:#center. |
|
101 |
bg := GradientBackground new color1:c1 color2:c2. |
|
102 |
bg usedLength:100. |
|
103 |
v2 viewBackground:bg. |
|
104 |
||
105 |
l3 label:'300'; adjust:#center. |
|
106 |
bg := GradientBackground new color1:c1 color2:c2. |
|
107 |
bg usedLength:300. |
|
108 |
v3 viewBackground:bg. |
|
109 |
||
110 |
l4 label:'view'; adjust:#center. |
|
111 |
bg := GradientBackground new color1:c1 color2:c2. |
|
112 |
bg usedLength:#view. |
|
113 |
v4 viewBackground:bg. |
|
114 |
||
115 |
l5 label:'screen'; adjust:#center. |
|
116 |
bg := GradientBackground new color1:c1 color2:c2 color3:c3. |
|
117 |
v5 viewBackground:bg. |
|
118 |
||
119 |
l6 label:'100'; adjust:#center. |
|
120 |
bg := GradientBackground new color1:c1 color2:c2 color3:c3. |
|
121 |
bg usedLength:100. |
|
122 |
v6 viewBackground:bg. |
|
123 |
||
124 |
l7 label:'300'; adjust:#center. |
|
125 |
bg := GradientBackground new color1:c1 color2:c2 color3:c3. |
|
126 |
bg usedLength:300. |
|
127 |
v7 viewBackground:bg. |
|
128 |
||
129 |
l8 label:'view'; adjust:#center. |
|
130 |
bg := GradientBackground new color1:c1 color2:c2 color3:c3. |
|
131 |
bg usedLength:#view. |
|
132 |
v8 viewBackground:bg. |
|
133 |
||
134 |
t open. |
|
135 |
[exEnd] |
|
136 |
||
137 |
[exBegin] |
|
138 |
|bg v| |
|
139 |
||
140 |
bg := GradientBackground new colors:{ Color red . Color green . Color blue . Color red }. |
|
141 |
v := View new extent:300@300. |
|
142 |
v viewBackground:bg. |
|
143 |
v open. |
|
144 |
[exEnd] |
|
145 |
[exBegin] |
|
146 |
|bg v| |
|
147 |
||
148 |
bg := GradientBackground new colors:{ Color red . Color green . Color blue . Color red }. |
|
149 |
bg usedLength:#view. |
|
150 |
v := View new extent:300@300. |
|
151 |
v viewBackground:bg. |
|
152 |
v open. |
|
153 |
[exEnd] |
|
154 |
[exBegin] |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
155 |
|bg v| |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
156 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
157 |
bg := GradientBackground new color1:Color red color2:Color yellow. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
158 |
v := View new extent:300@300. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
159 |
v viewBackground:bg. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
160 |
v open. |
6953 | 161 |
[exEnd] |
162 |
||
163 |
[exBegin] |
|
164 |
|bg v| |
|
165 |
||
166 |
bg := GradientBackground new color1:Color red color2:Color yellow. |
|
167 |
bg usedLength:100. |
|
168 |
v := View new extent:300@300. |
|
169 |
v viewBackground:bg. |
|
170 |
v open. |
|
171 |
[exEnd] |
|
172 |
||
173 |
[exBegin] |
|
174 |
|bg v| |
|
175 |
||
176 |
bg := GradientBackground new color1:Color red color2:Color yellow. |
|
6966 | 177 |
bg usedLength:#view. |
178 |
v := View new extent:300@300. |
|
179 |
v viewBackground:bg. |
|
180 |
v open. |
|
181 |
[exEnd] |
|
182 |
||
183 |
[exBegin] |
|
184 |
|bg v| |
|
185 |
||
186 |
bg := GradientBackground new color1:Color red color2:Color yellow. |
|
187 |
bg color3:Color green. |
|
6953 | 188 |
v := View new extent:300@300. |
189 |
v viewBackground:bg. |
|
190 |
v open. |
|
191 |
[exEnd] |
|
6966 | 192 |
[exBegin] |
193 |
|bg v| |
|
194 |
||
195 |
bg := GradientBackground new color1:Color red color2:Color yellow. |
|
196 |
bg color3:Color green. |
|
197 |
bg usedLength:100. |
|
198 |
v := View new extent:300@300. |
|
199 |
v viewBackground:bg. |
|
200 |
v open. |
|
201 |
[exEnd] |
|
202 |
[exBegin] |
|
203 |
|bg v| |
|
204 |
||
205 |
bg := GradientBackground new color1:Color red color2:Color yellow. |
|
206 |
bg color3:Color green. |
|
207 |
bg usedLength:#view. |
|
208 |
v := View new extent:300@300. |
|
209 |
v viewBackground:bg. |
|
210 |
v open. |
|
211 |
[exEnd] |
|
212 |
||
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
213 |
" |
5461 | 214 |
! ! |
215 |
||
6013 | 216 |
!GradientBackground class methodsFor:'instance creation'! |
217 |
||
218 |
horizontal:color1 to:color2 |
|
219 |
^ self new |
|
220 |
direction:#eastWest; |
|
221 |
color1:color1 color2:color2 |
|
222 |
||
223 |
" |
|
224 |
|bg v| |
|
225 |
||
226 |
bg := GradientBackground horizontal:Color red to:Color yellow. |
|
227 |
v := View new extent:300@300. |
|
228 |
v viewBackground:bg. |
|
229 |
v open. |
|
230 |
" |
|
6014 | 231 |
" |
232 |
|bg v| |
|
233 |
||
234 |
bg := GradientBackground horizontal:Color red to:Color yellow. |
|
235 |
v := View new extent:300@300. |
|
236 |
v viewBackground:bg. |
|
237 |
v open. |
|
238 |
" |
|
6013 | 239 |
! |
240 |
||
241 |
vertical:color1 to:color2 |
|
242 |
^ self new |
|
243 |
direction:#northSouth; |
|
244 |
color1:color1 color2:color2 |
|
245 |
||
246 |
" |
|
247 |
|bg v| |
|
248 |
||
249 |
bg := GradientBackground vertical:Color red to:Color yellow. |
|
250 |
v := View new extent:300@300. |
|
251 |
v viewBackground:bg. |
|
252 |
v open. |
|
253 |
" |
|
254 |
! ! |
|
255 |
||
6769 | 256 |
!GradientBackground class methodsFor:'queries'! |
257 |
||
258 |
possibleDirections |
|
259 |
^ #(#'northSouth' #'eastWest' ) |
|
260 |
! ! |
|
261 |
||
5684 | 262 |
!GradientBackground methodsFor:'accessing'! |
263 |
||
264 |
color1 |
|
6966 | 265 |
^ colors at:1 |
5684 | 266 |
|
267 |
"Created: / 23-01-2011 / 02:01:29 / cg" |
|
268 |
! |
|
269 |
||
270 |
color1:aColor |
|
6966 | 271 |
colors isNil ifTrue:[ |
272 |
colors := Array new:2. |
|
273 |
]. |
|
274 |
colors at:1 put:aColor. |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
275 |
cachedForm := nil. |
5684 | 276 |
|
277 |
"Created: / 23-01-2011 / 02:01:50 / cg" |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
278 |
"Modified: / 03-02-2011 / 19:49:18 / cg" |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
279 |
! |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
280 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
281 |
color1:aColor1 color2:aColor2 |
6966 | 282 |
colors isNil ifTrue:[ |
283 |
colors := Array new:2 |
|
284 |
]. |
|
285 |
colors at:1 put:aColor1. |
|
286 |
colors at:2 put:aColor2. |
|
287 |
cachedForm := nil. |
|
288 |
||
289 |
"Created: / 03-02-2011 / 19:52:59 / cg" |
|
290 |
! |
|
291 |
||
292 |
color1:aColor1 color2:aColor2 color3:aColor3 |
|
293 |
colors isNil ifTrue:[ |
|
294 |
colors := Array new:3 |
|
295 |
]. |
|
296 |
colors at:1 put:aColor1. |
|
297 |
colors at:2 put:aColor2. |
|
298 |
colors at:3 put:aColor3. |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
299 |
cachedForm := nil. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
300 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
301 |
"Created: / 03-02-2011 / 19:52:59 / cg" |
5684 | 302 |
! |
303 |
||
304 |
color2 |
|
6966 | 305 |
^ colors at:2 |
5684 | 306 |
|
307 |
"Created: / 23-01-2011 / 02:01:32 / cg" |
|
308 |
! |
|
309 |
||
310 |
color2:aColor |
|
6966 | 311 |
colors isNil ifTrue:[ |
312 |
colors := Array new:2. |
|
313 |
]. |
|
314 |
colors at:2 put:aColor. |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
315 |
cachedForm := nil. |
5684 | 316 |
|
6966 | 317 |
"Created: / 23-01-2011 / 02:01:50 / cg" |
318 |
"Modified: / 03-02-2011 / 19:49:18 / cg" |
|
319 |
! |
|
320 |
||
321 |
color3 |
|
322 |
^ colors at:3 ifAbsent:[nil] |
|
323 |
! |
|
324 |
||
325 |
color3:aColor |
|
326 |
colors isNil ifTrue:[ |
|
327 |
colors := Array new:3. |
|
328 |
] ifFalse:[ |
|
329 |
colors size < 3 ifTrue:[ |
|
330 |
colors := (Array new:3) replaceFrom:1 with:colors; yourself |
|
331 |
]. |
|
332 |
]. |
|
333 |
colors at:3 put:aColor. |
|
334 |
cachedForm := nil. |
|
335 |
||
336 |
"Created: / 23-01-2011 / 02:01:50 / cg" |
|
337 |
"Modified: / 03-02-2011 / 19:49:18 / cg" |
|
338 |
! |
|
339 |
||
340 |
colors:aColorVector |
|
341 |
colors := aColorVector. |
|
342 |
cachedForm := nil. |
|
5688 | 343 |
! |
344 |
||
345 |
direction |
|
346 |
"possible values: |
|
347 |
#northSouth |
|
348 |
#eastWest |
|
349 |
||
350 |
others are not yet supported |
|
351 |
" |
|
352 |
||
6966 | 353 |
(direction == #eastWest or:[direction == #horizontal]) ifTrue:[^ #eastWest]. |
354 |
^ #northSouth |
|
5688 | 355 |
|
356 |
"Modified: / 23-01-2011 / 14:36:36 / cg" |
|
357 |
! |
|
358 |
||
359 |
direction:something |
|
360 |
"possible values: |
|
361 |
#northSouth |
|
362 |
#eastWest |
|
363 |
||
364 |
others are not yet supported |
|
365 |
" |
|
366 |
||
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
367 |
direction ~= something ifTrue:[ |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
368 |
direction := something. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
369 |
cachedForm := nil. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
370 |
] |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
371 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
372 |
"Modified: / 03-02-2011 / 19:49:41 / cg" |
5738 | 373 |
! |
374 |
||
375 |
usedLength |
|
376 |
^ usedLength |
|
377 |
! |
|
378 |
||
6966 | 379 |
usedLength:nilOrSymbolOrNumber |
380 |
"specify: |
|
381 |
nil: use the screen height and interpolate gradient along that |
|
382 |
#view: use the view's height and interpolate gradient along that |
|
383 |
<integer>: interpolate from 0..n, with color2 above that. |
|
384 |
See examples on how each looks" |
|
385 |
||
386 |
nilOrSymbolOrNumber == #full ifTrue:[ |
|
387 |
"/ backw. compat. |
|
388 |
usedLength := #view |
|
389 |
] ifFalse:[ |
|
390 |
usedLength := nilOrSymbolOrNumber. |
|
391 |
] |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
392 |
! ! |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
393 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
394 |
!GradientBackground methodsFor:'converting'! |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
395 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
396 |
asFormOn:aDevice |
6014 | 397 |
|h w len| |
398 |
||
6966 | 399 |
"/ usedLength == #view ifTrue:[ |
6953 | 400 |
"/ self halt:'unsupported'. |
401 |
"/ ^ nil |
|
402 |
"/ ]. |
|
5688 | 403 |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
404 |
cachedForm isNil ifTrue:[ |
6966 | 405 |
(len := usedLength) == #view ifTrue:[ |
6014 | 406 |
len := nil |
407 |
]. |
|
6966 | 408 |
(self direction == #northSouth) ifTrue:[ |
6202
020ebdb99a1e
Replace references to Diplay with "Screen current" - where appropriate
Stefan Vogel <sv@exept.de>
parents:
6102
diff
changeset
|
409 |
h := len ? (aDevice height). "/ aView height. |
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
410 |
w := 8. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
411 |
] ifFalse:[ |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
412 |
h := 8. |
6202
020ebdb99a1e
Replace references to Diplay with "Screen current" - where appropriate
Stefan Vogel <sv@exept.de>
parents:
6102
diff
changeset
|
413 |
w := len ? (aDevice width). "/ aView width. |
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
414 |
]. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
415 |
cachedForm := Form width:w height:h depth:aDevice depth onDevice:aDevice. |
7359 | 416 |
cachedForm isNil ifTrue:[^nil]. |
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
417 |
"/ cachedForm clear. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
418 |
self fillRectangleX:0 y:0 width:w height:h in:cachedForm |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
419 |
]. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
420 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
421 |
^ cachedForm |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
422 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
423 |
"Created: / 03-02-2011 / 20:05:30 / cg" |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
424 |
! |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
425 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
426 |
onDevice:device |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
427 |
^ self asFormOn:device. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
428 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
429 |
"Created: / 03-02-2011 / 19:56:06 / cg" |
5684 | 430 |
! ! |
431 |
||
432 |
!GradientBackground methodsFor:'drawing'! |
|
433 |
||
6966 | 434 |
fillRectangleX:x y:y width:w height:h in:aGC |
7934 | 435 |
"fill a rectangular area in aGC with a color gradient through colors (yes, more than 2 are possible). |
436 |
This is a first (very inefficient) try; |
|
437 |
as it is (currently) only used for some splash-screens and in |
|
438 |
expecco's demo mode, we don't really care for much performance (yet)" |
|
5684 | 439 |
|
6966 | 440 |
|hHalf wHalf h1 h2 w1 w2 usedHeight usedWidth scaleStartX scaleStartY x2 y2 |
441 |
usedHeight2 usedWidth2 scaleStartX2 scaleStartY2 direction numSegs |
|
442 |
usedHeightRange usedWidthRange usedRange startPos endPos |
|
443 |
partRange segOffset segNr pos |
|
444 |
r1 r2 g1 g2 b1 b2 minR maxR minG maxG minB maxB color1 color2 |
|
445 |
dR dG dB r g b lastR lastG lastB endPart posRect szRun restSize| |
|
446 |
||
447 |
direction := self direction. |
|
448 |
||
449 |
usedLength isNil ifTrue:[ |
|
450 |
"/ use screen's height; so the gradient changes when the bounds are moved |
|
451 |
usedHeightRange := aGC device height. "/ aView height. |
|
452 |
usedWidthRange := aGC device width. "/ aView width. |
|
453 |
] ifFalse:[ |
|
454 |
usedLength == #view ifTrue:[ |
|
455 |
usedHeightRange := aGC height. |
|
456 |
usedWidthRange := aGC width. |
|
6014 | 457 |
] ifFalse:[ |
6966 | 458 |
usedHeightRange := usedLength. |
459 |
usedWidthRange := usedLength. |
|
460 |
]. |
|
461 |
]. |
|
462 |
direction == #northSouth ifTrue:[ |
|
463 |
usedRange := usedHeightRange. |
|
464 |
startPos := y. |
|
465 |
endPos := y+h. |
|
5739
c4fbd37a6164
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5738
diff
changeset
|
466 |
] ifFalse:[ |
6966 | 467 |
usedRange := usedWidthRange. |
468 |
startPos := x. |
|
469 |
endPos := x+w. |
|
5739
c4fbd37a6164
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5738
diff
changeset
|
470 |
]. |
6966 | 471 |
|
472 |
"/ each part |
|
473 |
numSegs := colors size - 1. |
|
474 |
partRange := (usedRange / numSegs) asFloat. |
|
5684 | 475 |
|
6966 | 476 |
"/ where is the start? |
477 |
segOffset := startPos \\ partRange. |
|
478 |
segNr := startPos // partRange + 1. |
|
479 |
||
480 |
pos := startPos. |
|
481 |
[pos < endPos] whileTrue:[ |
|
482 |
segNr > numSegs ifTrue:[ |
|
483 |
restSize := endPos - pos. |
|
484 |
aGC paint:(colors last). |
|
485 |
||
486 |
direction == #northSouth ifTrue:[ |
|
487 |
aGC fillRectangleX:x y:pos width:w height:restSize. |
|
488 |
] ifFalse:[ |
|
489 |
aGC fillRectangleX:pos y:y width:restSize height:h. |
|
490 |
]. |
|
491 |
^ self |
|
492 |
]. |
|
493 |
||
494 |
"/ we have to interpolate between those two colors |
|
495 |
color1 := colors at:segNr. |
|
496 |
color2 := colors at:segNr+1. |
|
497 |
||
498 |
r1 := color1 redByte. r2 := color2 redByte. |
|
499 |
g1 := color1 greenByte. g2 := color2 greenByte. |
|
500 |
b1 := color1 blueByte. b2 := color2 blueByte. |
|
5728
c3c7f362b4c3
changed: #fillRectangleX:y:width:height:in:
Stefan Vogel <sv@exept.de>
parents:
5705
diff
changeset
|
501 |
|
6966 | 502 |
minR := r1 min:r2. maxR := r1 max:r2. |
503 |
minG := g1 min:g2. maxG := g1 max:g2. |
|
504 |
minB := b1 min:b2. maxB := b1 max:b2. |
|
505 |
||
506 |
dR := (r2 - r1) / partRange. dG := (g2 - g1) / partRange. dB := (b2 - b1) / partRange. |
|
507 |
r := r1 + (dR * segOffset). |
|
508 |
g := g1 + (dG * segOffset). |
|
509 |
b := b1 + (dB * segOffset). |
|
5733
08e2b386abef
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
510 |
|
5732
fba4327a852b
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5731
diff
changeset
|
511 |
r := (r max:minR) min:maxR. |
fba4327a852b
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5731
diff
changeset
|
512 |
g := (g max:minG) min:maxG. |
fba4327a852b
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5731
diff
changeset
|
513 |
b := (b max:minB) min:maxB. |
5684 | 514 |
|
5733
08e2b386abef
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
515 |
lastR := r asInteger. lastG := g asInteger. lastB := b asInteger. |
6966 | 516 |
|
517 |
"/ now draw |
|
518 |
endPart := (startPos + partRange) truncated min:endPos. |
|
519 |
posRect := pos. |
|
520 |
szRun := 0. |
|
521 |
pos to:endPart-1 do:[:p | |
|
522 |
|rC gC bC| |
|
523 |
||
524 |
rC := r asInteger. gC := g asInteger. bC := b asInteger. |
|
5684 | 525 |
(rC ~~ lastR or:[gC ~~ lastG or:[bC ~~ lastB]]) ifTrue:[ |
6966 | 526 |
aGC paint:(Color redByte:lastR greenByte:lastG blueByte:lastB). |
527 |
direction == #northSouth ifTrue:[ |
|
528 |
aGC fillRectangleX:x y:posRect width:w height:szRun. |
|
529 |
] ifFalse:[ |
|
530 |
aGC fillRectangleX:posRect y:y width:szRun height:h. |
|
531 |
]. |
|
532 |
posRect := p. szRun := 0. |
|
5684 | 533 |
lastR := rC. lastG := gC. lastB := bC. |
534 |
]. |
|
6966 | 535 |
szRun := szRun + 1. |
5731
e638acae4e19
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5730
diff
changeset
|
536 |
r := ((r + dR) max:minR) min:maxR. |
e638acae4e19
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5730
diff
changeset
|
537 |
g := ((g + dG) max:minG) min:maxG. |
e638acae4e19
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5730
diff
changeset
|
538 |
b := ((b + dB) max:minB) min:maxB. |
5684 | 539 |
]. |
6966 | 540 |
szRun ~~ 0 ifTrue:[ |
541 |
aGC paint:(Color redByte:lastR greenByte:lastG blueByte:lastB). |
|
542 |
direction == #northSouth ifTrue:[ |
|
543 |
aGC fillRectangleX:x y:posRect width:w height:szRun. |
|
544 |
] ifFalse:[ |
|
545 |
aGC fillRectangleX:posRect y:y width:szRun height:h. |
|
546 |
]. |
|
5733
08e2b386abef
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5732
diff
changeset
|
547 |
]. |
6966 | 548 |
"/ self halt. |
549 |
"/ drawn one segment's gradient |
|
550 |
segOffset := 0. |
|
551 |
pos := startPos := endPart. |
|
552 |
segNr := segNr + 1. |
|
5688 | 553 |
]. |
7934 | 554 |
|
555 |
"Modified (comment): / 22-02-2017 / 21:09:03 / cg" |
|
5684 | 556 |
! ! |
557 |
||
6953 | 558 |
!GradientBackground methodsFor:'queries'! |
559 |
||
560 |
needsFullRedrawOnChangeOfHeight |
|
6966 | 561 |
^ usedLength == #view and:[self direction == #northSouth] |
6953 | 562 |
! |
563 |
||
564 |
needsFullRedrawOnChangeOfWidth |
|
6966 | 565 |
^ usedLength == #view and:[direction == #eastWest] |
6953 | 566 |
! ! |
567 |
||
5461 | 568 |
!GradientBackground class methodsFor:'documentation'! |
569 |
||
6014 | 570 |
version |
6953 | 571 |
^ '$Header$' |
6014 | 572 |
! |
573 |
||
5461 | 574 |
version_CVS |
6953 | 575 |
^ '$Header$' |
5461 | 576 |
! ! |
6013 | 577 |