summaryrefslogtreecommitdiffstats
path: root/src/shape-editor.cpp
diff options
context:
space:
mode:
authorLiam P. White <inkscapebrony@gmail.com>2014-07-26 17:11:51 +0000
committerLiam P. White <inkscapebrony@gmail.com>2014-07-26 17:11:51 +0000
commitcc73219a498e87298578996011b80680214f7a96 (patch)
tree40d0e91da69ff1ceafe2bc9377cdfc137174fafb /src/shape-editor.cpp
parentRead HSL color (CSS Color Module Level 3). (diff)
downloadinkscape-cc73219a498e87298578996011b80680214f7a96.tar.gz
inkscape-cc73219a498e87298578996011b80680214f7a96.zip
Clean up some ShapeHolder related things
(bzr r13341.1.100)
Diffstat (limited to 'src/shape-editor.cpp')
-rw-r--r--src/shape-editor.cpp202
1 files changed, 59 insertions, 143 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.
*/