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