Code

move shape_editor from node context to the parent class, event context
[inkscape.git] / src / desktop.cpp
index 1ee24f9c6d35854c73c20714dd1e1450dbf52103..8b60291ef36c8c39df023a0bc1ee2037acaf3c78 100644 (file)
@@ -535,7 +535,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 +756,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;
@@ -883,9 +883,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,8 +936,8 @@ 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;
             } 
@@ -1038,8 +1037,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 +1068,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 +1096,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;
     }
 
@@ -1809,6 +1805,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 +1818,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();
 }