summaryrefslogtreecommitdiff
path: root/eel
diff options
context:
space:
mode:
authorraveit65 <[email protected]>2016-06-15 23:14:23 +0200
committerraveit65 <[email protected]>2016-07-02 10:50:56 +0200
commit75659aa8d36813d4228949eeeafff317b71c5b93 (patch)
treee394dbdecc76213fcfe41c447b4bdf029e9c45dd /eel
parent36050c2e84626e52c11790cdc706079f6861c4a5 (diff)
downloadcaja-75659aa8d36813d4228949eeeafff317b71c5b93.tar.bz2
caja-75659aa8d36813d4228949eeeafff317b71c5b93.tar.xz
GTK+-3 eel-gdk-extensions: port GtkColor to GdkRGBA
with help from Alexei Sorokin
Diffstat (limited to 'eel')
-rw-r--r--eel/eel-gdk-extensions.c77
-rw-r--r--eel/eel-gdk-extensions.h9
2 files changed, 86 insertions, 0 deletions
diff --git a/eel/eel-gdk-extensions.c b/eel/eel-gdk-extensions.c
index 2da5bb03..878586ef 100644
--- a/eel/eel-gdk-extensions.c
+++ b/eel/eel-gdk-extensions.c
@@ -320,6 +320,32 @@ eel_gradient_set_bottom_color_spec (const char *gradient_spec,
* The same as gdk_color_parse, except sets the color to white if
* the spec. can't be parsed, instead of returning a boolean flag.
*/
+#if GTK_CHECK_VERSION (3, 0, 0)
+void
+eel_gdk_color_parse_with_white_default (const char *color_spec,
+ GdkRGBA *color)
+{
+ gboolean got_color;
+
+ g_return_if_fail (color != NULL);
+
+ got_color = FALSE;
+ if (color_spec != NULL)
+ {
+ if (gdk_rgba_parse (color, color_spec))
+ {
+ got_color = TRUE;
+ }
+ }
+
+ if (!got_color)
+ {
+ color->red = 1.0;
+ color->green = 1.0;
+ color->blue = 1.0;
+ }
+}
+#else
void
eel_gdk_color_parse_with_white_default (const char *color_spec,
GdkColor *color)
@@ -344,6 +370,7 @@ eel_gdk_color_parse_with_white_default (const char *color_spec,
color->blue = 0xFFFF;
}
}
+#endif
guint32
eel_rgb16_to_rgb (gushort r, gushort g, gushort b)
@@ -372,10 +399,19 @@ eel_rgb8_to_rgb (guchar r, guchar g, guchar b)
* Alpha gets set to fully opaque
*/
guint32
+#if GTK_CHECK_VERSION (3, 0, 0)
+eel_gdk_color_to_rgb (const GdkRGBA *color)
+{
+ return eel_rgb16_to_rgb ((guint) (color->red * 65535),
+ (guint) (color->green * 65535),
+ (guint) (color->blue * 65535));
+}
+#else
eel_gdk_color_to_rgb (const GdkColor *color)
{
return eel_rgb16_to_rgb (color->red, color->green, color->blue);
}
+#endif
/**
* eel_gdk_rgb_to_color
@@ -386,6 +422,16 @@ eel_gdk_color_to_rgb (const GdkColor *color)
*
* Return value: A GdkColor structure version of the given RGB color.
*/
+#if GTK_CHECK_VERSION (3, 0, 0)
+GdkRGBA
+eel_gdk_rgb_to_color (guint32 color)
+{
+ GdkRGBA result;
+
+ result.red = ((color >> 16) & 0xFF) / 0xFF;
+ result.green = ((color >> 8) & 0xFF) / 0xFF;
+ result.blue = (color & 0xff) / 0xFF;
+#else
GdkColor
eel_gdk_rgb_to_color (guint32 color)
{
@@ -395,6 +441,7 @@ eel_gdk_rgb_to_color (guint32 color)
result.green = ((color >> 8) & 0xFF) * 0x101;
result.blue = (color & 0xff) * 0x101;
result.pixel = 0;
+#endif
return result;
}
@@ -563,6 +610,35 @@ eel_make_color_inactive (GdkRGBA *color)
#if ! defined (EEL_OMIT_SELF_CHECK)
+#if GTK_CHECK_VERSION(3,0,0)
+static char *
+eel_gdk_color_as_hex_string (GdkRGBA color)
+{
+ return g_strdup_printf ("%04X%04X%04X",
+ (guint) (color.red * 65535),
+ (guint) (color.green * 65535),
+ (guint) (color.blue * 65535));
+}
+
+static char *
+eel_self_check_parse (const char *color_spec)
+{
+ GdkRGBA color;
+
+ eel_gdk_color_parse_with_white_default (color_spec, &color);
+ return eel_gdk_color_as_hex_string (color);
+}
+
+static char *
+eel_self_check_gdk_rgb_to_color (guint32 color)
+{
+ GdkRGBA result;
+
+ result = eel_gdk_rgb_to_color (color);
+
+ return eel_gdk_color_as_hex_string (result);
+}
+#else
static char *
eel_gdk_color_as_hex_string (GdkColor color)
{
@@ -588,6 +664,7 @@ eel_self_check_gdk_rgb_to_color (guint32 color)
return eel_gdk_color_as_hex_string (result);
}
+#endif
void
eel_self_check_gdk_extensions (void)
diff --git a/eel/eel-gdk-extensions.h b/eel/eel-gdk-extensions.h
index ad94ddbd..1c74cff2 100644
--- a/eel/eel-gdk-extensions.h
+++ b/eel/eel-gdk-extensions.h
@@ -103,15 +103,24 @@ char * eel_gradient_set_bottom_color_spec (const char
a boolean to indicate it cannot be parsed.
*/
void eel_gdk_color_parse_with_white_default (const char *color_spec,
+#if GTK_CHECK_VERSION (3, 0, 0)
+ GdkRGBA *parsed_color);
+#else
GdkColor *parsed_color);
+#endif
guint32 eel_rgb16_to_rgb (gushort r,
gushort g,
gushort b);
guint32 eel_rgb8_to_rgb (guchar r,
guchar g,
guchar b);
+#if GTK_CHECK_VERSION (3, 0, 0)
+guint32 eel_gdk_color_to_rgb (const GdkRGBA *color);
+GdkRGBA eel_gdk_rgb_to_color (guint32 color);
+#else
guint32 eel_gdk_color_to_rgb (const GdkColor *color);
GdkColor eel_gdk_rgb_to_color (guint32 color);
+#endif
char * eel_gdk_rgb_to_color_spec (guint32 color);
#if GTK_CHECK_VERSION(3,0,0)