Code

Filter effects dialog:
[inkscape.git] / src / seltrans.cpp
index 3de87ae28e2d343dc7ba18ff0ca34f924fcc633d..1661bdc6009cbe9d8cbd06a24df27b241cfa8f91 100644 (file)
@@ -88,13 +88,14 @@ Inkscape::SelTrans::SelTrans(SPDesktop *desktop) :
     _show(SHOW_CONTENT),
     _grabbed(false),
     _show_handles(true),
-    _snap_bbox_type(SPItem::GEOMETRIC_BBOX),
     _bbox(NR::Nothing()),
     _approximate_bbox(NR::Nothing()),
     _chandle(NULL),
     _stamp_cache(NULL),
     _message_context(desktop->messageStack())
 {
+    gchar const *prefs_bbox = prefs_get_string_attribute("tools.select", "bounding_box");
+    _snap_bbox_type = (prefs_bbox != NULL && strcmp(prefs_bbox, "geometric")==0)? SPItem::GEOMETRIC_BBOX : SPItem::APPROXIMATE_BBOX;
     
     g_return_if_fail(desktop != NULL);
 
@@ -309,6 +310,8 @@ void Inkscape::SelTrans::grab(NR::Point const &p, gdouble x, gdouble y, bool sho
         _opposite = _opposite_for_bboxpoints;
     }
     
+    // The lines below are usefull for debugging any snapping issues, as they'll spit out all points that are considered for snapping
+    
     /*std::cout << "Number of snap points:  " << _snap_points.size() << std::endl;
     for (std::vector<NR::Point>::const_iterator i = _snap_points.begin(); i != _snap_points.end(); i++)
     {
@@ -762,10 +765,6 @@ gboolean Inkscape::SelTrans::handleRequest(SPKnot *knot, NR::Point *position, gu
 
     knot->desktop->setPosition(*position);
 
-    if (state & GDK_MOD1_MASK) {
-        *position = _point + ( *position - _point ) / 10;
-    }
-
     if ((!(state & GDK_SHIFT_MASK) == !(_state == STATE_ROTATE)) && (&handle != &handle_center)) {
         _origin = _opposite;
         _origin_for_bboxpoints = _opposite_for_bboxpoints;
@@ -791,8 +790,9 @@ gboolean Inkscape::SelTrans::handleRequest(SPKnot *knot, NR::Point *position, gu
 void Inkscape::SelTrans::_selChanged(Inkscape::Selection *selection)
 {
     if (!_grabbed) {
+        // reread in case it changed on the fly:
         gchar const *prefs_bbox = prefs_get_string_attribute("tools.select", "bounding_box");
-        _snap_bbox_type = (prefs_bbox == NULL || strcmp(prefs_bbox, "geometric")==0)? SPItem::GEOMETRIC_BBOX : SPItem::APPROXIMATE_BBOX;
+        _snap_bbox_type = (prefs_bbox != NULL && strcmp(prefs_bbox, "geometric")==0)? SPItem::GEOMETRIC_BBOX : SPItem::APPROXIMATE_BBOX;
         //SPItem::APPROXIMATE_BBOX will be replaced by SPItem::VISUAL_BBOX, as soon as the latter is implemented properly
     
         _updateVolatileState();
@@ -877,6 +877,15 @@ gboolean Inkscape::SelTrans::scaleRequest(NR::Point &pt, guint state)
         }
     }
 
+    if (state & GDK_MOD1_MASK) { // scale by an integer multiplier/divider
+        for ( unsigned int i = 0 ; i < 2 ; i++ ) {
+            if (fabs(s[i]) > 1) 
+                s[i] = round(s[i]);
+            else 
+                s[i] = 1/round(1/(MIN(s[i], 10)));
+        }
+    }
+
     SnapManager const &m = _desktop->namedview->snap_manager;
 
     /* Get a STL list of the selected items.
@@ -1005,6 +1014,13 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR::
         s[axis] = 1e-15;
     }
 
+    if (state & GDK_MOD1_MASK) { // scale by an integer multiplier/divider
+        if (fabs(s[axis]) > 1) 
+            s[axis] = round(s[axis]);
+        else 
+            s[axis] = 1/round(1/(MIN(s[axis], 10)));
+    }
+
     /* Get a STL list of the selected items.
     ** FIXME: this should probably be done by Inkscape::Selection.
     */
@@ -1336,22 +1352,17 @@ void Inkscape::SelTrans::stretch(SPSelTransHandle const &handle, NR::Point &pt,
         return;
     }
 
-    //Get two corners of the new bbox
-    NR::Point p1 = _approximate_bbox->min() * (NR::translate(-scale_origin) * NR::Matrix(s) * NR::translate(scale_origin));
-    NR::Point p2 = _approximate_bbox->max() * (NR::translate(-scale_origin) * NR::Matrix(s) * NR::translate(scale_origin));
-
-    //Find the ones at the lower-left and upper-right, as required by get_scale_transform_with_stroke
-    NR::Point new_bbox_min = NR::Point(std::min(p1[NR::X], p2[NR::X]), std::min(p1[NR::Y], p2[NR::Y]));
-    NR::Point new_bbox_max = NR::Point(std::max(p1[NR::X], p2[NR::X]), std::max(p1[NR::Y], p2[NR::Y]));
+    NR::Point new_bbox_min = _approximate_bbox->min() * (NR::translate(-scale_origin) * NR::Matrix(s) * NR::translate(scale_origin));
+    NR::Point new_bbox_max = _approximate_bbox->max() * (NR::translate(-scale_origin) * NR::Matrix(s) * NR::translate(scale_origin));
 
     int transform_stroke = false;
     gdouble strokewidth = 0;
-        
+
     if ( _snap_bbox_type != SPItem::GEOMETRIC_BBOX) {
         transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
         strokewidth = _strokewidth;
     }
-        
+
     NR::Matrix scaler = get_scale_transform_with_stroke (*_approximate_bbox, strokewidth, transform_stroke,
                     new_bbox_min[NR::X], new_bbox_min[NR::Y], new_bbox_max[NR::X], new_bbox_max[NR::Y]);
 
@@ -1374,13 +1385,8 @@ void Inkscape::SelTrans::scale(NR::Point &pt, guint state)
             s[i] = 1e-9;
     }
     
-    //Get two corners of the new bbox
-    NR::Point p1 = _approximate_bbox->min() * (NR::translate(-_origin) * NR::Matrix(s) * NR::translate(_origin));
-    NR::Point p2 = _approximate_bbox->max() * (NR::translate(-_origin) * NR::Matrix(s) * NR::translate(_origin));
-
-    //Find the ones at the lower-left and upper-right, as required by get_scale_transform_with_stroke
-    NR::Point new_bbox_min = NR::Point(std::min(p1[NR::X], p2[NR::X]), std::min(p1[NR::Y], p2[NR::Y]));
-    NR::Point new_bbox_max = NR::Point(std::max(p1[NR::X], p2[NR::X]), std::max(p1[NR::Y], p2[NR::Y]));
+    NR::Point new_bbox_min = _approximate_bbox->min() * (NR::translate(-_origin) * NR::Matrix(s) * NR::translate(_origin));
+    NR::Point new_bbox_max = _approximate_bbox->max() * (NR::translate(-_origin) * NR::Matrix(s) * NR::translate(_origin));
     
     int transform_stroke = false;
     gdouble strokewidth = 0;