From 30c340c2c1ad07599daa4e97135cc3786e6a70fc Mon Sep 17 00:00:00 2001 From: johanengelen Date: Fri, 21 Dec 2007 21:56:19 +0000 Subject: [PATCH] guidelines: add methods to check horizontal/vertical, small fixes --- src/dialogs/guidelinedialog.cpp | 6 +++--- src/display/guideline.cpp | 8 ++++---- src/display/guideline.h | 3 +++ src/sp-guide.h | 3 +++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/dialogs/guidelinedialog.cpp b/src/dialogs/guidelinedialog.cpp index d0cdfdd2a..e3c2fd363 100644 --- a/src/dialogs/guidelinedialog.cpp +++ b/src/dialogs/guidelinedialog.cpp @@ -69,11 +69,11 @@ 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); - if (_guide->normal_to_line[Geom::Y] == 1.) { + if (_guide->is_horizontal()) { 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 ); + gdouble const newpos = ( _mode ? points : _guide->point_on_line[Geom::X] + points ); sp_guide_moveto(*_guide, Geom::Point(newpos, 0), true); } sp_document_done(SP_OBJECT_DOCUMENT(_guide), SP_VERB_NONE, @@ -172,7 +172,7 @@ void GuidelinePropertiesDialog::_setup() { signal_response().connect(sigc::mem_fun(*this, &GuidelinePropertiesDialog::_response)); // initialize dialog - if (_guide->normal_to_line[Geom::Y] == 0.) { + if (_guide->is_vertical()) { _oldpos = _guide->point_on_line[Geom::X]; } else { _oldpos = _guide->point_on_line[Geom::Y]; diff --git a/src/display/guideline.cpp b/src/display/guideline.cpp index 376c1b988..51b2ec38d 100644 --- a/src/display/guideline.cpp +++ b/src/display/guideline.cpp @@ -93,7 +93,7 @@ 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_to_line[Geom::Y] == 0.) { + if (gl->is_vertical()) { int position = gl->point_on_line[Geom::X]; if (position < buf->rect.x0 || position >= buf->rect.x1) { return; @@ -110,7 +110,7 @@ static void sp_guideline_render(SPCanvasItem *item, SPCanvasBuf *buf) d[2] = NR_COMPOSEN11_1111(b, a, d[2]); d += step; } - } else if (gl->normal_to_line[Geom::X] == 0.) { + } else if (gl->is_horizontal()) { int position = gl->point_on_line[Geom::Y]; if (position < buf->rect.y0 || position >= buf->rect.y1) { return; @@ -179,9 +179,9 @@ static void sp_guideline_update(SPCanvasItem *item, NR::Matrix const &affine, un gl->point_on_line[Geom::X] = affine[4] +0.5; gl->point_on_line[Geom::Y] = affine[5] -0.5; - if (gl->normal_to_line[Geom::X] == 0.) { + if (gl->is_horizontal()) { sp_canvas_update_bbox (item, -1000000, gl->point_on_line[Geom::Y], 1000000, gl->point_on_line[Geom::Y] + 1); - } else if (gl->normal_to_line[Geom::Y] == 0.) { + } else if (gl->is_vertical()) { sp_canvas_update_bbox (item, gl->point_on_line[Geom::X], -1000000, gl->point_on_line[Geom::X]+1, 1000000); } else { sp_canvas_update_bbox (item, -1000000, -1000000, 1000000, 1000000); diff --git a/src/display/guideline.h b/src/display/guideline.h index 66e2ee50e..451aec1da 100644 --- a/src/display/guideline.h +++ b/src/display/guideline.h @@ -31,6 +31,9 @@ struct SPGuideLine { double angle; unsigned int sensitive : 1; + + inline bool is_horizontal() const { return (normal_to_line[Geom::X] == 0.); }; + inline bool is_vertical() const { return (normal_to_line[Geom::Y] == 0.); }; }; struct SPGuideLineClass { diff --git a/src/sp-guide.h b/src/sp-guide.h index 436428474..819457cb7 100644 --- a/src/sp-guide.h +++ b/src/sp-guide.h @@ -33,6 +33,9 @@ struct SPGuide : public SPObject { guint32 hicolor; GSList *views; std::vector attached_items; + + inline bool is_horizontal() const { return (normal_to_line[Geom::X] == 0.); }; + inline bool is_vertical() const { return (normal_to_line[Geom::Y] == 0.); }; }; struct SPGuideClass { -- 2.30.2