]> git.tokkee.org Git - inkscape.git/commitdiff

Code

add snapindicator to rect tool but not satisfactory yet...
authorjohanengelen <johanengelen@users.sourceforge.net>
Tue, 4 Mar 2008 21:33:35 +0000 (21:33 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Tue, 4 Mar 2008 21:33:35 +0000 (21:33 +0000)
src/context-fns.cpp
src/rect-context.cpp

index c845fd275bdc19b34e600231ebe91906ccf2ac83..32c7eef000cf194356f6e57000f6b8fc58c48235 100644 (file)
@@ -12,6 +12,7 @@
 #include "desktop-affine.h"
 #include "event-context.h"
 #include "sp-namedview.h"
+#include "display/snap-indicator.h"
 
 static const double midpt_1_goldenratio = (1 + goldenratio) / 2;
 static const double midpt_goldenratio_2 = (goldenratio + 2) / 2;
@@ -85,6 +86,7 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item,
     bool const control = state & GDK_CONTROL_MASK;
 
     SnapManager const &m = desktop->namedview->snap_manager;
+    Inkscape::SnappedPoint snappoint;
 
     if (control) {
 
@@ -140,17 +142,20 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item,
             if (s[0].getDistance() < s[1].getDistance()) {
                 p[0] = s[0].getPoint();
                 p[1] = 2 * center - s[0].getPoint();
+                snappoint = s[0];
             } else {
                 p[0] = 2 * center - s[1].getPoint();
                 p[1] = s[1].getPoint();
+                snappoint = s[1];
             }
 
         } else {
 
             /* Our origin is the opposite corner.  Snap the drag point along the constraint vector */
             p[0] = center;
-            p[1] = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, p[1],
-                                     Inkscape::Snapper::ConstraintLine(p[1] - p[0]), item).getPoint();
+            snappoint = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, p[1],
+                                          Inkscape::Snapper::ConstraintLine(p[1] - p[0]), item);
+            p[1] = snappoint.getPoint();
         }
 
     } else if (shift) {
@@ -170,16 +175,24 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item,
         if (s[0].getDistance() < s[1].getDistance()) {
             p[0] = s[0].getPoint();
             p[1] = 2 * center - s[0].getPoint();
+            snappoint = s[0];
         } else {
             p[0] = 2 * center - s[1].getPoint();
             p[1] = s[1].getPoint();
+            snappoint = s[1];
         }
 
     } else {
 
         /* There's no constraint on the corner point, so just snap it to anything */
         p[0] = center;
-        p[1] = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, pt, item).getPoint();
+        snappoint = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, pt, item);
+        p[1] = snappoint.getPoint();
+    }
+
+    if (snappoint.getDistance() < NR_HUGE) {
+    // this does not work well enough yet.
+//        desktop->snapindicator->set_new_snappoint(snappoint.getPoint().to_2geom());
     }
 
     p[0] = sp_desktop_dt2root_xy_point(desktop, p[0]);
index 6aa7d418c85499652b422e08431e9acd0ee05c0a..70d7b7721aff64baecde4972ce3fffd463e844de 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "macros.h"
 #include "display/sp-canvas.h"
+#include "display/snap-indicator.h"
 #include "sp-rect.h"
 #include "document.h"
 #include "sp-namedview.h"
@@ -283,6 +284,8 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent
 
     event_context->tolerance = prefs_get_int_attribute_limited("options.dragtolerance", "value", 0, 0, 100);
 
+    desktop->snapindicator->remove_snappoint();
+
     gint ret = FALSE;
     switch (event->type) {
     case GDK_BUTTON_PRESS:
@@ -305,8 +308,11 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent
 
             /* Snap center */
             SnapManager const &m = desktop->namedview->snap_manager;
-            rc->center = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE,
-                                    button_dt, rc->item).getPoint();
+            Inkscape::SnappedPoint s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, button_dt, rc->item);
+            rc->center = s.getPoint();
+            if (s.getDistance() < NR_HUGE) {
+                desktop->snapindicator->set_new_snappoint(s.getPoint().to_2geom());
+            }
 
             sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
                                 ( GDK_KEY_PRESS_MASK |
@@ -336,8 +342,12 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent
             NR::Point motion_dt(desktop->w2d(motion_w));
             
             SnapManager const &m = desktop->namedview->snap_manager;
-            motion_dt = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt, rc->item).getPoint();
-            
+            Inkscape::SnappedPoint s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, motion_dt, rc->item);
+            motion_dt = s.getPoint();
+            if (s.getDistance() < NR_HUGE) {
+                desktop->snapindicator->set_new_snappoint(s.getPoint().to_2geom());
+            }
+
             sp_rect_drag(*rc, motion_dt, event->motion.state);
             gobble_motion_events(GDK_BUTTON1_MASK);
             ret = TRUE;