diff options
| author | Liam P. White <inkscapebrony@gmail.com> | 2014-07-26 17:11:51 +0000 |
|---|---|---|
| committer | Liam P. White <inkscapebrony@gmail.com> | 2014-07-26 17:11:51 +0000 |
| commit | cc73219a498e87298578996011b80680214f7a96 (patch) | |
| tree | 40d0e91da69ff1ceafe2bc9377cdfc137174fafb /src | |
| parent | Read HSL color (CSS Color Module Level 3). (diff) | |
| download | inkscape-cc73219a498e87298578996011b80680214f7a96.tar.gz inkscape-cc73219a498e87298578996011b80680214f7a96.zip | |
Clean up some ShapeHolder related things
(bzr r13341.1.100)
Diffstat (limited to 'src')
| -rw-r--r-- | src/shape-editor.cpp | 202 | ||||
| -rw-r--r-- | src/shape-editor.h | 54 | ||||
| -rw-r--r-- | src/ui/tools/arc-tool.cpp | 6 | ||||
| -rw-r--r-- | src/ui/tools/box3d-tool.cpp | 6 | ||||
| -rw-r--r-- | src/ui/tools/flood-tool.cpp | 6 | ||||
| -rw-r--r-- | src/ui/tools/lpe-tool.cpp | 7 | ||||
| -rw-r--r-- | src/ui/tools/node-tool.cpp | 2 | ||||
| -rw-r--r-- | src/ui/tools/rect-tool.cpp | 6 | ||||
| -rw-r--r-- | src/ui/tools/spiral-tool.cpp | 6 | ||||
| -rw-r--r-- | src/ui/tools/star-tool.cpp | 6 | ||||
| -rw-r--r-- | src/ui/tools/text-tool.cpp | 6 |
11 files changed, 98 insertions, 209 deletions
diff --git a/src/shape-editor.cpp b/src/shape-editor.cpp index bf53e8bc3..7915fe533 100644 --- a/src/shape-editor.cpp +++ b/src/shape-editor.cpp @@ -14,24 +14,15 @@ #include <string.h> #include <glibmm/i18n.h> -#include "sp-object.h" -#include "sp-item.h" -#include "sp-lpe-item.h" -#include "live_effects/lpeobject.h" -#include "selection.h" -#include "desktop.h" -#include "document.h" #include "desktop-handles.h" +#include "document.h" +#include "gc-anchored.h" #include "knotholder.h" -#include "live_effects/parameter/point.h" -#include "xml/node-event-vector.h" -#include "preferences.h" #include "object-edit.h" -#include "style.h" -#include "display/curve.h" -#include <2geom/pathvector.h> - +#include "sp-item.h" +#include "sp-object.h" #include "shape-editor.h" +#include "xml/node-event-vector.h" using Inkscape::createKnotHolder; @@ -44,133 +35,80 @@ ShapeEditor::ShapeEditor(SPDesktop *dt) { } ShapeEditor::~ShapeEditor() { - unset_item(SH_KNOTHOLDER); + unset_item(); } -void ShapeEditor::unset_item(SubType type, bool keep_knotholder) { - switch (type) { - case SH_NODEPATH: - // defunct - break; - case SH_KNOTHOLDER: - if (this->knotholder) { - Inkscape::XML::Node *old_repr = this->knotholder->repr; - if (old_repr && old_repr == knotholder_listener_attached_for) { - sp_repr_remove_listener_by_data(old_repr, this); - Inkscape::GC::release(old_repr); - knotholder_listener_attached_for = NULL; - } - - if (!keep_knotholder) { - delete this->knotholder; - this->knotholder = NULL; - } - } - break; - } -} +void ShapeEditor::unset_item(bool keep_knotholder) { + if (this->knotholder) { + Inkscape::XML::Node *old_repr = this->knotholder->repr; + if (old_repr && old_repr == knotholder_listener_attached_for) { + sp_repr_remove_listener_by_data(old_repr, this); + Inkscape::GC::release(old_repr); + knotholder_listener_attached_for = NULL; + } -bool ShapeEditor::has_nodepath () { - return false; + if (!keep_knotholder) { + delete this->knotholder; + this->knotholder = NULL; + } + } } -bool ShapeEditor::has_knotholder () { - return (this->knotholder != NULL); +bool ShapeEditor::has_knotholder() { + return this->knotholder != NULL; } -void ShapeEditor::update_knotholder () { +void ShapeEditor::update_knotholder() { if (this->knotholder) this->knotholder->update_knots(); } -bool ShapeEditor::has_local_change (SubType type) { - switch (type) { - case SH_NODEPATH: - // defunct - return false; - case SH_KNOTHOLDER: - return (this->knotholder && this->knotholder->local_change != 0); - default: - g_assert_not_reached(); - } +bool ShapeEditor::has_local_change() { + return (this->knotholder && this->knotholder->local_change != 0); } -void ShapeEditor::decrement_local_change (SubType type) { - switch (type) { - case SH_NODEPATH: - // defunct - break; - case SH_KNOTHOLDER: - if (this->knotholder) { - this->knotholder->local_change = FALSE; - } - break; - default: - g_assert_not_reached(); +void ShapeEditor::decrement_local_change() { + if (this->knotholder) { + this->knotholder->local_change = FALSE; } } -const SPItem *ShapeEditor::get_item (SubType type) { +const SPItem *ShapeEditor::get_item() { const SPItem *item = NULL; - switch (type) { - case SH_NODEPATH: - // defunct - break; - case SH_KNOTHOLDER: - if (this->has_knotholder()) { - item = this->knotholder->getItem(); - } - break; + if (this->has_knotholder()) { + item = this->knotholder->getItem(); } return item; } -GList *ShapeEditor::save_nodepath_selection () { - // defunct stub - return NULL; -} - -void ShapeEditor::restore_nodepath_selection (GList */*saved*/) { - // defunct stub -} - -void ShapeEditor::shapeeditor_event_attr_changed(gchar const *name) +void ShapeEditor::event_attr_changed(Inkscape::XML::Node *, gchar const *name, gchar const *, gchar const *, bool, void *data) { - gboolean changed_kh = FALSE; + g_assert(data); + ShapeEditor *sh = static_cast<ShapeEditor *>(data); + bool changed_kh = false; - if (has_knotholder()) + if (sh->has_knotholder()) { - changed_kh = !has_local_change(SH_KNOTHOLDER); - decrement_local_change(SH_KNOTHOLDER); + changed_kh = !sh->has_local_change(); + sh->decrement_local_change(); if (changed_kh) { // this can happen if an LPEItem's knotholder handle was dragged, in which case we want // to keep the knotholder; in all other cases (e.g., if the LPE itself changes) we delete it - reset_item(SH_KNOTHOLDER, !strcmp(name, "d")); + sh->reset_item(!strcmp(name, "d")); } } } - -static void shapeeditor_event_attr_changed(Inkscape::XML::Node */*repr*/, gchar const *name, - gchar const */*old_value*/, gchar const */*new_value*/, - bool /*is_interactive*/, gpointer data) -{ - g_assert(data); - ShapeEditor *sh = static_cast<ShapeEditor *>(data); - - sh->shapeeditor_event_attr_changed(name); -} - static Inkscape::XML::NodeEventVector shapeeditor_repr_events = { NULL, /* child_added */ NULL, /* child_removed */ - shapeeditor_event_attr_changed, + ShapeEditor::event_attr_changed, NULL, /* content_changed */ NULL /* order_changed */ }; -void ShapeEditor::set_item(SPItem *item, SubType type, bool keep_knotholder) { +void ShapeEditor::set_item(SPItem *item, bool keep_knotholder) { if (_blockSetItem) { return; } @@ -178,60 +116,38 @@ void ShapeEditor::set_item(SPItem *item, SubType type, bool keep_knotholder) { // this happens (and should only happen) when for an LPEItem having both knotholder and // nodepath the knotholder is adapted; in this case we don't want to delete the knotholder // since this freezes the handles - unset_item(type, keep_knotholder); + unset_item(keep_knotholder); if (item) { Inkscape::XML::Node *repr; - switch(type) { - case SH_NODEPATH: - // defunct - break; - - case SH_KNOTHOLDER: - if (!this->knotholder) { - // only recreate knotholder if none is present - this->knotholder = createKnotHolder(item, desktop); - } - if (this->knotholder) { - this->knotholder->update_knots(); - // setting new listener - repr = this->knotholder->repr; - if (repr != knotholder_listener_attached_for) { - Inkscape::GC::anchor(repr); - sp_repr_add_listener(repr, &shapeeditor_repr_events, this); - knotholder_listener_attached_for = repr; - } - } - break; + if (!this->knotholder) { + // only recreate knotholder if none is present + this->knotholder = createKnotHolder(item, desktop); + } + if (this->knotholder) { + this->knotholder->update_knots(); + // setting new listener + repr = this->knotholder->repr; + if (repr != knotholder_listener_attached_for) { + Inkscape::GC::anchor(repr); + sp_repr_add_listener(repr, &shapeeditor_repr_events, this); + knotholder_listener_attached_for = repr; + } } } } /** FIXME: This thing is only called when the item needs to be updated in response to repr change. - Why not make a reload function in NodePath and in KnotHolder? */ -void ShapeEditor::reset_item (SubType type, bool keep_knotholder) + Why not make a reload function in KnotHolder? */ +void ShapeEditor::reset_item(bool keep_knotholder) { - switch (type) { - case SH_NODEPATH: - // defunct - break; - case SH_KNOTHOLDER: - if ( knotholder ) { - SPObject *obj = sp_desktop_document(desktop)->getObjectByRepr(knotholder_listener_attached_for); /// note that it is not certain that this is an SPItem; it could be a LivePathEffectObject. - set_item(SP_ITEM(obj), SH_KNOTHOLDER, keep_knotholder); - } - break; + if (knotholder) { + SPObject *obj = sp_desktop_document(desktop)->getObjectByRepr(knotholder_listener_attached_for); /// note that it is not certain that this is an SPItem; it could be a LivePathEffectObject. + set_item(SP_ITEM(obj), keep_knotholder); } } -void ShapeEditor::nodepath_destroyed () { -} - -bool ShapeEditor::has_selection() { - return false; // so far, knotholder cannot have selection -} - /** * Returns true if this ShapeEditor has a knot above which the mouse currently hovers. */ diff --git a/src/shape-editor.h b/src/shape-editor.h index ec4b50fa3..df0dbfa3a 100644 --- a/src/shape-editor.h +++ b/src/shape-editor.h @@ -4,8 +4,8 @@ /* * Inkscape::ShapeEditor * - * This is a container class which contains either knotholder (for shapes) or nodepath (for - * paths). It is attached to a single item so only one of these is active at a time. + * This is a container class which contains a knotholder for shapes. + * It is attached to a single item. * * Authors: * bulia byak <buliabyak@users.sf.net> @@ -14,27 +14,12 @@ #include <glib.h> -#include <2geom/forward.h> - - -namespace Inkscape { namespace NodePath { class Path; } } namespace Inkscape { namespace XML { class Node; } } class KnotHolder; class LivePathEffectObject; class SPDesktop; class SPItem; -class SPNodeContext; -class ShapeEditorsCollective; - -#include <2geom/point.h> -#include <boost/optional.hpp> -#include <vector> - -enum SubType{ - SH_NODEPATH, - SH_KNOTHOLDER -}; class ShapeEditor { public: @@ -42,36 +27,25 @@ public: ShapeEditor(SPDesktop *desktop); ~ShapeEditor(); - void set_item (SPItem *item, SubType type, bool keep_knotholder = false); - void unset_item (SubType type, bool keep_knotholder = false); - - bool has_nodepath (); //((deprecated)) - void update_knotholder (); //((deprecated)) + void set_item(SPItem *item, bool keep_knotholder = false); + void unset_item(bool keep_knotholder = false); - bool has_local_change (SubType type); - void decrement_local_change (SubType type); + void update_knotholder(); //((deprecated)) - GList *save_nodepath_selection (); - void restore_nodepath_selection (GList *saved); - - void nodepath_destroyed (); - - bool has_selection (); - - Inkscape::NodePath::Path *get_nodepath() {return NULL;} //((deprecated)) - ShapeEditorsCollective *get_container() {return NULL;} - - // this one is only public because it's called from non-C++ repr changed callback - void shapeeditor_event_attr_changed(gchar const *name); + bool has_local_change(); + void decrement_local_change(); bool knot_mouseover() const; - static void blockSetItem(bool b) {_blockSetItem = b;} + static void blockSetItem(bool b) { _blockSetItem = b; } // kludge? + static void event_attr_changed(Inkscape::XML::Node * /*repr*/, gchar const *name, gchar const * /*old_value*/, + gchar const * /*new_value*/, bool /*is_interactive*/, void *data); private: - bool has_knotholder (); - void reset_item (SubType type, bool keep_knotholder = true); - const SPItem *get_item (SubType type); + bool has_knotholder(); + void reset_item (bool keep_knotholder = true); + const SPItem *get_item(); + static bool _blockSetItem; SPDesktop *desktop; diff --git a/src/ui/tools/arc-tool.cpp b/src/ui/tools/arc-tool.cpp index 43f8eb9e1..9fd68f1b9 100644 --- a/src/ui/tools/arc-tool.cpp +++ b/src/ui/tools/arc-tool.cpp @@ -102,8 +102,8 @@ ArcTool::~ArcTool() { * destroys old and creates new knotholder. */ void ArcTool::selection_changed(Inkscape::Selection* selection) { - this->shape_editor->unset_item(SH_KNOTHOLDER); - this->shape_editor->set_item(selection->singleItem(), SH_KNOTHOLDER); + this->shape_editor->unset_item(); + this->shape_editor->set_item(selection->singleItem()); } void ArcTool::setup() { @@ -115,7 +115,7 @@ void ArcTool::setup() { SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); if (item) { - this->shape_editor->set_item(item, SH_KNOTHOLDER); + this->shape_editor->set_item(item); } this->sel_changed_connection.disconnect(); diff --git a/src/ui/tools/box3d-tool.cpp b/src/ui/tools/box3d-tool.cpp index e00894d55..b998267c2 100644 --- a/src/ui/tools/box3d-tool.cpp +++ b/src/ui/tools/box3d-tool.cpp @@ -112,8 +112,8 @@ Box3dTool::~Box3dTool() { * destroys old and creates new knotholder. */ void Box3dTool::selection_changed(Inkscape::Selection* selection) { - this->shape_editor->unset_item(SH_KNOTHOLDER); - this->shape_editor->set_item(selection->singleItem(), SH_KNOTHOLDER); + this->shape_editor->unset_item(); + this->shape_editor->set_item(selection->singleItem()); if (selection->perspList().size() == 1) { // selecting a single box changes the current perspective @@ -147,7 +147,7 @@ void Box3dTool::setup() { SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); if (item) { - this->shape_editor->set_item(item, SH_KNOTHOLDER); + this->shape_editor->set_item(item); } this->sel_changed_connection.disconnect(); diff --git a/src/ui/tools/flood-tool.cpp b/src/ui/tools/flood-tool.cpp index d74848dc6..3fb56b2ad 100644 --- a/src/ui/tools/flood-tool.cpp +++ b/src/ui/tools/flood-tool.cpp @@ -119,8 +119,8 @@ FloodTool::~FloodTool() { * destroys old and creates new knotholder. */ void FloodTool::selection_changed(Inkscape::Selection* selection) { - this->shape_editor->unset_item(SH_KNOTHOLDER); - this->shape_editor->set_item(selection->singleItem(), SH_KNOTHOLDER); + this->shape_editor->unset_item(); + this->shape_editor->set_item(selection->singleItem()); } void FloodTool::setup() { @@ -130,7 +130,7 @@ void FloodTool::setup() { SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); if (item) { - this->shape_editor->set_item(item, SH_KNOTHOLDER); + this->shape_editor->set_item(item); } this->sel_changed_connection.disconnect(); diff --git a/src/ui/tools/lpe-tool.cpp b/src/ui/tools/lpe-tool.cpp index 9ab6d7814..e9b9421f1 100644 --- a/src/ui/tools/lpe-tool.cpp +++ b/src/ui/tools/lpe-tool.cpp @@ -129,8 +129,7 @@ void LpeTool::setup() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (item) { - this->shape_editor->set_item(item, SH_NODEPATH); - this->shape_editor->set_item(item, SH_KNOTHOLDER); + this->shape_editor->set_item(item); } if (prefs->getBool("/tools/lpetool/selcue")) { @@ -146,9 +145,9 @@ void sp_lpetool_context_selection_changed(Inkscape::Selection *selection, gpoint { LpeTool *lc = SP_LPETOOL_CONTEXT(data); - lc->shape_editor->unset_item(SH_KNOTHOLDER); + lc->shape_editor->unset_item(); SPItem *item = selection->singleItem(); - lc->shape_editor->set_item(item, SH_KNOTHOLDER); + lc->shape_editor->set_item(item); } void LpeTool::set(const Inkscape::Preferences::Entry& val) { diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index ce487831d..36f33e478 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -438,7 +438,7 @@ void NodeTool::selection_changed(Inkscape::Selection *sel) { this->_shape_editors.find(r.item) == this->_shape_editors.end()) { ShapeEditor *si = new ShapeEditor(this->desktop); - si->set_item(r.item, SH_KNOTHOLDER); + si->set_item(r.item); this->_shape_editors.insert(const_cast<SPItem*&>(r.item), si); } } diff --git a/src/ui/tools/rect-tool.cpp b/src/ui/tools/rect-tool.cpp index 39f422c1a..819671dd6 100644 --- a/src/ui/tools/rect-tool.cpp +++ b/src/ui/tools/rect-tool.cpp @@ -102,8 +102,8 @@ RectTool::~RectTool() { * destroys old and creates new knotholder. */ void RectTool::selection_changed(Inkscape::Selection* selection) { - this->shape_editor->unset_item(SH_KNOTHOLDER); - this->shape_editor->set_item(selection->singleItem(), SH_KNOTHOLDER); + this->shape_editor->unset_item(); + this->shape_editor->set_item(selection->singleItem()); } void RectTool::setup() { @@ -113,7 +113,7 @@ void RectTool::setup() { SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); if (item) { - this->shape_editor->set_item(item, SH_KNOTHOLDER); + this->shape_editor->set_item(item); } this->sel_changed_connection.disconnect(); diff --git a/src/ui/tools/spiral-tool.cpp b/src/ui/tools/spiral-tool.cpp index 5ae229df8..83712457a 100644 --- a/src/ui/tools/spiral-tool.cpp +++ b/src/ui/tools/spiral-tool.cpp @@ -104,8 +104,8 @@ SpiralTool::~SpiralTool() { * destroys old and creates new knotholder. */ void SpiralTool::selection_changed(Inkscape::Selection *selection) { - this->shape_editor->unset_item(SH_KNOTHOLDER); - this->shape_editor->set_item(selection->singleItem(), SH_KNOTHOLDER); + this->shape_editor->unset_item(); + this->shape_editor->set_item(selection->singleItem()); } void SpiralTool::setup() { @@ -119,7 +119,7 @@ void SpiralTool::setup() { SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); if (item) { - this->shape_editor->set_item(item, SH_KNOTHOLDER); + this->shape_editor->set_item(item); } Inkscape::Selection *selection = sp_desktop_selection(this->desktop); diff --git a/src/ui/tools/star-tool.cpp b/src/ui/tools/star-tool.cpp index 68f998920..ed28c0a8d 100644 --- a/src/ui/tools/star-tool.cpp +++ b/src/ui/tools/star-tool.cpp @@ -112,8 +112,8 @@ StarTool::~StarTool() { void StarTool::selection_changed(Inkscape::Selection* selection) { g_assert (selection != NULL); - this->shape_editor->unset_item(SH_KNOTHOLDER); - this->shape_editor->set_item(selection->singleItem(), SH_KNOTHOLDER); + this->shape_editor->unset_item(); + this->shape_editor->set_item(selection->singleItem()); } void StarTool::setup() { @@ -129,7 +129,7 @@ void StarTool::setup() { SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); if (item) { - this->shape_editor->set_item(item, SH_KNOTHOLDER); + this->shape_editor->set_item(item); } Inkscape::Selection *selection = sp_desktop_selection(this->desktop); diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp index ac830fe6b..b60a39e5d 100644 --- a/src/ui/tools/text-tool.cpp +++ b/src/ui/tools/text-tool.cpp @@ -177,7 +177,7 @@ void TextTool::setup() { SPItem *item = sp_desktop_selection(this->desktop)->singleItem(); if (item && SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) { - this->shape_editor->set_item(item, SH_KNOTHOLDER); + this->shape_editor->set_item(item); } this->sel_changed_connection = sp_desktop_selection(desktop)->connectChangedFirst( @@ -1411,10 +1411,10 @@ void TextTool::_selectionChanged(Inkscape::Selection *selection) ToolBase *ec = SP_EVENT_CONTEXT(this); - ec->shape_editor->unset_item(SH_KNOTHOLDER); + ec->shape_editor->unset_item(); SPItem *item = selection->singleItem(); if (item && SP_IS_FLOWTEXT(item) && SP_FLOWTEXT(item)->has_internal_frame()) { - ec->shape_editor->set_item(item, SH_KNOTHOLDER); + ec->shape_editor->set_item(item); } if (this->text && (item != this->text)) { |
