1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
3 /* eel-gdk-extensions.c: Graphics routines to augment what's in gdk.
4
5 Copyright (C) 1999, 2000 Eazel, Inc.
6
7 The Mate Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
11
12 The Mate 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.
16
17 You should have received a copy of the GNU Library General Public
18 License along with the Mate Library; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21
22 Authors: Darin Adler <darin@eazel.com>,
23 Pavel Cisler <pavel@eazel.com>,
24 Ramiro Estrugo <ramiro@eazel.com>
25 */
26
27 #include <config.h>
28 #include "eel-gdk-extensions.h"
29
30 #include "eel-glib-extensions.h"
31 #include "eel-lib-self-check-functions.h"
32 #include "eel-string.h"
33 #include <gdk-pixbuf/gdk-pixbuf.h>
34 #include <gdk/gdkprivate.h>
35 #include <gdk/gdk.h>
36 #include <gdk/gdkx.h>
37 #include <stdlib.h>
38 #include <pango/pango.h>
39
40 /**
41 * eel_gradient_new
42 * @start_color: Color for the top or left.
43 * @end_color: Color for the bottom or right.
44 * @is_horizontal: Direction of the gradient.
45 *
46 * Create a string that combines the start and end colors along
47 * with the direction of the gradient in a standard format.
48 */
49 char *
eel_gradient_new(const char * start_color,const char * end_color,gboolean is_horizontal)50 eel_gradient_new (const char *start_color,
51 const char *end_color,
52 gboolean is_horizontal)
53 {
54 /* Handle the special case where the start and end colors are identical.
55 Handle the special case where the end color is an empty string.
56 */
57 if (eel_strcmp(start_color, end_color) == 0 || end_color == NULL || end_color[0] == '\0')
58 {
59 return g_strdup (start_color);
60 }
61
62 /* Handle the special case where the start color is an empty string. */
63 if (start_color == NULL || start_color[0] == '\0')
64 {
65 return g_strdup (end_color);
66 }
67
68 /* Handle the general case. */
69 return g_strconcat (start_color, "-", end_color, is_horizontal ? ":h" : NULL, NULL);
70 }
71
72 /**
73 * eel_gradient_is_gradient
74 * @gradient_spec: A gradient spec. string.
75 *
76 * Return true if the spec. specifies a gradient instead of a solid color.
77 */
78 gboolean
eel_gradient_is_gradient(const char * gradient_spec)79 eel_gradient_is_gradient (const char *gradient_spec)
80 {
81 return eel_strchr (gradient_spec, '-') != NULL;
82 }
83
84 /**
85 * eel_gradient_is_horizontal
86 * @gradient_spec: A gradient spec. string.
87 *
88 * Return true if the spec. specifies a horizontal gradient.
89 */
90 gboolean
eel_gradient_is_horizontal(const char * gradient_spec)91 eel_gradient_is_horizontal (const char *gradient_spec)
92 {
93 size_t length;
94
95 length = eel_strlen (gradient_spec);
96 return length >= 2 && gradient_spec[length - 2] == ':' && gradient_spec[length - 1] == 'h';
97 }
98
99 static char *
eel_gradient_strip_trailing_direction_if_any(const char * gradient_spec)100 eel_gradient_strip_trailing_direction_if_any (const char *gradient_spec)
101 {
102 size_t length;
103
104 length = eel_strlen (gradient_spec);
105 if (length >= 2 && gradient_spec[length - 2] == ':'
106 && (gradient_spec[length - 1] == 'v' || gradient_spec[length - 1] == 'h'))
107 {
108 length -= 2;
109 }
110
111 return g_strndup (gradient_spec, length);
112 }
113
114 /* For parsing n-point gradients. Successive calls should pass the next_spec value
115 * set by the previous call as their first argument - to continue parsing where the
116 * previous call left off.
117 */
118 char *
eel_gradient_parse_one_color_spec(const char * spec,int * percent,const char ** next_spec)119 eel_gradient_parse_one_color_spec (const char *spec, int *percent, const char **next_spec)
120 {
121 char *result;
122 const char *rgb_end_ptr;
123 const char *percent_ptr;
124 const char *separator_ptr;
125
126 percent_ptr = eel_strchr (spec, '%');
127 separator_ptr = eel_strchr (spec, '-');
128
129 if (percent_ptr != NULL && (separator_ptr == NULL || percent_ptr < separator_ptr))
130 {
131 if (percent != NULL)
132 {
133 *percent = (int) strtol (percent_ptr + 1, NULL, 10);
134 }
135 rgb_end_ptr = percent_ptr;
136 }
137 else
138 {
139 if (percent != NULL)
140 {
141 *percent = 100;
142 }
143 rgb_end_ptr = separator_ptr;
144 }
145
146 if (rgb_end_ptr != NULL)
147 {
148 result = g_strndup (spec, rgb_end_ptr - spec);
149 }
150 else
151 {
152 result = eel_gradient_strip_trailing_direction_if_any (spec);
153 }
154
155 /* It's important not to use spec after setting *next_spec because it's
156 * likely that *next_spec == spec.
157 */
158 if (next_spec != NULL)
159 {
160 *next_spec = (separator_ptr != NULL) ? separator_ptr + 1 : NULL;
161 }
162
163 return result;
164 }
165
166 /* FIXME bugzilla.eazel.com 5076:
167 * anyone using eel_gradient_get_start_color_spec or
168 * eel_gradient_get_end_color_spec is assuming the gradient
169 * is 2 colors which is questionable.
170 *
171 * Callers should be rewritten and these fns eliminated.
172 */
173
174 /**
175 * eel_gradient_get_start_color_spec
176 * @gradient_spec: A gradient spec. string.
177 *
178 * Return the start color.
179 * This may be the entire gradient_spec if it's a solid color.
180 */
181 char *
eel_gradient_get_start_color_spec(const char * gradient_spec)182 eel_gradient_get_start_color_spec (const char *gradient_spec)
183 {
184 return eel_gradient_parse_one_color_spec (gradient_spec, NULL, NULL);
185 }
186
187 /**
188 * eel_gradient_get_end_color_spec
189 * @gradient_spec: A gradient spec. string.
190 *
191 * Return the end color.
192 * This may be the entire gradient_spec if it's a solid color.
193 */
194 char *
eel_gradient_get_end_color_spec(const char * gradient_spec)195 eel_gradient_get_end_color_spec (const char *gradient_spec)
196 {
197 char* color = NULL;
198
199 do
200 {
201 g_free (color);
202 color = eel_gradient_parse_one_color_spec (gradient_spec, NULL, &gradient_spec);
203 }
204 while (gradient_spec != NULL);
205
206 return color;
207 }
208
209 /* Do the work shared by all the set_color_spec functions below. */
210 static char *
eel_gradient_set_edge_color(const char * gradient_spec,const char * edge_color,gboolean is_horizontal,gboolean change_end)211 eel_gradient_set_edge_color (const char *gradient_spec,
212 const char *edge_color,
213 gboolean is_horizontal,
214 gboolean change_end)
215 {
216 char *opposite_color;
217 char *result;
218
219 g_assert (edge_color != NULL);
220
221 /* Get the color from the existing gradient spec. for the opposite
222 edge. This will parse away all the stuff we don't want from the
223 old gradient spec.
224 */
225 opposite_color = change_end
226 ? eel_gradient_get_start_color_spec (gradient_spec)
227 : eel_gradient_get_end_color_spec (gradient_spec);
228
229 /* Create a new gradient spec. The eel_gradient_new function handles
230 some special cases, so we don't have to bother with them here.
231 */
232 result = eel_gradient_new (change_end ? opposite_color : edge_color,
233 change_end ? edge_color : opposite_color,
234 is_horizontal);
235
236 g_free (opposite_color);
237
238 return result;
239 }
240
241 /**
242 * eel_gradient_set_left_color_spec
243 * @gradient_spec: A gradient spec. string.
244 * @left_color: Color spec. to replace left color with.
245 *
246 * Changes the left color to what's passed in.
247 * This creates a horizontal gradient.
248 */
249 char *
eel_gradient_set_left_color_spec(const char * gradient_spec,const char * left_color)250 eel_gradient_set_left_color_spec (const char *gradient_spec,
251 const char *left_color)
252 {
253 g_return_val_if_fail (gradient_spec != NULL, NULL);
254 g_return_val_if_fail (left_color != NULL, NULL);
255
256 return eel_gradient_set_edge_color (gradient_spec, left_color, TRUE, FALSE);
257 }
258
259 /**
260 * eel_gradient_set_top_color_spec
261 * @gradient_spec: A gradient spec. string.
262 * @top_color: Color spec. to replace top color with.
263 *
264 * Changes the top color to what's passed in.
265 * This creates a vertical gradient.
266 */
267 char *
eel_gradient_set_top_color_spec(const char * gradient_spec,const char * top_color)268 eel_gradient_set_top_color_spec (const char *gradient_spec,
269 const char *top_color)
270 {
271 g_return_val_if_fail (gradient_spec != NULL, NULL);
272 g_return_val_if_fail (top_color != NULL, NULL);
273
274 return eel_gradient_set_edge_color (gradient_spec, top_color, FALSE, FALSE);
275 }
276
277 /**
278 * eel_gradient_set_right_color_spec
279 * @gradient_spec: A gradient spec. string.
280 * @right_color: Color spec. to replace right color with.
281 *
282 * Changes the right color to what's passed in.
283 * This creates a horizontal gradient.
284 */
285 char *
eel_gradient_set_right_color_spec(const char * gradient_spec,const char * right_color)286 eel_gradient_set_right_color_spec (const char *gradient_spec,
287 const char *right_color)
288 {
289 g_return_val_if_fail (gradient_spec != NULL, NULL);
290 g_return_val_if_fail (right_color != NULL, NULL);
291
292 return eel_gradient_set_edge_color (gradient_spec, right_color, TRUE, TRUE);
293 }
294
295 /**
296 * eel_gradient_set_bottom_color_spec
297 * @gradient_spec: A gradient spec. string.
298 * @bottom_color: Color spec. to replace bottom color with.
299 *
300 * Changes the bottom color to what's passed in.
301 * This creates a vertical gradient.
302 */
303 char *
eel_gradient_set_bottom_color_spec(const char * gradient_spec,const char * bottom_color)304 eel_gradient_set_bottom_color_spec (const char *gradient_spec,
305 const char *bottom_color)
306 {
307 g_return_val_if_fail (gradient_spec != NULL, NULL);
308 g_return_val_if_fail (bottom_color != NULL, NULL);
309
310 return eel_gradient_set_edge_color (gradient_spec, bottom_color, FALSE, TRUE);
311 }
312
313 /**
314 * eel_gdk_rgba_parse_with_white_default
315 * @color: Pointer to place to put resulting color.
316 * @color_spec: A color spec, or NULL.
317 *
318 * The same as gdk_rgba_parse, except sets the color to white if
319 * the spec. can't be parsed, instead of returning a boolean flag.
320 */
321 void
eel_gdk_rgba_parse_with_white_default(GdkRGBA * color,const char * color_spec)322 eel_gdk_rgba_parse_with_white_default (GdkRGBA *color,
323 const char *color_spec)
324 {
325 gboolean got_color;
326
327 g_return_if_fail (color != NULL);
328
329 got_color = FALSE;
330 if (color_spec != NULL)
331 {
332 if (gdk_rgba_parse (color, color_spec))
333 {
334 got_color = TRUE;
335 }
336 }
337
338 if (!got_color)
339 {
340 color->red = 1.0;
341 color->green = 1.0;
342 color->blue = 1.0;
343 color->alpha = 1.0;
344 }
345 }
346
347 guint32
eel_rgb16_to_rgb(gushort r,gushort g,gushort b)348 eel_rgb16_to_rgb (gushort r, gushort g, gushort b)
349 {
350 guint32 result;
351
352 result = (0xff0000 | (r & 0xff00));
353 result <<= 8;
354 result |= ((g & 0xff00) | (b >> 8));
355
356 return result;
357 }
358
359 /**
360 * eel_gdk_rgba_to_rgb
361 * @color: A GdkRGBA style color.
362 * Returns: An rgb value.
363 *
364 * Converts from a GdkRGBA style color to a gdk_rgb one.
365 * Alpha gets set to fully opaque
366 */
367 guint32
eel_gdk_rgba_to_rgb(const GdkRGBA * color)368 eel_gdk_rgba_to_rgb (const GdkRGBA *color)
369 {
370 return eel_rgb16_to_rgb ((guint) (color->red * 65535),
371 (guint) (color->green * 65535),
372 (guint) (color->blue * 65535));
373 }
374
375 /**
376 * eel_gdk_rgb_to_rgba
377 * @color: a gdk_rgb style value.
378 *
379 * Converts from a gdk_rgb value style to a GdkRGBA one.
380 * The gdk_rgb color alpha channel is ignored.
381 *
382 * Return value: A GdkRGBA structure version of the given RGB color.
383 */
384 GdkRGBA
eel_gdk_rgb_to_rgba(guint32 color)385 eel_gdk_rgb_to_rgba (guint32 color)
386 {
387 GdkRGBA result;
388
389 result.red = ((gdouble) ((color >> 16) & 0xFF)) / 0xFF;
390 result.green = ((gdouble) ((color >> 8) & 0xFF)) / 0xFF;
391 result.blue = ((gdouble) (color & 0xFF)) / 0xFF;
392 result.alpha = 1.0;
393
394 return result;
395 }
396
397
398 /**
399 * eel_gdk_rgb_to_color_spec
400 * @color: a gdk_rgb style value.
401 *
402 * Converts from a gdk_rgb value style to a string color spec.
403 * The gdk_rgb color alpha channel is ignored.
404 *
405 * Return value: a newly allocated color spec.
406 */
407 char *
eel_gdk_rgb_to_color_spec(const guint32 color)408 eel_gdk_rgb_to_color_spec (const guint32 color)
409 {
410 return g_strdup_printf ("#%06X", (guint) (color & 0xFFFFFF));
411 }
412
413
414 /**
415 * eel_gdk_rgba_is_dark:
416 *
417 * Return true if the given color is `dark'
418 */
419 gboolean
eel_gdk_rgba_is_dark(const GdkRGBA * color)420 eel_gdk_rgba_is_dark (const GdkRGBA *color)
421 {
422 int intensity;
423
424 intensity = (((guint) (color->red * 0xff) * 77)
425 + ((guint) (color->green * 0xff) * 150)
426 + ((guint) (color->blue * 0xff) * 28)) >> 8;
427
428 return intensity < 128;
429 }
430
431 EelGdkGeometryFlags
eel_gdk_parse_geometry(const char * string,int * x_return,int * y_return,guint * width_return,guint * height_return)432 eel_gdk_parse_geometry (const char *string, int *x_return, int *y_return,
433 guint *width_return, guint *height_return)
434 {
435 int x11_flags;
436 EelGdkGeometryFlags gdk_flags;
437
438 g_return_val_if_fail (string != NULL, EEL_GDK_NO_VALUE);
439 g_return_val_if_fail (x_return != NULL, EEL_GDK_NO_VALUE);
440 g_return_val_if_fail (y_return != NULL, EEL_GDK_NO_VALUE);
441 g_return_val_if_fail (width_return != NULL, EEL_GDK_NO_VALUE);
442 g_return_val_if_fail (height_return != NULL, EEL_GDK_NO_VALUE);
443
444 x11_flags = XParseGeometry (string, x_return, y_return,
445 width_return, height_return);
446
447 gdk_flags = EEL_GDK_NO_VALUE;
448 if (x11_flags & XValue)
449 {
450 gdk_flags |= EEL_GDK_X_VALUE;
451 }
452 if (x11_flags & YValue)
453 {
454 gdk_flags |= EEL_GDK_Y_VALUE;
455 }
456 if (x11_flags & WidthValue)
457 {
458 gdk_flags |= EEL_GDK_WIDTH_VALUE;
459 }
460 if (x11_flags & HeightValue)
461 {
462 gdk_flags |= EEL_GDK_HEIGHT_VALUE;
463 }
464 if (x11_flags & XNegative)
465 {
466 gdk_flags |= EEL_GDK_X_NEGATIVE;
467 }
468 if (x11_flags & YNegative)
469 {
470 gdk_flags |= EEL_GDK_Y_NEGATIVE;
471 }
472
473 return gdk_flags;
474 }
475
476 #if ! defined (EEL_OMIT_SELF_CHECK)
477
478 static char *
eel_gdk_rgba_as_hex_string(GdkRGBA color)479 eel_gdk_rgba_as_hex_string (GdkRGBA color)
480 {
481 return g_strdup_printf ("%04X%04X%04X",
482 (guint) (color.red * 65535),
483 (guint) (color.green * 65535),
484 (guint) (color.blue * 65535));
485 }
486
487 static char *
eel_self_check_parse(const char * color_spec)488 eel_self_check_parse (const char *color_spec)
489 {
490 GdkRGBA color;
491
492 eel_gdk_rgba_parse_with_white_default (&color, color_spec);
493 return eel_gdk_rgba_as_hex_string (color);
494 }
495
496 static char *
eel_self_check_gdk_rgb_to_color(guint32 color)497 eel_self_check_gdk_rgb_to_color (guint32 color)
498 {
499 GdkRGBA result;
500
501 result = eel_gdk_rgb_to_rgba (color);
502
503 return eel_gdk_rgba_as_hex_string (result);
504 }
505
506 void
eel_self_check_gdk_extensions(void)507 eel_self_check_gdk_extensions (void)
508 {
509 /* eel_gradient_new */
510 EEL_CHECK_STRING_RESULT (eel_gradient_new ("", "", FALSE), "");
511 EEL_CHECK_STRING_RESULT (eel_gradient_new ("a", "b", FALSE), "a-b");
512 EEL_CHECK_STRING_RESULT (eel_gradient_new ("a", "b", TRUE), "a-b:h");
513 EEL_CHECK_STRING_RESULT (eel_gradient_new ("a", "a", FALSE), "a");
514 EEL_CHECK_STRING_RESULT (eel_gradient_new ("a", "a", TRUE), "a");
515
516 /* eel_gradient_is_gradient */
517 EEL_CHECK_BOOLEAN_RESULT (eel_gradient_is_gradient (""), FALSE);
518 EEL_CHECK_BOOLEAN_RESULT (eel_gradient_is_gradient ("-"), TRUE);
519 EEL_CHECK_BOOLEAN_RESULT (eel_gradient_is_gradient ("a"), FALSE);
520 EEL_CHECK_BOOLEAN_RESULT (eel_gradient_is_gradient ("a-b"), TRUE);
521 EEL_CHECK_BOOLEAN_RESULT (eel_gradient_is_gradient ("a-b:h"), TRUE);
522
523 /* eel_gradient_get_start_color_spec */
524 EEL_CHECK_STRING_RESULT (eel_gradient_get_start_color_spec (""), "");
525 EEL_CHECK_STRING_RESULT (eel_gradient_get_start_color_spec ("-"), "");
526 EEL_CHECK_STRING_RESULT (eel_gradient_get_start_color_spec ("a"), "a");
527 EEL_CHECK_STRING_RESULT (eel_gradient_get_start_color_spec ("a-b"), "a");
528 EEL_CHECK_STRING_RESULT (eel_gradient_get_start_color_spec ("a-"), "a");
529 EEL_CHECK_STRING_RESULT (eel_gradient_get_start_color_spec ("-b"), "");
530 EEL_CHECK_STRING_RESULT (eel_gradient_get_start_color_spec ("a:h"), "a");
531 EEL_CHECK_STRING_RESULT (eel_gradient_get_start_color_spec ("a:v"), "a");
532 EEL_CHECK_STRING_RESULT (eel_gradient_get_start_color_spec ("a:c"), "a:c");
533 EEL_CHECK_STRING_RESULT (eel_gradient_get_start_color_spec ("a:-b"), "a:");
534 EEL_CHECK_STRING_RESULT (eel_gradient_get_start_color_spec ("a:-b:v"), "a:");
535
536 /* eel_gradient_get_end_color_spec */
537 EEL_CHECK_STRING_RESULT (eel_gradient_get_end_color_spec (""), "");
538 EEL_CHECK_STRING_RESULT (eel_gradient_get_end_color_spec ("-"), "");
539 EEL_CHECK_STRING_RESULT (eel_gradient_get_end_color_spec ("a"), "a");
540 EEL_CHECK_STRING_RESULT (eel_gradient_get_end_color_spec ("a-b"), "b");
541 EEL_CHECK_STRING_RESULT (eel_gradient_get_end_color_spec ("a-"), "");
542 EEL_CHECK_STRING_RESULT (eel_gradient_get_end_color_spec ("-b"), "b");
543 EEL_CHECK_STRING_RESULT (eel_gradient_get_end_color_spec ("a:h"), "a");
544 EEL_CHECK_STRING_RESULT (eel_gradient_get_end_color_spec ("a:v"), "a");
545 EEL_CHECK_STRING_RESULT (eel_gradient_get_end_color_spec ("a:c"), "a:c");
546 EEL_CHECK_STRING_RESULT (eel_gradient_get_end_color_spec ("a:-b"), "b");
547 EEL_CHECK_STRING_RESULT (eel_gradient_get_end_color_spec ("a:-b:v"), "b");
548
549 /* eel_gradient_set_left_color_spec */
550 EEL_CHECK_STRING_RESULT (eel_gradient_set_left_color_spec ("", ""), "");
551 EEL_CHECK_STRING_RESULT (eel_gradient_set_left_color_spec ("", "a"), "a");
552 EEL_CHECK_STRING_RESULT (eel_gradient_set_left_color_spec ("a", ""), "a");
553 EEL_CHECK_STRING_RESULT (eel_gradient_set_left_color_spec ("a", "a"), "a");
554 EEL_CHECK_STRING_RESULT (eel_gradient_set_left_color_spec ("a", "b"), "b-a:h");
555 EEL_CHECK_STRING_RESULT (eel_gradient_set_left_color_spec ("a-c:v", "b"), "b-c:h");
556 EEL_CHECK_STRING_RESULT (eel_gradient_set_left_color_spec ("a-c:v", "c"), "c");
557 EEL_CHECK_STRING_RESULT (eel_gradient_set_left_color_spec ("a:-b:v", "d"), "d-b:h");
558
559 /* eel_gradient_set_top_color_spec */
560 EEL_CHECK_STRING_RESULT (eel_gradient_set_top_color_spec ("", ""), "");
561 EEL_CHECK_STRING_RESULT (eel_gradient_set_top_color_spec ("", "a"), "a");
562 EEL_CHECK_STRING_RESULT (eel_gradient_set_top_color_spec ("a", ""), "a");
563 EEL_CHECK_STRING_RESULT (eel_gradient_set_top_color_spec ("a", "a"), "a");
564 EEL_CHECK_STRING_RESULT (eel_gradient_set_top_color_spec ("a", "b"), "b-a");
565 EEL_CHECK_STRING_RESULT (eel_gradient_set_top_color_spec ("a-c:v", "b"), "b-c");
566 EEL_CHECK_STRING_RESULT (eel_gradient_set_top_color_spec ("a-c:v", "c"), "c");
567 EEL_CHECK_STRING_RESULT (eel_gradient_set_top_color_spec ("a:-b:h", "d"), "d-b");
568
569 /* eel_gradient_set_right_color_spec */
570 EEL_CHECK_STRING_RESULT (eel_gradient_set_right_color_spec ("", ""), "");
571 EEL_CHECK_STRING_RESULT (eel_gradient_set_right_color_spec ("", "a"), "a");
572 EEL_CHECK_STRING_RESULT (eel_gradient_set_right_color_spec ("a", ""), "a");
573 EEL_CHECK_STRING_RESULT (eel_gradient_set_right_color_spec ("a", "a"), "a");
574 EEL_CHECK_STRING_RESULT (eel_gradient_set_right_color_spec ("a", "b"), "a-b:h");
575 EEL_CHECK_STRING_RESULT (eel_gradient_set_right_color_spec ("a-c:v", "b"), "a-b:h");
576 EEL_CHECK_STRING_RESULT (eel_gradient_set_right_color_spec ("a-c:v", "c"), "a-c:h");
577 EEL_CHECK_STRING_RESULT (eel_gradient_set_right_color_spec ("a:-b:v", "d"), "a:-d:h");
578
579 /* eel_gradient_set_bottom_color_spec */
580 EEL_CHECK_STRING_RESULT (eel_gradient_set_bottom_color_spec ("", ""), "");
581 EEL_CHECK_STRING_RESULT (eel_gradient_set_bottom_color_spec ("", "a"), "a");
582 EEL_CHECK_STRING_RESULT (eel_gradient_set_bottom_color_spec ("a", ""), "a");
583 EEL_CHECK_STRING_RESULT (eel_gradient_set_bottom_color_spec ("a", "a"), "a");
584 EEL_CHECK_STRING_RESULT (eel_gradient_set_bottom_color_spec ("a", "b"), "a-b");
585 EEL_CHECK_STRING_RESULT (eel_gradient_set_bottom_color_spec ("a-c:v", "b"), "a-b");
586 EEL_CHECK_STRING_RESULT (eel_gradient_set_bottom_color_spec ("a-c:v", "c"), "a-c");
587 EEL_CHECK_STRING_RESULT (eel_gradient_set_bottom_color_spec ("a:-b:h", "d"), "a:-d");
588
589 /* eel_gdk_rgba_parse_with_white_default */
590 EEL_CHECK_STRING_RESULT (eel_self_check_parse (""), "FFFFFFFFFFFF");
591 EEL_CHECK_STRING_RESULT (eel_self_check_parse ("a"), "FFFFFFFFFFFF");
592 EEL_CHECK_STRING_RESULT (eel_self_check_parse ("white"), "FFFFFFFFFFFF");
593 EEL_CHECK_STRING_RESULT (eel_self_check_parse ("black"), "000000000000");
594 EEL_CHECK_STRING_RESULT (eel_self_check_parse ("red"), "FFFF00000000");
595 EEL_CHECK_STRING_RESULT (eel_self_check_parse ("#012345"), "010123234545");
596 /* EEL_CHECK_STRING_RESULT (eel_self_check_parse ("rgb:0123/4567/89AB"), "#014589"); */
597
598 /* eel_gdk_rgb_to_color */
599 EEL_CHECK_STRING_RESULT (eel_self_check_gdk_rgb_to_color (EEL_RGB_COLOR_RED), "FFFF00000000");
600 EEL_CHECK_STRING_RESULT (eel_self_check_gdk_rgb_to_color (EEL_RGB_COLOR_BLACK), "000000000000");
601 EEL_CHECK_STRING_RESULT (eel_self_check_gdk_rgb_to_color (EEL_RGB_COLOR_WHITE), "FFFFFFFFFFFF");
602 EEL_CHECK_STRING_RESULT (eel_self_check_gdk_rgb_to_color (EEL_RGB_COLOR_PACK (0x01, 0x23, 0x45)), "010123234545");
603
604 /* EEL_RGBA_COLOR_PACK */
605 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_PACK (0xFF, 0x00, 0x00, 00), EEL_RGB_COLOR_RED);
606 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_PACK (0x00, 0xFF, 0x00, 00), EEL_RGB_COLOR_GREEN);
607 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_PACK (0x00, 0x00, 0xFF, 00), EEL_RGB_COLOR_BLUE);
608 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_PACK (0xFF, 0xFF, 0xFF, 00), EEL_RGB_COLOR_WHITE);
609 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_PACK (0x00, 0x00, 0x00, 00), EEL_RGB_COLOR_BLACK);
610
611 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_PACK (0xFF, 0x00, 0x00, 0xFF), EEL_RGBA_COLOR_OPAQUE_RED);
612 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_PACK (0x00, 0xFF, 0x00, 0xFF), EEL_RGBA_COLOR_OPAQUE_GREEN);
613 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_PACK (0x00, 0x00, 0xFF, 0xFF), EEL_RGBA_COLOR_OPAQUE_BLUE);
614 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_PACK (0xFF, 0xFF, 0xFF, 0xFF), EEL_RGBA_COLOR_OPAQUE_WHITE);
615 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_PACK (0x00, 0x00, 0x00, 0xFF), EEL_RGBA_COLOR_OPAQUE_BLACK);
616
617 /* EEL_RGB_COLOR_PACK */
618 EEL_CHECK_INTEGER_RESULT (EEL_RGB_COLOR_PACK (0xFF, 0x00, 0x00), EEL_RGBA_COLOR_OPAQUE_RED);
619 EEL_CHECK_INTEGER_RESULT (EEL_RGB_COLOR_PACK (0x00, 0xFF, 0x00), EEL_RGBA_COLOR_OPAQUE_GREEN);
620 EEL_CHECK_INTEGER_RESULT (EEL_RGB_COLOR_PACK (0x00, 0x00, 0xFF), EEL_RGBA_COLOR_OPAQUE_BLUE);
621 EEL_CHECK_INTEGER_RESULT (EEL_RGB_COLOR_PACK (0xFF, 0xFF, 0xFF), EEL_RGBA_COLOR_OPAQUE_WHITE);
622 EEL_CHECK_INTEGER_RESULT (EEL_RGB_COLOR_PACK (0x00, 0x00, 0x00), EEL_RGBA_COLOR_OPAQUE_BLACK);
623
624 /* EEL_RGBA_COLOR_GET_R */
625 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_R (EEL_RGBA_COLOR_OPAQUE_RED), 0xFF);
626 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_R (EEL_RGBA_COLOR_OPAQUE_GREEN), 0x00);
627 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_R (EEL_RGBA_COLOR_OPAQUE_BLUE), 0x00);
628 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_R (EEL_RGBA_COLOR_OPAQUE_WHITE), 0xFF);
629 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_R (EEL_RGBA_COLOR_OPAQUE_BLACK), 0x00);
630 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_R (EEL_RGB_COLOR_RED), 0xFF);
631 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_R (EEL_RGB_COLOR_GREEN), 0x00);
632 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_R (EEL_RGB_COLOR_BLUE), 0x00);
633 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_R (EEL_RGB_COLOR_WHITE), 0xFF);
634 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_R (EEL_RGB_COLOR_BLACK), 0x00);
635
636 /* EEL_RGBA_COLOR_GET_G */
637 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_G (EEL_RGBA_COLOR_OPAQUE_RED), 0x00);
638 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_G (EEL_RGBA_COLOR_OPAQUE_GREEN), 0xFF);
639 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_G (EEL_RGBA_COLOR_OPAQUE_BLUE), 0x00);
640 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_G (EEL_RGBA_COLOR_OPAQUE_WHITE), 0xFF);
641 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_G (EEL_RGBA_COLOR_OPAQUE_BLACK), 0x00);
642 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_G (EEL_RGB_COLOR_RED), 0x00);
643 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_G (EEL_RGB_COLOR_GREEN), 0xFF);
644 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_G (EEL_RGB_COLOR_BLUE), 0x00);
645 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_G (EEL_RGB_COLOR_WHITE), 0xFF);
646 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_G (EEL_RGB_COLOR_BLACK), 0x00);
647
648 /* EEL_RGBA_COLOR_GET_B */
649 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_B (EEL_RGBA_COLOR_OPAQUE_RED), 0x00);
650 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_B (EEL_RGBA_COLOR_OPAQUE_GREEN), 0x00);
651 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_B (EEL_RGBA_COLOR_OPAQUE_BLUE), 0xFF);
652 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_B (EEL_RGBA_COLOR_OPAQUE_WHITE), 0xFF);
653 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_B (EEL_RGBA_COLOR_OPAQUE_BLACK), 0x00);
654 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_B (EEL_RGB_COLOR_RED), 0x00);
655 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_B (EEL_RGB_COLOR_GREEN), 0x00);
656 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_B (EEL_RGB_COLOR_BLUE), 0xFF);
657 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_B (EEL_RGB_COLOR_WHITE), 0xFF);
658 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_B (EEL_RGB_COLOR_BLACK), 0x00);
659
660 /* EEL_RGBA_COLOR_GET_A */
661 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_A (EEL_RGBA_COLOR_OPAQUE_RED), 0xFF);
662 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_A (EEL_RGBA_COLOR_OPAQUE_GREEN), 0xFF);
663 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_A (EEL_RGBA_COLOR_OPAQUE_BLUE), 0xFF);
664 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_A (EEL_RGBA_COLOR_OPAQUE_WHITE), 0xFF);
665 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_A (EEL_RGBA_COLOR_OPAQUE_BLACK), 0xFF);
666 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_A (EEL_RGB_COLOR_RED), 0x00);
667 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_A (EEL_RGB_COLOR_GREEN), 0x00);
668 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_A (EEL_RGB_COLOR_BLUE), 0x00);
669 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_A (EEL_RGB_COLOR_WHITE), 0x00);
670 EEL_CHECK_INTEGER_RESULT (EEL_RGBA_COLOR_GET_A (EEL_RGB_COLOR_BLACK), 0x00);
671
672 }
673
674 #endif /* ! EEL_OMIT_SELF_CHECK */
675