From 627d5932965a686f0c1aa9083cab4429f3ba7abb Mon Sep 17 00:00:00 2001 From: johanengelen Date: Sun, 16 Dec 2007 22:01:05 +0000 Subject: [PATCH] start of getting angled guidelines. define guide's normal instead of vertical/horizontal. rendering is not implemented for angled guides yet. --- src/desktop-events.cpp | 2 +- src/display/guideline.cpp | 13 +++++++------ src/display/guideline.h | 9 +++++---- src/sp-guide.cpp | 21 ++++++++++++++++++++- src/sp-guide.h | 1 + src/ui/widget/ruler.cpp | 2 +- 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index 98e96c38c..d3c521fec 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -66,7 +66,7 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge double const guide_pos_dt = event_dt[ horiz ? NR::Y : NR::X ]; - guide = sp_guideline_new(desktop->guides, guide_pos_dt, !horiz); + guide = sp_guideline_new(desktop->guides, guide_pos_dt, horiz ? Geom::Point(0.,1.) : Geom::Point(1.,0.)); sp_guideline_set_color(SP_GUIDELINE(guide), desktop->namedview->guidehicolor); gdk_pointer_grab(widget->window, FALSE, (GdkEventMask)(GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK ), diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index 36f51d3c6..b029be7a0 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -67,7 +67,7 @@ static void sp_guideline_init(SPGuideLine *gl) { gl->rgba = 0x0000ff7f; - gl->vertical = 0; + gl->normal = Geom::Point(0,1); gl->sensitive = 0; } @@ -90,7 +90,7 @@ static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf) int p0, p1, step; unsigned char *d; - if (gl->vertical) { + if (gl->normal[Geom::Y] == 0.) { if (gl->position < buf->rect.x0 || gl->position >= buf->rect.x1) { return; @@ -129,7 +129,7 @@ static void sp_guideline_update(SPCanvasItem *item, NR::Matrix const &affine, un ((SPCanvasItemClass *) parent_class)->update(item, affine, flags); } - if (gl->vertical) { + if (gl->normal[Geom::Y] == 0.) { gl->position = (int) (affine[4] + 0.5); sp_canvas_update_bbox (item, gl->position, -1000000, gl->position + 1, 1000000); } else { @@ -148,20 +148,21 @@ static double sp_guideline_point(SPCanvasItem *item, NR::Point p, SPCanvasItem * *actual_item = item; - if (gl->vertical) { + if (gl->normal[Geom::Y] == 0.) { return MAX(fabs(gl->position - p[NR::X])-1, 0); } else { return MAX(fabs(gl->position - p[NR::Y])-1, 0); } } -SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, double position, unsigned int vertical) +SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, double position, Geom::Point normal) { SPCanvasItem *item = sp_canvas_item_new(parent, SP_TYPE_GUIDELINE, NULL); SPGuideLine *gl = SP_GUIDELINE(item); - gl->vertical = vertical; + normal.normalize(); + gl->normal = normal; sp_guideline_set_position(gl, position); return item; diff --git a/src/display/guideline.h b/src/display/guideline.h index 22f0af69a..85f39754b 100644 --- a/src/display/guideline.h +++ b/src/display/guideline.h @@ -13,6 +13,7 @@ */ #include "sp-canvas.h" +#include <2geom/point.h> #define SP_TYPE_GUIDELINE (sp_guideline_get_type()) #define SP_GUIDELINE(o) (GTK_CHECK_CAST((o), SP_TYPE_GUIDELINE, SPGuideLine)) @@ -22,10 +23,10 @@ struct SPGuideLine { SPCanvasItem item; guint32 rgba; - + int position; - - unsigned int vertical : 1; + Geom::Point normal; +// unsigned int vertical : 1; unsigned int sensitive : 1; }; @@ -35,7 +36,7 @@ struct SPGuideLineClass { GType sp_guideline_get_type(); -SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, double position, unsigned int vertical); +SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, double position, Geom::Point normal); void sp_guideline_set_position(SPGuideLine *gl, double position); void sp_guideline_set_color(SPGuideLine *gl, unsigned int rgba); diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index d65c9997a..4fc5a0f85 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -6,9 +6,11 @@ * Authors: * Lauris Kaplinski * Peter Moulder + * Johan Engelen * * Copyright (C) 2000-2002 authors * Copyright (C) 2004 Monash University + * Copyright (C) 2007 Johan Engelen * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -172,7 +174,24 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value) if (value && !strcmp(value, "horizontal")) { /* Visual representation of a horizontal line, constrain vertically (y coordinate). */ guide->normal = component_vectors[NR::Y]; + } else if (value && !strcmp(value, "vertical")) { + guide->normal = component_vectors[NR::X]; + } else if (value) { + gchar ** strarray = g_strsplit(value, ",", 2); + double newx, newy; + unsigned int success = sp_svg_number_read_d(strarray[0], &newx); + success += sp_svg_number_read_d(strarray[1], &newy); + g_strfreev (strarray); + if (success == 2) { + Geom::Point direction(newx, newy); + direction.normalize(); + guide->normal = direction; + } else { + // default to vertical line for bad arguments + guide->normal = component_vectors[NR::X]; + } } else { + // default to vertical line for bad arguments guide->normal = component_vectors[NR::X]; } break; @@ -195,7 +214,7 @@ void sp_guide_show(SPGuide *guide, SPCanvasGroup *group, GCallback handler) bool const vertical_line_p = ( guide->normal == component_vectors[NR::X] ); g_assert(( guide->normal == component_vectors[NR::X] ) || ( guide->normal == component_vectors[NR::Y] ) ); - SPCanvasItem *item = sp_guideline_new(group, guide->position, vertical_line_p); + SPCanvasItem *item = sp_guideline_new(group, guide->position, vertical_line_p ? Geom::Point(1.,0.) : Geom::Point(0.,1.)); sp_guideline_set_color(SP_GUIDELINE(item), guide->color); g_signal_connect(G_OBJECT(item), "event", G_CALLBACK(handler), guide); diff --git a/src/sp-guide.h b/src/sp-guide.h index a3b876483..534992174 100644 --- a/src/sp-guide.h +++ b/src/sp-guide.h @@ -7,6 +7,7 @@ * A guideline * * Copyright (C) Lauris Kaplinski 2000 + * Copyright (C) Johan Engelen 2007 * */ diff --git a/src/ui/widget/ruler.cpp b/src/ui/widget/ruler.cpp index 681b1dbbc..6a6bd8264 100644 --- a/src/ui/widget/ruler.cpp +++ b/src/ui/widget/ruler.cpp @@ -106,7 +106,7 @@ Ruler::on_button_press_event(GdkEventButton *evb) sp_repr_set_boolean(repr, "showguides", TRUE); sp_repr_set_boolean(repr, "inkscape:guide-bbox", TRUE); double const guide_pos_dt = event_dt[ _horiz_f ? NR::Y : NR::X ]; - _guide = sp_guideline_new(_dt->guides, guide_pos_dt, !_horiz_f); + _guide = sp_guideline_new(_dt->guides, guide_pos_dt, _horiz_f ? Geom::Point(0.,1.) : Geom::Point(1.,0.)); sp_guideline_set_color(SP_GUIDELINE(_guide), _dt->namedview->guidehicolor); (void) get_window()->pointer_grab(false, Gdk::BUTTON_RELEASE_MASK | -- 2.30.2