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