]> git.sur5r.net Git - glabels/commitdiff
Applied color combo patch, provided by Emmanuel Pacaud (emmanuelp@sourceforge.net...
authorJim Evins <evins@snaught.com>
Wed, 8 Oct 2003 03:36:00 +0000 (03:36 +0000)
committerJim Evins <evins@snaught.com>
Wed, 8 Oct 2003 03:36:00 +0000 (03:36 +0000)
git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@307 f5e0f49d-192f-0410-a22d-a8d8700d0965

glabels2/src/mygal/widget-color-combo.c
glabels2/src/mygal/widget-color-combo.h

index d9df2240cbf23a8b5d8c226e643df993ad7df410..e67e305b7cd4a29c17d785223bcceb54c99a6b7e 100644 (file)
@@ -35,9 +35,7 @@
 
 #include <gtk/gtkentry.h>
 #include <gtk/gtksignal.h>
-#include <libgnomecanvas/gnome-canvas.h>
-#include <libgnomecanvas/gnome-canvas-pixbuf.h>
-#include <libgnomecanvas/gnome-canvas-rect-ellipse.h>
+#include <gtk/gtkimage.h>
 #include "e-util.h"
 #include "e-colors.h"
 #include "widget-color-combo.h"
@@ -53,10 +51,18 @@ static guint color_combo_signals [LAST_SIGNAL] = { 0, };
 static GObjectClass *color_combo_parent_class;
 
 #define make_color(CC,COL) (((COL) != NULL) ? (COL) : ((CC) ? ((CC)->default_color) : NULL))
+#define RGBA_TO_UINT(r,g,b,a)  ((((guint)(r))<<24)|(((guint)(g))<<16)|(((guint)(b))<<8)|(guint)(a))
+#define GDK_TO_UINT(c) RGBA_TO_UINT(((c).red>>8), ((c).green>>8), ((c).blue>>8), 0xff)
+
+#define PREVIEW_SIZE 20
 
 static void
 color_combo_set_color_internal (ColorCombo *cc, GdkColor *color)
 {
+       guint color_y, color_height;
+       guint height, width;
+       GdkPixbuf *pixbuf;
+       GdkPixbuf *color_pixbuf;
        GdkColor *new_color;
        GdkColor *outline_color;
 
@@ -64,10 +70,39 @@ color_combo_set_color_internal (ColorCombo *cc, GdkColor *color)
        /* If the new and the default are NULL draw an outline */
        outline_color = (new_color) ? new_color : &e_dark_gray;
 
-       gnome_canvas_item_set (cc->preview_color_item,
-                              "fill_color_gdk", new_color,
-                              "outline_color_gdk", outline_color,
-                              NULL);
+       pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (cc->preview_image));
+
+       if (!pixbuf)
+               return;
+
+       width = gdk_pixbuf_get_width (pixbuf);
+       height = gdk_pixbuf_get_height (pixbuf);
+
+       if (cc->preview_is_icon) {
+               color_y = height - 4;
+               color_height = 4;
+       }
+       else {
+               color_y = 0;
+               color_height = height;
+       }
+
+       color_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
+                                      TRUE, 8,
+                                      width,
+                                      color_height);
+       gdk_pixbuf_fill (color_pixbuf, GDK_TO_UINT (*outline_color));
+       gdk_pixbuf_copy_area (color_pixbuf, 0, 0, width, color_height,
+                             pixbuf, 0, color_y);
+
+       if (new_color != NULL)
+               gdk_pixbuf_fill (color_pixbuf, GDK_TO_UINT (*new_color));
+       else
+               gdk_pixbuf_fill (color_pixbuf, 0xffffff00);
+       gdk_pixbuf_copy_area (color_pixbuf, 0, 0, width - 2, color_height -2,
+                             pixbuf, 1, color_y + 1);
+
+       g_object_unref (color_pixbuf);
 }
 
 static void
