]>
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
)
238 PlanarSurface
*sp
= &l
->surface
.data
.planar
;
239 int left
= x
, top
= y
, right
= w
- 1, bottom
= h
- 1;
241 if (sp
->primary
->gc
== None
)
242 color_allocate_gc(sp
->primary
);
243 pix
= (sp
->primary
->r
<< default_red_shift
)
244 + (sp
->primary
->g
<< default_green_shift
)
245 + (sp
->primary
->b
<< default_blue_shift
);
247 for (a
= 0; a
< l
->area
.width
; a
++)
248 for (b
= 0; b
< l
->area
.height
; b
++)
249 sp
->pixel_data
[a
+ b
*l
->area
.width
] = pix
;
251 XFillRectangle(ob_display
, l
->pixmap
, sp
->primary
->gc
254 if (l
->surface
.data
.planar
.interlaced
) {
255 if (sp
->secondary
->gc
== None
)
256 color_allocate_gc(sp
->secondary
);
257 for (i
= y
; i
< h
; i
+= 2)
258 XDrawLine(ob_display
, l
->pixmap
, sp
->secondary
->gc
,
262 switch (texture.relief()) {
263 case RenderTexture::Raised:
264 switch (texture.bevel()) {
265 case RenderTexture::Bevel1:
266 XDrawLine(ob_display, l->pixmap, texture.bevelDarkColor().gc(),
267 left, bottom, right, bottom);
268 XDrawLine(ob_display, l->pixmap, texture.bevelDarkColor().gc(),
269 right, bottom, right, top);
271 XDrawLine(ob_display, l->pixmap, texture.bevelLightColor().gc(),
272 left, top, right, top);
273 XDrawLine(ob_display, l->pixmap, texture.bevelLightColor().gc(),
274 left, bottom, left, top);
276 case RenderTexture::Bevel2:
277 XDrawLine(ob_display, l->pixmap, texture.bevelDarkColor().gc(),
278 left + 1, bottom - 2, right - 2, bottom - 2);
279 XDrawLine(ob_display, l->pixmap, texture.bevelDarkColor().gc(),
280 right - 2, bottom - 2, right - 2, top + 1);
282 XDrawLine(ob_display, l->pixmap, texture.bevelLightColor().gc(),
283 left + 1, top + 1, right - 2, top + 1);
284 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
285 left + 1, bottom - 2, left + 1, top + 1);
288 assert(false); // unhandled RenderTexture::BevelType
291 case RenderTexture::Sunken:
292 switch (texture.bevel()) {
293 case RenderTexture::Bevel1:
294 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
295 left, bottom, right, bottom);
296 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
297 right, bottom, right, top);
299 XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
300 left, top, right, top);
301 XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
302 left, bottom, left, top);
304 case RenderTexture::Bevel2:
305 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
306 left + 1, bottom - 2, right - 2, bottom - 2);
307 XDrawLine(**display, sf.pixmap(), texture.bevelLightColor().gc(),
308 right - 2, bottom - 2, right - 2, top + 1);
310 XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
311 left + 1, top + 1, right - 2, top + 1);
312 XDrawLine(**display, sf.pixmap(), texture.bevelDarkColor().gc(),
313 left + 1, bottom - 2, left + 1, top + 1);
317 assert(false); // unhandled RenderTexture::BevelType
320 case RenderTexture::Flat:
321 if (texture.border())
322 XDrawRectangle(**display, sf.pixmap(), texture.borderColor().gc(),
323 left, top, right, bottom);
326 assert(false); // unhandled RenderTexture::ReliefType
This page took 0.05173 seconds and 4 git commands to generate.