Code

now that selection description includes style (filtered, clipped), we need to update...
[inkscape.git] / src / desktop.cpp
index 1ee24f9c6d35854c73c20714dd1e1450dbf52103..1f2baccbba2ed61559eb7d0ef70362dd9832accf 100644 (file)
@@ -104,7 +104,6 @@ static void _layer_hierarchy_changed(SPObject *top, SPObject *bottom, SPDesktop
 static void _reconstruction_start(SPDesktop * desktop);
 static void _reconstruction_finish(SPDesktop * desktop);
 static void _namedview_modified (SPObject *obj, guint flags, SPDesktop *desktop);
-static void _update_snap_distances (SPDesktop *desktop);
 
 /**
  * Return new desktop object.
@@ -535,7 +534,7 @@ bool SPDesktop::isLayer(SPObject *object) const {
 bool SPDesktop::isWithinViewport (SPItem *item) const
 {
     Geom::Rect const viewport = get_display_area();
-    boost::optional<Geom::Rect> const bbox = sp_item_bbox_desktop(item);
+    Geom::OptRect const bbox = sp_item_bbox_desktop(item);
     if (bbox) {
         return viewport.contains(*bbox);
     } else {
@@ -756,7 +755,7 @@ SPDesktop::set_display_area (double x0, double y0, double x1, double y1, double
 
     // FIXME: This 2geom idiom doesn't allow us to declare dbox const
     Geom::Rect viewbox = canvas->getViewbox();
-    viewbox.expandBy(border);
+    viewbox.expandBy(-border);
 
     double scale = _d2w.descrim();
     double newscale;
@@ -869,7 +868,7 @@ SPDesktop::next_zoom()
     \param  enable  Whether we're going in or out of quick zoom
 
 */
-void 
+void
 SPDesktop::zoom_quick (bool enable)
 {
     if (enable == _quick_zoom_enabled) {
@@ -883,9 +882,8 @@ SPDesktop::zoom_quick (bool enable)
         if (!zoomed) {
             SPItem * singleItem = selection->singleItem();
             if (singleItem != NULL && tools_isactive(this, TOOLS_NODES)) {
-                SPNodeContext * ncontext = SP_NODE_CONTEXT(event_context);
 
-                Inkscape::NodePath::Path * nodepath = ncontext->shape_editor->get_nodepath();
+                Inkscape::NodePath::Path * nodepath = event_context->shape_editor->get_nodepath();
                 // printf("I've got a nodepath, crazy\n");
 
                 Geom::Rect nodes;
@@ -937,11 +935,11 @@ SPDesktop::zoom_quick (bool enable)
         }
 
         if (!zoomed) {
-            boost::optional<Geom::Rect> const d = selection->bounds();
-            if (d && !d->isEmpty() && d->area() * 2.0 < _quick_zoom_stored_area.area()) {
+            Geom::OptRect const d = selection->bounds();
+            if (d && d->area() * 2.0 < _quick_zoom_stored_area.area()) {
                 set_display_area(*d, 10);
                 zoomed = true;
-            } 
+            }
         }
 
         if (!zoomed) {
@@ -1038,8 +1036,7 @@ SPDesktop::zoom_page()
     Geom::Rect d(Geom::Point(0, 0),
                  Geom::Point(sp_document_width(doc()), sp_document_height(doc())));
 
-    // FIXME: the original NR::Rect::isEmpty call contained an additional threshold of 1.0; is it safe to ignore it?
-    if (d.isEmpty()) {
+    if (d.minExtent() < 1.0) {
         return;
     }
 
@@ -1070,10 +1067,9 @@ SPDesktop::zoom_page_width()
 void
 SPDesktop::zoom_selection()
 {
-    boost::optional<Geom::Rect> const d = selection->bounds();
+    Geom::OptRect const d = selection->bounds();
 
-    // FIXME: the original NR::Rect::isEmpty call contained an additional threshold of 0.1; is it safe to ignore it?
-    if ( !d || d->isEmpty() ) {
+    if ( !d || d->minExtent() < 0.1 ) {
         return;
     }
 
@@ -1099,13 +1095,12 @@ SPDesktop::zoom_drawing()
     SPItem *docitem = SP_ITEM (sp_document_root (doc()));
     g_return_if_fail (docitem != NULL);
 
-    boost::optional<Geom::Rect> d = sp_item_bbox_desktop(docitem);
+    Geom::OptRect d = sp_item_bbox_desktop(docitem);
 
     /* Note that the second condition here indicates that
     ** there are no items in the drawing.
     */
-    // FIXME: the original NR::Rect::isEmpty call contained an additional threshold of 1.0; is it safe to ignore it?
-    if ( !d || d->isEmpty() ) {
+    if ( !d || d->minExtent() < 0.1 ) {
         return;
     }
 
@@ -1329,7 +1324,7 @@ SPDesktop::shutdown()
 
 bool SPDesktop::onDeleteUI (GdkEventAny*)
 {
-    if(shutdown()) 
+    if(shutdown())
         return true;
 
     destroyWidget();
@@ -1452,7 +1447,7 @@ void SPDesktop::showGrids(bool show, bool dirty_document)
     }
 }
 
-void SPDesktop::toggleSnapping()
+void SPDesktop::toggleSnapGlobal()
 {
     bool v = namedview->snap_manager.snapprefs.getSnapEnabledGlobally();
     Inkscape::XML::Node *repr = SP_OBJECT_REPR(namedview);
@@ -1702,12 +1697,6 @@ _namedview_modified (SPObject *obj, guint flags, SPDesktop *desktop)
 
     if (flags & SP_OBJECT_MODIFIED_FLAG) {
 
-        /* Recalculate snap distances */
-        /* FIXME: why is the desktop getting involved in setting up something
-        ** that is entirely to do with the namedview?
-        */
-        _update_snap_distances (desktop);
-
         /* Show/hide page background */
         if (nv->pagecolor & 0xff) {
             sp_canvas_item_show (desktop->table);
@@ -1762,33 +1751,6 @@ _namedview_modified (SPObject *obj, guint flags, SPDesktop *desktop)
     }
 }
 
-/**
- * Callback to reset snapper's distances.
- */
-static void
-_update_snap_distances (SPDesktop *desktop)
-{
-    SPUnit const &px = sp_unit_get_by_id(SP_UNIT_PX);
-
-    SPNamedView &nv = *desktop->namedview;
-
-    //tell all grid snappers
-    for ( GSList const *l = nv.grids; l != NULL; l = l->next) {
-        Inkscape::CanvasGrid *grid = (Inkscape::CanvasGrid*) l->data;
-        grid->snapper->setSnapperTolerance(sp_convert_distance_full(nv.gridtolerance,
-                                                                      *nv.gridtoleranceunit,
-                                                                      px));
-    }
-
-    nv.snap_manager.guide.setSnapperTolerance(sp_convert_distance_full(nv.guidetolerance,
-                                                                       *nv.guidetoleranceunit,
-                                                                       px));
-    nv.snap_manager.object.setSnapperTolerance(sp_convert_distance_full(nv.objecttolerance,
-                                                                        *nv.objecttoleranceunit,
-                                                                        px));
-}
-
-
 Geom::Matrix SPDesktop::w2d() const
 {
     return _w2d;
@@ -1809,6 +1771,12 @@ Geom::Matrix SPDesktop::doc2dt() const
     return _doc2dt;
 }
 
+Geom::Matrix SPDesktop::dt2doc() const
+{
+    // doc2dt is its own inverse
+    return _doc2dt;
+}
+
 Geom::Point SPDesktop::doc2dt(Geom::Point const &p) const
 {
     return p * _doc2dt;
@@ -1816,7 +1784,7 @@ Geom::Point SPDesktop::doc2dt(Geom::Point const &p) const
 
 Geom::Point SPDesktop::dt2doc(Geom::Point const &p) const
 {
-    return p * _doc2dt.inverse();
+    return p * dt2doc();
 }