[dia/cairo-port] Port line style picker



commit 5733ac0ea0ce00ce7779a12625c27e5b834ce8c9
Author: Zander Brown <zbrown gnome org>
Date:   Fri Dec 7 13:55:40 2018 +0000

    Port line style picker

 lib/dialinechooser.c | 45 ++++++++++++++++++---------------------------
 1 file changed, 18 insertions(+), 27 deletions(-)
---
diff --git a/lib/dialinechooser.c b/lib/dialinechooser.c
index ff360db6..506d94a2 100644
--- a/lib/dialinechooser.c
+++ b/lib/dialinechooser.c
@@ -119,17 +119,14 @@ dia_line_preview_expose(GtkWidget *widget, GdkEventExpose *event)
   gint width, height;
   gint x, y;
   GdkWindow *win;
-  GdkGC *gc;
-  GdkGCValues gcvalues;
-  gint8 dash_list[6];
+  double dash_list[6];
   int line_width = 2;
   GtkStyle *style;
+  GdkColor bg;
+  GdkColor fg;
+  cairo_t *ctx;
 
-#if GTK_CHECK_VERSION(2,18,0)
   if (gtk_widget_is_drawable(widget)) {
-#else
-  if (GTK_WIDGET_DRAWABLE(widget)) {
-#endif
     width = widget->allocation.width - misc->xpad * 2;
     height = widget->allocation.height - misc->ypad * 2;
     x = (widget->allocation.x + misc->xpad);
@@ -137,54 +134,48 @@ dia_line_preview_expose(GtkWidget *widget, GdkEventExpose *event)
 
     win = gtk_widget_get_window (widget);
     style = gtk_widget_get_style (widget);
-    gc = style->fg_gc[widget->state];
+    bg = style->base[gtk_widget_get_state(widget)];
+    fg = style->text[gtk_widget_get_state(widget)];
+
+    ctx = gdk_cairo_create (win);
+    cairo_set_line_cap (ctx, CAIRO_LINE_CAP_BUTT);
+    cairo_set_line_join (ctx, CAIRO_LINE_JOIN_MITER);
 
-    /* increase line width */
-    gdk_gc_get_values(gc, &gcvalues);
     switch (line->lstyle) {
     case LINESTYLE_DEFAULT:
     case LINESTYLE_SOLID:
-      gdk_gc_set_line_attributes(gc, line_width, GDK_LINE_SOLID,
-                                gcvalues.cap_style, gcvalues.join_style);
+      cairo_set_dash (ctx, dash_list, 0, 0);
       break;
     case LINESTYLE_DASHED:
-      gdk_gc_set_line_attributes(gc, line_width, GDK_LINE_ON_OFF_DASH,
-                                gcvalues.cap_style, gcvalues.join_style);
       dash_list[0] = 10;
       dash_list[1] = 10;
-      gdk_gc_set_dashes(gc, 0, dash_list, 2);
+      cairo_set_dash (ctx, dash_list, 2, 0);
       break;
     case LINESTYLE_DASH_DOT:
-      gdk_gc_set_line_attributes(gc, line_width, GDK_LINE_ON_OFF_DASH,
-                                gcvalues.cap_style, gcvalues.join_style);
       dash_list[0] = 10;
       dash_list[1] = 4;
       dash_list[2] = 2;
       dash_list[3] = 4;
-      gdk_gc_set_dashes(gc, 0, dash_list, 4);
+      cairo_set_dash (ctx, dash_list, 4, 0);
       break;
     case LINESTYLE_DASH_DOT_DOT:
-      gdk_gc_set_line_attributes(gc, line_width, GDK_LINE_ON_OFF_DASH,
-                                gcvalues.cap_style, gcvalues.join_style);
       dash_list[0] = 10;
       dash_list[1] = 2;
       dash_list[2] = 2;
       dash_list[3] = 2;
       dash_list[4] = 2;
       dash_list[5] = 2;
-      gdk_gc_set_dashes(gc, 0, dash_list, 6);
+      cairo_set_dash (ctx, dash_list, 6, 0);
       break;
     case LINESTYLE_DOTTED:
-      gdk_gc_set_line_attributes(gc, line_width, GDK_LINE_ON_OFF_DASH,
-                                gcvalues.cap_style, gcvalues.join_style);
       dash_list[0] = 2;
       dash_list[1] = 2;
-      gdk_gc_set_dashes(gc, 0, dash_list, 2);
+      cairo_set_dash (ctx, dash_list, 2, 0);
       break;
     }
-    gdk_draw_line(win, gc, x, y+height/2, x+width, y+height/2);
-    gdk_gc_set_line_attributes(gc, gcvalues.line_width, gcvalues.line_style,
-                              gcvalues.cap_style, gcvalues.join_style);
+    cairo_move_to (ctx, x, y + height / 2);
+    cairo_line_to (ctx, x + width, y + height / 2);
+    cairo_stroke (ctx);
   }
   return TRUE;
 }


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