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