GtkStyle patch for drawing bigger expanders...



Hi:

In adding an enlarged expander size to my 'HighContrastLargeprint' theme
I came across the problem that the line used to draw the expanders is
very thin, looks a little odd with big expanders.

Attached is a patch that, though it does not change the appearance of
the default expanders, increases the line thickness for bigger ones:

line_thickness = MAX (1, expander_size/7)

it then draws the lines, mitered, and adjusted for size so that the
result still fits in the specified size.

In the process I added a static func gtk_style_draw_polygon_with_gc to
avoid code duplication.

OK to commit?

I can provide .PNG files on request if you want to see the results.

-Bill
Index: gtk/gtkstyle.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkstyle.c,v
retrieving revision 1.98
diff -u -r1.98 gtkstyle.c
--- gtk/gtkstyle.c	2002/01/15 16:35:01	1.98
+++ gtk/gtkstyle.c	2002/01/25 15:55:24
@@ -4353,6 +4353,18 @@
 }
 
 static void
+gtk_style_draw_polygon_with_gc (GdkWindow *window, GdkGC *gc, gint line_width,
+				gboolean do_fill, GdkPoint *points, gint n_points)
+{
+  gdk_gc_set_line_attributes (gc, line_width,
+			      GDK_LINE_SOLID,
+			      GDK_CAP_BUTT, GDK_JOIN_MITER);
+
+  gdk_draw_polygon (window, gc, do_fill, points, n_points);
+  gdk_gc_set_line_attributes (gc, 0, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
+}
+
+static void
 gtk_default_draw_expander (GtkStyle        *style,
                            GdkWindow       *window,
                            GtkStateType     state_type,
@@ -4366,12 +4378,14 @@
   gint expander_size;
   GdkPoint points[3];
   gint i;
+  gint line_width;
   gdouble affine[6];
   gint degrees = 0;
   
   gtk_widget_style_get (widget,
 			"expander_size", &expander_size,
 			NULL);
+  line_width = MAX (1, expander_size/7);
 
   if (area)
     {
@@ -4379,12 +4393,13 @@
       gdk_gc_set_clip_rectangle (style->base_gc[GTK_STATE_NORMAL], area);
     }
 
-  points[0].x = 0;
-  points[0].y = 0;
-  points[1].x = expander_size / 2;
-  points[1].y =  expander_size / 2;
-  points[2].x = 0;
-  points[2].y = expander_size;
+  expander_size -= (line_width * 2 - 2);
+  points[0].x = line_width / 2;
+  points[0].y = line_width / 2;
+  points[1].x = expander_size / 2 + line_width / 2;
+  points[1].y = expander_size / 2 + line_width / 2;
+  points[2].x = line_width / 2;
+  points[2].y = expander_size + line_width / 2;
 
   switch (expander_style)
     {
@@ -4411,22 +4426,22 @@
 
   if (state_type == GTK_STATE_PRELIGHT)
     {
-      gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
-			TRUE, points, 3);
+      gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
+				      1, TRUE, points, 3);
     }
   else if (state_type == GTK_STATE_ACTIVE)
     {
-      gdk_draw_polygon (window, style->light_gc[GTK_STATE_ACTIVE],
-			TRUE, points, 3);
-      gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
-			FALSE, points, 3);
+      gtk_style_draw_polygon_with_gc (window, style->light_gc[GTK_STATE_ACTIVE],
+				      1, TRUE, points, 3);
+      gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
+				      line_width, FALSE, points, 3);
     }
   else
     {
-      gdk_draw_polygon (window, style->base_gc[GTK_STATE_NORMAL],
-			TRUE, points, 3);
-      gdk_draw_polygon (window, style->fg_gc[GTK_STATE_NORMAL],
-			FALSE, points, 3);
+      gtk_style_draw_polygon_with_gc (window, style->base_gc[GTK_STATE_NORMAL],
+				      1, TRUE, points, 3);
+      gtk_style_draw_polygon_with_gc (window, style->fg_gc[GTK_STATE_NORMAL],
+				      line_width, FALSE, points, 3);
     }
   if (area)
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]