23
23
#include "redmond_gtk2_drawing.h"
24
24
#include "redmond_gtk2_misc.h"
26
static char radio_base_bits[] = {
27
0x00,0x00,0x00,0x00,0xf0,0x01,0xf8,0x03,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
28
0x07,0xfc,0x07,0xf8,0x03,0xf0,0x01,0x00,0x00,0x00,0x00,0x00,0x00};
29
static char radio_black_bits[] = {
30
0x00,0x00,0xf0,0x01,0x0c,0x02,0x04,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
31
0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0d,0x08};
32
static char radio_dark_bits[] = {
33
0xf0,0x00,0x0c,0x02,0x02,0x00,0x02,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
34
0x00,0x00,0x00,0x02,0x00,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
35
static char radio_light_bits[] = {
36
0x00,0x00,0x00,0x04,0x00,0x08,0x00,0x08,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
37
0x10,0x00,0x10,0x00,0x08,0x00,0x08,0x08,0x06,0xf0,0x01,0x00,0x00};
38
static char radio_mid_bits[] = {
39
0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x04,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
40
0x08,0x00,0x08,0x00,0x04,0x00,0x06,0xf0,0x01,0x00,0x00,0x00,0x00};
41
static char radio_text_bits[] = {
42
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0xf0,0x01,0xf0,0x01,0xf0,
43
0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
52
radio_base_bits, NULL},
54
radio_black_bits, NULL},
56
radio_dark_bits, NULL},
58
radio_light_bits, NULL},
60
radio_mid_bits, NULL},
62
radio_text_bits, NULL}
66
/* Widget Type Lookups/Macros
68
Based on/modified from functions in
72
redmond_object_is_a (GtkWidget * widget, gchar * type_name)
74
gboolean result = FALSE;
78
GType tmp = g_type_from_name (type_name);
80
result = g_type_check_instance_is_a ((GTypeInstance *) widget, tmp);
87
redmond_is_combo_box_entry (GtkWidget * widget)
89
gboolean result = FALSE;
91
if ((widget) && (widget->parent))
93
if (IS_COMBO_BOX_ENTRY (widget->parent))
96
result = redmond_is_combo_box_entry (widget->parent);
102
combo_box_is_using_list (GtkWidget * widget)
104
gboolean result = FALSE;
106
if ((widget) && (IS_COMBO_BOX (widget->parent)))
108
gboolean *tmp = NULL;
110
gtk_widget_style_get (widget, "appears-as-list", &result, NULL);
120
redmond_is_combo_box (GtkWidget * widget, gboolean as_list)
122
gboolean result = FALSE;
124
if ((widget) && (widget->parent))
126
if (IS_COMBO_BOX (widget->parent))
129
result = (combo_box_is_using_list(widget));
131
result = (!combo_box_is_using_list(widget));
134
result = redmond_is_combo_box (widget->parent, as_list);
140
redmond_is_combo (GtkWidget * widget)
142
gboolean result = FALSE;
144
if ((widget) && (widget->parent))
146
if (IS_COMBO (widget->parent))
149
result = redmond_is_combo (widget->parent);
155
redmond_is_in_combo_box (GtkWidget * widget)
157
return ((redmond_is_combo (widget) || redmond_is_combo_box (widget, TRUE) || redmond_is_combo_box_entry (widget)));
161
redmond_is_toolbar_item (GtkWidget * widget)
163
gboolean result = FALSE;
165
if ((widget) && (widget->parent)) {
166
if ((IS_BONOBO_TOOLBAR (widget->parent))
167
|| (IS_BONOBO_DOCK_ITEM (widget->parent))
168
|| (IS_EGG_TOOLBAR (widget->parent))
169
|| (IS_TOOLBAR (widget->parent))
170
|| (IS_HANDLE_BOX (widget->parent)))
173
result = redmond_is_toolbar_item (widget->parent);
179
redmond_is_panel_widget_item (GtkWidget * widget)
181
gboolean result = FALSE;
183
if ((widget) && (widget->parent))
185
if (IS_PANEL_WIDGET (widget->parent))
188
result = redmond_is_panel_widget_item (widget->parent);
194
redmond_is_bonobo_dock_item (GtkWidget * widget)
196
gboolean result = FALSE;
200
if (IS_BONOBO_DOCK_ITEM(widget) || IS_BONOBO_DOCK_ITEM (widget->parent))
202
else if (IS_BOX(widget) || IS_BOX(widget->parent))
204
GtkContainer *box = IS_BOX(widget)?GTK_CONTAINER(widget):GTK_CONTAINER(widget->parent);
205
GList *children = NULL, *child = NULL;
207
children = gtk_container_get_children(box);
209
for (child = g_list_first(children); child; child = g_list_next(child))
211
if (IS_BONOBO_DOCK_ITEM_GRIP(child->data))
219
g_list_free(children);
225
/***********************************************/
227
/***********************************************/
229
/***********************************************
230
* redmond_sanitize_parameters -
232
* Ensure Size and Values are valid
234
* Taken from Smooth based on Metal
235
***********************************************/
237
redmond_sanitize_parameters(GtkStyle * style,
242
if (!style) return FALSE;
243
if (!window) return FALSE;
245
if ((width) && (height)) {
246
if ((*width == -1) && (*height == -1))
247
gdk_drawable_get_size (window, width, height);
248
else if (*width == -1)
249
gdk_drawable_get_size(window, width, NULL);
250
else if (*height == -1)
251
gdk_drawable_get_size (window, NULL, height);
256
/***********************************************
257
* redmond_option_menu_get_props -
259
* Find Option Menu Size and Spacing
262
***********************************************/
263
static GtkRequisition default_option_indicator_size = { 9, 5 };
264
static GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
267
redmond_option_menu_get_props (GtkWidget * widget,
268
GtkRequisition * indicator_size,
269
GtkBorder * indicator_spacing)
271
GtkRequisition *tmp_size = NULL;
272
GtkBorder *tmp_spacing = NULL;
274
if ((widget) && IS_OPTION_MENU(widget))
275
gtk_widget_style_get (widget,
276
"indicator_size", &tmp_size,
277
"indicator_spacing", &tmp_spacing, NULL);
281
*indicator_size = *tmp_size;
285
*indicator_size = default_option_indicator_size;
289
*indicator_spacing = *tmp_spacing;
290
g_free (tmp_spacing);
293
*indicator_spacing = default_option_indicator_spacing;
296
/***********************************************/
297
/* Colour Shade Routines */
298
/***********************************************/
300
/***********************************************
301
* color_get_rgb_from_hsb -
303
* Get HSB values from RGB values.
305
* Taken from Smooth but originated in GTK+
306
***********************************************/
308
color_get_hsb_from_rgb (gdouble red,
315
gdouble min, max, delta;
319
max = MAX(red, blue);
320
min = MIN(green, blue);
324
max = MAX(green, blue);
325
min = MIN(red, blue);
328
*brightness = (max + min) / 2;
337
if (*brightness <= 0.5)
338
*saturation = (max - min) / (max + min);
340
*saturation = (max - min) / (2 - max - min);
345
*hue = (green - blue) / delta;
346
else if (green == max)
347
*hue = 2 + (blue - red) / delta;
348
else if (blue == max)
349
*hue = 4 + (red - green) / delta;
357
/***********************************************
358
* color_get_rgb_from_hsb -
360
* Get RGB values from HSB values.
362
* Taken from Smooth but originated in GTK+
363
***********************************************/
364
#define MODULA(number, divisor) (((gint)number % divisor) + (number - (gint)number))
366
color_get_rgb_from_hsb (gdouble hue,
374
gdouble hue_shift[3], color_shift[3];
377
if (brightness <= 0.5)
378
m2 = brightness * (1 + saturation);
380
m2 = brightness + saturation - brightness * saturation;
382
m1 = 2 * brightness - m2;
384
hue_shift[0] = hue + 120;
386
hue_shift[2] = hue - 120;
388
color_shift[0] = color_shift[1] = color_shift[2] = brightness;
390
i = (saturation == 0)?3:0;
397
m3 = MODULA(m3, 360);
399
m3 = 360 - MODULA(ABS(m3), 360);
402
color_shift[i] = m1 + (m2 - m1) * m3 / 60;
406
color_shift[i] = m1 + (m2 - m1) * (240 - m3) / 60;
411
*red = color_shift[0];
412
*green = color_shift[1];
413
*blue = color_shift[2];
416
/***********************************************
417
* redmond_composite_color_shade -
419
* Calculate a composite color shade ratio.
421
* Taken from Smooth but originated in GTK+
422
***********************************************/
424
redmond_composite_color_shade(GdkColor *original,
433
gdouble saturation = 0;
434
gdouble brightness = 0;
436
red = (gdouble) original->red / 65535.0;
437
green = (gdouble) original->green / 65535.0;
438
blue = (gdouble) original->blue / 65535.0;
440
color_get_hsb_from_rgb (red, green, blue, &hue, &saturation, &brightness);
442
brightness = MIN(brightness*shade_ratio, 1.0);
443
brightness = MAX(brightness, 0.0);
445
saturation = MIN(saturation*shade_ratio, 1.0);
446
saturation = MAX(saturation, 0.0);
448
color_get_rgb_from_hsb (hue, saturation, brightness, &red, &green, &blue);
450
composite->red = red * 65535.0;
451
composite->green = green * 65535.0;
452
composite->blue = blue * 65535.0;
455
/***********************************************/
456
/* Base Drawing Routines */
457
/***********************************************/
459
/***********************************************
460
* redmond_draw_part -
462
* draw a bits generated pixmap part with a
464
***********************************************/
466
redmond_draw_part (GdkDrawable * drawable,
474
gdk_gc_set_clip_rectangle (gc, area);
476
if (!parts[part].bmap)
477
parts[part].bmap = gdk_bitmap_create_from_data (drawable,
479
PART_SIZE, PART_SIZE);
481
gdk_gc_set_ts_origin (gc, x, y);
482
gdk_gc_set_stipple (gc, parts[part].bmap);
483
gdk_gc_set_fill (gc, GDK_STIPPLED);
485
gdk_draw_rectangle (drawable, gc, TRUE, x, y, PART_SIZE, PART_SIZE);
487
gdk_gc_set_fill (gc, GDK_SOLID);
490
gdk_gc_set_clip_rectangle (gc, NULL);
493
/***********************************************
494
* do_redmond_draw_fill -
496
* A simple routine to fill with the bg_gc
497
***********************************************/
499
do_redmond_draw_default_fill (GtkStyle *style,
501
GtkStateType state_type,
509
gdk_gc_set_clip_rectangle(style->bg_gc[state_type], area);
511
gdk_draw_rectangle (window, style->bg_gc[state_type], TRUE,
515
gdk_gc_set_clip_rectangle(style->bg_gc[state_type], NULL);
518
/***********************************************
519
* do_redmond_draw_cross_hatch_fill -
521
* A simple routine to draw a thin cross-hatch
522
* background fill. This is use for Scrollbar
523
* Trough's and greyed Checkbox's
525
* It originated in Smooth-Engine.
526
***********************************************/
528
do_redmond_draw_cross_hatch_fill (GtkStyle * style,
538
GdkGCValues gc_values;
542
pixmap = gdk_pixmap_new (window, 2, 2, -1);
544
gdk_draw_point (pixmap, style->bg_gc[state], 0, 0);
545
gdk_draw_point (pixmap, style->bg_gc[state], 1, 1);
546
gdk_draw_point (pixmap, style->light_gc[state], 1, 0);
547
gdk_draw_point (pixmap, style->light_gc[state], 0, 1);
549
gc_values.fill = GDK_TILED;
550
gc_values.tile = pixmap;
551
gc_values.ts_x_origin = x;
552
gc_values.ts_y_origin = y;
553
gc = gdk_gc_new_with_values (window, &gc_values,
554
GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN |
555
GDK_GC_FILL | GDK_GC_TILE);
557
if (part != RADIO_NONE)
559
if (!parts[part].bmap)
560
parts[part].bmap = gdk_bitmap_create_from_data (window,
562
PART_SIZE, PART_SIZE);
563
gdk_gc_set_clip_origin (gc, x, y);
564
gdk_gc_set_clip_mask(gc, parts[part].bmap);
567
gdk_gc_set_clip_rectangle (gc, area);
569
gdk_draw_rectangle (window, gc, TRUE, x, y, width, height);
572
g_object_unref (pixmap);
575
/***********************************************
576
* do_redmond_draw_shadow -
578
* A simple routine to draw thin border
579
* with a topleft and bottomright gc.
580
* Used to cut down the length of all the
583
* It originated in Smooth-Engine.
584
***********************************************/
586
do_redmond_draw_shadow (GdkWindow * window,
593
gboolean topleft_overlap)
597
gdk_draw_line (window, br_gc, x, y + height - 1, x + width - 1,
599
gdk_draw_line (window, br_gc, x + width - 1, y, x + width - 1,
603
gdk_draw_line (window, tl_gc, x, y, x, y + height - 1);
604
gdk_draw_line (window, tl_gc, x, y, x + width - 1, y);
606
if (!topleft_overlap)
608
gdk_draw_line (window, br_gc, x, y + height - 1, x + width - 1,
610
gdk_draw_line (window, br_gc, x + width - 1, y, x + width - 1,
27
do_redmond_draw_pattern_fill (cairo_t * cr,
28
CairoPattern *pattern,
34
cairo_matrix_t original_matrix, current_matrix;
36
cairo_pattern_get_matrix(pattern->handle, &original_matrix);
37
current_matrix = original_matrix;
39
if (pattern->scale != REDMOND_DIRECTION_NONE)
41
gdouble scale_x = 1.0;
42
gdouble scale_y = 1.0;
44
if ((pattern->scale == REDMOND_DIRECTION_VERTICAL) || (pattern->scale == REDMOND_DIRECTION_BOTH))
49
if ((pattern->scale == REDMOND_DIRECTION_HORIZONTAL) || (pattern->scale == REDMOND_DIRECTION_BOTH))
54
cairo_matrix_scale(¤t_matrix, scale_x, scale_y);
57
if (pattern->translate != REDMOND_DIRECTION_NONE)
59
gdouble translate_x = 0;
60
gdouble translate_y = 0;
62
if ((pattern->translate == REDMOND_DIRECTION_VERTICAL) || (pattern->translate == REDMOND_DIRECTION_BOTH))
67
if ((pattern->translate == REDMOND_DIRECTION_HORIZONTAL) || (pattern->translate == REDMOND_DIRECTION_BOTH))
72
cairo_matrix_translate(¤t_matrix, translate_x, translate_y);
75
cairo_pattern_set_matrix(pattern->handle, ¤t_matrix);
79
cairo_set_source(cr, pattern->handle);
81
cairo_rectangle(cr, x, y, width, height);
87
cairo_pattern_set_matrix(pattern->handle, &original_matrix);
91
do_redmond_draw_masked_fill (cairo_t * cr,
93
CairoColor * background,
94
CairoColor * foreground,
100
ge_cairo_set_color(cr, background);
101
cairo_rectangle (cr, x, y, width, height);
104
ge_cairo_set_color(cr, foreground);
105
cairo_rectangle (cr, x, y, width, height);
106
cairo_mask (cr, mask->handle);
615
109
/***********************************************
616
110
* do_redmond_draw_check -
618
112
* A simple routine to draw a redmond style
619
* check mark using the passed GC.
113
* check mark using the passed Color.
621
115
* It originated in Smooth-Engine.
622
116
***********************************************/
624
do_redmond_draw_check (GdkWindow * window,
637
gdk_draw_line (window, gc, x + 0, y + height - 5, x + 0, y + height - 3); /* Left Line */
638
gdk_draw_line (window, gc, x + 1, y + height - 4, x + 1, y + height - 2); /* Right Line */
641
gdk_draw_line (window, gc, x + 2, y + height - 3, x + width - 1, y + 0); /* Top Line */
642
gdk_draw_line (window, gc, x + 2, y + height - 2, x + width - 1, y + 1); /* Center Line */
643
gdk_draw_line (window, gc, x + 2, y + height - 1, x + width - 1, y + 2); /* Bottom Line */
118
do_redmond_draw_check (cairo_t *canvas,
129
scale = MIN(width, height);
133
if (odd = (scale % 2))
138
if (scale <= (factor + 2))
141
left = x + floor((width - scale) / 2) + 0.5;
142
top = y + floor((height - scale) / 2) + 0.5;
146
ge_cairo_set_color(canvas, color);
147
cairo_set_line_width(canvas, 0.5);
153
+---+---+---+---+---+---+---+---+---+---+
154
0 | | | | | | | | | | |
155
+---+---+---+---+---+---+---+---+---+---+
156
1 | | | | | | | | | x | |
157
+---+---+---+---+---+---+---+---+---+---+
158
2 | | | | | | | | x | x | |
159
+---+---+---+---+---+---+---+---+---+---+
160
3 | | | | | | | x | x | x | |
161
+---+---+---+---+---+---+---+---+---+---+
162
4 | | x | | | | x | x | x | | |
163
+---+---+---+---+---+---+---+---+---+---+
164
5 | | x | x | | x | x | x | | | |
165
+---+---+---+---+---+---+---+---+---+---+
166
6 | | x | x | x | x | x | | | | |
167
+---+---+---+---+---+---+---+---+---+---+
168
7 | | | x | x | x | | | | | |
169
+---+---+---+---+---+---+---+---+---+---+
170
8 | | | | x | | | | | | |
171
+---+---+---+---+---+---+---+---+---+---+
172
9 | | | | | | | | | | |
173
+---+---+---+---+---+---+---+---+---+---+
178
+---+---+---+---+---+---+---+---+---+
179
0 | | | | | | | | | |
180
+---+---+---+---+---+---+---+---+---+
181
1 | | | | | | | | x | |
182
+---+---+---+---+---+---+---+---+---+
183
2 | | | | | | | x | x | |
184
+---+---+---+---+---+---+---+---+---+
185
3 | | x | | | | x | x | x | |
186
+---+---+---+---+---+---+---+---+---+
187
4 | | x | x | | x | x | x | | |
188
+---+---+---+---+---+---+---+---+---+
189
5 | | x | x | x | x | x | | | |
190
+---+---+---+---+---+---+---+---+---+
191
6 | | | x | x | x | | | | |
192
+---+---+---+---+---+---+---+---+---+
193
7 | | | | x | | | | | |
194
+---+---+---+---+---+---+---+---+---+
195
8 | | | | | | | | | |
196
+---+---+---+---+---+---+---+---+---+
200
cairo_move_to(canvas, left + floor((1*scale)/factor), top + floor(((4-odd)*scale)/factor)); //(1,4-odd)
201
cairo_line_to(canvas, left + floor((1*scale)/factor), top + floor(((6-odd)*scale)/factor)); //(1,6-odd)
202
cairo_line_to(canvas, left + floor((3*scale)/factor), top + floor(((8-odd)*scale)/factor)); //(3,8-odd)
203
cairo_line_to(canvas, left + floor(((8-odd)*scale)/factor), top + floor((3*scale)/factor)); //(8-odd,3)
204
cairo_line_to(canvas, left + floor(((8-odd)*scale)/factor), top + floor((1*scale)/factor)); //(8-odd,1)
205
cairo_line_to(canvas, left + floor((3*scale)/factor), top + floor(((6-odd)*scale)/factor)); //(3,6-odd)
206
cairo_line_to(canvas, left + floor((1*scale)/factor), top + floor(((4-odd)*scale)/factor)); //(1,4-odd)
210
cairo_move_to(canvas, left + floor((1*scale)/factor), top + floor(((4-odd)*scale)/factor)); //(1,4-odd)
211
cairo_line_to(canvas, left + floor((1*scale)/factor), top + floor(((6-odd)*scale)/factor)); //(1,6-odd)
212
cairo_line_to(canvas, left + floor((3*scale)/factor), top + floor(((8-odd)*scale)/factor)); //(3,8-odd)
213
cairo_line_to(canvas, left + floor(((8-odd)*scale)/factor), top + floor((3*scale)/factor)); //(8-odd,3)
214
cairo_line_to(canvas, left + floor(((8-odd)*scale)/factor), top + floor((1*scale)/factor)); //(8-odd,1)
215
cairo_line_to(canvas, left + floor((3*scale)/factor), top + floor(((6-odd)*scale)/factor)); //(3,6-odd)
216
cairo_line_to(canvas, left + floor((1*scale)/factor), top + floor(((4-odd)*scale)/factor)); //(1,4-odd)
218
cairo_stroke(canvas);
220
cairo_restore(canvas);
646
223
/***********************************************