From 5562f1c65a931abfa0924ce345867fa9ad4ce8e2 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Wed, 19 Dec 2007 23:30:04 +0000 Subject: [PATCH] correctly handle orientation changes of guidelines --- src/display/guideline.cpp | 6 ++++++ src/display/guideline.h | 1 + src/sp-guide.cpp | 33 ++++++++++++++++++++++++++++++++- src/sp-guide.h | 1 + 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index 32d0e0c1e..1f1d996ff 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -183,6 +183,12 @@ void sp_guideline_set_position(SPGuideLine *gl, Geom::Point point_on_line) NR::Matrix(NR::translate(point_on_line))); } +void sp_guideline_set_normal(SPGuideLine *gl, Geom::Point normal_to_line) +{ + gl->normal_to_line = normal_to_line; + sp_canvas_item_request_update(SP_CANVAS_ITEM (gl)); +} + void sp_guideline_set_color(SPGuideLine *gl, unsigned int rgba) { gl->rgba = rgba; diff --git a/src/display/guideline.h b/src/display/guideline.h index b3d9bb56b..24353af0a 100644 --- a/src/display/guideline.h +++ b/src/display/guideline.h @@ -41,6 +41,7 @@ GType sp_guideline_get_type(); SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, Geom::Point point_on_line, Geom::Point normal); void sp_guideline_set_position(SPGuideLine *gl, Geom::Point point_on_line); +void sp_guideline_set_normal(SPGuideLine *gl, Geom::Point normal_to_line); void sp_guideline_set_color(SPGuideLine *gl, unsigned int rgba); void sp_guideline_set_sensitive(SPGuideLine *gl, int sensitive); diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index 94f937ff9..bd5823e16 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -199,6 +199,7 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value) // default to vertical line for bad arguments guide->normal_to_line = component_vectors[NR::X]; } + sp_guide_set_normal(*guide, guide->normal_to_line.to_2geom(), false); } break; case SP_ATTR_POSITION: @@ -301,7 +302,7 @@ void sp_guide_moveto(SPGuide const &guide, Geom::Point const point_on_line, bool sp_guideline_set_position(SP_GUIDELINE(l->data), point_on_line); } - /* Calling sp_repr_set_svg_double must precede calling sp_item_notify_moveto in the commit + /* Calling sp_repr_set_svg_point must precede calling sp_item_notify_moveto in the commit case, so that the guide's new position is available for sp_item_rm_unsatisfied_cns. */ if (commit) { sp_repr_set_svg_point(SP_OBJECT(&guide)->repr, "position", point_on_line); @@ -318,6 +319,36 @@ void sp_guide_moveto(SPGuide const &guide, Geom::Point const point_on_line, bool */ } +/** + * \arg commit False indicates temporary moveto in response to motion event while dragging, + * true indicates a "committing" version: in response to button release event after + * dragging a guideline, or clicking OK in guide editing dialog. + */ +void sp_guide_set_normal(SPGuide const &guide, Geom::Point const normal_to_line, bool const commit) +{ + g_assert(SP_IS_GUIDE(&guide)); + + for (GSList *l = guide.views; l != NULL; l = l->next) { + sp_guideline_set_normal(SP_GUIDELINE(l->data), normal_to_line); + } + + /* Calling sp_repr_set_svg_point must precede calling sp_item_notify_moveto in the commit + case, so that the guide's new position is available for sp_item_rm_unsatisfied_cns. */ + if (commit) { + sp_repr_set_svg_point(SP_OBJECT(&guide)->repr, "orientation", normal_to_line); + } + +/* DISABLED CODE BECAUSE SPGuideAttachment IS NOT USE AT THE MOMENT (johan) + for (vector::const_iterator i(guide.attached_items.begin()), + iEnd(guide.attached_items.end()); + i != iEnd; ++i) + { + SPGuideAttachment const &att = *i; + sp_item_notify_moveto(*att.item, guide, att.snappoint_ix, position, commit); + } +*/ +} + /** * Returns a human-readable description of the guideline for use in dialog boxes and status bar. * diff --git a/src/sp-guide.h b/src/sp-guide.h index 48583bbe6..436428474 100644 --- a/src/sp-guide.h +++ b/src/sp-guide.h @@ -48,6 +48,7 @@ void sp_guide_sensitize(SPGuide *guide, SPCanvas *canvas, gboolean sensitive); Geom::Point sp_guide_position_from_pt(SPGuide const *guide, NR::Point const &pt); double sp_guide_distance_from_pt(SPGuide const *guide, Geom::Point const &pt); void sp_guide_moveto(SPGuide const &guide, Geom::Point const point_on_line, bool const commit); +void sp_guide_set_normal(SPGuide const &guide, Geom::Point const normal_to_line, bool const commit); void sp_guide_remove(SPGuide *guide); char *sp_guide_description(SPGuide const *guide); -- 2.30.2