From 62dd6c138e3547689acdcccbb289d822b458cdb0 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sat, 9 Jun 2012 14:40:09 +0100 Subject: Stop deriving SPCanvasItem from GtkObject (bzr r11469.1.1) --- src/common-context.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/common-context.cpp') diff --git a/src/common-context.cpp b/src/common-context.cpp index 467d19f72..9ced41a26 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -8,6 +8,7 @@ #include "message-context.h" #include "streq.h" #include "preferences.h" +#include "display/sp-canvas-item.h" #define MIN_PRESSURE 0.0 #define MAX_PRESSURE 1.0 @@ -116,7 +117,7 @@ static void sp_common_context_dispose(GObject *object) } while (ctx->segments) { - gtk_object_destroy(GTK_OBJECT(ctx->segments->data)); + sp_canvas_item_destroy(SP_CANVAS_ITEM(ctx->segments->data)); ctx->segments = g_slist_remove(ctx->segments, ctx->segments->data); } @@ -134,7 +135,7 @@ static void sp_common_context_dispose(GObject *object) } if (ctx->currentshape) { - gtk_object_destroy(GTK_OBJECT(ctx->currentshape)); + sp_canvas_item_destroy(ctx->currentshape); ctx->currentshape = 0; } -- cgit v1.2.3 From f8a5b66bb57495c83274218dc98530a071b10f27 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sun, 11 Nov 2012 11:20:05 +0000 Subject: cppcheck: Convert more C-style pointer casts to GObject or C++ (bzr r11867) --- src/common-context.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/common-context.cpp') diff --git a/src/common-context.cpp b/src/common-context.cpp index 9ced41a26..9d5dbb048 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -56,9 +56,9 @@ GType sp_common_context_get_type(void) static void sp_common_context_class_init(SPCommonContextClass *klass) { GObjectClass *object_class = (GObjectClass *) klass; - SPEventContextClass *event_context_class = (SPEventContextClass *) klass; + SPEventContextClass *event_context_class = SP_EVENT_CONTEXT_CLASS(klass); - common_parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass); + common_parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); object_class->dispose = sp_common_context_dispose; -- cgit v1.2.3 From 55b2e59196c6e980bdb3f03379de6707dd91082b Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sat, 26 Jan 2013 16:18:08 +0000 Subject: More GObject boilerplate reduction (bzr r12064) --- src/common-context.cpp | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) (limited to 'src/common-context.cpp') diff --git a/src/common-context.cpp b/src/common-context.cpp index 9d5dbb048..ff99b5c0b 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -19,8 +19,6 @@ #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); @@ -28,38 +26,13 @@ static void sp_common_context_set(SPEventContext *ec, Inkscape::Preferences::Ent static gint sp_common_context_root_handler(SPEventContext *event_context, GdkEvent *event); - -static SPEventContextClass *common_parent_class = 0; - -GType sp_common_context_get_type(void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPCommonContextClass), - 0, // base_init - 0, // base_finalize - (GClassInitFunc)sp_common_context_class_init, - 0, // class_finalize - 0, // class_data - sizeof(SPCommonContext), - 0, // n_preallocs - (GInstanceInitFunc)sp_common_context_init, - 0 // value_table - }; - type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPCommonContext", &info, static_cast(0)); - } - return type; -} - +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); - common_parent_class = SP_EVENT_CONTEXT_CLASS(g_type_class_peek_parent(klass)); - object_class->dispose = sp_common_context_dispose; event_context_class->setup = sp_common_context_setup; @@ -144,14 +117,14 @@ static void sp_common_context_dispose(GObject *object) ctx->_message_context = 0; } - G_OBJECT_CLASS(common_parent_class)->dispose(object); + G_OBJECT_CLASS(sp_common_context_parent_class)->dispose(object); } static void sp_common_context_setup(SPEventContext *ec) { - if ( common_parent_class->setup ) { - common_parent_class->setup(ec); + if ( SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->setup ) { + SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->setup(ec); } } @@ -199,8 +172,8 @@ static gint sp_common_context_root_handler(SPEventContext *event_context, GdkEve if ( !ret ) { - if ( common_parent_class->root_handler ) { - ret = common_parent_class->root_handler(event_context, event); + 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); } } -- cgit v1.2.3 From e58cac52b258e64c2cc88b0044bf9cfbaecedce2 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 9 Apr 2013 00:23:07 +0200 Subject: Started conversion of SPEventContext tree; added virtual pads to all classes. (bzr r11608.1.89) --- src/common-context.cpp | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'src/common-context.cpp') diff --git a/src/common-context.cpp b/src/common-context.cpp index ff99b5c0b..39a0d7cde 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -40,8 +40,16 @@ static void sp_common_context_class_init(SPCommonContextClass *klass) event_context_class->root_handler = sp_common_context_root_handler; } +CCommonContext::CCommonContext(SPCommonContext* commoncontext) : CEventContext(commoncontext) { + this->spcommoncontext = commoncontext; +} + static void sp_common_context_init(SPCommonContext *ctx) { + ctx->ccommoncontext = new CCommonContext(ctx); + delete ctx->ceventcontext; + ctx->ceventcontext = ctx->ccommoncontext; + // ctx->cursor_shape = cursor_eraser_xpm; // ctx->hot_x = 4; // ctx->hot_y = 4; @@ -123,13 +131,24 @@ static void sp_common_context_dispose(GObject *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); - } + ec->ceventcontext->setup(); +} + +void CCommonContext::setup() { +// if ( SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->setup ) { +// SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->setup(ec); +// } + CEventContext::setup(); } static void sp_common_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *value) { + ec->ceventcontext->set(value); +} + +void CCommonContext::set(Inkscape::Preferences::Entry* value) { + SPEventContext* ec = this->speventcontext; + SPCommonContext *ctx = SP_COMMON_CONTEXT(ec); Glib::ustring path = value->getEntryName(); @@ -166,15 +185,22 @@ static void sp_common_context_set(SPEventContext *ec, Inkscape::Preferences::Ent static gint sp_common_context_root_handler(SPEventContext *event_context, GdkEvent *event) { + return event_context->ceventcontext->root_handler(event); +} + +gint CCommonContext::root_handler(GdkEvent* event) { + SPEventContext* event_context = this->speventcontext; + gint ret = FALSE; // TODO add common hanlding 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); - } +// 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); +// } + ret = CEventContext::root_handler(event); } return ret; -- cgit v1.2.3 From 1d8f1753cd8cab38d19fcc26a4ad70ba2e794ac8 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 9 Apr 2013 22:12:07 +0200 Subject: Added constructors to EventContext tree / some missing virtual pads. (bzr r11608.1.90) --- src/common-context.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/common-context.cpp') diff --git a/src/common-context.cpp b/src/common-context.cpp index 39a0d7cde..1feb6ee95 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -35,21 +35,30 @@ static void sp_common_context_class_init(SPCommonContextClass *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; +// 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; } CCommonContext::CCommonContext(SPCommonContext* commoncontext) : CEventContext(commoncontext) { this->spcommoncontext = commoncontext; } -static void sp_common_context_init(SPCommonContext *ctx) -{ +SPCommonContext::SPCommonContext() : SPEventContext() { + SPCommonContext* ctx = this; + ctx->ccommoncontext = new CCommonContext(ctx); delete ctx->ceventcontext; ctx->ceventcontext = ctx->ccommoncontext; + ctx->_message_context = 0; + ctx->tremor = 0; + ctx->usetilt = 0; + ctx->is_drawing = false; + ctx->xtilt = 0; + ctx->ytilt = 0; + ctx->usepressure = 0; + // ctx->cursor_shape = cursor_eraser_xpm; // ctx->hot_x = 4; // ctx->hot_y = 4; @@ -88,6 +97,11 @@ static void sp_common_context_init(SPCommonContext *ctx) ctx->abs_width = false; } +static void sp_common_context_init(SPCommonContext *ctx) +{ + new (ctx) SPCommonContext(); +} + static void sp_common_context_dispose(GObject *object) { SPCommonContext *ctx = SP_COMMON_CONTEXT(object); -- cgit v1.2.3 From fbdc8b84ff670c684dafc7d7d403ed01e7077e70 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 13 Apr 2013 18:13:17 +0200 Subject: Replaced casting macros for EventContext tree; added contructors. (bzr r11608.1.96) --- src/common-context.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/common-context.cpp') diff --git a/src/common-context.cpp b/src/common-context.cpp index 1feb6ee95..fb0ddb720 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -47,9 +47,11 @@ CCommonContext::CCommonContext(SPCommonContext* commoncontext) : CEventContext(c SPCommonContext::SPCommonContext() : SPEventContext() { SPCommonContext* ctx = this; - ctx->ccommoncontext = new CCommonContext(ctx); - delete ctx->ceventcontext; - ctx->ceventcontext = ctx->ccommoncontext; + //ctx->ccommoncontext = new CCommonContext(ctx); + //delete ctx->ceventcontext; + //ctx->ceventcontext = ctx->ccommoncontext; + ctx->ccommoncontext = 0; + types.insert(typeid(SPCommonContext)); ctx->_message_context = 0; ctx->tremor = 0; -- cgit v1.2.3 From 65ba6ad9a82f8f47974eb10665478fd783692bb5 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 20 Apr 2013 23:19:46 +0200 Subject: Merging of EventContext classes complete. (bzr r11608.1.98) --- src/common-context.cpp | 89 +++----------------------------------------------- 1 file changed, 5 insertions(+), 84 deletions(-) (limited to 'src/common-context.cpp') diff --git a/src/common-context.cpp b/src/common-context.cpp index fb0ddb720..4d2125f91 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -18,41 +18,9 @@ #define DRAG_DEFAULT 1.0 #define DRAG_MAX 1.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; -} - -CCommonContext::CCommonContext(SPCommonContext* commoncontext) : CEventContext(commoncontext) { - this->spcommoncontext = commoncontext; -} - SPCommonContext::SPCommonContext() : SPEventContext() { SPCommonContext* ctx = this; - //ctx->ccommoncontext = new CCommonContext(ctx); - //delete ctx->ceventcontext; - //ctx->ceventcontext = ctx->ccommoncontext; - ctx->ccommoncontext = 0; - types.insert(typeid(SPCommonContext)); - ctx->_message_context = 0; ctx->tremor = 0; ctx->usetilt = 0; @@ -99,14 +67,8 @@ SPCommonContext::SPCommonContext() : SPEventContext() { ctx->abs_width = false; } -static void sp_common_context_init(SPCommonContext *ctx) -{ - new (ctx) SPCommonContext(); -} - -static void sp_common_context_dispose(GObject *object) -{ - SPCommonContext *ctx = SP_COMMON_CONTEXT(object); +SPCommonContext::~SPCommonContext() { + SPCommonContext *ctx = SP_COMMON_CONTEXT(this); if (ctx->accumulated) { ctx->accumulated = ctx->accumulated->unref(); @@ -141,29 +103,11 @@ static void sp_common_context_dispose(GObject *object) ctx->_message_context = 0; } - G_OBJECT_CLASS(sp_common_context_parent_class)->dispose(object); + //G_OBJECT_CLASS(sp_common_context_parent_class)->dispose(object); } - -static void sp_common_context_setup(SPEventContext *ec) -{ - ec->ceventcontext->setup(); -} - -void CCommonContext::setup() { -// if ( SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->setup ) { -// SP_EVENT_CONTEXT_CLASS(sp_common_context_parent_class)->setup(ec); -// } - CEventContext::setup(); -} - -static void sp_common_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *value) -{ - ec->ceventcontext->set(value); -} - -void CCommonContext::set(Inkscape::Preferences::Entry* value) { - SPEventContext* ec = this->speventcontext; +void SPCommonContext::set(Inkscape::Preferences::Entry* value) { + SPEventContext* ec = this; SPCommonContext *ctx = SP_COMMON_CONTEXT(ec); Glib::ustring path = value->getEntryName(); @@ -199,29 +143,6 @@ void CCommonContext::set(Inkscape::Preferences::Entry* value) { } } -static gint sp_common_context_root_handler(SPEventContext *event_context, GdkEvent *event) -{ - return event_context->ceventcontext->root_handler(event); -} - -gint CCommonContext::root_handler(GdkEvent* event) { - SPEventContext* event_context = this->speventcontext; - - gint ret = FALSE; - - // TODO add common hanlding - - - 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); -// } - ret = CEventContext::root_handler(event); - } - - return ret; -} - /* Local Variables: mode:c++ -- cgit v1.2.3 From bdde74bbab299f2ee448f1c55469c56a66fb01f7 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 21 Apr 2013 23:58:15 +0200 Subject: Removed some unused files; more refactoring in EventContext tree. (bzr r11608.1.104) --- src/common-context.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/common-context.cpp') diff --git a/src/common-context.cpp b/src/common-context.cpp index 4d2125f91..5ccbaaf5a 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -106,40 +106,40 @@ SPCommonContext::~SPCommonContext() { //G_OBJECT_CLASS(sp_common_context_parent_class)->dispose(object); } -void SPCommonContext::set(Inkscape::Preferences::Entry* value) { +void SPCommonContext::set(const Inkscape::Preferences::Entry& value) { SPEventContext* ec = this; SPCommonContext *ctx = SP_COMMON_CONTEXT(ec); - Glib::ustring path = value->getEntryName(); + 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(); + 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); + ctx->mass = 0.01 * CLAMP(value.getInt(10), 0, 100); } else if (path == "wiggle") { - ctx->drag = CLAMP((1 - 0.01 * value->getInt()), + 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); + ctx->angle = CLAMP(value.getDouble(), -90, 90); } else if (path == "width") { - ctx->width = 0.01 * CLAMP(value->getInt(10), 1, 100); + 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); + ctx->vel_thin = 0.01 * CLAMP(value.getInt(10), -100, 100); } else if (path == "tremor") { - ctx->tremor = 0.01 * CLAMP(value->getInt(), 0, 100); + ctx->tremor = 0.01 * CLAMP(value.getInt(), 0, 100); } else if (path == "flatness") { - ctx->flatness = 0.01 * CLAMP(value->getInt(), 0, 100); + ctx->flatness = 0.01 * CLAMP(value.getInt(), 0, 100); } else if (path == "usepressure") { - ctx->usepressure = value->getBool(); + ctx->usepressure = value.getBool(); } else if (path == "usetilt") { - ctx->usetilt = value->getBool(); + ctx->usetilt = value.getBool(); } else if (path == "abs_width") { - ctx->abs_width = value->getBool(); + ctx->abs_width = value.getBool(); } else if (path == "cap_rounding") { - ctx->cap_rounding = value->getDouble(); + ctx->cap_rounding = value.getDouble(); } } -- cgit v1.2.3 From b2dd3583e7372d23d18bbc6e861f4f645ec3dc37 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Tue, 30 Jul 2013 23:17:21 +0200 Subject: Further refactoring of EventContexts. (bzr r11608.1.109) --- src/common-context.cpp | 164 +++++++++++++++++++++++++++---------------------- 1 file changed, 90 insertions(+), 74 deletions(-) (limited to 'src/common-context.cpp') diff --git a/src/common-context.cpp b/src/common-context.cpp index 5ccbaaf5a..e6b82cf82 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 @@ -19,130 +20,145 @@ #define DRAG_MAX 1.0 SPCommonContext::SPCommonContext() : SPEventContext() { - SPCommonContext* ctx = this; - - ctx->_message_context = 0; - ctx->tremor = 0; - ctx->usetilt = 0; - ctx->is_drawing = false; - ctx->xtilt = 0; - ctx->ytilt = 0; - ctx->usepressure = 0; + this->_message_context = 0; + this->tremor = 0; + this->usetilt = 0; + this->is_drawing = false; + this->xtilt = 0; + this->ytilt = 0; + this->usepressure = 0; // 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; } SPCommonContext::~SPCommonContext() { - SPCommonContext *ctx = SP_COMMON_CONTEXT(this); - - if (ctx->accumulated) { - ctx->accumulated = ctx->accumulated->unref(); - ctx->accumulated = 0; + 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 (this->currentcurve) { + this->currentcurve = this->currentcurve->unref(); + this->currentcurve = 0; } - if (ctx->cal1) { - ctx->cal1 = ctx->cal1->unref(); - ctx->cal1 = 0; + + if (this->cal1) { + this->cal1 = this->cal1->unref(); + this->cal1 = 0; } - if (ctx->cal2) { - ctx->cal2 = ctx->cal2->unref(); - ctx->cal2 = 0; + + if (this->cal2) { + this->cal2 = this->cal2->unref(); + this->cal2 = 0; } - if (ctx->currentshape) { - sp_canvas_item_destroy(ctx->currentshape); - ctx->currentshape = 0; + if (this->currentshape) { + sp_canvas_item_destroy(this->currentshape); + this->currentshape = 0; } - if (ctx->_message_context) { - delete ctx->_message_context; - ctx->_message_context = 0; + if (this->_message_context) { + delete this->_message_context; + this->_message_context = 0; } //G_OBJECT_CLASS(sp_common_context_parent_class)->dispose(object); } void SPCommonContext::set(const Inkscape::Preferences::Entry& value) { - SPEventContext* ec = this; - - 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"; + 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 (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(); } } +/* 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] ); + + 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(); + + double const max = MAX ( drect.dimensions()[Geom::X], drect.dimensions()[Geom::Y] ); + + return Geom::Point(n[Geom::X] * max + drect.min()[Geom::X], n[Geom::Y] * max + drect.min()[Geom::Y]); +} + /* Local Variables: mode:c++ -- cgit v1.2.3 From 989abbac025a8b3349748d19a613a08586c5fdcd Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Wed, 31 Jul 2013 21:11:20 +0200 Subject: Fixed SPObject ctor and dtor; removed singleton.h; some smaller changes. (bzr r11608.1.110) --- src/common-context.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'src/common-context.cpp') diff --git a/src/common-context.cpp b/src/common-context.cpp index e6b82cf82..fb984cbf1 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -20,7 +20,6 @@ #define DRAG_MAX 1.0 SPCommonContext::SPCommonContext() : SPEventContext() { - this->_message_context = 0; this->tremor = 0; this->usetilt = 0; this->is_drawing = false; @@ -96,13 +95,6 @@ SPCommonContext::~SPCommonContext() { sp_canvas_item_destroy(this->currentshape); this->currentshape = 0; } - - if (this->_message_context) { - delete this->_message_context; - this->_message_context = 0; - } - - //G_OBJECT_CLASS(sp_common_context_parent_class)->dispose(object); } void SPCommonContext::set(const Inkscape::Preferences::Entry& value) { -- cgit v1.2.3 From d3f86d34d0d92505a798f8c9b83ca12dfcbf50ab Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sun, 13 Oct 2013 17:24:57 +0200 Subject: cppcheck (bzr r12680) --- src/common-context.cpp | 79 ++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 44 deletions(-) (limited to 'src/common-context.cpp') diff --git a/src/common-context.cpp b/src/common-context.cpp index fb984cbf1..2155f9739 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -19,50 +19,41 @@ #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; - -// ctx->cursor_shape = cursor_eraser_xpm; -// ctx->hot_x = 4; -// ctx->hot_y = 4; - - 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 */ - 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 */ - this->dragging = FALSE; - - this->mass = 0.3; - this->drag = DRAG_DEFAULT; - this->angle = 30.0; - this->width = 0.2; - this->pressure = DEFAULT_PRESSURE; - - this->vel_thin = 0.1; - this->flatness = 0.9; - this->cap_rounding = 0.0; - - this->abs_width = false; +SPCommonContext::SPCommonContext() : + SPEventContext(), + accumulated(NULL), + segments(NULL), + currentshape(NULL), + currentcurve(NULL), + cal1(NULL), + cal2(NULL), + point1(), + point2(), + repr(NULL), + cur(0,0), + vel(0,0), + vel_max(0), + acc(0,0), + ang(0,0), + last(0,0), + del(0,0), + pressure(DEFAULT_PRESSURE), + xtilt(0), + ytilt(0), + dragging(FALSE), + usepressure(FALSE), + usetilt(FALSE), + mass(0.3), + drag(DRAG_DEFAULT), + angle(30.0), + width(0.2), + vel_thin(0.1), + flatness(0.9), + tremor(0), + cap_rounding(0), + is_drawing(false), + abs_width(false) +{ } SPCommonContext::~SPCommonContext() { -- cgit v1.2.3 From 55b451bf382e0c3d5ed8728e42fbb535acfa8a33 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Thu, 7 Nov 2013 21:44:00 +0100 Subject: First step of moving tools into appropriate namespaces. (bzr r12782) --- src/common-context.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/common-context.cpp') diff --git a/src/common-context.cpp b/src/common-context.cpp index 2155f9739..e896d0829 100644 --- a/src/common-context.cpp +++ b/src/common-context.cpp @@ -19,8 +19,12 @@ #define DRAG_DEFAULT 1.0 #define DRAG_MAX 1.0 +namespace Inkscape { +namespace UI { +namespace Tools { + SPCommonContext::SPCommonContext() : - SPEventContext(), + ToolBase(), accumulated(NULL), segments(NULL), currentshape(NULL), @@ -142,6 +146,10 @@ Geom::Point SPCommonContext::getViewPoint(Geom::Point n) const { return Geom::Point(n[Geom::X] * max + drect.min()[Geom::X], n[Geom::Y] * max + drect.min()[Geom::Y]); } +} +} +} + /* Local Variables: mode:c++ -- cgit v1.2.3 From c04e30df241a3ee039077425bab9b9c37abe2854 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 9 Nov 2013 23:36:13 +0100 Subject: Moved and renamed some tool-related files. (bzr r12785) --- src/common-context.cpp | 162 ------------------------------------------------- 1 file changed, 162 deletions(-) delete mode 100644 src/common-context.cpp (limited to 'src/common-context.cpp') diff --git a/src/common-context.cpp b/src/common-context.cpp deleted file mode 100644 index e896d0829..000000000 --- a/src/common-context.cpp +++ /dev/null @@ -1,162 +0,0 @@ - -#include "common-context.h" - -#include - -#include "config.h" - -#include "message-context.h" -#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 -#define DEFAULT_PRESSURE 1.0 - -#define DRAG_MIN 0.0 -#define DRAG_DEFAULT 1.0 -#define DRAG_MAX 1.0 - -namespace Inkscape { -namespace UI { -namespace Tools { - -SPCommonContext::SPCommonContext() : - ToolBase(), - accumulated(NULL), - segments(NULL), - currentshape(NULL), - currentcurve(NULL), - cal1(NULL), - cal2(NULL), - point1(), - point2(), - repr(NULL), - cur(0,0), - vel(0,0), - vel_max(0), - acc(0,0), - ang(0,0), - last(0,0), - del(0,0), - pressure(DEFAULT_PRESSURE), - xtilt(0), - ytilt(0), - dragging(FALSE), - usepressure(FALSE), - usetilt(FALSE), - mass(0.3), - drag(DRAG_DEFAULT), - angle(30.0), - width(0.2), - vel_thin(0.1), - flatness(0.9), - tremor(0), - cap_rounding(0), - is_drawing(false), - abs_width(false) -{ -} - -SPCommonContext::~SPCommonContext() { - if (this->accumulated) { - this->accumulated = this->accumulated->unref(); - this->accumulated = 0; - } - - while (this->segments) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(this->segments->data)); - this->segments = g_slist_remove(this->segments, this->segments->data); - } - - if (this->currentcurve) { - this->currentcurve = this->currentcurve->unref(); - this->currentcurve = 0; - } - - if (this->cal1) { - this->cal1 = this->cal1->unref(); - this->cal1 = 0; - } - - if (this->cal2) { - this->cal2 = this->cal2->unref(); - this->cal2 = 0; - } - - if (this->currentshape) { - sp_canvas_item_destroy(this->currentshape); - this->currentshape = 0; - } -} - -void SPCommonContext::set(const Inkscape::Preferences::Entry& value) { - Glib::ustring path = value.getEntryName(); - - // ignore preset modifications - 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") { - this->mass = 0.01 * CLAMP(value.getInt(10), 0, 100); - } else if (path == "wiggle") { - this->drag = CLAMP((1 - 0.01 * value.getInt()), DRAG_MIN, DRAG_MAX); // drag is inverse to wiggle - } else if (path == "angle") { - this->angle = CLAMP(value.getDouble(), -90, 90); - } else if (path == "width") { - this->width = 0.01 * CLAMP(value.getInt(10), 1, 100); - } else if (path == "thinning") { - this->vel_thin = 0.01 * CLAMP(value.getInt(10), -100, 100); - } else if (path == "tremor") { - this->tremor = 0.01 * CLAMP(value.getInt(), 0, 100); - } else if (path == "flatness") { - this->flatness = 0.01 * CLAMP(value.getInt(), 0, 100); - } else if (path == "usepressure") { - this->usepressure = value.getBool(); - } else if (path == "usetilt") { - this->usetilt = value.getBool(); - } else if (path == "abs_width") { - this->abs_width = value.getBool(); - } else if (path == "cap_rounding") { - this->cap_rounding = value.getDouble(); - } -} - -/* 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] ); - - 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(); - - double const max = MAX ( drect.dimensions()[Geom::X], drect.dimensions()[Geom::Y] ); - - return Geom::Point(n[Geom::X] * max + drect.min()[Geom::X], n[Geom::Y] * max + drect.min()[Geom::Y]); -} - -} -} -} - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3