1
#include "misc_functions.h"
3
/* This function is based on XFCE's & CleanIce draw arrow routines, both which were based on ThinIce's */
5
do_draw_default_arrow(GdkWindow * window,
7
GtkArrowType arrow_type,
15
gint start, increment;
19
gdk_gc_set_clip_rectangle (gc, area);
21
if (arrow_type == GTK_ARROW_UP || arrow_type == GTK_ARROW_DOWN)
23
width = width + width % 2 - 1; /* Force odd */
25
steps = 1 + width / 2;
27
extra = height - steps;
29
if (arrow_type == GTK_ARROW_DOWN)
36
start = y + height - 1;
40
for (i = 0; i < extra; i++)
42
gdk_draw_line (window, gc, x, start + i * increment, x + width - 1, start + i * increment);
44
for (; i < height; i++)
46
gdk_draw_line (window, gc, x + (i - extra), start + i * increment, x + width - (i - extra) - 1, start + i * increment);
51
height = height + height % 2 - 1; /* Force odd */
53
steps = 1 + height / 2;
55
extra = width - steps;
57
if (arrow_type == GTK_ARROW_RIGHT)
64
start = x + width - 1;
68
for (i = 0; i < extra; i++)
70
gdk_draw_line (window, gc, start + i * increment, y, start + i * increment, y + height - 1);
72
for (; i < width; i++)
74
gdk_draw_line (window, gc, start + i * increment, y + (i - extra), start + i * increment, y + height - (i - extra) - 1);
78
gdk_gc_set_clip_rectangle (gc, NULL);
81
/* This function is based on EnGradient/IceGradient's draw arrow routines */
83
do_draw_icegradient_arrow(GdkWindow * window,
85
GtkArrowType arrow_type,
93
gint half_width, half_height,w;
99
w = MIN(width, height);
104
half_width = width / 2;
105
half_height = height / 2;
107
switch (arrow_type) {
109
points[0].x = x + half_width - 1;
112
points[1].y = y + height - 1;
113
points[2].x = x + width - 1;
114
points[2].y = y + height - 1;
115
points[3].x = x + half_width;
120
points[0].x = x + half_width ;
121
points[0].y = y + height - 1;
122
points[1].x = x + width - 1;
126
points[3].x = x + half_width - 1;
127
points[3].y = y + height - 1;
132
points[0].y = y + half_height;
133
points[1].x = x + width - 1;
134
points[1].y = y + height - 1;
135
points[2].x = x + width - 1;
138
points[3].y = y + half_height - 1;
141
case GTK_ARROW_RIGHT:
142
points[0].x = x + width - 1;
143
points[0].y = y + half_height - 1;
147
points[2].y = y + height - 1;
148
points[3].x = x + width - 1;
149
points[3].y = y + half_height;
158
gdk_gc_set_clip_rectangle (gc, area);
160
gdk_draw_polygon (window, gc, fill, points, 4);
163
gdk_gc_set_clip_rectangle (gc, NULL);
167
/* This function is taken straight from the Wonderland
168
* theme engine, with no modifications whatsoever.(yet...)
171
arrow_draw_hline (GdkWindow *window,
178
if (x2 - x1 < 7 && !last) /* 7 to get garretts pixels, otherwise 6 */
179
gdk_draw_line (window, gc, x1, y, x2, y);
184
gdk_draw_line (window, gc, x1+1, y, x1+1, y);
185
gdk_draw_line (window, gc, x2-1, y, x2-1, y);
189
gdk_draw_line (window, gc, x1+2, y, x1+2, y);
190
gdk_draw_line (window, gc, x2-2, y, x2-2, y);
195
gdk_draw_line (window, gc, x1, y, x1+2, y);
196
gdk_draw_line (window, gc, x2-2, y, x2, y);
200
/* This function is taken straight from the Wonderland
201
* theme engine, with no modifications whatsoever.(yet...)
204
arrow_draw_vline (GdkWindow *window,
211
if (y2 - y1 < 7 && !last) /* 7 to get garretts pixels */
212
gdk_draw_line (window, gc, x, y1, x, y2);
215
gdk_draw_line (window, gc, x, y1+2, x, y1+2);
216
gdk_draw_line (window, gc, x, y2-2, x, y2-2);
220
gdk_draw_line (window, gc, x, y1, x, y1+2);
221
gdk_draw_line (window, gc, x, y2-2, x, y2);
225
/* This function is based on the Wonderland theme engine,
226
* it is essentially calculate_arrow_geometry and draw_arrow,
227
* concatted into one composite whole...
230
do_draw_wonderland_arrow(GdkWindow * window,
232
GtkArrowType arrow_type,
256
if (arrow_type == GTK_ARROW_DOWN)
258
if (height % 2 == 1 || h % 2 == 0)
263
if (height % 2 == 0 || h % 2 == 0)
268
case GTK_ARROW_RIGHT:
279
if (arrow_type == GTK_ARROW_RIGHT)
281
if (width % 2 == 1 || w % 2 == 0)
286
if (width % 2 == 0 || w % 2 == 0)
292
/* should not be reached */
296
x += (width - w) / 2;
297
y += (height - h) / 2;
303
gdk_gc_set_clip_rectangle (gc, area);
305
if (arrow_type == GTK_ARROW_DOWN)
307
for (i = 0, j = -1; i < height; i++, j++)
308
arrow_draw_hline (window, gc, x + j, x + width - j - 1, y + i, i == 0);
311
else if (arrow_type == GTK_ARROW_UP)
313
for (i = height - 1, j = -1; i >= 0; i--, j++)
314
arrow_draw_hline (window, gc, x + j, x + width - j - 1, y + i, i == height - 1);
316
else if (arrow_type == GTK_ARROW_LEFT)
318
for (i = width - 1, j = -1; i >= 0; i--, j++)
319
arrow_draw_vline (window, gc, y + j, y + height - j - 1, x + i, i == width - 1);
321
else if (arrow_type == GTK_ARROW_RIGHT)
323
for (i = 0, j = -1; i < width; i++, j++)
324
arrow_draw_vline (window, gc, y + j, y + height - j - 1, x + i, i == 0);
328
gdk_gc_set_clip_rectangle (gc, NULL);
332
/* This function is another home grown routine simply for the
333
* purpose of abstracting the multiple draw_arrow routines, so
334
* that modifications such as new variants could easily be added
335
* later on with virtually no modifications anywhere else.
338
do_draw_arrow(GdkWindow * window,
340
GtkArrowType arrow_type,
349
gint aw=width, ah=height, extra_tail=0;
351
switch (arrow_style) {
352
case ARROW_STYLE_ICEGRADIENT :
355
x += (width - aw) / 2;
356
y += (height - ah) / 2;
357
do_draw_icegradient_arrow(window, area, arrow_type, fill_gc, TRUE, x, y, aw, ah);
358
do_draw_icegradient_arrow(window, area, arrow_type, border_gc, FALSE, x, y, aw, ah);
360
case ARROW_STYLE_WONDERLAND :
361
do_draw_wonderland_arrow(window, area, arrow_type, border_gc, x+1, y+1, width-2, height-2);
363
case ARROW_STYLE_THINICE :
364
case ARROW_STYLE_XFCE :
365
case ARROW_STYLE_DEFAULT :
366
if (arrow_style == ARROW_STYLE_THINICE)
369
if (arrow_style == ARROW_STYLE_XFCE)
374
if ((arrow_type == GTK_ARROW_LEFT) || (arrow_type == GTK_ARROW_RIGHT)) {
375
gfloat tmp=((ah+1)/2) - ((width%2)?1:0);
377
ah = 2*aw - 1 - ((width%2)?1:0);
384
if ((ah < 5) || (aw < 3)) {
390
gfloat tmp=((aw+1)/2) - ((height%2)?1:0);
393
aw = 2*ah - 1 - ((height%2)?1:0);
400
if ((aw < 5) || (ah < 3)) {
407
x += (width - aw) / 2 ;
408
y += (height - ah) / 2;
410
do_draw_default_arrow(window, area, arrow_type, border_gc, x, y, aw, ah);
411
do_draw_default_arrow(window, area, arrow_type, fill_gc, x+1, y+1, aw-2, ah-2);
413
case ARROW_STYLE_XPM :
415
do_draw_arrow(window, area, arrow_type, fill_gc, border_gc, x, y, width, height, ARROW_STYLE_ICEGRADIENT);
422
TranslateArrowStyleName (gchar * str, gint *retval)
424
#define is_enum(XX) (g_ascii_strncasecmp(str, XX, strlen(XX))==0)
425
if (is_enum("icegradient"))
426
*retval = ARROW_STYLE_ICEGRADIENT;
427
else if (is_enum("thinice"))
428
*retval = ARROW_STYLE_THINICE;
429
else if (is_enum("wonderland"))
430
*retval = ARROW_STYLE_WONDERLAND;
431
else if (is_enum("default") || is_enum("cleanice"))
432
*retval = ARROW_STYLE_DEFAULT;
433
else if (is_enum("xfce"))
434
*retval = ARROW_STYLE_XFCE;
435
else if (is_enum("xpm"))
436
*retval = ARROW_STYLE_XPM;