Code

Translations. French translation minor update.
[inkscape.git] / src / common-context.cpp
index d20b43b1234e602bd1ea820996702016336253a8..08bac0152fab10992d0dcaff98a2978de910f82d 100644 (file)
@@ -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);
 
@@ -82,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;
@@ -154,51 +155,39 @@ 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 = 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();
     }
 }
 
@@ -227,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 :