Code

more unreffing temporary styles properly
[inkscape.git] / src / object-edit.cpp
index 5ca3469771ae463c2eeab558fe90a97bbda7f13d..91257e7ba0c8c12029882479a885f1ed487d2e39 100644 (file)
@@ -14,8 +14,6 @@
 # include "config.h"
 #endif
 
-
-
 #include "sp-item.h"
 #include "sp-rect.h"
 #include "sp-ellipse.h"
@@ -25,7 +23,6 @@
 #include "sp-flowtext.h"
 #include "prefs-utils.h"
 #include "inkscape.h"
-#include "snap.h"
 #include "desktop-affine.h"
 #include <style.h>
 #include "desktop.h"
@@ -211,8 +208,6 @@ static NR::Point sp_pattern_scale_get(SPItem *item)
     return delta;
 }
 
-/* SPRect */
-
 static NR::Point sp_rect_rx_get(SPItem *item)
 {
     SPRect *rect = SP_RECT(item);
@@ -223,7 +218,7 @@ static NR::Point sp_rect_rx_get(SPItem *item)
 static void sp_rect_rx_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
 {
     SPRect *rect = SP_RECT(item);
-
+    
     if (state & GDK_CONTROL_MASK) {
         gdouble temp = MIN(rect->height.computed, rect->width.computed) / 2.0;
         rect->rx.computed = rect->ry.computed = CLAMP(rect->x.computed + rect->width.computed - p[NR::X], 0.0, temp);
@@ -248,7 +243,7 @@ static NR::Point sp_rect_ry_get(SPItem *item)
 static void sp_rect_ry_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
 {
     SPRect *rect = SP_RECT(item);
-
+    
     if (state & GDK_CONTROL_MASK) {
         gdouble temp = MIN(rect->height.computed, rect->width.computed) / 2.0;
         rect->rx.computed = rect->ry.computed = CLAMP(p[NR::Y] - rect->y.computed, 0.0, temp);
@@ -331,19 +326,8 @@ static NR::Point sp_rect_wh_get(SPItem *item)
     return NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed);
 }
 
-static NR::Point rect_snap_knot_position(SPRect *rect, NR::Point const &p)
-{
-    SPDesktop const *desktop = inkscape_active_desktop();
-    NR::Point s = sp_desktop_dt2root_xy_point(desktop, p);
-    SnapManager const &m = desktop->namedview->snap_manager;
-    s = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, s, rect).getPoint();
-    return sp_desktop_root2dt_xy_point(desktop, s);
-}
-
 static void sp_rect_wh_set_internal(SPRect *rect, NR::Point const &p, NR::Point const &origin, guint state)
 {
-    NR::Point const s = rect_snap_knot_position(rect, p);
-
     if (state & GDK_CONTROL_MASK) {
         // original width/height when drag started
         gdouble const w_orig = (origin[NR::X] - rect->x.computed);
@@ -353,8 +337,8 @@ static void sp_rect_wh_set_internal(SPRect *rect, NR::Point const &p, NR::Point
         gdouble const ratio = (w_orig / h_orig);
 
         // mouse displacement since drag started
-        gdouble const minx = s[NR::X] - origin[NR::X];
-        gdouble const miny = s[NR::Y] - origin[NR::Y];
+        gdouble const minx = p[NR::X] - origin[NR::X];
+        gdouble const miny = p[NR::Y] - origin[NR::Y];
 
         if (fabs(minx) > fabs(miny)) {
 
@@ -384,8 +368,8 @@ static void sp_rect_wh_set_internal(SPRect *rect, NR::Point const &p, NR::Point
 
     } else {
         // move freely
-        rect->width.computed = MAX(s[NR::X] - rect->x.computed, 0);
-        rect->height.computed = MAX(s[NR::Y] - rect->y.computed, 0);
+        rect->width.computed = MAX(p[NR::X] - rect->x.computed, 0);
+        rect->height.computed = MAX(p[NR::Y] - rect->y.computed, 0);
         rect->width._set = rect->height._set = true;
     }
 
@@ -420,11 +404,9 @@ static void sp_rect_xy_set(SPItem *item, NR::Point const &p, NR::Point const &or
     gdouble w_orig = opposite_x - origin[NR::X];
     gdouble h_orig = opposite_y - origin[NR::Y];
 
-    NR::Point const s = rect_snap_knot_position(rect, p);
-
     // mouse displacement since drag started
-    gdouble minx = s[NR::X] - origin[NR::X];
-    gdouble miny = s[NR::Y] - origin[NR::Y];
+    gdouble minx = p[NR::X] - origin[NR::X];
+    gdouble miny = p[NR::Y] - origin[NR::Y];
 
     if (state & GDK_CONTROL_MASK) {
         //original ratio
@@ -433,7 +415,7 @@ static void sp_rect_xy_set(SPItem *item, NR::Point const &p, NR::Point const &or
         if (fabs(minx) > fabs(miny)) {
 
             // snap to horizontal or diagonal
-            rect->x.computed = MIN(s[NR::X], opposite_x);
+            rect->x.computed = MIN(p[NR::X], opposite_x);
             rect->width.computed = MAX(w_orig - minx, 0);
             if (minx != 0 && fabs(miny/minx) > 0.5 * 1/ratio && (SGN(minx) == SGN(miny))) {
                 // closer to the diagonal and in same-sign quarters, change both using ratio
@@ -448,7 +430,7 @@ static void sp_rect_xy_set(SPItem *item, NR::Point const &p, NR::Point const &or
         } else {
 
             // snap to vertical or diagonal
-            rect->y.computed = MIN(s[NR::Y], opposite_y);
+            rect->y.computed = MIN(p[NR::Y], opposite_y);
             rect->height.computed = MAX(h_orig - miny, 0);
             if (miny != 0 && fabs(minx/miny) > 0.5 *ratio && (SGN(minx) == SGN(miny))) {
                 // closer to the diagonal and in same-sign quarters, change both using ratio
@@ -466,13 +448,13 @@ static void sp_rect_xy_set(SPItem *item, NR::Point const &p, NR::Point const &or
 
     } else {
         // move freely
-        rect->x.computed = MIN(s[NR::X], opposite_x);
+        rect->x.computed = MIN(p[NR::X], opposite_x);
         rect->width.computed = MAX(w_orig - minx, 0);
-        rect->y.computed = MIN(s[NR::Y], opposite_y);
+        rect->y.computed = MIN(p[NR::Y], opposite_y);
         rect->height.computed = MAX(h_orig - miny, 0);
         rect->width._set = rect->height._set = rect->x._set = rect->y._set = true;
     }
-
+    
     sp_rect_clamp_radii(rect);
 
     ((SPObject *)rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
@@ -509,6 +491,8 @@ static SPKnotHolder *sp_rect_knot_holder(SPItem *item, SPDesktop *desktop)
         "or stretch in one dimension only")
       );
 
+    SPRect *rect = SP_RECT(item);
+    
     sp_pat_knot_holder(item, knot_holder);
     return knot_holder;
 }
@@ -610,7 +594,7 @@ sp_arc_rx_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint s
 {
     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
     SPArc *arc = SP_ARC(item);
-
+    
     ge->rx.computed = fabs( ge->cx.computed - p[NR::X] );
 
     if ( state & GDK_CONTROL_MASK ) {
@@ -632,7 +616,7 @@ sp_arc_ry_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint s
 {
     SPGenericEllipse *ge = SP_GENERICELLIPSE(item);
     SPArc *arc = SP_ARC(item);
-
+    
     ge->ry.computed = fabs( ge->cy.computed - p[NR::Y] );
 
     if ( state & GDK_CONTROL_MASK ) {
@@ -700,7 +684,7 @@ static void
 sp_star_knot1_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
 {
     SPStar *star = SP_STAR(item);
-
+    
     NR::Point d = p - star->center;
 
     double arg1 = atan2(d);
@@ -724,6 +708,7 @@ static void
 sp_star_knot2_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state)
 {
     SPStar *star = SP_STAR(item);
+    
     if (star->flatsided == false) {
         NR::Point d = p - star->center;