visibility macros and flush() added to SrcFileSource; merge with master
[ardour.git] / libs / clearlooks-newer / clearlooks_draw_gummy.c
1 /* Clearlooks Gummy style
2  * Copyright (C) 2007 Andrea Cimitan
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  *
19  * Written by Andrea Cimitan <andrea.cimitan@gmail.com>
20  */
21
22 #include "clearlooks_draw.h"
23 #include "clearlooks_style.h"
24 #include "clearlooks_types.h"
25
26 #include "support.h"
27 #include <ge-support.h>
28
29 #include <cairo.h>
30
31 /* Normal shadings */
32 #define SHADE_TOP 1.08
33 #define SHADE_CENTER_TOP 1.02
34 #define SHADE_BOTTOM 0.94
35
36 /* Topleft highlight */
37 #define TOPLEFT_HIGHLIGHT_SHADE 1.3
38 #define TOPLEFT_HIGHLIGHT_ALPHA 0.4
39
40 /* Listview */
41 #define LISTVIEW_SHADE_TOP 1.06
42 #define LISTVIEW_SHADE_CENTER_TOP 1.02
43 #define LISTVIEW_SHADE_BOTTOM 0.96
44
45 /* Toolbar */
46 #define TOOLBAR_SHADE_TOP 1.04
47 #define TOOLBAR_SHADE_CENTER_TOP 1.01
48 #define TOOLBAR_SHADE_BOTTOM 0.97
49
50
51 static void
52 clearlooks_draw_gummy_gradient (cairo_t          *cr,
53                                 double x, double y, int width, int height,
54                                 const CairoColor *color,
55                                 gboolean disabled, gboolean radius, CairoCorners corners)
56 {
57         CairoColor fill;
58         CairoColor shade1, shade2, shade3;
59         cairo_pattern_t *pt;
60
61         ge_shade_color (color, disabled? 1.04 : SHADE_TOP, &shade1);
62         ge_shade_color (color, disabled? 1.01 : SHADE_CENTER_TOP, &shade2);
63         ge_shade_color (color, disabled? 0.99 : 1.0, &fill);
64         ge_shade_color (color, disabled? 0.96 : SHADE_BOTTOM, &shade3);
65
66         pt = cairo_pattern_create_linear (x, y, x, y+height);
67         cairo_pattern_add_color_stop_rgb (pt, 0.0, shade1.r, shade1.g, shade1.b);
68         cairo_pattern_add_color_stop_rgb (pt, 0.5, shade2.r, shade2.g, shade2.b);
69         cairo_pattern_add_color_stop_rgb (pt, 0.5, fill.r, fill.g, fill.b);
70         cairo_pattern_add_color_stop_rgb (pt, 1.0, shade3.r, shade3.g, shade3.b);
71
72         cairo_set_source (cr, pt);
73         ge_cairo_rounded_rectangle (cr, x, y, width, height, radius, corners);
74         cairo_fill (cr);
75
76         cairo_pattern_destroy (pt);
77 }
78
79 static void
80 clearlooks_set_mixed_color (cairo_t          *cr, 
81                             const CairoColor *color1, 
82                             const CairoColor *color2, 
83                             gdouble mix_factor)
84 {
85         CairoColor composite;
86
87         ge_mix_color (color1, color2, mix_factor, &composite);
88         ge_cairo_set_color (cr, &composite);
89 }
90
91 static void
92 clearlooks_gummy_draw_highlight_and_shade (cairo_t                *cr, 
93                                            const CairoColor       *bg_color,
94                                            const ShadowParameters *params,
95                                            int width, int height, gdouble radius)
96 {
97         CairoColor shadow;
98         CairoColor highlight;
99         uint8 corners = params->corners;
100         double x = 1.0;
101         double y = 1.0;
102
103         /* not really sure of shading ratios... we will think */
104         ge_shade_color (bg_color, 0.8, &shadow);
105         ge_shade_color (bg_color, 1.2, &highlight);
106
107         cairo_save (cr);
108
109         /* Top/Left highlight */
110         if (corners & CR_CORNER_BOTTOMLEFT)
111                 cairo_move_to (cr, x, y+height-radius);
112         else
113                 cairo_move_to (cr, x, y+height);
114
115         ge_cairo_rounded_corner (cr, x, y, radius, corners & CR_CORNER_TOPLEFT);
116
117         if (corners & CR_CORNER_TOPRIGHT)
118                 cairo_line_to (cr, x+width-radius, y);
119         else
120                 cairo_line_to (cr, x+width, y);
121
122         if (params->shadow & CL_SHADOW_OUT)
123                 cairo_set_source_rgba (cr, highlight.r, highlight.g, highlight.b, 0.5);
124         else
125                 cairo_set_source_rgba (cr, shadow.r, shadow.g, shadow.b, 0.5);
126                 
127         cairo_stroke (cr);
128
129         /* Bottom/Right highlight -- this includes the corners */
130         cairo_move_to (cr, x+width-radius, y); /* topright and by radius to the left */
131         ge_cairo_rounded_corner (cr, x+width, y, radius, corners & CR_CORNER_TOPRIGHT);
132         ge_cairo_rounded_corner (cr, x+width, y+height, radius, corners & CR_CORNER_BOTTOMRIGHT);
133         ge_cairo_rounded_corner (cr, x, y+height, radius, corners & CR_CORNER_BOTTOMLEFT);
134
135         if (params->shadow & CL_SHADOW_OUT)
136                 cairo_set_source_rgba (cr, shadow.r, shadow.g, shadow.b, 0.5);
137         else
138                 cairo_set_source_rgba (cr, highlight.r, highlight.g, highlight.b, 0.5);
139
140         cairo_stroke (cr);
141
142         cairo_restore (cr);
143 }
144
145 static void
146 clearlooks_gummy_draw_top_left_highlight (cairo_t *cr, const CairoColor *color,
147                                           const WidgetParameters *params,
148                                           int width, int height, gdouble radius)
149 {
150         CairoColor hilight; 
151
152         double light_top = params->ythickness-1,
153                light_bottom = height - params->ythickness - 1,
154                light_left = params->xthickness-1,
155                light_right = width - params->xthickness - 1;
156
157         ge_shade_color (color, TOPLEFT_HIGHLIGHT_SHADE, &hilight);
158         cairo_move_to (cr, light_left, light_bottom - (int)radius/2);
159
160         ge_cairo_rounded_corner (cr, light_left, light_top, radius, params->corners & CR_CORNER_TOPLEFT);
161
162         cairo_line_to (cr, light_right - (int)radius/2, light_top);
163         cairo_set_source_rgba (cr, hilight.r, hilight.g, hilight.b, TOPLEFT_HIGHLIGHT_ALPHA);
164         cairo_stroke (cr);
165 }
166
167 static void
168 clearlooks_gummy_draw_button (cairo_t                *cr,
169                               const ClearlooksColors *colors,
170                               const WidgetParameters *params,
171                               int x, int y, int width, int height)
172 {
173         double xoffset = 0, yoffset = 0;
174         CairoColor fill            = colors->bg[params->state_type];
175         CairoColor border_normal   = colors->shade[6];
176         CairoColor border_disabled = colors->shade[4];
177         double radius;
178
179         cairo_pattern_t *pattern;
180
181         cairo_save (cr);
182         cairo_translate (cr, x, y);
183         cairo_set_line_width (cr, 1.0);
184
185         /* Shadows and Glow */
186         if (params->xthickness == 3 || params->ythickness == 3)
187         {
188                 if (params->xthickness == 3)
189                         xoffset = 1;
190                 if (params->ythickness == 3)
191                         yoffset = 1;
192         }
193
194         radius = MIN (params->radius, MIN ((width - 2.0 - 2*xoffset) / 2.0, (height - 2.0 - 2*yoffset) / 2.0));
195
196         if (params->xthickness == 3 || params->ythickness == 3)
197         {
198                 cairo_translate (cr, 0.5, 0.5);
199
200                 if (params->enable_glow && !params->active && !params->disabled && !params->is_default)
201                 {
202                         CairoColor shadow;
203
204                         radius = MIN (params->radius, MIN ((width - 2.0 - 2*xoffset) / 2.0 - 1.0, (height - 2.0 - 2*yoffset) / 2.0 - 1.0));
205
206                         ge_cairo_rounded_rectangle (cr, 0, 0, width-1, height-1, radius+1, params->corners);
207                         ge_shade_color (&params->parentbg, 0.97, &shadow);
208                         ge_cairo_set_color (cr, &shadow);
209                         cairo_stroke (cr);
210
211                         ge_cairo_rounded_rectangle (cr, 1, 1, width-2, height-2, radius+1, params->corners);
212                         ge_shade_color (&params->parentbg, 0.93, &shadow);
213                         ge_cairo_set_color (cr, &shadow);
214                         cairo_stroke (cr);
215                 }
216
217                 if (params->is_default)
218                 {
219                         CairoColor shadow = colors->spot[1];
220
221                         radius = MIN (params->radius, MIN ((width - 2.0 - 2*xoffset) / 2.0 - 1.0, (height - 2.0 - 2*yoffset) / 2.0 - 1.0));
222
223                         ge_cairo_rounded_rectangle (cr, 0, 0, width-1, height-1, radius+1, params->corners);
224                         clearlooks_set_mixed_color (cr, &params->parentbg, &shadow, 0.5);
225                         cairo_stroke (cr);
226                 }
227
228                 if (!(params->enable_glow && !params->active && !params->disabled))
229                         params->style_functions->draw_inset (cr, &params->parentbg, 0, 0, width-1, height-1, params->radius+1, params->corners);
230                 cairo_translate (cr, -0.5, -0.5);
231         }
232
233         clearlooks_draw_gummy_gradient (cr, xoffset+1, yoffset+1, 
234                                       width-(xoffset*2)-2, height-(yoffset*2)-2, 
235                                       &fill, params->disabled, radius, params->corners);
236
237         /* Pressed button shadow */
238         if (params->active)
239         {
240                 CairoColor shadow;
241                 ge_shade_color (&fill, 0.92, &shadow);
242
243                 cairo_save (cr);
244
245                 ge_cairo_rounded_rectangle (cr, xoffset+1, yoffset+1, width-(xoffset*2)-2, height, radius, 
246                                             params->corners & (CR_CORNER_TOPLEFT | CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMLEFT));
247                 cairo_clip (cr);
248                 cairo_rectangle (cr, xoffset+1, yoffset+1, width-(xoffset*2)-2, 3);
249
250                 pattern = cairo_pattern_create_linear (xoffset+1, yoffset+1, xoffset+1, yoffset+4);
251                 cairo_pattern_add_color_stop_rgba (pattern, 0.0, shadow.r, shadow.g, shadow.b, 0.58);
252                 cairo_pattern_add_color_stop_rgba (pattern, 1.0, shadow.r, shadow.g, shadow.b, 0.0);
253                 cairo_set_source (cr, pattern);
254                 cairo_fill (cr);
255                 cairo_pattern_destroy (pattern);
256
257                 cairo_rectangle (cr, xoffset+1, yoffset+1, 3, height-(yoffset*2)-2);
258
259                 pattern = cairo_pattern_create_linear (xoffset+1, yoffset+1, xoffset+4, yoffset+1);
260                 cairo_pattern_add_color_stop_rgba (pattern, 0.0, shadow.r, shadow.g, shadow.b, 0.58);
261                 cairo_pattern_add_color_stop_rgba (pattern, 1.0, shadow.r, shadow.g, shadow.b, 0.0);
262                 cairo_set_source (cr, pattern);
263                 cairo_fill (cr);
264                 cairo_pattern_destroy (pattern);
265
266                 cairo_restore (cr);
267         }
268
269         /* Border */
270         if (params->is_default) /* || (params->prelight && params->enable_glow)) */
271                 border_normal = colors->spot[2];
272         if (params->disabled)
273                 ge_cairo_set_color (cr, &border_disabled);
274         else
275                 clearlooks_set_mixed_color (cr, &border_normal, &fill, 0.2);
276         ge_cairo_rounded_rectangle (cr, xoffset + 0.5, yoffset + 0.5,
277                                   width-(xoffset*2)-1, height-(yoffset*2)-1,
278                                   radius, params->corners);
279         cairo_stroke (cr);
280
281         if (!params->active)
282         {
283                 cairo_translate (cr, 0.5, 0.5);
284                 clearlooks_gummy_draw_top_left_highlight (cr, &fill, params, width, height, radius);
285         }
286         cairo_restore (cr);
287 }
288
289 static void
290 clearlooks_gummy_draw_entry (cairo_t                *cr,
291                              const ClearlooksColors *colors,
292                              const WidgetParameters *params,
293                              int x, int y, int width, int height)
294 {
295         const CairoColor *base = &colors->base[params->state_type];
296         CairoColor border = colors->shade[params->disabled ? 4 : 6];
297         double radius = MIN (params->radius, MIN ((width - 4.0) / 2.0, (height - 4.0) / 2.0));
298
299         if (params->focus)
300                 border = colors->spot[2];
301
302         cairo_translate (cr, x+0.5, y+0.5);
303         cairo_set_line_width (cr, 1.0);
304
305         /* Fill the background to get the correct corners. */
306         cairo_rectangle (cr, -0.5, -0.5, width, height);
307         ge_cairo_set_color (cr, &params->parentbg);
308         cairo_fill (cr);
309
310         /* Fill with the base color, because it was just cleared above */
311         cairo_rectangle (cr, 1.5, 1.5, width-4, height-4);
312         ge_cairo_set_color (cr, base);
313         cairo_fill (cr);
314
315         params->style_functions->draw_inset (cr, &params->parentbg, 0, 0, width-1, height-1, radius+1, params->corners);
316
317         /* Draw the inner shadow */
318         if (params->focus)
319         {
320                 /* ge_cairo_rounded_rectangle (cr, 2, 2, width-5, height-5, RADIUS-1, params->corners); */
321                 ge_cairo_set_color (cr, &colors->spot[0]);
322                 ge_cairo_stroke_rectangle (cr, 2, 2, width-5, height-5);
323         }
324         else
325         {
326                 CairoColor shadow; 
327                 ge_shade_color (&border, 0.92, &shadow);
328
329                 cairo_set_source_rgba (cr, shadow.r, shadow.g, shadow.b, params->disabled ? 0.09 : 0.18);
330                 /*
331                 cairo_move_to (cr, 2, height-3);
332                 cairo_arc (cr, params->xthickness+RADIUS-1, params->ythickness+RADIUS-1, RADIUS, G_PI, 270*(G_PI/180));
333                 cairo_line_to (cr, width-3, 2);
334                 */
335                 cairo_move_to (cr, 2, height-3);
336                 cairo_line_to (cr, 2, 2);
337                 cairo_line_to (cr, width-3, 2);
338                 cairo_stroke (cr);
339         }
340
341         ge_cairo_rounded_rectangle (cr, 1, 1, width-3, height-3, radius, params->corners);
342         ge_cairo_set_color (cr, &border);
343         cairo_stroke (cr);
344 }
345
346 static void
347 clearlooks_gummy_draw_progressbar_trough (cairo_t                *cr,
348                                           const ClearlooksColors *colors,
349                                           const WidgetParameters *params,
350                                           int x, int y, int width, int height)
351 {
352         const CairoColor *border = &colors->shade[7];
353         CairoColor        shadow;
354         cairo_pattern_t  *pattern;
355         double            radius = MIN (params->radius, MIN ((height-2.0) / 2.0, (width-2.0) / 2.0));
356
357         cairo_save (cr);
358
359         cairo_set_line_width (cr, 1.0);
360
361         /* Fill with bg color */
362         ge_cairo_set_color (cr, &colors->bg[params->state_type]);
363
364         cairo_rectangle (cr, x, y, width, height);
365         cairo_fill (cr);
366
367         /* Create trough box */
368         ge_cairo_rounded_rectangle (cr, x+1, y+1, width-2, height-2, radius, params->corners);
369         ge_cairo_set_color (cr, &colors->shade[2]);
370         cairo_fill (cr);
371
372         /* Draw border */
373         ge_cairo_rounded_rectangle (cr, x+0.5, y+0.5, width-1, height-1, radius, params->corners);
374         clearlooks_set_mixed_color (cr, border, &colors->shade[2], 0.3);
375         cairo_stroke (cr);
376
377         /* clip the corners of the shadows */
378         ge_cairo_rounded_rectangle (cr, x+1, y+1, width-2, height-2, radius, params->corners);
379         cairo_clip (cr);
380
381         ge_shade_color (border, 0.92, &shadow);
382
383         /* Top shadow */
384         cairo_rectangle (cr, x+1, y+1, width-2, 4);
385         pattern = cairo_pattern_create_linear (x, y, x, y+4);
386         cairo_pattern_add_color_stop_rgba (pattern, 0.0, shadow.r, shadow.g, shadow.b, 0.3);
387         cairo_pattern_add_color_stop_rgba (pattern, 1.0, shadow.r, shadow.g, shadow.b, 0.);
388         cairo_set_source (cr, pattern);
389         cairo_fill (cr);
390         cairo_pattern_destroy (pattern);
391
392         /* Left shadow */
393         cairo_rectangle (cr, x+1, y+1, 4, height-2);
394         pattern = cairo_pattern_create_linear (x, y, x+4, y);
395         cairo_pattern_add_color_stop_rgba (pattern, 0.0, shadow.r, shadow.g, shadow.b, 0.3);
396         cairo_pattern_add_color_stop_rgba (pattern, 1.0, shadow.r, shadow.g, shadow.b, 0.);
397         cairo_set_source (cr, pattern);
398         cairo_fill (cr);
399         cairo_pattern_destroy (pattern);
400
401         cairo_restore (cr);
402 }
403
404 static void
405 clearlooks_gummy_draw_progressbar_fill (cairo_t                     *cr,
406                                         const ClearlooksColors      *colors,
407                                         const WidgetParameters      *params,
408                                         const ProgressBarParameters *progressbar,
409                                         int x, int y, int width, int height, gint offset)
410 {
411         boolean      is_horizontal = progressbar->orientation < 2;
412         double       tile_pos = 0;
413         double       stroke_width;
414         double       radius;
415         int          x_step;
416
417         cairo_pattern_t *pattern;
418         CairoColor       shade1, shade2, shade3;
419         CairoColor       border;
420         CairoColor       shadow;
421
422         radius = MAX (0, params->radius - params->xthickness);
423
424         cairo_save (cr);
425
426         if (!is_horizontal)
427                 ge_cairo_exchange_axis (cr, &x, &y, &width, &height);
428
429         if ((progressbar->orientation == CL_ORIENTATION_RIGHT_TO_LEFT) || (progressbar->orientation == CL_ORIENTATION_BOTTOM_TO_TOP))
430                 ge_cairo_mirror (cr, CR_MIRROR_HORIZONTAL, &x, &y, &width, &height);
431
432         /* Clamp the radius so that the _height_ fits ... */
433         radius = MIN (radius, height / 2.0);
434
435         stroke_width = height*2;
436         x_step = (((float)stroke_width/10)*offset); /* This looks weird ... */
437
438         cairo_translate (cr, x, y);
439
440         cairo_save (cr);
441         /* This is kind of nasty ... Clip twice from each side in case the length
442          * of the fill is smaller than twice the radius. */
443         ge_cairo_rounded_rectangle (cr, 0, 0, width + radius, height, radius, CR_CORNER_TOPLEFT | CR_CORNER_BOTTOMLEFT);
444         cairo_clip (cr);
445         ge_cairo_rounded_rectangle (cr, -radius, 0, width + radius, height, radius, CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMRIGHT);
446         cairo_clip (cr);
447
448         /* Draw the background gradient */
449         ge_shade_color (&colors->spot[1], SHADE_TOP, &shade1);
450         ge_shade_color (&colors->spot[1], SHADE_CENTER_TOP, &shade2);
451         ge_shade_color (&colors->spot[1], SHADE_BOTTOM, &shade3);
452         pattern = cairo_pattern_create_linear (0, 0, 0, height);
453         cairo_pattern_add_color_stop_rgb (pattern, 0.0, shade1.r, shade1.g, shade1.b);
454         cairo_pattern_add_color_stop_rgb (pattern, 0.5, shade2.r, shade2.g, shade2.b);
455         cairo_pattern_add_color_stop_rgb (pattern, 0.5, colors->spot[1].r, colors->spot[1].g, colors->spot[1].b);
456         cairo_pattern_add_color_stop_rgb (pattern, 1.0, shade3.r, shade3.g, shade3.b);
457         cairo_set_source (cr, pattern);
458         cairo_paint (cr);
459         cairo_pattern_destroy (pattern);
460
461         /* Draw the Strokes */
462         while (tile_pos <= width+x_step)
463         {
464                 cairo_move_to (cr, stroke_width/2-x_step, 0);
465                 cairo_line_to (cr, stroke_width-x_step,   0);
466                 cairo_line_to (cr, stroke_width/2-x_step, height);
467                 cairo_line_to (cr, -x_step, height);
468                 
469                 cairo_translate (cr, stroke_width, 0);
470                 tile_pos += stroke_width;
471         }
472
473         cairo_set_source_rgba (cr, colors->spot[2].r,
474                                    colors->spot[2].g,
475                                    colors->spot[2].b,
476                                    0.15);
477
478         cairo_fill (cr);
479         cairo_restore (cr); /* rounded clip region */
480
481         /* inner highlight border
482          * This is again kinda ugly. Draw once from each side, clipping away the other. */
483         cairo_set_source_rgba (cr, colors->spot[0].r, colors->spot[0].g, colors->spot[0].b, 0.2);
484
485         /* left side */
486         cairo_save (cr);
487         cairo_rectangle (cr, 0, 0, width / 2, height);
488         cairo_clip (cr);
489
490         if (progressbar->pulsing)
491                 ge_cairo_rounded_rectangle (cr, 1.5, 0.5, width + radius, height - 1, radius, CR_CORNER_TOPLEFT | CR_CORNER_BOTTOMLEFT);
492         else
493                 ge_cairo_rounded_rectangle (cr, 0.5, 0.5, width + radius, height - 1, radius, CR_CORNER_TOPLEFT | CR_CORNER_BOTTOMLEFT);
494
495         cairo_stroke (cr);
496         cairo_restore (cr); /* clip */
497
498         /* right side */
499         cairo_save (cr);
500         cairo_rectangle (cr, width / 2, 0, (width+1) / 2, height);
501         cairo_clip (cr);
502
503         if (progressbar->value < 1.0 || progressbar->pulsing)
504                 ge_cairo_rounded_rectangle (cr, -1.5 - radius, 0.5, width + radius, height - 1, radius, CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMRIGHT);
505         else
506                 ge_cairo_rounded_rectangle (cr, -0.5 - radius, 0.5, width + radius, height - 1, radius, CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMRIGHT);
507
508         cairo_stroke (cr);
509         cairo_restore (cr); /* clip */
510
511
512         /* Draw the dark lines and the shadow */
513         cairo_save (cr);
514         /* Again, this weird clip area. */
515         ge_cairo_rounded_rectangle (cr, -1.0, 0, width + radius + 2.0, height, radius, CR_CORNER_TOPLEFT | CR_CORNER_BOTTOMLEFT);
516         cairo_clip (cr);
517         ge_cairo_rounded_rectangle (cr, -radius - 1.0, 0, width + radius + 2.0, height, radius, CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMRIGHT);
518         cairo_clip (cr);
519
520         border = colors->spot[2];
521         border.a = 0.6;
522         ge_shade_color (&colors->shade[7], 0.92, &shadow);
523         shadow.a = 0.2;
524
525         if (progressbar->pulsing)
526         {
527                 /* At the beginning of the bar. */
528                 cairo_move_to (cr, 0.5 + radius, height + 0.5);
529                 ge_cairo_rounded_corner (cr, 0.5, height + 0.5, radius + 1, CR_CORNER_BOTTOMLEFT);
530                 ge_cairo_rounded_corner (cr, 0.5, -0.5, radius + 1, CR_CORNER_TOPLEFT);
531                 ge_cairo_set_color (cr, &border);
532                 cairo_stroke (cr);
533
534                 cairo_move_to (cr, -0.5 + radius, height + 0.5);
535                 ge_cairo_rounded_corner (cr, -0.5, height + 0.5, radius + 1, CR_CORNER_BOTTOMLEFT);
536                 ge_cairo_rounded_corner (cr, -0.5, -0.5, radius + 1, CR_CORNER_TOPLEFT);
537                 ge_cairo_set_color (cr, &shadow);
538                 cairo_stroke (cr);
539         }
540         if (progressbar->value < 1.0 || progressbar->pulsing)
541         {
542                 /* At the end of the bar. */
543                 cairo_move_to (cr, width - 0.5 - radius, -0.5);
544                 ge_cairo_rounded_corner (cr, width - 0.5, -0.5, radius + 1, CR_CORNER_TOPRIGHT);
545                 ge_cairo_rounded_corner (cr, width - 0.5, height + 0.5, radius + 1, CR_CORNER_BOTTOMRIGHT);
546                 ge_cairo_set_color (cr, &border);
547                 cairo_stroke (cr);
548
549                 cairo_move_to (cr, width + 0.5 - radius, -0.5);
550                 ge_cairo_rounded_corner (cr, width + 0.5, -0.5, radius + 1, CR_CORNER_TOPRIGHT);
551                 ge_cairo_rounded_corner (cr, width + 0.5, height + 0.5, radius + 1, CR_CORNER_BOTTOMRIGHT);
552                 ge_cairo_set_color (cr, &shadow);
553                 cairo_stroke (cr);
554         }
555
556         cairo_restore (cr);
557
558         cairo_restore (cr); /* rotation, mirroring */
559 }
560
561 static void
562 clearlooks_gummy_scale_draw_gradient (cairo_t          *cr,
563                                       const CairoColor *fill,
564                                       const CairoColor *border,
565                                       int x, int y, int width, int height,
566                                       gboolean horizontal, gboolean in)
567 {
568         cairo_pattern_t *pattern;
569
570         CairoColor f1, f2;
571
572         ge_shade_color (fill, in? 0.95 : 1.1, &f1);
573         ge_shade_color (fill, in? 1.05 : 0.9, &f2);
574
575         pattern = cairo_pattern_create_linear (0, 0, horizontal ? 0 :  width, horizontal ? height : 0);
576         cairo_pattern_add_color_stop_rgba (pattern, 0.0, f1.r, f1.g, f1.b, f1.a);
577         cairo_pattern_add_color_stop_rgba (pattern, 1.0, f2.r, f2.g, f2.b, f2.a);
578
579         cairo_rectangle (cr, x+0.5, y+0.5, width-1, height-1);
580         cairo_set_source (cr, pattern);
581         cairo_fill (cr);
582         cairo_pattern_destroy (pattern);
583
584         clearlooks_set_mixed_color (cr, border, fill, 0.2);
585         ge_cairo_stroke_rectangle (cr, x, y, width, height);
586 }
587
588 #define TROUGH_SIZE 6
589 static void
590 clearlooks_gummy_draw_scale_trough (cairo_t                *cr,
591                                     const ClearlooksColors *colors,
592                                     const WidgetParameters *params,
593                                     const SliderParameters *slider,
594                                     int x, int y, int width, int height)
595 {
596         int     trough_width, trough_height;
597         double  translate_x, translate_y;
598
599         if (slider->horizontal)
600         {
601                 trough_width  = width-3;
602                 trough_height = TROUGH_SIZE-2;
603
604                 translate_x   = x + 0.5;
605                 translate_y   = y + 0.5 + (height/2) - (TROUGH_SIZE/2);
606         }
607         else
608         {
609                 trough_width  = TROUGH_SIZE-2;
610                 trough_height = height-3;
611
612                 translate_x   = x + 0.5 + (width/2) - (TROUGH_SIZE/2);
613                 translate_y  = y + 0.5;
614         }
615
616         cairo_set_line_width (cr, 1.0);
617         cairo_translate (cr, translate_x, translate_y);
618
619         if (!slider->fill_level)
620                 params->style_functions->draw_inset (cr, &params->parentbg, 0, 0, trough_width+2, trough_height+2, 0, 0);
621
622         cairo_translate (cr, 1, 1);
623
624         if (!slider->lower && !slider->fill_level)
625                 clearlooks_gummy_scale_draw_gradient (cr, 
626                                                       &colors->shade[2], /* bottom */
627                                                       &colors->shade[6], /* border */
628                                                       0, 0, trough_width, trough_height,
629                                                       slider->horizontal, TRUE);
630         else if (!slider->fill_level)
631                 clearlooks_gummy_scale_draw_gradient (cr, 
632                                                       &colors->spot[1], /* bottom */
633                                                       &colors->spot[2], /* border */
634                                                       0, 0, trough_width, trough_height,
635                                                       slider->horizontal, FALSE);
636         else {
637                 CairoColor c1 = colors->spot[1];
638                 CairoColor c2 = colors->spot[2];
639
640                 c1.a = 0.25;
641                 c2.a = 0.25;
642
643                 clearlooks_gummy_scale_draw_gradient (cr, 
644                                                       &c1, /* bottom */
645                                                       &c2, /* border */
646                                                       0, 0, trough_width, trough_height,
647                                                       slider->horizontal, FALSE);
648         }
649
650 }
651
652 static void
653 clearlooks_gummy_draw_tab (cairo_t                *cr,
654                            const ClearlooksColors *colors,
655                            const WidgetParameters *params,
656                            const TabParameters    *tab,
657                            int x, int y, int width, int height)
658 {
659
660         const CairoColor    *border        = &colors->shade[5];
661         const CairoColor    *stripe_fill   = &colors->spot[1];
662         const CairoColor    *stripe_border = &colors->spot[2];
663         const CairoColor    *fill;
664
665         cairo_pattern_t     *pattern;
666
667         double               radius;
668
669         radius = MIN (params->radius, MIN ((width - 2.0) / 2.0, (height - 2.0) / 2.0));
670
671         /* Set clip */
672         cairo_rectangle      (cr, x, y, width, height);
673         cairo_clip           (cr);
674         cairo_new_path       (cr);
675
676         /* Translate and set line width */
677         cairo_set_line_width (cr, 1.0);
678         cairo_translate      (cr, x+0.5, y+0.5);
679
680         /* Make the tabs slightly bigger than they should be, to create a gap */
681         /* And calculate the strip size too, while you're at it */
682         if (tab->gap_side == CL_GAP_TOP || tab->gap_side == CL_GAP_BOTTOM)
683         {
684                 height += 3.0;
685
686                 if (tab->gap_side == CL_GAP_TOP)
687                         cairo_translate (cr, 0.0, -3.0); /* gap at the other side */
688         }
689         else
690         {
691                 width += 3.0;
692
693                 if (tab->gap_side == CL_GAP_LEFT) 
694                         cairo_translate (cr, -3.0, 0.0); /* gap at the other side */
695         }
696
697         /* Set the fill color */
698         fill = &colors->bg[params->state_type];
699
700         /* Set tab shape */
701         ge_cairo_rounded_rectangle (cr, 0, 0, width-1, height-1,
702                                     radius, params->corners);
703
704         /* Draw fill */
705         ge_cairo_set_color (cr, fill);
706         cairo_fill  (cr);
707
708         /* Draw highlight */
709         if (!params->active)
710         {
711                 ShadowParameters shadow;
712
713                 shadow.shadow  = CL_SHADOW_OUT;
714                 shadow.corners = params->corners;
715
716                 clearlooks_gummy_draw_highlight_and_shade (cr, &colors->bg[0], &shadow,
717                                                      width, height, radius);
718         }
719
720         if (params->active)
721         {
722                 CairoColor hilight;
723                 CairoColor shade1, shade2, shade3;
724
725                 pattern = cairo_pattern_create_linear (tab->gap_side == CL_GAP_LEFT   ? width-1  : 0,
726                                                        tab->gap_side == CL_GAP_TOP    ? height-2 : 1,
727                                                        tab->gap_side == CL_GAP_RIGHT  ? width    : 0,
728                                                        tab->gap_side == CL_GAP_BOTTOM ? height   : 0);
729
730                 ge_cairo_rounded_rectangle (cr, 0, 0, width-1, height-1, radius, params->corners);
731
732                 ge_shade_color (fill, 1.14, &hilight);
733                 ge_shade_color (fill, SHADE_TOP, &shade1);
734                 ge_shade_color (fill, SHADE_CENTER_TOP, &shade2);
735                 ge_shade_color (fill, SHADE_BOTTOM, &shade3);
736
737                 cairo_pattern_add_color_stop_rgb (pattern, 0.0,        hilight.r, hilight.g, hilight.b);
738                 cairo_pattern_add_color_stop_rgb (pattern, 1.0/height, hilight.r, hilight.g, hilight.b);
739                 cairo_pattern_add_color_stop_rgb (pattern, 1.0/height, shade1.r, shade1.g, shade1.b);
740                 cairo_pattern_add_color_stop_rgb (pattern, 0.45,       shade2.r, shade2.g, shade2.b);
741                 cairo_pattern_add_color_stop_rgb (pattern, 0.45,       fill->r, fill->g, fill->b);
742                 cairo_pattern_add_color_stop_rgb (pattern, 1.0,        shade3.r, shade3.g, shade3.b);
743                 cairo_set_source (cr, pattern);
744                 cairo_fill (cr);
745                 cairo_pattern_destroy (pattern);
746         }
747         else
748         {
749                 /* Draw shade */
750                 pattern = cairo_pattern_create_linear (tab->gap_side == CL_GAP_LEFT   ? width-2  : 0,
751                                                        tab->gap_side == CL_GAP_TOP    ? height-2 : 0,
752                                                        tab->gap_side == CL_GAP_RIGHT  ? width    : 0,
753                                                        tab->gap_side == CL_GAP_BOTTOM ? height   : 0);
754
755                 ge_cairo_rounded_rectangle (cr, 0, 0, width-1, height-1, radius, params->corners);
756
757                 cairo_pattern_add_color_stop_rgba (pattern, 0.0, stripe_fill->r, stripe_fill->g, stripe_fill->b, 0.5);
758                 cairo_pattern_add_color_stop_rgba (pattern, 0.8, fill->r, fill->g, fill->b, 0.0);
759                 cairo_set_source (cr, pattern);
760                 cairo_fill (cr);
761                 cairo_pattern_destroy (pattern);
762         }
763
764         ge_cairo_rounded_rectangle (cr, 0, 0, width-1, height-1, radius, params->corners);
765
766         if (params->active)
767         {
768                 ge_cairo_set_color (cr, border);
769                 cairo_stroke (cr);
770         }
771         else
772         {
773                 pattern = cairo_pattern_create_linear (tab->gap_side == CL_GAP_LEFT   ? width-2  : 2,
774                                                        tab->gap_side == CL_GAP_TOP    ? height-2 : 2,
775                                                        tab->gap_side == CL_GAP_RIGHT  ? width    : 2,
776                                                        tab->gap_side == CL_GAP_BOTTOM ? height   : 2);
777
778                 cairo_pattern_add_color_stop_rgb (pattern, 0.0, stripe_border->r, stripe_border->g, stripe_border->b);
779                 cairo_pattern_add_color_stop_rgb (pattern, 0.8, border->r,        border->g,        border->b);
780                 cairo_set_source (cr, pattern);
781                 cairo_stroke (cr);
782                 cairo_pattern_destroy (pattern);
783         }
784 }
785
786 static void
787 clearlooks_gummy_draw_separator (cairo_t                   *cr,
788                                  const ClearlooksColors    *colors,
789                                  const WidgetParameters    *widget,
790                                  const SeparatorParameters *separator,
791                                  int x, int y, int width, int height)
792 {
793         CairoColor hilight;
794         CairoColor color = colors->shade[3];
795
796         (void) widget;
797         ge_shade_color (&color, 1.3, &hilight);
798
799         cairo_save (cr);
800         cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
801
802         if (separator->horizontal)
803         {
804                 cairo_set_line_width  (cr, 1.0);
805                 cairo_translate       (cr, x, y+0.5);
806
807                 cairo_move_to         (cr, 0.0,   0.0);
808                 cairo_line_to         (cr, width, 0.0);
809                 ge_cairo_set_color    (cr, &color);
810                 cairo_stroke          (cr);
811
812                 cairo_move_to         (cr, 0.0,   1.0);
813                 cairo_line_to         (cr, width, 1.0);
814                 ge_cairo_set_color    (cr, &hilight);
815                 cairo_stroke          (cr);
816         }
817         else
818         {
819                 cairo_set_line_width  (cr, 1.0);
820                 cairo_translate       (cr, x+0.5, y);
821
822                 cairo_move_to         (cr, 0.0, 0.0);
823                 cairo_line_to         (cr, 0.0, height);
824                 ge_cairo_set_color    (cr, &color);
825                 cairo_stroke          (cr);
826
827                 cairo_move_to         (cr, 1.0, 0.0);
828                 cairo_line_to         (cr, 1.0, height);
829                 ge_cairo_set_color    (cr, &hilight);
830                 cairo_stroke          (cr);
831         }
832
833         cairo_restore (cr);
834 }
835
836 static void
837 clearlooks_gummy_draw_slider (cairo_t                *cr,
838                               const ClearlooksColors *colors,
839                               const WidgetParameters *params,
840                               int x, int y, int width, int height)
841 {
842         const CairoColor *border = &colors->shade[7];
843         CairoColor  fill;
844         CairoColor  shade1, shade2, shade3;
845         cairo_pattern_t *pattern;
846         int bar_x, i;
847         int shift_x;
848
849         cairo_set_line_width (cr, 1.0); 
850         cairo_translate      (cr, x, y);
851
852         cairo_translate (cr, -0.5, -0.5);
853
854         ge_shade_color (&colors->bg[params->state_type], 1.0, &fill);
855         if (params->prelight)
856                 ge_shade_color (&fill, 1.04, &fill);
857
858         ge_shade_color (&fill, SHADE_TOP, &shade1);
859         ge_shade_color (&fill, SHADE_CENTER_TOP, &shade2);
860         ge_shade_color (&fill, SHADE_BOTTOM, &shade3);
861
862         pattern = cairo_pattern_create_linear (1, 1, 1, height-2);
863         cairo_pattern_add_color_stop_rgb(pattern, 0,   shade1.r, shade1.g, shade1.b);
864         cairo_pattern_add_color_stop_rgb(pattern, 0.5, shade2.r, shade2.g, shade2.b);
865         cairo_pattern_add_color_stop_rgb(pattern, 0.5, fill.r, fill.g, fill.b);
866         cairo_pattern_add_color_stop_rgb(pattern, 1.0, shade3.r, shade3.g, shade3.b);
867         cairo_rectangle (cr, 1, 1, width-2, height-2);
868         cairo_set_source (cr, pattern);
869         cairo_fill (cr);
870         cairo_pattern_destroy (pattern);
871
872         clearlooks_set_mixed_color (cr, border, &fill, 0.2);
873         if (params->prelight)
874                 ge_cairo_set_color (cr, &colors->spot[2]);
875         ge_cairo_rounded_rectangle (cr, 0.5, 0.5, width-1, height-1, 2.5, params->corners);
876         cairo_stroke (cr);
877
878         /* Handle */
879         shift_x = (width%2 == 0 ? 1 : 0);
880         bar_x = width/2-3+shift_x;
881         cairo_translate (cr, 0.5, 0.5);
882         ge_cairo_set_color (cr, border);
883         for (i=0; i<3-shift_x; i++)
884         {
885                 cairo_move_to (cr, bar_x, 4);
886                 cairo_line_to (cr, bar_x, height-5);
887                 bar_x += 3;
888         }
889         cairo_stroke (cr);
890
891         clearlooks_gummy_draw_top_left_highlight (cr, &fill, params, width, height, 2.0);
892 }
893
894 static void
895 clearlooks_gummy_draw_slider_button (cairo_t                *cr,
896                                      const ClearlooksColors *colors,
897                                      const WidgetParameters *params,
898                                      const SliderParameters *slider,
899                                      int x, int y, int width, int height)
900 {
901         double radius = MIN (params->radius, MIN ((width - 1.0) / 2.0, (height - 1.0) / 2.0));
902
903         cairo_set_line_width (cr, 1.0);
904
905         if (!slider->horizontal)
906                 ge_cairo_exchange_axis (cr, &x, &y, &width, &height);
907
908         cairo_translate (cr, x+0.5, y+0.5);
909
910         params->style_functions->draw_shadow (cr, colors, radius, width-1, height-1);
911         params->style_functions->draw_slider (cr, colors, params, 1, 1, width-2, height-2);
912 }
913
914 static void
915 clearlooks_gummy_draw_scrollbar_stepper (cairo_t                          *cr,
916                                          const ClearlooksColors           *colors,
917                                          const WidgetParameters           *widget,
918                                          const ScrollBarParameters        *scrollbar,
919                                          const ScrollBarStepperParameters *stepper,
920                                          int x, int y, int width, int height)
921 {
922         CairoCorners corners = CR_CORNER_NONE;
923         const CairoColor *border = &colors->shade[scrollbar->has_color ? 7 : 6];
924         CairoColor fill;
925         CairoColor shade1, shade2, shade3;
926         cairo_pattern_t *pattern;
927         double radius = MIN (widget->radius, MIN ((width - 2.0) / 2.0, (height - 2.0) / 2.0));
928
929         if (scrollbar->horizontal)
930         {
931                 if (stepper->stepper == CL_STEPPER_A)
932                         corners = CR_CORNER_TOPLEFT | CR_CORNER_BOTTOMLEFT;
933                 else if (stepper->stepper == CL_STEPPER_D)
934                         corners = CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMRIGHT;
935         }
936         else
937         {
938                 if (stepper->stepper == CL_STEPPER_A)
939                         corners = CR_CORNER_TOPLEFT | CR_CORNER_TOPRIGHT;
940                 else if (stepper->stepper == CL_STEPPER_D)
941                         corners = CR_CORNER_BOTTOMLEFT | CR_CORNER_BOTTOMRIGHT;
942         }
943
944         cairo_translate (cr, x, y);
945         cairo_set_line_width (cr, 1);
946
947         ge_cairo_rounded_rectangle (cr, 1, 1, width-2, height-2, radius, corners);
948
949         if (scrollbar->horizontal)
950                 pattern = cairo_pattern_create_linear (0, 0, 0, height);
951         else
952                 pattern = cairo_pattern_create_linear (0, 0, width, 0);
953
954         fill = colors->bg[widget->state_type];
955         ge_shade_color(&fill, SHADE_TOP, &shade1);
956         ge_shade_color(&fill, SHADE_CENTER_TOP, &shade2); 
957         ge_shade_color(&fill, SHADE_BOTTOM, &shade3); 
958
959         cairo_pattern_add_color_stop_rgb(pattern, 0,   shade1.r, shade1.g, shade1.b);
960         cairo_pattern_add_color_stop_rgb(pattern, 0.5, shade2.r, shade2.g, shade2.b);
961         cairo_pattern_add_color_stop_rgb(pattern, 0.5, fill.r, fill.g, fill.b);
962         cairo_pattern_add_color_stop_rgb(pattern, 1.0, shade3.r, shade3.g, shade3.b);
963         cairo_set_source (cr, pattern);
964         cairo_fill (cr);
965         cairo_pattern_destroy (pattern);
966
967         cairo_translate (cr, 0.5, 0.5);
968         clearlooks_gummy_draw_top_left_highlight (cr, &fill, widget, width, height, (stepper->stepper == CL_STEPPER_A) ? radius : 0);
969         cairo_translate (cr, -0.5, -0.5);
970
971         ge_cairo_rounded_rectangle (cr, 0.5, 0.5, width-1, height-1, radius, corners);
972         clearlooks_set_mixed_color (cr, border, &fill, 0.2);
973         cairo_stroke (cr);
974
975         cairo_translate (cr, 0.5, 0.5);
976 }
977
978 static void
979 clearlooks_gummy_draw_scrollbar_slider (cairo_t                   *cr,
980                                         const ClearlooksColors    *colors,
981                                         const WidgetParameters    *widget,
982                                         const ScrollBarParameters *scrollbar,
983                                         int x, int y, int width, int height)
984 {
985         CairoColor fill = scrollbar->color;
986         CairoColor border, handles;
987         CairoColor hilight;
988         CairoColor shade1, shade2, shade3;
989         cairo_pattern_t *pattern;
990         int bar_x, i;
991
992         gdouble hue_scroll, brightness_scroll, saturation_scroll;
993         gdouble hue_bg, brightness_bg, saturation_bg;
994
995         ge_hsb_from_color (&fill, &hue_scroll, &saturation_scroll, &brightness_scroll);
996         ge_hsb_from_color (&colors->bg[0], &hue_bg, &saturation_bg, &brightness_bg);
997
998         /* Set the right color for border and handles */
999         if ((fabs(saturation_scroll - saturation_bg) < 0.30) &&
1000             (fabs(brightness_scroll - brightness_bg) < 0.20))
1001                 ge_shade_color (&fill, 0.475, &border);
1002         else
1003                 ge_shade_color (&fill, 0.575, &border);
1004         /* The following lines increase contrast when the HUE is between 25 and 195, */
1005         /* fixing a LOT of colorschemes! */
1006         if (scrollbar->has_color && (hue_scroll < 195) && (hue_scroll > 25))
1007                 ge_shade_color (&border, 0.85, &border);
1008
1009         handles = border;
1010         ge_mix_color (&border, &fill, scrollbar->has_color? 0.3 : 0.2, &border);
1011
1012         if (scrollbar->junction & CL_JUNCTION_BEGIN)
1013         {
1014                 if (scrollbar->horizontal)
1015                 {
1016                         x -= 1;
1017                         width += 1;
1018                 }
1019                 else
1020                 {
1021                         y -= 1;
1022                         height += 1;
1023                 }
1024         }
1025         if (scrollbar->junction & CL_JUNCTION_END)
1026         {
1027                 if (scrollbar->horizontal)
1028                         width += 1;
1029                 else
1030                         height += 1;
1031         }
1032
1033         if (!scrollbar->horizontal)
1034                 ge_cairo_exchange_axis (cr, &x, &y, &width, &height);
1035
1036         cairo_translate (cr, x, y);
1037
1038         if (widget->prelight)
1039                 ge_shade_color (&fill, 1.04, &fill);
1040
1041         cairo_set_line_width (cr, 1);
1042
1043         ge_shade_color (&fill, TOPLEFT_HIGHLIGHT_SHADE, &hilight);
1044         ge_shade_color (&fill, SHADE_TOP, &shade1);
1045         ge_shade_color (&fill, SHADE_CENTER_TOP, &shade2);
1046         ge_shade_color (&fill, SHADE_BOTTOM, &shade3);
1047
1048         pattern = cairo_pattern_create_linear (1, 1, 1, height-2);
1049         cairo_pattern_add_color_stop_rgb (pattern, 0,   shade1.r, shade1.g, shade1.b);
1050         cairo_pattern_add_color_stop_rgb (pattern, 0.5, shade2.r, shade2.g, shade2.b);
1051         cairo_pattern_add_color_stop_rgb (pattern, 0.5, fill.r,  fill.g,  fill.b);
1052         cairo_pattern_add_color_stop_rgb (pattern, 1,   shade3.r, shade3.g, shade3.b);
1053         cairo_rectangle (cr, 1, 1, width-2, height-2);
1054         cairo_set_source (cr, pattern);
1055         cairo_fill (cr);
1056         cairo_pattern_destroy (pattern);
1057
1058         if (scrollbar->has_color) 
1059         {
1060                 cairo_set_source_rgba (cr, hilight.r, hilight.g, hilight.b, 0.2);
1061                 ge_cairo_stroke_rectangle (cr, 1.5, 1.5, width-3, height-3);
1062         }
1063         else
1064         {
1065                 cairo_move_to (cr, 1.5, height-1.5);
1066                 cairo_line_to (cr, 1.5, 1.5);
1067                 cairo_line_to (cr, width-1.5, 1.5);
1068                 cairo_set_source_rgba (cr, hilight.r, hilight.g, hilight.b, TOPLEFT_HIGHLIGHT_ALPHA);
1069                 cairo_stroke(cr);
1070         }
1071
1072         ge_cairo_set_color (cr, &border);
1073         ge_cairo_stroke_rectangle (cr, 0.5, 0.5, width-1, height-1);
1074
1075         /* Handle */
1076         bar_x = width/2 - 4;
1077         cairo_translate(cr, 0.5, 0.5);
1078         ge_cairo_set_color (cr, &handles);
1079         for (i=0; i<3; i++)
1080         {
1081                 cairo_move_to (cr, bar_x, 5);
1082                 cairo_line_to (cr, bar_x, height-6);
1083                 bar_x += 3;
1084         }
1085         cairo_stroke (cr);
1086 }
1087
1088 static void
1089 clearlooks_gummy_draw_list_view_header (cairo_t                        *cr,
1090                                         const ClearlooksColors         *colors,
1091                                         const WidgetParameters         *params,
1092                                         const ListViewHeaderParameters *header,
1093                                         int x, int y, int width, int height)
1094 {
1095 /*
1096         CairoColor *border = !params->prelight? (CairoColor*)&colors->shade[4] : (CairoColor*)&colors->spot[1];
1097 */
1098         const CairoColor *border = &colors->shade[4];
1099         const CairoColor *fill   = &colors->bg[params->state_type];
1100         CairoColor hilight;
1101         CairoColor shade1, shade2, shade3;
1102
1103         cairo_pattern_t *pattern;
1104
1105         ge_shade_color (fill, 1.11, &hilight);
1106         ge_shade_color (fill, LISTVIEW_SHADE_TOP, &shade1);
1107         ge_shade_color (fill, LISTVIEW_SHADE_CENTER_TOP, &shade2);
1108         ge_shade_color (fill, LISTVIEW_SHADE_BOTTOM, &shade3);
1109
1110         cairo_translate (cr, x, y);
1111         cairo_set_line_width (cr, 1.0);
1112
1113         /* Draw the fill */
1114         pattern = cairo_pattern_create_linear (0, 0, 0, height);
1115         cairo_pattern_add_color_stop_rgb (pattern, 0.0, shade1.r, shade1.g, shade1.b);
1116         cairo_pattern_add_color_stop_rgb (pattern, 0.5, shade2.r, shade2.g, shade2.b);
1117         cairo_pattern_add_color_stop_rgb (pattern, 0.5, fill->r, fill->g, fill->b);
1118         cairo_pattern_add_color_stop_rgb (pattern, 1.0-1.0/height, shade3.r, shade3.g, shade3.b);
1119         cairo_pattern_add_color_stop_rgb (pattern, 1.0-1.0/height, border->r, border->g, border->b);
1120         cairo_pattern_add_color_stop_rgb (pattern, 1.0, border->r, border->g, border->b);
1121
1122         cairo_set_source (cr, pattern);
1123         cairo_rectangle (cr, 0, 0, width, height);
1124         cairo_fill (cr);
1125
1126         cairo_pattern_destroy (pattern);
1127
1128         /* Draw highlight */
1129         if (header->order == CL_ORDER_FIRST)
1130         {
1131                 cairo_move_to (cr, 0.5, height-1.5);
1132                 cairo_line_to (cr, 0.5, 0.5);
1133         }
1134         else
1135                 cairo_move_to (cr, 0.0, 0.5);
1136
1137         cairo_line_to (cr, width, 0.5);
1138
1139         ge_cairo_set_color (cr, &hilight);
1140         cairo_stroke (cr);
1141
1142         /* Draw resize grip */
1143         if ((params->ltr && header->order != CL_ORDER_LAST) ||
1144             (!params->ltr && header->order != CL_ORDER_FIRST) || header->resizable)
1145         {
1146                 SeparatorParameters separator;
1147                 separator.horizontal = FALSE;
1148
1149                 if (params->ltr)
1150                         params->style_functions->draw_separator (cr, colors, params, &separator,
1151                                                                  width-1.5, 4.0, 2, height-8.0);
1152                 else
1153                         params->style_functions->draw_separator (cr, colors, params, &separator,
1154                                                                  1.5, 4.0, 2, height-8.0);
1155         }
1156 }
1157
1158 static void
1159 clearlooks_gummy_draw_toolbar (cairo_t                 *cr,
1160                                const ClearlooksColors  *colors,
1161                                const WidgetParameters  *widget,
1162                                const ToolbarParameters *toolbar,
1163                                int x, int y, int width, int height)
1164 {
1165         CairoColor light;
1166         const CairoColor *dark;
1167         const CairoColor *fill = &colors->bg[GTK_STATE_NORMAL];
1168
1169         (void) widget;
1170
1171         dark = &colors->shade[3];
1172
1173         ge_shade_color (fill, toolbar->style == 1 ? 1.1 : 1.05, &light);
1174
1175         cairo_set_line_width (cr, 1.0);
1176         cairo_translate (cr, x, y);
1177
1178         if (toolbar->style == 1) /* Enable Extra features */
1179         {
1180                 cairo_pattern_t *pattern;
1181                 CairoColor shade1, shade2, shade3;
1182
1183                 ge_shade_color (fill, TOOLBAR_SHADE_TOP, &shade1);
1184                 ge_shade_color (fill, TOOLBAR_SHADE_CENTER_TOP, &shade2);
1185                 ge_shade_color (fill, TOOLBAR_SHADE_BOTTOM, &shade3);
1186
1187                 /* Draw the fill */
1188                 pattern = cairo_pattern_create_linear (0, 0, 0, height);
1189                 cairo_pattern_add_color_stop_rgb (pattern, 0.0, shade1.r, shade1.g, shade1.b);
1190                 cairo_pattern_add_color_stop_rgb (pattern, 0.5, shade2.r, shade2.g, shade2.b);
1191                 cairo_pattern_add_color_stop_rgb (pattern, 0.5, fill->r, fill->g, fill->b);
1192                 cairo_pattern_add_color_stop_rgb (pattern, 1.0, shade3.r, shade3.g, shade3.b);
1193
1194                 cairo_set_source (cr, pattern);
1195                 cairo_rectangle (cr, 0, 0, width, height);
1196                 cairo_fill (cr);
1197
1198                 cairo_pattern_destroy (pattern);
1199         }
1200         else /* Flat */
1201         {
1202                 ge_cairo_set_color (cr, fill);
1203                 cairo_paint (cr);
1204         }
1205
1206         if (!toolbar->topmost)
1207         {
1208                 /* Draw highlight */
1209                 cairo_move_to       (cr, 0, 0.5);
1210                 cairo_line_to       (cr, width-1, 0.5);
1211                 ge_cairo_set_color  (cr, &light);
1212                 cairo_stroke        (cr);
1213         }
1214
1215         /* Draw shadow */
1216         cairo_move_to       (cr, 0, height-0.5);
1217         cairo_line_to       (cr, width-1, height-0.5);
1218         ge_cairo_set_color  (cr, dark);
1219         cairo_stroke        (cr);
1220 }
1221
1222 static void
1223 clearlooks_gummy_draw_menuitem (cairo_t                *cr,
1224                                 const ClearlooksColors *colors,
1225                                 const WidgetParameters *params,
1226                                 int x, int y, int width, int height)
1227 {
1228         const CairoColor *fill = &colors->spot[1];
1229         const CairoColor *border = &colors->spot[2];
1230         CairoColor shade1, shade2, shade3;
1231         cairo_pattern_t *pattern;
1232
1233         ge_shade_color (fill, SHADE_TOP, &shade1);
1234         ge_shade_color (fill, SHADE_CENTER_TOP, &shade2);
1235         ge_shade_color (fill, SHADE_BOTTOM, &shade3);
1236         cairo_set_line_width (cr, 1.0);
1237
1238         ge_cairo_rounded_rectangle (cr, x+0.5, y+0.5, width - 1, height - 1, params->radius, params->corners);
1239
1240         pattern = cairo_pattern_create_linear (x, y, x, y + height);
1241         cairo_pattern_add_color_stop_rgb (pattern, 0,   shade1.r, shade1.g, shade1.b);
1242         cairo_pattern_add_color_stop_rgb (pattern, 0.5, shade2.r, shade2.g, shade2.b);
1243         cairo_pattern_add_color_stop_rgb (pattern, 0.5, fill->r,  fill->g,  fill->b);
1244         cairo_pattern_add_color_stop_rgb (pattern, 1,   shade3.r, shade3.g, shade3.b);
1245
1246         cairo_set_source (cr, pattern);
1247         cairo_fill_preserve  (cr);
1248         cairo_pattern_destroy (pattern);
1249
1250         ge_cairo_set_color (cr, border);
1251         cairo_stroke (cr);
1252 }
1253
1254 static void
1255 clearlooks_gummy_draw_menubaritem (cairo_t                *cr,
1256                                    const ClearlooksColors *colors,
1257                                    const WidgetParameters *params,
1258                                    int x, int y, int width, int height)
1259 {
1260         const CairoColor *fill = &colors->spot[1];
1261         const CairoColor *border = &colors->spot[2];
1262         CairoColor shade1, shade2, shade3;
1263         cairo_pattern_t *pattern;
1264
1265         ge_shade_color (fill, SHADE_TOP, &shade1);
1266         ge_shade_color (fill, SHADE_CENTER_TOP, &shade2);
1267         ge_shade_color (fill, SHADE_BOTTOM, &shade3);
1268         cairo_set_line_width (cr, 1.0);
1269
1270         ge_cairo_rounded_rectangle (cr, x+0.5, y+0.5, width - 1, height - 1, params->radius, params->corners);
1271
1272         pattern = cairo_pattern_create_linear (x, y, x, y + height);
1273         cairo_pattern_add_color_stop_rgb (pattern, 0,   shade1.r, shade1.g, shade1.b);
1274         cairo_pattern_add_color_stop_rgb (pattern, 0.5, shade2.r, shade2.g, shade2.b);
1275         cairo_pattern_add_color_stop_rgb (pattern, 0.5, fill->r,  fill->g,  fill->b);
1276         cairo_pattern_add_color_stop_rgb (pattern, 1,   shade3.r, shade3.g, shade3.b);
1277
1278         cairo_set_source (cr, pattern);
1279         cairo_fill_preserve  (cr);
1280         cairo_pattern_destroy (pattern);
1281
1282         ge_cairo_set_color (cr, border);
1283         cairo_stroke (cr);
1284 }
1285
1286 static void
1287 clearlooks_gummy_draw_selected_cell (cairo_t                *cr,
1288                                      const ClearlooksColors *colors,
1289                                      const WidgetParameters *params,
1290                                      int x, int y, int width, int height)
1291 {
1292         CairoColor color;
1293
1294         if (params->focus)
1295                 color = colors->base[params->state_type];
1296         else
1297                 color = colors->base[GTK_STATE_ACTIVE];
1298
1299         clearlooks_draw_gummy_gradient (cr, x, y, width, height, &color, params->disabled, 0.0, CR_CORNER_NONE);
1300 }
1301
1302 static void
1303 clearlooks_gummy_draw_statusbar (cairo_t                *cr,
1304                                  const ClearlooksColors *colors,
1305                                  const WidgetParameters *widget,
1306                                  int x, int y, int width, int height)
1307 {
1308         CairoColor hilight;
1309         const CairoColor *dark = &colors->shade[3];
1310
1311         (void) widget;
1312         (void) height;
1313
1314         ge_shade_color (dark, 1.3, &hilight);
1315
1316         cairo_set_line_width  (cr, 1);
1317         cairo_translate       (cr, x, y+0.5);
1318         cairo_move_to         (cr, 0, 0);
1319         cairo_line_to         (cr, width, 0);
1320         ge_cairo_set_color    (cr, dark);
1321         cairo_stroke          (cr);
1322
1323         cairo_translate       (cr, 0, 1);
1324         cairo_move_to         (cr, 0, 0);
1325         cairo_line_to         (cr, width, 0);
1326         ge_cairo_set_color    (cr, &hilight);
1327         cairo_stroke          (cr);
1328 }
1329
1330 static void
1331 clearlooks_gummy_draw_radiobutton (cairo_t                  *cr,
1332                                    const ClearlooksColors   *colors,
1333                                    const WidgetParameters   *widget,
1334                                    const CheckboxParameters *checkbox,
1335                                    int x, int y, int width, int height)
1336 {
1337         const CairoColor *border;
1338         const CairoColor *dot;
1339         CairoColor shadow;
1340         CairoColor highlight;
1341         cairo_pattern_t *pt;
1342         gboolean inconsistent;
1343         gboolean draw_bullet = (checkbox->shadow_type == GTK_SHADOW_IN);
1344
1345         (void) width;
1346         (void) height;
1347
1348         inconsistent = (checkbox->shadow_type == GTK_SHADOW_ETCHED_IN);
1349         draw_bullet |= inconsistent;
1350
1351         if (widget->disabled)
1352         {
1353                 border = &colors->shade[5];
1354                 dot    = &colors->shade[6];
1355         }
1356         else
1357         {
1358                 if (widget->prelight)
1359                         border = &colors->spot[2];
1360                 else
1361                         border = &colors->shade[6];
1362                 dot    = &colors->text[0];
1363         }
1364
1365         ge_shade_color (&widget->parentbg, 0.9, &shadow);
1366         ge_shade_color (&widget->parentbg, 1.1, &highlight);
1367
1368         pt = cairo_pattern_create_linear (0, 0, 13, 13);
1369         cairo_pattern_add_color_stop_rgb (pt, 0.0, shadow.r, shadow.b, shadow.g);
1370         cairo_pattern_add_color_stop_rgba (pt, 0.5, shadow.r, shadow.b, shadow.g, 0.5);
1371         cairo_pattern_add_color_stop_rgba (pt, 0.5, highlight.r, highlight.g, highlight.b, 0.5);
1372         cairo_pattern_add_color_stop_rgb (pt, 1.0, highlight.r, highlight.g, highlight.b);
1373
1374         cairo_translate (cr, x, y);
1375
1376         cairo_set_line_width (cr, 2);
1377         cairo_arc (cr, 7, 7, 6, 0, G_PI*2);
1378         cairo_set_source (cr, pt);
1379         cairo_stroke (cr);
1380         cairo_pattern_destroy (pt);
1381
1382         cairo_set_line_width (cr, 1);
1383
1384         cairo_arc (cr, 7, 7, 5.5, 0, G_PI*2);
1385
1386         if (!widget->disabled)
1387         {
1388                 if (widget->prelight)
1389                         clearlooks_set_mixed_color (cr, &colors->base[0], &colors->spot[1], 0.5);
1390                 else
1391                         ge_cairo_set_color (cr, &colors->base[0]);
1392                 cairo_fill_preserve (cr);
1393         }
1394
1395         ge_cairo_set_color (cr, border);
1396         cairo_stroke (cr);
1397
1398         if (draw_bullet)
1399         {
1400                 if (inconsistent)
1401                 {
1402                         cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
1403                         cairo_set_line_width (cr, 4);
1404
1405                         cairo_move_to(cr, 5, 7);
1406                         cairo_line_to(cr, 9, 7);
1407
1408                         ge_cairo_set_color (cr, dot);
1409                         cairo_stroke (cr);
1410                 }
1411                 else
1412                 {
1413                         cairo_arc (cr, 7, 7, 3, 0, G_PI*2);
1414                         ge_cairo_set_color (cr, dot);
1415                         cairo_fill (cr);
1416
1417                         cairo_arc (cr, 6, 6, 1, 0, G_PI*2);
1418                         cairo_set_source_rgba (cr, highlight.r, highlight.g, highlight.b, 0.5);
1419                         cairo_fill (cr);
1420                 }
1421         }
1422 }
1423
1424 static void
1425 clearlooks_gummy_draw_checkbox (cairo_t                  *cr,
1426                                 const ClearlooksColors   *colors,
1427                                 const WidgetParameters   *widget,
1428                                 const CheckboxParameters *checkbox,
1429                                 int x, int y, int width, int height)
1430 {
1431         const CairoColor *border;
1432         const CairoColor *dot; 
1433         gboolean inconsistent = FALSE;
1434         gboolean draw_bullet = (checkbox->shadow_type == GTK_SHADOW_IN);
1435
1436         inconsistent = (checkbox->shadow_type == GTK_SHADOW_ETCHED_IN);
1437         draw_bullet |= inconsistent;
1438
1439         if (widget->disabled)
1440         {
1441                 border = &colors->shade[5];
1442                 dot    = &colors->shade[6];
1443         }
1444         else
1445         {
1446                 if (widget->prelight)
1447                         border = &colors->spot[2];
1448                 else            
1449                         border = &colors->shade[6];
1450                 dot    = &colors->text[GTK_STATE_NORMAL];
1451         }
1452
1453         cairo_translate (cr, x, y);
1454         cairo_set_line_width (cr, 1);
1455
1456         if (widget->xthickness > 2 && widget->ythickness > 2)
1457         {
1458                 widget->style_functions->draw_inset (cr, &widget->parentbg, 0.5, 0.5, 
1459                                   width-1, height-1, (widget->radius > 0)? 1 : 0, CR_CORNER_ALL);
1460                 
1461                 /* Draw the rectangle for the checkbox itself */
1462                 ge_cairo_rounded_rectangle (cr, 1.5, 1.5, 
1463                                   width-3, height-3, (widget->radius > 0)? 1 : 0, CR_CORNER_ALL);
1464         }
1465         else
1466         {
1467                 /* Draw the rectangle for the checkbox itself */
1468                 ge_cairo_rounded_rectangle (cr, 0.5, 0.5, 
1469                                   width-1, height-1, (widget->radius > 0)? 1 : 0, CR_CORNER_ALL);
1470         }
1471         
1472         if (!widget->disabled)
1473         {               
1474                 if (widget->prelight)
1475                         clearlooks_set_mixed_color (cr, &colors->base[0], &colors->spot[1], 0.5);
1476                 else            
1477                         ge_cairo_set_color (cr, &colors->base[0]);
1478                 cairo_fill_preserve (cr);
1479         }
1480
1481         ge_cairo_set_color (cr, border);
1482         cairo_stroke (cr);
1483
1484         if (draw_bullet)
1485         {
1486                 if (inconsistent) /* Inconsistent */
1487                 {
1488                         cairo_set_line_width (cr, 2.0);
1489                         cairo_move_to (cr, 3, height*0.5);
1490                         cairo_line_to (cr, width-3, height*0.5);
1491                 }
1492                 else
1493                 {
1494                         cairo_set_line_width (cr, 1.7);
1495                         cairo_move_to (cr, 0.5 + (width*0.2), (height*0.5));
1496                         cairo_line_to (cr, 0.5 + (width*0.4), (height*0.7));
1497
1498                         cairo_curve_to (cr, 0.5 + (width*0.4), (height*0.7),
1499                                             0.5 + (width*0.5), (height*0.4),
1500                                             0.5 + (width*0.70), (height*0.25));
1501
1502                 }
1503
1504                 ge_cairo_set_color (cr, dot);
1505                 cairo_stroke (cr);
1506         }
1507 }
1508
1509 void
1510 clearlooks_register_style_gummy (ClearlooksStyleFunctions *functions)
1511 {
1512         functions->draw_button              = clearlooks_gummy_draw_button;
1513         functions->draw_entry               = clearlooks_gummy_draw_entry;
1514         functions->draw_progressbar_trough  = clearlooks_gummy_draw_progressbar_trough;
1515         functions->draw_progressbar_fill    = clearlooks_gummy_draw_progressbar_fill;
1516         functions->draw_scale_trough        = clearlooks_gummy_draw_scale_trough;
1517         functions->draw_tab                 = clearlooks_gummy_draw_tab;
1518         functions->draw_separator           = clearlooks_gummy_draw_separator;
1519         functions->draw_slider              = clearlooks_gummy_draw_slider;
1520         functions->draw_slider_button       = clearlooks_gummy_draw_slider_button;
1521         functions->draw_scrollbar_stepper   = clearlooks_gummy_draw_scrollbar_stepper;
1522         functions->draw_scrollbar_slider    = clearlooks_gummy_draw_scrollbar_slider;
1523         functions->draw_list_view_header    = clearlooks_gummy_draw_list_view_header;
1524         functions->draw_toolbar             = clearlooks_gummy_draw_toolbar;
1525         functions->draw_menuitem            = clearlooks_gummy_draw_menuitem;
1526         functions->draw_menubaritem         = clearlooks_gummy_draw_menubaritem;
1527         functions->draw_selected_cell       = clearlooks_gummy_draw_selected_cell;
1528         functions->draw_statusbar           = clearlooks_gummy_draw_statusbar;
1529         functions->draw_checkbox            = clearlooks_gummy_draw_checkbox;
1530         functions->draw_radiobutton         = clearlooks_gummy_draw_radiobutton;
1531 }