Code

Filter effects dialog:
[inkscape.git] / src / seltrans.cpp
index 52afc0e1484a14e9fed0c49420d2ba459ffdb3da..1661bdc6009cbe9d8cbd06a24df27b241cfa8f91 100644 (file)
@@ -94,8 +94,8 @@ Inkscape::SelTrans::SelTrans(SPDesktop *desktop) :
     _stamp_cache(NULL),
     _message_context(desktop->messageStack())
 {
-    //_snap_bbox_type = SPItem::GEOMETRIC_BBOX; //TODO: Get this parameter from UI; hardcoded for the time being
-    _snap_bbox_type = SPItem::APPROXIMATE_BBOX;
+    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);
 
@@ -112,8 +112,6 @@ Inkscape::SelTrans::SelTrans(SPDesktop *desktop) :
     _updateHandles();
 
     _selection = sp_desktop_selection(desktop);
-    
-    
 
     _norm = sp_canvas_item_new(sp_desktop_controls(desktop),
                                SP_TYPE_CTRL,
@@ -264,7 +262,12 @@ void Inkscape::SelTrans::grab(NR::Point const &p, gdouble x, gdouble y, bool sho
     // The selector tool should snap the bbox and the special snappoints, but not path nodes
     // (The special points are the handles, center, rotation axis, font baseline, ends of spiral, etc.)
 
-    // First, get all special points for snapping
+    // First, determine the bounding box for snapping ...
+    _bbox = selection->bounds(_snap_bbox_type);    
+    _approximate_bbox = selection->bounds(SPItem::APPROXIMATE_BBOX); // Used for correctly scaling the strokewidth
+
+
+    // Next, get all special points for snapping
     _snap_points = selection->getSnapPoints(); // Excludes path nodes
     std::vector<NR::Point> snap_points_hull = selection->getSnapPointsConvexHull(); // Includes path nodes
     if (_snap_points.size() > 100) {
@@ -289,11 +292,6 @@ void Inkscape::SelTrans::grab(NR::Point const &p, gdouble x, gdouble y, bool sho
         }
     }
     
-    // Next, determine the bounding box for snapping ...
-    _bbox = selection->bounds(_snap_bbox_type);
-    
-    _approximate_bbox = selection->bounds(SPItem::APPROXIMATE_BBOX); // Used for correctly scaling the strokewidth
-    
     _bbox_points.clear();
     if (_bbox) {
         // ... and add the bbox corners to _bbox_points
@@ -312,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++)
     {
@@ -597,30 +597,10 @@ void Inkscape::SelTrans::_updateVolatileState()
         return;
     }
 
-    // First, get all special points for snapping
-    std::vector<NR::Point> snap_points_hull = selection->getSnapPointsConvexHull(); // Includes path nodes
-    // Find bbox hulling all special points, which excludes stroke width. Here we need to include the
-    // path nodes, for example because a rectangle which has been converted to a path doesn't have 
-    // any other special points
-    NR::Rect snap_points_bbox;
-    if ( snap_points_hull.empty() == false ) {
-        std::vector<NR::Point>::iterator i = snap_points_hull.begin();
-        snap_points_bbox = NR::Rect(*i, *i);
-        i++;
-        while (i != snap_points_hull.end()) {
-            snap_points_bbox.expandTo(*i);
-            i++;
-        }
-    }
-    
-    // Next, determine the bounding box for snapping ...
+    //Update the bboxes
     _bbox = selection->bounds(_snap_bbox_type);
     _approximate_bbox = selection->bounds(SPItem::APPROXIMATE_BBOX);
     
-    /*std::cout << "Approximate BBox: " << _approximate_bbox->min() << " - " << _approximate_bbox->max() << std::endl;
-    std::cout << "Geometric BBox: " << selection->bounds(SPItem::GEOMETRIC_BBOX)->min() << " - " << selection->bounds(SPItem::GEOMETRIC_BBOX)->max() << std::endl;
-    */
-    
     if (!_bbox) {
         _empty = true;
         return;
@@ -785,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;
@@ -814,6 +790,11 @@ 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;
+        //SPItem::APPROXIMATE_BBOX will be replaced by SPItem::VISUAL_BBOX, as soon as the latter is implemented properly
+    
         _updateVolatileState();
         _current.set_identity();
         _center_is_set = false; // center(s) may have changed
@@ -896,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.
@@ -1024,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.
     */
@@ -1360,12 +1357,12 @@ void Inkscape::SelTrans::stretch(SPSelTransHandle const &handle, NR::Point &pt,
 
     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]);
 
@@ -1387,9 +1384,10 @@ void Inkscape::SelTrans::scale(NR::Point &pt, guint state)
         if (fabs(s[i]) < 1e-9)
             s[i] = 1e-9;
     }
+    
     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;