Verified Commit d0137e84 authored by Zander's avatar Zander 💥

Port DiaPageLayout

parent af3c7836
...@@ -58,7 +58,6 @@ struct _DiaPageLayout { ...@@ -58,7 +58,6 @@ struct _DiaPageLayout {
GtkWidget *darea; GtkWidget *darea;
GdkGC *gc;
GdkColor white, black, blue; GdkColor white, black, blue;
gint papernum; /* index into page_metrics array */ gint papernum; /* index into page_metrics array */
...@@ -366,7 +365,6 @@ dia_page_layout_init(DiaPageLayout *self) ...@@ -366,7 +365,6 @@ dia_page_layout_init(DiaPageLayout *self)
self->blue.blue = 0x7fff; self->blue.blue = 0x7fff;
gdk_color_alloc(gtk_widget_get_colormap(GTK_WIDGET(self)), &self->blue); gdk_color_alloc(gtk_widget_get_colormap(GTK_WIDGET(self)), &self->blue);
self->gc = NULL;
self->block_changed = FALSE; self->block_changed = FALSE;
} }
...@@ -610,68 +608,96 @@ darea_expose_event(DiaPageLayout *self, GdkEventExpose *event) ...@@ -610,68 +608,96 @@ darea_expose_event(DiaPageLayout *self, GdkEventExpose *event)
GdkWindow *window = gtk_widget_get_window(self->darea); GdkWindow *window = gtk_widget_get_window(self->darea);
gfloat val; gfloat val;
gint num; gint num;
cairo_t *ctx;
if (!window) if (!window)
return FALSE; return FALSE;
if (!self->gc) ctx = gdk_cairo_create (window);
self->gc = gdk_gc_new(window); cairo_set_line_cap (ctx, CAIRO_LINE_CAP_SQUARE);
cairo_set_line_width (ctx, 1);
cairo_set_antialias (ctx, CAIRO_ANTIALIAS_NONE);
gdk_window_clear_area (window, cairo_set_source_rgba (ctx, 0, 0, 0, 0);
0, 0, cairo_rectangle (ctx, 0, 0,
self->darea->allocation.width, self->darea->allocation.width,
self->darea->allocation.height); self->darea->allocation.height);
cairo_fill (ctx);
/* draw the page image */ /* draw the page image */
gdk_gc_set_foreground(self->gc, &self->black); gdk_cairo_set_source_color (ctx, &self->black);
gdk_draw_rectangle(window, self->gc, TRUE, self->x+3, self->y+3, cairo_rectangle(ctx, self->x+3, self->y+3, self->width, self->height);
self->width, self->height); cairo_fill (ctx);
gdk_gc_set_foreground(self->gc, &self->white); gdk_cairo_set_source_color (ctx, &self->white);
gdk_draw_rectangle(window, self->gc, TRUE, self->x, self->y, cairo_rectangle (ctx, self->x, self->y, self->width, self->height);
self->width, self->height); cairo_fill (ctx);
gdk_gc_set_foreground(self->gc, &self->black); gdk_cairo_set_source_color (ctx, &self->black);
gdk_draw_rectangle(window, self->gc, FALSE, self->x, self->y, cairo_rectangle (ctx, self->x + 1, self->y, self->width, self->height);
self->width-1, self->height-1); cairo_stroke (ctx);
gdk_gc_set_foreground(self->gc, &self->blue); gdk_cairo_set_source_color (ctx, &self->blue);
/* draw margins */ /* draw margins */
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(self->orient_portrait))) { if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->orient_portrait))) {
val = dia_unit_spinner_get_value(DIA_UNIT_SPINNER(self->tmargin)); /* Top */
num = self->y + val * self->height /get_paper_psheight(self->papernum); val = dia_unit_spinner_get_value (DIA_UNIT_SPINNER (self->tmargin));
gdk_draw_line(window, self->gc, self->x+1, num, self->x+self->width-2,num); num = self->y + val * self->height / get_paper_psheight (self->papernum);
cairo_move_to (ctx, self->x + 2, num);
val = dia_unit_spinner_get_value(DIA_UNIT_SPINNER(self->bmargin)); cairo_line_to (ctx, self->x + self->width, num);
cairo_stroke (ctx);
/* Bottom */
val = dia_unit_spinner_get_value (DIA_UNIT_SPINNER (self->bmargin));
num = self->y + self->height - num = self->y + self->height -
val * self->height / get_paper_psheight(self->papernum); val * self->height / get_paper_psheight (self->papernum);
gdk_draw_line(window, self->gc, self->x+1, num, self->x+self->width-2,num); cairo_move_to (ctx, self->x + 2, num);
cairo_line_to (ctx, self->x + self->width, num);
val = dia_unit_spinner_get_value(DIA_UNIT_SPINNER(self->lmargin)); cairo_stroke (ctx);
num = self->x + val * self->width / get_paper_pswidth(self->papernum);
gdk_draw_line(window, self->gc, num, self->y+1,num,self->y+self->height-2); /* Left */
val = dia_unit_spinner_get_value (DIA_UNIT_SPINNER (self->lmargin));
val = dia_unit_spinner_get_value(DIA_UNIT_SPINNER(self->rmargin)); num = self->x + val * self->width / get_paper_pswidth (self->papernum);
cairo_move_to (ctx, num + 1, self->y + 1);
cairo_line_to (ctx, num + 1, self->y + self->height - 1);
cairo_stroke (ctx);
/* Right */
val = dia_unit_spinner_get_value (DIA_UNIT_SPINNER (self->rmargin));
num = self->x + self->width - num = self->x + self->width -
val * self->width / get_paper_pswidth(self->papernum); val * self->width / get_paper_pswidth (self->papernum);
gdk_draw_line(window, self->gc, num, self->y+1,num,self->y+self->height-2); cairo_move_to (ctx, num + 1, self->y + 1);
cairo_line_to (ctx, num + 1, self->y + self->height - 1);
cairo_stroke (ctx);
} else { } else {
val = dia_unit_spinner_get_value(DIA_UNIT_SPINNER(self->tmargin)); /* Top */
num = self->y + val * self->height /get_paper_pswidth(self->papernum); val = dia_unit_spinner_get_value (DIA_UNIT_SPINNER (self->tmargin));
gdk_draw_line(window, self->gc, self->x+1, num, self->x+self->width-2,num); num = self->y + val * self->height / get_paper_pswidth (self->papernum);
cairo_move_to (ctx, self->x + 2, num);
val = dia_unit_spinner_get_value(DIA_UNIT_SPINNER(self->bmargin)); cairo_line_to (ctx, self->x + self->width, num);
cairo_stroke (ctx);
/* Bottom */
val = dia_unit_spinner_get_value (DIA_UNIT_SPINNER (self->bmargin));
num = self->y + self->height - num = self->y + self->height -
val * self->height / get_paper_pswidth(self->papernum); val * self->height / get_paper_pswidth (self->papernum);
gdk_draw_line(window, self->gc, self->x+1, num, self->x+self->width-2,num); cairo_move_to (ctx, self->x + 2, num);
cairo_line_to (ctx, self->x + self->width, num);
val = dia_unit_spinner_get_value(DIA_UNIT_SPINNER(self->lmargin)); cairo_stroke (ctx);
num = self->x + val * self->width / get_paper_psheight(self->papernum);
gdk_draw_line(window, self->gc, num, self->y+1,num,self->y+self->height-2); /* Left */
val = dia_unit_spinner_get_value (DIA_UNIT_SPINNER (self->lmargin));
val = dia_unit_spinner_get_value(DIA_UNIT_SPINNER(self->rmargin)); num = self->x + val * self->width / get_paper_psheight (self->papernum);
cairo_move_to (ctx, num + 1, self->y + 1);
cairo_line_to (ctx, num + 1, self->y + self->height - 1);
cairo_stroke (ctx);
/* Right */
val = dia_unit_spinner_get_value (DIA_UNIT_SPINNER (self->rmargin));
num = self->x + self->width - num = self->x + self->width -
val * self->width / get_paper_psheight(self->papernum); val * self->width / get_paper_psheight (self->papernum);
gdk_draw_line(window, self->gc, num, self->y+1,num,self->y+self->height-2); cairo_move_to (ctx, num + 1, self->y + 1);
cairo_line_to (ctx, num + 1, self->y + self->height - 1);
cairo_stroke (ctx);
} }
return FALSE; return FALSE;
...@@ -801,13 +827,6 @@ scale_changed(DiaPageLayout *self) ...@@ -801,13 +827,6 @@ scale_changed(DiaPageLayout *self)
static void static void
dia_page_layout_destroy(GtkObject *object) dia_page_layout_destroy(GtkObject *object)
{ {
DiaPageLayout *self = DIA_PAGE_LAYOUT(object);
if (self->gc) {
g_object_unref(self->gc);
self->gc = NULL;
}
if (parent_class->destroy) if (parent_class->destroy)
(* parent_class->destroy)(object); (* parent_class->destroy)(object);
} }
......
...@@ -71,7 +71,7 @@ linewidth_area_draw (GtkWidget *linewidth_area) ...@@ -71,7 +71,7 @@ linewidth_area_draw (GtkWidget *linewidth_area)
int x_offs; int x_offs;
GtkStyle *style; GtkStyle *style;
cairo_t *ctx; cairo_t *ctx;
double dashes[] = { 1, 1, 1, 0, 0, 0 }; double dashes[] = { 3 };
if (!linewidth_area_pixmap) /* we haven't gotten initial expose yet, if (!linewidth_area_pixmap) /* we haven't gotten initial expose yet,
* no point in drawing anything */ * no point in drawing anything */
...@@ -81,7 +81,7 @@ linewidth_area_draw (GtkWidget *linewidth_area) ...@@ -81,7 +81,7 @@ linewidth_area_draw (GtkWidget *linewidth_area)
cairo_set_line_width (ctx, 1); cairo_set_line_width (ctx, 1);
cairo_set_line_cap (ctx, CAIRO_LINE_CAP_BUTT); cairo_set_line_cap (ctx, CAIRO_LINE_CAP_BUTT);
cairo_set_line_join (ctx, CAIRO_LINE_JOIN_MITER); cairo_set_line_join (ctx, CAIRO_LINE_JOIN_MITER);
cairo_set_dash (ctx, dashes, 6, 0); cairo_set_dash (ctx, dashes, 1, 0);
gdk_drawable_get_size (linewidth_area_pixmap, &width, &height); gdk_drawable_get_size (linewidth_area_pixmap, &width, &height);
......
...@@ -107,7 +107,7 @@ magnify_motion(MagnifyTool *tool, GdkEventMotion *event, ...@@ -107,7 +107,7 @@ magnify_motion(MagnifyTool *tool, GdkEventMotion *event,
if (tool->box_active) { if (tool->box_active) {
GdkColor white; GdkColor white;
cairo_t *ctx; cairo_t *ctx;
double dashes[] = { 1, 1, 1, 0, 0, 0 }; double dashes[] = { 3 };
tool->moved = TRUE; tool->moved = TRUE;
color_convert(&color_white, &white); color_convert(&color_white, &white);
...@@ -117,7 +117,7 @@ magnify_motion(MagnifyTool *tool, GdkEventMotion *event, ...@@ -117,7 +117,7 @@ magnify_motion(MagnifyTool *tool, GdkEventMotion *event,
cairo_set_line_width (ctx, 1); cairo_set_line_width (ctx, 1);
cairo_set_line_cap (ctx, CAIRO_LINE_CAP_BUTT); cairo_set_line_cap (ctx, CAIRO_LINE_CAP_BUTT);
cairo_set_line_join (ctx, CAIRO_LINE_JOIN_MITER); cairo_set_line_join (ctx, CAIRO_LINE_JOIN_MITER);
cairo_set_dash (ctx, dashes, 6, 0); cairo_set_dash (ctx, dashes, 1, 0);
gdk_cairo_set_source_color (ctx, &white); gdk_cairo_set_source_color (ctx, &white);
cairo_set_operator (ctx, CAIRO_OPERATOR_XOR); cairo_set_operator (ctx, CAIRO_OPERATOR_XOR);
......
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