diff options
| author | Markus Engel <markus.engel@tum.de> | 2014-03-26 21:24:57 +0000 |
|---|---|---|
| committer | Markus Engel <markus.engel@tum.de> | 2014-03-26 21:24:57 +0000 |
| commit | 490cccade871fc530f7927f9eb8e7425e0e928db (patch) | |
| tree | 3e4641a60fa7a93b5b29365a8fce9e6687e97353 /src | |
| parent | Cleaned up includes of tools / revert experimental casting macro replacements... (diff) | |
| download | inkscape-490cccade871fc530f7927f9eb8e7425e0e928db.tar.gz inkscape-490cccade871fc530f7927f9eb8e7425e0e928db.zip | |
Cleaned up connector-tool, pen-tool, and pencil-tool.
(bzr r13217)
Diffstat (limited to 'src')
| -rw-r--r-- | src/ui/tools/connector-tool.cpp | 96 | ||||
| -rw-r--r-- | src/ui/tools/pen-tool.cpp | 212 | ||||
| -rw-r--r-- | src/ui/tools/pencil-tool.cpp | 93 |
3 files changed, 199 insertions, 202 deletions
diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index d2e23837c..b72ce5346 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -379,7 +379,7 @@ cc_deselect_handle(SPKnot* knot) } bool ConnectorTool::item_handler(SPItem* item, GdkEvent* event) { - gint ret = FALSE; + bool ret = false; Geom::Point p(event->button.x, event->button.y); @@ -412,7 +412,7 @@ bool ConnectorTool::item_handler(SPItem* item, GdkEvent* event) { } } - ret = TRUE; + ret = true; } break; @@ -422,7 +422,7 @@ bool ConnectorTool::item_handler(SPItem* item, GdkEvent* event) { this->_setActiveShape(item); } - ret = TRUE; + ret = true; } break; @@ -434,7 +434,7 @@ bool ConnectorTool::item_handler(SPItem* item, GdkEvent* event) { } bool ConnectorTool::root_handler(GdkEvent* event) { - gint ret = FALSE; + bool ret = false; switch (event->type) { case GDK_BUTTON_PRESS: @@ -469,20 +469,15 @@ gint ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { Geom::Point const event_w(bevent.x, bevent.y); /* Find desktop coordinates */ Geom::Point p = this->desktop->w2d(event_w); - ToolBase *event_context = SP_EVENT_CONTEXT(this); - gint ret = FALSE; - - if ( bevent.button == 1 && !event_context->space_panning ) { - - SPDesktop *desktop = this->desktop; + bool ret = false; + if ( bevent.button == 1 && !this->space_panning ) { if (Inkscape::have_viable_layer(desktop, this->message_context) == false) { - return TRUE; + return true; } - Geom::Point const event_w(bevent.x, - bevent.y); + Geom::Point const event_w(bevent.x, bevent.y); this->xp = bevent.x; this->yp = bevent.y; @@ -520,7 +515,7 @@ gint ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { } this->state = SP_CONNECTOR_CONTEXT_DRAGGING; - ret = TRUE; + ret = true; break; } case SP_CONNECTOR_CONTEXT_DRAGGING: @@ -539,7 +534,7 @@ gint ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { } this->cc_set_active_conn(this->newconn); this->state = SP_CONNECTOR_CONTEXT_IDLE; - ret = TRUE; + ret = true; break; } case SP_CONNECTOR_CONTEXT_CLOSE: @@ -564,20 +559,19 @@ gint ConnectorTool::_handleButtonPress(GdkEventButton const &bevent) { else if (this->npoints != 0) { this->_finish(); this->state = SP_CONNECTOR_CONTEXT_IDLE; - ret = TRUE; + ret = true; } } return ret; } gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { - gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(this); + bool ret = false; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { + if (this->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { // allow middle-button scrolling - return FALSE; + return false; } Geom::Point const event_w(mevent.x, mevent.y); @@ -586,7 +580,7 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); if ( ( abs( (gint) mevent.x - this->xp ) < this->tolerance ) && ( abs( (gint) mevent.y - this->yp ) < this->tolerance ) ) { - return FALSE; // Do not drag if we're within tolerance from origin. + return false; // Do not drag if we're within tolerance from origin. } } // Once the user has moved farther than tolerance from the original location @@ -594,12 +588,10 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { // the motion notify coordinates as given (no snapping back to origin) this->within_tolerance = false; - SPDesktop *const dt = this->desktop; - /* Find desktop coordinates */ - Geom::Point p = dt->w2d(event_w); + Geom::Point p = desktop->w2d(event_w); - SnapManager &m = dt->namedview->snap_manager; + SnapManager &m = desktop->namedview->snap_manager; switch (this->state) { case SP_CONNECTOR_CONTEXT_DRAGGING: @@ -607,12 +599,12 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { gobble_motion_events(mevent.state); // This is movement during a connector creation. if ( this->npoints > 0 ) { - m.setup(dt); + m.setup(desktop); m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); m.unSetup(); this->selection->clear(); this->_setSubsequentPoint(p); - ret = TRUE; + ret = true; } break; } @@ -621,7 +613,7 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { gobble_motion_events(GDK_BUTTON1_MASK); g_assert( SP_IS_PATH(this->clickeditem)); - m.setup(dt); + m.setup(desktop); m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_OTHER_HANDLE); m.unSetup(); @@ -645,7 +637,7 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->red_curve->transform(i2d); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve); - ret = TRUE; + ret = true; break; } case SP_CONNECTOR_CONTEXT_STOP: @@ -653,7 +645,7 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { break; default: if (!this->sp_event_context_knot_mouseover()) { - m.setup(dt); + m.setup(desktop); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_OTHER_HANDLE)); m.unSetup(); } @@ -663,13 +655,10 @@ gint ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) { } gint ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { - gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(this); - if ( revent.button == 1 && !event_context->space_panning ) { + bool ret = false; - SPDesktop *desktop = this->desktop; + if ( revent.button == 1 && !this->space_panning ) { SPDocument *doc = sp_desktop_document(desktop); - SnapManager &m = desktop->namedview->snap_manager; Geom::Point const event_w(revent.x, revent.y); @@ -688,7 +677,7 @@ gint ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { if (this->within_tolerance) { this->_finishSegment(p); - return TRUE; + return true; } // Connector has been created via a drag, end it now. this->_setSubsequentPoint(p); @@ -711,7 +700,7 @@ gint ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { doc->ensureUpToDate(); this->state = SP_CONNECTOR_CONTEXT_IDLE; - return TRUE; + return true; break; } case SP_CONNECTOR_CONTEXT_STOP: @@ -720,13 +709,13 @@ gint ConnectorTool::_handleButtonRelease(GdkEventButton const &revent) { default: break; } - ret = TRUE; + ret = true; } return ret; } gint ConnectorTool::_handleKeyPress(guint const keyval) { - gint ret = FALSE; + bool ret = false; switch (keyval) { case GDK_KEY_Return: @@ -734,13 +723,11 @@ gint ConnectorTool::_handleKeyPress(guint const keyval) { if (this->npoints != 0) { this->_finish(); this->state = SP_CONNECTOR_CONTEXT_IDLE; - ret = TRUE; + ret = true; } break; case GDK_KEY_Escape: if (this->state == SP_CONNECTOR_CONTEXT_REROUTING) { - - SPDesktop *desktop = this->desktop; SPDocument *doc = sp_desktop_document(desktop); this->_reroutingFinish(NULL); @@ -750,13 +737,13 @@ gint ConnectorTool::_handleKeyPress(guint const keyval) { this->state = SP_CONNECTOR_CONTEXT_IDLE; desktop->messageStack()->flash( Inkscape::NORMAL_MESSAGE, _("Connector endpoint drag cancelled.")); - ret = TRUE; + ret = true; } else if (this->npoints != 0) { // if drawing, cancel, otherwise pass it up for deselecting this->state = SP_CONNECTOR_CONTEXT_STOP; this->_resetColors(); - ret = TRUE; + ret = true; } break; default: @@ -766,7 +753,6 @@ gint ConnectorTool::_handleKeyPress(guint const keyval) { } void ConnectorTool::_reroutingFinish(Geom::Point *const p) { - SPDesktop *desktop = this->desktop; SPDocument *doc = sp_desktop_document(desktop); // Clear the temporary path: @@ -819,14 +805,13 @@ void ConnectorTool::_setInitialPoint(Geom::Point const p) { void ConnectorTool::_setSubsequentPoint(Geom::Point const p) { g_assert( this->npoints != 0 ); - SPDesktop *dt = this->desktop; - Geom::Point o = dt->dt2doc(this->p[0]); - Geom::Point d = dt->dt2doc(p); + Geom::Point o = desktop->dt2doc(this->p[0]); + Geom::Point d = desktop->dt2doc(p); Avoid::Point src(o[Geom::X], o[Geom::Y]); Avoid::Point dst(d[Geom::X], d[Geom::Y]); if (!this->newConnRef) { - Avoid::Router *router = sp_desktop_document(dt)->router; + Avoid::Router *router = sp_desktop_document(desktop)->router; this->newConnRef = new Avoid::ConnRef(router); this->newConnRef->setEndpoint(Avoid::VertID::src, src); if (this->isOrthogonal) @@ -841,7 +826,7 @@ void ConnectorTool::_setSubsequentPoint(Geom::Point const p) { this->newConnRef->router()->processTransaction(); // Recreate curve from libavoid route. recreateCurve( this->red_curve, this->newConnRef, this->curvature ); - this->red_curve->transform(dt->doc2dt()); + this->red_curve->transform(desktop->doc2dt()); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve); } @@ -890,7 +875,6 @@ void ConnectorTool::_flushWhite(SPCurve *gc) { /* Now we have to go back to item coordinates at last */ c->transform(this->desktop->dt2doc()); - SPDesktop *desktop = this->desktop; SPDocument *doc = sp_desktop_document(desktop); Inkscape::XML::Document *xml_doc = doc->getReprDoc(); @@ -965,7 +949,6 @@ void ConnectorTool::_finishSegment(Geom::Point const /*p*/) { } void ConnectorTool::_finish() { - SPDesktop *const desktop = this->desktop; desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing connector")); this->red_curve->reset(); @@ -1083,7 +1066,6 @@ endpt_handler(SPKnot */*knot*/, GdkEvent *event, ConnectorTool *cc) } void ConnectorTool::_activeShapeAddKnot(SPItem* item) { - SPDesktop *desktop = this->desktop; SPKnot *knot = sp_knot_new(desktop, 0); knot->owner = item; @@ -1096,10 +1078,12 @@ void ConnectorTool::_activeShapeAddKnot(SPItem* item) { // We don't want to use the standard knot handler. g_signal_handler_disconnect(G_OBJECT(knot->item), knot->_event_handler_id); + knot->_event_handler_id = 0; g_signal_connect(G_OBJECT(knot->item), "event", G_CALLBACK(cc_generic_knot_handler), knot); + sp_knot_set_position(knot, item->avoidRef->getConnectionPointPos() * desktop->doc2dt(), 0); sp_knot_show(knot); this->knots[knot] = 1; @@ -1198,7 +1182,6 @@ void ConnectorTool::cc_set_active_conn(SPItem *item) { } for (int i = 0; i < 2; ++i) { - // Create the handle if it doesn't exist if ( this->endpt_handle[i] == NULL ) { SPKnot *knot = sp_knot_new(this->desktop, @@ -1215,6 +1198,7 @@ void ConnectorTool::cc_set_active_conn(SPItem *item) { // since we don't want this knot to be draggable. g_signal_handler_disconnect(G_OBJECT(knot->item), knot->_event_handler_id); + knot->_event_handler_id = 0; g_signal_connect(G_OBJECT(knot->item), "event", @@ -1228,6 +1212,7 @@ void ConnectorTool::cc_set_active_conn(SPItem *item) { g_signal_handlers_disconnect_by_func( G_OBJECT(this->endpt_handle[i]->item), (void*)G_CALLBACK(endpt_handler), (gpointer) this ); + this->endpt_handler_id[i] = 0; } @@ -1264,10 +1249,13 @@ void cc_create_connection_point(ConnectorTool* cc) { cc_deselect_handle( cc->selected_handle ); } + SPKnot *knot = sp_knot_new(cc->desktop, 0); + // We do not process events on this knot. g_signal_handler_disconnect(G_OBJECT(knot->item), knot->_event_handler_id); + knot->_event_handler_id = 0; cc_select_handle( knot ); diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index 7228690b1..ea66360d0 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -263,7 +263,7 @@ void PenTool::_endpointSnapHandle(Geom::Point &p, guint const state) const { } bool PenTool::item_handler(SPItem* item, GdkEvent* event) { - gint ret = FALSE; + bool ret = false; switch (event->type) { case GDK_BUTTON_PRESS: @@ -287,7 +287,7 @@ bool PenTool::item_handler(SPItem* item, GdkEvent* event) { * Callback to handle all pen events. */ bool PenTool::root_handler(GdkEvent* event) { - gint ret = FALSE; + bool ret = false; switch (event->type) { case GDK_BUTTON_PRESS: @@ -327,22 +327,20 @@ bool PenTool::root_handler(GdkEvent* event) { gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { if (this->events_disabled) { // skip event processing if events are disabled - return FALSE; + return false; } - FreehandBase * const dc = SP_DRAW_CONTEXT(this); - SPDesktop * const desktop = dc->desktop; Geom::Point const event_w(bevent.x, bevent.y); Geom::Point event_dt(desktop->w2d(event_w)); - ToolBase *event_context = SP_EVENT_CONTEXT(this); - gint ret = FALSE; - if (bevent.button == 1 && !event_context->space_panning + bool ret = false; + + if (bevent.button == 1 && !this->space_panning // make sure this is not the last click for a waiting LPE (otherwise we want to finish the path) && this->expecting_clicks_for_LPE != 1) { - if (Inkscape::have_viable_layer(desktop, dc->message_context) == false) { - return TRUE; + if (Inkscape::have_viable_layer(desktop, this->message_context) == false) { + return true; } if (!this->grab ) { @@ -392,8 +390,8 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE); m.unSetup(); } - spdc_create_single_dot(event_context, p, "/tools/freehand/pen", bevent.state); - ret = TRUE; + spdc_create_single_dot(this, p, "/tools/freehand/pen", bevent.state); + ret = true; break; } @@ -441,9 +439,9 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { if (this->green_anchor && this->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; + this->green_closed = TRUE; } - ret = TRUE; + ret = true; break; } else { @@ -454,7 +452,7 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { } this->state = this->polylines_only ? PenTool::POINT : PenTool::CONTROL; - ret = TRUE; + ret = true; break; case PenTool::CONTROL: g_warning("Button down in CONTROL state"); @@ -474,17 +472,17 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { this->_finishSegment(event_dt, bevent.state); if (this->green_closed) { // finishing at the start anchor, close curve - this->_finish(TRUE); + this->_finish(true); } else { // finishing at some other anchor, finish curve but not close - this->_finish(FALSE); + this->_finish(false); } - ret = TRUE; + ret = true; } else if (bevent.button == 3 && this->npoints != 0) { // right click - finish path - this->_finish(FALSE); - ret = TRUE; + this->_finish(false); + ret = true; } if (this->expecting_clicks_for_LPE > 0) { @@ -498,28 +496,25 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { * Handle motion_notify event. */ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { - gint ret = FALSE; - - ToolBase *event_context = SP_EVENT_CONTEXT(this); - SPDesktop * const dt = event_context->desktop; + bool ret = false; - if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { + if (this->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { // allow scrolling - return FALSE; + return false; } if (this->events_disabled) { // skip motion events if pen events are disabled - return FALSE; + return false; } - Geom::Point const event_w(mevent.x, - mevent.y); + 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. + return false; // Do not drag if we're within tolerance from origin. } } // Once the user has moved farther than tolerance from the original location @@ -528,7 +523,7 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { pen_within_tolerance = false; // Find desktop coordinates - Geom::Point p = dt->w2d(event_w); + Geom::Point p = desktop->w2d(event_w); // Test, whether we hit any anchor SPDrawAnchor *anchor = spdc_test_inside(this, event_w); @@ -543,8 +538,8 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->_setSubsequentPoint(p, true); ret = TRUE; } else if (!this->sp_event_context_knot_mouseover()) { - SnapManager &m = dt->namedview->snap_manager; - m.setup(dt); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); m.unSetup(); } @@ -554,7 +549,7 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { // Placing controls is last operation in CLOSE state this->_endpointSnap(p, mevent.state); this->_setCtrl(p, mevent.state); - ret = TRUE; + ret = true; break; case PenTool::STOP: // This is perfectly valid @@ -584,7 +579,7 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->anchor_statusbar = false; } - ret = TRUE; + ret = true; } else { if (anchor && !this->anchor_statusbar) { this->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to continue the path from this point.")); @@ -594,8 +589,8 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->anchor_statusbar = false; } if (!this->sp_event_context_knot_mouseover()) { - SnapManager &m = dt->namedview->snap_manager; - m.setup(dt); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); m.unSetup(); } @@ -614,15 +609,15 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->_setCtrl(this->p[1], mevent.state); } gobble_motion_events(GDK_BUTTON1_MASK); - ret = TRUE; + ret = true; break; case PenTool::STOP: // This is perfectly valid break; default: if (!this->sp_event_context_knot_mouseover()) { - SnapManager &m = dt->namedview->snap_manager; - m.setup(dt); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); m.unSetup(); } @@ -641,17 +636,14 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { if (this->events_disabled) { // skip event processing if events are disabled - return FALSE; + return false; } - gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(this); - if ( revent.button == 1 && !event_context->space_panning) { + bool ret = false; - FreehandBase *dc = SP_DRAW_CONTEXT (this); + if (revent.button == 1 && !this->space_panning) { + Geom::Point const event_w(revent.x, revent.y); - Geom::Point const event_w(revent.x, - revent.y); // Find desktop coordinates Geom::Point p = this->desktop->w2d(event_w); @@ -677,14 +669,14 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { } } this->state = PenTool::CONTROL; - ret = TRUE; + ret = true; break; case PenTool::CONTROL: // End current segment this->_endpointSnap(p, revent.state); this->_finishSegment(p, revent.state); this->state = PenTool::POINT; - ret = TRUE; + ret = true; break; case PenTool::CLOSE: // End current segment @@ -692,14 +684,14 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { this->_endpointSnap(p, revent.state); } this->_finishSegment(p, revent.state); - this->_finish(TRUE); + this->_finish(true); this->state = PenTool::POINT; - ret = TRUE; + ret = true; break; case PenTool::STOP: // This is allowed, if we just canceled curve this->state = PenTool::POINT; - ret = TRUE; + ret = true; break; default: break; @@ -717,10 +709,10 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { this->_finishSegment(p, revent.state); if (this->green_closed) { // finishing at the start anchor, close curve - this->_finish(TRUE); + this->_finish(true); } else { // finishing at some other anchor, finish curve but not close - this->_finish(FALSE); + this->_finish(false); } break; case PenTool::STOP: @@ -730,7 +722,7 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { break; } this->state = PenTool::POINT; - ret = TRUE; + ret = true; break; default: break; @@ -742,9 +734,9 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { this->grab = NULL; } - ret = TRUE; + ret = true; - dc->green_closed = FALSE; + this->green_closed = FALSE; } // TODO: can we be sure that the path was created correctly? @@ -752,13 +744,12 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { if (this->expecting_clicks_for_LPE == 0 && this->hasWaitingLPE()) { this->setPolylineMode(); - ToolBase *ec = SP_EVENT_CONTEXT(this); - Inkscape::Selection *selection = sp_desktop_selection (ec->desktop); + Inkscape::Selection *selection = sp_desktop_selection(this->desktop); if (this->waiting_LPE) { // we have an already created LPE waiting for a path this->waiting_LPE->acceptParamPath(SP_PATH(selection->singleItem())); - selection->add(SP_OBJECT(this->waiting_item)); + selection->add(this->waiting_item); this->waiting_LPE = NULL; } else { // the case that we need to create a new LPE and apply it to the just-drawn path is @@ -770,11 +761,11 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { } gint PenTool::_handle2ButtonPress(GdkEventButton const &bevent) { - gint ret = FALSE; + bool ret = false; // only end on LMB double click. Otherwise horizontal scrolling causes ending of the path if (this->npoints != 0 && bevent.button == 1) { this->_finish(FALSE); - ret = TRUE; + ret = true; } return ret; } @@ -881,67 +872,97 @@ void PenTool::_lastpointToLine() { gint PenTool::_handleKeyPress(GdkEvent *event) { - - gint ret = FALSE; + bool 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)) this->_lastpointMoveScreen(-10, 0); // shift - else this->_lastpointMoveScreen(-1, 0); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMoveScreen(-10, 0); // shift + } + else { + this->_lastpointMoveScreen(-1, 0); // no shift + } } else { // no alt - if (MOD__SHIFT(event)) this->_lastpointMove(-10*nudge, 0); // shift - else this->_lastpointMove(-nudge, 0); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMove(-10*nudge, 0); // shift + } + else { + this->_lastpointMove(-nudge, 0); // no shift + } } - ret = TRUE; + 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)) this->_lastpointMoveScreen(0, 10); // shift - else this->_lastpointMoveScreen(0, 1); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMoveScreen(0, 10); // shift + } + else { + this->_lastpointMoveScreen(0, 1); // no shift + } } else { // no alt - if (MOD__SHIFT(event)) this->_lastpointMove(0, 10*nudge); // shift - else this->_lastpointMove(0, nudge); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMove(0, 10*nudge); // shift + } + else { + this->_lastpointMove(0, nudge); // no shift + } } - ret = TRUE; + 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)) this->_lastpointMoveScreen(10, 0); // shift - else this->_lastpointMoveScreen(1, 0); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMoveScreen(10, 0); // shift + } + else { + this->_lastpointMoveScreen(1, 0); // no shift + } } else { // no alt - if (MOD__SHIFT(event)) this->_lastpointMove(10*nudge, 0); // shift - else this->_lastpointMove(nudge, 0); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMove(10*nudge, 0); // shift + } + else { + this->_lastpointMove(nudge, 0); // no shift + } } - ret = TRUE; + 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)) this->_lastpointMoveScreen(0, -10); // shift - else this->_lastpointMoveScreen(0, -1); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMoveScreen(0, -10); // shift + } + else { + this->_lastpointMoveScreen(0, -1); // no shift + } } else { // no alt - if (MOD__SHIFT(event)) this->_lastpointMove(0, -10*nudge); // shift - else this->_lastpointMove(0, -nudge); // no shift + if (MOD__SHIFT(event)) { + this->_lastpointMove(0, -10*nudge); // shift + } + else { + this->_lastpointMove(0, -nudge); // no shift + } } - ret = TRUE; + ret = true; } break; @@ -983,29 +1004,29 @@ gint PenTool::_handleKeyPress(GdkEvent *event) { case GDK_KEY_u: if (MOD__SHIFT_ONLY(event)) { this->_lastpointToCurve(); - ret = TRUE; + ret = true; } break; case GDK_KEY_L: case GDK_KEY_l: if (MOD__SHIFT_ONLY(event)) { this->_lastpointToLine(); - ret = TRUE; + ret = true; } break; case GDK_KEY_Return: case GDK_KEY_KP_Enter: if (this->npoints != 0) { - this->_finish(FALSE); - ret = TRUE; + this->_finish(false); + ret = true; } break; case GDK_KEY_Escape: if (this->npoints != 0) { // if drawing, cancel, otherwise pass it up for deselecting this->_cancel (); - ret = TRUE; + ret = true; } break; case GDK_KEY_z: @@ -1013,13 +1034,13 @@ gint PenTool::_handleKeyPress(GdkEvent *event) { if (MOD__CTRL_ONLY(event) && this->npoints != 0) { // if drawing, cancel, otherwise pass it up for undo this->_cancel (); - ret = TRUE; + ret = true; } break; case GDK_KEY_g: case GDK_KEY_G: if (MOD__SHIFT_ONLY(event)) { - sp_selection_to_guides(SP_EVENT_CONTEXT(this)->desktop); + sp_selection_to_guides(this->desktop); ret = true; } break; @@ -1029,7 +1050,7 @@ gint PenTool::_handleKeyPress(GdkEvent *event) { if ( this->green_curve->is_empty() || (this->green_curve->last_segment() == NULL) ) { if (!this->red_curve->is_empty()) { this->_cancel (); - ret = TRUE; + ret = true; } else { // do nothing; this event should be handled upstream } @@ -1067,7 +1088,7 @@ gint PenTool::_handleKeyPress(GdkEvent *event) { this->state = PenTool::POINT; this->_setSubsequentPoint(pt, true); pen_last_paraxial_dir = !pen_last_paraxial_dir; - ret = TRUE; + ret = true; } break; default: @@ -1120,7 +1141,6 @@ void PenTool::_setAngleDistanceStatusMessage(Geom::Point const p, int pc_point_t g_assert((pc_point_to_compare == 0) || (pc_point_to_compare == 3)); // exclude control handles g_assert(message != NULL); - SPDesktop *desktop = SP_EVENT_CONTEXT(this)->desktop; Geom::Point rel = p - this->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()); @@ -1257,7 +1277,6 @@ void PenTool::_finish(gboolean const closed) { this->_disableEvents(); - SPDesktop *const desktop = this->desktop; this->message_context->clear(); desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Drawing finished")); @@ -1278,7 +1297,6 @@ void PenTool::_finish(gboolean const closed) { this->green_anchor = sp_draw_anchor_destroy(this->green_anchor); } - this->desktop->canvas->endForcedFullRedraws(); this->_enableEvents(); diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 230ec62af..88bba34cf 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -115,7 +115,7 @@ void PencilTool::_endpointSnap(Geom::Point &p, guint const state) { * Callback for handling all pencil context events. */ bool PencilTool::root_handler(GdkEvent* event) { - gint ret = FALSE; + bool ret = false; switch (event->type) { case GDK_BUTTON_PRESS: @@ -150,16 +150,13 @@ bool PencilTool::root_handler(GdkEvent* event) { } gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { - gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(this); - if ( bevent.button == 1 && !event_context->space_panning) { + bool ret = false; - FreehandBase *dc = SP_DRAW_CONTEXT (this); - SPDesktop *desktop = dc->desktop; + if ( bevent.button == 1 && !this->space_panning) { Inkscape::Selection *selection = sp_desktop_selection(desktop); - if (Inkscape::have_viable_layer(desktop, dc->message_context) == false) { - return TRUE; + if (Inkscape::have_viable_layer(desktop, this->message_context) == false) { + return true; } if (!this->grab) { @@ -185,7 +182,7 @@ gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { switch (this->state) { case SP_PENCIL_CONTEXT_ADDLINE: /* Current segment will be finished with release */ - ret = TRUE; + ret = true; break; default: /* Set first point of sequence */ @@ -196,7 +193,7 @@ gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { if (!(bevent.state & GDK_SHIFT_MASK)) { m.freeSnapReturnByRef(p, Inkscape::SNAPSOURCE_NODE_HANDLE); } - spdc_create_single_dot(event_context, p, "/tools/freehand/pencil", bevent.state); + spdc_create_single_dot(this, p, "/tools/freehand/pencil", bevent.state); m.unSetup(); ret = true; break; @@ -221,7 +218,7 @@ gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { } this->sa = anchor; this->_setStartpoint(p); - ret = TRUE; + ret = true; break; } @@ -231,25 +228,23 @@ gint PencilTool::_handleButtonPress(GdkEventButton const &bevent) { } gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { - SPDesktop *const dt = this->desktop; - if ((mevent.state & GDK_CONTROL_MASK) && (mevent.state & GDK_BUTTON1_MASK)) { // mouse was accidentally moved during Ctrl+click; // ignore the motion and create a single point this->is_drawing = false; - return TRUE; + return true; } - gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(this); - if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { + bool ret = false; + + if (this->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { // allow scrolling - return FALSE; + return false; } if ( ( mevent.state & GDK_BUTTON1_MASK ) && !this->grab && this->is_drawing) { /* Grab mouse, so release will not pass unnoticed */ - this->grab = SP_CANVAS_ITEM(dt->acetate); + this->grab = SP_CANVAS_ITEM(desktop->acetate); sp_canvas_item_grab(this->grab, ( GDK_KEY_PRESS_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK ), @@ -257,7 +252,7 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { } /* Find desktop coordinates */ - Geom::Point p = dt->w2d(Geom::Point(mevent.x, mevent.y)); + Geom::Point p = desktop->w2d(Geom::Point(mevent.x, mevent.y)); /* Test whether we hit any anchor. */ SPDrawAnchor *anchor = spdc_test_inside(this, Geom::Point(mevent.x, mevent.y)); @@ -266,7 +261,7 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gint const tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); if ( Geom::LInfty( Geom::Point(mevent.x,mevent.y) - pencil_drag_origin_w ) < tolerance ) { - return FALSE; // Do not drag if we're within tolerance from origin. + return false; // Do not drag if we're within tolerance from origin. } } @@ -286,13 +281,13 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { p = ptnr; } this->_setEndpoint(p); - ret = TRUE; + ret = true; break; default: /* We may be idle or already freehand */ if ( mevent.state & GDK_BUTTON1_MASK && this->is_drawing ) { if (this->state == SP_PENCIL_CONTEXT_IDLE) { - sp_event_context_discard_delayed_snap_event(event_context); + sp_event_context_discard_delayed_snap_event(this); } this->state = SP_PENCIL_CONTEXT_FREEHAND; @@ -313,7 +308,7 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->ps.push_back(this->p[0]); } this->_addFreehandPoint(p, mevent.state); - ret = TRUE; + ret = true; } if (anchor && !this->anchor_statusbar) { @@ -340,8 +335,8 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { // a) press the mousebutton to start a freehand drawing, or // b) release the mousebutton to finish a freehand drawing if (!this->sp_event_context_knot_mouseover()) { - SnapManager &m = dt->namedview->snap_manager; - m.setup(dt); + SnapManager &m = desktop->namedview->snap_manager; + m.setup(desktop); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); m.unSetup(); } @@ -351,20 +346,16 @@ gint PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { } gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { - gint ret = FALSE; - - ToolBase *event_context = SP_EVENT_CONTEXT(this); - if ( revent.button == 1 && this->is_drawing && !event_context->space_panning) { - SPDesktop *const dt = this->desktop; + bool ret = false; + if ( revent.button == 1 && this->is_drawing && !this->space_panning) { this->is_drawing = false; /* Find desktop coordinates */ - Geom::Point p = dt->w2d(Geom::Point(revent.x, revent.y)); + Geom::Point p = desktop->w2d(Geom::Point(revent.x, revent.y)); /* Test whether we hit any anchor. */ - SPDrawAnchor *anchor = spdc_test_inside(this, Geom::Point(revent.x, - revent.y)); + SPDrawAnchor *anchor = spdc_test_inside(this, Geom::Point(revent.x, revent.y)); switch (this->state) { case SP_PENCIL_CONTEXT_IDLE: @@ -374,7 +365,7 @@ gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { // Ctrl+click creates a single point so only set context in ADDLINE mode when Ctrl isn't pressed this->state = SP_PENCIL_CONTEXT_ADDLINE; } - ret = TRUE; + ret = true; break; case SP_PENCIL_CONTEXT_ADDLINE: /* Finish segment now */ @@ -387,13 +378,12 @@ gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { this->_setEndpoint(p); this->_finishEndpoint(); this->state = SP_PENCIL_CONTEXT_IDLE; - sp_event_context_discard_delayed_snap_event(event_context); - ret = TRUE; + sp_event_context_discard_delayed_snap_event(this); + ret = true; break; case SP_PENCIL_CONTEXT_FREEHAND: if (revent.state & GDK_MOD1_MASK) { /* sketch mode: interpolate the sketched path and improve the current output path with the new interpolation. don't finish sketch */ - this->_sketchInterpolate(); if (this->green_anchor) { @@ -418,7 +408,7 @@ gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { this->ea = anchor; /* Write curves to object */ - dt->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing freehand")); + desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing freehand")); this->_interpolate(); spdc_concat_colors_and_flush(this, FALSE); @@ -431,7 +421,7 @@ gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { // reset sketch mode too this->sketch_n = 0; } - ret = TRUE; + ret = true; break; case SP_PENCIL_CONTEXT_SKETCH: default: @@ -444,7 +434,7 @@ gint PencilTool::_handleButtonRelease(GdkEventButton const &revent) { this->grab = NULL; } - ret = TRUE; + ret = true; } return ret; } @@ -458,7 +448,7 @@ void PencilTool::_cancel() { this->is_drawing = false; this->state = SP_PENCIL_CONTEXT_IDLE; - sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(this)); + sp_event_context_discard_delayed_snap_event(this); this->red_curve->reset(); sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL); @@ -478,7 +468,8 @@ void PencilTool::_cancel() { } gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { - gint ret = FALSE; + bool ret = false; + switch (keyval) { case GDK_KEY_Up: case GDK_KEY_Down: @@ -486,7 +477,7 @@ gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { case GDK_KEY_KP_Down: // Prevent the zoom field from activation. if (!mod_ctrl_only(state)) { - ret = TRUE; + ret = true; } break; case GDK_KEY_Escape: @@ -494,7 +485,7 @@ gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { // if drawing, cancel, otherwise pass it up for deselecting if (this->state != SP_PENCIL_CONTEXT_IDLE) { this->_cancel(); - ret = TRUE; + ret = true; } } break; @@ -504,14 +495,14 @@ gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { // if drawing, cancel, otherwise pass it up for undo if (this->state != SP_PENCIL_CONTEXT_IDLE) { this->_cancel(); - ret = TRUE; + ret = true; } } break; case GDK_KEY_g: case GDK_KEY_G: if (mod_shift_only(state)) { - sp_selection_to_guides(SP_EVENT_CONTEXT(this)->desktop); + sp_selection_to_guides(this->desktop); ret = true; } break; @@ -530,14 +521,14 @@ gint PencilTool::_handleKeyPress(guint const keyval, guint const state) { } gint PencilTool::_handleKeyRelease(guint const keyval, guint const /*state*/) { - gint ret = FALSE; + bool ret = false; switch (keyval) { case GDK_KEY_Alt_L: case GDK_KEY_Alt_R: case GDK_KEY_Meta_L: case GDK_KEY_Meta_R: if (this->state == SP_PENCIL_CONTEXT_SKETCH) { - spdc_concat_colors_and_flush(this, FALSE); + spdc_concat_colors_and_flush(this, false); this->sketch_n = 0; this->sa = NULL; this->ea = NULL; @@ -545,9 +536,9 @@ gint PencilTool::_handleKeyRelease(guint const keyval, guint const /*state*/) { this->green_anchor = sp_draw_anchor_destroy(this->green_anchor); } this->state = SP_PENCIL_CONTEXT_IDLE; - sp_event_context_discard_delayed_snap_event(SP_EVENT_CONTEXT(this)); + sp_event_context_discard_delayed_snap_event(this); this->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Finishing freehand sketch")); - ret = TRUE; + ret = true; } break; default: |
