author | Stefan Vogel <sv@exept.de> |
Fri, 04 Mar 2011 17:09:07 +0100 | |
changeset 5728 | c3c7f362b4c3 |
parent 5705 | 56318de85b68 |
child 5730 | 74d4e149580b |
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 |
||
14 |
AbstractBackground subclass:#GradientBackground |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
15 |
instanceVariableNames:'color1 color2 direction cachedForm usedLength' |
5461 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Graphics-Support' |
|
19 |
! |
|
20 |
||
21 |
!GradientBackground class methodsFor:'documentation'! |
|
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 2009 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
35 |
! |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
36 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
37 |
examples |
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 |
|bg v| |
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 |
bg := GradientBackground new color1:Color red color2:Color yellow. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
42 |
v := View new extent:300@300. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
43 |
v viewBackground:bg. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
44 |
v open. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
45 |
" |
5461 | 46 |
! ! |
47 |
||
5684 | 48 |
!GradientBackground methodsFor:'accessing'! |
49 |
||
50 |
color1 |
|
51 |
^ color1 |
|
52 |
||
53 |
"Created: / 23-01-2011 / 02:01:29 / cg" |
|
54 |
! |
|
55 |
||
56 |
color1:aColor |
|
57 |
color1 := aColor. |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
58 |
cachedForm := nil. |
5684 | 59 |
|
60 |
"Created: / 23-01-2011 / 02:01:50 / cg" |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
61 |
"Modified: / 03-02-2011 / 19:49:18 / cg" |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
62 |
! |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
63 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
64 |
color1:aColor1 color2:aColor2 |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
65 |
color1 := aColor1. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
66 |
color2 := aColor2. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
67 |
cachedForm := nil. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
68 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
69 |
"Created: / 03-02-2011 / 19:52:59 / cg" |
5684 | 70 |
! |
71 |
||
72 |
color2 |
|
73 |
^ color2 |
|
74 |
||
75 |
"Created: / 23-01-2011 / 02:01:32 / cg" |
|
76 |
! |
|
77 |
||
78 |
color2:aColor |
|
79 |
color2 := aColor. |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
80 |
cachedForm := nil. |
5684 | 81 |
|
82 |
"Created: / 23-01-2011 / 02:01:55 / cg" |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
83 |
"Modified: / 03-02-2011 / 19:49:23 / cg" |
5688 | 84 |
! |
85 |
||
86 |
direction |
|
87 |
"possible values: |
|
88 |
#northSouth |
|
89 |
#eastWest |
|
90 |
||
91 |
others are not yet supported |
|
92 |
" |
|
93 |
||
94 |
^ direction |
|
95 |
||
96 |
"Modified: / 23-01-2011 / 14:36:36 / cg" |
|
97 |
! |
|
98 |
||
99 |
direction:something |
|
100 |
"possible values: |
|
101 |
#northSouth |
|
102 |
#eastWest |
|
103 |
||
104 |
others are not yet supported |
|
105 |
" |
|
106 |
||
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
107 |
direction ~= something ifTrue:[ |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
108 |
direction := something. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
109 |
cachedForm := nil. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
110 |
] |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
111 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
112 |
"Modified: / 03-02-2011 / 19:49:41 / cg" |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
113 |
! ! |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
114 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
115 |
!GradientBackground methodsFor:'converting'! |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
116 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
117 |
asFormOn:aDevice |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
118 |
|h w| |
5688 | 119 |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
120 |
cachedForm isNil ifTrue:[ |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
121 |
(direction == #northSouth or:[direction == nil]) ifTrue:[ |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
122 |
h := usedLength ? (Display height). "/ aView height. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
123 |
w := 8. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
124 |
] ifFalse:[ |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
125 |
h := 8. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
126 |
w := usedLength ? (Display width). "/ aView width. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
127 |
]. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
128 |
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
|
129 |
"/ cachedForm clear. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
130 |
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
|
131 |
]. |
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 |
^ cachedForm |
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 |
"Created: / 03-02-2011 / 20:05:30 / cg" |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
136 |
! |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
137 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
138 |
onDevice:device |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
139 |
^ self asFormOn:device. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
140 |
|
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
141 |
"Created: / 03-02-2011 / 19:56:06 / cg" |
5684 | 142 |
! ! |
143 |
||
144 |
!GradientBackground methodsFor:'drawing'! |
|
145 |
||
146 |
fillRectangleX:x y:y width:w height:h in:aView |
|
147 |
"this is a first (very inefficient) try" |
|
148 |
||
5688 | 149 |
|hAll wAll r1 r2 g1 g2 b1 b2 dR r dG g dB b |
150 |
xRight yBot rC gC bC lastR lastG lastB| |
|
5687
d4ab14b6cf0a
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5684
diff
changeset
|
151 |
|
5688 | 152 |
"/ always take the full-screen as reference |
153 |
"/ (so we do not have to care for changed gradient, when view changes size) |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
154 |
hAll := usedLength ? (Display height). "/ aView height. |
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
155 |
wAll := usedLength ? (Display width). "/ aView width. |
5684 | 156 |
|
157 |
r1 := color1 redByte. |
|
158 |
r2 := color2 redByte. |
|
159 |
g1 := color1 greenByte. |
|
160 |
g2 := color2 greenByte. |
|
161 |
b1 := color1 blueByte. |
|
162 |
b2 := color2 blueByte. |
|
163 |
||
5728
c3c7f362b4c3
changed: #fillRectangleX:y:width:height:in:
Stefan Vogel <sv@exept.de>
parents:
5705
diff
changeset
|
164 |
aView lineStyle:#solid. |
c3c7f362b4c3
changed: #fillRectangleX:y:width:height:in:
Stefan Vogel <sv@exept.de>
parents:
5705
diff
changeset
|
165 |
|
5688 | 166 |
"/ individual lines; from top to bottom |
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
167 |
(direction == #northSouth or:[direction == #vertical or:[direction == nil]]) ifTrue:[ |
5687
d4ab14b6cf0a
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5684
diff
changeset
|
168 |
dR := (r2 - r1) / hAll. |
5684 | 169 |
r := r1 + (dR * y). |
5687
d4ab14b6cf0a
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5684
diff
changeset
|
170 |
dG := (g2 - g1) / hAll. |
5684 | 171 |
g := g1 + (dG * y). |
5687
d4ab14b6cf0a
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5684
diff
changeset
|
172 |
dB := (b2 - b1) / hAll. |
5684 | 173 |
b := b1 + (dB * y). |
174 |
||
175 |
xRight := x+w-1. |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
176 |
0 to:hAll-1 do:[:yP | |
5684 | 177 |
rC := r asInteger. |
178 |
gC := g asInteger. |
|
179 |
bC := b asInteger. |
|
180 |
(rC ~~ lastR or:[gC ~~ lastG or:[bC ~~ lastB]]) ifTrue:[ |
|
181 |
aView foreground:(Color redByte:rC greenByte:gC blueByte:bC). |
|
182 |
lastR := rC. lastG := gC. lastB := bC. |
|
183 |
]. |
|
5728
c3c7f362b4c3
changed: #fillRectangleX:y:width:height:in:
Stefan Vogel <sv@exept.de>
parents:
5705
diff
changeset
|
184 |
"xRight+1 since X11 does not show the last point of a line" |
c3c7f362b4c3
changed: #fillRectangleX:y:width:height:in:
Stefan Vogel <sv@exept.de>
parents:
5705
diff
changeset
|
185 |
aView displayLineFromX:x y:y+yP toX:xRight+1 y:y+yP. |
c3c7f362b4c3
changed: #fillRectangleX:y:width:height:in:
Stefan Vogel <sv@exept.de>
parents:
5705
diff
changeset
|
186 |
r := r + dR "used to do min:r2 here, but this does not work if r2 < r1 and dR is negative". |
c3c7f362b4c3
changed: #fillRectangleX:y:width:height:in:
Stefan Vogel <sv@exept.de>
parents:
5705
diff
changeset
|
187 |
g := g + dG . |
c3c7f362b4c3
changed: #fillRectangleX:y:width:height:in:
Stefan Vogel <sv@exept.de>
parents:
5705
diff
changeset
|
188 |
b := b + dB. |
5684 | 189 |
]. |
5728
c3c7f362b4c3
changed: #fillRectangleX:y:width:height:in:
Stefan Vogel <sv@exept.de>
parents:
5705
diff
changeset
|
190 |
aView fillRectangleX:x y:hAll-1 width:w height:(h-hAll+1). |
5688 | 191 |
^ self. |
192 |
]. |
|
193 |
||
194 |
"/ individual lines; from left to right |
|
195 |
(direction == #eastWest or:[direction == #horizontal]) ifTrue:[ |
|
196 |
dR := (r2 - r1) / wAll. |
|
197 |
r := r1 + (dR * y). |
|
198 |
dG := (g2 - g1) / wAll. |
|
199 |
g := g1 + (dG * y). |
|
200 |
dB := (b2 - b1) / wAll. |
|
201 |
b := b1 + (dB * y). |
|
202 |
||
203 |
yBot := y+h-1. |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
204 |
0 to:wAll-1 do:[:xP | |
5688 | 205 |
rC := r asInteger. |
206 |
gC := g asInteger. |
|
207 |
bC := b asInteger. |
|
208 |
(rC ~~ lastR or:[gC ~~ lastG or:[bC ~~ lastB]]) ifTrue:[ |
|
209 |
aView foreground:(Color redByte:rC greenByte:gC blueByte:bC). |
|
210 |
lastR := rC. lastG := gC. lastB := bC. |
|
211 |
]. |
|
5728
c3c7f362b4c3
changed: #fillRectangleX:y:width:height:in:
Stefan Vogel <sv@exept.de>
parents:
5705
diff
changeset
|
212 |
"yBot+1 since X11 does not show the last point of a line" |
c3c7f362b4c3
changed: #fillRectangleX:y:width:height:in:
Stefan Vogel <sv@exept.de>
parents:
5705
diff
changeset
|
213 |
aView displayLineFromX:x+xP y:y toX:x+xP y:yBot+1. |
c3c7f362b4c3
changed: #fillRectangleX:y:width:height:in:
Stefan Vogel <sv@exept.de>
parents:
5705
diff
changeset
|
214 |
r := r + dR. |
c3c7f362b4c3
changed: #fillRectangleX:y:width:height:in:
Stefan Vogel <sv@exept.de>
parents:
5705
diff
changeset
|
215 |
g := g + dG. |
c3c7f362b4c3
changed: #fillRectangleX:y:width:height:in:
Stefan Vogel <sv@exept.de>
parents:
5705
diff
changeset
|
216 |
b := b + dB. |
5688 | 217 |
]. |
5728
c3c7f362b4c3
changed: #fillRectangleX:y:width:height:in:
Stefan Vogel <sv@exept.de>
parents:
5705
diff
changeset
|
218 |
aView fillRectangleX:wAll y:y width:(w-wAll+1) height:h. |
5688 | 219 |
^ self. |
5684 | 220 |
] |
221 |
||
222 |
"Created: / 23-01-2011 / 01:59:29 / cg" |
|
5705
56318de85b68
comment/format in: #initializeAllPluginClasses
Claus Gittinger <cg@exept.de>
parents:
5692
diff
changeset
|
223 |
"Modified: / 03-02-2011 / 20:26:55 / cg" |
5684 | 224 |
! ! |
225 |
||
5461 | 226 |
!GradientBackground class methodsFor:'documentation'! |
227 |
||
228 |
version_CVS |
|
5728
c3c7f362b4c3
changed: #fillRectangleX:y:width:height:in:
Stefan Vogel <sv@exept.de>
parents:
5705
diff
changeset
|
229 |
^ '$Header: /cvs/stx/stx/libview/GradientBackground.st,v 1.7 2011-03-04 16:09:07 stefan Exp $' |
5461 | 230 |
! ! |