diff options
| author | Ted Gould <ted@gould.cx> | 2008-10-27 18:03:09 +0000 |
|---|---|---|
| committer | Ted Gould <ted@canonical.com> | 2008-10-27 18:03:09 +0000 |
| commit | 7dbe11bc23efa5f51a9b84e7d0f6dd16e63e0902 (patch) | |
| tree | 7d3a2b95b84a03a19cb132cdf88bea0ab6dc4773 /src/common-context.cpp | |
| parent | Merging from trunk (diff) | |
| download | inkscape-7dbe11bc23efa5f51a9b84e7d0f6dd16e63e0902.tar.gz inkscape-7dbe11bc23efa5f51a9b84e7d0f6dd16e63e0902.zip | |
From trunk
(bzr r6885)
Diffstat (limited to 'src/common-context.cpp')
| -rw-r--r-- | src/common-context.cpp | 76 |
1 files changed, 32 insertions, 44 deletions
diff --git a/src/common-context.cpp b/src/common-context.cpp index eab50b478..48a7f308c 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -8,6 +8,7 @@ #include "forward.h" #include "message-context.h" #include "streq.h" +#include "preferences.h" #define MIN_PRESSURE 0.0 #define MAX_PRESSURE 1.0 @@ -23,7 +24,7 @@ static void sp_common_context_init(SPCommonContext *erc); static void sp_common_context_dispose(GObject *object); static void sp_common_context_setup(SPEventContext *ec); -static void sp_common_context_set(SPEventContext *ec, gchar const *key, gchar const *value); +static void sp_common_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val); static gint sp_common_context_root_handler(SPEventContext *event_context, GdkEvent *event); @@ -154,51 +155,38 @@ static void sp_common_context_setup(SPEventContext *ec) } } -static inline bool -get_bool_value(char const *const val) -{ - return ( val && *val == '1' ); - /* The only possible values if written by inkscape are NULL (attribute not present) - * or "0" or "1". - * - * For other values (e.g. if modified by a human without following the above rules), the - * current implementation does the right thing for empty string, "no", "false", "n", "f" - * but the wrong thing for "yes", "true", "y", "t". */ -} - -static void sp_common_context_set(SPEventContext *ec, gchar const *key, gchar const *value) +static void sp_common_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *value) { SPCommonContext *ctx = SP_COMMON_CONTEXT(ec); - - if (streq(key, "mass")) { - double const dval = ( value ? g_ascii_strtod (value, NULL) : 0.2 ); - ctx->mass = CLAMP(dval, -1000.0, 1000.0); - } else if (streq(key, "wiggle")) { - double const dval = ( value ? g_ascii_strtod (value, NULL) : (1 - DRAG_DEFAULT)); - ctx->drag = CLAMP((1 - dval), DRAG_MIN, DRAG_MAX); // drag is inverse to wiggle - } else if (streq(key, "angle")) { - double const dval = ( value ? g_ascii_strtod (value, NULL) : 0.0); - ctx->angle = CLAMP (dval, -90, 90); - } else if (streq(key, "width")) { - double const dval = ( value ? g_ascii_strtod (value, NULL) : 0.1 ); - ctx->width = CLAMP(dval, -1000.0, 1000.0); - } else if (streq(key, "thinning")) { - double const dval = ( value ? g_ascii_strtod (value, NULL) : 0.1 ); - ctx->vel_thin = CLAMP(dval, -1.0, 1.0); - } else if (streq(key, "tremor")) { - double const dval = ( value ? g_ascii_strtod (value, NULL) : 0.0 ); - ctx->tremor = CLAMP(dval, 0.0, 1.0); - } else if (streq(key, "flatness")) { - double const dval = ( value ? g_ascii_strtod (value, NULL) : 1.0 ); - ctx->flatness = CLAMP(dval, 0, 1.0); - } else if (streq(key, "usepressure")) { - ctx->usepressure = get_bool_value(value); - } else if (streq(key, "usetilt")) { - ctx->usetilt = get_bool_value(value); - } else if (streq(key, "abs_width")) { - ctx->abs_width = get_bool_value(value); - } else if (streq(key, "cap_rounding")) { - ctx->cap_rounding = ( value ? g_ascii_strtod (value, NULL) : 0.0 ); + Glib::ustring path = value->getEntryName(); + + // ignore preset modifications + static Glib::ustring const presets_path = ec->pref_observer->observed_path + "/preset"; + Glib::ustring const &full_path = value->getPath(); + if (full_path.compare(0, presets_path.size(), presets_path) == 0) return; + + if (path == "mass") { + ctx->mass = CLAMP(value->getDouble(0.2), -1000.0, 1000.0); + } else if (path == "wiggle") { + ctx->drag = CLAMP((1 - value->getDouble(1 - DRAG_DEFAULT)), DRAG_MIN, DRAG_MAX); // drag is inverse to wiggle + } else if (path == "angle") { + ctx->angle = CLAMP(value->getDouble(), -90, 90); + } else if (path == "width") { + ctx->width = CLAMP(value->getDouble(0.1), -1000.0, 1000.0); + } else if (path == "thinning") { + ctx->vel_thin = CLAMP(value->getDouble(0.1), -1.0, 1.0); + } else if (path == "tremor") { + ctx->tremor = CLAMP(value->getDouble(), 0.0, 1.0); + } else if (path == "flatness") { + ctx->flatness = CLAMP(value->getDouble(1.0), 0, 1.0); + } else if (path == "usepressure") { + ctx->usepressure = value->getBool(); + } else if (path == "usetilt") { + ctx->usetilt = value->getBool(); + } else if (path == "abs_width") { + ctx->abs_width = value->getBool(); + } else if (path == "cap_rounding") { + ctx->cap_rounding = value->getDouble(); } } |
