From 0459094999e0298341ecad677464043528d1036f Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Wed, 9 May 2012 00:54:48 -0700 Subject: Centralized line creation and enhanced visibility. (bzr r11350) --- src/pen-context.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 2fe510416..b97fc5527 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -211,17 +211,18 @@ static void sp_pen_context_setup(SPEventContext *ec) ((SPEventContextClass *) pen_parent_class)->setup(ec); } + ControlManager &mgr = ControlManager::getManager(); + // Pen indicators - pc->c0 = ControlManager::getManager().createControl(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), Inkscape::CTRL_TYPE_ADJ_HANDLE); - ControlManager::getManager().track(pc->c0); + pc->c0 = mgr.createControl(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), Inkscape::CTRL_TYPE_ADJ_HANDLE); + mgr.track(pc->c0); + + pc->c1 = mgr.createControl(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), Inkscape::CTRL_TYPE_ADJ_HANDLE); + mgr.track(pc->c1); - pc->c1 = ControlManager::getManager().createControl(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), Inkscape::CTRL_TYPE_ADJ_HANDLE); - ControlManager::getManager().track(pc->c1); + pc->cl0 = mgr.createControlLine(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec))); + pc->cl1 = mgr.createControlLine(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec))); - pc->cl0 = SP_CTRLLINE(sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRLLINE, NULL)); - pc->cl0->setRgba32(0x0000007f); - pc->cl1 = SP_CTRLLINE(sp_canvas_item_new(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), SP_TYPE_CTRLLINE, NULL)); - pc->cl1->setRgba32(0x0000007f); sp_canvas_item_hide(pc->c0); sp_canvas_item_hide(pc->c1); -- cgit v1.2.3 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/pen-context.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index b97fc5527..a8aedb649 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -169,19 +169,19 @@ static void sp_pen_context_dispose(GObject *object) SPPenContext *pc = SP_PEN_CONTEXT(object); if (pc->c0) { - gtk_object_destroy(GTK_OBJECT(pc->c0)); + sp_canvas_item_destroy(pc->c0); pc->c0 = NULL; } if (pc->c1) { - gtk_object_destroy(GTK_OBJECT(pc->c1)); + sp_canvas_item_destroy(pc->c1); pc->c1 = NULL; } if (pc->cl0) { - gtk_object_destroy(GTK_OBJECT(pc->cl0)); + sp_canvas_item_destroy(pc->cl0); pc->cl0 = NULL; } if (pc->cl1) { - gtk_object_destroy(GTK_OBJECT(pc->cl1)); + sp_canvas_item_destroy(pc->cl1); pc->cl1 = NULL; } @@ -871,7 +871,7 @@ void pen_redraw_all (SPPenContext *const pc) if (pc->green_bpaths) { // remove old piecewise green canvasitems while (pc->green_bpaths) { - gtk_object_destroy(GTK_OBJECT(pc->green_bpaths->data)); + sp_canvas_item_destroy(SP_CANVAS_ITEM(pc->green_bpaths->data)); pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data); } // one canvas bpath for all of green_curve @@ -1135,7 +1135,7 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) // Destroy topmost green bpath if (pc->green_bpaths) { if (pc->green_bpaths->data) - gtk_object_destroy(GTK_OBJECT(pc->green_bpaths->data)); + sp_canvas_item_destroy(SP_CANVAS_ITEM(pc->green_bpaths->data)); pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data); } // Get last segment @@ -1182,7 +1182,7 @@ static void spdc_reset_colors(SPPenContext *pc) sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->blue_bpath), NULL); // Green while (pc->green_bpaths) { - gtk_object_destroy(GTK_OBJECT(pc->green_bpaths->data)); + sp_canvas_item_destroy(SP_CANVAS_ITEM(pc->green_bpaths->data)); pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data); } pc->green_curve->reset(); -- cgit v1.2.3 From 9abd33133650d77714fccf09d0c9ff27c9b75a78 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Thu, 5 Jul 2012 22:39:08 +0100 Subject: Drop GTK+ 2.20 support. Fixed bugs: - https://launchpad.net/bugs/1020494 (bzr r11529) --- src/pen-context.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index a8aedb649..6bf6531be 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -45,10 +45,6 @@ #include "tools-switch.h" #include "ui/control-manager.h" -#if !GTK_CHECK_VERSION(2,22,0) -#include "compat-key-syms.h" -#endif - using Inkscape::ControlManager; -- cgit v1.2.3 From 191bfb7baf9d1602d6ba6e5d747fd5ffad1e59a9 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Tue, 10 Jul 2012 18:26:54 +0200 Subject: Shortcuts. Fix for Bug #167796 (zoom keys (shortcuts) 3,4,6 on numeric pad not working). (bzr r11537) --- src/pen-context.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 6bf6531be..ade041019 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -978,7 +978,6 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) case GDK_KEY_Left: // move last point left case GDK_KEY_KP_Left: - case GDK_KEY_KP_4: if (!MOD__CTRL) { // not ctrl if (MOD__ALT) { // alt if (MOD__SHIFT) pen_lastpoint_move_screen(pc, -10, 0); // shift @@ -993,7 +992,6 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) break; case GDK_KEY_Up: // move last point up case GDK_KEY_KP_Up: - case GDK_KEY_KP_8: if (!MOD__CTRL) { // not ctrl if (MOD__ALT) { // alt if (MOD__SHIFT) pen_lastpoint_move_screen(pc, 0, 10); // shift @@ -1008,7 +1006,6 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) break; case GDK_KEY_Right: // move last point right case GDK_KEY_KP_Right: - case GDK_KEY_KP_6: if (!MOD__CTRL) { // not ctrl if (MOD__ALT) { // alt if (MOD__SHIFT) pen_lastpoint_move_screen(pc, 10, 0); // shift @@ -1023,7 +1020,6 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) break; case GDK_KEY_Down: // move last point down case GDK_KEY_KP_Down: - case GDK_KEY_KP_2: if (!MOD__CTRL) { // not ctrl if (MOD__ALT) { // alt if (MOD__SHIFT) pen_lastpoint_move_screen(pc, 0, -10); // shift -- cgit v1.2.3 From 370a3f5cc9e39352a081e5d5dd8c43676547a6e6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 4 Oct 2012 11:45:44 +1000 Subject: code cleanup: add own includes to cpp files or make the functions static if they are not used elsewhere. (bzr r11735) --- src/pen-context.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index ade041019..cb20eb3eb 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -861,7 +861,7 @@ static gint pen_handle_2button_press(SPPenContext *const pc, GdkEventButton cons return ret; } -void pen_redraw_all (SPPenContext *const pc) +static void pen_redraw_all (SPPenContext *const pc) { // green if (pc->green_bpaths) { @@ -915,7 +915,7 @@ void pen_redraw_all (SPPenContext *const pc) } } -void pen_lastpoint_move (SPPenContext *const pc, gdouble x, gdouble y) +static void pen_lastpoint_move (SPPenContext *const pc, gdouble x, gdouble y) { if (pc->npoints != 5) return; @@ -936,12 +936,12 @@ void pen_lastpoint_move (SPPenContext *const pc, gdouble x, gdouble y) pen_redraw_all(pc); } -void pen_lastpoint_move_screen (SPPenContext *const pc, gdouble x, gdouble y) +static void pen_lastpoint_move_screen (SPPenContext *const pc, gdouble x, gdouble y) { pen_lastpoint_move (pc, x / pc->desktop->current_zoom(), y / pc->desktop->current_zoom()); } -void pen_lastpoint_tocurve (SPPenContext *const pc) +static void pen_lastpoint_tocurve (SPPenContext *const pc) { if (pc->npoints != 5) return; @@ -956,7 +956,7 @@ void pen_lastpoint_tocurve (SPPenContext *const pc) pen_redraw_all(pc); } -void pen_lastpoint_toline (SPPenContext *const pc) +static void pen_lastpoint_toline (SPPenContext *const pc) { if (pc->npoints != 5) return; -- 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/pen-context.cpp | 46 +++++++++------------------------------------- 1 file changed, 9 insertions(+), 37 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index cb20eb3eb..6e3ed201e 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -47,9 +47,6 @@ using Inkscape::ControlManager; - -static void sp_pen_context_class_init(SPPenContextClass *klass); -static void sp_pen_context_init(SPPenContext *pc); static void sp_pen_context_dispose(GObject *object); static void sp_pen_context_setup(SPEventContext *ec); @@ -78,35 +75,12 @@ static void pen_enable_events(SPPenContext *const pc); static Geom::Point pen_drag_origin_w(0, 0); static bool pen_within_tolerance = false; -static SPDrawContextClass *pen_parent_class; - static int pen_next_paraxial_direction(const SPPenContext *const pc, Geom::Point const &pt, Geom::Point const &origin, guint state); static void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Point &pt, guint const state, bool snap); static int pen_last_paraxial_dir = 0; // last used direction in horizontal/vertical mode; 0 = horizontal, 1 = vertical - -/** - * Register SPPenContext with Gdk and return its type. - */ -GType sp_pen_context_get_type(void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof(SPPenContextClass), - NULL, NULL, - (GClassInitFunc) sp_pen_context_class_init, - NULL, NULL, - sizeof(SPPenContext), - 4, - (GInstanceInitFunc) sp_pen_context_init, - NULL, // value_table - }; - type = g_type_register_static(SP_TYPE_DRAW_CONTEXT, "SPPenContext", &info, (GTypeFlags)0); - } - return type; -} +G_DEFINE_TYPE(SPPenContext, sp_pen_context, SP_TYPE_DRAW_CONTEXT); /** * Initialize the SPPenContext vtable. @@ -119,8 +93,6 @@ static void sp_pen_context_class_init(SPPenContextClass *klass) object_class = (GObjectClass *) klass; event_context_class = (SPEventContextClass *) klass; - pen_parent_class = (SPDrawContextClass*)g_type_class_peek_parent(klass); - object_class->dispose = sp_pen_context_dispose; event_context_class->setup = sp_pen_context_setup; @@ -181,7 +153,7 @@ static void sp_pen_context_dispose(GObject *object) pc->cl1 = NULL; } - G_OBJECT_CLASS(pen_parent_class)->dispose(object); + G_OBJECT_CLASS(sp_pen_context_parent_class)->dispose(object); if (pc->expecting_clicks_for_LPE > 0) { // we received too few clicks to sanely set the parameter path so we remove the LPE from the item @@ -203,8 +175,8 @@ static void sp_pen_context_setup(SPEventContext *ec) { SPPenContext *pc = SP_PEN_CONTEXT(ec); - if (((SPEventContextClass *) pen_parent_class)->setup) { - ((SPEventContextClass *) pen_parent_class)->setup(ec); + if (((SPEventContextClass *) sp_pen_context_parent_class)->setup) { + ((SPEventContextClass *) sp_pen_context_parent_class)->setup(ec); } ControlManager &mgr = ControlManager::getManager(); @@ -265,8 +237,8 @@ static void sp_pen_context_finish(SPEventContext *ec) pen_cancel (pc); } - if (((SPEventContextClass *) pen_parent_class)->finish) { - ((SPEventContextClass *) pen_parent_class)->finish(ec); + if (((SPEventContextClass *) sp_pen_context_parent_class)->finish) { + ((SPEventContextClass *) sp_pen_context_parent_class)->finish(ec); } } @@ -347,8 +319,8 @@ static gint sp_pen_context_item_handler(SPEventContext *ec, SPItem *item, GdkEve } if (!ret) { - if (((SPEventContextClass *) pen_parent_class)->item_handler) - ret = ((SPEventContextClass *) pen_parent_class)->item_handler(ec, item, event); + if (((SPEventContextClass *) sp_pen_context_parent_class)->item_handler) + ret = ((SPEventContextClass *) sp_pen_context_parent_class)->item_handler(ec, item, event); } return ret; @@ -390,7 +362,7 @@ static gint sp_pen_context_root_handler(SPEventContext *ec, GdkEvent *event) if (!ret) { gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) - = ((SPEventContextClass *) pen_parent_class)->root_handler; + = ((SPEventContextClass *) sp_pen_context_parent_class)->root_handler; if (parent_root_handler) { ret = parent_root_handler(ec, 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/pen-context.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 13 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 6e3ed201e..2c045f8ad 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -102,11 +102,20 @@ static void sp_pen_context_class_init(SPPenContextClass *klass) event_context_class->item_handler = sp_pen_context_item_handler; } +CPenContext::CPenContext(SPPenContext* pencontext) : CDrawContext(pencontext) { + this->sppencontext = pencontext; +} + /** * Callback to initialize SPPenContext object. */ static void sp_pen_context_init(SPPenContext *pc) { + pc->cpencontext = new CPenContext(pc); + delete pc->cdrawcontext; + pc->cdrawcontext = pc->cpencontext; + pc->ceventcontext = pc->cpencontext; + SPEventContext *event_context = SP_EVENT_CONTEXT(pc); event_context->cursor_shape = cursor_pen_xpm; @@ -173,11 +182,18 @@ void sp_pen_context_set_polyline_mode(SPPenContext *const pc) { */ static void sp_pen_context_setup(SPEventContext *ec) { + ec->ceventcontext->setup(); +} + +void CPenContext::setup() { + SPEventContext* ec = this->speventcontext; + SPPenContext *pc = SP_PEN_CONTEXT(ec); - if (((SPEventContextClass *) sp_pen_context_parent_class)->setup) { - ((SPEventContextClass *) sp_pen_context_parent_class)->setup(ec); - } +// if (((SPEventContextClass *) sp_pen_context_parent_class)->setup) { +// ((SPEventContextClass *) sp_pen_context_parent_class)->setup(ec); +// } + CDrawContext::setup(); ControlManager &mgr = ControlManager::getManager(); @@ -229,6 +245,12 @@ static void pen_cancel (SPPenContext *const pc) */ static void sp_pen_context_finish(SPEventContext *ec) { + ec->ceventcontext->finish(); +} + +void CPenContext::finish() { + SPEventContext* ec = this->speventcontext; + SPPenContext *pc = SP_PEN_CONTEXT(ec); sp_event_context_discard_delayed_snap_event(ec); @@ -237,9 +259,10 @@ static void sp_pen_context_finish(SPEventContext *ec) pen_cancel (pc); } - if (((SPEventContextClass *) sp_pen_context_parent_class)->finish) { - ((SPEventContextClass *) sp_pen_context_parent_class)->finish(ec); - } +// if (((SPEventContextClass *) sp_pen_context_parent_class)->finish) { +// ((SPEventContextClass *) sp_pen_context_parent_class)->finish(ec); +// } + CDrawContext::finish(); } /** @@ -247,6 +270,12 @@ static void sp_pen_context_finish(SPEventContext *ec) */ static void sp_pen_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val) { + ec->ceventcontext->set(val); +} + +void CPenContext::set(Inkscape::Preferences::Entry* val) { + SPEventContext* ec = this->speventcontext; + SPPenContext *pc = SP_PEN_CONTEXT(ec); Glib::ustring name = val->getEntryName(); @@ -303,6 +332,12 @@ static void spdc_endpoint_snap_handle(SPPenContext const *const pc, Geom::Point static gint sp_pen_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event) { + return ec->ceventcontext->item_handler(item, event); +} + +gint CPenContext::item_handler(SPItem* item, GdkEvent* event) { + SPEventContext* ec = this->speventcontext; + SPPenContext *const pc = SP_PEN_CONTEXT(ec); gint ret = FALSE; @@ -319,8 +354,9 @@ static gint sp_pen_context_item_handler(SPEventContext *ec, SPItem *item, GdkEve } if (!ret) { - if (((SPEventContextClass *) sp_pen_context_parent_class)->item_handler) - ret = ((SPEventContextClass *) sp_pen_context_parent_class)->item_handler(ec, item, event); +// if (((SPEventContextClass *) sp_pen_context_parent_class)->item_handler) +// ret = ((SPEventContextClass *) sp_pen_context_parent_class)->item_handler(ec, item, event); + ret = CDrawContext::item_handler(item, event); } return ret; @@ -331,6 +367,12 @@ static gint sp_pen_context_item_handler(SPEventContext *ec, SPItem *item, GdkEve */ static gint sp_pen_context_root_handler(SPEventContext *ec, GdkEvent *event) { + return ec->ceventcontext->root_handler(event); +} + +gint CPenContext::root_handler(GdkEvent* event) { + SPEventContext* ec = this->speventcontext; + SPPenContext *const pc = SP_PEN_CONTEXT(ec); gint ret = FALSE; @@ -361,11 +403,12 @@ static gint sp_pen_context_root_handler(SPEventContext *ec, GdkEvent *event) } if (!ret) { - gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) - = ((SPEventContextClass *) sp_pen_context_parent_class)->root_handler; - if (parent_root_handler) { - ret = parent_root_handler(ec, event); - } +// gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) +// = ((SPEventContextClass *) sp_pen_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/pen-context.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 2c045f8ad..333f9ef87 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -95,27 +95,29 @@ static void sp_pen_context_class_init(SPPenContextClass *klass) object_class->dispose = sp_pen_context_dispose; - event_context_class->setup = sp_pen_context_setup; - event_context_class->finish = sp_pen_context_finish; - event_context_class->set = sp_pen_context_set; - event_context_class->root_handler = sp_pen_context_root_handler; - event_context_class->item_handler = sp_pen_context_item_handler; +// event_context_class->setup = sp_pen_context_setup; +// event_context_class->finish = sp_pen_context_finish; +// event_context_class->set = sp_pen_context_set; +// event_context_class->root_handler = sp_pen_context_root_handler; +// event_context_class->item_handler = sp_pen_context_item_handler; } CPenContext::CPenContext(SPPenContext* pencontext) : CDrawContext(pencontext) { this->sppencontext = pencontext; } -/** - * Callback to initialize SPPenContext object. - */ -static void sp_pen_context_init(SPPenContext *pc) -{ +SPPenContext::SPPenContext() : SPDrawContext() { + SPPenContext* pc = this; + pc->cpencontext = new CPenContext(pc); delete pc->cdrawcontext; pc->cdrawcontext = pc->cpencontext; pc->ceventcontext = pc->cpencontext; + pc->polylines_only = false; + pc->polylines_paraxial = false; + pc->expecting_clicks_for_LPE = 0; + SPEventContext *event_context = SP_EVENT_CONTEXT(pc); event_context->cursor_shape = cursor_pen_xpm; @@ -138,6 +140,14 @@ static void sp_pen_context_init(SPPenContext *pc) pc->waiting_item = NULL; } +/** + * Callback to initialize SPPenContext object. + */ +static void sp_pen_context_init(SPPenContext *pc) +{ + new (pc) SPPenContext(); +} + /** * Callback to destroy the SPPenContext object's members and itself. */ -- 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/pen-context.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 333f9ef87..180152642 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -80,6 +80,8 @@ static void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Po static int pen_last_paraxial_dir = 0; // last used direction in horizontal/vertical mode; 0 = horizontal, 1 = vertical +const std::string SPPenContext::prefsPath = "/tools/freehand/pen"; + G_DEFINE_TYPE(SPPenContext, sp_pen_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/pen-context.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 180152642..7e85b46af 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -80,6 +80,21 @@ static void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Po static int pen_last_paraxial_dir = 0; // last used direction in horizontal/vertical mode; 0 = horizontal, 1 = vertical + +#include "sp-factory.h" + +namespace { + SPEventContext* createPenContext() { + return new SPPenContext(); + } + + bool penContextRegistered = ToolFactory::instance().registerObject("/tools/freehand/pen", createPenContext); +} + +const std::string& CPenContext::getPrefsPath() { + return SPPenContext::prefsPath; +} + const std::string SPPenContext::prefsPath = "/tools/freehand/pen"; G_DEFINE_TYPE(SPPenContext, sp_pen_context, SP_TYPE_DRAW_CONTEXT); @@ -115,6 +130,7 @@ SPPenContext::SPPenContext() : SPDrawContext() { delete pc->cdrawcontext; pc->cdrawcontext = pc->cpencontext; pc->ceventcontext = pc->cpencontext; + types.insert(typeid(SPPenContext)); pc->polylines_only = false; pc->polylines_paraxial = 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/pen-context.cpp | 113 +++++++++------------------------------------------- 1 file changed, 18 insertions(+), 95 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 7e85b46af..caaac32db 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -47,14 +47,6 @@ using Inkscape::ControlManager; -static void sp_pen_context_dispose(GObject *object); - -static void sp_pen_context_setup(SPEventContext *ec); -static void sp_pen_context_finish(SPEventContext *ec); -static void sp_pen_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val); -static gint sp_pen_context_root_handler(SPEventContext *ec, GdkEvent *event); -static gint sp_pen_context_item_handler(SPEventContext *event_context, SPItem *item, GdkEvent *event); - static void spdc_pen_set_initial_point(SPPenContext *pc, Geom::Point const p); static void spdc_pen_set_subsequent_point(SPPenContext *const pc, Geom::Point const p, bool statusbar, guint status = 0); static void spdc_pen_set_ctrl(SPPenContext *pc, Geom::Point const p, guint state); @@ -91,47 +83,15 @@ namespace { bool penContextRegistered = ToolFactory::instance().registerObject("/tools/freehand/pen", createPenContext); } -const std::string& CPenContext::getPrefsPath() { +const std::string& SPPenContext::getPrefsPath() { return SPPenContext::prefsPath; } const std::string SPPenContext::prefsPath = "/tools/freehand/pen"; -G_DEFINE_TYPE(SPPenContext, sp_pen_context, SP_TYPE_DRAW_CONTEXT); - -/** - * Initialize the SPPenContext vtable. - */ -static void sp_pen_context_class_init(SPPenContextClass *klass) -{ - GObjectClass *object_class; - SPEventContextClass *event_context_class; - - object_class = (GObjectClass *) klass; - event_context_class = (SPEventContextClass *) klass; - - object_class->dispose = sp_pen_context_dispose; - -// event_context_class->setup = sp_pen_context_setup; -// event_context_class->finish = sp_pen_context_finish; -// event_context_class->set = sp_pen_context_set; -// event_context_class->root_handler = sp_pen_context_root_handler; -// event_context_class->item_handler = sp_pen_context_item_handler; -} - -CPenContext::CPenContext(SPPenContext* pencontext) : CDrawContext(pencontext) { - this->sppencontext = pencontext; -} - SPPenContext::SPPenContext() : SPDrawContext() { SPPenContext* pc = this; - pc->cpencontext = new CPenContext(pc); - delete pc->cdrawcontext; - pc->cdrawcontext = pc->cpencontext; - pc->ceventcontext = pc->cpencontext; - types.insert(typeid(SPPenContext)); - pc->polylines_only = false; pc->polylines_paraxial = false; pc->expecting_clicks_for_LPE = 0; @@ -158,20 +118,8 @@ SPPenContext::SPPenContext() : SPDrawContext() { pc->waiting_item = NULL; } -/** - * Callback to initialize SPPenContext object. - */ -static void sp_pen_context_init(SPPenContext *pc) -{ - new (pc) SPPenContext(); -} - -/** - * Callback to destroy the SPPenContext object's members and itself. - */ -static void sp_pen_context_dispose(GObject *object) -{ - SPPenContext *pc = SP_PEN_CONTEXT(object); +SPPenContext::~SPPenContext() { + SPPenContext *pc = SP_PEN_CONTEXT(this); if (pc->c0) { sp_canvas_item_destroy(pc->c0); @@ -190,7 +138,7 @@ static void sp_pen_context_dispose(GObject *object) pc->cl1 = NULL; } - G_OBJECT_CLASS(sp_pen_context_parent_class)->dispose(object); + //G_OBJECT_CLASS(sp_pen_context_parent_class)->dispose(object); if (pc->expecting_clicks_for_LPE > 0) { // we received too few clicks to sanely set the parameter path so we remove the LPE from the item @@ -208,20 +156,15 @@ void sp_pen_context_set_polyline_mode(SPPenContext *const pc) { /** * Callback to initialize SPPenContext object. */ -static void sp_pen_context_setup(SPEventContext *ec) -{ - ec->ceventcontext->setup(); -} - -void CPenContext::setup() { - SPEventContext* ec = this->speventcontext; +void SPPenContext::setup() { + SPEventContext* ec = this; SPPenContext *pc = SP_PEN_CONTEXT(ec); // if (((SPEventContextClass *) sp_pen_context_parent_class)->setup) { // ((SPEventContextClass *) sp_pen_context_parent_class)->setup(ec); // } - CDrawContext::setup(); + SPDrawContext::setup(); ControlManager &mgr = ControlManager::getManager(); @@ -271,13 +214,8 @@ static void pen_cancel (SPPenContext *const pc) /** * Finalization callback. */ -static void sp_pen_context_finish(SPEventContext *ec) -{ - ec->ceventcontext->finish(); -} - -void CPenContext::finish() { - SPEventContext* ec = this->speventcontext; +void SPPenContext::finish() { + SPEventContext* ec = this; SPPenContext *pc = SP_PEN_CONTEXT(ec); @@ -290,19 +228,14 @@ void CPenContext::finish() { // if (((SPEventContextClass *) sp_pen_context_parent_class)->finish) { // ((SPEventContextClass *) sp_pen_context_parent_class)->finish(ec); // } - CDrawContext::finish(); + SPDrawContext::finish(); } /** * Callback that sets key to value in pen context. */ -static void sp_pen_context_set(SPEventContext *ec, Inkscape::Preferences::Entry *val) -{ - ec->ceventcontext->set(val); -} - -void CPenContext::set(Inkscape::Preferences::Entry* val) { - SPEventContext* ec = this->speventcontext; +void SPPenContext::set(Inkscape::Preferences::Entry* val) { + SPEventContext* ec = this; SPPenContext *pc = SP_PEN_CONTEXT(ec); Glib::ustring name = val->getEntryName(); @@ -358,13 +291,8 @@ static void spdc_endpoint_snap_handle(SPPenContext const *const pc, Geom::Point } } -static gint sp_pen_context_item_handler(SPEventContext *ec, SPItem *item, GdkEvent *event) -{ - return ec->ceventcontext->item_handler(item, event); -} - -gint CPenContext::item_handler(SPItem* item, GdkEvent* event) { - SPEventContext* ec = this->speventcontext; +gint SPPenContext::item_handler(SPItem* item, GdkEvent* event) { + SPEventContext* ec = this; SPPenContext *const pc = SP_PEN_CONTEXT(ec); @@ -384,7 +312,7 @@ gint CPenContext::item_handler(SPItem* item, GdkEvent* event) { if (!ret) { // if (((SPEventContextClass *) sp_pen_context_parent_class)->item_handler) // ret = ((SPEventContextClass *) sp_pen_context_parent_class)->item_handler(ec, item, event); - ret = CDrawContext::item_handler(item, event); + ret = SPDrawContext::item_handler(item, event); } return ret; @@ -393,13 +321,8 @@ gint CPenContext::item_handler(SPItem* item, GdkEvent* event) { /** * Callback to handle all pen events. */ -static gint sp_pen_context_root_handler(SPEventContext *ec, GdkEvent *event) -{ - return ec->ceventcontext->root_handler(event); -} - -gint CPenContext::root_handler(GdkEvent* event) { - SPEventContext* ec = this->speventcontext; +gint SPPenContext::root_handler(GdkEvent* event) { + SPEventContext* ec = this; SPPenContext *const pc = SP_PEN_CONTEXT(ec); @@ -436,7 +359,7 @@ gint CPenContext::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/pen-context.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index caaac32db..177aeaca9 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -73,7 +73,7 @@ static void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Po static int pen_last_paraxial_dir = 0; // last used direction in horizontal/vertical mode; 0 = horizontal, 1 = vertical -#include "sp-factory.h" +#include "tool-factory.h" namespace { SPEventContext* createPenContext() { -- 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/pen-context.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 177aeaca9..00f7294be 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -234,14 +234,14 @@ void SPPenContext::finish() { /** * Callback that sets key to value in pen context. */ -void SPPenContext::set(Inkscape::Preferences::Entry* val) { +void SPPenContext::set(const Inkscape::Preferences::Entry& val) { SPEventContext* ec = this; SPPenContext *pc = SP_PEN_CONTEXT(ec); - Glib::ustring name = val->getEntryName(); + Glib::ustring name = val.getEntryName(); if (name == "mode") { - if ( val->getString() == "drag" ) { + if ( val.getString() == "drag" ) { pc->mode = SP_PEN_CONTEXT_MODE_DRAG; } else { pc->mode = SP_PEN_CONTEXT_MODE_CLICK; -- cgit v1.2.3 From 9b2956fbaefb4e12bad3fc359c47e5923f33bb41 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 28 Apr 2013 00:05:16 +0200 Subject: various changes (bzr r11608.1.105) --- src/pen-context.cpp | 94 ++++++++++++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 00f7294be..4281fdc54 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -103,8 +103,8 @@ SPPenContext::SPPenContext() : SPDrawContext() { event_context->hot_y = 4; pc->npoints = 0; - pc->mode = SP_PEN_CONTEXT_MODE_CLICK; - pc->state = SP_PEN_CONTEXT_POINT; + pc->mode = MODE_CLICK; + pc->state = POINT; pc->c0 = NULL; pc->c1 = NULL; @@ -199,7 +199,7 @@ void SPPenContext::setup() { static void pen_cancel (SPPenContext *const pc) { pc->num_clicks = 0; - pc->state = SP_PEN_CONTEXT_STOP; + pc->state = SPPenContext::STOP; spdc_reset_colors(pc); sp_canvas_item_hide(pc->c0); sp_canvas_item_hide(pc->c1); @@ -242,9 +242,9 @@ void SPPenContext::set(const Inkscape::Preferences::Entry& val) { if (name == "mode") { if ( val.getString() == "drag" ) { - pc->mode = SP_PEN_CONTEXT_MODE_DRAG; + pc->mode = MODE_DRAG; } else { - pc->mode = SP_PEN_CONTEXT_MODE_CLICK; + pc->mode = MODE_CLICK; } } } @@ -406,26 +406,26 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const SPDrawAnchor * const anchor = spdc_test_inside(pc, event_w); switch (pc->mode) { - case SP_PEN_CONTEXT_MODE_CLICK: + case SPPenContext::MODE_CLICK: // In click mode we add point on release switch (pc->state) { - case SP_PEN_CONTEXT_POINT: - case SP_PEN_CONTEXT_CONTROL: - case SP_PEN_CONTEXT_CLOSE: + case SPPenContext::POINT: + case SPPenContext::CONTROL: + case SPPenContext::CLOSE: break; - case SP_PEN_CONTEXT_STOP: + case SPPenContext::STOP: // This is allowed, if we just canceled curve - pc->state = SP_PEN_CONTEXT_POINT; + pc->state = SPPenContext::POINT; break; default: break; } break; - case SP_PEN_CONTEXT_MODE_DRAG: + case SPPenContext::MODE_DRAG: switch (pc->state) { - case SP_PEN_CONTEXT_STOP: + case SPPenContext::STOP: // This is allowed, if we just canceled curve - case SP_PEN_CONTEXT_POINT: + case SPPenContext::POINT: if (pc->npoints == 0) { Geom::Point p; @@ -481,7 +481,7 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const p = anchor->dp; // we hit an anchor, will finish the curve (either with or without closing) // in release handler - pc->state = SP_PEN_CONTEXT_CLOSE; + pc->state = SPPenContext::CLOSE; if (pc->green_anchor && pc->green_anchor->active) { // we clicked on the current curve start, so close it even if @@ -498,13 +498,13 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const } } - pc->state = pc->polylines_only ? SP_PEN_CONTEXT_POINT : SP_PEN_CONTEXT_CONTROL; + pc->state = pc->polylines_only ? SPPenContext::POINT : SPPenContext::CONTROL; ret = TRUE; break; - case SP_PEN_CONTEXT_CONTROL: + case SPPenContext::CONTROL: g_warning("Button down in CONTROL state"); break; - case SP_PEN_CONTEXT_CLOSE: + case SPPenContext::CLOSE: g_warning("Button down in CLOSE state"); break; default: @@ -580,9 +580,9 @@ static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion cons SPDrawAnchor *anchor = spdc_test_inside(pc, event_w); switch (pc->mode) { - case SP_PEN_CONTEXT_MODE_CLICK: + case SPPenContext::MODE_CLICK: switch (pc->state) { - case SP_PEN_CONTEXT_POINT: + case SPPenContext::POINT: if ( pc->npoints != 0 ) { // Only set point, if we are already appending spdc_endpoint_snap(pc, p, mevent.state); @@ -595,23 +595,23 @@ static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion cons m.unSetup(); } break; - case SP_PEN_CONTEXT_CONTROL: - case SP_PEN_CONTEXT_CLOSE: + case SPPenContext::CONTROL: + case SPPenContext::CLOSE: // Placing controls is last operation in CLOSE state spdc_endpoint_snap(pc, p, mevent.state); spdc_pen_set_ctrl(pc, p, mevent.state); ret = TRUE; break; - case SP_PEN_CONTEXT_STOP: + case SPPenContext::STOP: // This is perfectly valid break; default: break; } break; - case SP_PEN_CONTEXT_MODE_DRAG: + case SPPenContext::MODE_DRAG: switch (pc->state) { - case SP_PEN_CONTEXT_POINT: + case SPPenContext::POINT: if ( pc->npoints > 0 ) { // Only set point, if we are already appending @@ -647,8 +647,8 @@ static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion cons } } break; - case SP_PEN_CONTEXT_CONTROL: - case SP_PEN_CONTEXT_CLOSE: + case SPPenContext::CONTROL: + case SPPenContext::CLOSE: // Placing controls is last operation in CLOSE state // snap the handle @@ -662,7 +662,7 @@ static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion cons gobble_motion_events(GDK_BUTTON1_MASK); ret = TRUE; break; - case SP_PEN_CONTEXT_STOP: + case SPPenContext::STOP: // This is perfectly valid break; default: @@ -706,9 +706,9 @@ static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton con SPDrawAnchor *anchor = spdc_test_inside(pc, event_w); switch (pc->mode) { - case SP_PEN_CONTEXT_MODE_CLICK: + case SPPenContext::MODE_CLICK: switch (pc->state) { - case SP_PEN_CONTEXT_POINT: + case SPPenContext::POINT: if ( pc->npoints == 0 ) { // Start new thread only with button release if (anchor) { @@ -723,43 +723,43 @@ static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton con p = anchor->dp; } } - pc->state = SP_PEN_CONTEXT_CONTROL; + pc->state = SPPenContext::CONTROL; ret = TRUE; break; - case SP_PEN_CONTEXT_CONTROL: + case SPPenContext::CONTROL: // End current segment spdc_endpoint_snap(pc, p, revent.state); spdc_pen_finish_segment(pc, p, revent.state); - pc->state = SP_PEN_CONTEXT_POINT; + pc->state = SPPenContext::POINT; ret = TRUE; break; - case SP_PEN_CONTEXT_CLOSE: + case SPPenContext::CLOSE: // End current segment if (!anchor) { // Snap node only if not hitting anchor spdc_endpoint_snap(pc, p, revent.state); } spdc_pen_finish_segment(pc, p, revent.state); spdc_pen_finish(pc, TRUE); - pc->state = SP_PEN_CONTEXT_POINT; + pc->state = SPPenContext::POINT; ret = TRUE; break; - case SP_PEN_CONTEXT_STOP: + case SPPenContext::STOP: // This is allowed, if we just canceled curve - pc->state = SP_PEN_CONTEXT_POINT; + pc->state = SPPenContext::POINT; ret = TRUE; break; default: break; } break; - case SP_PEN_CONTEXT_MODE_DRAG: + case SPPenContext::MODE_DRAG: switch (pc->state) { - case SP_PEN_CONTEXT_POINT: - case SP_PEN_CONTEXT_CONTROL: + case SPPenContext::POINT: + case SPPenContext::CONTROL: spdc_endpoint_snap(pc, p, revent.state); spdc_pen_finish_segment(pc, p, revent.state); break; - case SP_PEN_CONTEXT_CLOSE: + case SPPenContext::CLOSE: spdc_endpoint_snap(pc, p, revent.state); spdc_pen_finish_segment(pc, p, revent.state); if (pc->green_closed) { @@ -770,13 +770,13 @@ static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton con spdc_pen_finish(pc, FALSE); } break; - case SP_PEN_CONTEXT_STOP: + case SPPenContext::STOP: // This is allowed, if we just cancelled curve break; default: break; } - pc->state = SP_PEN_CONTEXT_POINT; + pc->state = SPPenContext::POINT; ret = TRUE; break; default: @@ -1118,7 +1118,7 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) sp_canvas_item_hide(pc->c1); sp_canvas_item_hide(pc->cl0); sp_canvas_item_hide(pc->cl1); - pc->state = SP_PEN_CONTEXT_POINT; + pc->state = SPPenContext::POINT; spdc_pen_set_subsequent_point(pc, pt, true); pen_last_paraxial_dir = !pen_last_paraxial_dir; ret = TRUE; @@ -1252,8 +1252,8 @@ static void spdc_pen_set_ctrl(SPPenContext *const pc, Geom::Point const p, guint sp_canvas_item_show(pc->c0); sp_canvas_item_show(pc->cl0); bool is_symm = false; - if ( ( ( pc->mode == SP_PEN_CONTEXT_MODE_CLICK ) && ( state & GDK_CONTROL_MASK ) ) || - ( ( pc->mode == SP_PEN_CONTEXT_MODE_DRAG ) && !( state & GDK_SHIFT_MASK ) ) ) { + if ( ( ( pc->mode == SPPenContext::MODE_CLICK ) && ( state & GDK_CONTROL_MASK ) ) || + ( ( pc->mode == SPPenContext::MODE_DRAG ) && !( state & GDK_SHIFT_MASK ) ) ) { Geom::Point delta = p - pc->p[3]; pc->p[2] = pc->p[3] - delta; is_symm = true; @@ -1323,7 +1323,7 @@ static void spdc_pen_finish(SPPenContext *const pc, gboolean const closed) pc->ea = NULL; pc->npoints = 0; - pc->state = SP_PEN_CONTEXT_POINT; + pc->state = SPPenContext::POINT; sp_canvas_item_hide(pc->c0); sp_canvas_item_hide(pc->c1); -- cgit v1.2.3 From 192d134e8283fadf349eb41d66f63206c98c33d1 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 28 Apr 2013 15:48:03 -0700 Subject: Temporily fix abiguous macros before later removal. (bzr r12310) --- src/pen-context.cpp | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 6e3ed201e..5972a6ca8 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -950,13 +950,13 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) case GDK_KEY_Left: // move last point left case GDK_KEY_KP_Left: - if (!MOD__CTRL) { // not ctrl - if (MOD__ALT) { // alt - if (MOD__SHIFT) pen_lastpoint_move_screen(pc, -10, 0); // shift + if (!MOD__CTRL(event)) { // not ctrl + if (MOD__ALT(event)) { // alt + if (MOD__SHIFT(event)) pen_lastpoint_move_screen(pc, -10, 0); // shift else pen_lastpoint_move_screen(pc, -1, 0); // no shift } else { // no alt - if (MOD__SHIFT) pen_lastpoint_move(pc, -10*nudge, 0); // shift + if (MOD__SHIFT(event)) pen_lastpoint_move(pc, -10*nudge, 0); // shift else pen_lastpoint_move(pc, -nudge, 0); // no shift } ret = TRUE; @@ -964,13 +964,13 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) break; case GDK_KEY_Up: // move last point up case GDK_KEY_KP_Up: - if (!MOD__CTRL) { // not ctrl - if (MOD__ALT) { // alt - if (MOD__SHIFT) pen_lastpoint_move_screen(pc, 0, 10); // shift + if (!MOD__CTRL(event)) { // not ctrl + if (MOD__ALT(event)) { // alt + if (MOD__SHIFT(event)) pen_lastpoint_move_screen(pc, 0, 10); // shift else pen_lastpoint_move_screen(pc, 0, 1); // no shift } else { // no alt - if (MOD__SHIFT) pen_lastpoint_move(pc, 0, 10*nudge); // shift + if (MOD__SHIFT(event)) pen_lastpoint_move(pc, 0, 10*nudge); // shift else pen_lastpoint_move(pc, 0, nudge); // no shift } ret = TRUE; @@ -978,13 +978,13 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) break; case GDK_KEY_Right: // move last point right case GDK_KEY_KP_Right: - if (!MOD__CTRL) { // not ctrl - if (MOD__ALT) { // alt - if (MOD__SHIFT) pen_lastpoint_move_screen(pc, 10, 0); // shift + if (!MOD__CTRL(event)) { // not ctrl + if (MOD__ALT(event)) { // alt + if (MOD__SHIFT(event)) pen_lastpoint_move_screen(pc, 10, 0); // shift else pen_lastpoint_move_screen(pc, 1, 0); // no shift } else { // no alt - if (MOD__SHIFT) pen_lastpoint_move(pc, 10*nudge, 0); // shift + if (MOD__SHIFT(event)) pen_lastpoint_move(pc, 10*nudge, 0); // shift else pen_lastpoint_move(pc, nudge, 0); // no shift } ret = TRUE; @@ -992,13 +992,13 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) break; case GDK_KEY_Down: // move last point down case GDK_KEY_KP_Down: - if (!MOD__CTRL) { // not ctrl - if (MOD__ALT) { // alt - if (MOD__SHIFT) pen_lastpoint_move_screen(pc, 0, -10); // shift + if (!MOD__CTRL(event)) { // not ctrl + if (MOD__ALT(event)) { // alt + if (MOD__SHIFT(event)) pen_lastpoint_move_screen(pc, 0, -10); // shift else pen_lastpoint_move_screen(pc, 0, -1); // no shift } else { // no alt - if (MOD__SHIFT) pen_lastpoint_move(pc, 0, -10*nudge); // shift + if (MOD__SHIFT(event)) pen_lastpoint_move(pc, 0, -10*nudge); // shift else pen_lastpoint_move(pc, 0, -nudge); // no shift } ret = TRUE; @@ -1008,7 +1008,7 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) /*TODO: this is not yet enabled?? looks like some traces of the Geometry tool case GDK_KEY_P: case GDK_KEY_p: - if (MOD__SHIFT_ONLY) { + if (MOD__SHIFT_ONLY(event)) { sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::PARALLEL, 2); ret = TRUE; } @@ -1016,7 +1016,7 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) case GDK_KEY_C: case GDK_KEY_c: - if (MOD__SHIFT_ONLY) { + if (MOD__SHIFT_ONLY(event)) { sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::CIRCLE_3PTS, 3); ret = TRUE; } @@ -1024,7 +1024,7 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) case GDK_KEY_B: case GDK_KEY_b: - if (MOD__SHIFT_ONLY) { + if (MOD__SHIFT_ONLY(event)) { sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::PERP_BISECTOR, 2); ret = TRUE; } @@ -1032,7 +1032,7 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) case GDK_KEY_A: case GDK_KEY_a: - if (MOD__SHIFT_ONLY) { + if (MOD__SHIFT_ONLY(event)) { sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::ANGLE_BISECTOR, 3); ret = TRUE; } @@ -1041,14 +1041,14 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) case GDK_KEY_U: case GDK_KEY_u: - if (MOD__SHIFT_ONLY) { + if (MOD__SHIFT_ONLY(event)) { pen_lastpoint_tocurve(pc); ret = TRUE; } break; case GDK_KEY_L: case GDK_KEY_l: - if (MOD__SHIFT_ONLY) { + if (MOD__SHIFT_ONLY(event)) { pen_lastpoint_toline(pc); ret = TRUE; } @@ -1070,7 +1070,7 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) break; case GDK_KEY_z: case GDK_KEY_Z: - if (MOD__CTRL_ONLY && pc->npoints != 0) { + if (MOD__CTRL_ONLY(event) && pc->npoints != 0) { // if drawing, cancel, otherwise pass it up for undo pen_cancel (pc); ret = TRUE; @@ -1078,7 +1078,7 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) break; case GDK_KEY_g: case GDK_KEY_G: - if (MOD__SHIFT_ONLY) { + if (MOD__SHIFT_ONLY(event)) { sp_selection_to_guides(SP_EVENT_CONTEXT(pc)->desktop); ret = true; } -- cgit v1.2.3 From 4d84edcf25468530660a441c55544c7db27c2682 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Fri, 19 Jul 2013 15:08:24 -0400 Subject: Removed "helper/units.h" from "pen-context.cpp". (bzr r12380.1.38) --- src/pen-context.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 5972a6ca8..eac2ce5d1 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -39,7 +39,6 @@ #include "display/sp-ctrlline.h" #include "display/sodipodi-ctrl.h" #include -#include "helper/units.h" #include "macros.h" #include "context-fns.h" #include "tools-switch.h" @@ -1188,8 +1187,12 @@ static void spdc_pen_set_angle_distance_status_message(SPPenContext *const pc, G GString *dist = SP_PX_TO_METRIC_STRING(Geom::L2(rel), desktop->namedview->getDefaultMetric()); double angle = atan2(rel[Geom::Y], rel[Geom::X]) * 180 / M_PI; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (prefs->getBool("/options/compassangledisplay/value", 0) != 0) - angle = angle_to_compass (angle); + if (prefs->getBool("/options/compassangledisplay/value", 0) != 0) { + angle = 90 - angle; + if (angle < 0) { + angle += 360; + } + } pc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, message, angle, dist->str); g_string_free(dist, FALSE); -- cgit v1.2.3 From fdf69629c66f6c1a69d88a00bb6c1311c97b631b Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sat, 20 Jul 2013 15:08:31 -0400 Subject: Ported away from and removed "sp-metrics.*". (bzr r12380.1.47) --- src/pen-context.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index eac2ce5d1..69abf3513 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -22,7 +22,6 @@ #include "pen-context.h" #include "sp-namedview.h" -#include "sp-metrics.h" #include "desktop.h" #include "desktop-handles.h" #include "selection.h" @@ -1184,7 +1183,8 @@ static void spdc_pen_set_angle_distance_status_message(SPPenContext *const pc, G SPDesktop *desktop = SP_EVENT_CONTEXT(pc)->desktop; Geom::Point rel = p - pc->p[pc_point_to_compare]; - GString *dist = SP_PX_TO_METRIC_STRING(Geom::L2(rel), desktop->namedview->getDefaultMetric()); + Inkscape::Util::Quantity q = Inkscape::Util::Quantity(Geom::L2(rel), "px"); + GString *dist = g_string_new(q.string(*desktop->namedview->doc_units).c_str()); double angle = atan2(rel[Geom::Y], rel[Geom::X]) * 180 / M_PI; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/options/compassangledisplay/value", 0) != 0) { -- 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/pen-context.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 21fc4fc51..690b520bc 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -291,7 +291,7 @@ static void spdc_endpoint_snap_handle(SPPenContext const *const pc, Geom::Point } } -gint SPPenContext::item_handler(SPItem* item, GdkEvent* event) { +bool SPPenContext::item_handler(SPItem* item, GdkEvent* event) { SPEventContext* ec = this; SPPenContext *const pc = SP_PEN_CONTEXT(ec); @@ -321,7 +321,7 @@ gint SPPenContext::item_handler(SPItem* item, GdkEvent* event) { /** * Callback to handle all pen events. */ -gint SPPenContext::root_handler(GdkEvent* event) { +bool SPPenContext::root_handler(GdkEvent* event) { SPEventContext* ec = this; SPPenContext *const pc = SP_PEN_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/pen-context.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 690b520bc..fbcb6dae5 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -205,8 +205,8 @@ static void pen_cancel (SPPenContext *const pc) sp_canvas_item_hide(pc->c1); sp_canvas_item_hide(pc->cl0); sp_canvas_item_hide(pc->cl1); - 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(); } @@ -386,7 +386,7 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const // make sure this is not the last click for a waiting LPE (otherwise we want to finish the path) && pc->expecting_clicks_for_LPE != 1) { - if (Inkscape::have_viable_layer(desktop, dc->_message_context) == false) { + if (Inkscape::have_viable_layer(desktop, dc->message_context) == false) { return TRUE; } @@ -623,20 +623,20 @@ static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion cons } if (anchor && !pc->anchor_statusbar) { - pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("Click or click and drag to close and finish the path.")); + pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("Click or click and drag 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; } ret = TRUE; } else { if (anchor && !pc->anchor_statusbar) { - pc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("Click or click and drag to continue the path from this point.")); + pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("Click or click and 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; } if (!sp_event_context_knot_mouseover(pc)) { @@ -1185,7 +1185,7 @@ static void spdc_pen_set_angle_distance_status_message(SPPenContext *const pc, G if (prefs->getBool("/options/compassangledisplay/value", 0) != 0) angle = angle_to_compass (angle); - pc->_message_context->setF(Inkscape::IMMEDIATE_MESSAGE, message, angle, dist->str); + pc->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, message, angle, dist->str); g_string_free(dist, FALSE); } @@ -1314,7 +1314,7 @@ static void spdc_pen_finish(SPPenContext *const pc, gboolean const closed) pen_disable_events(pc); SPDesktop *const desktop = pc->desktop; - pc->_message_context->clear(); + pc->message_context->clear(); desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Drawing finished")); pc->red_curve->reset(); -- 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/pen-context.cpp | 155 +++++++++++++++++++--------------------------------- 1 file changed, 57 insertions(+), 98 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index fbcb6dae5..1221c7ec7 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -90,59 +90,51 @@ const std::string& SPPenContext::getPrefsPath() { const std::string SPPenContext::prefsPath = "/tools/freehand/pen"; SPPenContext::SPPenContext() : SPDrawContext() { - SPPenContext* pc = this; + this->polylines_only = false; + this->polylines_paraxial = false; + this->expecting_clicks_for_LPE = 0; - pc->polylines_only = false; - pc->polylines_paraxial = false; - pc->expecting_clicks_for_LPE = 0; + this->cursor_shape = cursor_pen_xpm; + this->hot_x = 4; + this->hot_y = 4; - SPEventContext *event_context = SP_EVENT_CONTEXT(pc); - - event_context->cursor_shape = cursor_pen_xpm; - event_context->hot_x = 4; - event_context->hot_y = 4; - - pc->npoints = 0; - pc->mode = MODE_CLICK; - pc->state = POINT; + this->npoints = 0; + this->mode = MODE_CLICK; + this->state = POINT; - pc->c0 = NULL; - pc->c1 = NULL; - pc->cl0 = NULL; - pc->cl1 = NULL; + this->c0 = NULL; + this->c1 = NULL; + this->cl0 = NULL; + this->cl1 = NULL; - pc->events_disabled = 0; + this->events_disabled = 0; - pc->num_clicks = 0; - pc->waiting_LPE = NULL; - pc->waiting_item = NULL; + this->num_clicks = 0; + this->waiting_LPE = NULL; + this->waiting_item = NULL; } SPPenContext::~SPPenContext() { - SPPenContext *pc = SP_PEN_CONTEXT(this); - - if (pc->c0) { - sp_canvas_item_destroy(pc->c0); - pc->c0 = NULL; + if (this->c0) { + sp_canvas_item_destroy(this->c0); + this->c0 = NULL; } - if (pc->c1) { - sp_canvas_item_destroy(pc->c1); - pc->c1 = NULL; + if (this->c1) { + sp_canvas_item_destroy(this->c1); + this->c1 = NULL; } - if (pc->cl0) { - sp_canvas_item_destroy(pc->cl0); - pc->cl0 = NULL; + if (this->cl0) { + sp_canvas_item_destroy(this->cl0); + this->cl0 = NULL; } - if (pc->cl1) { - sp_canvas_item_destroy(pc->cl1); - pc->cl1 = NULL; + if (this->cl1) { + sp_canvas_item_destroy(this->cl1); + this->cl1 = NULL; } - //G_OBJECT_CLASS(sp_pen_context_parent_class)->dispose(object); - - if (pc->expecting_clicks_for_LPE > 0) { + if (this->expecting_clicks_for_LPE > 0) { // we received too few clicks to sanely set the parameter path so we remove the LPE from the item - sp_lpe_item_remove_current_path_effect(pc->waiting_item, false); + sp_lpe_item_remove_current_path_effect(this->waiting_item, false); } } @@ -157,42 +149,34 @@ void sp_pen_context_set_polyline_mode(SPPenContext *const pc) { * Callback to initialize SPPenContext object. */ void SPPenContext::setup() { - SPEventContext* ec = this; - - SPPenContext *pc = SP_PEN_CONTEXT(ec); - -// if (((SPEventContextClass *) sp_pen_context_parent_class)->setup) { -// ((SPEventContextClass *) sp_pen_context_parent_class)->setup(ec); -// } SPDrawContext::setup(); ControlManager &mgr = ControlManager::getManager(); // Pen indicators - pc->c0 = mgr.createControl(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), Inkscape::CTRL_TYPE_ADJ_HANDLE); - mgr.track(pc->c0); + this->c0 = mgr.createControl(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(this)), Inkscape::CTRL_TYPE_ADJ_HANDLE); + mgr.track(this->c0); - pc->c1 = mgr.createControl(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec)), Inkscape::CTRL_TYPE_ADJ_HANDLE); - mgr.track(pc->c1); + this->c1 = mgr.createControl(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(this)), Inkscape::CTRL_TYPE_ADJ_HANDLE); + mgr.track(this->c1); - pc->cl0 = mgr.createControlLine(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec))); - pc->cl1 = mgr.createControlLine(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(ec))); + this->cl0 = mgr.createControlLine(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(this))); + this->cl1 = mgr.createControlLine(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(this))); + sp_canvas_item_hide(this->c0); + sp_canvas_item_hide(this->c1); + sp_canvas_item_hide(this->cl0); + sp_canvas_item_hide(this->cl1); - sp_canvas_item_hide(pc->c0); - sp_canvas_item_hide(pc->c1); - sp_canvas_item_hide(pc->cl0); - sp_canvas_item_hide(pc->cl1); - - sp_event_context_read(ec, "mode"); + sp_event_context_read(this, "mode"); - pc->anchor_statusbar = false; + this->anchor_statusbar = false; - sp_pen_context_set_polyline_mode(pc); + sp_pen_context_set_polyline_mode(this); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/freehand/pen/selcue")) { - ec->enableSelectionCue(); + this->enableSelectionCue(); } } @@ -215,19 +199,12 @@ static void pen_cancel (SPPenContext *const pc) * Finalization callback. */ void SPPenContext::finish() { - SPEventContext* ec = this; - - SPPenContext *pc = SP_PEN_CONTEXT(ec); - - sp_event_context_discard_delayed_snap_event(ec); + sp_event_context_discard_delayed_snap_event(this); - if (pc->npoints != 0) { - pen_cancel (pc); + if (this->npoints != 0) { + pen_cancel(this); } -// if (((SPEventContextClass *) sp_pen_context_parent_class)->finish) { -// ((SPEventContextClass *) sp_pen_context_parent_class)->finish(ec); -// } SPDrawContext::finish(); } @@ -235,16 +212,13 @@ void SPPenContext::finish() { * Callback that sets key to value in pen context. */ void SPPenContext::set(const Inkscape::Preferences::Entry& val) { - SPEventContext* ec = this; - - SPPenContext *pc = SP_PEN_CONTEXT(ec); Glib::ustring name = val.getEntryName(); if (name == "mode") { if ( val.getString() == "drag" ) { - pc->mode = MODE_DRAG; + this->mode = MODE_DRAG; } else { - pc->mode = MODE_CLICK; + this->mode = MODE_CLICK; } } } @@ -292,26 +266,20 @@ static void spdc_endpoint_snap_handle(SPPenContext const *const pc, Geom::Point } bool SPPenContext::item_handler(SPItem* item, GdkEvent* event) { - SPEventContext* ec = this; - - SPPenContext *const pc = SP_PEN_CONTEXT(ec); - gint ret = FALSE; switch (event->type) { case GDK_BUTTON_PRESS: - ret = pen_handle_button_press(pc, event->button); + ret = pen_handle_button_press(this, event->button); break; case GDK_BUTTON_RELEASE: - ret = pen_handle_button_release(pc, event->button); + ret = pen_handle_button_release(this, event->button); break; default: break; } if (!ret) { -// if (((SPEventContextClass *) sp_pen_context_parent_class)->item_handler) -// ret = ((SPEventContextClass *) sp_pen_context_parent_class)->item_handler(ec, item, event); ret = SPDrawContext::item_handler(item, event); } @@ -322,31 +290,27 @@ bool SPPenContext::item_handler(SPItem* item, GdkEvent* event) { * Callback to handle all pen events. */ bool SPPenContext::root_handler(GdkEvent* event) { - SPEventContext* ec = this; - - SPPenContext *const pc = SP_PEN_CONTEXT(ec); - gint ret = FALSE; switch (event->type) { case GDK_BUTTON_PRESS: - ret = pen_handle_button_press(pc, event->button); + ret = pen_handle_button_press(this, event->button); break; case GDK_MOTION_NOTIFY: - ret = pen_handle_motion_notify(pc, event->motion); + ret = pen_handle_motion_notify(this, event->motion); break; case GDK_BUTTON_RELEASE: - ret = pen_handle_button_release(pc, event->button); + ret = pen_handle_button_release(this, event->button); break; case GDK_2BUTTON_PRESS: - ret = pen_handle_2button_press(pc, event->button); + ret = pen_handle_2button_press(this, event->button); break; case GDK_KEY_PRESS: - ret = pen_handle_key_press(pc, event); + ret = pen_handle_key_press(this, event); break; default: @@ -354,11 +318,6 @@ bool SPPenContext::root_handler(GdkEvent* event) { } if (!ret) { -// gint (*const parent_root_handler)(SPEventContext *, GdkEvent *) -// = ((SPEventContextClass *) sp_pen_context_parent_class)->root_handler; -// if (parent_root_handler) { -// ret = parent_root_handler(ec, event); -// } ret = SPDrawContext::root_handler(event); } -- cgit v1.2.3 From 4f857ae84089672e9c7378d327e54889f64c62fb Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Fri, 4 Oct 2013 23:57:28 +0200 Subject: C++ (bzr r12660) --- src/pen-context.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 916fb7cdb..d67bc5e57 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -132,7 +132,7 @@ SPPenContext::~SPPenContext() { if (this->expecting_clicks_for_LPE > 0) { // we received too few clicks to sanely set the parameter path so we remove the LPE from the item - sp_lpe_item_remove_current_path_effect(this->waiting_item, false); + this->waiting_item->removeCurrentPathEffect(false); } } -- cgit v1.2.3 From a970dc423d59ea844bdb1af48d5d9419a5e2a287 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sun, 13 Oct 2013 00:24:05 +0200 Subject: Units: stop newing Unit objects. pass around pointers to "undeletable" Unit objects in the UnitTable. I think we should move to using indexed units, and pass around the index of the unit in the unittable, or smth like that... ? (bzr r12679) --- src/pen-context.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index d67bc5e57..428ebd6d9 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -1137,7 +1137,7 @@ static void spdc_pen_set_angle_distance_status_message(SPPenContext *const pc, G SPDesktop *desktop = SP_EVENT_CONTEXT(pc)->desktop; Geom::Point rel = p - pc->p[pc_point_to_compare]; Inkscape::Util::Quantity q = Inkscape::Util::Quantity(Geom::L2(rel), "px"); - GString *dist = g_string_new(q.string(*desktop->namedview->doc_units).c_str()); + GString *dist = g_string_new(q.string(desktop->namedview->doc_units).c_str()); double angle = atan2(rel[Geom::Y], rel[Geom::X]) * 180 / M_PI; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/options/compassangledisplay/value", 0) != 0) { -- 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/pen-context.cpp | 216 +++++++++++++++++++++++++++------------------------- 1 file changed, 111 insertions(+), 105 deletions(-) (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 428ebd6d9..726034fac 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -42,52 +42,54 @@ #include "context-fns.h" #include "tools-switch.h" #include "ui/control-manager.h" +#include "tool-factory.h" using Inkscape::ControlManager; -static void spdc_pen_set_initial_point(SPPenContext *pc, Geom::Point const p); -static void spdc_pen_set_subsequent_point(SPPenContext *const pc, Geom::Point const p, bool statusbar, guint status = 0); -static void spdc_pen_set_ctrl(SPPenContext *pc, Geom::Point const p, guint state); -static void spdc_pen_finish_segment(SPPenContext *pc, Geom::Point p, guint state); +namespace Inkscape { +namespace UI { +namespace Tools { + +static void spdc_pen_set_initial_point(PenTool *pc, Geom::Point const p); +static void spdc_pen_set_subsequent_point(PenTool *const pc, Geom::Point const p, bool statusbar, guint status = 0); +static void spdc_pen_set_ctrl(PenTool *pc, Geom::Point const p, guint state); +static void spdc_pen_finish_segment(PenTool *pc, Geom::Point p, guint state); -static void spdc_pen_finish(SPPenContext *pc, gboolean closed); +static void spdc_pen_finish(PenTool *pc, gboolean closed); -static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const &bevent); -static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion const &mevent); -static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton const &revent); -static gint pen_handle_2button_press(SPPenContext *const pc, GdkEventButton const &bevent); -static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event); -static void spdc_reset_colors(SPPenContext *pc); +static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bevent); +static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &mevent); +static gint pen_handle_button_release(PenTool *const pc, GdkEventButton const &revent); +static gint pen_handle_2button_press(PenTool *const pc, GdkEventButton const &bevent); +static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event); +static void spdc_reset_colors(PenTool *pc); -static void pen_disable_events(SPPenContext *const pc); -static void pen_enable_events(SPPenContext *const pc); +static void pen_disable_events(PenTool *const pc); +static void pen_enable_events(PenTool *const pc); static Geom::Point pen_drag_origin_w(0, 0); static bool pen_within_tolerance = false; -static int pen_next_paraxial_direction(const SPPenContext *const pc, Geom::Point const &pt, Geom::Point const &origin, guint state); -static void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Point &pt, guint const state, bool snap); +static int pen_next_paraxial_direction(const PenTool *const pc, Geom::Point const &pt, Geom::Point const &origin, guint state); +static void pen_set_to_nearest_horiz_vert(const PenTool *const pc, Geom::Point &pt, guint const state, bool snap); static int pen_last_paraxial_dir = 0; // last used direction in horizontal/vertical mode; 0 = horizontal, 1 = vertical - -#include "tool-factory.h" - namespace { - SPEventContext* createPenContext() { - return new SPPenContext(); + ToolBase* createPenContext() { + return new PenTool(); } bool penContextRegistered = ToolFactory::instance().registerObject("/tools/freehand/pen", createPenContext); } -const std::string& SPPenContext::getPrefsPath() { - return SPPenContext::prefsPath; +const std::string& PenTool::getPrefsPath() { + return PenTool::prefsPath; } -const std::string SPPenContext::prefsPath = "/tools/freehand/pen"; +const std::string PenTool::prefsPath = "/tools/freehand/pen"; -SPPenContext::SPPenContext() : SPDrawContext() { +PenTool::PenTool() : SPDrawContext() { this->polylines_only = false; this->polylines_paraxial = false; this->expecting_clicks_for_LPE = 0; @@ -112,7 +114,7 @@ SPPenContext::SPPenContext() : SPDrawContext() { this->waiting_item = NULL; } -SPPenContext::~SPPenContext() { +PenTool::~PenTool() { if (this->c0) { sp_canvas_item_destroy(this->c0); this->c0 = NULL; @@ -136,7 +138,7 @@ SPPenContext::~SPPenContext() { } } -void sp_pen_context_set_polyline_mode(SPPenContext *const pc) { +void sp_pen_context_set_polyline_mode(PenTool *const pc) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); guint mode = prefs->getInt("/tools/freehand/pen/freehand-mode", 0); pc->polylines_only = (mode == 2 || mode == 3); @@ -144,9 +146,9 @@ void sp_pen_context_set_polyline_mode(SPPenContext *const pc) { } /** - * Callback to initialize SPPenContext object. + * Callback to initialize PenTool object. */ -void SPPenContext::setup() { +void PenTool::setup() { SPDrawContext::setup(); ControlManager &mgr = ControlManager::getManager(); @@ -178,10 +180,10 @@ void SPPenContext::setup() { } } -static void pen_cancel (SPPenContext *const pc) +static void pen_cancel (PenTool *const pc) { pc->num_clicks = 0; - pc->state = SPPenContext::STOP; + pc->state = PenTool::STOP; spdc_reset_colors(pc); sp_canvas_item_hide(pc->c0); sp_canvas_item_hide(pc->c1); @@ -196,7 +198,7 @@ static void pen_cancel (SPPenContext *const pc) /** * Finalization callback. */ -void SPPenContext::finish() { +void PenTool::finish() { sp_event_context_discard_delayed_snap_event(this); if (this->npoints != 0) { @@ -209,7 +211,7 @@ void SPPenContext::finish() { /** * Callback that sets key to value in pen context. */ -void SPPenContext::set(const Inkscape::Preferences::Entry& val) { +void PenTool::set(const Inkscape::Preferences::Entry& val) { Glib::ustring name = val.getEntryName(); if (name == "mode") { @@ -224,7 +226,7 @@ void SPPenContext::set(const Inkscape::Preferences::Entry& val) { /** * Snaps new node relative to the previous node. */ -static void spdc_endpoint_snap(SPPenContext const *const pc, Geom::Point &p, guint const state) +static void spdc_endpoint_snap(PenTool const *const pc, Geom::Point &p, guint const state) { if ((state & GDK_CONTROL_MASK) && !pc->polylines_paraxial) { //CTRL enables angular snapping if (pc->npoints > 0) { @@ -248,7 +250,7 @@ static void spdc_endpoint_snap(SPPenContext const *const pc, Geom::Point &p, gui /** * Snaps new node's handle relative to the new node. */ -static void spdc_endpoint_snap_handle(SPPenContext const *const pc, Geom::Point &p, guint const state) +static void spdc_endpoint_snap_handle(PenTool const *const pc, Geom::Point &p, guint const state) { g_return_if_fail(( pc->npoints == 2 || pc->npoints == 5 )); @@ -263,7 +265,7 @@ static void spdc_endpoint_snap_handle(SPPenContext const *const pc, Geom::Point } } -bool SPPenContext::item_handler(SPItem* item, GdkEvent* event) { +bool PenTool::item_handler(SPItem* item, GdkEvent* event) { gint ret = FALSE; switch (event->type) { @@ -287,7 +289,7 @@ bool SPPenContext::item_handler(SPItem* item, GdkEvent* event) { /** * Callback to handle all pen events. */ -bool SPPenContext::root_handler(GdkEvent* event) { +bool PenTool::root_handler(GdkEvent* event) { gint ret = FALSE; switch (event->type) { @@ -325,7 +327,7 @@ bool SPPenContext::root_handler(GdkEvent* event) { /** * Handle mouse button press event. */ -static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const &bevent) +static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bevent) { if (pc->events_disabled) { // skip event processing if events are disabled @@ -336,7 +338,7 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const SPDesktop * const desktop = SP_EVENT_CONTEXT_DESKTOP(dc); Geom::Point const event_w(bevent.x, bevent.y); Geom::Point event_dt(desktop->w2d(event_w)); - SPEventContext *event_context = SP_EVENT_CONTEXT(pc); + ToolBase *event_context = SP_EVENT_CONTEXT(pc); gint ret = FALSE; if (bevent.button == 1 && !event_context->space_panning @@ -363,26 +365,26 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const SPDrawAnchor * const anchor = spdc_test_inside(pc, event_w); switch (pc->mode) { - case SPPenContext::MODE_CLICK: + case PenTool::MODE_CLICK: // In click mode we add point on release switch (pc->state) { - case SPPenContext::POINT: - case SPPenContext::CONTROL: - case SPPenContext::CLOSE: + case PenTool::POINT: + case PenTool::CONTROL: + case PenTool::CLOSE: break; - case SPPenContext::STOP: + case PenTool::STOP: // This is allowed, if we just canceled curve - pc->state = SPPenContext::POINT; + pc->state = PenTool::POINT; break; default: break; } break; - case SPPenContext::MODE_DRAG: + case PenTool::MODE_DRAG: switch (pc->state) { - case SPPenContext::STOP: + case PenTool::STOP: // This is allowed, if we just canceled curve - case SPPenContext::POINT: + case PenTool::POINT: if (pc->npoints == 0) { Geom::Point p; @@ -438,7 +440,7 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const p = anchor->dp; // we hit an anchor, will finish the curve (either with or without closing) // in release handler - pc->state = SPPenContext::CLOSE; + pc->state = PenTool::CLOSE; if (pc->green_anchor && pc->green_anchor->active) { // we clicked on the current curve start, so close it even if @@ -455,13 +457,13 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const } } - pc->state = pc->polylines_only ? SPPenContext::POINT : SPPenContext::CONTROL; + pc->state = pc->polylines_only ? PenTool::POINT : PenTool::CONTROL; ret = TRUE; break; - case SPPenContext::CONTROL: + case PenTool::CONTROL: g_warning("Button down in CONTROL state"); break; - case SPPenContext::CLOSE: + case PenTool::CLOSE: g_warning("Button down in CLOSE state"); break; default: @@ -499,11 +501,11 @@ static gint pen_handle_button_press(SPPenContext *const pc, GdkEventButton const /** * Handle motion_notify event. */ -static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion const &mevent) +static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &mevent) { gint ret = FALSE; - SPEventContext *event_context = SP_EVENT_CONTEXT(pc); + ToolBase *event_context = SP_EVENT_CONTEXT(pc); SPDesktop * const dt = SP_EVENT_CONTEXT_DESKTOP(event_context); if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { @@ -537,9 +539,9 @@ static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion cons SPDrawAnchor *anchor = spdc_test_inside(pc, event_w); switch (pc->mode) { - case SPPenContext::MODE_CLICK: + case PenTool::MODE_CLICK: switch (pc->state) { - case SPPenContext::POINT: + case PenTool::POINT: if ( pc->npoints != 0 ) { // Only set point, if we are already appending spdc_endpoint_snap(pc, p, mevent.state); @@ -552,23 +554,23 @@ static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion cons m.unSetup(); } break; - case SPPenContext::CONTROL: - case SPPenContext::CLOSE: + case PenTool::CONTROL: + case PenTool::CLOSE: // Placing controls is last operation in CLOSE state spdc_endpoint_snap(pc, p, mevent.state); spdc_pen_set_ctrl(pc, p, mevent.state); ret = TRUE; break; - case SPPenContext::STOP: + case PenTool::STOP: // This is perfectly valid break; default: break; } break; - case SPPenContext::MODE_DRAG: + case PenTool::MODE_DRAG: switch (pc->state) { - case SPPenContext::POINT: + case PenTool::POINT: if ( pc->npoints > 0 ) { // Only set point, if we are already appending @@ -604,8 +606,8 @@ static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion cons } } break; - case SPPenContext::CONTROL: - case SPPenContext::CLOSE: + case PenTool::CONTROL: + case PenTool::CLOSE: // Placing controls is last operation in CLOSE state // snap the handle @@ -619,7 +621,7 @@ static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion cons gobble_motion_events(GDK_BUTTON1_MASK); ret = TRUE; break; - case SPPenContext::STOP: + case PenTool::STOP: // This is perfectly valid break; default: @@ -641,7 +643,7 @@ static gint pen_handle_motion_notify(SPPenContext *const pc, GdkEventMotion cons /** * Handle mouse button release event. */ -static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton const &revent) +static gint pen_handle_button_release(PenTool *const pc, GdkEventButton const &revent) { if (pc->events_disabled) { // skip event processing if events are disabled @@ -649,7 +651,7 @@ static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton con } gint ret = FALSE; - SPEventContext *event_context = SP_EVENT_CONTEXT(pc); + ToolBase *event_context = SP_EVENT_CONTEXT(pc); if ( revent.button == 1 && !event_context->space_panning) { SPDrawContext *dc = SP_DRAW_CONTEXT (pc); @@ -663,9 +665,9 @@ static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton con SPDrawAnchor *anchor = spdc_test_inside(pc, event_w); switch (pc->mode) { - case SPPenContext::MODE_CLICK: + case PenTool::MODE_CLICK: switch (pc->state) { - case SPPenContext::POINT: + case PenTool::POINT: if ( pc->npoints == 0 ) { // Start new thread only with button release if (anchor) { @@ -680,43 +682,43 @@ static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton con p = anchor->dp; } } - pc->state = SPPenContext::CONTROL; + pc->state = PenTool::CONTROL; ret = TRUE; break; - case SPPenContext::CONTROL: + case PenTool::CONTROL: // End current segment spdc_endpoint_snap(pc, p, revent.state); spdc_pen_finish_segment(pc, p, revent.state); - pc->state = SPPenContext::POINT; + pc->state = PenTool::POINT; ret = TRUE; break; - case SPPenContext::CLOSE: + case PenTool::CLOSE: // End current segment if (!anchor) { // Snap node only if not hitting anchor spdc_endpoint_snap(pc, p, revent.state); } spdc_pen_finish_segment(pc, p, revent.state); spdc_pen_finish(pc, TRUE); - pc->state = SPPenContext::POINT; + pc->state = PenTool::POINT; ret = TRUE; break; - case SPPenContext::STOP: + case PenTool::STOP: // This is allowed, if we just canceled curve - pc->state = SPPenContext::POINT; + pc->state = PenTool::POINT; ret = TRUE; break; default: break; } break; - case SPPenContext::MODE_DRAG: + case PenTool::MODE_DRAG: switch (pc->state) { - case SPPenContext::POINT: - case SPPenContext::CONTROL: + case PenTool::POINT: + case PenTool::CONTROL: spdc_endpoint_snap(pc, p, revent.state); spdc_pen_finish_segment(pc, p, revent.state); break; - case SPPenContext::CLOSE: + case PenTool::CLOSE: spdc_endpoint_snap(pc, p, revent.state); spdc_pen_finish_segment(pc, p, revent.state); if (pc->green_closed) { @@ -727,13 +729,13 @@ static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton con spdc_pen_finish(pc, FALSE); } break; - case SPPenContext::STOP: + case PenTool::STOP: // This is allowed, if we just cancelled curve break; default: break; } - pc->state = SPPenContext::POINT; + pc->state = PenTool::POINT; ret = TRUE; break; default: @@ -756,7 +758,7 @@ static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton con if (pc->expecting_clicks_for_LPE == 0 && sp_pen_context_has_waiting_LPE(pc)) { sp_pen_context_set_polyline_mode(pc); - SPEventContext *ec = SP_EVENT_CONTEXT(pc); + ToolBase *ec = SP_EVENT_CONTEXT(pc); Inkscape::Selection *selection = sp_desktop_selection (ec->desktop); if (pc->waiting_LPE) { @@ -773,7 +775,7 @@ static gint pen_handle_button_release(SPPenContext *const pc, GdkEventButton con return ret; } -static gint pen_handle_2button_press(SPPenContext *const pc, GdkEventButton const &bevent) +static gint pen_handle_2button_press(PenTool *const pc, GdkEventButton const &bevent) { gint ret = FALSE; // only end on LMB double click. Otherwise horizontal scrolling causes ending of the path @@ -784,7 +786,7 @@ static gint pen_handle_2button_press(SPPenContext *const pc, GdkEventButton cons return ret; } -static void pen_redraw_all (SPPenContext *const pc) +static void pen_redraw_all (PenTool *const pc) { // green if (pc->green_bpaths) { @@ -838,7 +840,7 @@ static void pen_redraw_all (SPPenContext *const pc) } } -static void pen_lastpoint_move (SPPenContext *const pc, gdouble x, gdouble y) +static void pen_lastpoint_move (PenTool *const pc, gdouble x, gdouble y) { if (pc->npoints != 5) return; @@ -859,12 +861,12 @@ static void pen_lastpoint_move (SPPenContext *const pc, gdouble x, gdouble y) pen_redraw_all(pc); } -static void pen_lastpoint_move_screen (SPPenContext *const pc, gdouble x, gdouble y) +static void pen_lastpoint_move_screen (PenTool *const pc, gdouble x, gdouble y) { pen_lastpoint_move (pc, x / pc->desktop->current_zoom(), y / pc->desktop->current_zoom()); } -static void pen_lastpoint_tocurve (SPPenContext *const pc) +static void pen_lastpoint_tocurve (PenTool *const pc) { if (pc->npoints != 5) return; @@ -879,7 +881,7 @@ static void pen_lastpoint_tocurve (SPPenContext *const pc) pen_redraw_all(pc); } -static void pen_lastpoint_toline (SPPenContext *const pc) +static void pen_lastpoint_toline (PenTool *const pc) { if (pc->npoints != 5) return; @@ -890,7 +892,7 @@ static void pen_lastpoint_toline (SPPenContext *const pc) } -static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) +static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event) { gint ret = FALSE; @@ -1075,7 +1077,7 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) sp_canvas_item_hide(pc->c1); sp_canvas_item_hide(pc->cl0); sp_canvas_item_hide(pc->cl1); - pc->state = SPPenContext::POINT; + pc->state = PenTool::POINT; spdc_pen_set_subsequent_point(pc, pt, true); pen_last_paraxial_dir = !pen_last_paraxial_dir; ret = TRUE; @@ -1087,7 +1089,7 @@ static gint pen_handle_key_press(SPPenContext *const pc, GdkEvent *event) return ret; } -static void spdc_reset_colors(SPPenContext *pc) +static void spdc_reset_colors(PenTool *pc) { // Red pc->red_curve->reset(); @@ -1111,7 +1113,7 @@ static void spdc_reset_colors(SPPenContext *pc) } -static void spdc_pen_set_initial_point(SPPenContext *const pc, Geom::Point const p) +static void spdc_pen_set_initial_point(PenTool *const pc, Geom::Point const p) { g_assert( pc->npoints == 0 ); @@ -1128,7 +1130,7 @@ static void spdc_pen_set_initial_point(SPPenContext *const pc, Geom::Point const * This type of message always shows angle/distance as the last * two parameters ("angle %3.2f°, distance %s"). */ -static void spdc_pen_set_angle_distance_status_message(SPPenContext *const pc, Geom::Point const p, int pc_point_to_compare, gchar const *message) +static void spdc_pen_set_angle_distance_status_message(PenTool *const pc, Geom::Point const p, int pc_point_to_compare, gchar const *message) { g_assert(pc != NULL); g_assert((pc_point_to_compare == 0) || (pc_point_to_compare == 3)); // exclude control handles @@ -1151,7 +1153,7 @@ static void spdc_pen_set_angle_distance_status_message(SPPenContext *const pc, G g_string_free(dist, FALSE); } -static void spdc_pen_set_subsequent_point(SPPenContext *const pc, Geom::Point const p, bool statusbar, guint status) +static void spdc_pen_set_subsequent_point(PenTool *const pc, Geom::Point const p, bool statusbar, guint status) { g_assert( pc->npoints != 0 ); // todo: Check callers to see whether 2 <= npoints is guaranteed. @@ -1196,7 +1198,7 @@ static void spdc_pen_set_subsequent_point(SPPenContext *const pc, Geom::Point co } } -static void spdc_pen_set_ctrl(SPPenContext *const pc, Geom::Point const p, guint const state) +static void spdc_pen_set_ctrl(PenTool *const pc, Geom::Point const p, guint const state) { sp_canvas_item_show(pc->c1); sp_canvas_item_show(pc->cl1); @@ -1214,8 +1216,8 @@ static void spdc_pen_set_ctrl(SPPenContext *const pc, Geom::Point const p, guint sp_canvas_item_show(pc->c0); sp_canvas_item_show(pc->cl0); bool is_symm = false; - if ( ( ( pc->mode == SPPenContext::MODE_CLICK ) && ( state & GDK_CONTROL_MASK ) ) || - ( ( pc->mode == SPPenContext::MODE_DRAG ) && !( state & GDK_SHIFT_MASK ) ) ) { + if ( ( ( pc->mode == PenTool::MODE_CLICK ) && ( state & GDK_CONTROL_MASK ) ) || + ( ( pc->mode == PenTool::MODE_DRAG ) && !( state & GDK_SHIFT_MASK ) ) ) { Geom::Point delta = p - pc->p[3]; pc->p[2] = pc->p[3] - delta; is_symm = true; @@ -1238,7 +1240,7 @@ static void spdc_pen_set_ctrl(SPPenContext *const pc, Geom::Point const p, guint } } -static void spdc_pen_finish_segment(SPPenContext *const pc, Geom::Point const p, guint const state) +static void spdc_pen_finish_segment(PenTool *const pc, Geom::Point const p, guint const state) { if (pc->polylines_paraxial) { pen_last_paraxial_dir = pen_next_paraxial_direction(pc, p, pc->p[0], state); @@ -1264,7 +1266,7 @@ static void spdc_pen_finish_segment(SPPenContext *const pc, Geom::Point const p, } } -static void spdc_pen_finish(SPPenContext *const pc, gboolean const closed) +static void spdc_pen_finish(PenTool *const pc, gboolean const closed) { if (pc->expecting_clicks_for_LPE > 1) { // don't let the path be finished before we have collected the required number of mouse clicks @@ -1285,7 +1287,7 @@ static void spdc_pen_finish(SPPenContext *const pc, gboolean const closed) pc->ea = NULL; pc->npoints = 0; - pc->state = SPPenContext::POINT; + pc->state = PenTool::POINT; sp_canvas_item_hide(pc->c0); sp_canvas_item_hide(pc->c1); @@ -1302,17 +1304,17 @@ static void spdc_pen_finish(SPPenContext *const pc, gboolean const closed) pen_enable_events(pc); } -static void pen_disable_events(SPPenContext *const pc) { +static void pen_disable_events(PenTool *const pc) { pc->events_disabled++; } -static void pen_enable_events(SPPenContext *const pc) { +static void pen_enable_events(PenTool *const pc) { g_return_if_fail(pc->events_disabled != 0); pc->events_disabled--; } -void sp_pen_context_wait_for_LPE_mouse_clicks(SPPenContext *pc, Inkscape::LivePathEffect::EffectType effect_type, +void sp_pen_context_wait_for_LPE_mouse_clicks(PenTool *pc, Inkscape::LivePathEffect::EffectType effect_type, unsigned int num_clicks, bool use_polylines) { if (effect_type == Inkscape::LivePathEffect::INVALID_LPE) @@ -1324,14 +1326,14 @@ void sp_pen_context_wait_for_LPE_mouse_clicks(SPPenContext *pc, Inkscape::LivePa pc->polylines_paraxial = false; // TODO: think if this is correct for all cases } -void sp_pen_context_cancel_waiting_for_LPE(SPPenContext *pc) +void sp_pen_context_cancel_waiting_for_LPE(PenTool *pc) { pc->waiting_LPE_type = Inkscape::LivePathEffect::INVALID_LPE; pc->expecting_clicks_for_LPE = 0; sp_pen_context_set_polyline_mode(pc); } -static int pen_next_paraxial_direction(const SPPenContext *const pc, +static int pen_next_paraxial_direction(const PenTool *const pc, Geom::Point const &pt, Geom::Point const &origin, guint state) { // // after the first mouse click we determine whether the mouse pointer is closest to a @@ -1355,7 +1357,7 @@ static int pen_next_paraxial_direction(const SPPenContext *const pc, } } -void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Point &pt, guint const state, bool snap) +void pen_set_to_nearest_horiz_vert(const PenTool *const pc, Geom::Point &pt, guint const state, bool snap) { Geom::Point const origin = pc->p[0]; @@ -1386,6 +1388,10 @@ void pen_set_to_nearest_horiz_vert(const SPPenContext *const pc, Geom::Point &pt } } +} +} +} + /* 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/pen-context.cpp | 1404 --------------------------------------------------- 1 file changed, 1404 deletions(-) delete mode 100644 src/pen-context.cpp (limited to 'src/pen-context.cpp') diff --git a/src/pen-context.cpp b/src/pen-context.cpp deleted file mode 100644 index 726034fac..000000000 --- a/src/pen-context.cpp +++ /dev/null @@ -1,1404 +0,0 @@ -/** \file - * Pen event context implementation. - */ - -/* - * Authors: - * Lauris Kaplinski - * bulia byak - * Jon A. Cruz - * - * Copyright (C) 2000 Lauris Kaplinski - * Copyright (C) 2000-2001 Ximian, Inc. - * Copyright (C) 2002 Lauris Kaplinski - * Copyright (C) 2004 Monash University - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include -#include -#include - -#include "pen-context.h" -#include "sp-namedview.h" -#include "desktop.h" -#include "desktop-handles.h" -#include "selection.h" -#include "selection-chemistry.h" -#include "draw-anchor.h" -#include "message-stack.h" -#include "message-context.h" -#include "preferences.h" -#include "sp-path.h" -#include "display/sp-canvas.h" -#include "display/curve.h" -#include "pixmaps/cursor-pen.xpm" -#include "display/canvas-bpath.h" -#include "display/sp-ctrlline.h" -#include "display/sodipodi-ctrl.h" -#include -#include "macros.h" -#include "context-fns.h" -#include "tools-switch.h" -#include "ui/control-manager.h" -#include "tool-factory.h" - -using Inkscape::ControlManager; - -namespace Inkscape { -namespace UI { -namespace Tools { - -static void spdc_pen_set_initial_point(PenTool *pc, Geom::Point const p); -static void spdc_pen_set_subsequent_point(PenTool *const pc, Geom::Point const p, bool statusbar, guint status = 0); -static void spdc_pen_set_ctrl(PenTool *pc, Geom::Point const p, guint state); -static void spdc_pen_finish_segment(PenTool *pc, Geom::Point p, guint state); - -static void spdc_pen_finish(PenTool *pc, gboolean closed); - -static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bevent); -static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &mevent); -static gint pen_handle_button_release(PenTool *const pc, GdkEventButton const &revent); -static gint pen_handle_2button_press(PenTool *const pc, GdkEventButton const &bevent); -static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event); -static void spdc_reset_colors(PenTool *pc); - -static void pen_disable_events(PenTool *const pc); -static void pen_enable_events(PenTool *const pc); - -static Geom::Point pen_drag_origin_w(0, 0); -static bool pen_within_tolerance = false; - -static int pen_next_paraxial_direction(const PenTool *const pc, Geom::Point const &pt, Geom::Point const &origin, guint state); -static void pen_set_to_nearest_horiz_vert(const PenTool *const pc, Geom::Point &pt, guint const state, bool snap); - -static int pen_last_paraxial_dir = 0; // last used direction in horizontal/vertical mode; 0 = horizontal, 1 = vertical - -namespace { - ToolBase* createPenContext() { - return new PenTool(); - } - - bool penContextRegistered = ToolFactory::instance().registerObject("/tools/freehand/pen", createPenContext); -} - -const std::string& PenTool::getPrefsPath() { - return PenTool::prefsPath; -} - -const std::string PenTool::prefsPath = "/tools/freehand/pen"; - -PenTool::PenTool() : SPDrawContext() { - this->polylines_only = false; - this->polylines_paraxial = false; - this->expecting_clicks_for_LPE = 0; - - this->cursor_shape = cursor_pen_xpm; - this->hot_x = 4; - this->hot_y = 4; - - this->npoints = 0; - this->mode = MODE_CLICK; - this->state = POINT; - - this->c0 = NULL; - this->c1 = NULL; - this->cl0 = NULL; - this->cl1 = NULL; - - this->events_disabled = 0; - - this->num_clicks = 0; - this->waiting_LPE = NULL; - this->waiting_item = NULL; -} - -PenTool::~PenTool() { - if (this->c0) { - sp_canvas_item_destroy(this->c0); - this->c0 = NULL; - } - if (this->c1) { - sp_canvas_item_destroy(this->c1); - this->c1 = NULL; - } - if (this->cl0) { - sp_canvas_item_destroy(this->cl0); - this->cl0 = NULL; - } - if (this->cl1) { - sp_canvas_item_destroy(this->cl1); - this->cl1 = NULL; - } - - if (this->expecting_clicks_for_LPE > 0) { - // we received too few clicks to sanely set the parameter path so we remove the LPE from the item - this->waiting_item->removeCurrentPathEffect(false); - } -} - -void sp_pen_context_set_polyline_mode(PenTool *const pc) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - guint mode = prefs->getInt("/tools/freehand/pen/freehand-mode", 0); - pc->polylines_only = (mode == 2 || mode == 3); - pc->polylines_paraxial = (mode == 3); -} - -/** - * Callback to initialize PenTool object. - */ -void PenTool::setup() { - SPDrawContext::setup(); - - ControlManager &mgr = ControlManager::getManager(); - - // Pen indicators - this->c0 = mgr.createControl(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(this)), Inkscape::CTRL_TYPE_ADJ_HANDLE); - mgr.track(this->c0); - - this->c1 = mgr.createControl(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(this)), Inkscape::CTRL_TYPE_ADJ_HANDLE); - mgr.track(this->c1); - - this->cl0 = mgr.createControlLine(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(this))); - this->cl1 = mgr.createControlLine(sp_desktop_controls(SP_EVENT_CONTEXT_DESKTOP(this))); - - sp_canvas_item_hide(this->c0); - sp_canvas_item_hide(this->c1); - sp_canvas_item_hide(this->cl0); - sp_canvas_item_hide(this->cl1); - - sp_event_context_read(this, "mode"); - - this->anchor_statusbar = false; - - sp_pen_context_set_polyline_mode(this); - - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (prefs->getBool("/tools/freehand/pen/selcue")) { - this->enableSelectionCue(); - } -} - -static void pen_cancel (PenTool *const pc) -{ - pc->num_clicks = 0; - pc->state = PenTool::STOP; - spdc_reset_colors(pc); - sp_canvas_item_hide(pc->c0); - sp_canvas_item_hide(pc->c1); - sp_canvas_item_hide(pc->cl0); - sp_canvas_item_hide(pc->cl1); - pc->message_context->clear(); - pc->message_context->flash(Inkscape::NORMAL_MESSAGE, _("Drawing cancelled")); - - pc->desktop->canvas->endForcedFullRedraws(); -} - -/** - * Finalization callback. - */ -void PenTool::finish() { - sp_event_context_discard_delayed_snap_event(this); - - if (this->npoints != 0) { - pen_cancel(this); - } - - SPDrawContext::finish(); -} - -/** - * Callback that sets key to value in pen context. - */ -void PenTool::set(const Inkscape::Preferences::Entry& val) { - Glib::ustring name = val.getEntryName(); - - if (name == "mode") { - if ( val.getString() == "drag" ) { - this->mode = MODE_DRAG; - } else { - this->mode = MODE_CLICK; - } - } -} - -/** - * Snaps new node relative to the previous node. - */ -static void spdc_endpoint_snap(PenTool const *const pc, Geom::Point &p, guint const state) -{ - if ((state & GDK_CONTROL_MASK) && !pc->polylines_paraxial) { //CTRL enables angular snapping - if (pc->npoints > 0) { - spdc_endpoint_snap_rotation(pc, p, pc->p[0], state); - } - } else { - // We cannot use shift here to disable snapping because the shift-key is already used - // to toggle the paraxial direction; if the user wants to disable snapping (s)he will - // have to use the %-key, the menu, or the snap toolbar - if ((pc->npoints > 0) && pc->polylines_paraxial) { - // snap constrained - pen_set_to_nearest_horiz_vert(pc, p, state, true); - } else { - // snap freely - boost::optional origin = pc->npoints > 0 ? pc->p[0] : boost::optional(); - spdc_endpoint_snap_free(pc, p, origin, state); // pass the origin, to allow for perpendicular / tangential snapping - } - } -} - -/** - * Snaps new node's handle relative to the new node. - */ -static void spdc_endpoint_snap_handle(PenTool const *const pc, Geom::Point &p, guint const state) -{ - g_return_if_fail(( pc->npoints == 2 || - pc->npoints == 5 )); - - if ((state & GDK_CONTROL_MASK)) { //CTRL enables angular snapping - spdc_endpoint_snap_rotation(pc, p, pc->p[pc->npoints - 2], state); - } else { - if (!(state & GDK_SHIFT_MASK)) { //SHIFT disables all snapping, except the angular snapping above - boost::optional origin = pc->p[pc->npoints - 2]; - spdc_endpoint_snap_free(pc, p, origin, state); - } - } -} - -bool PenTool::item_handler(SPItem* item, GdkEvent* event) { - gint ret = FALSE; - - switch (event->type) { - case GDK_BUTTON_PRESS: - ret = pen_handle_button_press(this, event->button); - break; - case GDK_BUTTON_RELEASE: - ret = pen_handle_button_release(this, event->button); - break; - default: - break; - } - - if (!ret) { - ret = SPDrawContext::item_handler(item, event); - } - - return ret; -} - -/** - * Callback to handle all pen events. - */ -bool PenTool::root_handler(GdkEvent* event) { - gint ret = FALSE; - - switch (event->type) { - case GDK_BUTTON_PRESS: - ret = pen_handle_button_press(this, event->button); - break; - - case GDK_MOTION_NOTIFY: - ret = pen_handle_motion_notify(this, event->motion); - break; - - case GDK_BUTTON_RELEASE: - ret = pen_handle_button_release(this, event->button); - break; - - case GDK_2BUTTON_PRESS: - ret = pen_handle_2button_press(this, event->button); - break; - - case GDK_KEY_PRESS: - ret = pen_handle_key_press(this, event); - break; - - default: - break; - } - - if (!ret) { - ret = SPDrawContext::root_handler(event); - } - - return ret; -} - -/** - * Handle mouse button press event. - */ -static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bevent) -{ - if (pc->events_disabled) { - // skip event processing if events are disabled - return FALSE; - } - - SPDrawContext * const dc = SP_DRAW_CONTEXT(pc); - SPDesktop * const desktop = SP_EVENT_CONTEXT_DESKTOP(dc); - Geom::Point const event_w(bevent.x, bevent.y); - Geom::Point event_dt(desktop->w2d(event_w)); - ToolBase *event_context = SP_EVENT_CONTEXT(pc); - - gint ret = FALSE; - if (bevent.button == 1 && !event_context->space_panning - // make sure this is not the last click for a waiting LPE (otherwise we want to finish the path) - && pc->expecting_clicks_for_LPE != 1) { - - if (Inkscape::have_viable_layer(desktop, dc->message_context) == false) { - return TRUE; - } - - if (!pc->grab ) { - // Grab mouse, so release will not pass unnoticed - pc->grab = SP_CANVAS_ITEM(desktop->acetate); - sp_canvas_item_grab(pc->grab, ( GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_POINTER_MOTION_MASK ), - NULL, bevent.time); - } - - pen_drag_origin_w = event_w; - pen_within_tolerance = true; - - // Test whether we hit any anchor. - SPDrawAnchor * const anchor = spdc_test_inside(pc, event_w); - - switch (pc->mode) { - case PenTool::MODE_CLICK: - // In click mode we add point on release - switch (pc->state) { - case PenTool::POINT: - case PenTool::CONTROL: - case PenTool::CLOSE: - break; - case PenTool::STOP: - // This is allowed, if we just canceled curve - pc->state = PenTool::POINT; - break; - default: - break; - } - break; - case PenTool::MODE_DRAG: - switch (pc->state) { - case PenTool::STOP: - // This is allowed, if we just canceled curve - case PenTool::POINT: - if (pc->npoints == 0) { - - Geom::Point p; - if ((bevent.state & GDK_CONTROL_MASK) && (pc->polylines_only || pc->polylines_paraxial)) { - p = event_dt; - if (!(bevent.state & GDK_SHIFT_MASK)) { - SnapManager &m = desktop->namedview->snap_manager; - m.setup(desktop); - m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE); - m.unSetup(); - } - spdc_create_single_dot(event_context, p, "/tools/freehand/pen", bevent.state); - ret = TRUE; - break; - } - - // TODO: Perhaps it would be nicer to rearrange the following case - // distinction so that the case of a waiting LPE is treated separately - - // Set start anchor - pc->sa = anchor; - if (anchor && !sp_pen_context_has_waiting_LPE(pc)) { - // Adjust point to anchor if needed; if we have a waiting LPE, we need - // a fresh path to be created so don't continue an existing one - p = anchor->dp; - desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Continuing selected path")); - } else { - // This is the first click of a new curve; deselect item so that - // this curve is not combined with it (unless it is drawn from its - // anchor, which is handled by the sibling branch above) - Inkscape::Selection * const selection = sp_desktop_selection(desktop); - if (!(bevent.state & GDK_SHIFT_MASK) || sp_pen_context_has_waiting_LPE(pc)) { - // if we have a waiting LPE, we need a fresh path to be created - // so don't append to an existing one - selection->clear(); - desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new path")); - } else if (selection->singleItem() && SP_IS_PATH(selection->singleItem())) { - desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Appending to selected path")); - } - - // Create green anchor - p = event_dt; - spdc_endpoint_snap(pc, p, bevent.state); - pc->green_anchor = sp_draw_anchor_new(pc, pc->green_curve, TRUE, p); - } - spdc_pen_set_initial_point(pc, p); - } else { - - // Set end anchor - pc->ea = anchor; - Geom::Point p; - if (anchor) { - p = anchor->dp; - // we hit an anchor, will finish the curve (either with or without closing) - // in release handler - pc->state = PenTool::CLOSE; - - if (pc->green_anchor && pc->green_anchor->active) { - // we clicked on the current curve start, so close it even if - // we drag a handle away from it - dc->green_closed = TRUE; - } - ret = TRUE; - break; - - } else { - p = event_dt; - spdc_endpoint_snap(pc, p, bevent.state); // Snap node only if not hitting anchor. - spdc_pen_set_subsequent_point(pc, p, true); - } - } - - pc->state = pc->polylines_only ? PenTool::POINT : PenTool::CONTROL; - ret = TRUE; - break; - case PenTool::CONTROL: - g_warning("Button down in CONTROL state"); - break; - case PenTool::CLOSE: - g_warning("Button down in CLOSE state"); - break; - default: - break; - } - break; - default: - break; - } - } else if (pc->expecting_clicks_for_LPE == 1 && pc->npoints != 0) { - // when the last click for a waiting LPE occurs we want to finish the path - spdc_pen_finish_segment(pc, event_dt, bevent.state); - if (pc->green_closed) { - // finishing at the start anchor, close curve - spdc_pen_finish(pc, TRUE); - } else { - // finishing at some other anchor, finish curve but not close - spdc_pen_finish(pc, FALSE); - } - - ret = TRUE; - } else if (bevent.button == 3 && pc->npoints != 0) { - // right click - finish path - spdc_pen_finish(pc, FALSE); - ret = TRUE; - } - - if (pc->expecting_clicks_for_LPE > 0) { - --pc->expecting_clicks_for_LPE; - } - - return ret; -} - -/** - * Handle motion_notify event. - */ -static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &mevent) -{ - gint ret = FALSE; - - ToolBase *event_context = SP_EVENT_CONTEXT(pc); - SPDesktop * const dt = SP_EVENT_CONTEXT_DESKTOP(event_context); - - if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { - // allow scrolling - return FALSE; - } - - if (pc->events_disabled) { - // skip motion events if pen events are disabled - return FALSE; - } - - Geom::Point const event_w(mevent.x, - mevent.y); - if (pen_within_tolerance) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gint const tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); - if ( Geom::LInfty( event_w - pen_drag_origin_w ) < tolerance ) { - return FALSE; // Do not drag if we're within tolerance from origin. - } - } - // Once the user has moved farther than tolerance from the original location - // (indicating they intend to move the object, not click), then always process the - // motion notify coordinates as given (no snapping back to origin) - pen_within_tolerance = false; - - // Find desktop coordinates - Geom::Point p = dt->w2d(event_w); - - // Test, whether we hit any anchor - SPDrawAnchor *anchor = spdc_test_inside(pc, event_w); - - switch (pc->mode) { - case PenTool::MODE_CLICK: - switch (pc->state) { - case PenTool::POINT: - if ( pc->npoints != 0 ) { - // Only set point, if we are already appending - spdc_endpoint_snap(pc, p, mevent.state); - spdc_pen_set_subsequent_point(pc, p, true); - ret = TRUE; - } else if (!sp_event_context_knot_mouseover(pc)) { - SnapManager &m = dt->namedview->snap_manager; - m.setup(dt); - m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); - m.unSetup(); - } - break; - case PenTool::CONTROL: - case PenTool::CLOSE: - // Placing controls is last operation in CLOSE state - spdc_endpoint_snap(pc, p, mevent.state); - spdc_pen_set_ctrl(pc, p, mevent.state); - ret = TRUE; - break; - case PenTool::STOP: - // This is perfectly valid - break; - default: - break; - } - break; - case PenTool::MODE_DRAG: - switch (pc->state) { - case PenTool::POINT: - if ( pc->npoints > 0 ) { - // Only set point, if we are already appending - - if (!anchor) { // Snap node only if not hitting anchor - spdc_endpoint_snap(pc, p, mevent.state); - spdc_pen_set_subsequent_point(pc, p, true, mevent.state); - } else { - spdc_pen_set_subsequent_point(pc, anchor->dp, false, mevent.state); - } - - if (anchor && !pc->anchor_statusbar) { - pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("Click or click and drag to close and finish the path.")); - pc->anchor_statusbar = true; - } else if (!anchor && pc->anchor_statusbar) { - pc->message_context->clear(); - pc->anchor_statusbar = false; - } - - ret = TRUE; - } else { - if (anchor && !pc->anchor_statusbar) { - pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("Click or click and drag to continue the path from this point.")); - pc->anchor_statusbar = true; - } else if (!anchor && pc->anchor_statusbar) { - pc->message_context->clear(); - pc->anchor_statusbar = false; - } - if (!sp_event_context_knot_mouseover(pc)) { - SnapManager &m = dt->namedview->snap_manager; - m.setup(dt); - m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); - m.unSetup(); - } - } - break; - case PenTool::CONTROL: - case PenTool::CLOSE: - // Placing controls is last operation in CLOSE state - - // snap the handle - spdc_endpoint_snap_handle(pc, p, mevent.state); - - if (!pc->polylines_only) { - spdc_pen_set_ctrl(pc, p, mevent.state); - } else { - spdc_pen_set_ctrl(pc, pc->p[1], mevent.state); - } - gobble_motion_events(GDK_BUTTON1_MASK); - ret = TRUE; - break; - case PenTool::STOP: - // This is perfectly valid - break; - default: - if (!sp_event_context_knot_mouseover(pc)) { - SnapManager &m = dt->namedview->snap_manager; - m.setup(dt); - m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); - m.unSetup(); - } - break; - } - break; - default: - break; - } - return ret; -} - -/** - * Handle mouse button release event. - */ -static gint pen_handle_button_release(PenTool *const pc, GdkEventButton const &revent) -{ - if (pc->events_disabled) { - // skip event processing if events are disabled - return FALSE; - } - - gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(pc); - if ( revent.button == 1 && !event_context->space_panning) { - - SPDrawContext *dc = SP_DRAW_CONTEXT (pc); - - Geom::Point const event_w(revent.x, - revent.y); - // Find desktop coordinates - Geom::Point p = pc->desktop->w2d(event_w); - - // Test whether we hit any anchor. - SPDrawAnchor *anchor = spdc_test_inside(pc, event_w); - - switch (pc->mode) { - case PenTool::MODE_CLICK: - switch (pc->state) { - case PenTool::POINT: - if ( pc->npoints == 0 ) { - // Start new thread only with button release - if (anchor) { - p = anchor->dp; - } - pc->sa = anchor; - spdc_pen_set_initial_point(pc, p); - } else { - // Set end anchor here - pc->ea = anchor; - if (anchor) { - p = anchor->dp; - } - } - pc->state = PenTool::CONTROL; - ret = TRUE; - break; - case PenTool::CONTROL: - // End current segment - spdc_endpoint_snap(pc, p, revent.state); - spdc_pen_finish_segment(pc, p, revent.state); - pc->state = PenTool::POINT; - ret = TRUE; - break; - case PenTool::CLOSE: - // End current segment - if (!anchor) { // Snap node only if not hitting anchor - spdc_endpoint_snap(pc, p, revent.state); - } - spdc_pen_finish_segment(pc, p, revent.state); - spdc_pen_finish(pc, TRUE); - pc->state = PenTool::POINT; - ret = TRUE; - break; - case PenTool::STOP: - // This is allowed, if we just canceled curve - pc->state = PenTool::POINT; - ret = TRUE; - break; - default: - break; - } - break; - case PenTool::MODE_DRAG: - switch (pc->state) { - case PenTool::POINT: - case PenTool::CONTROL: - spdc_endpoint_snap(pc, p, revent.state); - spdc_pen_finish_segment(pc, p, revent.state); - break; - case PenTool::CLOSE: - spdc_endpoint_snap(pc, p, revent.state); - spdc_pen_finish_segment(pc, p, revent.state); - if (pc->green_closed) { - // finishing at the start anchor, close curve - spdc_pen_finish(pc, TRUE); - } else { - // finishing at some other anchor, finish curve but not close - spdc_pen_finish(pc, FALSE); - } - break; - case PenTool::STOP: - // This is allowed, if we just cancelled curve - break; - default: - break; - } - pc->state = PenTool::POINT; - ret = TRUE; - break; - default: - break; - } - - if (pc->grab) { - // Release grab now - sp_canvas_item_ungrab(pc->grab, revent.time); - pc->grab = NULL; - } - - ret = TRUE; - - dc->green_closed = FALSE; - } - - // TODO: can we be sure that the path was created correctly? - // TODO: should we offer an option to collect the clicks in a list? - if (pc->expecting_clicks_for_LPE == 0 && sp_pen_context_has_waiting_LPE(pc)) { - sp_pen_context_set_polyline_mode(pc); - - ToolBase *ec = SP_EVENT_CONTEXT(pc); - Inkscape::Selection *selection = sp_desktop_selection (ec->desktop); - - if (pc->waiting_LPE) { - // we have an already created LPE waiting for a path - pc->waiting_LPE->acceptParamPath(SP_PATH(selection->singleItem())); - selection->add(SP_OBJECT(pc->waiting_item)); - pc->waiting_LPE = NULL; - } else { - // the case that we need to create a new LPE and apply it to the just-drawn path is - // handled in spdc_check_for_and_apply_waiting_LPE() in draw-context.cpp - } - } - - return ret; -} - -static gint pen_handle_2button_press(PenTool *const pc, GdkEventButton const &bevent) -{ - gint ret = FALSE; - // only end on LMB double click. Otherwise horizontal scrolling causes ending of the path - if (pc->npoints != 0 && bevent.button == 1) { - spdc_pen_finish(pc, FALSE); - ret = TRUE; - } - return ret; -} - -static void pen_redraw_all (PenTool *const pc) -{ - // green - if (pc->green_bpaths) { - // remove old piecewise green canvasitems - while (pc->green_bpaths) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(pc->green_bpaths->data)); - pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data); - } - // one canvas bpath for all of green_curve - SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(pc->desktop), pc->green_curve); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(cshape), 0, SP_WIND_RULE_NONZERO); - - pc->green_bpaths = g_slist_prepend(pc->green_bpaths, cshape); - } - - if (pc->green_anchor) - SP_CTRL(pc->green_anchor->ctrl)->moveto(pc->green_anchor->dp); - - pc->red_curve->reset(); - pc->red_curve->moveto(pc->p[0]); - pc->red_curve->curveto(pc->p[1], pc->p[2], pc->p[3]); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve); - - // handles - if (pc->p[0] != pc->p[1]) { - SP_CTRL(pc->c1)->moveto(pc->p[1]); - pc->cl1->setCoords(pc->p[0], pc->p[1]); - sp_canvas_item_show(pc->c1); - sp_canvas_item_show(pc->cl1); - } else { - sp_canvas_item_hide(pc->c1); - sp_canvas_item_hide(pc->cl1); - } - - Geom::Curve const * last_seg = pc->green_curve->last_segment(); - if (last_seg) { - Geom::CubicBezier const * cubic = dynamic_cast( last_seg ); - if ( cubic && - (*cubic)[2] != pc->p[0] ) - { - Geom::Point p2 = (*cubic)[2]; - SP_CTRL(pc->c0)->moveto(p2); - pc->cl0->setCoords(p2, pc->p[0]); - sp_canvas_item_show(pc->c0); - sp_canvas_item_show(pc->cl0); - } else { - sp_canvas_item_hide(pc->c0); - sp_canvas_item_hide(pc->cl0); - } - } -} - -static void pen_lastpoint_move (PenTool *const pc, gdouble x, gdouble y) -{ - if (pc->npoints != 5) - return; - - // green - if (!pc->green_curve->is_empty()) { - pc->green_curve->last_point_additive_move( Geom::Point(x,y) ); - } else { - // start anchor too - if (pc->green_anchor) { - pc->green_anchor->dp += Geom::Point(x, y); - } - } - - // red - pc->p[0] += Geom::Point(x, y); - pc->p[1] += Geom::Point(x, y); - pen_redraw_all(pc); -} - -static void pen_lastpoint_move_screen (PenTool *const pc, gdouble x, gdouble y) -{ - pen_lastpoint_move (pc, x / pc->desktop->current_zoom(), y / pc->desktop->current_zoom()); -} - -static void pen_lastpoint_tocurve (PenTool *const pc) -{ - if (pc->npoints != 5) - return; - - Geom::CubicBezier const * cubic = dynamic_cast( pc->green_curve->last_segment() ); - if ( cubic ) { - pc->p[1] = pc->p[0] + (Geom::Point)( (*cubic)[3] - (*cubic)[2] ); - } else { - pc->p[1] = pc->p[0] + (1./3)*(pc->p[3] - pc->p[0]); - } - - pen_redraw_all(pc); -} - -static void pen_lastpoint_toline (PenTool *const pc) -{ - if (pc->npoints != 5) - return; - - pc->p[1] = pc->p[0]; - - pen_redraw_all(pc); -} - - -static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event) -{ - - gint ret = FALSE; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gdouble const nudge = prefs->getDoubleLimited("/options/nudgedistance/value", 2, 0, 1000, "px"); // in px - - switch (get_group0_keyval (&event->key)) { - - case GDK_KEY_Left: // move last point left - case GDK_KEY_KP_Left: - if (!MOD__CTRL(event)) { // not ctrl - if (MOD__ALT(event)) { // alt - if (MOD__SHIFT(event)) pen_lastpoint_move_screen(pc, -10, 0); // shift - else pen_lastpoint_move_screen(pc, -1, 0); // no shift - } - else { // no alt - if (MOD__SHIFT(event)) pen_lastpoint_move(pc, -10*nudge, 0); // shift - else pen_lastpoint_move(pc, -nudge, 0); // no shift - } - ret = TRUE; - } - break; - case GDK_KEY_Up: // move last point up - case GDK_KEY_KP_Up: - if (!MOD__CTRL(event)) { // not ctrl - if (MOD__ALT(event)) { // alt - if (MOD__SHIFT(event)) pen_lastpoint_move_screen(pc, 0, 10); // shift - else pen_lastpoint_move_screen(pc, 0, 1); // no shift - } - else { // no alt - if (MOD__SHIFT(event)) pen_lastpoint_move(pc, 0, 10*nudge); // shift - else pen_lastpoint_move(pc, 0, nudge); // no shift - } - ret = TRUE; - } - break; - case GDK_KEY_Right: // move last point right - case GDK_KEY_KP_Right: - if (!MOD__CTRL(event)) { // not ctrl - if (MOD__ALT(event)) { // alt - if (MOD__SHIFT(event)) pen_lastpoint_move_screen(pc, 10, 0); // shift - else pen_lastpoint_move_screen(pc, 1, 0); // no shift - } - else { // no alt - if (MOD__SHIFT(event)) pen_lastpoint_move(pc, 10*nudge, 0); // shift - else pen_lastpoint_move(pc, nudge, 0); // no shift - } - ret = TRUE; - } - break; - case GDK_KEY_Down: // move last point down - case GDK_KEY_KP_Down: - if (!MOD__CTRL(event)) { // not ctrl - if (MOD__ALT(event)) { // alt - if (MOD__SHIFT(event)) pen_lastpoint_move_screen(pc, 0, -10); // shift - else pen_lastpoint_move_screen(pc, 0, -1); // no shift - } - else { // no alt - if (MOD__SHIFT(event)) pen_lastpoint_move(pc, 0, -10*nudge); // shift - else pen_lastpoint_move(pc, 0, -nudge); // no shift - } - ret = TRUE; - } - break; - -/*TODO: this is not yet enabled?? looks like some traces of the Geometry tool - case GDK_KEY_P: - case GDK_KEY_p: - if (MOD__SHIFT_ONLY(event)) { - sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::PARALLEL, 2); - ret = TRUE; - } - break; - - case GDK_KEY_C: - case GDK_KEY_c: - if (MOD__SHIFT_ONLY(event)) { - sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::CIRCLE_3PTS, 3); - ret = TRUE; - } - break; - - case GDK_KEY_B: - case GDK_KEY_b: - if (MOD__SHIFT_ONLY(event)) { - sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::PERP_BISECTOR, 2); - ret = TRUE; - } - break; - - case GDK_KEY_A: - case GDK_KEY_a: - if (MOD__SHIFT_ONLY(event)) { - sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::ANGLE_BISECTOR, 3); - ret = TRUE; - } - break; -*/ - - case GDK_KEY_U: - case GDK_KEY_u: - if (MOD__SHIFT_ONLY(event)) { - pen_lastpoint_tocurve(pc); - ret = TRUE; - } - break; - case GDK_KEY_L: - case GDK_KEY_l: - if (MOD__SHIFT_ONLY(event)) { - pen_lastpoint_toline(pc); - ret = TRUE; - } - break; - - case GDK_KEY_Return: - case GDK_KEY_KP_Enter: - if (pc->npoints != 0) { - spdc_pen_finish(pc, FALSE); - ret = TRUE; - } - break; - case GDK_KEY_Escape: - if (pc->npoints != 0) { - // if drawing, cancel, otherwise pass it up for deselecting - pen_cancel (pc); - ret = TRUE; - } - break; - case GDK_KEY_z: - case GDK_KEY_Z: - if (MOD__CTRL_ONLY(event) && pc->npoints != 0) { - // if drawing, cancel, otherwise pass it up for undo - pen_cancel (pc); - ret = TRUE; - } - break; - case GDK_KEY_g: - case GDK_KEY_G: - if (MOD__SHIFT_ONLY(event)) { - sp_selection_to_guides(SP_EVENT_CONTEXT(pc)->desktop); - ret = true; - } - break; - case GDK_KEY_BackSpace: - case GDK_KEY_Delete: - case GDK_KEY_KP_Delete: - if ( pc->green_curve->is_empty() || (pc->green_curve->last_segment() == NULL) ) { - if (!pc->red_curve->is_empty()) { - pen_cancel (pc); - ret = TRUE; - } else { - // do nothing; this event should be handled upstream - } - } else { - // Reset red curve - pc->red_curve->reset(); - // Destroy topmost green bpath - if (pc->green_bpaths) { - if (pc->green_bpaths->data) - sp_canvas_item_destroy(SP_CANVAS_ITEM(pc->green_bpaths->data)); - pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data); - } - // Get last segment - if ( pc->green_curve->is_empty() ) { - g_warning("pen_handle_key_press, case GDK_KP_Delete: Green curve is empty"); - break; - } - // The code below assumes that pc->green_curve has only ONE path ! - Geom::Curve const * crv = pc->green_curve->last_segment(); - pc->p[0] = crv->initialPoint(); - if ( Geom::CubicBezier const * cubic = dynamic_cast(crv)) { - pc->p[1] = (*cubic)[1]; - } else { - pc->p[1] = pc->p[0]; - } - Geom::Point const pt(( pc->npoints < 4 - ? (Geom::Point)(crv->finalPoint()) - : pc->p[3] )); - pc->npoints = 2; - pc->green_curve->backspace(); - sp_canvas_item_hide(pc->c0); - sp_canvas_item_hide(pc->c1); - sp_canvas_item_hide(pc->cl0); - sp_canvas_item_hide(pc->cl1); - pc->state = PenTool::POINT; - spdc_pen_set_subsequent_point(pc, pt, true); - pen_last_paraxial_dir = !pen_last_paraxial_dir; - ret = TRUE; - } - break; - default: - break; - } - return ret; -} - -static void spdc_reset_colors(PenTool *pc) -{ - // Red - pc->red_curve->reset(); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), NULL); - // Blue - pc->blue_curve->reset(); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->blue_bpath), NULL); - // Green - while (pc->green_bpaths) { - sp_canvas_item_destroy(SP_CANVAS_ITEM(pc->green_bpaths->data)); - pc->green_bpaths = g_slist_remove(pc->green_bpaths, pc->green_bpaths->data); - } - pc->green_curve->reset(); - if (pc->green_anchor) { - pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor); - } - pc->sa = NULL; - pc->ea = NULL; - pc->npoints = 0; - pc->red_curve_is_valid = false; -} - - -static void spdc_pen_set_initial_point(PenTool *const pc, Geom::Point const p) -{ - g_assert( pc->npoints == 0 ); - - pc->p[0] = p; - pc->p[1] = p; - pc->npoints = 2; - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), NULL); - - pc->desktop->canvas->forceFullRedrawAfterInterruptions(5); -} - -/** - * Show the status message for the current line/curve segment. - * This type of message always shows angle/distance as the last - * two parameters ("angle %3.2f°, distance %s"). - */ -static void spdc_pen_set_angle_distance_status_message(PenTool *const pc, Geom::Point const p, int pc_point_to_compare, gchar const *message) -{ - g_assert(pc != NULL); - g_assert((pc_point_to_compare == 0) || (pc_point_to_compare == 3)); // exclude control handles - g_assert(message != NULL); - - SPDesktop *desktop = SP_EVENT_CONTEXT(pc)->desktop; - Geom::Point rel = p - pc->p[pc_point_to_compare]; - Inkscape::Util::Quantity q = Inkscape::Util::Quantity(Geom::L2(rel), "px"); - GString *dist = g_string_new(q.string(desktop->namedview->doc_units).c_str()); - double angle = atan2(rel[Geom::Y], rel[Geom::X]) * 180 / M_PI; - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (prefs->getBool("/options/compassangledisplay/value", 0) != 0) { - angle = 90 - angle; - if (angle < 0) { - angle += 360; - } - } - - pc->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, message, angle, dist->str); - g_string_free(dist, FALSE); -} - -static void spdc_pen_set_subsequent_point(PenTool *const pc, Geom::Point const p, bool statusbar, guint status) -{ - g_assert( pc->npoints != 0 ); - // todo: Check callers to see whether 2 <= npoints is guaranteed. - - pc->p[2] = p; - pc->p[3] = p; - pc->p[4] = p; - pc->npoints = 5; - pc->red_curve->reset(); - bool is_curve; - pc->red_curve->moveto(pc->p[0]); - if (pc->polylines_paraxial && !statusbar) { - // we are drawing horizontal/vertical lines and hit an anchor; - Geom::Point const origin = pc->p[0]; - // if the previous point and the anchor are not aligned either horizontally or vertically... - if ((abs(p[Geom::X] - origin[Geom::X]) > 1e-9) && (abs(p[Geom::Y] - origin[Geom::Y]) > 1e-9)) { - // ...then we should draw an L-shaped path, consisting of two paraxial segments - Geom::Point intermed = p; - pen_set_to_nearest_horiz_vert(pc, intermed, status, false); - pc->red_curve->lineto(intermed); - } - pc->red_curve->lineto(p); - is_curve = false; - } else { - // one of the 'regular' modes - if (pc->p[1] != pc->p[0]) { - pc->red_curve->curveto(pc->p[1], p, p); - is_curve = true; - } else { - pc->red_curve->lineto(p); - is_curve = false; - } - } - - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve); - - if (statusbar) { - gchar *message = is_curve ? - _("Curve segment: angle %3.2f°, distance %s; with Ctrl to snap angle, Enter to finish the path" ): - _("Line segment: angle %3.2f°, distance %s; with Ctrl to snap angle, Enter to finish the path"); - spdc_pen_set_angle_distance_status_message(pc, p, 0, message); - } -} - -static void spdc_pen_set_ctrl(PenTool *const pc, Geom::Point const p, guint const state) -{ - sp_canvas_item_show(pc->c1); - sp_canvas_item_show(pc->cl1); - - if ( pc->npoints == 2 ) { - pc->p[1] = p; - sp_canvas_item_hide(pc->c0); - sp_canvas_item_hide(pc->cl0); - SP_CTRL(pc->c1)->moveto(pc->p[1]); - pc->cl1->setCoords(pc->p[0], pc->p[1]); - - spdc_pen_set_angle_distance_status_message(pc, p, 0, _("Curve handle: angle %3.2f°, length %s; with Ctrl to snap angle")); - } else if ( pc->npoints == 5 ) { - pc->p[4] = p; - sp_canvas_item_show(pc->c0); - sp_canvas_item_show(pc->cl0); - bool is_symm = false; - if ( ( ( pc->mode == PenTool::MODE_CLICK ) && ( state & GDK_CONTROL_MASK ) ) || - ( ( pc->mode == PenTool::MODE_DRAG ) && !( state & GDK_SHIFT_MASK ) ) ) { - Geom::Point delta = p - pc->p[3]; - pc->p[2] = pc->p[3] - delta; - is_symm = true; - pc->red_curve->reset(); - pc->red_curve->moveto(pc->p[0]); - pc->red_curve->curveto(pc->p[1], pc->p[2], pc->p[3]); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve); - } - SP_CTRL(pc->c0)->moveto(pc->p[2]); - pc->cl0 ->setCoords(pc->p[3], pc->p[2]); - SP_CTRL(pc->c1)->moveto(pc->p[4]); - pc->cl1->setCoords(pc->p[3], pc->p[4]); - - gchar *message = is_symm ? - _("Curve handle, symmetric: angle %3.2f°, length %s; with Ctrl to snap angle, with Shift to move this handle only") : - _("Curve handle: angle %3.2f°, length %s; with Ctrl to snap angle, with Shift to move this handle only"); - spdc_pen_set_angle_distance_status_message(pc, p, 3, message); - } else { - g_warning("Something bad happened - npoints is %d", pc->npoints); - } -} - -static void spdc_pen_finish_segment(PenTool *const pc, Geom::Point const p, guint const state) -{ - if (pc->polylines_paraxial) { - pen_last_paraxial_dir = pen_next_paraxial_direction(pc, p, pc->p[0], state); - } - - ++pc->num_clicks; - - if (!pc->red_curve->is_empty()) { - pc->green_curve->append_continuous(pc->red_curve, 0.0625); - SPCurve *curve = pc->red_curve->copy(); - /// \todo fixme: - SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(pc->desktop), curve); - curve->unref(); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), pc->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - - pc->green_bpaths = g_slist_prepend(pc->green_bpaths, cshape); - - pc->p[0] = pc->p[3]; - pc->p[1] = pc->p[4]; - pc->npoints = 2; - - pc->red_curve->reset(); - } -} - -static void spdc_pen_finish(PenTool *const pc, gboolean const closed) -{ - if (pc->expecting_clicks_for_LPE > 1) { - // don't let the path be finished before we have collected the required number of mouse clicks - return; - } - - pc->num_clicks = 0; - - pen_disable_events(pc); - - SPDesktop *const desktop = pc->desktop; - pc->message_context->clear(); - desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Drawing finished")); - - pc->red_curve->reset(); - spdc_concat_colors_and_flush(pc, closed); - pc->sa = NULL; - pc->ea = NULL; - - pc->npoints = 0; - pc->state = PenTool::POINT; - - sp_canvas_item_hide(pc->c0); - sp_canvas_item_hide(pc->c1); - sp_canvas_item_hide(pc->cl0); - sp_canvas_item_hide(pc->cl1); - - if (pc->green_anchor) { - pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor); - } - - - pc->desktop->canvas->endForcedFullRedraws(); - - pen_enable_events(pc); -} - -static void pen_disable_events(PenTool *const pc) { - pc->events_disabled++; -} - -static void pen_enable_events(PenTool *const pc) { - g_return_if_fail(pc->events_disabled != 0); - - pc->events_disabled--; -} - -void sp_pen_context_wait_for_LPE_mouse_clicks(PenTool *pc, Inkscape::LivePathEffect::EffectType effect_type, - unsigned int num_clicks, bool use_polylines) -{ - if (effect_type == Inkscape::LivePathEffect::INVALID_LPE) - return; - - pc->waiting_LPE_type = effect_type; - pc->expecting_clicks_for_LPE = num_clicks; - pc->polylines_only = use_polylines; - pc->polylines_paraxial = false; // TODO: think if this is correct for all cases -} - -void sp_pen_context_cancel_waiting_for_LPE(PenTool *pc) -{ - pc->waiting_LPE_type = Inkscape::LivePathEffect::INVALID_LPE; - pc->expecting_clicks_for_LPE = 0; - sp_pen_context_set_polyline_mode(pc); -} - -static int pen_next_paraxial_direction(const PenTool *const pc, - Geom::Point const &pt, Geom::Point const &origin, guint state) { - // - // after the first mouse click we determine whether the mouse pointer is closest to a - // horizontal or vertical segment; for all subsequent mouse clicks, we use the direction - // orthogonal to the last one; pressing Shift toggles the direction - // - // num_clicks is not reliable because spdc_pen_finish_segment is sometimes called too early - // (on first mouse release), in which case num_clicks immediately becomes 1. - // if (pc->num_clicks == 0) { - - if (pc->green_curve->is_empty()) { - // first mouse click - double dist_h = fabs(pt[Geom::X] - origin[Geom::X]); - double dist_v = fabs(pt[Geom::Y] - origin[Geom::Y]); - int ret = (dist_h < dist_v) ? 1 : 0; // 0 = horizontal, 1 = vertical - pen_last_paraxial_dir = (state & GDK_SHIFT_MASK) ? 1 - ret : ret; - return pen_last_paraxial_dir; - } else { - // subsequent mouse click - return (state & GDK_SHIFT_MASK) ? pen_last_paraxial_dir : 1 - pen_last_paraxial_dir; - } -} - -void pen_set_to_nearest_horiz_vert(const PenTool *const pc, Geom::Point &pt, guint const state, bool snap) -{ - Geom::Point const origin = pc->p[0]; - - int next_dir = pen_next_paraxial_direction(pc, pt, origin, state); - - if (!snap) { - if (next_dir == 0) { - // line is forced to be horizontal - pt[Geom::Y] = origin[Geom::Y]; - } else { - // line is forced to be vertical - pt[Geom::X] = origin[Geom::X]; - } - } else { - // Create a horizontal or vertical constraint line - Inkscape::Snapper::SnapConstraint cl(origin, next_dir ? Geom::Point(0, 1) : Geom::Point(1, 0)); - - // Snap along the constraint line; if we didn't snap then still the constraint will be applied - SnapManager &m = pc->desktop->namedview->snap_manager; - - Inkscape::Selection *selection = sp_desktop_selection (pc->desktop); - // selection->singleItem() is the item that is currently being drawn. This item will not be snapped to (to avoid self-snapping) - // TODO: Allow snapping to the stationary parts of the item, and only ignore the last segment - - m.setup(pc->desktop, true, selection->singleItem()); - m.constrainedSnapReturnByRef(pt, Inkscape::SNAPSOURCE_NODE_HANDLE, cl); - m.unSetup(); - } -} - -} -} -} - -/* - 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