]> git.tokkee.org Git - inkscape.git/commitdiff

Code

remove flashing test indicator on pointparam.
authorjohanengelen <johanengelen@users.sourceforge.net>
Sun, 2 Mar 2008 22:01:12 +0000 (22:01 +0000)
committerjohanengelen <johanengelen@users.sourceforge.net>
Sun, 2 Mar 2008 22:01:12 +0000 (22:01 +0000)
remove some leftover code from point param code
remove test pointparam from LPEKnot
added SnapIndicator
added SnapIndicator to SPDesktop, and a call from guidesnapping to display a snapindicator when a guide is snapped.
fix canvas-temporary-item-list.cpp

src/desktop-events.cpp
src/desktop.cpp
src/desktop.h
src/display/Makefile_insert
src/display/canvas-temporary-item-list.cpp
src/display/display-forward.h
src/display/snap-indicator.cpp [new file with mode: 0644]
src/display/snap-indicator.h [new file with mode: 0644]
src/live_effects/lpe-knot.h
src/live_effects/parameter/point.cpp
src/live_effects/parameter/point.h

index 1351d62f0d5fbd9d1c33f2a8efbfb2b074bd4c51..e115a744a3560ef50420bec9a81ba759e0bcbe87 100644 (file)
@@ -17,6 +17,7 @@
 #include <map>
 #include <string>
 #include "display/guideline.h"
+#include "display/snap-indicator.h"
 #include "helper/unit-menu.h"
 #include "helper/units.h"
 #include "desktop.h"
@@ -142,11 +143,16 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge
                 NR::Point event_dt(desktop->w2d(event_w));
                 
                 SnapManager const &m = desktop->namedview->snap_manager;
-                event_dt = m.guideSnap(event_dt, normal).getPoint();
-                
+                Inkscape::SnappedPoint snappoint = m.guideSnap(event_dt, normal);
+                event_dt = snappoint.getPoint();
+
                 sp_guideline_set_position(SP_GUIDELINE(guide), event_dt.to_2geom());
                 desktop->set_coordinate_status(event_dt);
                 desktop->setPosition (event_dt);
+
+                if (snappoint.getDistance() < NR_HUGE) {
+                    desktop->snapindicator->set_new_snappoint(snappoint.getPoint().to_2geom());
+                }
             }
             break;
     case GDK_BUTTON_RELEASE:
@@ -238,12 +244,18 @@ gint sp_dt_guide_event(SPCanvasItem *item, GdkEvent *event, gpointer data)
                 // This is for snapping while dragging existing guidelines. New guidelines, 
                 // which are dragged off the ruler, are being snapped in sp_dt_ruler_event
                 SnapManager const &m = desktop->namedview->snap_manager;
-                motion_dt = m.guideSnap(motion_dt, guide->normal_to_line).getPoint();
-                
+                Inkscape::SnappedPoint snappoint = m.guideSnap(motion_dt, guide->normal_to_line);
+                motion_dt = snappoint.getPoint();
+
                 sp_guide_moveto(*guide, motion_dt.to_2geom(), false);
                 moved = true;
                 desktop->set_coordinate_status(motion_dt);
                 desktop->setPosition (motion_dt);
+
+                if (snappoint.getDistance() < NR_HUGE) {
+                    desktop->snapindicator->set_new_snappoint(snappoint.getPoint().to_2geom());
+                }
+
                 ret = TRUE;
             }
             break;
index 65025027ad9641e7c5395d664eb3d3dfb306ace0..3ff4bf2f590df2376e7078d35ac7d04317a97229 100644 (file)
@@ -78,6 +78,7 @@
 #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"
@@ -117,6 +118,7 @@ SPDesktop::SPDesktop() :
     layer_manager( 0 ),
     event_log( 0 ),
     temporary_item_list( 0 ),
+    snapindicator( 0 ),
     acetate( 0 ),
     main( 0 ),
     gridgroup( 0 ),
