Code

fix crash, allow combine to work transparently on groups
[inkscape.git] / src / selcue.cpp
index 6d365659206749a1101673d513b85ae1bad81f81..67c9712d1f14b2a73b6f34417bb642ce1357022b 100644 (file)
@@ -12,6 +12,8 @@
  * Released under GNU GPL, read the file 'COPYING' for more information
  */
 
+#include <string.h>
+
 #include "desktop-handles.h"
 #include "selection.h"
 #include "display/sp-canvas-util.h"
@@ -21,7 +23,7 @@
 #include "text-editing.h"
 #include "sp-text.h"
 #include "sp-flowtext.h"
-#include "prefs-utils.h"
+#include "preferences.h"
 #include "selcue.h"
 
 Inkscape::SelCue::SelCue(SPDesktop *desktop)
@@ -68,48 +70,53 @@ void Inkscape::SelCue::_updateItemBboxes()
     }
     _text_baselines.clear();
 
-    gint mode = prefs_get_int_attribute ("options.selcue", "value", MARK);
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    gint mode = prefs->getInt("/options/selcue/value", MARK);
     if (mode == NONE) {
         return;
     }
 
     g_return_if_fail(_selection != NULL);
 
+    int prefs_bbox = prefs->getBool("/tools/bounding_box");
+    SPItem::BBoxType bbox_type = !prefs_bbox ? 
+        SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX;
+    
     for (GSList const *l = _selection->itemList(); l != NULL; l = l->next) {
         SPItem *item = (SPItem *) l->data;
 
-        NR::Rect const b = sp_item_bbox_desktop(item);
+        Geom::OptRect const b = sp_item_bbox_desktop(item, bbox_type);
 
         SPCanvasItem* box = NULL;
 
-        if (mode == MARK) {
-            box = sp_canvas_item_new(sp_desktop_controls(_desktop),
-                                      SP_TYPE_CTRL,
-                                      "mode", SP_CTRL_MODE_XOR,
-                                      "shape", SP_CTRL_SHAPE_DIAMOND,
-                                      "size", 5.0,
-                                      "filled", TRUE,
-                                      "fill_color", 0x000000ff,
-                                      "stroked", FALSE,
-                                      "stroke_color", 0x000000ff,
-                                      NULL);
-            sp_canvas_item_show(box);
-            SP_CTRL(box)->moveto(NR::Point(b.min()[NR::X], b.max()[NR::Y]));
-
-            sp_canvas_item_move_to_z(box, 0); // just low enough to not get in the way of other draggable knots
-
-        } else if (mode == BBOX) {
-            box = sp_canvas_item_new(
-                sp_desktop_controls(_desktop),
-                SP_TYPE_CTRLRECT,
-                NULL
-                );
-
-            SP_CTRLRECT(box)->setRectangle(b);
-            SP_CTRLRECT(box)->setColor(0x000000a0, 0, 0);
-            SP_CTRLRECT(box)->setDashed(true);
-
-            sp_canvas_item_move_to_z(box, 0);
+        if (b) {
+            if (mode == MARK) {
+                box = sp_canvas_item_new(sp_desktop_controls(_desktop),
+                                         SP_TYPE_CTRL,
+                                         "mode", SP_CTRL_MODE_XOR,
+                                         "shape", SP_CTRL_SHAPE_DIAMOND,
+                                         "size", 5.0,
+                                         "filled", TRUE,
+                                         "fill_color", 0x000000ff,
+                                         "stroked", FALSE,
+                                         "stroke_color", 0x000000ff,
+                                         NULL);
+                sp_canvas_item_show(box);
+                SP_CTRL(box)->moveto(Geom::Point(b->min()[Geom::X], b->max()[Geom::Y]));
+
+                sp_canvas_item_move_to_z(box, 0); // just low enough to not get in the way of other draggable knots
+
+            } else if (mode == BBOX) {
+                box = sp_canvas_item_new(sp_desktop_controls(_desktop),
+                                         SP_TYPE_CTRLRECT,
+                                         NULL);
+
+                SP_CTRLRECT(box)->setRectangle(*b);
+                SP_CTRLRECT(box)->setColor(0x000000a0, 0, 0);
+                SP_CTRLRECT(box)->setDashed(true);
+
+                sp_canvas_item_move_to_z(box, 0);
+            }
         }
 
         if (box) {
@@ -120,7 +127,7 @@ void Inkscape::SelCue::_updateItemBboxes()
         if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { // visualize baseline
             Inkscape::Text::Layout const *layout = te_get_layout(item);
             if (layout != NULL) {
-                NR::Point a = layout->characterAnchorPoint(layout->begin()) * sp_item_i2d_affine(item);
+                Geom::Point a = layout->characterAnchorPoint(layout->begin()) * sp_item_i2d_affine(item);
                 baseline_point = sp_canvas_item_new(sp_desktop_controls(_desktop), SP_TYPE_CTRL,
                                                     "mode", SP_CTRL_MODE_XOR,
                                                     "size", 4.0,