]>
Dogcows Code - chaz/openbox/blob - render/gradient.c
4 #include "../kernel/openbox.h"
7 void gradient_render(Surface
*sf
, int w
, int h
)
9 pixel32
*data
= sf
->data
.planar
.pixel_data
;
14 switch (sf
->data
.planar
.grad
) {
15 case Background_Solid
: /* already handled */
17 case Background_Vertical
:
18 gradient_vertical(sf
, w
, h
);
20 case Background_Horizontal
:
21 gradient_horizontal(sf
, w
, h
);
23 case Background_Diagonal
:
24 gradient_diagonal(sf
, w
, h
);
26 case Background_CrossDiagonal
:
27 gradient_crossdiagonal(sf
, w
, h
);
30 g_message("unhandled gradient");
34 if (sf
->data
.planar
.relief
== Flat
&& sf
->data
.planar
.border
) {
35 r
= sf
->data
.planar
.border_color
->r
;
36 g
= sf
->data
.planar
.border_color
->g
;
37 b
= sf
->data
.planar
.border_color
->b
;
38 current
= (r
<< default_red_shift
)
39 + (g
<< default_green_shift
)
40 + (b
<< default_blue_shift
);
41 for (off
= 0, x
= 0; x
< w
; ++x
, off
++) {
42 *(data
+ off
) = current
;
43 *(data
+ off
+ ((h
-1) * w
)) = current
;
45 for (off
= 0, x
= 0; x
< h
; ++x
, off
++) {
46 *(data
+ (off
* w
)) = current
;
47 *(data
+ (off
* w
) + w
- 1) = current
;
51 if (sf
->data
.planar
.relief
!= Flat
) {
52 if (sf
->data
.planar
.bevel
== Bevel1
) {
53 for (off
= 1, x
= 1; x
< w
- 1; ++x
, off
++)
55 data
+ off
+ (h
-1) * w
,
56 sf
->data
.planar
.relief
==Raised
);
57 for (off
= 0, x
= 0; x
< h
; ++x
, off
++)
58 highlight(data
+ off
* w
,
59 data
+ off
* w
+ w
- 1,
60 sf
->data
.planar
.relief
==Raised
);
63 if (sf
->data
.planar
.bevel
== Bevel2
) {
64 for (off
= 2, x
= 2; x
< w
- 2; ++x
, off
++)
65 highlight(data
+ off
+ w
,
66 data
+ off
+ (h
-2) * w
,
67 sf
->data
.planar
.relief
==Raised
);
68 for (off
= 1, x
= 1; x
< h
-1; ++x
, off
++)
69 highlight(data
+ off
* w
+ 1,
70 data
+ off
* w
+ w
- 2,
71 sf
->data
.planar
.relief
==Raised
);
78 void gradient_vertical(Surface
*sf
, int w
, int h
)
80 pixel32
*data
= sf
->data
.planar
.pixel_data
;
86 dr
= (float)(sf
->data
.planar
.secondary
->r
- sf
->data
.planar
.primary
->r
);
89 dg
= (float)(sf
->data
.planar
.secondary
->g
- sf
->data
.planar
.primary
->g
);
92 db
= (float)(sf
->data
.planar
.secondary
->b
- sf
->data
.planar
.primary
->b
);
95 for (y
= 0; y
< h
; ++y
) {
96 r
= sf
->data
.planar
.primary
->r
+ (int)(dr
* y
);
97 g
= sf
->data
.planar
.primary
->g
+ (int)(dg
* y
);
98 b
= sf
->data
.planar
.primary
->b
+ (int)(db
* y
);
99 current
= (r
<< default_red_shift
)
100 + (g
<< default_green_shift
)
101 + (b
<< default_blue_shift
);
102 for (x
= 0; x
< w
; ++x
, ++data
)
107 void gradient_horizontal(Surface
*sf
, int w
, int h
)
109 pixel32
*data
= sf
->data
.planar
.pixel_data
;
115 dr
= (float)(sf
->data
.planar
.secondary
->r
- sf
->data
.planar
.primary
->r
);
118 dg
= (float)(sf
->data
.planar
.secondary
->g
- sf
->data
.planar
.primary
->g
);
121 db
= (float)(sf
->data
.planar
.secondary
->b
- sf
->data
.planar
.primary
->b
);
124 for (x
= 0; x
< w
; ++x
, ++data
) {
125 r
= sf
->data
.planar
.primary
->r
+ (int)(dr
* x
);
126 g
= sf
->data
.planar
.primary
->g
+ (int)(dg
* x
);
127 b
= sf
->data
.planar
.primary
->b
+ (int)(db
* x
);
128 current
= (r
<< default_red_shift
)
129 + (g
<< default_green_shift
)
130 + (b
<< default_blue_shift
);
131 for (y
= 0; y
< h
; ++y
)
132 *(data
+ y
*w
) = current
;
136 void gradient_diagonal(Surface
*sf
, int w
, int h
)
138 pixel32
*data
= sf
->data
.planar
.pixel_data
;
140 float drx
, dgx
, dbx
, dry
, dgy
, dby
;
144 for (y
= 0; y
< h
; ++y
) {
145 drx
= (float)(sf
->data
.planar
.secondary
->r
- sf
->data
.planar
.primary
->r
);
149 dgx
= (float)(sf
->data
.planar
.secondary
->g
- sf
->data
.planar
.primary
->g
);
153 dbx
= (float)(sf
->data
.planar
.secondary
->b
- sf
->data
.planar
.primary
->b
);
156 for (x
= 0; x
< w
; ++x
, ++data
) {
157 r
= sf
->data
.planar
.primary
->r
+ ((int)(drx
* x
) + (int)(dry
* y
))/2;
158 g
= sf
->data
.planar
.primary
->g
+ ((int)(dgx
* x
) + (int)(dgy
* y
))/2;
159 b
= sf
->data
.planar
.primary
->b
+ ((int)(dbx
* x
) + (int)(dby
* y
))/2;
160 current
= (r
<< default_red_shift
)
161 + (g
<< default_green_shift
)
162 + (b
<< default_blue_shift
);
168 void gradient_crossdiagonal(Surface
*sf
, int w
, int h
)
170 pixel32
*data
= sf
->data
.planar
.pixel_data
;
172 float drx
, dgx
, dbx
, dry
, dgy
, dby
;
176 for (y
= 0; y
< h
; ++y
) {
177 drx
= (float)(sf
->data
.planar
.secondary
->r
- sf
->data
.planar
.primary
->r
);
181 dgx
= (float)(sf
->data
.planar
.secondary
->g
- sf
->data
.planar
.primary
->g
);
185 dbx
= (float)(sf
->data
.planar
.secondary
->b
- sf
->data
.planar
.primary
->b
);
188 for (x
= w
; x
> 0; --x
, ++data
) {
189 r
= sf
->data
.planar
.primary
->r
+ ((int)(drx
* (x
-1)) + (int)(dry
* y
))/2;
190 g
= sf
->data
.planar
.primary
->g
+ ((int)(dgx
* (x
-1)) + (int)(dgy
* y
))/2;
191 b
= sf
->data
.planar
.primary
->b
+ ((int)(dbx
* (x
-1)) + (int)(dby
* y
))/2;
192 current
= (r
<< default_red_shift
)
193 + (g
<< default_green_shift
)
194 + (b
<< default_blue_shift
);
200 void highlight(pixel32
*x
, pixel32
*y
, gboolean raised
)
212 r
= (*up
>> default_red_shift
) & 0xFF;
214 g
= (*up
>> default_green_shift
) & 0xFF;
216 b
= (*up
>> default_blue_shift
) & 0xFF;
218 if (r
> 255) r
= 255;
219 if (g
> 255) g
= 255;
220 if (b
> 255) b
= 255;
221 *up
= (r
<< default_red_shift
) + (g
<< default_green_shift
)
222 + (b
<< default_blue_shift
);
224 r
= (*down
>> default_red_shift
) & 0xFF;
225 r
= (r
>> 1) + (r
>> 2);
226 g
= (*down
>> default_green_shift
) & 0xFF;
227 g
= (g
>> 1) + (g
>> 2);
228 b
= (*down
>> default_blue_shift
) & 0xFF;
229 b
= (b
>> 1) + (b
>> 2);
230 *down
= (r
<< default_red_shift
) + (g
<< default_green_shift
)
231 + (b
<< default_blue_shift
);
234 void gradient_solid(Appearance
*l
, int x
, int y
, int w
, int h
)
237 PlanarSurface
*sp
= &l
->surface
.data
.planar
;
238 int left
= x
, top
= y
, right
= w
- 1, bottom
= h
- 1;
240 if (sp
->primary
->gc
== None
)
241 color_allocate_gc(sp
->primary
);
242 XFillRectangle(ob_display
, l
->pixmap
, sp
->primary
->gc
245 if (l
->surface
.data
.planar
.interlaced
) {
246 if (sp
->secondary
->gc
== None
)
247 color_allocate_gc(sp
->secondary
);
248 for (i
= y
; i
< h
; i
+= 2)
249 XDrawLine(ob_display
, l
->pixmap
, sp
->secondary
->gc
,
253 switch (texture.relief()) {
254 case RenderTexture::Raised:
255 switch (texture.bevel()) {
256 case RenderTexture::Bevel1:
257 XDrawLine(ob_display, l->pixmap, texture.bevelDarkColor().gc(),
258 left, bottom, right, bottom);
259 XDrawLine(ob_display, l->pixmap, texture.bevelDarkColor().gc(),
260 right, bottom, right, top);
262 XDrawLine(ob_display, l->pixmap, texture.bevelLightColor().gc(),
263 left, top, right, top);
264 XDrawLine(ob_display, l->pixmap, texture.bevelLightColor().gc(),
265 left, bottom, left, top);
267 case RenderTexture::Bevel2:
268 XDrawLine(ob_display, l->pixmap, texture.bevelDarkColor().gc(),
269 left + 1, bottom - 2, right - 2, bottom - 2);
270 XDrawLine(ob_display, l->pixmap, texture.bevelDarkColor().gc(),
271 right - 2, bottom - 2, right - 2, top + 1);
273 XDrawLine(ob_display, l->pixmap, texture.bevelLightColor().gc(),
274 left + 1, top + 1, right - 2, top + 1);
275 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
276 left + 1, bottom - 2, left + 1, top + 1);
279 assert(false); // unhandled RenderTexture::BevelType
282 case RenderTexture::Sunken:
283 switch (texture.bevel()) {
284 case RenderTexture::Bevel1:
285 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
286 left, bottom, right, bottom);
287 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
288 right, bottom, right, top);
290 XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
291 left, top, right, top);
292 XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
293 left, bottom, left, top);
295 case RenderTexture::Bevel2:
296 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
297 left + 1, bottom - 2, right - 2, bottom - 2);
298 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
299 right - 2, bottom - 2, right - 2, top + 1);
301 XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
302 left + 1, top + 1, right - 2, top + 1);
303 XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
304 left + 1, bottom - 2, left + 1, top + 1);
308 assert(false); // unhandled RenderTexture::BevelType
311 case RenderTexture::Flat:
312 if (texture.border())
313 XDrawRectangle(**display, sf.pixmap(), texture.borderColor().gc(),
314 left, top, right, bottom);
317 assert(false); // unhandled RenderTexture::ReliefType
This page took 0.053278 seconds and 4 git commands to generate.