summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbulia byak <buliabyak@gmail.com>2006-04-12 17:16:28 +0000
committerbuliabyak <buliabyak@users.sourceforge.net>2006-04-12 17:16:28 +0000
commit4fdf3f76b0203a79b24febeafc2311b85bdcfa76 (patch)
tree416226ddec29976768f8e18326f5cd23202bde74 /src
parentadd some includes (diff)
downloadinkscape-4fdf3f76b0203a79b24febeafc2311b85bdcfa76.tar.gz
inkscape-4fdf3f76b0203a79b24febeafc2311b85bdcfa76.zip
remove the old _d_changed and _typestr_changed hacks, replacing by an int-valued local_change flag; this works much faster with less code
(bzr r495)
Diffstat (limited to 'src')
-rw-r--r--src/node-context.cpp16
-rw-r--r--src/nodepath.cpp68
-rw-r--r--src/nodepath.h3
3 files changed, 19 insertions, 68 deletions
diff --git a/src/node-context.cpp b/src/node-context.cpp
index ccdb6c79e..1e01b1af9 100644
--- a/src/node-context.cpp
+++ b/src/node-context.cpp
@@ -310,7 +310,6 @@ nodepath_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
bool is_interactive, gpointer data)
{
SPItem *item = NULL;
- char const *newd = NULL, *newtypestr = NULL;
gboolean changed = FALSE;
g_assert(data);
@@ -322,21 +321,18 @@ nodepath_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
if (np) {
item = SP_ITEM(np->path);
- if (!strcmp(name, "d")) {
- newd = new_value;
- changed = nodepath_repr_d_changed(np, new_value);
- } else if (!strcmp(name, "sodipodi:nodetypes")) {
- newtypestr = new_value;
- changed = nodepath_repr_typestr_changed(np, new_value);
- } else {
- return;
- // With paths, we only need to act if one of the path-affecting attributes has changed.
+ if (!strcmp(name, "d") || !strcmp(name, "sodipodi:nodetypes")) { // With paths, we only need to act if one of the path-affecting attributes has changed.
+ changed = (np->local_change == 0);
+ if (np->local_change > 0)
+ np->local_change--;
}
+
} else if (kh) {
item = SP_ITEM(kh->item);
changed = !(kh->local_change);
kh->local_change = FALSE;
}
+
if (np && changed) {
GList *saved = NULL;
SPDesktop *desktop = np->desktop;
diff --git a/src/nodepath.cpp b/src/nodepath.cpp
index 97be9355c..b50ee90c7 100644
--- a/src/nodepath.cpp
+++ b/src/nodepath.cpp
@@ -182,6 +182,7 @@ Inkscape::NodePath::Path *sp_nodepath_new(SPDesktop *desktop, SPItem *item)
np->selected = NULL;
np->nodeContext = NULL; //Let the context that makes this set it
np->livarot_path = NULL;
+ np->local_change = 0;
// we need to update item's transform from the repr here,
// because they may be out of sync when we respond
@@ -294,62 +295,6 @@ static void sp_nodepath_cleanup(Inkscape::NodePath::Path *nodepath)
g_list_free(badSubPaths);
}
-
-
-/**
- * \brief Returns true if the argument nodepath and the d attribute in
- * its repr do not match.
- *
- * This may happen if repr was changed in, e.g., XML editor or by undo.
- *
- * \todo
- * UGLY HACK, think how we can eliminate it. IDEA: try instead a local_change flag in node context?
- */
-gboolean nodepath_repr_d_changed(Inkscape::NodePath::Path *np, char const *newd)
-{
- g_assert(np);
-
- SPCurve *curve = create_curve(np);
-
- gchar *svgpath = sp_svg_write_path(curve->bpath);
-
- char const *attr_d = ( newd
- ? newd
- : SP_OBJECT(np->path)->repr->attribute("d") );
-
- gboolean ret;
- if (attr_d && svgpath)
- ret = strcmp(attr_d, svgpath);
- else
- ret = TRUE;
-
- g_free(svgpath);
- sp_curve_unref(curve);
-
- return ret;
-}
-
-/**
- * \brief Returns true if the argument nodepath and the sodipodi:nodetypes
- * attribute in its repr do not match.
- *
- * This may happen if repr was changed in, e.g., the XML editor or by undo.
- * IDEA: try instead a local_change flag in node context?
- */
-gboolean nodepath_repr_typestr_changed(Inkscape::NodePath::Path *np, char const *newtypestr)
-{
- g_assert(np);
- gchar *typestr = create_typestr(np);
- char const *attr_typestr = ( newtypestr
- ? newtypestr
- : SP_OBJECT(np->path)->repr->attribute("sodipodi:nodetypes") );
- gboolean const ret = (attr_typestr && strcmp(attr_typestr, typestr));
-
- g_free(typestr);
-
- return ret;
-}
-
/**
* Create new nodepath from b, make it subpath of np.
* \param t The node type.
@@ -465,8 +410,15 @@ static void update_repr_internal(Inkscape::NodePath::Path *np)
gchar *typestr = create_typestr(np);
gchar *svgpath = sp_svg_write_path(curve->bpath);
- repr->setAttribute("d", svgpath);
- repr->setAttribute("sodipodi:nodetypes", typestr);
+ if (repr->attribute("d") == NULL || strcmp(svgpath, repr->attribute("d"))) { // d changed
+ np->local_change++;
+ repr->setAttribute("d", svgpath);
+ }
+
+ if (repr->attribute("sodipodi:nodetypes") == NULL || strcmp(typestr, repr->attribute("sodipodi:nodetypes"))) { // nodetypes changed
+ np->local_change++;
+ repr->setAttribute("sodipodi:nodetypes", typestr);
+ }
g_free(svgpath);
g_free(typestr);
diff --git a/src/nodepath.h b/src/nodepath.h
index aaa488cf3..656d64ebb 100644
--- a/src/nodepath.h
+++ b/src/nodepath.h
@@ -130,6 +130,9 @@ class Path {
/// livarot library is used for "point on path" and "nearest position on path", so we need to maintain its path representation as well
::Path *livarot_path;
+
+ /// true if we changed repr, to tell this change from an external one such as from undo, simplify, or another desktop
+ uint local_change;
};