[gtksourceview/gtksourceview-4-2] gtksourceview: add GIMP style color formats
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/gtksourceview-4-2] gtksourceview: add GIMP style color formats
- Date: Tue, 3 Sep 2019 00:53:12 +0000 (UTC)
commit 08185ae4fc90670d6d489704344a89776124807a
Author: Christian Hergert <chergert redhat com>
Date: Mon Sep 2 17:52:36 2019 -0700
gtksourceview: add GIMP style color formats
This implements an alternate format so that we can have DnD coming from
the GIMP color picker. With this patch, we can drag from the color picker
into the GtkSourceView.
gtksourceview/gtksourceview.c | 40 +++++++++++++++++++++++++++++++---------
1 file changed, 31 insertions(+), 9 deletions(-)
---
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index 6e0852f7..e60034d3 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -4259,30 +4259,52 @@ view_dnd_drop (GtkTextView *view,
if (info == TARGET_COLOR)
{
- guint16 *vals;
+ GdkRGBA rgba;
gchar string[] = "#000000";
gint buffer_x;
gint buffer_y;
gint length = gtk_selection_data_get_length (selection_data);
+ guint format;
if (length < 0)
{
return;
}
- if (gtk_selection_data_get_format (selection_data) != 16 || length != 8)
+ format = gtk_selection_data_get_format (selection_data);
+
+ if (format == 8 && length == 4)
{
- g_warning ("Received invalid color data\n");
- return;
+ guint8 *vals;
+
+ vals = (gpointer) gtk_selection_data_get_data (selection_data);
+
+ rgba.red = vals[0] / 256.0;
+ rgba.green = vals[1] / 256.0;
+ rgba.blue = vals[2] / 256.0;
+ rgba.alpha = 1.0;
}
+ else if (format == 16 && length == 8)
+ {
+ guint16 *vals;
- vals = (gpointer) gtk_selection_data_get_data (selection_data);
+ vals = (gpointer) gtk_selection_data_get_data (selection_data);
- vals[0] /= 256;
- vals[1] /= 256;
- vals[2] /= 256;
+ rgba.red = vals[0] / 65535.0;
+ rgba.green = vals[1] / 65535.0;
+ rgba.blue = vals[2] / 65535.0;
+ rgba.alpha = 1.0;
+ }
+ else
+ {
+ g_warning ("Received invalid color data\n");
+ return;
+ }
- g_snprintf (string, sizeof (string), "#%02X%02X%02X", vals[0], vals[1], vals[2]);
+ g_snprintf (string, sizeof string, "#%02X%02X%02X",
+ (gint)(rgba.red * 256),
+ (gint)(rgba.green * 256),
+ (gint)(rgba.blue * 256));
gtk_text_view_window_to_buffer_coords (view,
GTK_TEXT_WINDOW_TEXT,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]