From 84e5676034b77e63dbc43746cec0a8b48fd06f7c Mon Sep 17 00:00:00 2001 From: johanengelen Date: Mon, 24 Dec 2007 00:48:00 +0000 Subject: [PATCH] angled guidelines: create angled line when dragging from edge of rulers --- src/desktop-events.cpp | 32 +++++++++++++++++++++++-------- src/display/canvas-axonomgrid.cpp | 4 ++-- src/display/canvas-grid.cpp | 18 ++++++++--------- src/display/canvas-grid.h | 6 +++--- src/sp-namedview.cpp | 14 ++++++++++++++ src/sp-namedview.h | 1 + 6 files changed, 53 insertions(+), 22 deletions(-) diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index 24d94b5a3..d5158255a 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -31,6 +31,9 @@ #include "xml/repr.h" #include "dialogs/guidelinedialog.h" #include "snap.h" +#include "display/canvas-grid.h" +#include "display/canvas-axonomgrid.h" +#include <2geom/point.h> /* Root item handler */ @@ -67,23 +70,36 @@ 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); + // calculate the normal of the guidelines when dragged from the edges of rulers. + Geom::Point normal_bl_to_tr(-1.,1.); //bottomleft to topright + Geom::Point normal_tr_to_bl(1.,1.); //topright to bottomleft + normal_bl_to_tr.normalize(); + normal_tr_to_bl.normalize(); + Inkscape::CanvasGrid * grid = sp_namedview_get_first_enabled_grid(desktop->namedview); + if ( grid && grid->getGridType() == Inkscape::GRID_AXONOMETRIC ) { + Inkscape::CanvasAxonomGrid *axonomgrid = dynamic_cast(grid); + if (event->button.state & GDK_CONTROL_MASK) { + // guidelines normal to gridlines + normal_bl_to_tr = Geom::Point::polar(-axonomgrid->angle_rad[0], 1.0); + normal_tr_to_bl = Geom::Point::polar(axonomgrid->angle_rad[2], 1.0); + } else { + normal_bl_to_tr = rot90(Geom::Point::polar(axonomgrid->angle_rad[2], 1.0)); + normal_tr_to_bl = rot90(Geom::Point::polar(-axonomgrid->angle_rad[0], 1.0)); + } + } if (horiz) { if (wx < 50) { - normal = Geom::Point(-1.,1.); - normal.normalize(); + normal = normal_bl_to_tr; } else if (wx > width - 50) { - normal = Geom::Point(1.,1.); - normal.normalize(); + normal = normal_tr_to_bl; } else { normal = Geom::Point(0.,1.); } } else { if (wy < 50) { - normal = Geom::Point(-1.,1.); - normal.normalize(); + normal = normal_bl_to_tr; } else if (wy > height - 50) { - normal = Geom::Point(1.,1.); - normal.normalize(); + normal = normal_tr_to_bl; } else { normal = Geom::Point(1.,0.); } diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index bb9923680..3d9375d2d 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -408,7 +408,7 @@ CanvasAxonomGrid::readRepr() visible = (strcmp(value,"true") == 0); } - if ( (value = repr->attribute("snap_enabled")) ) { + if ( (value = repr->attribute("enabled")) ) { g_assert(snapper != NULL); snapper->setEnabled(strcmp(value,"true") == 0); } @@ -453,7 +453,7 @@ CanvasAxonomGrid::updateWidgets() _rcb_visible.setActive(visible); if (snapper != NULL) { - _rcb_snap_enabled.setActive(snapper->getEnabled()); + _rcb_enabled.setActive(snapper->getEnabled()); } _rumg.setUnit (gridunit); diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 021a62f96..8d7bdd0e8 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -174,15 +174,15 @@ CanvasGrid::CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocume namelabel.set_markup(str); vbox.pack_start(namelabel, true, true); + _rcb_enabled.init ( _("_Enabled"), + _("Determines whether to snap to this grid or not. Can be 'on' for invisible grids."), + "enabled", _wr, false, repr, doc); + vbox.pack_start(*dynamic_cast(_rcb_enabled._button), true, true); + _rcb_visible.init ( _("_Visible"), _("Determines whether the grid is displayed or not. Objects are still snapped to invisible grids."), - "visible", _wr, false, repr, doc); + "visible", _wr, true, repr, doc); vbox.pack_start(*dynamic_cast(_rcb_visible._button), true, true); - - _rcb_snap_enabled.init ( _("_Snapping enabled"), - _("Determines whether to snap to this grid or not. Can be 'on' for invisible grids."), - "snap_enabled", _wr, false, repr, doc); - vbox.pack_start(*dynamic_cast(_rcb_snap_enabled._button), true, true); } CanvasGrid::~CanvasGrid() @@ -334,7 +334,7 @@ CanvasGrid::on_repr_attr_changed(Inkscape::XML::Node *repr, gchar const *key, gc ((CanvasGrid*) data)->onReprAttrChanged(repr, key, oldval, newval, is_interactive); } -bool CanvasGrid::isSnapEnabled() +bool CanvasGrid::isEnabled() { if (snapper == NULL) { return false; @@ -657,7 +657,7 @@ CanvasXYGrid::readRepr() visible = (strcmp(value,"true") == 0); } - if ( (value = repr->attribute("snap_enabled")) ) { + if ( (value = repr->attribute("enabled")) ) { g_assert(snapper != NULL); snapper->setEnabled(strcmp(value,"true") == 0); } @@ -703,7 +703,7 @@ CanvasXYGrid::updateWidgets() _rcb_visible.setActive(visible); if (snapper != NULL) { - _rcb_snap_enabled.setActive(snapper->getEnabled()); + _rcb_enabled.setActive(snapper->getEnabled()); } _rumg.setUnit (gridunit); diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h index bc21a14aa..b8ed8174c 100644 --- a/src/display/canvas-grid.h +++ b/src/display/canvas-grid.h @@ -98,8 +98,8 @@ public: static void on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data); - bool isVisible() { return visible; }; - bool isSnapEnabled(); + bool isVisible() { return (isEnabled() &&visible); }; + bool isEnabled(); protected: CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument *in_doc, GridType type); @@ -114,7 +114,7 @@ protected: Inkscape::UI::Widget::Registry _wr; Inkscape::UI::Widget::RegisteredCheckButton _rcb_visible; bool visible; - Inkscape::UI::Widget::RegisteredCheckButton _rcb_snap_enabled; + Inkscape::UI::Widget::RegisteredCheckButton _rcb_enabled; GridType gridtype; diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 7705a21ec..fdbedab4e 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -950,6 +950,20 @@ SPMetric SPNamedView::getDefaultMetric() const } } +/** + * Returns the first grid it could find that isEnabled(). Returns NULL, if none is enabled + */ +Inkscape::CanvasGrid * sp_namedview_get_first_enabled_grid(SPNamedView *namedview) +{ + for (GSList const * l = namedview->grids; l != NULL; l = l->next) { + Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data; + if (grid->isEnabled()) + return grid; + } + + return NULL; +} + /* Local Variables: diff --git a/src/sp-namedview.h b/src/sp-namedview.h index 3e1923f1d..f79a0fb42 100644 --- a/src/sp-namedview.h +++ b/src/sp-namedview.h @@ -102,6 +102,7 @@ void sp_namedview_update_layers_from_document (SPDesktop *desktop); void sp_namedview_toggle_guides(SPDocument *doc, Inkscape::XML::Node *repr); void sp_namedview_show_grids(SPNamedView *namedview, bool show, bool dirty_document); +Inkscape::CanvasGrid * sp_namedview_get_first_enabled_grid(SPNamedView *namedview); #endif /* !INKSCAPE_SP_NAMEDVIEW_H */ -- 2.30.2