Verified Commit 56543289 authored by Zander's avatar Zander 💥

Port line style picker

parent 33e5aaa3
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment