author | Claus Gittinger <cg@exept.de> |
Mon, 31 Jan 2011 17:29:00 +0100 | |
changeset 5692 | 3187401537b7 |
parent 5688 | 0fec2a60ad63 |
child 5705 | 56318de85b68 |
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 |
|
15 |
instanceVariableNames:'color1 color2 direction' |
|
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 |
" |
|
35 |
! ! |
|
36 |
||
5684 | 37 |
!GradientBackground methodsFor:'accessing'! |
38 |
||
39 |
color1 |
|
40 |
^ color1 |
|
41 |
||
42 |
"Created: / 23-01-2011 / 02:01:29 / cg" |
|
43 |
! |
|
44 |
||
45 |
color1:aColor |
|
46 |
color1 := aColor. |
|
47 |
||
48 |
"Created: / 23-01-2011 / 02:01:50 / cg" |
|
49 |
! |
|
50 |
||
51 |
color2 |
|
52 |
^ color2 |
|
53 |
||
54 |
"Created: / 23-01-2011 / 02:01:32 / cg" |
|
55 |
! |
|
56 |
||
57 |
color2:aColor |
|
58 |
color2 := aColor. |
|
59 |
||
60 |
"Created: / 23-01-2011 / 02:01:55 / cg" |
|
5688 | 61 |
! |
62 |
||
63 |
direction |
|
64 |
"possible values: |
|
65 |
#northSouth |
|
66 |
#eastWest |
|
67 |
||
68 |
others are not yet supported |
|
69 |
" |
|
70 |
||
71 |
^ direction |
|
72 |
||
73 |
"Modified: / 23-01-2011 / 14:36:36 / cg" |
|
74 |
! |
|
75 |
||
76 |
direction:something |
|
77 |
"possible values: |
|
78 |
#northSouth |
|
79 |
#eastWest |
|
80 |
||
81 |
others are not yet supported |
|
82 |
" |
|
83 |
||
84 |
direction := something. |
|
85 |
||
86 |
"Modified: / 23-01-2011 / 14:36:44 / cg" |
|
5684 | 87 |
! ! |
88 |
||
89 |
!GradientBackground methodsFor:'drawing'! |
|
90 |
||
91 |
fillRectangleX:x y:y width:w height:h in:aView |
|
92 |
"this is a first (very inefficient) try" |
|
93 |
||
5688 | 94 |
|hAll wAll r1 r2 g1 g2 b1 b2 dR r dG g dB b |
95 |
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
|
96 |
|
5688 | 97 |
"/ always take the full-screen as reference |
98 |
"/ (so we do not have to care for changed gradient, when view changes size) |
|
99 |
hAll := Display height. "/ aView height. |
|
100 |
wAll := Display width. "/ aView width. |
|
5684 | 101 |
|
102 |
r1 := color1 redByte. |
|
103 |
r2 := color2 redByte. |
|
104 |
g1 := color1 greenByte. |
|
105 |
g2 := color2 greenByte. |
|
106 |
b1 := color1 blueByte. |
|
107 |
b2 := color2 blueByte. |
|
108 |
||
5688 | 109 |
"/ individual lines; from top to bottom |
110 |
(direction == #northSouth or:[direction == #vertical]) ifTrue:[ |
|
5687
d4ab14b6cf0a
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5684
diff
changeset
|
111 |
dR := (r2 - r1) / hAll. |
5684 | 112 |
r := r1 + (dR * y). |
5687
d4ab14b6cf0a
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5684
diff
changeset
|
113 |
dG := (g2 - g1) / hAll. |
5684 | 114 |
g := g1 + (dG * y). |
5687
d4ab14b6cf0a
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5684
diff
changeset
|
115 |
dB := (b2 - b1) / hAll. |
5684 | 116 |
b := b1 + (dB * y). |
117 |
||
118 |
xRight := x+w-1. |
|
119 |
0 to:h-1 do:[:yP | |
|
120 |
rC := r asInteger. |
|
121 |
gC := g asInteger. |
|
122 |
bC := b asInteger. |
|
123 |
(rC ~~ lastR or:[gC ~~ lastG or:[bC ~~ lastB]]) ifTrue:[ |
|
124 |
aView foreground:(Color redByte:rC greenByte:gC blueByte:bC). |
|
125 |
lastR := rC. lastG := gC. lastB := bC. |
|
126 |
]. |
|
127 |
aView displayLineFromX:x y:y+yP toX:xRight y:y+yP. |
|
5692
3187401537b7
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5688
diff
changeset
|
128 |
r := (r + dR) min:r2. |
3187401537b7
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5688
diff
changeset
|
129 |
g := (g + dG) min:g2. |
3187401537b7
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5688
diff
changeset
|
130 |
b := (b + dB) min:b2. |
5684 | 131 |
]. |
5688 | 132 |
^ self. |
133 |
]. |
|
134 |
||
135 |
"/ individual lines; from left to right |
|
136 |
(direction == #eastWest or:[direction == #horizontal]) ifTrue:[ |
|
137 |
dR := (r2 - r1) / wAll. |
|
138 |
r := r1 + (dR * y). |
|
139 |
dG := (g2 - g1) / wAll. |
|
140 |
g := g1 + (dG * y). |
|
141 |
dB := (b2 - b1) / wAll. |
|
142 |
b := b1 + (dB * y). |
|
143 |
||
144 |
yBot := y+h-1. |
|
145 |
0 to:w-1 do:[:xP | |
|
146 |
rC := r asInteger. |
|
147 |
gC := g asInteger. |
|
148 |
bC := b asInteger. |
|
149 |
(rC ~~ lastR or:[gC ~~ lastG or:[bC ~~ lastB]]) ifTrue:[ |
|
150 |
aView foreground:(Color redByte:rC greenByte:gC blueByte:bC). |
|
151 |
lastR := rC. lastG := gC. lastB := bC. |
|
152 |
]. |
|
153 |
aView displayLineFromX:x+xP y:y toX:x+xP y:yBot. |
|
5692
3187401537b7
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5688
diff
changeset
|
154 |
r := (r + dR) min:r2. |
3187401537b7
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5688
diff
changeset
|
155 |
g := (g + dG) min:g2. |
3187401537b7
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5688
diff
changeset
|
156 |
b := (b + dB) min:b2. |
5688 | 157 |
]. |
158 |
^ self. |
|
5684 | 159 |
] |
160 |
||
161 |
"Created: / 23-01-2011 / 01:59:29 / cg" |
|
5692
3187401537b7
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5688
diff
changeset
|
162 |
"Modified: / 31-01-2011 / 17:28:53 / cg" |
5684 | 163 |
! ! |
164 |
||
5461 | 165 |
!GradientBackground class methodsFor:'documentation'! |
166 |
||
167 |
version_CVS |
|
5692
3187401537b7
changed: #fillRectangleX:y:width:height:in:
Claus Gittinger <cg@exept.de>
parents:
5688
diff
changeset
|
168 |
^ '$Header: /cvs/stx/stx/libview/GradientBackground.st,v 1.5 2011-01-31 16:29:00 cg Exp $' |
5461 | 169 |
! ! |