Code

dropper modes: replace undecipherable icons with text labels
[inkscape.git] / src / desktop.cpp
index d2547f5a60895fce146a486dcc1a286285d646d0..f9d17b01ad6bbc5e938c8c9c5df0e2b8007427ab 100644 (file)
@@ -12,7 +12,7 @@
  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
  *
  * Copyright (C) 2007 Jon A. Cruz
- * Copyright (C) 2006-2007 Johan Engelen
+ * Copyright (C) 2006-2008 Johan Engelen
  * Copyright (C) 2006 John Bintz
  * Copyright (C) 2004 MenTaLguY
  * Copyright (C) 1999-2002 Lauris Kaplinski
@@ -77,6 +77,8 @@
 #include "display/gnome-canvas-acetate.h"
 #include "display/sodipodi-ctrlrect.h"
 #include "display/sp-canvas-util.h"
+#include "display/canvas-temporary-item-list.h"
+#include "display/snap-indicator.h"
 #include "libnr/nr-matrix-div.h"
 #include "libnr/nr-rect-ops.h"
 #include "ui/dialog/dialog-manager.h"
@@ -86,6 +88,7 @@
 #include "event-log.h"
 #include "display/canvas-grid.h"
 #include "widgets/desktop-widget.h"
+#include "box3d-context.h"
 
 #include "display/sp-canvas.h"
 
@@ -115,6 +118,8 @@ SPDesktop::SPDesktop() :
     event_context( 0 ),
     layer_manager( 0 ),
     event_log( 0 ),
+    temporary_item_list( 0 ),
+    snapindicator( 0 ),
     acetate( 0 ),
     main( 0 ),
     gridgroup( 0 ),
@@ -122,6 +127,7 @@ SPDesktop::SPDesktop() :
     drawing( 0 ),
     sketch( 0 ),
     controls( 0 ),
+    tempgroup ( 0 ),
     table( 0 ),
     page( 0 ),
     page_border( 0 ),
@@ -217,6 +223,7 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas)
     guides = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);
     sketch = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);
     controls = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);
+    tempgroup = (SPCanvasGroup *) sp_canvas_item_new (main, SP_TYPE_CANVAS_GROUP, NULL);
 
     /* Push select tool to the bottom of stack */
     /** \todo
@@ -310,11 +317,23 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas)
     layer_manager = new Inkscape::LayerManager( this );
 
     showGrids(namedview->grids_visible, false);
+
+    temporary_item_list = new Inkscape::Display::TemporaryItemList( this );
+    snapindicator = new Inkscape::Display::SnapIndicator ( this );
 }
 
 
 void SPDesktop::destroy()
 {
+    if (snapindicator) {
+        delete snapindicator;
+        snapindicator = NULL;
+    }
+    if (temporary_item_list) {
+        delete temporary_item_list;
+        temporary_item_list = NULL;
+    }
+
     namedview->hide(this);
 
     _activate_connection.disconnect();
@@ -368,6 +387,28 @@ SPDesktop::~SPDesktop() {}
 //--------------------------------------------------------------------
 /* Public methods */
 
+
+/** Note that lifetime is measured in milliseconds
+* it is perfectly safe to ignore the returned pointer: the object is deleted by itself, so don't delete it elsewhere!
+* The return value should only be used as argument for SPDesktop::remove_temporary_canvasitem, because the object might be deleted already.
+*/
+Inkscape::Display::TemporaryItem *
+SPDesktop::add_temporary_canvasitem (SPCanvasItem *item, guint lifetime)
+{
+    return temporary_item_list->add_item(item, lifetime);
+}
+
+/** It is perfectly safe to call this function while the object has already been deleted due to a timeout.
+*/
+void
+SPDesktop::remove_temporary_canvasitem (Inkscape::Display::TemporaryItem * tempitem)
+{
+    // check for non-null temporary_item_list, because during destruction of desktop, some destructor might try to access this list!
+    if (tempitem && temporary_item_list) {
+        temporary_item_list->delete_item(tempitem);
+    }
+}
+
 void SPDesktop::setDisplayModeNormal()
 {
     SP_CANVAS_ARENA (drawing)->arena->rendermode = RENDERMODE_NORMAL;
@@ -701,6 +742,9 @@ SPDesktop::set_display_area (double x0, double y0, double x1, double y1, double
     /* Scroll */
     sp_canvas_scroll_to (canvas, x0 * newscale - border, y1 * -newscale - border, clear);
 
+    /*  update perspective lines if we are in the 3D box tool (so that infinite ones are shown correctly) */
+    sp_box3d_context_update_lines(event_context);
+
     _widget->updateRulers();
     _widget->updateScrollbars(expansion(_d2w));
     _widget->updateZoom();
@@ -939,6 +983,9 @@ SPDesktop::scroll_world (double dx, double dy, bool is_scrolling)
 
     sp_canvas_scroll_to(canvas, viewbox.min()[NR::X] - dx, viewbox.min()[NR::Y] - dy, FALSE, is_scrolling);
 
+    /*  update perspective lines if we are in the 3D box tool (so that infinite ones are shown correctly) */
+    sp_box3d_context_update_lines(event_context);
+
     _widget->updateRulers();
     _widget->updateScrollbars(expansion(_d2w));
 }