@@ -178,53 +213,39 @@ color_combo_construct (ColorCombo *cc, GdkPixbuf *icon,
                       ColorGroup *color_group)
 {
        GdkColor *color;
+       GdkPixbuf *pixbuf = NULL;
+
        g_return_if_fail (cc != NULL);
        g_return_if_fail (IS_COLOR_COMBO (cc));
 
        /*
-        * Our button with the canvas preview
+        * Our button with the gtk_image preview
         */
        cc->preview_button = gtk_button_new ();
-       gtk_button_set_relief (GTK_BUTTON (cc->preview_button), GTK_RELIEF_NONE);
+       cc->preview_is_icon = FALSE;
+       
+       if (icon)
+               /* use icon only if size > 4*4 */
+               if ((gdk_pixbuf_get_width (icon) > 4) && 
+                   (gdk_pixbuf_get_height (icon) > 4))
+               {
+                       cc->preview_is_icon = TRUE;
+                       pixbuf = gdk_pixbuf_copy (icon);
+               }
+       
+       if (pixbuf == NULL)
+               pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
+                                        TRUE, 8, 
+                                        PREVIEW_SIZE, 
+                                        PREVIEW_SIZE);
+
+       cc->preview_image = gtk_image_new_from_pixbuf (pixbuf);
+       g_object_unref (pixbuf);
 
-       cc->preview_canvas = GNOME_CANVAS (gnome_canvas_new ());
-
-       gnome_canvas_set_scroll_region (cc->preview_canvas, 0, 0, 24, 24);
-       if (icon) {
-               gnome_canvas_item_new (
-                       GNOME_CANVAS_GROUP (gnome_canvas_root (cc->preview_canvas)),
-                       GNOME_TYPE_CANVAS_PIXBUF,
-                       "pixbuf", icon,
-                       "x",      0.0,
-                       "y",      0.0,
-                       "anchor", GTK_ANCHOR_NW,
-                       NULL);
-               gdk_pixbuf_unref (icon);
-
-               cc->preview_color_item = gnome_canvas_item_new (
-                       GNOME_CANVAS_GROUP (gnome_canvas_root (cc->preview_canvas)),
-                       gnome_canvas_rect_get_type (),
-                       "x1",         3.0,
-                       "y1",         19.0,
-                       "x2",         20.0,
-                       "y2",         22.0,
-                       "fill_color", "black",
-                       "width_pixels", 1,
-                       NULL);
-       } else
-               cc->preview_color_item = gnome_canvas_item_new (
-                       GNOME_CANVAS_GROUP (gnome_canvas_root (cc->preview_canvas)),
-                       gnome_canvas_rect_get_type (),
-                       "x1",         2.0,
-                       "y1",         1.0,
-                       "x2",         21.0,
-                       "y2",         22.0,
-                       "fill_color", "black",
-                       "width_pixels", 1,
-                       NULL);
-
-       gtk_container_add (GTK_CONTAINER (cc->preview_button), GTK_WIDGET (cc->preview_canvas));
-       gtk_widget_set_usize (GTK_WIDGET (cc->preview_canvas), 24, 22);
+       gtk_button_set_relief (GTK_BUTTON (cc->preview_button), GTK_RELIEF_NONE);
+       gtk_widget_show (cc->preview_image);
+       
+       gtk_container_add (GTK_CONTAINER (cc->preview_button), cc->preview_image);
        g_signal_connect (cc->preview_button, "clicked",
                          G_CALLBACK (preview_clicked), cc);
 
index 15509f2ba33a7ea9cc526a6fa8b17c52fd488c87..581e4a43ccd6e74bff7907b7eb1744defca4d0b6 100644 (file)
@@ -44,11 +44,12 @@ typedef struct _ColorCombo {
        GtkComboBox     combo_box;
 
        /*
-        * Canvas where we display
+        * GtkImage where we display
         */
        GtkWidget       *preview_button;
-       GnomeCanvas     *preview_canvas;
-       GnomeCanvasItem *preview_color_item;
+       GtkWidget       *preview_image;
+       gboolean        preview_is_icon;
+
        ColorPalette    *palette;
 
         GdkColor *default_color;