Code

Translations. French translation minor update.
[inkscape.git] / src / common-context.cpp
index a52e83c22fce6bbfa730ce64fd7c64e5e53bae8e..08bac0152fab10992d0dcaff98a2978de910f82d 100644 (file)
@@ -7,19 +7,24 @@
 
 #include "forward.h"
 #include "message-context.h"
+#include "streq.h"
+#include "preferences.h"
 
-#define DRAG_DEFAULT 1.0
 #define MIN_PRESSURE      0.0
 #define MAX_PRESSURE      1.0
 #define DEFAULT_PRESSURE  1.0
 
+#define DRAG_MIN 0.0
+#define DRAG_DEFAULT 1.0
+#define DRAG_MAX 1.0
+
 
 static void sp_common_context_class_init(SPCommonContextClass *klass);
 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);
 
@@ -78,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;
@@ -143,18 +148,63 @@ static void sp_common_context_dispose(GObject *object)
 }
 
 
-static void sp_common_context_setup(SPEventContext */*ec*/)
+static void sp_common_context_setup(SPEventContext *ec)
 {
+    if ( common_parent_class->setup ) {
+        common_parent_class->setup(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);
+    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();
+    }
 }
 
-static gint sp_common_context_root_handler(SPEventContext */*event_context*/, GdkEvent */*event*/)
+static gint sp_common_context_root_handler(SPEventContext *event_context, GdkEvent *event)
 {
-  return 0;
+    gint ret = FALSE;
+
+    // TODO add common hanlding
+
+
+    if ( !ret ) {
+        if ( common_parent_class->root_handler ) {
+            ret = common_parent_class->root_handler(event_context, event);
+        }
+    }
+
+    return ret;
 }
 
 /*
@@ -166,4 +216,4 @@ static gint sp_common_context_root_handler(SPEventContext */*event_context*/, Gd
   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 :