@@ -316,13 +318,20 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas)
     showGrids(namedview->grids_visible, false);
 
     temporary_item_list = new Inkscape::Display::TemporaryItemList( this );
+    snapindicator = new Inkscape::Display::SnapIndicator ( this );
 }
 
 
 void SPDesktop::destroy()
 {
-    delete temporary_item_list;
-    temporary_item_list = NULL;
+    if (snapindicator) {
+        delete snapindicator;
+        snapindicator = NULL;
+    }
+    if (temporary_item_list) {
+        delete temporary_item_list;
+        temporary_item_list = NULL;
+    }
 
     namedview->hide(this);
 
@@ -393,7 +402,10 @@ SPDesktop::add_temporary_canvasitem (SPCanvasItem *item, guint lifetime)
 void
 SPDesktop::remove_temporary_canvasitem (Inkscape::Display::TemporaryItem * tempitem)
 {
-    temporary_item_list->delete_item(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()
index bb05331b6add722ff1cd3f0565a14736467227e9..1435eea6fc02da5528bf4bb5615be7a4a876cedc 100644 (file)
@@ -75,6 +75,7 @@ namespace Inkscape {
   namespace Display {
       class TemporaryItemList;
       class TemporaryItem;
+      class SnapIndicator;
   }
 }
 
@@ -95,6 +96,7 @@ struct SPDesktop : public Inkscape::UI::View::View
     Inkscape::EventLog        *event_log;
 
     Inkscape::Display::TemporaryItemList *temporary_item_list;
+    Inkscape::Display::SnapIndicator *snapindicator;
 
     SPCanvasItem  *acetate;
     SPCanvasGroup *main;
index 61cb02155b101c0a02fa5647d74194afe6d45767..d7b0fb608043549251adeaabc4c00c4eb00985a2 100644 (file)
@@ -55,6 +55,8 @@ display_libspdisplay_a_SOURCES = \
        display/nr-plain-stuff-gdk.h    \
        display/nr-plain-stuff.cpp      \
        display/nr-plain-stuff.h        \
+       display/snap-indicator.cpp      \
+       display/snap-indicator.h        \
        display/sodipodi-ctrl.cpp       \
        display/sodipodi-ctrl.h \
        display/sodipodi-ctrlrect.cpp   \
index 5b92e18287d01067d34b44a158bd27529d0ca03b..54e81a1f0fb0dd83543e990ec8d795c53bd18049 100644 (file)
@@ -37,11 +37,11 @@ TemporaryItemList::~TemporaryItemList()
 TemporaryItem *\r
 TemporaryItemList::add_item(SPCanvasItem *item, guint lifetime)\r
 {\r
-    if (lifetime > 100) { // beware of strange things happening due to very short timeouts\r
-        TemporaryItem * tempitem = new TemporaryItem(item, lifetime);\r
-        itemlist.push_back(tempitem);\r
-        tempitem->signal_timeout.connect( sigc::mem_fun(*this, &TemporaryItemList::_item_timeout) );\r
-    }\r
+    // beware of strange things happening due to very short timeouts\r
+    TemporaryItem * tempitem = new TemporaryItem(item, lifetime);\r
+    itemlist.push_back(tempitem);\r
+    tempitem->signal_timeout.connect( sigc::mem_fun(*this, &TemporaryItemList::_item_timeout) );\r
+    return tempitem;\r
 }\r
 \r
 void\r
index a28b7d03a350dd091c93cf6eed2a04a25268f831..191aac61fa1d117669484acf61ae8367d0b32e2a 100644 (file)
@@ -11,6 +11,12 @@ struct SPCanvasGroup;
 struct SPCanvasGroupClass;
 struct SPCurve;
 
+namespace Inkscape {
+namespace Display {
+    class TemporaryItem;
+    class TemporaryItemList;
+}
+}
 
 #define SP_TYPE_CANVAS_ITEM (sp_canvas_item_get_type())
 #define SP_CANVAS_ITEM(obj) (GTK_CHECK_CAST((obj), SP_TYPE_CANVAS_ITEM, SPCanvasItem))
diff --git a/src/display/snap-indicator.cpp b/src/display/snap-indicator.cpp
new file mode 100644 (file)
index 0000000..1d005ce
--- /dev/null
@@ -0,0 +1,76 @@
+/** \file\r
+ * Provides a class that shows a temporary indicator on the canvas of where the snap was, and what kind of snap\r
+ *\r
+ * Authors:\r
+ *   Johan Engelen\r
+ *\r
+ * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>\r
+ *\r
+ * Released under GNU GPL, read the file 'COPYING' for more information\r
+ */\r
+\r
+#include "display/snap-indicator.h"\r
+\r
+#include "desktop.h"\r
+#include "desktop-handles.h"\r
+#include "display/sodipodi-ctrl.h"\r
+#include "knot.h"\r
+\r
+namespace Inkscape {\r
+namespace Display {\r
+\r
+/** lifetime is measured in milliseconds\r
+ */\r
+SnapIndicator::SnapIndicator(SPDesktop * desktop)\r
+    :   tempitem(NULL),\r
+        desktop(desktop)\r
+{\r
+}\r
+\r
+SnapIndicator::~SnapIndicator()\r
+{\r
+    // remove item that might be present\r
+    remove_snappoint();\r
+}\r
+\r
+void\r
+SnapIndicator::set_new_snappoint(Geom::Point p)\r
+{\r
+    remove_snappoint();\r
+\r
+    SPCanvasItem * canvasitem = sp_canvas_item_new( sp_desktop_tempgroup (desktop),\r
+                                                    SP_TYPE_CTRL,\r
+                                                    "anchor", GTK_ANCHOR_CENTER,\r
+                                                    "size", 6.0,\r
+                                                    "stroked", TRUE,\r
+                                                    "stroke_color", 0xf000f0ff,\r
+                                                    "mode", SP_KNOT_MODE_XOR,\r
+                                                    "shape", SP_KNOT_SHAPE_CROSS,\r
+                                                    NULL );\r
+    SP_CTRL(canvasitem)->moveto ( p );\r
+    tempitem = desktop->add_temporary_canvasitem(canvasitem, 2000);\r
+}\r
+\r
+void\r
+SnapIndicator::remove_snappoint()\r
+{\r
+    if (tempitem) {\r
+        desktop->remove_temporary_canvasitem(tempitem);\r
+        tempitem = NULL;\r
+    }\r
+}\r
+\r
+\r
+} //namespace Display\r
+} /* namespace Inkscape */\r
+\r
+/*\r
+  Local Variables:\r
+  mode:c++\r
+  c-file-style:"stroustrup"\r
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
+  indent-tabs-mode:nil\r
+  fill-column:99\r
+  End:\r
+*/\r
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :\r
diff --git a/src/display/snap-indicator.h b/src/display/snap-indicator.h
new file mode 100644 (file)
index 0000000..bedeb49
--- /dev/null
@@ -0,0 +1,53 @@
+#ifndef INKSCAPE_DISPLAY_SNAP_INDICATOR_H\r
+#define INKSCAPE_DISPLAY_SNAP_INDICATOR_H\r
+\r
+/** \file\r
+ * Provides a class that shows a temporary indicator on the canvas of where the snap was, and what kind of snap\r
+ *\r
+ * Authors:\r
+ *   Johan Engelen\r
+ *\r
+ * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>\r
+ *\r
+ * Released under GNU GPL, read the file 'COPYING' for more information\r
+ */\r
+\r
+#include "forward.h"\r
+#include "display/display-forward.h"\r
+#include <2geom/point.h>\r
+\r
+namespace Inkscape {\r
+namespace Display {\r
+\r
+class SnapIndicator  {\r
+public:\r
+    SnapIndicator(SPDesktop *desktop);\r
+    virtual ~SnapIndicator();\r
+\r
+    void set_new_snappoint(Geom::Point p);\r
+    void remove_snappoint();\r
+\r
+protected:\r
+    TemporaryItem * tempitem;\r
+    SPDesktop *desktop;\r
+\r
+private:\r
+    SnapIndicator(const SnapIndicator&);\r
+    SnapIndicator& operator=(const SnapIndicator&);\r
+};\r
+\r
+} //namespace Display\r
+} //namespace Inkscape\r
+\r
+#endif\r
+\r
+/*\r
+  Local Variables:\r
+  mode:c++\r
+  c-file-style:"stroustrup"\r
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
+  indent-tabs-mode:nil\r
+  fill-column:99\r
+  End:\r
+*/\r
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :\r
index f456ab2ce516d9c17fd544c611f7960372c70c6d..a030f756763304e2ea15ef50d7673dee36b3f02c 100644 (file)
@@ -16,7 +16,6 @@
 
 #include "live_effects/effect.h"
 #include "live_effects/parameter/parameter.h"
-#include "live_effects/parameter/point.h"
 
 namespace Inkscape {
 namespace LivePathEffect {
index 38bf4be57607ddbf7b576a144908ce197f37589e..075f7544f88ee4fec9409bd4777be6eaf146d5ff 100644 (file)
 #include "desktop.h"
 #include "selection.h"
 
-// temporarily needed for tempitem tryout
-#include "desktop-handles.h"
-#include "display/sodipodi-ctrl.h"
-#include "knot.h"
-#include "display/canvas-temporary-item-list.h"
-
 #define LPEPOINTPARAM_DEBUG // undefine to disable all on-canvas editing code for PointParam
 
 namespace Inkscape {
@@ -41,7 +35,6 @@ PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip,
                         Effect* effect, Geom::Point default_value )
     : Geom::Point(default_value), Parameter(label, tip, key, wr, effect), defvalue(default_value)
 {
-    knot = NULL;
 #ifdef LPEPOINTPARAM_DEBUG
     oncanvas_editable = true;
 #endif
@@ -49,8 +42,6 @@ PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip,
 
 PointParam::~PointParam()
 {
-    if (knot)
-        g_object_unref (G_OBJECT (knot));
 }
 
 void
@@ -144,22 +135,6 @@ PointParam::param_editOncanvas(SPItem * item, SPDesktop * dt)
 
     ShapeEditor * shape_editor = SP_NODE_CONTEXT( dt->event_context )->shape_editor;
     shape_editor->set_item_lpe_point_parameter(item, SP_OBJECT(param_effect->getLPEObj()), param_key.c_str());
-
-
-    /* TEMPORARY CODE TO TEST TEMPORARY CANVAS ITEMS */
-    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
-    SPCanvasItem * canvasitem = sp_canvas_item_new( sp_desktop_tempgroup (desktop),
-                                                    SP_TYPE_CTRL,
-                                                    "anchor", GTK_ANCHOR_CENTER,
-                                                    "size", 8.0,
-                                                    "stroked", TRUE,
-                                                    "stroke_color", 0xf000f0ff,
-                                                    "mode", SP_KNOT_MODE_XOR,
-                                                    "shape", SP_KNOT_SHAPE_CROSS,
-                                                    NULL );
-    SP_CTRL(canvasitem)->moveto ( static_cast<Geom::Point> (*this) );
-    desktop->add_temporary_canvasitem(canvasitem, 2000);
-    /* END ----   TEMPORARY CODE TO TEST TEMPORARY CANVAS ITEMS */
 }
 
 
index a6866f7df6082cde66d9df5bf55d9bdc31463e12..c167807d9cbd641f33e5925a0010aaec90b81929 100644 (file)
@@ -16,8 +16,6 @@
 
 #include "live_effects/parameter/parameter.h"
 
-struct SPKnot;
-
 namespace Inkscape {
 
 namespace LivePathEffect {
@@ -53,8 +51,6 @@ private:
 
     void on_button_click();
 
-    SPKnot *knot;
-
     Geom::Point defvalue;
 };