diff --git a/src/common-context.cpp b/src/common-context.cpp
index a52e83c22fce6bbfa730ce64fd7c64e5e53bae8e..d20b43b1234e602bd1ea820996702016336253a8 100644 (file)
--- a/src/common-context.cpp
+++ b/src/common-context.cpp
#include "forward.h"
#include "message-context.h"
+#include "streq.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_setup(SPEventContext */*ec*/)
+static void sp_common_context_setup(SPEventContext *ec)
{
+ if ( common_parent_class->setup ) {
+ common_parent_class->setup(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, gchar const *key, gchar const *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 );
+ }
}
-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;
}
/*