diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2014-03-27 00:42:29 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2014-03-27 00:42:29 +0000 |
| commit | fefbd217fefe5e29d7913e58ff8b1bc9d8d44939 (patch) | |
| tree | 0fc16570bde5385eeb4933224cdfff67532bf4c4 /src/ui/tools/pen-tool.cpp | |
| parent | Adding cout << output to check bug in Geom::are_near (diff) | |
| parent | Changed some return types from gint to bool. (diff) | |
| download | inkscape-fefbd217fefe5e29d7913e58ff8b1bc9d8d44939.tar.gz inkscape-fefbd217fefe5e29d7913e58ff8b1bc9d8d44939.zip | |
update to trunk
(bzr r11950.1.315)
Diffstat (limited to 'src/ui/tools/pen-tool.cpp')
| -rw-r--r-- | src/ui/tools/pen-tool.cpp | 247 |
1 files changed, 132 insertions, 115 deletions
diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index cea8e67e6..053f1ac3d 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -307,7 +307,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: @@ -331,7 +331,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: @@ -368,14 +368,12 @@ bool PenTool::root_handler(GdkEvent* event) { /** * Handle mouse button press event. */ -gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { +bool 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)); //Test whether we hit any anchor. @@ -387,18 +385,18 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { if( anchor && anchor == this->sa && this->green_curve->is_empty()){ //remove the following line to avoid having one node on top of another _finishSegment(event_dt, bevent.state); - _finish( FALSE); - return TRUE; + _finish( false); + return true; } - return FALSE; + return false; } - 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 ) { @@ -446,8 +444,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; } @@ -482,7 +480,7 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { // Create green anchor p = event_dt; this->_endpointSnap(p, bevent.state); - this->green_anchor = sp_draw_anchor_new(this, this->green_curve, TRUE, p); + this->green_anchor = sp_draw_anchor_new(this, this->green_curve, true, p); } this->_setInitialPoint(p); } else { @@ -499,9 +497,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 { @@ -510,11 +508,9 @@ gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { this->_setSubsequentPoint(p, true); } } - // avoid the creation of a control point so a node is created in the release event this->state = (this->spiro || this->bspline || this->polylines_only) ? PenTool::POINT : PenTool::CONTROL; - - ret = TRUE; + ret = true; break; case PenTool::CONTROL: g_warning("Button down in CONTROL state"); @@ -534,17 +530,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) { @@ -557,30 +553,28 @@ 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 PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { + 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); + //we take out the function the const "tolerance" because we need it later Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gint const tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); + if (pen_within_tolerance) { 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 @@ -589,7 +583,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); @@ -602,10 +596,10 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { // Only set point, if we are already appending this->_endpointSnap(p, mevent.state); this->_setSubsequentPoint(p, true); - ret = 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(); } @@ -615,7 +609,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 @@ -649,7 +643,7 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->anchor_statusbar = false; } - ret = TRUE; + ret = true; } else { if (anchor && !this->anchor_statusbar) { if(!this->spiro && !this->bspline){ @@ -664,8 +658,8 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { } 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(); } @@ -686,15 +680,15 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { } 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(); } @@ -722,20 +716,17 @@ gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { /** * Handle mouse button release event. */ -gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { +bool 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); @@ -744,7 +735,7 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { SPDrawAnchor *anchor = spdc_test_inside(this, event_w); // if we try to create a node in the same place as another node, we skip if((!anchor || anchor == this->sa) && (this->spiro || this->bspline) && this->npoints > 0 && this->p[0] == this->p[3]){ - return TRUE; + return true; } switch (this->mode) { @@ -772,14 +763,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 @@ -791,14 +782,14 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { if(this->spiro){ sp_canvas_item_hide(this->c1); } - 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; @@ -820,10 +811,10 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { } 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: @@ -833,7 +824,7 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { break; } this->state = PenTool::POINT; - ret = TRUE; + ret = true; break; default: break; @@ -844,9 +835,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? @@ -854,13 +845,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 @@ -871,12 +861,12 @@ gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { return ret; } -gint PenTool::_handle2ButtonPress(GdkEventButton const &bevent) { - gint ret = FALSE; +bool PenTool::_handle2ButtonPress(GdkEventButton const &bevent) { + 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; + this->_finish(false); + ret = true; } return ret; } @@ -1066,68 +1056,98 @@ void PenTool::_lastpointToLine() { } -gint PenTool::_handleKeyPress(GdkEvent *event) { - - gint ret = FALSE; +bool PenTool::_handleKeyPress(GdkEvent *event) { + 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; @@ -1136,7 +1156,7 @@ gint PenTool::_handleKeyPress(GdkEvent *event) { case GDK_KEY_p: if (MOD__SHIFT_ONLY(event)) { sp_pen_context_wait_for_LPE_mouse_clicks(pc, Inkscape::LivePathEffect::PARALLEL, 2); - ret = TRUE; + ret = true; } break; @@ -1144,7 +1164,7 @@ gint PenTool::_handleKeyPress(GdkEvent *event) { 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; + ret = true; } break; @@ -1152,7 +1172,7 @@ gint PenTool::_handleKeyPress(GdkEvent *event) { 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; + ret = true; } break; @@ -1160,7 +1180,7 @@ gint PenTool::_handleKeyPress(GdkEvent *event) { 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; + ret = true; } break; */ @@ -1169,29 +1189,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: @@ -1199,13 +1219,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; @@ -1215,7 +1235,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 } @@ -1284,7 +1304,7 @@ gint PenTool::_handleKeyPress(GdkEvent *event) { //redraw this->_bspline_spiro_build(); - ret = TRUE; + ret = true; } break; default: @@ -1340,7 +1360,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()); @@ -1354,7 +1373,7 @@ void PenTool::_setAngleDistanceStatusMessage(Geom::Point const p, int pc_point_t } this->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, message, angle, dist->str); - g_string_free(dist, FALSE); + g_string_free(dist, false); } // this function changes the colors red, green and blue making them transparent or not, depending on if spiro is being used. @@ -2165,7 +2184,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")); @@ -2190,7 +2208,6 @@ void PenTool::_finish(gboolean const closed) { this->green_anchor = sp_draw_anchor_destroy(this->green_anchor); } - this->desktop->canvas->endForcedFullRedraws(); this->_enableEvents(); |
