GtkTextTag * gimp_text_buffer_get_color_tag (GimpTextBuffer *buffer, const GimpRGB *color) { GList *list; GtkTextTag *tag; gchar name[256]; GdkColor gdk_color; guchar r, g, b; gimp_rgb_get_uchar (color, &r, &g, &b); for (list = buffer->color_tags; list; list = g_list_next (list)) { GimpRGB tag_color; guchar tag_r, tag_g, tag_b; tag = list->data; gimp_text_tag_get_color (tag, &tag_color); gimp_rgb_get_uchar (&tag_color, &tag_r, &tag_g, &tag_b); /* Do not compare the alpha channel, since it's unused */ if (tag_r == r && tag_g == g && tag_b == b) { return tag; } } g_snprintf (name, sizeof (name), "color-#%02x%02x%02x", r, g, b); gimp_rgb_get_gdk_color (color, &gdk_color); tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (buffer), name, "foreground-gdk", &gdk_color, "foreground-set", TRUE, NULL); buffer->color_tags = g_list_prepend (buffer->color_tags, tag); return tag; }
/** * gimp_canvas_set_bg_color: * @canvas: a #GimpCanvas widget * @color: a color in #GimpRGB format * * Sets the background color of the canvas's window. This * is the color the canvas is set to if it is cleared. **/ void gimp_canvas_set_bg_color (GimpCanvas *canvas, GimpRGB *color) { GtkWidget *widget = GTK_WIDGET (canvas); GdkColormap *colormap; GdkColor gdk_color; if (! GTK_WIDGET_REALIZED (widget)) return; gimp_rgb_get_gdk_color (color, &gdk_color); colormap = gdk_drawable_get_colormap (widget->window); g_return_if_fail (colormap != NULL); gdk_colormap_alloc_color (colormap, &gdk_color, FALSE, TRUE); gdk_window_set_background (widget->window, &gdk_color); }