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/pencil-context.cpp | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'src/pencil-context.cpp') diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index 090a43a25..eefa30ad6 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -88,12 +88,21 @@ sp_pencil_context_class_init(SPPencilContextClass *klass) event_context_class->root_handler = sp_pencil_context_root_handler; } +CPencilContext::CPencilContext(SPPencilContext* pencilcontext) : CDrawContext(pencilcontext) { + this->sppencilcontext = pencilcontext; +} + /** * Callback to initialize SPPencilContext object. */ static void sp_pencil_context_init(SPPencilContext *pc) { + pc->cpencilcontext = new CPencilContext(pc); + delete pc->cdrawcontext; + pc->cdrawcontext = pc->cpencilcontext; + pc->ceventcontext = pc->cpencilcontext; + SPEventContext *event_context = SP_EVENT_CONTEXT(pc); event_context->cursor_shape = cursor_pencil_xpm; @@ -115,14 +124,21 @@ sp_pencil_context_init(SPPencilContext *pc) static void sp_pencil_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CPencilContext::setup() { + SPEventContext* ec = this->speventcontext; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/freehand/pencil/selcue")) { ec->enableSelectionCue(); } - if (((SPEventContextClass *) sp_pencil_context_parent_class)->setup) { - ((SPEventContextClass *) sp_pencil_context_parent_class)->setup(ec); - } +// if (((SPEventContextClass *) sp_pencil_context_parent_class)->setup) { +// ((SPEventContextClass *) sp_pencil_context_parent_class)->setup(ec); +// } + CDrawContext::setup(); SPPencilContext *const pc = SP_PENCIL_CONTEXT(ec); pc->is_drawing = false; @@ -160,6 +176,12 @@ spdc_endpoint_snap(SPPencilContext const *pc, Geom::Point &p, guint const state) gint sp_pencil_context_root_handler(SPEventContext *const ec, GdkEvent *event) { + return ec->ceventcontext->root_handler(event); +} + +gint CPencilContext::root_handler(GdkEvent* event) { + SPEventContext* ec = this->speventcontext; + SPPencilContext *const pc = SP_PENCIL_CONTEXT(ec); gint ret = FALSE; @@ -190,11 +212,12 @@ sp_pencil_context_root_handler(SPEventContext *const ec, GdkEvent *event) } if (!ret) { - gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) - = ((SPEventContextClass *) sp_pencil_context_parent_class)->root_handler; - if (parent_root_handler) { - ret = parent_root_handler(ec, event); - } +// gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) +// = ((SPEventContextClass *) sp_pencil_context_parent_class)->root_handler; +// if (parent_root_handler) { +// ret = parent_root_handler(ec, event); +// } + ret = CDrawContext::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/pencil-context.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/pencil-context.cpp') diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index eefa30ad6..47580b4d2 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -84,25 +84,24 @@ sp_pencil_context_class_init(SPPencilContextClass *klass) object_class->dispose = sp_pencil_context_dispose; - event_context_class->setup = sp_pencil_context_setup; - event_context_class->root_handler = sp_pencil_context_root_handler; +// event_context_class->setup = sp_pencil_context_setup; +// event_context_class->root_handler = sp_pencil_context_root_handler; } CPencilContext::CPencilContext(SPPencilContext* pencilcontext) : CDrawContext(pencilcontext) { this->sppencilcontext = pencilcontext; } -/** - * Callback to initialize SPPencilContext object. - */ -static void -sp_pencil_context_init(SPPencilContext *pc) -{ +SPPencilContext::SPPencilContext() : SPDrawContext() { + SPPencilContext* pc = this; + pc->cpencilcontext = new CPencilContext(pc); delete pc->cdrawcontext; pc->cdrawcontext = pc->cpencilcontext; pc->ceventcontext = pc->cpencilcontext; + pc->is_drawing = false; + SPEventContext *event_context = SP_EVENT_CONTEXT(pc); event_context->cursor_shape = cursor_pencil_xpm; @@ -118,6 +117,15 @@ sp_pencil_context_init(SPPencilContext *pc) pc->sketch_n = 0; } +/** + * Callback to initialize SPPencilContext object. + */ +static void +sp_pencil_context_init(SPPencilContext *pc) +{ + new (pc) SPPencilContext(); +} + /** * Callback to setup SPPencilContext object. */ -- cgit v1.2.3 From fbb85064cfaaf03cc09bacedb16a8561f61f2b3d Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 13 Apr 2013 00:37:18 +0200 Subject: Added prefPaths to contexts; modified SPFactory (bzr r11608.1.94) --- src/pencil-context.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/pencil-context.cpp') diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index 47580b4d2..0b3955a0c 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -68,6 +68,8 @@ static bool pencil_within_tolerance = false; static bool in_svg_plane(Geom::Point const &p) { return Geom::LInfty(p) < 1e18; } +const std::string SPPencilContext::prefsPath = "/tools/freehand/pencil"; + G_DEFINE_TYPE(SPPencilContext, sp_pencil_context, SP_TYPE_DRAW_CONTEXT); /** -- 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/pencil-context.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/pencil-context.cpp') diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index 0b3955a0c..3c2269bd2 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -68,6 +68,20 @@ static bool pencil_within_tolerance = false; static bool in_svg_plane(Geom::Point const &p) { return Geom::LInfty(p) < 1e18; } +#include "sp-factory.h" + +namespace { + SPEventContext* createPencilContext() { + return new SPPencilContext(); + } + + bool pencilContextRegistered = ToolFactory::instance().registerObject("/tools/freehand/pencil", createPencilContext); +} + +const std::string& CPencilContext::getPrefsPath() { + return SPPencilContext::prefsPath; +} + const std::string SPPencilContext::prefsPath = "/tools/freehand/pencil"; G_DEFINE_TYPE(SPPencilContext, sp_pencil_context, SP_TYPE_DRAW_CONTEXT); @@ -101,6 +115,7 @@ SPPencilContext::SPPencilContext() : SPDrawContext() { delete pc->cdrawcontext; pc->cdrawcontext = pc->cpencilcontext; pc->ceventcontext = pc->cpencilcontext; + types.insert(typeid(SPPencilContext)); pc->is_drawing = false; -- 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/pencil-context.cpp | 77 ++++++-------------------------------------------- 1 file changed, 8 insertions(+), 69 deletions(-) (limited to 'src/pencil-context.cpp') diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index 3c2269bd2..e13e6985c 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -45,10 +45,6 @@ #include "display/curve.h" #include "livarot/Path.h" -static void sp_pencil_context_setup(SPEventContext *ec); -static void sp_pencil_context_dispose(GObject *object); - -static gint sp_pencil_context_root_handler(SPEventContext *event_context, GdkEvent *event); static gint pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &bevent); static gint pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mevent); static gint pencil_handle_button_release(SPPencilContext *const pc, GdkEventButton const &revent); @@ -78,45 +74,15 @@ namespace { bool pencilContextRegistered = ToolFactory::instance().registerObject("/tools/freehand/pencil", createPencilContext); } -const std::string& CPencilContext::getPrefsPath() { +const std::string& SPPencilContext::getPrefsPath() { return SPPencilContext::prefsPath; } const std::string SPPencilContext::prefsPath = "/tools/freehand/pencil"; -G_DEFINE_TYPE(SPPencilContext, sp_pencil_context, SP_TYPE_DRAW_CONTEXT); - -/** - * Initialize SPPencilContext vtable. - */ -static void -sp_pencil_context_class_init(SPPencilContextClass *klass) -{ - GObjectClass *object_class; - SPEventContextClass *event_context_class; - - object_class = (GObjectClass *) klass; - event_context_class = (SPEventContextClass *) klass; - - object_class->dispose = sp_pencil_context_dispose; - -// event_context_class->setup = sp_pencil_context_setup; -// event_context_class->root_handler = sp_pencil_context_root_handler; -} - -CPencilContext::CPencilContext(SPPencilContext* pencilcontext) : CDrawContext(pencilcontext) { - this->sppencilcontext = pencilcontext; -} - SPPencilContext::SPPencilContext() : SPDrawContext() { SPPencilContext* pc = this; - pc->cpencilcontext = new CPencilContext(pc); - delete pc->cdrawcontext; - pc->cdrawcontext = pc->cpencilcontext; - pc->ceventcontext = pc->cpencilcontext; - types.insert(typeid(SPPencilContext)); - pc->is_drawing = false; SPEventContext *event_context = SP_EVENT_CONTEXT(pc); @@ -134,26 +100,8 @@ SPPencilContext::SPPencilContext() : SPDrawContext() { pc->sketch_n = 0; } -/** - * Callback to initialize SPPencilContext object. - */ -static void -sp_pencil_context_init(SPPencilContext *pc) -{ - new (pc) SPPencilContext(); -} - -/** - * Callback to setup SPPencilContext object. - */ -static void -sp_pencil_context_setup(SPEventContext *ec) -{ - ec->ceventcontext->setup(); -} - -void CPencilContext::setup() { - SPEventContext* ec = this->speventcontext; +void SPPencilContext::setup() { + SPEventContext* ec = this; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/freehand/pencil/selcue")) { @@ -163,7 +111,7 @@ void CPencilContext::setup() { // if (((SPEventContextClass *) sp_pencil_context_parent_class)->setup) { // ((SPEventContextClass *) sp_pencil_context_parent_class)->setup(ec); // } - CDrawContext::setup(); + SPDrawContext::setup(); SPPencilContext *const pc = SP_PENCIL_CONTEXT(ec); pc->is_drawing = false; @@ -171,10 +119,7 @@ void CPencilContext::setup() { pc->anchor_statusbar = false; } -static void -sp_pencil_context_dispose(GObject *object) -{ - G_OBJECT_CLASS(sp_pencil_context_parent_class)->dispose(object); +SPPencilContext::~SPPencilContext() { } /** Snaps new node relative to the previous node. */ @@ -198,14 +143,8 @@ spdc_endpoint_snap(SPPencilContext const *pc, Geom::Point &p, guint const state) /** * Callback for handling all pencil context events. */ -gint -sp_pencil_context_root_handler(SPEventContext *const ec, GdkEvent *event) -{ - return ec->ceventcontext->root_handler(event); -} - -gint CPencilContext::root_handler(GdkEvent* event) { - SPEventContext* ec = this->speventcontext; +gint SPPencilContext::root_handler(GdkEvent* event) { + SPEventContext* ec = this; SPPencilContext *const pc = SP_PENCIL_CONTEXT(ec); @@ -242,7 +181,7 @@ gint CPencilContext::root_handler(GdkEvent* event) { // if (parent_root_handler) { // ret = parent_root_handler(ec, event); // } - ret = CDrawContext::root_handler(event); + ret = SPDrawContext::root_handler(event); } return ret; -- cgit v1.2.3 From 5512f857e2f33f1aa40124dc82b353e5f2e5a0b0 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 20 Apr 2013 23:58:53 +0200 Subject: Moved factories to different files. (bzr r11608.1.100) --- src/pencil-context.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pencil-context.cpp') diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index e13e6985c..28ae41974 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -64,7 +64,7 @@ static bool pencil_within_tolerance = false; static bool in_svg_plane(Geom::Point const &p) { return Geom::LInfty(p) < 1e18; } -#include "sp-factory.h" +#include "tool-factory.h" namespace { SPEventContext* createPencilContext() { -- 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/pencil-context.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pencil-context.cpp') diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index 28ae41974..b81580f3a 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -143,7 +143,7 @@ spdc_endpoint_snap(SPPencilContext const *pc, Geom::Point &p, guint const state) /** * Callback for handling all pencil context events. */ -gint SPPencilContext::root_handler(GdkEvent* event) { +bool SPPencilContext::root_handler(GdkEvent* event) { SPEventContext* ec = this; SPPencilContext *const pc = SP_PENCIL_CONTEXT(ec); -- 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/pencil-context.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/pencil-context.cpp') diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index b81580f3a..c7257ff10 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -198,7 +198,7 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(dc); Inkscape::Selection *selection = sp_desktop_selection(desktop); - if (Inkscape::have_viable_layer(desktop, dc->_message_context) == false) { + if (Inkscape::have_viable_layer(desktop, dc->message_context) == false) { return TRUE; } @@ -359,21 +359,21 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev } if (anchor && !pc->anchor_statusbar) { - pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("Release here to close and finish the path.")); + pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("Release here to close and finish the path.")); pc->anchor_statusbar = true; } else if (!anchor && pc->anchor_statusbar) { - pc->_message_context->clear(); + pc->message_context->clear(); pc->anchor_statusbar = false; } else if (!anchor) { - pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("Drawing a freehand path")); + pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("Drawing a freehand path")); } } else { if (anchor && !pc->anchor_statusbar) { - pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("Drag to continue the path from this point.")); + pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("Drag to continue the path from this point.")); pc->anchor_statusbar = true; } else if (!anchor && pc->anchor_statusbar) { - pc->_message_context->clear(); + pc->message_context->clear(); pc->anchor_statusbar = false; } } @@ -517,8 +517,8 @@ pencil_cancel (SPPencilContext *const pc) pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor); } - pc->_message_context->clear(); - pc->_message_context->flash(Inkscape::NORMAL_MESSAGE, _("Drawing cancelled")); + pc->message_context->clear(); + pc->message_context->flash(Inkscape::NORMAL_MESSAGE, _("Drawing cancelled")); pc->desktop->canvas->endForcedFullRedraws(); } -- cgit v1.2.3 From ef3c72e61987caa06a105c70cec83089892581ed Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 4 Aug 2013 15:09:03 +0200 Subject: Cleaned up once more. (bzr r11608.1.118) --- src/pencil-context.cpp | 54 ++++++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 37 deletions(-) (limited to 'src/pencil-context.cpp') diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index c7257ff10..94310ea31 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -81,42 +81,31 @@ const std::string& SPPencilContext::getPrefsPath() { const std::string SPPencilContext::prefsPath = "/tools/freehand/pencil"; SPPencilContext::SPPencilContext() : SPDrawContext() { - SPPencilContext* pc = this; + this->is_drawing = false; - pc->is_drawing = false; + this->cursor_shape = cursor_pencil_xpm; + this->hot_x = 4; + this->hot_y = 4; - SPEventContext *event_context = SP_EVENT_CONTEXT(pc); - - event_context->cursor_shape = cursor_pencil_xpm; - event_context->hot_x = 4; - event_context->hot_y = 4; - - pc->npoints = 0; - pc->state = SP_PENCIL_CONTEXT_IDLE; - pc->req_tangent = Geom::Point(0, 0); + this->npoints = 0; + this->state = SP_PENCIL_CONTEXT_IDLE; + this->req_tangent = Geom::Point(0, 0); // since SPPencilContext is not properly constructed... - pc->sketch_interpolation = Geom::Piecewise >(); - pc->sketch_n = 0; + this->sketch_interpolation = Geom::Piecewise >(); + this->sketch_n = 0; } void SPPencilContext::setup() { - SPEventContext* ec = this; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/freehand/pencil/selcue")) { - ec->enableSelectionCue(); + this->enableSelectionCue(); } -// if (((SPEventContextClass *) sp_pencil_context_parent_class)->setup) { -// ((SPEventContextClass *) sp_pencil_context_parent_class)->setup(ec); -// } SPDrawContext::setup(); - SPPencilContext *const pc = SP_PENCIL_CONTEXT(ec); - pc->is_drawing = false; - - pc->anchor_statusbar = false; + this->is_drawing = false; + this->anchor_statusbar = false; } SPPencilContext::~SPPencilContext() { @@ -144,31 +133,27 @@ spdc_endpoint_snap(SPPencilContext const *pc, Geom::Point &p, guint const state) * Callback for handling all pencil context events. */ bool SPPencilContext::root_handler(GdkEvent* event) { - SPEventContext* ec = this; - - SPPencilContext *const pc = SP_PENCIL_CONTEXT(ec); - gint ret = FALSE; switch (event->type) { case GDK_BUTTON_PRESS: - ret = pencil_handle_button_press(pc, event->button); + ret = pencil_handle_button_press(this, event->button); break; case GDK_MOTION_NOTIFY: - ret = pencil_handle_motion_notify(pc, event->motion); + ret = pencil_handle_motion_notify(this, event->motion); break; case GDK_BUTTON_RELEASE: - ret = pencil_handle_button_release(pc, event->button); + ret = pencil_handle_button_release(this, event->button); break; case GDK_KEY_PRESS: - ret = pencil_handle_key_press(pc, get_group0_keyval (&event->key), event->key.state); + ret = pencil_handle_key_press(this, get_group0_keyval (&event->key), event->key.state); break; case GDK_KEY_RELEASE: - ret = pencil_handle_key_release(pc, get_group0_keyval (&event->key), event->key.state); + ret = pencil_handle_key_release(this, get_group0_keyval (&event->key), event->key.state); break; default: @@ -176,11 +161,6 @@ bool SPPencilContext::root_handler(GdkEvent* event) { } if (!ret) { -// gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) -// = ((SPEventContextClass *) sp_pencil_context_parent_class)->root_handler; -// if (parent_root_handler) { -// ret = parent_root_handler(ec, event); -// } ret = SPDrawContext::root_handler(event); } -- cgit v1.2.3