diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2008-03-02 13:38:15 +0000 |
|---|---|---|
| committer | johanengelen <johanengelen@users.sourceforge.net> | 2008-03-02 13:38:15 +0000 |
| commit | acae310d49358ac8de885fa8692caf5e4067574c (patch) | |
| tree | b19affe735ea558718e378184a11031bbe44c328 /src | |
| parent | warning cleanup (diff) | |
| download | inkscape-acae310d49358ac8de885fa8692caf5e4067574c.tar.gz inkscape-acae310d49358ac8de885fa8692caf5e4067574c.zip | |
NEW: temporary on-canvas indicators
(bzr r4918)
Diffstat (limited to 'src')
| -rw-r--r-- | src/desktop-handles.cpp | 8 | ||||
| -rw-r--r-- | src/desktop-handles.h | 1 | ||||
| -rw-r--r-- | src/desktop.cpp | 30 | ||||
| -rw-r--r-- | src/desktop.h | 10 | ||||
| -rw-r--r-- | src/display/Makefile_insert | 4 | ||||
| -rw-r--r-- | src/display/canvas-temporary-item-list.cpp | 83 | ||||
| -rw-r--r-- | src/display/canvas-temporary-item-list.h | 58 | ||||
| -rw-r--r-- | src/display/canvas-temporary-item.cpp | 72 | ||||
| -rw-r--r-- | src/display/canvas-temporary-item.h | 56 | ||||
| -rw-r--r-- | src/live_effects/effect.h | 3 | ||||
| -rw-r--r-- | src/live_effects/lpe-test-doEffect-stack.cpp | 4 | ||||
| -rw-r--r-- | src/live_effects/lpe-test-doEffect-stack.h | 2 | ||||
| -rw-r--r-- | src/live_effects/parameter/point.cpp | 37 |
13 files changed, 355 insertions, 13 deletions
diff --git a/src/desktop-handles.cpp b/src/desktop-handles.cpp index 1241bfa02..481bf35ea 100644 --- a/src/desktop-handles.cpp +++ b/src/desktop-handles.cpp @@ -103,6 +103,14 @@ sp_desktop_controls (SPDesktop const * desktop) return desktop->controls; } +SPCanvasGroup * +sp_desktop_tempgroup (SPDesktop const * desktop) +{ + g_return_val_if_fail (desktop != NULL, NULL); + + return desktop->tempgroup; +} + Inkscape::MessageStack * sp_desktop_message_stack (SPDesktop const * desktop) { diff --git a/src/desktop-handles.h b/src/desktop-handles.h index d7e3bfdae..72c943949 100644 --- a/src/desktop-handles.h +++ b/src/desktop-handles.h @@ -39,6 +39,7 @@ SPCanvasGroup * sp_desktop_guides (SPDesktop const * desktop); SPCanvasItem *sp_desktop_drawing (SPDesktop const *desktop); SPCanvasGroup * sp_desktop_sketch (SPDesktop const * desktop); SPCanvasGroup * sp_desktop_controls (SPDesktop const * desktop); +SPCanvasGroup * sp_desktop_tempgroup (SPDesktop const * desktop); Inkscape::MessageStack * sp_desktop_message_stack (SPDesktop const * desktop); SPNamedView * sp_desktop_namedview (SPDesktop const * desktop); diff --git a/src/desktop.cpp b/src/desktop.cpp index d2547f5a6..65025027a 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -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,7 @@ #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 "libnr/nr-matrix-div.h" #include "libnr/nr-rect-ops.h" #include "ui/dialog/dialog-manager.h" @@ -115,6 +116,7 @@ SPDesktop::SPDesktop() : event_context( 0 ), layer_manager( 0 ), event_log( 0 ), + temporary_item_list( 0 ), acetate( 0 ), main( 0 ), gridgroup( 0 ), @@ -122,6 +124,7 @@ SPDesktop::SPDesktop() : drawing( 0 ), sketch( 0 ), controls( 0 ), + tempgroup ( 0 ), table( 0 ), page( 0 ), page_border( 0 ), @@ -217,6 +220,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 +314,16 @@ 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 ); } void SPDesktop::destroy() { + delete temporary_item_list; + temporary_item_list = NULL; + namedview->hide(this); _activate_connection.disconnect(); @@ -368,6 +377,25 @@ 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) +{ + temporary_item_list->delete_item(tempitem); +} + void SPDesktop::setDisplayModeNormal() { SP_CANVAS_ARENA (drawing)->arena->rendermode = RENDERMODE_NORMAL; diff --git a/src/desktop.h b/src/desktop.h index 84b829726..bb05331b6 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -72,6 +72,10 @@ namespace Inkscape { namespace Whiteboard { class SessionManager; } + namespace Display { + class TemporaryItemList; + class TemporaryItem; + } } /** @@ -90,6 +94,8 @@ struct SPDesktop : public Inkscape::UI::View::View Inkscape::LayerManager *layer_manager; Inkscape::EventLog *event_log; + Inkscape::Display::TemporaryItemList *temporary_item_list; + SPCanvasItem *acetate; SPCanvasGroup *main; SPCanvasGroup *gridgroup; @@ -97,6 +103,7 @@ struct SPDesktop : public Inkscape::UI::View::View SPCanvasItem *drawing; SPCanvasGroup *sketch; SPCanvasGroup *controls; + SPCanvasGroup *tempgroup; ///< contains temporary canvas items SPCanvasItem *table; ///< outside-of-page background SPCanvasItem *page; ///< page background SPCanvasItem *page_border; ///< page border @@ -173,6 +180,9 @@ struct SPDesktop : public Inkscape::UI::View::View return _guides_message_context; } + Inkscape::Display::TemporaryItem * add_temporary_canvasitem (SPCanvasItem *item, guint lifetime); + void remove_temporary_canvasitem (Inkscape::Display::TemporaryItem * tempitem); + void setDisplayModeNormal(); void setDisplayModeOutline(); void displayModeToggle(); diff --git a/src/display/Makefile_insert b/src/display/Makefile_insert index 4994434d7..61cb02155 100644 --- a/src/display/Makefile_insert +++ b/src/display/Makefile_insert @@ -40,6 +40,10 @@ display_libspdisplay_a_SOURCES = \ display/canvas-grid.h \ display/canvas-axonomgrid.cpp \ display/canvas-axonomgrid.h \ + display/canvas-temporary-item.cpp \ + display/canvas-temporary-item.h \ + display/canvas-temporary-item-list.cpp \ + display/canvas-temporary-item-list.h \ display/curve.cpp \ display/curve.h \ display/display-forward.h \ diff --git a/src/display/canvas-temporary-item-list.cpp b/src/display/canvas-temporary-item-list.cpp new file mode 100644 index 000000000..5b92e1828 --- /dev/null +++ b/src/display/canvas-temporary-item-list.cpp @@ -0,0 +1,83 @@ +/** \file
+ * Provides a class that can contain active TemporaryItem's on a desktop
+ * Code inspired by message-stack.cpp
+ *
+ * Authors:
+ * Johan Engelen
+ *
+ * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "display/canvas-temporary-item-list.h"
+
+#include "display/canvas-temporary-item.h"
+
+namespace Inkscape {
+namespace Display {
+
+TemporaryItemList::TemporaryItemList(SPDesktop *desktop)
+ : desktop(desktop)
+{
+
+}
+
+TemporaryItemList::~TemporaryItemList()
+{
+ // delete all items in list so the timeouts are removed
+ for ( std::list<TemporaryItem*>::iterator it = itemlist.begin(); it != itemlist.end(); ++it ) {
+ TemporaryItem * tempitem = *it;
+ delete tempitem;
+ }
+ itemlist.clear();
+}
+
+/* Note that TemporaryItem or TemporaryItemList is responsible for deletion and such, so this return pointer can safely be ignored. */
+TemporaryItem *
+TemporaryItemList::add_item(SPCanvasItem *item, guint lifetime)
+{
+ if (lifetime > 100) { // beware of strange things happening due to very short timeouts
+ TemporaryItem * tempitem = new TemporaryItem(item, lifetime);
+ itemlist.push_back(tempitem);
+ tempitem->signal_timeout.connect( sigc::mem_fun(*this, &TemporaryItemList::_item_timeout) );
+ }
+}
+
+void
+TemporaryItemList::delete_item( TemporaryItem * tempitem )
+{
+ // check if the item is in the list, if so, delete it. (in other words, don't wait for the item to delete itself)
+ bool in_list = false;
+ for ( std::list<TemporaryItem*>::iterator it = itemlist.begin(); it != itemlist.end(); ++it ) {
+ if ( *it == tempitem ) {
+ in_list = true;
+ break;
+ }
+ }
+ if (in_list) {
+ itemlist.remove(tempitem);
+ delete tempitem;
+ }
+}
+
+void
+TemporaryItemList::_item_timeout(TemporaryItem * tempitem)
+{
+ itemlist.remove(tempitem);
+ // no need to delete the item, it does that itself after signal_timeout.emit() completes
+}
+
+} //namespace Display
+} /* namespace Inkscape */
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/display/canvas-temporary-item-list.h b/src/display/canvas-temporary-item-list.h new file mode 100644 index 000000000..cd4bcfe99 --- /dev/null +++ b/src/display/canvas-temporary-item-list.h @@ -0,0 +1,58 @@ +#ifndef INKSCAPE_CANVAS_TEMPORARY_ITEM_LIST_H
+#define INKSCAPE_CANVAS_TEMPORARY_ITEM_LIST_H
+
+/** \file
+ * Provides a class that can contain active TemporaryItem's on a desktop
+ *
+ * Authors:
+ * Johan Engelen
+ *
+ * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "forward.h"
+#include "display/display-forward.h"
+#include <list>
+
+namespace Inkscape {
+namespace Display {
+
+class TemporaryItem;
+
+class TemporaryItemList {
+public:
+ TemporaryItemList(SPDesktop *desktop);
+ virtual ~TemporaryItemList();
+
+ TemporaryItem* add_item (SPCanvasItem *item, guint lifetime);
+ void delete_item (TemporaryItem * tempitem);
+
+protected:
+ SPDesktop *desktop; /** Desktop we are on. */
+
+ std::list<TemporaryItem *> itemlist; /** list of temp items */
+
+ void _item_timeout (TemporaryItem * tempitem);
+
+private:
+ TemporaryItemList(const TemporaryItemList&);
+ TemporaryItemList& operator=(const TemporaryItemList&);
+};
+
+} //namespace Display
+} //namespace Inkscape
+
+#endif
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/display/canvas-temporary-item.cpp b/src/display/canvas-temporary-item.cpp new file mode 100644 index 000000000..da6caf2c1 --- /dev/null +++ b/src/display/canvas-temporary-item.cpp @@ -0,0 +1,72 @@ +/** \file
+ * Provides a class that can contain active TemporaryItem's on a desktop
+ * When the object is deleted, it also deletes the canvasitem it contains!
+ * This object should be created/managed by a TemporaryItemList.
+ * After its lifetime, it fires the timeout signal, afterwards *it deletes itself*.
+ *
+ * (part of code inspired by message-stack.cpp)
+ *
+ * Authors:
+ * Johan Engelen
+ *
+ * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "display/canvas-temporary-item.h"
+
+#include <gtk/gtkobject.h>
+
+namespace Inkscape {
+namespace Display {
+
+/** lifetime is measured in milliseconds
+ */
+TemporaryItem::TemporaryItem(SPCanvasItem *item, guint lifetime)
+ : canvasitem(item),
+ timeout_id(0)
+{
+ if (lifetime > 0) {
+ timeout_id = g_timeout_add(lifetime, &TemporaryItem::_timeout, this);
+ }
+}
+
+TemporaryItem::~TemporaryItem()
+{
+ // when it has not expired yet...
+ if (timeout_id) {
+ g_source_remove(timeout_id);
+ timeout_id = 0;
+ }
+
+ if (canvasitem) {
+ // destroying the item automatically hides it
+ gtk_object_destroy (GTK_OBJECT (canvasitem));
+ canvasitem = NULL;
+ }
+}
+
+/* static method*/
+gboolean TemporaryItem::_timeout(gpointer data) {
+ TemporaryItem *tempitem = reinterpret_cast<TemporaryItem *>(data);
+ tempitem->timeout_id = 0;
+ tempitem->signal_timeout.emit(tempitem);
+ delete tempitem;
+ return FALSE;
+}
+
+
+} //namespace Display
+} /* namespace Inkscape */
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/display/canvas-temporary-item.h b/src/display/canvas-temporary-item.h new file mode 100644 index 000000000..0caa0d943 --- /dev/null +++ b/src/display/canvas-temporary-item.h @@ -0,0 +1,56 @@ +#ifndef INKSCAPE_CANVAS_TEMPORARY_ITEM_H
+#define INKSCAPE_CANVAS_TEMPORARY_ITEM_H
+
+/** \file
+ * Provides a class to put a canvasitem temporarily on-canvas.
+ *
+ * Authors:
+ * Johan Engelen
+ *
+ * Copyright (C) Johan Engelen 2008 <j.b.c.engelen@utwente.nl>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "display/display-forward.h"
+
+#include <sigc++/sigc++.h>
+
+namespace Inkscape {
+namespace Display {
+
+class TemporaryItem {
+public:
+ TemporaryItem(SPCanvasItem *item, guint lifetime);
+ virtual ~TemporaryItem();
+
+ sigc::signal<void, TemporaryItem *> signal_timeout;
+
+protected:
+ friend class TemporaryItemList;
+
+ SPCanvasItem * canvasitem; /** The item we are holding on to */
+ guint timeout_id; /** ID by which glib knows the timeout event */
+
+ static gboolean _timeout(gpointer data); ///< callback for when lifetime expired
+
+private:
+ TemporaryItem(const TemporaryItem&);
+ TemporaryItem& operator=(const TemporaryItem&);
+};
+
+} //namespace Display
+} //namespace Inkscape
+
+#endif
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index fb5e85b1b..6b5295071 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -19,7 +19,7 @@ #define LPE_CONVERSION_TOLERANCE 0.01 // FIXME: find good solution for this. -//#define LPE_ENABLE_TEST_EFFECTS +#define LPE_ENABLE_TEST_EFFECTS struct SPDocument; struct SPDesktop; @@ -117,7 +117,6 @@ protected: std::vector<Parameter *> param_vector; int oncanvasedit_it; - Inkscape::UI::Widget::Registry wr; LivePathEffectObject *lpeobj; diff --git a/src/live_effects/lpe-test-doEffect-stack.cpp b/src/live_effects/lpe-test-doEffect-stack.cpp index f6ecad562..f20ce8cec 100644 --- a/src/live_effects/lpe-test-doEffect-stack.cpp +++ b/src/live_effects/lpe-test-doEffect-stack.cpp @@ -18,9 +18,11 @@ namespace LivePathEffect { LPEdoEffectStackTest::LPEdoEffectStackTest(LivePathEffectObject *lpeobject) : Effect(lpeobject), - step(_("Stack step"), (""), "step", &wr, this) + step(_("Stack step"), (""), "step", &wr, this), + point(_("point param"), "", "point_param", &wr, this) { registerParameter( dynamic_cast<Parameter *>(&step) ); + registerParameter( dynamic_cast<Parameter *>(&point) ); } LPEdoEffectStackTest::~LPEdoEffectStackTest() diff --git a/src/live_effects/lpe-test-doEffect-stack.h b/src/live_effects/lpe-test-doEffect-stack.h index 3d853aa8c..1417512d1 100644 --- a/src/live_effects/lpe-test-doEffect-stack.h +++ b/src/live_effects/lpe-test-doEffect-stack.h @@ -15,6 +15,7 @@ #include "live_effects/effect.h" #include "live_effects/parameter/parameter.h" +#include "live_effects/parameter/point.h" namespace Inkscape { namespace LivePathEffect { @@ -31,6 +32,7 @@ public: private: ScalarParam step; + PointParam point; LPEdoEffectStackTest(const LPEdoEffectStackTest&); LPEdoEffectStackTest& operator=(const LPEdoEffectStackTest&); diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index 1859a0a09..38bf4be57 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -14,22 +14,23 @@ #include "ui/widget/point.h" #include "widgets/icon.h" #include "ui/widget/registered-widget.h" -#include "knot.h" #include "inkscape.h" #include "verbs.h" // needed for on-canvas editting: #include "tools-switch.h" -#include "shape-editor.h" #include "node-context.h" -#include "desktop-handles.h" -#include "selection.h" +#include "shape-editor.h" #include "desktop.h" +#include "selection.h" -#define LPEPOINTPARAM_DEBUG // undefine to disable all on-canvas editing code for PointParam +// 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 PRM_KNOT_COLOR_NORMAL 0xffffff00 -#define PRM_KNOT_COLOR_SELECTED 0x0000ff00 +#define LPEPOINTPARAM_DEBUG // undefine to disable all on-canvas editing code for PointParam namespace Inkscape { @@ -93,6 +94,7 @@ PointParam::param_newWidget(Gtk::Tooltips * tooltips) param_effect->getRepr(), param_effect->getSPDoc() ) ); pointwdg->setValue( (*this)[0], (*this)[1] ); + pointwdg->clearProgrammatically(); pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter")); Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "draw_node", Inkscape::ICON_SIZE_BUTTON) ); @@ -142,6 +144,22 @@ 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 */ } @@ -158,9 +176,10 @@ PointParam::param_transform_multiply(Geom::Matrix const& postmul, bool /*set*/) void PointParam::on_button_click() { - SPItem * item = sp_desktop_selection(SP_ACTIVE_DESKTOP)->singleItem(); + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + SPItem * item = sp_desktop_selection(desktop)->singleItem(); if (item != NULL) { - param_editOncanvas(item, SP_ACTIVE_DESKTOP); + param_editOncanvas(item, desktop); } } |
