From: joncruz Date: Mon, 2 Jun 2008 07:01:30 +0000 (+0000) Subject: Pass through more calls to parent contexts, and added more common property handling. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=d892789c74d4ab69585c6487a763f755ee659a94;p=inkscape.git Pass through more calls to parent contexts, and added more common property handling. Fixes bug #236667 and issues with middle-drag and ctrl-arrow. --- diff --git a/src/common-context.cpp b/src/common-context.cpp index a52e83c22..c28e704ee 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -8,11 +8,14 @@ #include "forward.h" #include "message-context.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); @@ -143,18 +146,64 @@ 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, gchar const *key, gchar const *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 ); + } } -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; } /* diff --git a/src/dyna-draw-context.cpp b/src/dyna-draw-context.cpp index 9f759558c..7f3c41c2e 100644 --- a/src/dyna-draw-context.cpp +++ b/src/dyna-draw-context.cpp @@ -79,9 +79,6 @@ #define DYNA_MIN_WIDTH 1.0e-6 -#define DRAG_MIN 0.0 -#define DRAG_DEFAULT 1.0 -#define DRAG_MAX 1.0 // FIXME: move it to some shared file to be reused by both calligraphy and dropper #define C1 0.552 @@ -258,39 +255,15 @@ sp_dyna_draw_context_set(SPEventContext *ec, gchar const *key, gchar const *val) { SPDynaDrawContext *ddc = SP_DYNA_DRAW_CONTEXT(ec); - if (!strcmp(key, "mass")) { - double const dval = ( val ? g_ascii_strtod (val, NULL) : 0.2 ); - ddc->mass = CLAMP(dval, -1000.0, 1000.0); - } else if (!strcmp(key, "wiggle")) { - double const dval = ( val ? g_ascii_strtod (val, NULL) : (1 - DRAG_DEFAULT)); - ddc->drag = CLAMP((1 - dval), DRAG_MIN, DRAG_MAX); // drag is inverse to wiggle - } else if (!strcmp(key, "angle")) { - double const dval = ( val ? g_ascii_strtod (val, NULL) : 0.0); - ddc->angle = CLAMP (dval, -90, 90); - } else if (!strcmp(key, "width")) { - double const dval = ( val ? g_ascii_strtod (val, NULL) : 0.1 ); - ddc->width = CLAMP(dval, -1000.0, 1000.0); - } else if (!strcmp(key, "thinning")) { - double const dval = ( val ? g_ascii_strtod (val, NULL) : 0.1 ); - ddc->vel_thin = CLAMP(dval, -1.0, 1.0); - } else if (!strcmp(key, "tremor")) { - double const dval = ( val ? g_ascii_strtod (val, NULL) : 0.0 ); - ddc->tremor = CLAMP(dval, 0.0, 1.0); - } else if (!strcmp(key, "flatness")) { - double const dval = ( val ? g_ascii_strtod (val, NULL) : 1.0 ); - ddc->flatness = CLAMP(dval, 0, 1.0); - } else if (!strcmp(key, "tracebackground")) { + if (!strcmp(key, "tracebackground")) { ddc->trace_bg = (val && strcmp(val, "0")); - } else if (!strcmp(key, "usepressure")) { - ddc->usepressure = (val && strcmp(val, "0")); - } else if (!strcmp(key, "usetilt")) { - ddc->usetilt = (val && strcmp(val, "0")); - } else if (!strcmp(key, "abs_width")) { - ddc->abs_width = (val && strcmp(val, "0")); } else if (!strcmp(key, "keep_selected")) { ddc->keep_selected = (val && strcmp(val, "0")); - } else if (!strcmp(key, "cap_rounding")) { - ddc->cap_rounding = ( val ? g_ascii_strtod (val, NULL) : 0.0 ); + } else { + //pass on up to parent class to handle common attributes. + if ( dd_parent_class->set ) { + dd_parent_class->set(ec, key, val); + } } //g_print("DDC: %g %g %g %g\n", ddc->mass, ddc->drag, ddc->angle, ddc->width); diff --git a/src/eraser-context.cpp b/src/eraser-context.cpp index 1920baed5..88496b065 100644 --- a/src/eraser-context.cpp +++ b/src/eraser-context.cpp @@ -218,40 +218,10 @@ static ProfileFloatElement f_profile[PROFILE_FLOAT_SIZE] = { static void sp_eraser_context_set(SPEventContext *ec, gchar const *key, gchar const *val) { - SPEraserContext *erc = SP_ERASER_CONTEXT(ec); - - if (!strcmp(key, "mass")) { - double const dval = ( val ? g_ascii_strtod (val, NULL) : 0.2 ); - erc->mass = CLAMP(dval, -1000.0, 1000.0); - } else if (!strcmp(key, "wiggle")) { - double const dval = ( val ? g_ascii_strtod (val, NULL) : (1 - DRAG_DEFAULT)); - erc->drag = CLAMP((1 - dval), DRAG_MIN, DRAG_MAX); // drag is inverse to wiggle - } else if (!strcmp(key, "angle")) { - double const dval = ( val ? g_ascii_strtod (val, NULL) : 0.0); - erc->angle = CLAMP (dval, -90, 90); - } else if (!strcmp(key, "width")) { - double const dval = ( val ? g_ascii_strtod (val, NULL) : 0.1 ); - erc->width = CLAMP(dval, -1000.0, 1000.0); - } else if (!strcmp(key, "thinning")) { - double const dval = ( val ? g_ascii_strtod (val, NULL) : 0.1 ); - erc->vel_thin = CLAMP(dval, -1.0, 1.0); - } else if (!strcmp(key, "tremor")) { - double const dval = ( val ? g_ascii_strtod (val, NULL) : 0.0 ); - erc->tremor = CLAMP(dval, 0.0, 1.0); - } else if (!strcmp(key, "flatness")) { - double const dval = ( val ? g_ascii_strtod (val, NULL) : 1.0 ); - erc->flatness = CLAMP(dval, 0, 1.0); - } else if (!strcmp(key, "usepressure")) { - erc->usepressure = (val && strcmp(val, "0")); - } else if (!strcmp(key, "usetilt")) { - erc->usetilt = (val && strcmp(val, "0")); - } else if (!strcmp(key, "abs_width")) { - erc->abs_width = (val && strcmp(val, "0")); - } else if (!strcmp(key, "cap_rounding")) { - erc->cap_rounding = ( val ? g_ascii_strtod (val, NULL) : 0.0 ); + //pass on up to parent class to handle common attributes. + if ( eraser_parent_class->set ) { + eraser_parent_class->set(ec, key, val); } - - //g_print("ERC: %g %g %g %g\n", erc->mass, erc->drag, erc->angle, erc->width); } static double