X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fcommon-context.cpp;h=08bac0152fab10992d0dcaff98a2978de910f82d;hb=3410aa1a9f9cb90fe886b982d114e213d3d1fc03;hp=c28e704ee789f7ee3ede1b0b90db17684137dcd3;hpb=d892789c74d4ab69585c6487a763f755ee659a94;p=inkscape.git diff --git a/src/common-context.cpp b/src/common-context.cpp index c28e704ee..08bac0152 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -7,6 +7,8 @@ #include "forward.h" #include "message-context.h" +#include "streq.h" +#include "preferences.h" #define MIN_PRESSURE 0.0 #define MAX_PRESSURE 1.0 @@ -22,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); @@ -81,13 +83,13 @@ static void sp_common_context_init(SPCommonContext *ctx) ctx->repr = 0; /* Common values */ - ctx->cur = NR::Point(0,0); - ctx->last = NR::Point(0,0); - ctx->vel = NR::Point(0,0); + ctx->cur = Geom::Point(0,0); + ctx->last = Geom::Point(0,0); + ctx->vel = Geom::Point(0,0); ctx->vel_max = 0; - ctx->acc = NR::Point(0,0); - ctx->ang = NR::Point(0,0); - ctx->del = NR::Point(0,0); + ctx->acc = Geom::Point(0,0); + ctx->ang = Geom::Point(0,0); + ctx->del = Geom::Point(0,0); /* attributes */ ctx->dragging = FALSE; @@ -153,40 +155,39 @@ 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 *value) { SPCommonContext *ctx = SP_COMMON_CONTEXT(ec); - - if (!strcmp(key, "mass")) { - double const dval = ( value ? g_ascii_strtod (value, NULL) : 0.2 ); - ctx->mass = CLAMP(dval, -1000.0, 1000.0); - } else if (!strcmp(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 (!strcmp(key, "angle")) { - double const dval = ( value ? g_ascii_strtod (value, NULL) : 0.0); - ctx->angle = CLAMP (dval, -90, 90); - } else if (!strcmp(key, "width")) { - double const dval = ( value ? g_ascii_strtod (value, NULL) : 0.1 ); - ctx->width = CLAMP(dval, -1000.0, 1000.0); - } else if (!strcmp(key, "thinning")) { - double const dval = ( value ? g_ascii_strtod (value, NULL) : 0.1 ); - ctx->vel_thin = CLAMP(dval, -1.0, 1.0); - } else if (!strcmp(key, "tremor")) { - double const dval = ( value ? g_ascii_strtod (value, NULL) : 0.0 ); - ctx->tremor = CLAMP(dval, 0.0, 1.0); - } else if (!strcmp(key, "flatness")) { - double const dval = ( value ? g_ascii_strtod (value, NULL) : 1.0 ); - ctx->flatness = CLAMP(dval, 0, 1.0); - } else if (!strcmp(key, "usepressure")) { - ctx->usepressure = ( value && strcmp(value, "0")); - } else if (!strcmp(key, "usetilt")) { - ctx->usetilt = ( value && strcmp(value, "0")); - } else if (!strcmp(key, "abs_width")) { - ctx->abs_width = ( value && strcmp(value, "0")); - } else if (!strcmp(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 = 0.01 * CLAMP(value->getInt(10), 0, 100); + } else if (path == "wiggle") { + ctx->drag = CLAMP((1 - 0.01 * value->getInt()), + 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 = 0.01 * CLAMP(value->getInt(10), 1, 100); + } else if (path == "thinning") { + ctx->vel_thin = 0.01 * CLAMP(value->getInt(10), -100, 100); + } else if (path == "tremor") { + ctx->tremor = 0.01 * CLAMP(value->getInt(), 0, 100); + } else if (path == "flatness") { + ctx->flatness = 0.01 * CLAMP(value->getInt(), 0, 100); + } 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(); } } @@ -215,4 +216,4 @@ static gint sp_common_context_root_handler(SPEventContext *event_context, GdkEve fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :