diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2013-09-19 22:33:11 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2013-09-19 22:33:11 +0000 |
| commit | 4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7 (patch) | |
| tree | caeb924426bcc861badc6fa81318b67460b26d47 /src/common-context.cpp | |
| parent | Update to trunk (diff) | |
| parent | updates for cmake (diff) | |
| download | inkscape-4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7.tar.gz inkscape-4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7.zip | |
Update to trunk
(bzr r11950.1.141)
Diffstat (limited to 'src/common-context.cpp')
| -rw-r--r-- | src/common-context.cpp | 195 |
1 files changed, 83 insertions, 112 deletions
diff --git a/src/common-context.cpp b/src/common-context.cpp index ff99b5c0b..fb984cbf1 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -9,6 +9,7 @@ #include "streq.h" #include "preferences.h" #include "display/sp-canvas-item.h" +#include "desktop.h" #define MIN_PRESSURE 0.0 #define MAX_PRESSURE 1.0 @@ -18,166 +19,136 @@ #define DRAG_DEFAULT 1.0 #define DRAG_MAX 1.0 +SPCommonContext::SPCommonContext() : SPEventContext() { + this->tremor = 0; + this->usetilt = 0; + this->is_drawing = false; + this->xtilt = 0; + this->ytilt = 0; + this->usepressure = 0; -static void sp_common_context_dispose(GObject *object); - -static void sp_common_context_setup(SPEventContext *ec); -static void sp_common_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val); - -static gint sp_common_context_root_handler(SPEventContext *event_context, GdkEvent *event); - -G_DEFINE_TYPE(SPCommonContext, sp_common_context, SP_TYPE_EVENT_CONTEXT); - -static void sp_common_context_class_init(SPCommonContextClass *klass) -{ - GObjectClass *object_class = (GObjectClass *) klass; - SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - - object_class->dispose = sp_common_context_dispose; - - event_context_class->setup = sp_common_context_setup; - event_context_class->set = sp_common_context_set; - event_context_class->root_handler = sp_common_context_root_handler; -} - -static void sp_common_context_init(SPCommonContext *ctx) -{ // ctx->cursor_shape = cursor_eraser_xpm; // ctx->hot_x = 4; // ctx->hot_y = 4; - ctx->accumulated = 0; - ctx->segments = 0; - ctx->currentcurve = 0; - ctx->currentshape = 0; - ctx->npoints = 0; - ctx->cal1 = 0; - ctx->cal2 = 0; - ctx->repr = 0; + this->accumulated = 0; + this->segments = 0; + this->currentcurve = 0; + this->currentshape = 0; + this->npoints = 0; + this->cal1 = 0; + this->cal2 = 0; + this->repr = 0; /* Common values */ - ctx->cur = Geom::Point(0,0); - ctx->last = Geom::Point(0,0); - ctx->vel = Geom::Point(0,0); - ctx->vel_max = 0; - ctx->acc = Geom::Point(0,0); - ctx->ang = Geom::Point(0,0); - ctx->del = Geom::Point(0,0); + this->cur = Geom::Point(0,0); + this->last = Geom::Point(0,0); + this->vel = Geom::Point(0,0); + this->vel_max = 0; + this->acc = Geom::Point(0,0); + this->ang = Geom::Point(0,0); + this->del = Geom::Point(0,0); /* attributes */ - ctx->dragging = FALSE; + this->dragging = FALSE; - ctx->mass = 0.3; - ctx->drag = DRAG_DEFAULT; - ctx->angle = 30.0; - ctx->width = 0.2; - ctx->pressure = DEFAULT_PRESSURE; + this->mass = 0.3; + this->drag = DRAG_DEFAULT; + this->angle = 30.0; + this->width = 0.2; + this->pressure = DEFAULT_PRESSURE; - ctx->vel_thin = 0.1; - ctx->flatness = 0.9; - ctx->cap_rounding = 0.0; + this->vel_thin = 0.1; + this->flatness = 0.9; + this->cap_rounding = 0.0; - ctx->abs_width = false; + this->abs_width = false; } -static void sp_common_context_dispose(GObject *object) -{ - SPCommonContext *ctx = SP_COMMON_CONTEXT(object); - - if (ctx->accumulated) { - ctx->accumulated = ctx->accumulated->unref(); - ctx->accumulated = 0; +SPCommonContext::~SPCommonContext() { + if (this->accumulated) { + this->accumulated = this->accumulated->unref(); + this->accumulated = 0; } - while (ctx->segments) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(ctx->segments->data)); - ctx->segments = g_slist_remove(ctx->segments, ctx->segments->data); + while (this->segments) { + sp_canvas_item_destroy(SP_CANVAS_ITEM(this->segments->data)); + this->segments = g_slist_remove(this->segments, this->segments->data); } - if (ctx->currentcurve) { - ctx->currentcurve = ctx->currentcurve->unref(); - ctx->currentcurve = 0; - } - if (ctx->cal1) { - ctx->cal1 = ctx->cal1->unref(); - ctx->cal1 = 0; - } - if (ctx->cal2) { - ctx->cal2 = ctx->cal2->unref(); - ctx->cal2 = 0; + if (this->currentcurve) { + this->currentcurve = this->currentcurve->unref(); + this->currentcurve = 0; } - if (ctx->currentshape) { - sp_canvas_item_destroy(ctx->currentshape); - ctx->currentshape = 0; + if (this->cal1) { + this->cal1 = this->cal1->unref(); + this->cal1 = 0; } - if (ctx->_message_context) { - delete ctx->_message_context; - ctx->_message_context = 0; + if (this->cal2) { + this->cal2 = this->cal2->unref(); + this->cal2 = 0; } - G_OBJECT_CLASS(sp_common_context_parent_class)->dispose(object); -} - - -static void sp_common_context_setup(SPEventContext *ec) -{ - if ( SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->setup ) { - SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->setup(ec); + if (this->currentshape) { + sp_canvas_item_destroy(this->currentshape); + this->currentshape = 0; } } -static void sp_common_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *value) -{ - SPCommonContext *ctx = SP_COMMON_CONTEXT(ec); - Glib::ustring path = value->getEntryName(); +void SPCommonContext::set(const Inkscape::Preferences::Entry& value) { + 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; + static Glib::ustring const presets_path = this->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); + this->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 + this->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); + this->angle = CLAMP(value.getDouble(), -90, 90); } else if (path == "width") { - ctx->width = 0.01 * CLAMP(value->getInt(10), 1, 100); + this->width = 0.01 * CLAMP(value.getInt(10), 1, 100); } else if (path == "thinning") { - ctx->vel_thin = 0.01 * CLAMP(value->getInt(10), -100, 100); + this->vel_thin = 0.01 * CLAMP(value.getInt(10), -100, 100); } else if (path == "tremor") { - ctx->tremor = 0.01 * CLAMP(value->getInt(), 0, 100); + this->tremor = 0.01 * CLAMP(value.getInt(), 0, 100); } else if (path == "flatness") { - ctx->flatness = 0.01 * CLAMP(value->getInt(), 0, 100); + this->flatness = 0.01 * CLAMP(value.getInt(), 0, 100); } else if (path == "usepressure") { - ctx->usepressure = value->getBool(); + this->usepressure = value.getBool(); } else if (path == "usetilt") { - ctx->usetilt = value->getBool(); + this->usetilt = value.getBool(); } else if (path == "abs_width") { - ctx->abs_width = value->getBool(); + this->abs_width = value.getBool(); } else if (path == "cap_rounding") { - ctx->cap_rounding = value->getDouble(); + this->cap_rounding = value.getDouble(); } } -static gint sp_common_context_root_handler(SPEventContext *event_context, GdkEvent *event) -{ - gint ret = FALSE; +/* Get normalized point */ +Geom::Point SPCommonContext::getNormalizedPoint(Geom::Point v) const { + Geom::Rect drect = this->desktop->get_display_area(); + + double const max = MAX ( drect.dimensions()[Geom::X], drect.dimensions()[Geom::Y] ); - // TODO add common hanlding + return Geom::Point(( v[Geom::X] - drect.min()[Geom::X] ) / max, ( v[Geom::Y] - drect.min()[Geom::Y] ) / max); +} +/* Get view point */ +Geom::Point SPCommonContext::getViewPoint(Geom::Point n) const { + Geom::Rect drect = this->desktop->get_display_area(); - if ( !ret ) { - if ( SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->root_handler ) { - ret = SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->root_handler(event_context, event); - } - } + double const max = MAX ( drect.dimensions()[Geom::X], drect.dimensions()[Geom::Y] ); - return ret; + return Geom::Point(n[Geom::X] * max + drect.min()[Geom::X], n[Geom::Y] * max + drect.min()[Geom::Y]); } /* |
