6 static void highlight(RrPixel32
*x
, RrPixel32
*y
, gboolean raised
);
7 static void gradient_solid(RrAppearance
*l
, int w
, int h
);
8 static void gradient_vertical(RrSurface
*sf
, int w
, int h
);
9 static void gradient_horizontal(RrSurface
*sf
, int w
, int h
);
10 static void gradient_diagonal(RrSurface
*sf
, int w
, int h
);
11 static void gradient_crossdiagonal(RrSurface
*sf
, int w
, int h
);
12 static void gradient_pyramid(RrSurface
*sf
, int inw
, int inh
);
14 void RrRender(RrAppearance
*a
, int w
, int h
)
16 RrPixel32
*data
= a
->surface
.pixel_data
;
21 switch (a
->surface
.grad
) {
22 case RR_SURFACE_SOLID
:
23 gradient_solid(a
, w
, h
);
25 case RR_SURFACE_VERTICAL
:
26 gradient_vertical(&a
->surface
, w
, h
);
28 case RR_SURFACE_HORIZONTAL
:
29 gradient_horizontal(&a
->surface
, w
, h
);
31 case RR_SURFACE_DIAGONAL
:
32 gradient_diagonal(&a
->surface
, w
, h
);
34 case RR_SURFACE_CROSS_DIAGONAL
:
35 gradient_crossdiagonal(&a
->surface
, w
, h
);
37 case RR_SURFACE_PYRAMID
:
38 gradient_pyramid(&a
->surface
, w
, h
);
41 g_assert_not_reached(); /* unhandled gradient */
45 if (a
->surface
.relief
== RR_RELIEF_FLAT
&& a
->surface
.border
) {
46 r
= a
->surface
.border_color
->r
;
47 g
= a
->surface
.border_color
->g
;
48 b
= a
->surface
.border_color
->b
;
49 current
= (r
<< RrDefaultRedOffset
)
50 + (g
<< RrDefaultGreenOffset
)
51 + (b
<< RrDefaultBlueOffset
);
52 for (off
= 0, x
= 0; x
< w
; ++x
, off
++) {
53 *(data
+ off
) = current
;
54 *(data
+ off
+ ((h
-1) * w
)) = current
;
56 for (off
= 0, x
= 0; x
< h
; ++x
, off
++) {
57 *(data
+ (off
* w
)) = current
;
58 *(data
+ (off
* w
) + w
- 1) = current
;
62 if (a
->surface
.relief
!= RR_RELIEF_FLAT
) {
63 if (a
->surface
.bevel
== RR_BEVEL_1
) {
64 for (off
= 1, x
= 1; x
< w
- 1; ++x
, off
++)
66 data
+ off
+ (h
-1) * w
,
67 a
->surface
.relief
==RR_RELIEF_RAISED
);
68 for (off
= 0, x
= 0; x
< h
; ++x
, off
++)
69 highlight(data
+ off
* w
,
70 data
+ off
* w
+ w
- 1,
71 a
->surface
.relief
==RR_RELIEF_RAISED
);
74 if (a
->surface
.bevel
== RR_BEVEL_2
) {
75 for (off
= 2, x
= 2; x
< w
- 2; ++x
, off
++)
76 highlight(data
+ off
+ w
,
77 data
+ off
+ (h
-2) * w
,
78 a
->surface
.relief
==RR_RELIEF_RAISED
);
79 for (off
= 1, x
= 1; x
< h
-1; ++x
, off
++)
80 highlight(data
+ off
* w
+ 1,
81 data
+ off
* w
+ w
- 2,
82 a
->surface
.relief
==RR_RELIEF_RAISED
);
87 static void highlight(RrPixel32
*x
, RrPixel32
*y
, gboolean raised
)
99 r
= (*up
>> RrDefaultRedOffset
) & 0xFF;
101 g
= (*up
>> RrDefaultGreenOffset
) & 0xFF;
103 b
= (*up
>> RrDefaultBlueOffset
) & 0xFF;
105 if (r
> 0xFF) r
= 0xFF;
106 if (g
> 0xFF) g
= 0xFF;
107 if (b
> 0xFF) b
= 0xFF;
108 *up
= (r
<< RrDefaultRedOffset
) + (g
<< RrDefaultGreenOffset
)
109 + (b
<< RrDefaultBlueOffset
);
111 r
= (*down
>> RrDefaultRedOffset
) & 0xFF;
112 r
= (r
>> 1) + (r
>> 2);
113 g
= (*down
>> RrDefaultGreenOffset
) & 0xFF;
114 g
= (g
>> 1) + (g
>> 2);
115 b
= (*down
>> RrDefaultBlueOffset
) & 0xFF;
116 b
= (b
>> 1) + (b
>> 2);
117 *down
= (r
<< RrDefaultRedOffset
) + (g
<< RrDefaultGreenOffset
)
118 + (b
<< RrDefaultBlueOffset
);
121 static void create_bevel_colors(RrAppearance
*l
)
126 r
= l
->surface
.primary
->r
;
128 g
= l
->surface
.primary
->g
;
130 b
= l
->surface
.primary
->b
;
132 if (r
> 0xFF) r
= 0xFF;
133 if (g
> 0xFF) g
= 0xFF;
134 if (b
> 0xFF) b
= 0xFF;
135 g_assert(!l
->surface
.bevel_light
);
136 l
->surface
.bevel_light
= RrColorNew(l
->inst
, r
, g
, b
);
137 RrColorAllocateGC(l
->surface
.bevel_light
);
140 r
= l
->surface
.primary
->r
;
141 r
= (r
>> 1) + (r
>> 2);
142 g
= l
->surface
.primary
->g
;
143 g
= (g
>> 1) + (g
>> 2);
144 b
= l
->surface
.primary
->b
;
145 b
= (b
>> 1) + (b
>> 2);
146 g_assert(!l
->surface
.bevel_dark
);
147 l
->surface
.bevel_dark
= RrColorNew(l
->inst
, r
, g
, b
);
148 RrColorAllocateGC(l
->surface
.bevel_dark
);
151 static void gradient_solid(RrAppearance
*l
, int w
, int h
)
155 RrSurface
*sp
= &l
->surface
;
156 int left
= 0, top
= 0, right
= w
- 1, bottom
= h
- 1;
158 if (sp
->primary
->gc
== None
)
159 RrColorAllocateGC(sp
->primary
);
160 pix
= (sp
->primary
->r
<< RrDefaultRedOffset
)
161 + (sp
->primary
->g
<< RrDefaultGreenOffset
)
162 + (sp
->primary
->b
<< RrDefaultBlueOffset
);
164 for (a
= 0; a
< w
; a
++)
165 for (b
= 0; b
< h
; b
++)
166 sp
->pixel_data
[a
+ b
* w
] = pix
;
168 XFillRectangle(RrDisplay(l
->inst
), l
->pixmap
, sp
->primary
->gc
,
171 if (sp
->interlaced
) {
172 if (sp
->secondary
->gc
== None
)
173 RrColorAllocateGC(sp
->secondary
);
174 for (i
= 0; i
< h
; i
+= 2)
175 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, sp
->secondary
->gc
,
179 switch (sp
->relief
) {
180 case RR_RELIEF_RAISED
:
182 create_bevel_colors(l
);
186 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, sp
->bevel_dark
->gc
,
187 left
, bottom
, right
, bottom
);
188 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, sp
->bevel_dark
->gc
,
189 right
, bottom
, right
, top
);
191 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, sp
->bevel_light
->gc
,
192 left
, top
, right
, top
);
193 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, sp
->bevel_light
->gc
,
194 left
, bottom
, left
, top
);
197 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
,
199 left
+ 1, bottom
- 2, right
- 2, bottom
- 2);
200 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
,
202 right
- 2, bottom
- 2, right
- 2, top
+ 1);
204 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
,
206 left
+ 1, top
+ 1, right
- 2, top
+ 1);
207 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
,
209 left
+ 1, bottom
- 2, left
+ 1, top
+ 1);
212 g_assert_not_reached(); /* unhandled BevelType */
215 case RR_RELIEF_SUNKEN
:
217 create_bevel_colors(l
);
221 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, sp
->bevel_light
->gc
,
222 left
, bottom
, right
, bottom
);
223 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, sp
->bevel_light
->gc
,
224 right
, bottom
, right
, top
);
226 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, sp
->bevel_dark
->gc
,
227 left
, top
, right
, top
);
228 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, sp
->bevel_dark
->gc
,
229 left
, bottom
, left
, top
);
232 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, sp
->bevel_light
->gc
,
233 left
+ 1, bottom
- 2, right
- 2, bottom
- 2);
234 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, sp
->bevel_light
->gc
,
235 right
- 2, bottom
- 2, right
- 2, top
+ 1);
237 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, sp
->bevel_dark
->gc
,
238 left
+ 1, top
+ 1, right
- 2, top
+ 1);
239 XDrawLine(RrDisplay(l
->inst
), l
->pixmap
, sp
->bevel_dark
->gc
,
240 left
+ 1, bottom
- 2, left
+ 1, top
+ 1);
244 g_assert_not_reached(); /* unhandled BevelType */
249 if (sp
->border_color
->gc
== None
)
250 RrColorAllocateGC(sp
->border_color
);
251 XDrawRectangle(RrDisplay(l
->inst
), l
->pixmap
, sp
->border_color
->gc
,
252 left
, top
, right
, bottom
);
256 g_assert_not_reached(); /* unhandled ReliefType */
260 /* * * * * * * * * * * * * * GRADIENT MAGIC WOOT * * * * * * * * * * * * * * */
263 unsigned int color##x[3]; \
264 int len##x, cdelta##x[3], error##x[3] = { 0, 0, 0 }, inc##x[3]; \
265 gboolean bigslope##x[3] /* color slope > 1 */
267 #define SETUP(x, from, to, w) \
270 color##x[0] = from->r; \
271 color##x[1] = from->g; \
272 color##x[2] = from->b; \
274 cdelta##x[0] = to->r - from->r; \
275 cdelta##x[1] = to->g - from->g; \
276 cdelta##x[2] = to->b - from->b; \
278 if (cdelta##x[0] < 0) { \
279 cdelta##x[0] = -cdelta##x[0]; \
283 if (cdelta##x[1] < 0) { \
284 cdelta##x[1] = -cdelta##x[1]; \
288 if (cdelta##x[2] < 0) { \
289 cdelta##x[2] = -cdelta##x[2]; \
293 bigslope##x[0] = cdelta##x[0] > w;\
294 bigslope##x[1] = cdelta##x[1] > w;\
295 bigslope##x[2] = cdelta##x[2] > w
297 #define COLOR_RR(x, c) \
298 c->r = color##x[0]; \
299 c->g = color##x[1]; \
303 ((color##x[0] << RrDefaultRedOffset) + \
304 (color##x[1] << RrDefaultGreenOffset) + \
305 (color##x[2] << RrDefaultBlueOffset))
307 #define INCREMENT(x, i) \
313 for (i = 2; i >= 0; --i) { \
314 if (!cdelta##x[i]) continue; \
316 if (!bigslope##x[i]) { \
317 /* Y (color) is dependant on X */ \
318 error##x[i] += cdelta##x[i]; \
319 if ((error##x[i] << 1) >= len##x) { \
320 color##x[i] += INCREMENT(x, i); \
321 error##x[i] -= len##x; \
324 /* X is dependant on Y (color) */ \
326 color##x[i] += INCREMENT(x, i); \
327 error##x[i] += len##x; \
328 if ((error##x[i] << 1) >= cdelta##x[i]) { \
329 error##x[i] -= cdelta##x[i]; \
337 static void gradient_horizontal(RrSurface
*sf
, int w
, int h
)
340 RrPixel32
*data
= sf
->pixel_data
, *datav
;
344 SETUP(x
, sf
->primary
, sf
->secondary
, w
);
346 for (x
= w
- 1; x
> 0; --x
) { /* 0 -> w-1 */
349 for (y
= h
- 1; y
>= 0; --y
) { /* 0 -> h */
358 for (y
= h
- 1; y
>= 0; --y
) /* 0 -> h */
359 *(data
+ y
* w
) = current
;
362 static void gradient_vertical(RrSurface
*sf
, int w
, int h
)
365 RrPixel32
*data
= sf
->pixel_data
;
369 SETUP(y
, sf
->primary
, sf
->secondary
, h
);
371 for (y
= h
- 1; y
> 0; --y
) { /* 0 -> h-1 */
373 for (x
= w
- 1; x
>= 0; --x
) /* 0 -> w */
379 for (x
= w
- 1; x
>= 0; --x
) /* 0 -> w */
384 static void gradient_diagonal(RrSurface
*sf
, int w
, int h
)
387 RrPixel32
*data
= sf
->pixel_data
;
395 extracorner
.r
= (sf
->primary
->r
+ sf
->secondary
->r
) / 2;
396 extracorner
.g
= (sf
->primary
->g
+ sf
->secondary
->g
) / 2;
397 extracorner
.b
= (sf
->primary
->b
+ sf
->secondary
->b
) / 2;
399 SETUP(lefty
, sf
->primary
, (&extracorner
), h
);
400 SETUP(righty
, (&extracorner
), sf
->secondary
, h
);
402 for (y
= h
- 1; y
> 0; --y
) { /* 0 -> h-1 */
403 COLOR_RR(lefty
, (&left
));
404 COLOR_RR(righty
, (&right
));
406 SETUP(x
, (&left
), (&right
), w
);
408 for (x
= w
- 1; x
> 0; --x
) { /* 0 -> w-1 */
409 *(data
++) = COLOR(x
);
413 *(data
++) = COLOR(x
);
418 COLOR_RR(lefty
, (&left
));
419 COLOR_RR(righty
, (&right
));
421 SETUP(x
, (&left
), (&right
), w
);
423 for (x
= w
- 1; x
> 0; --x
) { /* 0 -> w-1 */
424 *(data
++) = COLOR(x
);
431 static void gradient_crossdiagonal(RrSurface
*sf
, int w
, int h
)
434 RrPixel32
*data
= sf
->pixel_data
;
442 extracorner
.r
= (sf
->primary
->r
+ sf
->secondary
->r
) / 2;
443 extracorner
.g
= (sf
->primary
->g
+ sf
->secondary
->g
) / 2;
444 extracorner
.b
= (sf
->primary
->b
+ sf
->secondary
->b
) / 2;
446 SETUP(lefty
, (&extracorner
), sf
->secondary
, h
);
447 SETUP(righty
, sf
->primary
, (&extracorner
), h
);
449 for (y
= h
- 1; y
> 0; --y
) { /* 0 -> h-1 */
450 COLOR_RR(lefty
, (&left
));
451 COLOR_RR(righty
, (&right
));
453 SETUP(x
, (&left
), (&right
), w
);
455 for (x
= w
- 1; x
> 0; --x
) { /* 0 -> w-1 */
456 *(data
++) = COLOR(x
);
460 *(data
++) = COLOR(x
);
465 COLOR_RR(lefty
, (&left
));
466 COLOR_RR(righty
, (&right
));
468 SETUP(x
, (&left
), (&right
), w
);
470 for (x
= w
- 1; x
> 0; --x
) { /* 0 -> w-1 */
471 *(data
++) = COLOR(x
);
478 static void gradient_pyramid(RrSurface
*sf
, int inw
, int inh
)
480 int x
, y
, w
= (inw
>> 1) + 1, h
= (inh
>> 1) + 1;
481 RrPixel32
*data
= sf
->pixel_data
;
482 RrPixel32
*end
= data
+ inw
*inh
- 1;
491 extracorner
.r
= (sf
->primary
->r
+ sf
->secondary
->r
) / 2;
492 extracorner
.g
= (sf
->primary
->g
+ sf
->secondary
->g
) / 2;
493 extracorner
.b
= (sf
->primary
->b
+ sf
->secondary
->b
) / 2;
495 SETUP(lefty
, (&extracorner
), sf
->secondary
, h
);
496 SETUP(righty
, sf
->primary
, (&extracorner
), h
);
498 for (y
= h
- 1; y
> 0; --y
) { /* 0 -> h-1 */
499 COLOR_RR(lefty
, (&left
));
500 COLOR_RR(righty
, (&right
));
502 SETUP(x
, (&left
), (&right
), w
);
504 for (x
= w
- 1; x
> 0; --x
) { /* 0 -> w-1 */
507 *(data
+inw
-x
) = current
;
509 *(end
-(inw
-x
)) = current
;
515 *(data
+inw
-x
) = current
;
517 *(end
-(inw
-x
)) = current
;
525 COLOR_RR(lefty
, (&left
));
526 COLOR_RR(righty
, (&right
));
528 SETUP(x
, (&left
), (&right
), w
);
530 for (x
= w
- 1; x
> 0; --x
) { /* 0 -> w-1 */
533 *(data
+inw
-x
) = current
;
535 *(end
-(inw
-x
)) = current
;
541 *(data
+inw
-x
) = current
;
543 *(end
-(inw
-x
)) = current
;