#include "color-combo-color-menu-item.h"
-#include "marshal.h"
#include <glib/gi18n.h>
-#include <gtk/gtkmenuitem.h>
-#include <gtk/gtkseparatormenuitem.h>
-#include <gtk/gtklabel.h>
-#include <gtk/gtkimage.h>
+#include <gtk/gtk.h>
+
+#include "color-swatch.h"
#include "color.h"
-#include "util.h"
+#include "marshal.h"
+
/*===========================================*/
/* Private macros and constants. */
/*===========================================*/
+#define SIZE 20
+
/*===========================================*/
/* Private types */
struct _glColorComboColorMenuItemPrivate {
- gint id;
+ gint id;
+
+ GtkWidget *swatch;
};
static void gl_color_combo_color_menu_item_finalize (GObject *object);
-static GdkPixbuf *
-create_color_pixbuf (gdouble w,
- gdouble h,
- guint color);
/****************************************************************************/
/* Boilerplate Object stuff. */
gl_color_combo_color_menu_item_class_init (glColorComboColorMenuItemClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
gl_color_combo_color_menu_item_parent_class = g_type_class_peek_parent (class);
const gchar *tip)
{
glColorComboColorMenuItem *this;
- GdkPixbuf *pixbuf;
this = g_object_new (GL_TYPE_COLOR_COMBO_COLOR_MENU_ITEM, NULL);
this->priv->id = id;
- pixbuf = create_color_pixbuf (16, 16, color);
- gtk_container_add (GTK_CONTAINER (this),
- gtk_image_new_from_pixbuf (pixbuf));
+ this->priv->swatch = gl_color_swatch_new (SIZE, SIZE, color);
+ gtk_container_add (GTK_CONTAINER (this), this->priv->swatch);
gtk_widget_set_tooltip_text (GTK_WIDGET (this), tip);
guint color,
const gchar *tip)
{
- GdkPixbuf *pixbuf;
-
this->priv->id = id;
- pixbuf = create_color_pixbuf (16, 16, color);
- gtk_image_set_from_pixbuf (GTK_IMAGE (gtk_bin_get_child (GTK_BIN (this))),
- pixbuf);
+ gl_color_swatch_set_color (GL_COLOR_SWATCH (this->priv->swatch), color);
gtk_widget_set_tooltip_text (GTK_WIDGET (this), tip);
- }
-
-
-/*****************************************************************************/
-/* Create new pixbuf with color preview. */
-/*****************************************************************************/
-static GdkPixbuf *
-create_color_pixbuf (gdouble w,
- gdouble h,
- guint color)
-{
- cairo_surface_t *surface;
- cairo_t *cr;
- GdkPixbuf *pixbuf;
-
- surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
-
- cr = cairo_create (surface);
-
- cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
-
- cairo_save (cr);
- cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
- cairo_paint (cr);
- cairo_restore (cr);
-
- cairo_rectangle( cr, 2, 2, w-3, h-3 );
-
- cairo_set_source_rgba (cr,
- GL_COLOR_F_RED (color),
- GL_COLOR_F_GREEN (color),
- GL_COLOR_F_BLUE (color),
- GL_COLOR_F_ALPHA (color));
- cairo_fill_preserve( cr );
-
- cairo_set_line_width (cr, 1.0);
- cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
- cairo_stroke (cr);
-
- cairo_destroy( cr );
-
- pixbuf = gl_util_cairo_convert_to_pixbuf (surface);
- cairo_surface_destroy (surface);
-
- return pixbuf;
}