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