static void selectcolor_paint(GtkWidget *widget) { cairo_t *cr; cr = gdk_cairo_create(widget->window); cairo_fill(cr); gint color = SELECT_COLOR(widget)->color; gint circle = SELECT_COLOR(widget)->circle; double r = ((color & 0xff0000) >> 16) / 255.0; double g = ((color & 0xff00) >> 8) / 255.0; double b = ((color & 0xff)) / 255.0; gboolean sensitiv = gtk_widget_is_sensitive(widget); int x = widget->allocation.x; int y = widget->allocation.y; int width = 10; if (!sensitiv) { r = r / 2 + 0.5; g = g / 2 + 0.5; b = b / 2 + 0.5; } double radius = 0; if (widget->allocation.width > widget->allocation.height) { width = widget->allocation.height; x += (widget->allocation.width - width) / 2; radius = widget->allocation.height / 2.0; } else { width = widget->allocation.width; y += (widget->allocation.height - width) / 2; radius = widget->allocation.width / 2.0; } cairo_set_source_rgb(cr, r, g, b); if (circle) { cairo_arc(cr, radius + x, radius + y, radius - 1, 0, 2 * M_PI); } else { cairo_rectangle(cr, x + 1, y + 1, width - 2, width - 2); } cairo_fill(cr); if (sensitiv) { cairo_set_source_rgb(cr, 0, 0, 0); } else { cairo_set_source_rgb(cr, 0.5, 0.5, 0.5); } if (circle) { cairo_arc(cr, radius + x, radius + y, radius - 1, 0, 2 * M_PI); } else { cairo_rectangle(cr, x + 1, y + 1, width - 2, width - 2); } cairo_stroke(cr); cairo_destroy(cr); }
static void selectcolor_size_request(GtkWidget *widget, GtkRequisition *requisition) { g_return_if_fail(widget != NULL); g_return_if_fail(IS_SELECT_COLOR(widget)); g_return_if_fail(requisition != NULL); requisition->width = SELECT_COLOR(widget)->size; requisition->height = SELECT_COLOR(widget)->size; }
GtkWidget * selectcolor_new(gint color) { GtkWidget * w = GTK_WIDGET(gtk_type_new(selectcolor_get_type())); selectcolor_set_color(w, color); SELECT_COLOR(w)->circle = false; SELECT_COLOR(w)->size = 16; return w; }
void selectcolor_set_size(GtkWidget* sc, gint size) { g_return_if_fail(sc != NULL); g_return_if_fail(IS_SELECT_COLOR(sc)); SELECT_COLOR(sc)->size = size; }
void selectcolor_set_circle(GtkWidget * sc, gboolean circle) { g_return_if_fail(sc != NULL); g_return_if_fail(IS_SELECT_COLOR(sc)); SELECT_COLOR(sc)->circle = circle; if (gtk_widget_is_drawable(GTK_WIDGET(sc))) { selectcolor_paint(sc); } }
void selectcolor_set_color(GtkWidget * sc, gint color) { g_return_if_fail(sc != NULL); g_return_if_fail(IS_SELECT_COLOR(sc)); SELECT_COLOR(sc)->color = color; if (gtk_widget_is_drawable(GTK_WIDGET(sc))) { selectcolor_paint(sc); } }
static void selectcolor_destroy(GtkObject *object) { SelectColor *sc; SelectColorClass *klass; g_return_if_fail(object != NULL); g_return_if_fail(IS_SELECT_COLOR(object)); sc = SELECT_COLOR(object); klass = (SelectColorClass*) gtk_type_class(gtk_widget_get_type()); if (GTK_OBJECT_CLASS(klass)->destroy) { (*GTK_OBJECT_CLASS(klass)->destroy)(object); } }