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