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/display | |
| parent | warning cleanup (diff) | |
| download | inkscape-acae310d49358ac8de885fa8692caf5e4067574c.tar.gz inkscape-acae310d49358ac8de885fa8692caf5e4067574c.zip | |
NEW: temporary on-canvas indicators
(bzr r4918)
Diffstat (limited to 'src/display')
| -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 |
5 files changed, 273 insertions, 0 deletions
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 :
|
