From 2072f9268dd316cfa701b785bf38efcde9b06f2d Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 7 May 2004 14:52:10 +0000 Subject: [PATCH] Draw focus indication in the color wheel using standard focus style. 2004-05-07 Matthias Clasen * gtk/gtkhsv.c: Draw focus indication in the color wheel using standard focus style. (#63071, Bill Haneman, idea for new style by Owen Taylor) * gtk/gtkstyle.c (gtk_default_draw_focus): Support drawing on focus on the colorwheel via details. --- ChangeLog | 16 +++++++ ChangeLog.pre-2-10 | 16 +++++++ ChangeLog.pre-2-6 | 16 +++++++ ChangeLog.pre-2-8 | 16 +++++++ gtk/gtkhsv.c | 105 ++++++++++++++++++++++++++------------------- gtk/gtkstyle.c | 20 ++++++--- 6 files changed, 139 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c69d53945..3feb3feba3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2004-05-07 Matthias Clasen + + * gtk/gtkhsv.c: Draw focus indication in the color wheel using + standard focus style. (#63071, Bill Haneman, idea for new + style by Owen Taylor) + + * gtk/gtkstyle.c (gtk_default_draw_focus): Support drawing on + focus on the colorwheel via details. + +2004-05-06 Matthias Clasen + + Merge from 2.4: + + * gtk/gtkcombobox.c (gtk_combo_box_menu_state_changed): Remove + this no longer needed signal handler. (#141817, Paul Pogonyshev) + Fri May 7 00:41:46 2004 Matthias Clasen * gtk/gtktearoffmenuitem.h: diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 1c69d53945..3feb3feba3 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,19 @@ +2004-05-07 Matthias Clasen + + * gtk/gtkhsv.c: Draw focus indication in the color wheel using + standard focus style. (#63071, Bill Haneman, idea for new + style by Owen Taylor) + + * gtk/gtkstyle.c (gtk_default_draw_focus): Support drawing on + focus on the colorwheel via details. + +2004-05-06 Matthias Clasen + + Merge from 2.4: + + * gtk/gtkcombobox.c (gtk_combo_box_menu_state_changed): Remove + this no longer needed signal handler. (#141817, Paul Pogonyshev) + Fri May 7 00:41:46 2004 Matthias Clasen * gtk/gtktearoffmenuitem.h: diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 1c69d53945..3feb3feba3 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,19 @@ +2004-05-07 Matthias Clasen + + * gtk/gtkhsv.c: Draw focus indication in the color wheel using + standard focus style. (#63071, Bill Haneman, idea for new + style by Owen Taylor) + + * gtk/gtkstyle.c (gtk_default_draw_focus): Support drawing on + focus on the colorwheel via details. + +2004-05-06 Matthias Clasen + + Merge from 2.4: + + * gtk/gtkcombobox.c (gtk_combo_box_menu_state_changed): Remove + this no longer needed signal handler. (#141817, Paul Pogonyshev) + Fri May 7 00:41:46 2004 Matthias Clasen * gtk/gtktearoffmenuitem.h: diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 1c69d53945..3feb3feba3 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,19 @@ +2004-05-07 Matthias Clasen + + * gtk/gtkhsv.c: Draw focus indication in the color wheel using + standard focus style. (#63071, Bill Haneman, idea for new + style by Owen Taylor) + + * gtk/gtkstyle.c (gtk_default_draw_focus): Support drawing on + focus on the colorwheel via details. + +2004-05-06 Matthias Clasen + + Merge from 2.4: + + * gtk/gtkcombobox.c (gtk_combo_box_menu_state_changed): Remove + this no longer needed signal handler. (#141817, Paul Pogonyshev) + Fri May 7 00:41:46 2004 Matthias Clasen * gtk/gtktearoffmenuitem.h: diff --git a/gtk/gtkhsv.c b/gtk/gtkhsv.c index 465edc8e6e..764edb7398 100644 --- a/gtk/gtkhsv.c +++ b/gtk/gtkhsv.c @@ -380,14 +380,18 @@ static void gtk_hsv_size_request (GtkWidget *widget, GtkRequisition *requisition) { - GtkHSV *hsv; - HSVPrivate *priv; + GtkHSV *hsv = GTK_HSV (widget); + HSVPrivate *priv = hsv->priv; + gint focus_width; + gint focus_pad; + + gtk_widget_style_get (widget, + "focus-line-width", &focus_width, + "focus-padding", &focus_pad, + NULL); - hsv = GTK_HSV (widget); - priv = hsv->priv; - - requisition->width = priv->size; - requisition->height = priv->size; + requisition->width = priv->size + 2 * (focus_width + focus_pad); + requisition->height = priv->size + 2 * (focus_width + focus_pad); } /* Size_allocate handler for the HSV color selector */ @@ -581,7 +585,7 @@ compute_triangle (GtkHSV *hsv, priv = hsv->priv; - center = priv->size / 2.0; + center = GTK_WIDGET (hsv)->requisition.width / 2.0; outer = priv->size / 2.0; inner = outer - priv->ring_width; angle = priv->h * 2.0 * G_PI; @@ -633,7 +637,7 @@ compute_sv (GtkHSV *hsv, priv = hsv->priv; compute_triangle (hsv, &ihx, &ihy, &isx, &isy, &ivx, &ivy); - center = priv->size / 2.0; + center = GTK_WIDGET (hsv)->requisition.width / 2.0; hx = ihx - center; hy = center - ihy; sx = isx - center; @@ -736,7 +740,7 @@ compute_v (GtkHSV *hsv, priv = hsv->priv; - center = priv->size / 2.0; + center = GTK_WIDGET (hsv)->requisition.width / 2.0; dx = x - center; dy = center - y; @@ -923,6 +927,7 @@ paint_ring (GtkHSV *hsv, gint width, gint height) { + GtkWidget *widget = GTK_WIDGET (hsv); HSVPrivate *priv; int xx, yy; gdouble dx, dy, dist; @@ -935,10 +940,17 @@ paint_ring (GtkHSV *hsv, GdkBitmap *mask; GdkGC *gc; GdkColor color; + gint focus_width; + gint focus_pad; + + gtk_widget_style_get (widget, + "focus-line-width", &focus_width, + "focus-padding", &focus_pad, + NULL); priv = hsv->priv; - center = priv->size / 2.0; + center = widget->requisition.width / 2.0; outer = priv->size / 2.0; inner = outer - priv->ring_width; @@ -998,14 +1010,16 @@ paint_ring (GtkHSV *hsv, color.pixel = 1; gdk_gc_set_foreground (gc, &color); gdk_draw_arc (mask, gc, TRUE, - -x, -y, + focus_width + focus_pad - x, + focus_width + focus_pad - y, priv->size - 1, priv->size - 1, 0, 360 * 64); color.pixel = 0; gdk_gc_set_foreground (gc, &color); gdk_draw_arc (mask, gc, TRUE, - -x + priv->ring_width - 1, -y + priv->ring_width - 1, + focus_width + focus_pad - x + priv->ring_width - 1, + focus_width + focus_pad - y + priv->ring_width - 1, priv->size - 2 * priv->ring_width + 1, priv->size - 2 * priv->ring_width + 1, 0, 360 * 64); @@ -1056,25 +1070,12 @@ paint_ring (GtkHSV *hsv, /* Draw ring outline */ - if (GTK_WIDGET_HAS_FOCUS (hsv) && - priv->focus_on_ring) + if (GTK_WIDGET_HAS_FOCUS (hsv) && priv->focus_on_ring) { - gint focus_width; - gint focus_halfwidth; - GdkGC *gc = gtk_hsv_get_focus_gc (hsv, &focus_width); - focus_halfwidth = (focus_width + 1) / 2; - - gdk_draw_arc (drawable, gc, FALSE, - -x + focus_width/2, -y + focus_width/2, - priv->size - focus_width, priv->size - focus_width, - 0, 360 * 64); - gdk_draw_arc (drawable, gc, FALSE, - -x + priv->ring_width - focus_halfwidth, -y + priv->ring_width - focus_halfwidth, - priv->size - 2 * priv->ring_width + focus_width, - priv->size - 2 * priv->ring_width + focus_width, - 0, 360 * 64); - - g_object_unref (gc); + gtk_paint_focus (widget->style, drawable, + GTK_WIDGET_STATE (widget), + NULL, widget, NULL, + x, y, width, height); } } @@ -1109,6 +1110,7 @@ paint_triangle (GtkHSV *hsv, gint width, gint height) { + GtkWidget *widget = GTK_WIDGET (hsv); HSVPrivate *priv; gint hx, hy, sx, sy, vx, vy; /* HSV vertices */ gint x1, y1, r1, g1, b1; /* First vertex in scanline order */ @@ -1123,6 +1125,7 @@ paint_triangle (GtkHSV *hsv, GdkColor color; GdkPoint points[3]; gdouble r, g, b; + gchar *detail; priv = hsv->priv; @@ -1236,7 +1239,7 @@ paint_triangle (GtkHSV *hsv, /* Create clipping mask */ - mask = gdk_pixmap_new (GTK_WIDGET (hsv)->window, width, height, 1); + mask = gdk_pixmap_new (widget->window, width, height, 1); gc = gdk_gc_new (mask); @@ -1274,18 +1277,6 @@ paint_triangle (GtkHSV *hsv, g_free (buf); - /* Draw triangle focus outline */ - - if (GTK_WIDGET_HAS_FOCUS (hsv) && - !priv->focus_on_ring) - { - gint focus_width = 1; - GdkGC *gc = gtk_hsv_get_focus_gc (hsv, &focus_width); - - gdk_draw_polygon (drawable, gc, FALSE, points, 3); - g_object_unref (gc); - } - /* Draw value marker */ xx = floor (sx + (vx - sx) * priv->v + (hx - vx) * priv->s * priv->v + 0.5) - x; @@ -1298,12 +1289,14 @@ paint_triangle (GtkHSV *hsv, if (INTENSITY (r, g, b) > 0.5) { + detail = "colorwheel_light"; color.red = 0x0000; color.green = 0x0000; color.blue = 0x0000; } else { + detail = "colorwheel_dark"; color.red = 0xffff; color.green = 0xffff; color.blue = 0xffff; @@ -1313,6 +1306,7 @@ paint_triangle (GtkHSV *hsv, #define OUTER_RADIUS 4 #define INNER_RADIUS 3 +#define FOCUS_RADIUS 6 gdk_draw_arc (drawable, priv->gc, FALSE, xx - OUTER_RADIUS, yy - OUTER_RADIUS, @@ -1322,6 +1316,29 @@ paint_triangle (GtkHSV *hsv, xx - INNER_RADIUS, yy - INNER_RADIUS, INNER_RADIUS * 2, INNER_RADIUS * 2, 0, 360 * 64); + + /* Draw focus outline */ + + if (GTK_WIDGET_HAS_FOCUS (hsv) && + !priv->focus_on_ring) + { + gint focus_width; + gint focus_pad; + + gtk_widget_style_get (widget, + "focus-line-width", &focus_width, + "focus-padding", &focus_pad, + NULL); + + gtk_paint_focus (widget->style, drawable, + GTK_WIDGET_STATE (widget), + NULL, widget, detail, + xx - FOCUS_RADIUS - focus_width - focus_pad, + yy - FOCUS_RADIUS - focus_width - focus_pad, + 2 * (FOCUS_RADIUS + focus_width + focus_pad), + 2 * (FOCUS_RADIUS + focus_width + focus_pad)); + } + } /* Paints the contents of the HSV color selector */ diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c index 91d7679a61..407a6f4338 100644 --- a/gtk/gtkstyle.c +++ b/gtk/gtkstyle.c @@ -1880,14 +1880,18 @@ gtk_style_real_realize (GtkStyle *style) style->white.blue = 0xffff; gdk_colormap_alloc_color (style->colormap, &style->white, FALSE, TRUE); - gc_values_mask = GDK_GC_FOREGROUND; + gc_values_mask = GDK_GC_FOREGROUND | GDK_GC_BACKGROUND; gc_values.foreground = style->black; + gc_values.background = style->white; style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask); gc_values.foreground = style->white; + gc_values.background = style->black; style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask); + gc_values_mask = GDK_GC_FOREGROUND; + for (i = 0; i < 5; i++) { if (style->rc_style && style->rc_style->bg_pixmap_name[i]) @@ -4615,8 +4619,6 @@ gtk_default_draw_focus (GtkStyle *style, gint8 *dash_list = "\1\1"; gint dash_len; - gc = style->fg_gc[state_type]; - if (widget) { gtk_widget_style_get (widget, @@ -4629,13 +4631,19 @@ gtk_default_draw_focus (GtkStyle *style, sanitize_size (window, &width, &height); - if (area) - gdk_gc_set_clip_rectangle (gc, area); + if (detail && !strcmp (detail, "colorwheel_light")) + gc = style->black_gc; + else if (detail && !strcmp (detail, "colorwheel_dark")) + gc = style->white_gc; + else + gc = style->fg_gc[state_type]; gdk_gc_set_line_attributes (gc, line_width, dash_list[0] ? GDK_LINE_ON_OFF_DASH : GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER); - + + if (area) + gdk_gc_set_clip_rectangle (gc, area); if (detail && !strcmp (detail, "add-mode")) {