Code

angled guidelines: create angled line when dragging from edge of rulers
authorjohanengelen <johanengelen@users.sourceforge.net>
Mon, 24 Dec 2007 00:48:00 +0000 (00:48 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Mon, 24 Dec 2007 00:48:00 +0000 (00:48 +0000)
src/desktop-events.cpp
src/display/canvas-axonomgrid.cpp
src/display/canvas-grid.cpp
src/display/canvas-grid.h
src/sp-namedview.cpp
src/sp-namedview.h

index 24d94b5a32ee61eb7c47a546669d2b388d4386fc..d5158255abe473f0f700032445257229a59c8b2c 100644 (file)
@@ -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<Inkscape::CanvasAxonomGrid *>(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.);
                     }
index bb992368051119f485180787b7b987042ef48b41..3d9375d2d1f0001538d57cc9c89c119e218341a1 100644 (file)
@@ -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);
index 021a62f96e8212e15dce9ef7fc5c1def64263f1b..8d7bdd0e8228a72b089da24158e269b90e88d669 100644 (file)
@@ -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<Gtk::Widget*>(_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<Gtk::Widget*>(_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<Gtk::Widget*>(_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);
index bc21a14aa9a3e233a0fd9fa45b07661f82dc3253..b8ed8174c617d22200b416c6e563f36353a7609a 100644 (file)
@@ -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;
 
index 7705a21ec9b3098bb4bd14d5d955eecfbfeee99d..fdbedab4e5b3a9ab766e81be660410151a26618c 100644 (file)
@@ -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:
index 3e1923f1dc26f33a71f6b887a972b21514de68bb..f79a0fb429ac0de0be08432a9409f5e20cd2d18f 100644 (file)
@@ -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 */