From 26df83e9e39227d74ed76d9241f7e752da1bffaa Mon Sep 17 00:00:00 2001 From: johanengelen Date: Wed, 19 Dec 2007 22:42:06 +0000 Subject: [PATCH] guides: switch from using one position coordinate to Geom::Point point_on_line --- src/desktop-events.cpp | 45 +++++++++---------------- src/dialogs/guidelinedialog.cpp | 17 +++++++--- src/display/guideline.cpp | 46 +++++++++++++------------- src/display/guideline.h | 8 ++--- src/guide-snapper.cpp | 3 +- src/satisfied-guide-cns.cpp | 2 +- src/sp-guide.cpp | 53 ++++++++++++++++++------------ src/sp-guide.h | 7 ++-- src/sp-item-rm-unsatisfied-cns.cpp | 2 +- src/ui/widget/ruler.cpp | 6 ++-- src/xml/repr-util.cpp | 11 +++++++ src/xml/repr.h | 7 ++++ 12 files changed, 114 insertions(+), 93 deletions(-) diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index fec316bd3..f0561202d 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -63,10 +63,7 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge sp_repr_set_boolean(repr, "showguides", TRUE); sp_repr_set_boolean(repr, "inkscape:guide-bbox", TRUE); - double const guide_pos_dt = event_dt[ horiz - ? NR::Y - : NR::X ]; - guide = sp_guideline_new(desktop->guides, guide_pos_dt, horiz ? Geom::Point(0.,1.) : Geom::Point(1.,0.)); + guide = sp_guideline_new(desktop->guides, event_dt.to_2geom(), 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 ), @@ -82,11 +79,7 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge SnapManager const &m = desktop->namedview->snap_manager; event_dt = m.guideSnap(event_dt, component_vectors[horiz ? NR::Y : NR::X]).getPoint(); - double const guide_pos_dt = event_dt[ horiz - ? NR::Y - : NR::X ]; - - sp_guideline_set_position(SP_GUIDELINE(guide), guide_pos_dt); + sp_guideline_set_position(SP_GUIDELINE(guide), event_dt.to_2geom()); desktop->set_coordinate_status(event_dt); desktop->setPosition (event_dt); } @@ -107,10 +100,7 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc()); Inkscape::XML::Node *repr = xml_doc->createElement("sodipodi:guide"); repr->setAttribute("orientation", (horiz) ? "horizontal" : "vertical"); - double const guide_pos_dt = event_dt[ horiz - ? NR::Y - : NR::X ]; - sp_repr_set_svg_double(repr, "position", guide_pos_dt); + sp_repr_set_svg_point(repr, "position", event_dt.to_2geom()); SP_OBJECT_REPR(desktop->namedview)->appendChild(repr); Inkscape::GC::release(repr); sp_document_done(sp_desktop_document(desktop), SP_VERB_NONE, @@ -167,7 +157,7 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) ret = TRUE; } break; - case GDK_MOTION_NOTIFY: + case GDK_MOTION_NOTIFY: if (dragging) { NR::Point const motion_w(event->motion.x, event->motion.y); @@ -185,23 +175,23 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) ret = TRUE; } break; - case GDK_BUTTON_RELEASE: + case GDK_BUTTON_RELEASE: if (dragging && event->button.button == 1) { if (moved) { NR::Point const event_w(event->button.x, event->button.y); NR::Point event_dt(desktop->w2d(event_w)); - + SnapManager const &m = desktop->namedview->snap_manager; - event_dt = m.guideSnap(event_dt, guide->normal_to_line).getPoint(); - + event_dt = m.guideSnap(event_dt, guide->normal_to_line).getPoint(); + if (sp_canvas_world_pt_inside_window(item->canvas, event_w)) { sp_guide_moveto(*guide, sp_guide_position_from_pt(guide, event_dt), true); sp_document_done(sp_desktop_document(desktop), SP_VERB_NONE, _("Move guide")); } else { /* Undo movement of any attached shapes. */ - sp_guide_moveto(*guide, guide->position, false); + sp_guide_moveto(*guide, guide->point_on_line, false); sp_guide_remove(guide); sp_document_done(sp_desktop_document(desktop), SP_VERB_NONE, _("Delete guide")); @@ -214,25 +204,20 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data) sp_canvas_item_ungrab(item, event->button.time); ret=TRUE; } - case GDK_ENTER_NOTIFY: - { - + case GDK_ENTER_NOTIFY: + { sp_guideline_set_color(SP_GUIDELINE(item), guide->hicolor); - GString *position_string = SP_PX_TO_METRIC_STRING(guide->position, desktop->namedview->getDefaultMetric()); char *guide_description = sp_guide_description(guide); - - desktop->guidesMessageContext()->setF(Inkscape::NORMAL_MESSAGE, _("%s at %s"), guide_description, position_string->str); - + desktop->guidesMessageContext()->setF(Inkscape::NORMAL_MESSAGE, "%s", guide_description); g_free(guide_description); - g_string_free(position_string, TRUE); break; - } - case GDK_LEAVE_NOTIFY: + } + case GDK_LEAVE_NOTIFY: sp_guideline_set_color(SP_GUIDELINE(item), guide->color); desktop->guidesMessageContext()->clear(); break; - default: + default: break; } diff --git a/src/dialogs/guidelinedialog.cpp b/src/dialogs/guidelinedialog.cpp index aef0cc473..d0cdfdd2a 100644 --- a/src/dialogs/guidelinedialog.cpp +++ b/src/dialogs/guidelinedialog.cpp @@ -69,10 +69,13 @@ void GuidelinePropertiesDialog::_onApply() gdouble const raw_dist = _spin_button.get_value(); SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(_unit_selector->gobj())); gdouble const points = sp_units_get_pixels(raw_dist, unit); - gdouble const newpos = ( _mode - ? points - : _guide->position + points ); - sp_guide_moveto(*_guide, newpos, true); + if (_guide->normal_to_line[Geom::Y] == 1.) { + gdouble const newpos = ( _mode ? points : _guide->point_on_line[Geom::Y] + points ); + sp_guide_moveto(*_guide, Geom::Point(0, newpos), true); + } else { + gdouble const newpos = ( _mode ? points : _guide->point_on_line[Geom::Y] + points ); + sp_guide_moveto(*_guide, Geom::Point(newpos, 0), true); + } sp_document_done(SP_OBJECT_DOCUMENT(_guide), SP_VERB_NONE, _("Set guide properties")); } @@ -169,7 +172,11 @@ void GuidelinePropertiesDialog::_setup() { signal_response().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_response)); // initialize dialog - _oldpos = _guide->position; + if (_guide->normal_to_line[Geom::Y] == 0.) { + _oldpos = _guide->point_on_line[Geom::X]; + } else { + _oldpos = _guide->point_on_line[Geom::Y]; + } { gchar *guide_description = sp_guide_description(_guide); Inkscape::XML::Node *repr = SP_OBJECT_REPR (_guide); diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index 154b7c3b8..fcddbb0e6 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -69,7 +69,8 @@ static void sp_guideline_init(SPGuideLine *gl) { gl->rgba = 0x0000ff7f; - gl->normal = Geom::Point(0,1); + gl->normal_to_line = Geom::Point(0,1); + gl->point_on_line = Geom::Point(0,0); gl->sensitive = 0; } @@ -89,15 +90,16 @@ static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf) unsigned int const b = NR_RGBA32_B (gl->rgba); unsigned int const a = NR_RGBA32_A (gl->rgba); - if (gl->normal[Geom::Y] == 0.) { - if (gl->position < buf->rect.x0 || gl->position >= buf->rect.x1) { + if (gl->normal_to_line[Geom::Y] == 0.) { + int position = gl->point_on_line[Geom::X]; + if (position < buf->rect.x0 || position >= buf->rect.x1) { return; } int p0 = buf->rect.y0; int p1 = buf->rect.y1; int step = buf->buf_rowstride; - unsigned char *d = buf->buf + 3 * (gl->position - buf->rect.x0); + unsigned char *d = buf->buf + 3 * (position - buf->rect.x0); for (int p = p0; p < p1; p++) { d[0] = NR_COMPOSEN11_1111(r, a, d[0]); @@ -105,15 +107,16 @@ static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf) d[2] = NR_COMPOSEN11_1111(b, a, d[2]); d += step; } - } else if (gl->normal[Geom::X] == 0.) { - if (gl->position < buf->rect.y0 || gl->position >= buf->rect.y1) { + } else if (gl->normal_to_line[Geom::X] == 0.) { + int position = gl->point_on_line[Geom::Y]; + if (position < buf->rect.y0 || position >= buf->rect.y1) { return; } int p0 = buf->rect.x0; int p1 = buf->rect.x1; int step = 3; - unsigned char *d = buf->buf + (gl->position - buf->rect.y0) * buf->buf_rowstride; + unsigned char *d = buf->buf + (position - buf->rect.y0) * buf->buf_rowstride; for (int p = p0; p < p1; p++) { d[0] = NR_COMPOSEN11_1111(r, a, d[0]); @@ -134,15 +137,17 @@ static void sp_guideline_update(SPCanvasItem *item, NR::Matrix const &affine, un ((SPCanvasItemClass *) parent_class)->update(item, affine, flags); } - 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); + gl->point_on_line[Geom::X] = affine[4]; + gl->point_on_line[Geom::Y] = affine[5]; + + if (gl->normal_to_line[Geom::Y] == 1.) { + sp_canvas_update_bbox (item, -1000000, -1000000, 1000000, 1000000); } else { - gl->position = (int) (affine[5] - 0.5); - sp_canvas_update_bbox (item, -1000000, gl->position, 1000000, gl->position + 1); + sp_canvas_update_bbox (item, -1000000, -1000000, 1000000, 1000000); } } +// Returns 0.0 if point is on the guideline static double sp_guideline_point(SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item) { SPGuideLine *gl = SP_GUIDELINE (item); @@ -153,30 +158,27 @@ static double sp_guideline_point(SPCanvasItem *item, NR::Point p, SPCanvasItem * *actual_item = item; - 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); - } + double distance = Geom::dot((p.to_2geom() - gl->point_on_line), gl->normal_to_line); + return MAX(fabs(distance)-1, 0); } -SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, double position, Geom::Point normal) +SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, Geom::Point point_on_line, Geom::Point normal) { SPCanvasItem *item = sp_canvas_item_new(parent, SP_TYPE_GUIDELINE, NULL); SPGuideLine *gl = SP_GUIDELINE(item); normal.normalize(); - gl->normal = normal; - sp_guideline_set_position(gl, position); + gl->normal_to_line = normal; + sp_guideline_set_position(gl, point_on_line); return item; } -void sp_guideline_set_position(SPGuideLine *gl, double position) +void sp_guideline_set_position(SPGuideLine *gl, Geom::Point point_on_line) { sp_canvas_item_affine_absolute(SP_CANVAS_ITEM (gl), - NR::Matrix(NR::translate(position, position))); + NR::Matrix(NR::translate(point_on_line))); } void sp_guideline_set_color(SPGuideLine *gl, unsigned int rgba) diff --git a/src/display/guideline.h b/src/display/guideline.h index a9bfc809b..b3d9bb56b 100644 --- a/src/display/guideline.h +++ b/src/display/guideline.h @@ -26,8 +26,8 @@ struct SPGuideLine { guint32 rgba; - int position; - Geom::Point normal; + Geom::Point normal_to_line; + Geom::Point point_on_line; unsigned int sensitive : 1; }; @@ -38,9 +38,9 @@ struct SPGuideLineClass { GType sp_guideline_get_type(); -SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, double position, Geom::Point normal); +SPCanvasItem *sp_guideline_new(SPCanvasGroup *parent, Geom::Point point_on_line, Geom::Point normal); -void sp_guideline_set_position(SPGuideLine *gl, double position); +void sp_guideline_set_position(SPGuideLine *gl, Geom::Point point_on_line); void sp_guideline_set_color(SPGuideLine *gl, unsigned int rgba); void sp_guideline_set_sensitive(SPGuideLine *gl, int sensitive); diff --git a/src/guide-snapper.cpp b/src/guide-snapper.cpp index 1e78f609a..fb16382d2 100644 --- a/src/guide-snapper.cpp +++ b/src/guide-snapper.cpp @@ -32,8 +32,7 @@ Inkscape::GuideSnapper::LineList Inkscape::GuideSnapper::_getSnapLines(NR::Point for (GSList const *l = _named_view->guides; l != NULL; l = l->next) { SPGuide const *g = SP_GUIDE(l->data); - NR::Point point_on_line = (g->normal_to_line == component_vectors[NR::X]) ? NR::Point(g->position, 0) : NR::Point(0, g->position); - s.push_back(std::make_pair(g->normal_to_line, point_on_line)); + s.push_back(std::make_pair(g->normal_to_line, g->point_on_line)); } return s; diff --git a/src/satisfied-guide-cns.cpp b/src/satisfied-guide-cns.cpp index ece5118c5..112930925 100644 --- a/src/satisfied-guide-cns.cpp +++ b/src/satisfied-guide-cns.cpp @@ -13,7 +13,7 @@ void satisfied_guide_cns(SPDesktop const &desktop, for (GSList const *l = nv.guides; l != NULL; l = l->next) { SPGuide &g = *SP_GUIDE(l->data); for (unsigned int i = 0; i < snappoints.size(); ++i) { - if (approx_equal(dot(g.normal_to_line, snappoints[i]), g.position)) { + if (approx_equal( sp_guide_distance_from_pt(&g, snappoints[i].to_2geom()), 0) ) { cns.push_back(SPGuideConstraint(&g, i)); } } diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp index ff16c5381..94f937ff9 100644 --- a/src/sp-guide.cpp +++ b/src/sp-guide.cpp @@ -20,6 +20,7 @@ #endif #include "display/guideline.h" #include "svg/svg.h" +#include "svg/stringstream.h" #include "attributes.h" #include "sp-guide.h" #include @@ -28,6 +29,11 @@ #include #include #include +#include "sp-metrics.h" +#include "inkscape.h" +#include "desktop.h" +#include "sp-namedview.h" + using std::vector; enum { @@ -102,9 +108,7 @@ static void sp_guide_class_init(SPGuideClass *gc) static void sp_guide_init(SPGuide *guide) { guide->normal_to_line = component_vectors[NR::Y]; - /* constrain y coordinate; horizontal line. I doubt it ever matters what we initialize - this to. */ - guide->position = 0.0; + guide->point_on_line = Geom::Point(0.,0.); guide->color = 0x0000ff7f; guide->hicolor = 0xff00007f; } @@ -215,11 +219,10 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value) guide->point_on_line = Geom::Point(newx, 0); } } - sp_svg_number_read_d(value, &guide->position); // update position in non-committing way // fixme: perhaps we need to add an update method instead, and request_update here - sp_guide_moveto(*guide, guide->position, false); + sp_guide_moveto(*guide, guide->point_on_line, false); } break; default: @@ -232,10 +235,7 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value) void sp_guide_show(SPGuide *guide, SPCanvasGroup *group, GCallback handler) { - bool const vertical_line_p = ( guide->normal_to_line == component_vectors[NR::X] ); - g_assert(( guide->normal_to_line == component_vectors[NR::X] ) || - ( guide->normal_to_line == component_vectors[NR::Y] ) ); - SPCanvasItem *item = sp_guideline_new(group, guide->position, vertical_line_p ? Geom::Point(1.,0.) : Geom::Point(0.,1.)); + SPCanvasItem *item = sp_guideline_new(group, guide->point_on_line, guide->normal_to_line.to_2geom()); sp_guideline_set_color(SP_GUIDELINE(item), guide->color); g_signal_connect(G_OBJECT(item), "event", G_CALLBACK(handler), guide); @@ -278,32 +278,36 @@ void sp_guide_sensitize(SPGuide *guide, SPCanvas *canvas, gboolean sensitive) g_assert_not_reached(); } -double sp_guide_position_from_pt(SPGuide const *guide, NR::Point const &pt) +Geom::Point sp_guide_position_from_pt(SPGuide const *guide, NR::Point const &pt) +{ + return -(pt.to_2geom() - guide->point_on_line); +} + +double sp_guide_distance_from_pt(SPGuide const *guide, Geom::Point const &pt) { - return dot(guide->normal_to_line, pt); + return dot(pt - guide->point_on_line, guide->normal_to_line); } /** * \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. + * 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_moveto(SPGuide const &guide, gdouble const position, bool const commit) +void sp_guide_moveto(SPGuide const &guide, Geom::Point const point_on_line, bool const commit) { g_assert(SP_IS_GUIDE(&guide)); for (GSList *l = guide.views; l != NULL; l = l->next) { - sp_guideline_set_position(SP_GUIDELINE(l->data), - position); + 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 case, so that the guide's new position is available for sp_item_rm_unsatisfied_cns. */ if (commit) { - sp_repr_set_svg_double(SP_OBJECT(&guide)->repr, - "position", position); + sp_repr_set_svg_point(SP_OBJECT(&guide)->repr, "position", point_on_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) @@ -311,6 +315,7 @@ void sp_guide_moveto(SPGuide const &guide, gdouble const position, bool const co SPGuideAttachment const &att = *i; sp_item_notify_moveto(*att.item, guide, att.snappoint_ix, position, commit); } +*/ } /** @@ -322,20 +327,26 @@ char *sp_guide_description(SPGuide const *guide) { using NR::X; using NR::Y; + + GString *position_string_x = SP_PX_TO_METRIC_STRING(guide->point_on_line[X], SP_ACTIVE_DESKTOP->namedview->getDefaultMetric()); + GString *position_string_y = SP_PX_TO_METRIC_STRING(guide->point_on_line[Y], SP_ACTIVE_DESKTOP->namedview->getDefaultMetric()); if ( guide->normal_to_line == component_vectors[X] ) { - return g_strdup(_("vertical guideline")); + return g_strdup_printf(_("vertical guideline at %s"), position_string_x->str); } else if ( guide->normal_to_line == component_vectors[Y] ) { - return g_strdup(_("horizontal guideline")); + return g_strdup_printf(_("horizontal guideline at %s"), position_string_y->str); } else { double const radians = atan2(guide->normal_to_line[X], guide->normal_to_line[Y]); /* flip y axis and rotate 90 degrees to convert to line angle */ double const degrees = ( radians / M_PI ) * 180.0; int const degrees_int = (int) floor( degrees + .5 ); - return g_strdup_printf("%d degree guideline", degrees_int); + return g_strdup_printf("%d degree guideline at (%s,%s)", degrees_int, position_string_x->str, position_string_y->str); /* Alternative suggestion: "angled guideline". */ } + + g_string_free(position_string_x, TRUE); + g_string_free(position_string_y, TRUE); } void sp_guide_remove(SPGuide *guide) diff --git a/src/sp-guide.h b/src/sp-guide.h index aa3464918..48583bbe6 100644 --- a/src/sp-guide.h +++ b/src/sp-guide.h @@ -28,7 +28,7 @@ struct SPGuide : public SPObject { NR::Point normal_to_line; Geom::Point point_on_line; - gdouble position; + guint32 color; guint32 hicolor; GSList *views; @@ -45,8 +45,9 @@ void sp_guide_show(SPGuide *guide, SPCanvasGroup *group, GCallback handler); void sp_guide_hide(SPGuide *guide, SPCanvas *canvas); void sp_guide_sensitize(SPGuide *guide, SPCanvas *canvas, gboolean sensitive); -double sp_guide_position_from_pt(SPGuide const *guide, NR::Point const &pt); -void sp_guide_moveto(SPGuide const &guide, gdouble const position, bool const commit); +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_remove(SPGuide *guide); char *sp_guide_description(SPGuide const *guide); diff --git a/src/sp-item-rm-unsatisfied-cns.cpp b/src/sp-item-rm-unsatisfied-cns.cpp index 1f6a9ebe7..7f3f06975 100644 --- a/src/sp-item-rm-unsatisfied-cns.cpp +++ b/src/sp-item-rm-unsatisfied-cns.cpp @@ -18,7 +18,7 @@ void sp_item_rm_unsatisfied_cns(SPItem &item) SPGuideConstraint const &cn = item.constraints[i]; int const snappoint_ix = cn.snappoint_ix; g_assert( snappoint_ix < int(snappoints.size()) ); - if (!approx_equal(dot(cn.g->normal_to_line, snappoints[snappoint_ix]), cn.g->position)) { + if (!approx_equal( sp_guide_distance_from_pt(cn.g, snappoints[snappoint_ix].to_2geom()), 0) ) { remove_last(cn.g->attached_items, SPGuideAttachment(&item, cn.snappoint_ix)); g_assert( i < item.constraints.size() ); vector::iterator const ei(&item.constraints[i]); diff --git a/src/ui/widget/ruler.cpp b/src/ui/widget/ruler.cpp index 6a6bd8264..27c991446 100644 --- a/src/ui/widget/ruler.cpp +++ b/src/ui/widget/ruler.cpp @@ -105,8 +105,7 @@ Ruler::on_button_press_event(GdkEventButton *evb) _dragging = true; 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 ? Geom::Point(0.,1.) : Geom::Point(1.,0.)); + _guide = sp_guideline_new(_dt->guides, event_dt.to_2geom(), _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 | @@ -124,8 +123,7 @@ Ruler::on_motion_notify_event(GdkEventMotion *) NR::Point const &event_dt = get_event_dt(); if (_dragging) { - double const guide_pos_dt = event_dt[ _horiz_f ? NR::Y : NR::X ]; - sp_guideline_set_position(SP_GUIDELINE(_guide), guide_pos_dt); + sp_guideline_set_position(SP_GUIDELINE(_guide), event_dt.to_2geom()); _dt->set_coordinate_status(event_dt); _dt->setPosition(event_dt); } diff --git a/src/xml/repr-util.cpp b/src/xml/repr-util.cpp index 693558cf7..560a70004 100644 --- a/src/xml/repr-util.cpp +++ b/src/xml/repr-util.cpp @@ -576,6 +576,17 @@ sp_repr_set_svg_double(Inkscape::XML::Node *repr, gchar const *key, double val) return true; } +unsigned sp_repr_set_svg_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point val) +{ + g_return_val_if_fail(repr != NULL, FALSE); + g_return_val_if_fail(key != NULL, FALSE); + + Inkscape::SVGOStringStream os; + os << val[Geom::X] << "," << val[Geom::Y]; + + repr->setAttribute(key, os.str().c_str()); + return true; +} /* Local Variables: diff --git a/src/xml/repr.h b/src/xml/repr.h index 497cda119..2b5f4ad1e 100644 --- a/src/xml/repr.h +++ b/src/xml/repr.h @@ -21,6 +21,8 @@ #include "xml/document.h" #include "xml/sp-css-attr.h" +#include <2geom/point.h> + #define SP_SODIPODI_NS_URI "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" #define SP_BROKEN_SODIPODI_NS_URI "http://inkscape.sourceforge.net/DTD/sodipodi-0.dtd" #define SP_INKSCAPE_NS_URI "http://www.inkscape.org/namespaces/inkscape" @@ -127,6 +129,10 @@ * Kees Cook 2004-07-01, updated MenTaLguY 2005-01-25 */ +namespace Geom { +class Point; +} + /* SPXMLNs */ char const *sp_xml_ns_uri_prefix(gchar const *uri, gchar const *suggested); char const *sp_xml_ns_prefix_uri(gchar const *prefix); @@ -215,6 +221,7 @@ unsigned sp_repr_set_boolean(Inkscape::XML::Node *repr, gchar const *key, unsign unsigned sp_repr_set_int(Inkscape::XML::Node *repr, gchar const *key, int val); unsigned sp_repr_set_css_double(Inkscape::XML::Node *repr, gchar const *key, double val); unsigned sp_repr_set_svg_double(Inkscape::XML::Node *repr, gchar const *key, double val); +unsigned sp_repr_set_svg_point(Inkscape::XML::Node *repr, gchar const *key, Geom::Point val); /// \deprecated ! double sp_repr_get_double_attribute(Inkscape::XML::Node *repr, gchar const *key, double def); -- 2.30.2