SVG of thorsten's editor track/bus list icons
[ardour2.git] / libs / clearlooks-newer / clearlooks_draw.c
blobc614e90918c3293cb54070273cfbf4ee0009b958
1 /* Clearlooks theme engine
2 * Copyright (C) 2006 Richard Stellingwerff
3 * Copyright (C) 2006 Daniel Borgman
4 * Copyright (C) 2007 Benjamin Berg
5 * Copyright (C) 2007 Andrea Cimitan
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 #include "clearlooks_draw.h"
25 #include "clearlooks_style.h"
26 #include "clearlooks_types.h"
28 #include "support.h"
29 #include <ge-support.h>
30 #include <math.h>
32 #ifndef M_PI
33 #define M_PI 3.14159265358979323846
34 #endif
36 #include <cairo.h>
38 typedef void (*menubar_draw_proto) (cairo_t *cr,
39 const ClearlooksColors *colors,
40 const WidgetParameters *params,
41 const MenuBarParameters *menubar,
42 int x, int y, int width, int height);
44 static void
45 clearlooks_draw_inset (cairo_t *cr,
46 const CairoColor *bg_color,
47 double x, double y, double w, double h,
48 double radius, uint8 corners)
50 CairoColor shadow;
51 CairoColor highlight;
53 /* not really sure of shading ratios... we will think */
54 ge_shade_color (bg_color, 0.94, &shadow);
55 ge_shade_color (bg_color, 1.06, &highlight);
57 /* highlight */
58 cairo_move_to (cr, x + w + (radius * -0.2928932188), y - (radius * -0.2928932188)); /* 0.2928932... 1-sqrt(2)/2 gives middle of curve */
60 if (corners & CR_CORNER_TOPRIGHT)
61 cairo_arc (cr, x + w - radius, y + radius, radius, G_PI * 1.75, G_PI * 2);
62 else
63 cairo_line_to (cr, x + w, y);
65 if (corners & CR_CORNER_BOTTOMRIGHT)
66 cairo_arc (cr, x + w - radius, y + h - radius, radius, 0, G_PI * 0.5);
67 else
68 cairo_line_to (cr, x + w, y + h);
70 if (corners & CR_CORNER_BOTTOMLEFT)
71 cairo_arc (cr, x + radius, y + h - radius, radius, G_PI * 0.5, G_PI * 0.75);
72 else
73 cairo_line_to (cr, x, y + h);
75 ge_cairo_set_color (cr, &highlight);
76 cairo_stroke (cr);
78 /* shadow */
79 cairo_move_to (cr, x + (radius * 0.2928932188), y + h + (radius * -0.2928932188));
81 if (corners & CR_CORNER_BOTTOMLEFT)
82 cairo_arc (cr, x + radius, y + h - radius, radius, M_PI * 0.75, M_PI);
83 else
84 cairo_line_to (cr, x, y + h);
86 if (corners & CR_CORNER_TOPLEFT)
87 cairo_arc (cr, x + radius, y + radius, radius, M_PI, M_PI * 1.5);
88 else
89 cairo_line_to (cr, x, y);
91 if (corners & CR_CORNER_TOPRIGHT)
92 cairo_arc (cr, x + w - radius, y + radius, radius, M_PI * 1.5, M_PI * 1.75);
93 else
94 cairo_line_to (cr, x + w, y);
96 ge_cairo_set_color (cr, &shadow);
97 cairo_stroke (cr);
100 static void
101 clearlooks_draw_shadow (cairo_t *cr, const ClearlooksColors *colors, gfloat radius, int width, int height)
103 CairoColor shadow;
104 ge_shade_color (&colors->shade[6], 0.92, &shadow);
106 cairo_set_line_width (cr, 1.0);
108 cairo_set_source_rgba (cr, shadow.r, shadow.g, shadow.b, 0.1);
110 cairo_move_to (cr, width, radius);
111 ge_cairo_rounded_corner (cr, width, height, radius, CR_CORNER_BOTTOMRIGHT);
112 cairo_line_to (cr, radius, height);
114 cairo_stroke (cr);
117 static void
118 clearlooks_draw_top_left_highlight (cairo_t *cr, const CairoColor *color,
119 const WidgetParameters *params,
120 int width, int height, gdouble radius)
122 CairoColor hilight;
124 double light_top = params->ythickness-1,
125 light_bottom = height - params->ythickness - 1,
126 light_left = params->xthickness-1,
127 light_right = width - params->xthickness - 1;
129 ge_shade_color (color, 1.3, &hilight);
130 cairo_move_to (cr, light_left, light_bottom - (int)radius/2);
132 ge_cairo_rounded_corner (cr, light_left, light_top, radius, params->corners & CR_CORNER_TOPLEFT);
134 cairo_line_to (cr, light_right - (int)radius/2, light_top);
135 cairo_set_source_rgba (cr, hilight.r, hilight.g, hilight.b, 0.5);
136 cairo_stroke (cr);
139 #ifdef DEVELOPMENT
140 #warning seems to be very slow in scrollbar_stepper
141 #endif
143 static void
144 clearlooks_draw_highlight_and_shade (cairo_t *cr, const ClearlooksColors *colors,
145 const ShadowParameters *params,
146 int width, int height, gdouble radius)
148 CairoColor hilight;
149 CairoColor shadow;
150 uint8 corners = params->corners;
151 double x = 1.0;
152 double y = 1.0;
154 ge_shade_color (&colors->bg[GTK_STATE_NORMAL], 1.06, &hilight);
155 ge_shade_color (&colors->bg[GTK_STATE_NORMAL], 0.94, &shadow);
157 width -= 3;
158 height -= 3;
160 cairo_save (cr);
162 /* Top/Left highlight */
163 if (corners & CR_CORNER_BOTTOMLEFT)
164 cairo_move_to (cr, x, y+height-radius);
165 else
166 cairo_move_to (cr, x, y+height);
168 ge_cairo_rounded_corner (cr, x, y, radius, corners & CR_CORNER_TOPLEFT);
170 if (corners & CR_CORNER_TOPRIGHT)
171 cairo_line_to (cr, x+width-radius, y);
172 else
173 cairo_line_to (cr, x+width, y);
175 if (params->shadow & CL_SHADOW_OUT)
176 ge_cairo_set_color (cr, &hilight);
177 else
178 ge_cairo_set_color (cr, &shadow);
180 cairo_stroke (cr);
182 /* Bottom/Right highlight -- this includes the corners */
183 cairo_move_to (cr, x+width-radius, y); /* topright and by radius to the left */
184 ge_cairo_rounded_corner (cr, x+width, y, radius, corners & CR_CORNER_TOPRIGHT);
185 ge_cairo_rounded_corner (cr, x+width, y+height, radius, corners & CR_CORNER_BOTTOMRIGHT);
186 ge_cairo_rounded_corner (cr, x, y+height, radius, corners & CR_CORNER_BOTTOMLEFT);
188 if (params->shadow & CL_SHADOW_OUT)
189 ge_cairo_set_color (cr, &shadow);
190 else
191 ge_cairo_set_color (cr, &hilight);
193 cairo_stroke (cr);
195 cairo_restore (cr);
198 static void
199 clearlooks_set_border_gradient (cairo_t *cr, const CairoColor *color, double hilight, int width, int height)
201 cairo_pattern_t *pattern;
203 CairoColor bottom_shade;
204 ge_shade_color (color, hilight, &bottom_shade);
206 pattern = cairo_pattern_create_linear (0, 0, width, height);
207 cairo_pattern_add_color_stop_rgb (pattern, 0, color->r, color->g, color->b);
208 cairo_pattern_add_color_stop_rgb (pattern, 1, bottom_shade.r, bottom_shade.g, bottom_shade.b);
210 cairo_set_source (cr, pattern);
211 cairo_pattern_destroy (pattern);
214 static void
215 clearlooks_draw_gripdots (cairo_t *cr, const ClearlooksColors *colors, int x, int y,
216 int width, int height, int xr, int yr,
217 float contrast)
219 const CairoColor *dark = &colors->shade[4];
220 CairoColor hilight;
221 int i, j;
222 int xoff, yoff;
224 ge_shade_color (dark, 1.5, &hilight);
226 for ( i = 0; i < xr; i++ )
228 for ( j = 0; j < yr; j++ )
230 xoff = x -(xr * 3 / 2) + 3 * i;
231 yoff = y -(yr * 3 / 2) + 3 * j;
233 cairo_rectangle (cr, width/2+0.5+xoff, height/2+0.5+yoff, 2, 2);
234 cairo_set_source_rgba (cr, hilight.r, hilight.g, hilight.b, 0.8+contrast);
235 cairo_fill (cr);
236 cairo_rectangle (cr, width/2+0.5+xoff, height/2+0.5+yoff, 1, 1);
237 cairo_set_source_rgba (cr, dark->r, dark->g, dark->b, 0.8+contrast);
238 cairo_fill (cr);
243 static void
244 clearlooks_draw_button (cairo_t *cr,
245 const ClearlooksColors *colors,
246 const WidgetParameters *params,
247 int x, int y, int width, int height)
249 double xoffset = 0, yoffset = 0;
250 double radius = params->radius;
251 const CairoColor *fill = &colors->bg[params->state_type];
252 const CairoColor *border_normal = &colors->shade[6];
253 const CairoColor *border_disabled = &colors->shade[4];
255 CairoColor shadow;
256 ge_shade_color (border_normal, 0.925, &shadow);
258 cairo_save (cr);
260 cairo_translate (cr, x, y);
261 cairo_set_line_width (cr, 1.0);
263 if (params->xthickness == 3 || params->ythickness == 3)
265 if (params->xthickness == 3)
266 xoffset = 1;
267 if (params->ythickness == 3)
268 yoffset = 1;
271 radius = MIN (radius, MIN ((width - 2.0 - xoffset * 2.0) / 2.0, (height - 2.0 - yoffset * 2) / 2.0));
273 if (params->xthickness == 3 || params->ythickness == 3)
275 cairo_translate (cr, 0.5, 0.5);
276 params->style_functions->draw_inset (cr, &params->parentbg, 0, 0, width-1, height-1, radius+1, params->corners);
277 cairo_translate (cr, -0.5, -0.5);
280 ge_cairo_rounded_rectangle (cr, xoffset+1, yoffset+1,
281 width-(xoffset*2)-2,
282 height-(yoffset*2)-2,
283 radius, params->corners);
285 if (!params->active)
287 cairo_pattern_t *pattern;
288 gdouble shade_size = ((100.0/height)*8.0)/100.0;
289 CairoColor top_shade, bottom_shade, middle_shade;
291 ge_shade_color (fill, 1.1, &top_shade);
292 ge_shade_color (fill, 0.98, &middle_shade);
293 ge_shade_color (fill, 0.93, &bottom_shade);
295 pattern = cairo_pattern_create_linear (0, 0, 0, height);
296 cairo_pattern_add_color_stop_rgb (pattern, 0.0, top_shade.r, top_shade.g, top_shade.b);
297 cairo_pattern_add_color_stop_rgb (pattern, shade_size, fill->r, fill->g, fill->b);
298 cairo_pattern_add_color_stop_rgb (pattern, 1.0 - shade_size, middle_shade.r, middle_shade.g, middle_shade.b);
299 cairo_pattern_add_color_stop_rgb (pattern, (height-(yoffset*2)-1)/height, bottom_shade.r, bottom_shade.g, bottom_shade.b);
300 cairo_pattern_add_color_stop_rgba (pattern, (height-(yoffset*2)-1)/height, bottom_shade.r, bottom_shade.g, bottom_shade.b, 0.7);
301 cairo_pattern_add_color_stop_rgba (pattern, 1.0, bottom_shade.r, bottom_shade.g, bottom_shade.b, 0.7);
303 cairo_set_source (cr, pattern);
304 cairo_fill (cr);
305 cairo_pattern_destroy (pattern);
307 else
309 cairo_pattern_t *pattern;
311 ge_cairo_set_color (cr, fill);
312 cairo_fill_preserve (cr);
314 pattern = cairo_pattern_create_linear (0, 0, 0, height);
315 cairo_pattern_add_color_stop_rgba (pattern, 0.0, shadow.r, shadow.g, shadow.b, 0.0);
316 cairo_pattern_add_color_stop_rgba (pattern, 0.4, shadow.r, shadow.g, shadow.b, 0.0);
317 cairo_pattern_add_color_stop_rgba (pattern, 1.0, shadow.r, shadow.g, shadow.b, 0.2);
318 cairo_set_source (cr, pattern);
319 cairo_fill_preserve (cr);
320 cairo_pattern_destroy (pattern);
322 pattern = cairo_pattern_create_linear (0, yoffset+1, 0, 3+yoffset);
323 cairo_pattern_add_color_stop_rgba (pattern, 0.0, shadow.r, shadow.g, shadow.b, params->disabled ? 0.125 : 0.3);
324 cairo_pattern_add_color_stop_rgba (pattern, 1.0, shadow.r, shadow.g, shadow.b, 0.0);
325 cairo_set_source (cr, pattern);
326 cairo_fill_preserve (cr);
327 cairo_pattern_destroy (pattern);
329 pattern = cairo_pattern_create_linear (xoffset+1, 0, 3+xoffset, 0);
330 cairo_pattern_add_color_stop_rgba (pattern, 0.0, shadow.r, shadow.g, shadow.b, params->disabled ? 0.125 : 0.3);
331 cairo_pattern_add_color_stop_rgba (pattern, 1.0, shadow.r, shadow.g, shadow.b, 0.0);
332 cairo_set_source (cr, pattern);
333 cairo_fill (cr);
334 cairo_pattern_destroy (pattern);
338 /* Drawing the border */
339 if (!params->active && params->is_default)
341 const CairoColor *l = &colors->shade[4];
342 const CairoColor *d = &colors->shade[4];
343 ge_cairo_set_color (cr, l);
344 ge_cairo_stroke_rectangle (cr, 2.5, 2.5, width-5, height-5);
346 ge_cairo_set_color (cr, d);
347 ge_cairo_stroke_rectangle (cr, 3.5, 3.5, width-7, height-7);
350 ge_cairo_rounded_rectangle (cr, xoffset + 0.5, yoffset + 0.5, width-(xoffset*2)-1, height-(yoffset*2)-1, radius, params->corners);
352 if (params->disabled)
353 ge_cairo_set_color (cr, border_disabled);
354 else
355 if (!params->active)
356 clearlooks_set_border_gradient (cr, border_normal, 1.32, 0, height);
357 else
358 ge_cairo_set_color (cr, border_normal);
360 cairo_stroke (cr);
362 /* Draw the "shadow" */
363 if (!params->active)
365 cairo_translate (cr, 0.5, 0.5);
366 /* Draw right shadow */
367 cairo_move_to (cr, width-params->xthickness, params->ythickness - 1);
368 cairo_line_to (cr, width-params->xthickness, height - params->ythickness - 1);
369 cairo_set_source_rgba (cr, shadow.r, shadow.g, shadow.b, 0.1);
370 cairo_stroke (cr);
372 /* Draw topleft shadow */
373 clearlooks_draw_top_left_highlight (cr, fill, params, width, height, radius);
375 cairo_restore (cr);
378 static void
379 clearlooks_draw_entry (cairo_t *cr,
380 const ClearlooksColors *colors,
381 const WidgetParameters *params,
382 int x, int y, int width, int height)
384 const CairoColor *base = &colors->base[params->state_type];
385 CairoColor border = colors->shade[params->disabled ? 4 : 6];
386 double radius = MIN (params->radius, MIN ((width - 4.0) / 2.0, (height - 4.0) / 2.0));
388 if (params->focus)
389 border = colors->spot[2];
391 cairo_translate (cr, x+0.5, y+0.5);
392 cairo_set_line_width (cr, 1.0);
394 /* Fill the background (shouldn't have to) */
395 cairo_rectangle (cr, -0.5, -0.5, width, height);
396 ge_cairo_set_color (cr, &params->parentbg);
397 cairo_fill (cr);
399 /* Fill the entry's base color (why isn't is large enough by default?) */
400 cairo_rectangle (cr, 1.5, 1.5, width-4, height-4);
401 ge_cairo_set_color (cr, base);
402 cairo_fill (cr);
404 params->style_functions->draw_inset (cr, &params->parentbg, 0, 0, width-1, height-1, radius+1, params->corners);
406 /* Draw the inner shadow */
407 if (params->focus)
409 /* ge_cairo_rounded_rectangle (cr, 2, 2, width-5, height-5, RADIUS-1, params->corners); */
410 ge_cairo_set_color (cr, &colors->spot[0]);
411 ge_cairo_stroke_rectangle (cr, 2, 2, width-5, height-5);
413 else
415 CairoColor shadow;
416 ge_shade_color (&border, 0.925, &shadow);
418 cairo_set_source_rgba (cr, shadow.r, shadow.g, shadow.b, params->disabled ? 0.05 : 0.1);
420 cairo_move_to (cr, 2, height-3);
421 cairo_arc (cr, params->xthickness+RADIUS-1, params->ythickness+RADIUS-1, RADIUS, G_PI, 270*(G_PI/180));
422 cairo_line_to (cr, width-3, 2);*/
423 cairo_move_to (cr, 2, height-3);
424 cairo_line_to (cr, 2, 2);
425 cairo_line_to (cr, width-3, 2);
426 cairo_stroke (cr);
429 ge_cairo_rounded_rectangle (cr, 1, 1, width-3, height-3, radius, params->corners);
430 if (params->focus || params->disabled)
431 ge_cairo_set_color (cr, &border);
432 else
433 clearlooks_set_border_gradient (cr, &border, 1.32, 0, height);
434 cairo_stroke (cr);
437 static void
438 clearlooks_draw_spinbutton (cairo_t *cr,
439 const ClearlooksColors *colors,
440 const WidgetParameters *params,
441 int x, int y, int width, int height)
443 const CairoColor *border = &colors->shade[!params->disabled ? 5 : 3];
444 CairoColor hilight;
446 params->style_functions->draw_button (cr, colors, params, x, y, width, height);
448 ge_shade_color (border, 1.5, &hilight);
450 cairo_translate (cr, x, y);
452 cairo_move_to (cr, params->xthickness + 0.5, (height/2) + 0.5);
453 cairo_line_to (cr, width-params->xthickness - 0.5, (height/2) + 0.5);
454 ge_cairo_set_color (cr, border);
455 cairo_stroke (cr);
457 cairo_move_to (cr, params->xthickness + 0.5, (height/2)+1.5);
458 cairo_line_to (cr, width-params->xthickness - 0.5, (height/2)+1.5);
459 ge_cairo_set_color (cr, &hilight);
460 cairo_stroke (cr);
463 static void
464 clearlooks_draw_spinbutton_down (cairo_t *cr,
465 const ClearlooksColors *colors,
466 const WidgetParameters *params,
467 int x, int y, int width, int height)
469 cairo_pattern_t *pattern;
470 double radius = MIN (params->radius, MIN ((width - 4.0) / 2.0, (height - 4.0) / 2.0));
471 CairoColor shadow;
472 ge_shade_color (&colors->bg[GTK_STATE_NORMAL], 0.8, &shadow);
474 cairo_translate (cr, x+1, y+1);
476 ge_cairo_rounded_rectangle (cr, 1, 1, width-4, height-4, radius, params->corners);
478 ge_cairo_set_color (cr, &colors->bg[params->state_type]);
480 cairo_fill_preserve (cr);
482 pattern = cairo_pattern_create_linear (0, 0, 0, height);
483 cairo_pattern_add_color_stop_rgb (pattern, 0.0, shadow.r, shadow.g, shadow.b);
484 cairo_pattern_add_color_stop_rgba (pattern, 1.0, shadow.r, shadow.g, shadow.b, 0.0);
486 cairo_set_source (cr, pattern);
487 cairo_fill (cr);
489 cairo_pattern_destroy (pattern);
492 static void
493 clearlooks_scale_draw_gradient (cairo_t *cr,
494 const CairoColor *c1,
495 const CairoColor *c2,
496 const CairoColor *c3,
497 int x, int y, int width, int height,
498 boolean horizontal)
500 cairo_pattern_t *pattern;
502 pattern = cairo_pattern_create_linear (0, 0, horizontal ? 0 : width, horizontal ? height : 0);
503 cairo_pattern_add_color_stop_rgb (pattern, 0.0, c1->r, c1->g, c1->b);
504 cairo_pattern_add_color_stop_rgb (pattern, 1.0, c2->r, c2->g, c2->b);
506 cairo_rectangle (cr, x+0.5, y+0.5, width-1, height-1);
507 cairo_set_source (cr, pattern);
508 cairo_fill (cr);
509 cairo_pattern_destroy (pattern);
511 ge_cairo_set_color (cr, c3);
512 ge_cairo_stroke_rectangle (cr, x, y, width, height);
515 #define TROUGH_SIZE 6
516 static void
517 clearlooks_draw_scale_trough (cairo_t *cr,
518 const ClearlooksColors *colors,
519 const WidgetParameters *params,
520 const SliderParameters *slider,
521 int x, int y, int width, int height)
523 int trough_width, trough_height;
524 double translate_x, translate_y;
526 if (slider->horizontal)
528 trough_width = width-3;
529 trough_height = TROUGH_SIZE-2;
531 translate_x = x + 0.5;
532 translate_y = y + 0.5 + (height/2) - (TROUGH_SIZE/2);
534 else
536 trough_width = TROUGH_SIZE-2;
537 trough_height = height-3;
539 translate_x = x + 0.5 + (width/2) - (TROUGH_SIZE/2);
540 translate_y = y + 0.5;
543 cairo_set_line_width (cr, 1.0);
544 cairo_translate (cr, translate_x, translate_y);
546 if (!slider->fill_level)
547 params->style_functions->draw_inset (cr, &params->parentbg, 0, 0, trough_width+2, trough_height+2, 0, 0);
549 cairo_translate (cr, 1, 1);
551 if (!slider->lower && ! slider->fill_level)
552 clearlooks_scale_draw_gradient (cr, &colors->shade[3], /* top */
553 &colors->shade[2], /* bottom */
554 &colors->shade[6], /* border */
555 0, 0, trough_width, trough_height,
556 slider->horizontal);
557 else
558 clearlooks_scale_draw_gradient (cr, &colors->spot[1], /* top */
559 &colors->spot[0], /* bottom */
560 &colors->spot[2], /* border */
561 0, 0, trough_width, trough_height,
562 slider->horizontal);
565 static void
566 clearlooks_draw_slider (cairo_t *cr,
567 const ClearlooksColors *colors,
568 const WidgetParameters *params,
569 int x, int y, int width, int height)
571 const CairoColor *border = &colors->shade[params->disabled ? 4 : 6];
572 const CairoColor *spot = &colors->spot[1];
573 const CairoColor *fill = &colors->shade[2];
574 double radius = MIN (params->radius, MIN ((width - 1.0) / 2.0, (height - 1.0) / 2.0));
576 cairo_pattern_t *pattern;
578 cairo_set_line_width (cr, 1.0);
579 cairo_translate (cr, x, y);
581 if (params->prelight)
582 border = &colors->spot[2];
584 /* fill the widget */
585 cairo_rectangle (cr, 0.5, 0.5, width-2, height-2);
587 /* Fake light */
588 if (!params->disabled)
590 const CairoColor *top = &colors->shade[0];
591 const CairoColor *bot = &colors->shade[2];
593 pattern = cairo_pattern_create_linear (0, 0, 0, height);
594 cairo_pattern_add_color_stop_rgb (pattern, 0.0, top->r, top->g, top->b);
595 cairo_pattern_add_color_stop_rgb (pattern, 1.0, bot->r, bot->g, bot->b);
596 cairo_set_source (cr, pattern);
597 cairo_fill (cr);
598 cairo_pattern_destroy (pattern);
600 else
602 ge_cairo_set_color (cr, fill);
603 cairo_rectangle (cr, 0.5, 0.5, width-2, height-2);
604 cairo_fill (cr);
607 /* Set the clip */
608 cairo_save (cr);
609 cairo_rectangle (cr, 0.5, 0.5, 6, height-2);
610 cairo_rectangle (cr, width-7.5, 0.5, 6 , height-2);
611 cairo_clip_preserve (cr);
613 cairo_new_path (cr);
615 /* Draw the handles */
616 ge_cairo_rounded_rectangle (cr, 0.5, 0.5, width-1, height-1, radius, params->corners);
617 pattern = cairo_pattern_create_linear (0.5, 0.5, 0.5, 0.5+height);
619 if (params->prelight)
621 CairoColor highlight;
622 ge_shade_color (spot, 1.5, &highlight);
623 cairo_pattern_add_color_stop_rgb (pattern, 0.0, highlight.r, highlight.g, highlight.b);
624 cairo_pattern_add_color_stop_rgb (pattern, 1.0, spot->r, spot->g, spot->b);
625 cairo_set_source (cr, pattern);
627 else
629 CairoColor hilight;
630 ge_shade_color (fill, 1.5, &hilight);
631 cairo_set_source_rgba (cr, hilight.r, hilight.g, hilight.b, 0.5);
634 cairo_fill (cr);
635 cairo_pattern_destroy (pattern);
637 cairo_restore (cr);
639 /* Draw the border */
640 ge_cairo_rounded_rectangle (cr, 0, 0, width-1, height-1, radius, params->corners);
642 if (params->prelight || params->disabled)
643 ge_cairo_set_color (cr, border);
644 else
645 clearlooks_set_border_gradient (cr, border, 1.2, 0, height);
646 cairo_stroke (cr);
648 /* Draw handle lines */
649 if (width > 14)
651 cairo_move_to (cr, 6, 0.5);
652 cairo_line_to (cr, 6, height-1);
654 cairo_move_to (cr, width-7, 0.5);
655 cairo_line_to (cr, width-7, height-1);
657 cairo_set_line_width (cr, 1.0);
658 cairo_set_source_rgba (cr, border->r,
659 border->g,
660 border->b,
661 0.3);
662 cairo_stroke (cr);
666 static void
667 clearlooks_draw_slider_button (cairo_t *cr,
668 const ClearlooksColors *colors,
669 const WidgetParameters *params,
670 const SliderParameters *slider,
671 int x, int y, int width, int height)
673 double radius = MIN (params->radius, MIN ((width - 2.0) / 2.0, (height - 2.0) / 2.0));
674 cairo_set_line_width (cr, 1.0);
676 if (!slider->horizontal)
677 ge_cairo_exchange_axis (cr, &x, &y, &width, &height);
678 cairo_translate (cr, x+0.5, y+0.5);
680 params->style_functions->draw_shadow (cr, colors, radius, width-1, height-1);
681 params->style_functions->draw_slider (cr, colors, params, 1, 1, width-2, height-2);
683 if (width > 24)
684 params->style_functions->draw_gripdots (cr, colors, 0, 0, width-2, height-2, 3, 3, 0);
687 static void
688 clearlooks_draw_progressbar_trough (cairo_t *cr,
689 const ClearlooksColors *colors,
690 const WidgetParameters *params,
691 int x, int y, int width, int height)
693 const CairoColor *border = &colors->shade[6];
694 CairoColor shadow;
695 cairo_pattern_t *pattern;
696 double radius = MIN (params->radius, MIN ((height-2.0) / 2.0, (width-2.0) / 2.0));
698 cairo_save (cr);
700 cairo_set_line_width (cr, 1.0);
702 /* Fill with bg color */
703 ge_cairo_set_color (cr, &colors->bg[params->state_type]);
705 cairo_rectangle (cr, x, y, width, height);
706 cairo_fill (cr);
708 /* Create trough box */
709 ge_cairo_rounded_rectangle (cr, x+1, y+1, width-2, height-2, radius, params->corners);
710 ge_cairo_set_color (cr, &colors->shade[3]);
711 cairo_fill (cr);
713 /* Draw border */
714 ge_cairo_rounded_rectangle (cr, x+0.5, y+0.5, width-1, height-1, radius, params->corners);
715 ge_cairo_set_color (cr, border);
716 cairo_stroke (cr);
718 /* clip the corners of the shadows */
719 ge_cairo_rounded_rectangle (cr, x+1, y+1, width-2, height-2, radius, params->corners);
720 cairo_clip (cr);
722 ge_shade_color (border, 0.925, &shadow);
724 /* Top shadow */
725 cairo_rectangle (cr, x+1, y+1, width-2, 4);
726 pattern = cairo_pattern_create_linear (x, y, x, y+4);
727 cairo_pattern_add_color_stop_rgba (pattern, 0.0, shadow.r, shadow.g, shadow.b, 0.3);
728 cairo_pattern_add_color_stop_rgba (pattern, 1.0, shadow.r, shadow.g, shadow.b, 0.);
729 cairo_set_source (cr, pattern);
730 cairo_fill (cr);
731 cairo_pattern_destroy (pattern);
733 /* Left shadow */
734 cairo_rectangle (cr, x+1, y+1, 4, height-2);
735 pattern = cairo_pattern_create_linear (x, y, x+4, y);
736 cairo_pattern_add_color_stop_rgba (pattern, 0.0, shadow.r, shadow.g, shadow.b, 0.3);
737 cairo_pattern_add_color_stop_rgba (pattern, 1.0, shadow.r, shadow.g, shadow.b, 0.);
738 cairo_set_source (cr, pattern);
739 cairo_fill (cr);
740 cairo_pattern_destroy (pattern);
742 cairo_restore (cr);
745 static void
746 clearlooks_draw_progressbar_fill (cairo_t *cr,
747 const ClearlooksColors *colors,
748 const WidgetParameters *params,
749 const ProgressBarParameters *progressbar,
750 int x, int y, int width, int height,
751 gint offset)
753 boolean is_horizontal = progressbar->orientation < 2;
754 double tile_pos = 0;
755 double stroke_width;
756 double radius;
757 int x_step;
759 cairo_pattern_t *pattern;
760 CairoColor bg_shade;
761 CairoColor border;
762 CairoColor shadow;
764 radius = MAX (0, params->radius - params->xthickness);
766 cairo_save (cr);
768 if (!is_horizontal)
769 ge_cairo_exchange_axis (cr, &x, &y, &width, &height);
771 if ((progressbar->orientation == CL_ORIENTATION_RIGHT_TO_LEFT) || (progressbar->orientation == CL_ORIENTATION_BOTTOM_TO_TOP))
772 ge_cairo_mirror (cr, CR_MIRROR_HORIZONTAL, &x, &y, &width, &height);
774 /* Clamp the radius so that the _height_ fits ... */
775 radius = MIN (radius, height / 2.0);
777 stroke_width = height*2;
778 x_step = (((float)stroke_width/10)*offset); /* This looks weird ... */
780 cairo_translate (cr, x, y);
782 cairo_save (cr);
783 /* This is kind of nasty ... Clip twice from each side in case the length
784 * of the fill is smaller than twice the radius. */
785 ge_cairo_rounded_rectangle (cr, 0, 0, width + radius, height, radius, CR_CORNER_TOPLEFT | CR_CORNER_BOTTOMLEFT);
786 cairo_clip (cr);
787 ge_cairo_rounded_rectangle (cr, -radius, 0, width + radius, height, radius, CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMRIGHT);
788 cairo_clip (cr);
790 /* Draw the background gradient */
791 ge_shade_color (&colors->spot[1], 1.1, &bg_shade);
792 pattern = cairo_pattern_create_linear (0, 0, 0, height);
793 cairo_pattern_add_color_stop_rgb (pattern, 0.0, bg_shade.r, bg_shade.g, bg_shade.b);
794 cairo_pattern_add_color_stop_rgb (pattern, 0.6, colors->spot[1].r, colors->spot[1].g, colors->spot[1].b);
795 cairo_pattern_add_color_stop_rgb (pattern, 1.0, bg_shade.r, bg_shade.g, bg_shade.b);
796 cairo_set_source (cr, pattern);
797 cairo_paint (cr);
798 cairo_pattern_destroy (pattern);
800 /* Draw the Strokes */
801 while (tile_pos <= width+x_step)
803 cairo_move_to (cr, stroke_width/2-x_step, 0);
804 cairo_line_to (cr, stroke_width-x_step, 0);
805 cairo_line_to (cr, stroke_width/2-x_step, height);
806 cairo_line_to (cr, -x_step, height);
808 cairo_translate (cr, stroke_width, 0);
809 tile_pos += stroke_width;
812 cairo_set_source_rgba (cr, colors->spot[2].r,
813 colors->spot[2].g,
814 colors->spot[2].b,
815 0.15);
817 cairo_fill (cr);
818 cairo_restore (cr); /* rounded clip region */
820 /* inner highlight border
821 * This is again kinda ugly. Draw once from each side, clipping away the other. */
822 cairo_set_source_rgba (cr, colors->spot[0].r, colors->spot[0].g, colors->spot[0].b, 0.5);
824 /* left side */
825 cairo_save (cr);
826 cairo_rectangle (cr, 0, 0, width / 2, height);
827 cairo_clip (cr);
829 if (progressbar->pulsing)
830 ge_cairo_rounded_rectangle (cr, 1.5, 0.5, width + radius, height - 1, radius, CR_CORNER_TOPLEFT | CR_CORNER_BOTTOMLEFT);
831 else
832 ge_cairo_rounded_rectangle (cr, 0.5, 0.5, width + radius, height - 1, radius, CR_CORNER_TOPLEFT | CR_CORNER_BOTTOMLEFT);
834 cairo_stroke (cr);
835 cairo_restore (cr); /* clip */
837 /* right side */
838 cairo_save (cr);
839 cairo_rectangle (cr, width / 2, 0, (width+1) / 2, height);
840 cairo_clip (cr);
842 if (progressbar->value < 1.0 || progressbar->pulsing)
843 ge_cairo_rounded_rectangle (cr, -1.5 - radius, 0.5, width + radius, height - 1, radius, CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMRIGHT);
844 else
845 ge_cairo_rounded_rectangle (cr, -0.5 - radius, 0.5, width + radius, height - 1, radius, CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMRIGHT);
847 cairo_stroke (cr);
848 cairo_restore (cr); /* clip */
851 /* Draw the dark lines and the shadow */
852 cairo_save (cr);
853 /* Again, this weird clip area. */
854 ge_cairo_rounded_rectangle (cr, -1.0, 0, width + radius + 2.0, height, radius, CR_CORNER_TOPLEFT | CR_CORNER_BOTTOMLEFT);
855 cairo_clip (cr);
856 ge_cairo_rounded_rectangle (cr, -radius - 1.0, 0, width + radius + 2.0, height, radius, CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMRIGHT);
857 cairo_clip (cr);
859 border = colors->spot[2];
860 border.a = 0.5;
861 shadow.r = 0.0;
862 shadow.g = 0.0;
863 shadow.b = 0.0;
864 shadow.a = 0.1;
866 if (progressbar->pulsing)
868 /* At the beginning of the bar. */
869 cairo_move_to (cr, 0.5 + radius, height + 0.5);
870 ge_cairo_rounded_corner (cr, 0.5, height + 0.5, radius + 1, CR_CORNER_BOTTOMLEFT);
871 ge_cairo_rounded_corner (cr, 0.5, -0.5, radius + 1, CR_CORNER_TOPLEFT);
872 ge_cairo_set_color (cr, &border);
873 cairo_stroke (cr);
875 cairo_move_to (cr, -0.5 + radius, height + 0.5);
876 ge_cairo_rounded_corner (cr, -0.5, height + 0.5, radius + 1, CR_CORNER_BOTTOMLEFT);
877 ge_cairo_rounded_corner (cr, -0.5, -0.5, radius + 1, CR_CORNER_TOPLEFT);
878 ge_cairo_set_color (cr, &shadow);
879 cairo_stroke (cr);
881 if (progressbar->value < 1.0 || progressbar->pulsing)
883 /* At the end of the bar. */
884 cairo_move_to (cr, width - 0.5 - radius, -0.5);
885 ge_cairo_rounded_corner (cr, width - 0.5, -0.5, radius + 1, CR_CORNER_TOPRIGHT);
886 ge_cairo_rounded_corner (cr, width - 0.5, height + 0.5, radius + 1, CR_CORNER_BOTTOMRIGHT);
887 ge_cairo_set_color (cr, &border);
888 cairo_stroke (cr);
890 cairo_move_to (cr, width + 0.5 - radius, -0.5);
891 ge_cairo_rounded_corner (cr, width + 0.5, -0.5, radius + 1, CR_CORNER_TOPRIGHT);
892 ge_cairo_rounded_corner (cr, width + 0.5, height + 0.5, radius + 1, CR_CORNER_BOTTOMRIGHT);
893 ge_cairo_set_color (cr, &shadow);
894 cairo_stroke (cr);
897 cairo_restore (cr);
899 cairo_restore (cr); /* rotation, mirroring */
902 static void
903 clearlooks_draw_optionmenu (cairo_t *cr,
904 const ClearlooksColors *colors,
905 const WidgetParameters *params,
906 const OptionMenuParameters *optionmenu,
907 int x, int y, int width, int height)
909 SeparatorParameters separator;
910 int offset = params->ythickness + 1;
912 params->style_functions->draw_button (cr, colors, params, x, y, width, height);
914 separator.horizontal = FALSE;
915 params->style_functions->draw_separator (cr, colors, params, &separator, x+optionmenu->linepos, y + offset, 2, height - offset*2);
918 static void
919 clearlooks_draw_menu_item_separator (cairo_t *cr,
920 const ClearlooksColors *colors,
921 const WidgetParameters *widget,
922 const SeparatorParameters *separator,
923 int x, int y, int width, int height)
925 (void) widget;
927 cairo_save (cr);
928 cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
929 ge_cairo_set_color (cr, &colors->shade[5]);
931 if (separator->horizontal)
932 cairo_rectangle (cr, x, y, width, 1);
933 else
934 cairo_rectangle (cr, x, y, 1, height);
936 cairo_fill (cr);
938 cairo_restore (cr);
941 static void
942 clearlooks_draw_menubar0 (cairo_t *cr,
943 const ClearlooksColors *colors,
944 const WidgetParameters *params,
945 const MenuBarParameters *menubar,
946 int x, int y, int width, int height)
948 (void) params;
949 (void) menubar;
951 /* const CairoColor *light = &colors->shade[0]; */
952 const CairoColor *dark = &colors->shade[3];
954 cairo_set_line_width (cr, 1);
955 cairo_translate (cr, x, y+0.5);
957 /* cairo_move_to (cr, 0, 0); */
958 /* cairo_line_to (cr, width, 0); */
959 /* ge_cairo_set_color (cr, light); */
960 /* cairo_stroke (cr); */
962 cairo_move_to (cr, 0, height-1);
963 cairo_line_to (cr, width, height-1);
964 ge_cairo_set_color (cr, dark);
965 cairo_stroke (cr);
968 static void
969 clearlooks_draw_menubar2 (cairo_t *cr,
970 const ClearlooksColors *colors,
971 const WidgetParameters *params,
972 const MenuBarParameters *menubar,
973 int x, int y, int width, int height)
975 (void) params;
976 (void) menubar;
978 CairoColor lower;
979 cairo_pattern_t *pattern;
981 ge_shade_color (&colors->bg[0], 0.96, &lower);
983 cairo_translate (cr, x, y);
984 cairo_rectangle (cr, 0, 0, width, height);
986 /* Draw the gradient */
987 pattern = cairo_pattern_create_linear (0, 0, 0, height);
988 cairo_pattern_add_color_stop_rgb (pattern, 0.0, colors->bg[0].r,
989 colors->bg[0].g,
990 colors->bg[0].b);
991 cairo_pattern_add_color_stop_rgb (pattern, 1.0, lower.r,
992 lower.g,
993 lower.b);
994 cairo_set_source (cr, pattern);
995 cairo_fill (cr);
996 cairo_pattern_destroy (pattern);
998 /* Draw bottom line */
999 cairo_set_line_width (cr, 1.0);
1000 cairo_move_to (cr, 0, height-0.5);
1001 cairo_line_to (cr, width, height-0.5);
1002 ge_cairo_set_color (cr, &colors->shade[3]);
1003 cairo_stroke (cr);
1006 static void
1007 clearlooks_draw_menubar1 (cairo_t *cr,
1008 const ClearlooksColors *colors,
1009 const WidgetParameters *params,
1010 const MenuBarParameters *menubar,
1011 int x, int y, int width, int height)
1013 const CairoColor *border = &colors->shade[3];
1015 clearlooks_draw_menubar2 (cr, colors, params, menubar,
1016 x, y, width, height);
1018 ge_cairo_set_color (cr, border);
1019 ge_cairo_stroke_rectangle (cr, 0.5, 0.5, width-1, height-1);
1023 static menubar_draw_proto clearlooks_menubar_draw[3] =
1025 clearlooks_draw_menubar0,
1026 clearlooks_draw_menubar1,
1027 clearlooks_draw_menubar2
1030 static void
1031 clearlooks_draw_menubar (cairo_t *cr,
1032 const ClearlooksColors *colors,
1033 const WidgetParameters *params,
1034 const MenuBarParameters *menubar,
1035 int x, int y, int width, int height)
1037 if (menubar->style < 0 || menubar->style > 3)
1038 return;
1040 clearlooks_menubar_draw[menubar->style](cr, colors, params, menubar,
1041 x, y, width, height);
1044 static void
1045 clearlooks_get_frame_gap_clip (int x, int y, int width, int height,
1046 const FrameParameters *frame,
1047 ClearlooksRectangle *bevel,
1048 ClearlooksRectangle *border)
1050 (void) x;
1051 (void) y;
1053 if (frame->gap_side == CL_GAP_TOP)
1055 CLEARLOOKS_RECTANGLE_SET ((*bevel), 1.5 + frame->gap_x, -0.5,
1056 frame->gap_width - 3, 2.0);
1057 CLEARLOOKS_RECTANGLE_SET ((*border), 0.5 + frame->gap_x, -0.5,
1058 frame->gap_width - 2, 2.0);
1060 else if (frame->gap_side == CL_GAP_BOTTOM)
1062 CLEARLOOKS_RECTANGLE_SET ((*bevel), 1.5 + frame->gap_x, height - 2.5,
1063 frame->gap_width - 3, 2.0);
1064 CLEARLOOKS_RECTANGLE_SET ((*border), 0.5 + frame->gap_x, height - 1.5,
1065 frame->gap_width - 2, 2.0);
1067 else if (frame->gap_side == CL_GAP_LEFT)
1069 CLEARLOOKS_RECTANGLE_SET ((*bevel), -0.5, 1.5 + frame->gap_x,
1070 2.0, frame->gap_width - 3);
1071 CLEARLOOKS_RECTANGLE_SET ((*border), -0.5, 0.5 + frame->gap_x,
1072 1.0, frame->gap_width - 2);
1074 else if (frame->gap_side == CL_GAP_RIGHT)
1076 CLEARLOOKS_RECTANGLE_SET ((*bevel), width - 2.5, 1.5 + frame->gap_x,
1077 2.0, frame->gap_width - 3);
1078 CLEARLOOKS_RECTANGLE_SET ((*border), width - 1.5, 0.5 + frame->gap_x,
1079 1.0, frame->gap_width - 2);
1083 static void
1084 clearlooks_draw_frame (cairo_t *cr,
1085 const ClearlooksColors *colors,
1086 const WidgetParameters *params,
1087 const FrameParameters *frame,
1088 int x, int y, int width, int height)
1090 const CairoColor *border = frame->border;
1091 const CairoColor *dark = (CairoColor*)&colors->shade[4];
1092 ClearlooksRectangle bevel_clip = {0, 0, 0, 0};
1093 ClearlooksRectangle frame_clip = {0, 0, 0, 0};
1094 double radius = MIN (params->radius, MIN ((width - 2.0) / 2.0, (height - 2.0) / 2.0));
1095 CairoColor hilight;
1097 ge_shade_color (&colors->bg[GTK_STATE_NORMAL], 1.05, &hilight);
1099 if (frame->shadow == CL_SHADOW_NONE)
1100 return;
1102 if (frame->gap_x != -1)
1103 clearlooks_get_frame_gap_clip (x, y, width, height,
1104 frame, &bevel_clip, &frame_clip);
1106 cairo_set_line_width (cr, 1.0);
1107 cairo_translate (cr, x+0.5, y+0.5);
1109 /* save everything */
1110 cairo_save (cr);
1111 /* Set clip for the bevel */
1112 if (frame->gap_x != -1)
1114 /* Set clip for gap */
1115 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
1116 cairo_rectangle (cr, -0.5, -0.5, width, height);
1117 cairo_rectangle (cr, bevel_clip.x, bevel_clip.y, bevel_clip.width, bevel_clip.height);
1118 cairo_clip (cr);
1121 /* Draw the bevel */
1122 if (frame->shadow == CL_SHADOW_ETCHED_IN || frame->shadow == CL_SHADOW_ETCHED_OUT)
1124 ge_cairo_set_color (cr, &hilight);
1125 if (frame->shadow == CL_SHADOW_ETCHED_IN)
1126 ge_cairo_rounded_rectangle (cr, 1, 1, width-2, height-2, radius, params->corners);
1127 else
1128 ge_cairo_rounded_rectangle (cr, 0, 0, width-2, height-2, radius, params->corners);
1129 cairo_stroke (cr);
1131 else if (frame->shadow != CL_SHADOW_NONE)
1133 ShadowParameters shadow;
1134 shadow.corners = params->corners;
1135 shadow.shadow = frame->shadow;
1136 clearlooks_draw_highlight_and_shade (cr, colors, &shadow, width, height, 0);
1139 /* restore the previous clip region */
1140 cairo_restore (cr);
1141 cairo_save (cr);
1142 if (frame->gap_x != -1)
1144 /* Set clip for gap */
1145 cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
1146 cairo_rectangle (cr, -0.5, -0.5, width, height);
1147 cairo_rectangle (cr, frame_clip.x, frame_clip.y, frame_clip.width, frame_clip.height);
1148 cairo_clip (cr);
1151 /* Draw frame */
1152 if (frame->shadow == CL_SHADOW_ETCHED_IN || frame->shadow == CL_SHADOW_ETCHED_OUT)
1154 ge_cairo_set_color (cr, dark);
1155 if (frame->shadow == CL_SHADOW_ETCHED_IN)
1156 ge_cairo_rounded_rectangle (cr, 0, 0, width-2, height-2, radius, params->corners);
1157 else
1158 ge_cairo_rounded_rectangle (cr, 1, 1, width-2, height-2, radius, params->corners);
1160 else
1162 ge_cairo_set_color (cr, border);
1163 ge_cairo_rounded_rectangle (cr, 0, 0, width-1, height-1, radius, params->corners);
1165 cairo_stroke (cr);
1167 cairo_restore (cr);
1170 static void
1171 clearlooks_draw_tab (cairo_t *cr,
1172 const ClearlooksColors *colors,
1173 const WidgetParameters *params,
1174 const TabParameters *tab,
1175 int x, int y, int width, int height)
1177 const CairoColor *border1 = &colors->shade[6];
1178 const CairoColor *border2 = &colors->shade[5];
1179 const CairoColor *stripe_fill = &colors->spot[1];
1180 const CairoColor *stripe_border = &colors->spot[2];
1181 const CairoColor *fill;
1182 CairoColor hilight;
1184 cairo_pattern_t *pattern;
1186 double radius;
1187 double strip_size;
1189 radius = MIN (params->radius, MIN ((width - 2.0) / 2.0, (height - 2.0) / 2.0));
1191 /* Set clip */
1192 cairo_rectangle (cr, x, y, width, height);
1193 cairo_clip (cr);
1194 cairo_new_path (cr);
1196 /* Translate and set line width */
1197 cairo_set_line_width (cr, 1.0);
1198 cairo_translate (cr, x+0.5, y+0.5);
1201 /* Make the tabs slightly bigger than they should be, to create a gap */
1202 /* And calculate the strip size too, while you're at it */
1203 if (tab->gap_side == CL_GAP_TOP || tab->gap_side == CL_GAP_BOTTOM)
1205 height += 3.0;
1206 strip_size = 2.0/height; /* 2 pixel high strip */
1208 if (tab->gap_side == CL_GAP_TOP)
1209 cairo_translate (cr, 0.0, -3.0); /* gap at the other side */
1211 else
1213 width += 3.0;
1214 strip_size = 2.0/width;
1216 if (tab->gap_side == CL_GAP_LEFT)
1217 cairo_translate (cr, -3.0, 0.0); /* gap at the other side */
1220 /* Set the fill color */
1221 fill = &colors->bg[params->state_type];
1223 /* Set tab shape */
1224 ge_cairo_rounded_rectangle (cr, 0, 0, width-1, height-1,
1225 radius, params->corners);
1227 /* Draw fill */
1228 ge_cairo_set_color (cr, fill);
1229 cairo_fill (cr);
1232 ge_shade_color (fill, 1.3, &hilight);
1234 /* Draw highlight */
1235 if (!params->active)
1237 ShadowParameters shadow;
1239 shadow.shadow = CL_SHADOW_OUT;
1240 shadow.corners = params->corners;
1242 clearlooks_draw_highlight_and_shade (cr, colors, &shadow,
1243 width,
1244 height, radius);
1248 if (params->active)
1250 CairoColor shadow;
1251 pattern = cairo_pattern_create_linear ( tab->gap_side == CL_GAP_LEFT ? width-1 : 0,
1252 tab->gap_side == CL_GAP_TOP ? height-2 : 1,
1253 tab->gap_side == CL_GAP_RIGHT ? width : 0,
1254 tab->gap_side == CL_GAP_BOTTOM ? height : 0 );
1256 ge_cairo_rounded_rectangle (cr, 0, 0, width-1, height-1, radius, params->corners);
1258 ge_shade_color (fill, 0.92, &shadow);
1260 cairo_pattern_add_color_stop_rgba (pattern, 0.0, hilight.r, hilight.g, hilight.b, 0.4);
1261 cairo_pattern_add_color_stop_rgba (pattern, 1.0/height, hilight.r, hilight.g, hilight.b, 0.4);
1262 cairo_pattern_add_color_stop_rgb (pattern, 1.0/height, fill->r,fill->g,fill->b);
1263 cairo_pattern_add_color_stop_rgb (pattern, 1.0, shadow.r,shadow.g,shadow.b);
1264 cairo_set_source (cr, pattern);
1265 cairo_fill (cr);
1266 cairo_pattern_destroy (pattern);
1268 else
1270 /* Draw shade */
1271 pattern = cairo_pattern_create_linear ( tab->gap_side == CL_GAP_LEFT ? width-2 : 0,
1272 tab->gap_side == CL_GAP_TOP ? height-2 : 0,
1273 tab->gap_side == CL_GAP_RIGHT ? width : 0,
1274 tab->gap_side == CL_GAP_BOTTOM ? height : 0 );
1276 ge_cairo_rounded_rectangle (cr, 0, 0, width-1, height-1, radius, params->corners);
1279 cairo_pattern_add_color_stop_rgb (pattern, 0.0, stripe_fill->r, stripe_fill->g, stripe_fill->b);
1280 cairo_pattern_add_color_stop_rgb (pattern, strip_size, stripe_fill->r, stripe_fill->g, stripe_fill->b);
1281 cairo_pattern_add_color_stop_rgba (pattern, strip_size, hilight.r, hilight.g, hilight.b, 0.5);
1282 cairo_pattern_add_color_stop_rgba (pattern, 0.8, hilight.r, hilight.g, hilight.b, 0.0);
1283 cairo_set_source (cr, pattern);
1284 cairo_fill (cr);
1285 cairo_pattern_destroy (pattern);
1288 ge_cairo_rounded_rectangle (cr, 0, 0, width-1, height-1, radius, params->corners);
1290 if (params->active)
1292 ge_cairo_set_color (cr, border2);
1293 cairo_stroke (cr);
1295 else
1297 pattern = cairo_pattern_create_linear ( tab->gap_side == CL_GAP_LEFT ? width-2 : 2,
1298 tab->gap_side == CL_GAP_TOP ? height-2 : 2,
1299 tab->gap_side == CL_GAP_RIGHT ? width : 2,
1300 tab->gap_side == CL_GAP_BOTTOM ? height : 2 );
1302 cairo_pattern_add_color_stop_rgb (pattern, 0.0, stripe_border->r, stripe_border->g, stripe_border->b);
1303 cairo_pattern_add_color_stop_rgb (pattern, strip_size, stripe_border->r, stripe_border->g, stripe_border->b);
1304 cairo_pattern_add_color_stop_rgb (pattern, strip_size, border1->r, border1->g, border1->b);
1305 cairo_pattern_add_color_stop_rgb (pattern, 1.0, border2->r, border2->g, border2->b);
1306 cairo_set_source (cr, pattern);
1307 cairo_stroke (cr);
1308 cairo_pattern_destroy (pattern);
1312 static void
1313 clearlooks_draw_separator (cairo_t *cr,
1314 const ClearlooksColors *colors,
1315 const WidgetParameters *widget,
1316 const SeparatorParameters *separator,
1317 int x, int y, int width, int height)
1319 (void) widget;
1321 CairoColor color = colors->shade[3];
1322 CairoColor hilight;
1323 ge_shade_color (&color, 1.4, &hilight);
1325 cairo_save (cr);
1326 cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
1328 if (separator->horizontal)
1330 cairo_set_line_width (cr, 1.0);
1331 cairo_translate (cr, x, y+0.5);
1333 cairo_move_to (cr, 0.0, 0.0);
1334 cairo_line_to (cr, width, 0.0);
1335 ge_cairo_set_color (cr, &color);
1336 cairo_stroke (cr);
1338 cairo_move_to (cr, 0.0, 1.0);
1339 cairo_line_to (cr, width, 1.0);
1340 ge_cairo_set_color (cr, &hilight);
1341 cairo_stroke (cr);
1343 else
1345 cairo_set_line_width (cr, 1.0);
1346 cairo_translate (cr, x+0.5, y);
1348 cairo_move_to (cr, 0.0, 0.0);
1349 cairo_line_to (cr, 0.0, height);
1350 ge_cairo_set_color (cr, &color);
1351 cairo_stroke (cr);
1353 cairo_move_to (cr, 1.0, 0.0);
1354 cairo_line_to (cr, 1.0, height);
1355 ge_cairo_set_color (cr, &hilight);
1356 cairo_stroke (cr);
1359 cairo_restore (cr);
1362 static void
1363 clearlooks_draw_list_view_header (cairo_t *cr,
1364 const ClearlooksColors *colors,
1365 const WidgetParameters *params,
1366 const ListViewHeaderParameters *header,
1367 int x, int y, int width, int height)
1369 const CairoColor *border = &colors->shade[5];
1370 cairo_pattern_t *pattern;
1371 CairoColor hilight;
1372 CairoColor shadow;
1374 ge_shade_color (border, 1.5, &hilight);
1375 ge_shade_color (border, 0.925, &shadow);
1377 cairo_translate (cr, x, y);
1378 cairo_set_line_width (cr, 1.0);
1380 /* Draw highlight */
1381 if (header->order == CL_ORDER_FIRST)
1383 cairo_move_to (cr, 0.5, height-1);
1384 cairo_line_to (cr, 0.5, 0.5);
1386 else
1387 cairo_move_to (cr, 0.0, 0.5);
1389 cairo_line_to (cr, width, 0.5);
1391 ge_cairo_set_color (cr, &hilight);
1392 cairo_stroke (cr);
1394 /* Draw bottom border */
1395 cairo_move_to (cr, 0.0, height-0.5);
1396 cairo_line_to (cr, width, height-0.5);
1397 ge_cairo_set_color (cr, border);
1398 cairo_stroke (cr);
1400 /* Draw bottom shade */
1401 pattern = cairo_pattern_create_linear (0.0, height-5.0, 0.0, height-1.0);
1402 cairo_pattern_add_color_stop_rgba (pattern, 0.0, shadow.r, shadow.g, shadow.b, 0.0);
1403 cairo_pattern_add_color_stop_rgba (pattern, 1.0, shadow.r, shadow.g, shadow.b, 0.3);
1405 cairo_rectangle (cr, 0.0, height-5.0, width, 4.0);
1406 cairo_set_source (cr, pattern);
1407 cairo_fill (cr);
1408 cairo_pattern_destroy (pattern);
1410 /* Draw resize grip */
1411 if ((params->ltr && header->order != CL_ORDER_LAST) ||
1412 (!params->ltr && header->order != CL_ORDER_FIRST) || header->resizable)
1414 SeparatorParameters separator;
1415 separator.horizontal = FALSE;
1417 if (params->ltr)
1418 params->style_functions->draw_separator (cr, colors, params, &separator,
1419 width-1.5, 4.0, 2, height-8.0);
1420 else
1421 params->style_functions->draw_separator (cr, colors, params, &separator,
1422 1.5, 4.0, 2, height-8.0);
1426 /* We can't draw transparent things here, since it will be called on the same
1427 * surface multiple times, when placed on a handlebox_bin or dockitem_bin */
1428 static void
1429 clearlooks_draw_toolbar (cairo_t *cr,
1430 const ClearlooksColors *colors,
1431 const WidgetParameters *widget,
1432 const ToolbarParameters *toolbar,
1433 int x, int y, int width, int height)
1435 (void) widget;
1437 const CairoColor *fill = &colors->bg[GTK_STATE_NORMAL];
1438 const CairoColor *dark = &colors->shade[3];
1439 CairoColor light;
1440 ge_shade_color (fill, 1.1, &light);
1442 cairo_set_line_width (cr, 1.0);
1443 cairo_translate (cr, x, y);
1445 ge_cairo_set_color (cr, fill);
1446 cairo_paint (cr);
1448 if (!toolbar->topmost)
1450 /* Draw highlight */
1451 cairo_move_to (cr, 0, 0.5);
1452 cairo_line_to (cr, width-1, 0.5);
1453 ge_cairo_set_color (cr, &light);
1454 cairo_stroke (cr);
1457 /* Draw shadow */
1458 cairo_move_to (cr, 0, height-0.5);
1459 cairo_line_to (cr, width-1, height-0.5);
1460 ge_cairo_set_color (cr, dark);
1461 cairo_stroke (cr);
1464 static void
1465 clearlooks_draw_menuitem (cairo_t *cr,
1466 const ClearlooksColors *colors,
1467 const WidgetParameters *widget,
1468 int x, int y, int width, int height)
1470 const CairoColor *fill = &colors->spot[1];
1471 CairoColor fill_shade;
1472 CairoColor border = colors->spot[2];
1473 cairo_pattern_t *pattern;
1475 ge_shade_color (&border, 1.05, &border);
1476 ge_shade_color (fill, 0.85, &fill_shade);
1477 cairo_set_line_width (cr, 1.0);
1479 ge_cairo_rounded_rectangle (cr, x+0.5, y+0.5, width - 1, height - 1, widget->radius, widget->corners);
1481 pattern = cairo_pattern_create_linear (x, y, x, y + height);
1482 cairo_pattern_add_color_stop_rgb (pattern, 0, fill->r, fill->g, fill->b);
1483 cairo_pattern_add_color_stop_rgb (pattern, 1.0, fill_shade.r, fill_shade.g, fill_shade.b);
1485 cairo_set_source (cr, pattern);
1486 cairo_fill_preserve (cr);
1487 cairo_pattern_destroy (pattern);
1489 ge_cairo_set_color (cr, &border);
1490 cairo_stroke (cr);
1493 static void
1494 clearlooks_draw_menubaritem (cairo_t *cr,
1495 const ClearlooksColors *colors,
1496 const WidgetParameters *widget,
1497 int x, int y, int width, int height)
1499 const CairoColor *fill = &colors->spot[1];
1500 CairoColor fill_shade;
1501 CairoColor border = colors->spot[2];
1502 cairo_pattern_t *pattern;
1504 ge_shade_color (&border, 1.05, &border);
1505 ge_shade_color (fill, 0.85, &fill_shade);
1507 cairo_set_line_width (cr, 1.0);
1508 ge_cairo_rounded_rectangle (cr, x + 0.5, y + 0.5, width - 1, height, widget->radius, widget->corners);
1510 pattern = cairo_pattern_create_linear (x, y, x, y + height);
1511 cairo_pattern_add_color_stop_rgb (pattern, 0, fill->r, fill->g, fill->b);
1512 cairo_pattern_add_color_stop_rgb (pattern, 1.0, fill_shade.r, fill_shade.g, fill_shade.b);
1514 cairo_set_source (cr, pattern);
1515 cairo_fill_preserve (cr);
1516 cairo_pattern_destroy (pattern);
1518 ge_cairo_set_color (cr, &border);
1519 cairo_stroke_preserve (cr);
1522 static void
1523 clearlooks_draw_selected_cell (cairo_t *cr,
1524 const ClearlooksColors *colors,
1525 const WidgetParameters *params,
1526 int x, int y, int width, int height)
1528 CairoColor upper_color;
1529 CairoColor lower_color;
1530 CairoColor border;
1531 cairo_pattern_t *pattern;
1532 cairo_save (cr);
1534 cairo_translate (cr, x, y);
1536 if (params->focus)
1537 upper_color = colors->base[params->state_type];
1538 else
1539 upper_color = colors->base[GTK_STATE_ACTIVE];
1541 ge_shade_color(&upper_color, 0.92, &lower_color);
1543 pattern = cairo_pattern_create_linear (0, 0, 0, height);
1544 cairo_pattern_add_color_stop_rgb (pattern, 0.0, upper_color.r,
1545 upper_color.g,
1546 upper_color.b);
1547 cairo_pattern_add_color_stop_rgb (pattern, 1.0, lower_color.r,
1548 lower_color.g,
1549 lower_color.b);
1551 cairo_set_source (cr, pattern);
1552 cairo_rectangle (cr, 0, 0, width, height);
1553 cairo_fill (cr);
1555 cairo_pattern_destroy (pattern);
1557 ge_shade_color(&upper_color, 0.8, &border);
1559 cairo_move_to (cr, 0, 0.5);
1560 cairo_rel_line_to (cr, width, 0);
1561 cairo_move_to (cr, 0, height-0.5);
1562 cairo_rel_line_to (cr, width, 0);
1564 ge_cairo_set_color (cr, &border);
1565 cairo_stroke (cr);
1567 cairo_restore (cr);
1571 static void
1572 clearlooks_draw_scrollbar_trough (cairo_t *cr,
1573 const ClearlooksColors *colors,
1574 const WidgetParameters *widget,
1575 const ScrollBarParameters *scrollbar,
1576 int x, int y, int width, int height)
1578 (void) widget;
1580 const CairoColor *bg = &colors->shade[2];
1581 const CairoColor *border = &colors->shade[5];
1582 CairoColor bg_shade;
1583 cairo_pattern_t *pattern;
1585 ge_shade_color (bg, 0.95, &bg_shade);
1587 cairo_set_line_width (cr, 1);
1588 /* cairo_translate (cr, x, y); */
1590 if (scrollbar->horizontal)
1591 ge_cairo_exchange_axis (cr, &x, &y, &width, &height);
1593 cairo_translate (cr, x, y);
1595 /* Draw fill */
1596 cairo_rectangle (cr, 1, 0, width-2, height);
1597 ge_cairo_set_color (cr, bg);
1598 cairo_fill (cr);
1600 /* Draw shadow */
1601 pattern = cairo_pattern_create_linear (1, 0, 3, 0);
1602 cairo_pattern_add_color_stop_rgb (pattern, 0, bg_shade.r, bg_shade.g, bg_shade.b);
1603 cairo_pattern_add_color_stop_rgb (pattern, 1.0, bg->r, bg->g, bg->b);
1604 cairo_rectangle (cr, 1, 0, 4, height);
1605 cairo_set_source (cr, pattern);
1606 cairo_fill (cr);
1607 cairo_pattern_destroy (pattern);
1609 /* Draw border */
1610 ge_cairo_set_color (cr, border);
1611 ge_cairo_stroke_rectangle (cr, 0.5, 0.5, width-1, height-1);
1614 static void
1615 clearlooks_draw_scrollbar_stepper (cairo_t *cr,
1616 const ClearlooksColors *colors,
1617 const WidgetParameters *widget,
1618 const ScrollBarParameters *scrollbar,
1619 const ScrollBarStepperParameters *stepper,
1620 int x, int y, int width, int height)
1622 CairoCorners corners = CR_CORNER_NONE;
1623 CairoColor border;
1624 CairoColor s1, s2, s3, s4;
1625 cairo_pattern_t *pattern;
1626 ShadowParameters shadow;
1627 double radius = MIN (widget->radius, MIN ((width - 2.0) / 2.0, (height - 2.0) / 2.0));
1629 ge_shade_color(&colors->shade[6], 1.05, &border);
1631 if (scrollbar->horizontal)
1633 if (stepper->stepper == CL_STEPPER_A)
1634 corners = CR_CORNER_TOPLEFT | CR_CORNER_BOTTOMLEFT;
1635 else if (stepper->stepper == CL_STEPPER_D)
1636 corners = CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMRIGHT;
1638 else
1640 if (stepper->stepper == CL_STEPPER_A)
1641 corners = CR_CORNER_TOPLEFT | CR_CORNER_TOPRIGHT;
1642 else if (stepper->stepper == CL_STEPPER_D)
1643 corners = CR_CORNER_BOTTOMLEFT | CR_CORNER_BOTTOMRIGHT;
1646 cairo_translate (cr, x, y);
1647 cairo_set_line_width (cr, 1);
1649 ge_cairo_rounded_rectangle (cr, 1, 1, width-2, height-2, radius, corners);
1651 if (scrollbar->horizontal)
1652 pattern = cairo_pattern_create_linear (0, 0, 0, height);
1653 else
1654 pattern = cairo_pattern_create_linear (0, 0, width, 0);
1656 s2 = colors->bg[widget->state_type];
1657 ge_shade_color(&s2, 1.06, &s1);
1658 ge_shade_color(&s2, 0.98, &s3);
1659 ge_shade_color(&s2, 0.94, &s4);
1661 cairo_pattern_add_color_stop_rgb(pattern, 0, s1.r, s1.g, s1.b);
1662 cairo_pattern_add_color_stop_rgb(pattern, 0.5, s2.r, s2.g, s2.b);
1663 cairo_pattern_add_color_stop_rgb(pattern, 0.7, s3.r, s3.g, s3.b);
1664 cairo_pattern_add_color_stop_rgb(pattern, 1.0, s4.r, s4.g, s4.b);
1665 cairo_set_source (cr, pattern);
1666 cairo_fill (cr);
1667 cairo_pattern_destroy (pattern);
1669 cairo_translate (cr, 0.5, 0.5);
1670 clearlooks_draw_top_left_highlight (cr, &s2, widget, width, height, (stepper->stepper == CL_STEPPER_A) ? radius : 0);
1671 cairo_translate (cr, -0.5, -0.5);
1673 ge_cairo_rounded_rectangle (cr, 0.5, 0.5, width-1, height-1, radius, corners);
1674 clearlooks_set_border_gradient (cr, &border, 1.2, (scrollbar->horizontal ? 0 : width), (scrollbar->horizontal ? height: 0));
1675 cairo_stroke (cr);
1677 cairo_translate (cr, 0.5, 0.5);
1678 shadow.shadow = CL_SHADOW_OUT;
1679 shadow.corners = corners;
1681 clearlooks_draw_highlight_and_shade (cr, &shadow,
1682 width,
1683 height, params->radius);*/
1686 static void
1687 clearlooks_draw_scrollbar_slider (cairo_t *cr,
1688 const ClearlooksColors *colors,
1689 const WidgetParameters *widget,
1690 const ScrollBarParameters *scrollbar,
1691 int x, int y, int width, int height)
1693 if (scrollbar->junction & CL_JUNCTION_BEGIN)
1695 if (scrollbar->horizontal)
1697 x -= 1;
1698 width += 1;
1700 else
1702 y -= 1;
1703 height += 1;
1706 if (scrollbar->junction & CL_JUNCTION_END)
1708 if (scrollbar->horizontal)
1709 width += 1;
1710 else
1711 height += 1;
1714 if (!scrollbar->horizontal)
1715 ge_cairo_exchange_axis (cr, &x, &y, &width, &height);
1717 cairo_translate (cr, x, y);
1719 if (scrollbar->has_color)
1721 const CairoColor *border = &colors->shade[7];
1722 CairoColor fill = scrollbar->color;
1723 CairoColor hilight;
1724 CairoColor shade1, shade2, shade3;
1725 cairo_pattern_t *pattern;
1727 if (widget->prelight)
1728 ge_shade_color (&fill, 1.1, &fill);
1730 cairo_set_line_width (cr, 1);
1732 ge_shade_color (&fill, 1.3, &hilight);
1733 ge_shade_color (&fill, 1.1, &shade1);
1734 ge_shade_color (&fill, 1.05, &shade2);
1735 ge_shade_color (&fill, 0.98, &shade3);
1737 pattern = cairo_pattern_create_linear (1, 1, 1, height-2);
1738 cairo_pattern_add_color_stop_rgb (pattern, 0, shade1.r, shade1.g, shade1.b);
1739 cairo_pattern_add_color_stop_rgb (pattern, 0.5, shade2.r, shade2.g, shade2.b);
1740 cairo_pattern_add_color_stop_rgb (pattern, 0.5, shade3.r, shade3.g, shade3.b);
1741 cairo_pattern_add_color_stop_rgb (pattern, 1, fill.r, fill.g, fill.b);
1742 cairo_rectangle (cr, 1, 1, width-2, height-2);
1743 cairo_set_source (cr, pattern);
1744 cairo_fill (cr);
1745 cairo_pattern_destroy (pattern);
1747 cairo_set_source_rgba (cr, hilight.r, hilight.g, hilight.b, 0.5);
1748 ge_cairo_stroke_rectangle (cr, 1.5, 1.5, width-3, height-3);
1750 ge_cairo_set_color (cr, border);
1751 ge_cairo_stroke_rectangle (cr, 0.5, 0.5, width-1, height-1);
1753 else
1755 const CairoColor *dark = &colors->shade[4];
1756 const CairoColor *light = &colors->shade[0];
1757 CairoColor border;
1758 CairoColor s1, s2, s3, s4, s5;
1759 cairo_pattern_t *pattern;
1760 int bar_x, i;
1762 ge_shade_color(&colors->shade[6], 1.05, &border);
1764 s2 = colors->bg[widget->state_type];
1765 ge_shade_color(&s2, 1.06, &s1);
1766 ge_shade_color(&s2, 0.98, &s3);
1767 ge_shade_color(&s2, 0.94, &s4);
1769 pattern = cairo_pattern_create_linear(1, 1, 1, height-1);
1770 cairo_pattern_add_color_stop_rgb(pattern, 0, s1.r, s1.g, s1.b);
1771 cairo_pattern_add_color_stop_rgb(pattern, 0.5, s2.r, s2.g, s2.b);
1772 cairo_pattern_add_color_stop_rgb(pattern, 0.7, s3.r, s3.g, s3.b);
1773 cairo_pattern_add_color_stop_rgb(pattern, 1.0, s4.r, s4.g, s4.b);
1775 cairo_rectangle (cr, 1, 1, width-2, height-2);
1776 cairo_set_source(cr, pattern);
1777 cairo_fill(cr);
1778 cairo_pattern_destroy(pattern);
1780 clearlooks_set_border_gradient (cr, &border, 1.2, 0, height);
1781 ge_cairo_stroke_rectangle (cr, 0.5, 0.5, width-1, height-1);
1783 cairo_move_to (cr, 1.5, height-1.5);
1784 cairo_line_to (cr, 1.5, 1.5);
1785 cairo_line_to (cr, width-1.5, 1.5);
1786 ge_shade_color (&s2, 1.3, &s5);
1787 cairo_set_source_rgba (cr, s5.r, s5.g, s5.b, 0.5);
1788 cairo_stroke(cr);
1790 /* draw handles */
1791 cairo_set_line_width (cr, 1);
1793 bar_x = width/2 - 4;
1794 cairo_translate(cr, 0.5, 0.5);
1795 for (i=0; i<3; i++)
1797 cairo_move_to (cr, bar_x, 4);
1798 cairo_line_to (cr, bar_x, height-5);
1799 ge_cairo_set_color (cr, dark);
1800 cairo_stroke (cr);
1802 cairo_move_to (cr, bar_x+1, 4);
1803 cairo_line_to (cr, bar_x+1, height-5);
1804 ge_cairo_set_color (cr, light);
1805 cairo_stroke (cr);
1807 bar_x += 3;
1813 static void
1814 clearlooks_draw_statusbar (cairo_t *cr,
1815 const ClearlooksColors *colors,
1816 const WidgetParameters *widget,
1817 int x, int y, int width, int height)
1819 (void) widget;
1820 (void) height;
1822 const CairoColor *dark = &colors->shade[3];
1823 CairoColor hilight;
1825 ge_shade_color (dark, 1.4, &hilight);
1827 cairo_set_line_width (cr, 1);
1828 cairo_translate (cr, x, y+0.5);
1829 cairo_move_to (cr, 0, 0);
1830 cairo_line_to (cr, width, 0);
1831 ge_cairo_set_color (cr, dark);
1832 cairo_stroke (cr);
1834 cairo_translate (cr, 0, 1);
1835 cairo_move_to (cr, 0, 0);
1836 cairo_line_to (cr, width, 0);
1837 ge_cairo_set_color (cr, &hilight);
1838 cairo_stroke (cr);
1841 static void
1842 clearlooks_draw_menu_frame (cairo_t *cr,
1843 const ClearlooksColors *colors,
1844 const WidgetParameters *widget,
1845 int x, int y, int width, int height)
1847 (void) widget;
1849 const CairoColor *border = &colors->shade[5];
1850 cairo_translate (cr, x, y);
1851 cairo_set_line_width (cr, 1);
1853 cairo_set_source_rgba (cr, colors->bg[0].r, colors->bg[0].g, colors->bg[0].b, 0.9);
1854 cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
1855 cairo_paint (cr);
1857 ge_cairo_set_color (cr, border);
1858 ge_cairo_stroke_rectangle (cr, 0.5, 0.5, width-1, height-1);
1861 static void
1862 clearlooks_draw_tooltip (cairo_t *cr,
1863 const ClearlooksColors *colors,
1864 const WidgetParameters *widget,
1865 int x, int y, int width, int height)
1867 CairoColor border;
1869 ge_shade_color (&colors->bg[widget->state_type], 0.6, &border);
1871 cairo_save (cr);
1873 cairo_translate (cr, x, y);
1874 cairo_set_line_width (cr, 1);
1876 ge_cairo_set_color (cr, &colors->bg[widget->state_type]);
1877 cairo_rectangle (cr, 0, 0, width, height);
1878 cairo_fill (cr);
1880 ge_cairo_set_color (cr, &border);
1881 ge_cairo_stroke_rectangle (cr, 0.5, 0.5, width-1, height-1);
1883 cairo_restore (cr);
1886 static void
1887 clearlooks_draw_handle (cairo_t *cr,
1888 const ClearlooksColors *colors,
1889 const WidgetParameters *params,
1890 const HandleParameters *handle,
1891 int x, int y, int width, int height)
1893 const CairoColor *fill = &colors->bg[params->state_type];
1894 int num_bars = 6; /* shut up gcc warnings */
1895 int bar_spacing;
1897 switch (handle->type)
1899 case CL_HANDLE_TOOLBAR:
1900 num_bars = 6;
1901 bar_spacing = 3;
1902 break;
1903 case CL_HANDLE_SPLITTER:
1904 num_bars = 16;
1905 bar_spacing = 3;
1906 break;
1909 if (params->prelight)
1911 cairo_rectangle (cr, x, y, width, height);
1912 ge_cairo_set_color (cr, fill);
1913 cairo_fill (cr);
1916 cairo_translate (cr, x+0.5, y+0.5);
1918 cairo_set_line_width (cr, 1);
1920 if (handle->horizontal)
1922 params->style_functions->draw_gripdots (cr, colors, 0, 0, width, height, num_bars, 2, 0.1);
1924 else
1926 params->style_functions->draw_gripdots (cr, colors, 0, 0, width, height, 2, num_bars, 0.1);
1930 static void
1931 clearlooks_draw_resize_grip (cairo_t *cr,
1932 const ClearlooksColors *colors,
1933 const WidgetParameters *widget,
1934 const ResizeGripParameters *grip,
1935 int x, int y, int width, int height)
1937 (void) widget;
1939 const CairoColor *dark = &colors->shade[4];
1940 CairoColor hilight;
1941 int lx, ly;
1942 int x_down;
1943 int y_down;
1944 int dots;
1946 ge_shade_color (dark, 1.5, &hilight);
1948 /* The number of dots fitting into the area. Just hardcoded to 4 right now. */
1949 /* dots = MIN (width - 2, height - 2) / 3; */
1950 dots = 4;
1952 cairo_save (cr);
1954 switch (grip->edge)
1956 case CL_WINDOW_EDGE_NORTH_EAST:
1957 x_down = 0;
1958 y_down = 0;
1959 cairo_translate (cr, x + width - 3*dots + 2, y + 1);
1960 break;
1961 case CL_WINDOW_EDGE_SOUTH_EAST:
1962 x_down = 0;
1963 y_down = 1;
1964 cairo_translate (cr, x + width - 3*dots + 2, y + height - 3*dots + 2);
1965 break;
1966 case CL_WINDOW_EDGE_SOUTH_WEST:
1967 x_down = 1;
1968 y_down = 1;
1969 cairo_translate (cr, x + 1, y + height - 3*dots + 2);
1970 break;
1971 case CL_WINDOW_EDGE_NORTH_WEST:
1972 x_down = 1;
1973 y_down = 0;
1974 cairo_translate (cr, x + 1, y + 1);
1975 break;
1976 default:
1977 /* Not implemented. */
1978 return;
1981 for (lx = 0; lx < dots; lx++) /* horizontally */
1983 for (ly = 0; ly <= lx; ly++) /* vertically */
1985 int mx, my;
1986 mx = x_down * dots + (1 - x_down * 2) * lx - x_down;
1987 my = y_down * dots + (1 - y_down * 2) * ly - y_down;
1989 ge_cairo_set_color (cr, &hilight);
1990 cairo_rectangle (cr, mx*3-1, my*3-1, 2, 2);
1991 cairo_fill (cr);
1993 ge_cairo_set_color (cr, dark);
1994 cairo_rectangle (cr, mx*3-1, my*3-1, 1, 1);
1995 cairo_fill (cr);
1999 cairo_restore (cr);
2002 static void
2003 clearlooks_draw_radiobutton (cairo_t *cr,
2004 const ClearlooksColors *colors,
2005 const WidgetParameters *widget,
2006 const CheckboxParameters *checkbox,
2007 int x, int y, int width, int height)
2009 (void) width;
2010 (void) height;
2012 const CairoColor *border;
2013 const CairoColor *dot;
2014 CairoColor shadow;
2015 CairoColor highlight;
2016 cairo_pattern_t *pt;
2017 gboolean inconsistent;
2018 gboolean draw_bullet = (checkbox->shadow_type == GTK_SHADOW_IN);
2020 inconsistent = (checkbox->shadow_type == GTK_SHADOW_ETCHED_IN);
2021 draw_bullet |= inconsistent;
2023 if (widget->disabled)
2025 border = &colors->shade[5];
2026 dot = &colors->shade[6];
2028 else
2030 border = &colors->shade[6];
2031 dot = &colors->text[0];
2034 ge_shade_color (&widget->parentbg, 0.9, &shadow);
2035 ge_shade_color (&widget->parentbg, 1.1, &highlight);
2037 pt = cairo_pattern_create_linear (0, 0, 13, 13);
2038 cairo_pattern_add_color_stop_rgb (pt, 0.0, shadow.r, shadow.b, shadow.g);
2039 cairo_pattern_add_color_stop_rgba (pt, 0.5, shadow.r, shadow.b, shadow.g, 0.5);
2040 cairo_pattern_add_color_stop_rgba (pt, 0.5, highlight.r, highlight.g, highlight.b, 0.5);
2041 cairo_pattern_add_color_stop_rgb (pt, 1.0, highlight.r, highlight.g, highlight.b);
2043 cairo_translate (cr, x, y);
2045 cairo_set_line_width (cr, 2);
2046 cairo_arc (cr, 7, 7, 6, 0, G_PI*2);
2047 cairo_set_source (cr, pt);
2048 cairo_stroke (cr);
2049 cairo_pattern_destroy (pt);
2051 cairo_set_line_width (cr, 1);
2053 cairo_arc (cr, 7, 7, 5.5, 0, G_PI*2);
2055 if (!widget->disabled)
2057 ge_cairo_set_color (cr, &colors->base[0]);
2058 cairo_fill_preserve (cr);
2061 ge_cairo_set_color (cr, border);
2062 cairo_stroke (cr);
2064 if (draw_bullet)
2066 if (inconsistent)
2068 cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
2069 cairo_set_line_width (cr, 4);
2071 cairo_move_to(cr, 5, 7);
2072 cairo_line_to(cr, 9, 7);
2074 ge_cairo_set_color (cr, dot);
2075 cairo_stroke (cr);
2077 else
2079 cairo_arc (cr, 7, 7, 3, 0, G_PI*2);
2080 ge_cairo_set_color (cr, dot);
2081 cairo_fill (cr);
2083 cairo_arc (cr, 6, 6, 1, 0, G_PI*2);
2084 cairo_set_source_rgba (cr, highlight.r, highlight.g, highlight.b, 0.5);
2085 cairo_fill (cr);
2090 static void
2091 clearlooks_draw_checkbox (cairo_t *cr,
2092 const ClearlooksColors *colors,
2093 const WidgetParameters *widget,
2094 const CheckboxParameters *checkbox,
2095 int x, int y, int width, int height)
2097 const CairoColor *border;
2098 const CairoColor *dot;
2099 gboolean inconsistent = FALSE;
2100 gboolean draw_bullet = (checkbox->shadow_type == GTK_SHADOW_IN);
2102 inconsistent = (checkbox->shadow_type == GTK_SHADOW_ETCHED_IN);
2103 draw_bullet |= inconsistent;
2105 if (widget->disabled)
2107 border = &colors->shade[5];
2108 dot = &colors->shade[6];
2110 else
2112 border = &colors->shade[6];
2113 dot = &colors->text[GTK_STATE_NORMAL];
2116 cairo_translate (cr, x, y);
2117 cairo_set_line_width (cr, 1);
2119 if (widget->xthickness > 2 && widget->ythickness > 2)
2121 widget->style_functions->draw_inset (cr, &widget->parentbg, 0.5, 0.5, width-1, height-1, 1, CR_CORNER_ALL);
2123 /* Draw the rectangle for the checkbox itself */
2124 ge_cairo_rounded_rectangle (cr, 1.5, 1.5, width-3, height-3, (widget->radius > 0)? 1 : 0, CR_CORNER_ALL);
2126 else
2128 /* Draw the rectangle for the checkbox itself */
2129 ge_cairo_rounded_rectangle (cr, 0.5, 0.5, width-1, height-1, (widget->radius > 0)? 1 : 0, CR_CORNER_ALL);
2132 if (!widget->disabled)
2134 ge_cairo_set_color (cr, &colors->base[0]);
2135 cairo_fill_preserve (cr);
2138 ge_cairo_set_color (cr, border);
2139 cairo_stroke (cr);
2141 if (draw_bullet)
2143 if (inconsistent) /* Inconsistent */
2145 cairo_set_line_width (cr, 2.0);
2146 cairo_move_to (cr, 3, height*0.5);
2147 cairo_line_to (cr, width-3, height*0.5);
2149 else
2151 cairo_set_line_width (cr, 1.7);
2152 cairo_move_to (cr, 0.5 + (width*0.2), (height*0.5));
2153 cairo_line_to (cr, 0.5 + (width*0.4), (height*0.7));
2155 cairo_curve_to (cr, 0.5 + (width*0.4), (height*0.7),
2156 0.5 + (width*0.5), (height*0.4),
2157 0.5 + (width*0.70), (height*0.25));
2161 ge_cairo_set_color (cr, dot);
2162 cairo_stroke (cr);
2166 static void
2167 clearlooks_draw_normal_arrow (cairo_t *cr, const CairoColor *color,
2168 double x, double y, double width, double height)
2170 double arrow_width;
2171 double arrow_height;
2172 double line_width_2;
2174 cairo_save (cr);
2176 arrow_width = MIN (height * 2.0 + MAX (1.0, ceil (height * 2.0 / 6.0 * 2.0) / 2.0) / 2.0, width);
2177 line_width_2 = MAX (1.0, ceil (arrow_width / 6.0 * 2.0) / 2.0) / 2.0;
2178 arrow_height = arrow_width / 2.0 + line_width_2;
2180 cairo_translate (cr, x, y - arrow_height / 2.0);
2182 cairo_move_to (cr, -arrow_width / 2.0, line_width_2);
2183 cairo_line_to (cr, -arrow_width / 2.0 + line_width_2, 0);
2184 /* cairo_line_to (cr, 0, arrow_height - line_width_2); */
2185 cairo_arc_negative (cr, 0, arrow_height - 2*line_width_2 - 2*line_width_2 * sqrt(2), 2*line_width_2, G_PI_2 + G_PI_4, G_PI_4);
2186 cairo_line_to (cr, arrow_width / 2.0 - line_width_2, 0);
2187 cairo_line_to (cr, arrow_width / 2.0, line_width_2);
2188 cairo_line_to (cr, 0, arrow_height);
2189 cairo_close_path (cr);
2191 ge_cairo_set_color (cr, color);
2192 cairo_fill (cr);
2194 cairo_restore (cr);
2197 static void
2198 clearlooks_draw_combo_arrow (cairo_t *cr, const CairoColor *color,
2199 double x, double y, double width, double height)
2201 double arrow_width = MIN (height * 2 / 3.0, width);
2202 double arrow_height = arrow_width / 2.0;
2203 double gap_size = 1.0 * arrow_height;
2205 cairo_save (cr);
2206 cairo_translate (cr, x, y - (arrow_height + gap_size) / 2.0);
2207 cairo_rotate (cr, G_PI);
2208 clearlooks_draw_normal_arrow (cr, color, 0, 0, arrow_width, arrow_height);
2209 cairo_restore (cr);
2211 clearlooks_draw_normal_arrow (cr, color, x, y + (arrow_height + gap_size) / 2.0, arrow_width, arrow_height);
2214 static void
2215 _clearlooks_draw_arrow (cairo_t *cr, const CairoColor *color,
2216 ClearlooksDirection dir, ClearlooksArrowType type,
2217 double x, double y, double width, double height)
2219 double rotate;
2221 if (dir == CL_DIRECTION_LEFT)
2222 rotate = G_PI*1.5;
2223 else if (dir == CL_DIRECTION_RIGHT)
2224 rotate = G_PI*0.5;
2225 else if (dir == CL_DIRECTION_UP)
2226 rotate = G_PI;
2227 else if (dir == CL_DIRECTION_DOWN)
2228 rotate = 0;
2229 else
2230 return;
2232 if (type == CL_ARROW_NORMAL)
2234 cairo_translate (cr, x, y);
2235 cairo_rotate (cr, -rotate);
2236 clearlooks_draw_normal_arrow (cr, color, 0, 0, width, height);
2238 else if (type == CL_ARROW_COMBO)
2240 cairo_translate (cr, x, y);
2241 clearlooks_draw_combo_arrow (cr, color, 0, 0, width, height);
2245 static void
2246 clearlooks_draw_arrow (cairo_t *cr,
2247 const ClearlooksColors *colors,
2248 const WidgetParameters *widget,
2249 const ArrowParameters *arrow,
2250 int x, int y, int width, int height)
2252 const CairoColor *color = &colors->fg[widget->state_type];
2253 gdouble tx, ty;
2255 tx = x + width/2.0;
2256 ty = y + height/2.0;
2258 if (widget->disabled)
2260 _clearlooks_draw_arrow (cr, &colors->shade[0],
2261 arrow->direction, arrow->type,
2262 tx+0.5, ty+0.5, width, height);
2265 cairo_identity_matrix (cr);
2267 _clearlooks_draw_arrow (cr, color, arrow->direction, arrow->type,
2268 tx, ty, width, height);
2271 void
2272 clearlooks_register_style_classic (ClearlooksStyleFunctions *functions)
2274 g_assert (functions);
2276 functions->draw_button = clearlooks_draw_button;
2277 functions->draw_scale_trough = clearlooks_draw_scale_trough;
2278 functions->draw_progressbar_trough = clearlooks_draw_progressbar_trough;
2279 functions->draw_progressbar_fill = clearlooks_draw_progressbar_fill;
2280 functions->draw_slider_button = clearlooks_draw_slider_button;
2281 functions->draw_entry = clearlooks_draw_entry;
2282 functions->draw_spinbutton = clearlooks_draw_spinbutton;
2283 functions->draw_spinbutton_down = clearlooks_draw_spinbutton_down;
2284 functions->draw_optionmenu = clearlooks_draw_optionmenu;
2285 functions->draw_inset = clearlooks_draw_inset;
2286 functions->draw_menubar = clearlooks_draw_menubar;
2287 functions->draw_tab = clearlooks_draw_tab;
2288 functions->draw_frame = clearlooks_draw_frame;
2289 functions->draw_separator = clearlooks_draw_separator;
2290 functions->draw_menu_item_separator = clearlooks_draw_menu_item_separator;
2291 functions->draw_list_view_header = clearlooks_draw_list_view_header;
2292 functions->draw_toolbar = clearlooks_draw_toolbar;
2293 functions->draw_menuitem = clearlooks_draw_menuitem;
2294 functions->draw_menubaritem = clearlooks_draw_menubaritem;
2295 functions->draw_selected_cell = clearlooks_draw_selected_cell;
2296 functions->draw_scrollbar_stepper = clearlooks_draw_scrollbar_stepper;
2297 functions->draw_scrollbar_slider = clearlooks_draw_scrollbar_slider;
2298 functions->draw_scrollbar_trough = clearlooks_draw_scrollbar_trough;
2299 functions->draw_statusbar = clearlooks_draw_statusbar;
2300 functions->draw_menu_frame = clearlooks_draw_menu_frame;
2301 functions->draw_tooltip = clearlooks_draw_tooltip;
2302 functions->draw_handle = clearlooks_draw_handle;
2303 functions->draw_resize_grip = clearlooks_draw_resize_grip;
2304 functions->draw_arrow = clearlooks_draw_arrow;
2305 functions->draw_checkbox = clearlooks_draw_checkbox;
2306 functions->draw_radiobutton = clearlooks_draw_radiobutton;
2307 functions->draw_shadow = clearlooks_draw_shadow;
2308 functions->draw_slider = clearlooks_draw_slider;
2309 functions->draw_gripdots = clearlooks_draw_gripdots;