diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2014-03-02 01:09:08 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2014-03-02 01:09:08 +0000 |
| commit | dc53920a347f1ac1157d863f91a18f206d134fd5 (patch) | |
| tree | ff9765299345e61fc42590dc3f17c042895b438f /src/ui/tools/pen-tool.cpp | |
| parent | update to trunk (diff) | |
| parent | Added some consts. Turned functions to member functions. (diff) | |
| download | inkscape-dc53920a347f1ac1157d863f91a18f206d134fd5.tar.gz inkscape-dc53920a347f1ac1157d863f91a18f206d134fd5.zip | |
Resolving conflicts, maybe broken
(bzr r11950.1.264)
Diffstat (limited to 'src/ui/tools/pen-tool.cpp')
| -rw-r--r-- | src/ui/tools/pen-tool.cpp | 1194 |
1 files changed, 592 insertions, 602 deletions
diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index 9d9313102..c6d87e2d8 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -129,10 +129,6 @@ 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 { @@ -213,15 +209,15 @@ PenTool::~PenTool() { } } -void sp_pen_context_set_polyline_mode(PenTool *const pc) { +void PenTool::setPolylineMode() { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); guint mode = prefs->getInt("/tools/freehand/pen/freehand-mode", 0); //spanish: cambiamos los modos para dar cabida al modo bspline - pc->polylines_only = (mode == 3 || mode == 4); - pc->polylines_paraxial = (mode == 4); + this->polylines_only = (mode == 3 || mode == 4); + this->polylines_paraxial = (mode == 4); //we call the function which defines the Spiro modes and the BSpline //todo: merge to one function only - sp_pen_context_set_mode(pc, mode); + sp_pen_context_set_mode(this, mode); } /* @@ -229,8 +225,8 @@ void sp_pen_context_set_polyline_mode(PenTool *const pc) { */ void sp_pen_context_set_mode(PenTool *const pc, guint mode) { //spanish: definimos los modos - pc->spiro = (mode == 1); - pc->bspline = (mode == 2); + this->spiro = (mode == 1); + this->bspline = (mode == 2); } /** @@ -260,7 +256,7 @@ void PenTool::setup() { this->anchor_statusbar = false; - sp_pen_context_set_polyline_mode(this); + this->setPolylineMode(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/tools/freehand/pen/selcue")) { @@ -268,19 +264,18 @@ void PenTool::setup() { } } -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(); +void PenTool::_cancel() { + this->num_clicks = 0; + this->state = PenTool::STOP; + this->_resetColors(); + sp_canvas_item_hide(this->c0); + sp_canvas_item_hide(this->c1); + sp_canvas_item_hide(this->cl0); + sp_canvas_item_hide(this->cl1); + this->message_context->clear(); + this->message_context->flash(Inkscape::NORMAL_MESSAGE, _("Drawing cancelled")); + + this->desktop->canvas->endForcedFullRedraws(); } /** @@ -290,7 +285,7 @@ void PenTool::finish() { sp_event_context_discard_delayed_snap_event(this); if (this->npoints != 0) { - pen_cancel(this); + this->_cancel(); } FreehandBase::finish(); @@ -311,26 +306,31 @@ void PenTool::set(const Inkscape::Preferences::Entry& val) { } } +bool PenTool::hasWaitingLPE() { + // note: waiting_LPE_type is defined in SPDrawContext + return (this->waiting_LPE != NULL || + this->waiting_LPE_type != Inkscape::LivePathEffect::INVALID_LPE); +} + /** * 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); +void PenTool::_endpointSnap(Geom::Point &p, guint const state) const { + if ((state & GDK_CONTROL_MASK) && !this->polylines_paraxial) { //CTRL enables angular snapping + if (this->npoints > 0) { + spdc_endpoint_snap_rotation(this, p, this->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) { + if ((this->npoints > 0) && this->polylines_paraxial) { // snap constrained - pen_set_to_nearest_horiz_vert(pc, p, state, true); + this->_setToNearestHorizVert(p, state, true); } else { // snap freely - boost::optional<Geom::Point> origin = pc->npoints > 0 ? pc->p[0] : boost::optional<Geom::Point>(); - spdc_endpoint_snap_free(pc, p, origin, state); // pass the origin, to allow for perpendicular / tangential snapping + boost::optional<Geom::Point> origin = this->npoints > 0 ? this->p[0] : boost::optional<Geom::Point>(); + spdc_endpoint_snap_free(this, p, origin, state); // pass the origin, to allow for perpendicular / tangential snapping } } } @@ -338,17 +338,16 @@ static void spdc_endpoint_snap(PenTool const *const pc, Geom::Point &p, guint co /** * 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 )); +void PenTool::_endpointSnapHandle(Geom::Point &p, guint const state) const { + g_return_if_fail(( this->npoints == 2 || + this->npoints == 5 )); if ((state & GDK_CONTROL_MASK)) { //CTRL enables angular snapping - spdc_endpoint_snap_rotation(pc, p, pc->p[pc->npoints - 2], state); + spdc_endpoint_snap_rotation(this, p, this->p[this->npoints - 2], state); } else { if (!(state & GDK_SHIFT_MASK)) { //SHIFT disables all snapping, except the angular snapping above - boost::optional<Geom::Point> origin = pc->p[pc->npoints - 2]; - spdc_endpoint_snap_free(pc, p, origin, state); + boost::optional<Geom::Point> origin = this->p[this->npoints - 2]; + spdc_endpoint_snap_free(this, p, origin, state); } } } @@ -358,10 +357,10 @@ bool PenTool::item_handler(SPItem* item, GdkEvent* event) { switch (event->type) { case GDK_BUTTON_PRESS: - ret = pen_handle_button_press(this, event->button); + ret = this->_handleButtonPress(event->button); break; case GDK_BUTTON_RELEASE: - ret = pen_handle_button_release(this, event->button); + ret = this->_handleButtonRelease(event->button); break; default: break; @@ -382,23 +381,23 @@ bool PenTool::root_handler(GdkEvent* event) { switch (event->type) { case GDK_BUTTON_PRESS: - ret = pen_handle_button_press(this, event->button); + ret = this->_handleButtonPress(event->button); break; case GDK_MOTION_NOTIFY: - ret = pen_handle_motion_notify(this, event->motion); + ret = this->_handleMotionNotify(event->motion); break; case GDK_BUTTON_RELEASE: - ret = pen_handle_button_release(this, event->button); + ret = this->_handleButtonRelease(event->button); break; case GDK_2BUTTON_PRESS: - ret = pen_handle_2button_press(this, event->button); + ret = this->_handle2ButtonPress(event->button); break; case GDK_KEY_PRESS: - ret = pen_handle_key_press(this, event); + ret = this->_handleKeyPress(event); break; default: @@ -415,25 +414,24 @@ bool PenTool::root_handler(GdkEvent* event) { /** * Handle mouse button press event. */ -static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bevent) -{ - if (pc->events_disabled) { +gint PenTool::_handleButtonPress(GdkEventButton const &bevent) { + if (this->events_disabled) { // skip event processing if events are disabled return FALSE; } - FreehandBase * const dc = SP_DRAW_CONTEXT(pc); + 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(pc); //Test whether we hit any anchor. SPDrawAnchor * const anchor = spdc_test_inside(pc, event_w); + ToolBase *event_context = SP_EVENT_CONTEXT(this); //with this we avoid creating a new point over the existing one - if(bevent.button != 3 && (pc->spiro || pc->bspline) && pc->npoints > 0 && pc->p[0] == pc->p[3]){ - pc->state = PenTool::STOP; - if( anchor && anchor == pc->sa && pc->green_curve->is_empty()){ + if(bevent.button != 3 && (this->spiro || this->bspline) && this->npoints > 0 && this->p[0] == this->p[3]){ + this->state = PenTool::STOP; + if( anchor && anchor == this->sa && this->green_curve->is_empty()){ //spanish Borrar siguiente linea para evitar un nodo encima de otro spdc_pen_finish_segment(pc, event_dt, bevent.state); spdc_pen_finish(pc, FALSE); @@ -444,16 +442,16 @@ static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bev 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) { + && this->expecting_clicks_for_LPE != 1) { if (Inkscape::have_viable_layer(desktop, dc->message_context) == false) { return TRUE; } - if (!pc->grab ) { + if (!this->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 | + 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 ), NULL, bevent.time); @@ -462,31 +460,32 @@ static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bev pen_drag_origin_w = event_w; pen_within_tolerance = true; - switch (pc->mode) { + switch (this->mode) { + case PenTool::MODE_CLICK: // In click mode we add point on release - switch (pc->state) { + switch (this->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; + this->state = PenTool::POINT; break; default: break; } break; case PenTool::MODE_DRAG: - switch (pc->state) { + switch (this->state) { case PenTool::STOP: // This is allowed, if we just canceled curve case PenTool::POINT: - if (pc->npoints == 0) { + if (this->npoints == 0) { Geom::Point p; - if ((bevent.state & GDK_CONTROL_MASK) && (pc->polylines_only || pc->polylines_paraxial)) { + if ((bevent.state & GDK_CONTROL_MASK) && (this->polylines_only || this->polylines_paraxial)) { p = event_dt; if (!(bevent.state & GDK_SHIFT_MASK)) { SnapManager &m = desktop->namedview->snap_manager; @@ -503,12 +502,12 @@ static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bev // distinction so that the case of a waiting LPE is treated separately // Set start anchor - pc->sa = anchor; - //spanish: continuamos una curva existente + + this->sa = anchor; if(anchor){ bspline_spiro_start_anchor(pc,(bevent.state & GDK_SHIFT_MASK)); } - if (anchor && (!sp_pen_context_has_waiting_LPE(pc) || pc->bspline || pc->spiro)) { + if (anchor && (!this->hasWaitingLPE()|| this->bspline || this->spiro)) { // 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; @@ -518,7 +517,7 @@ static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bev // 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 (!(bevent.state & GDK_SHIFT_MASK) || this->hasWaitingLPE()) { // if we have a waiting LPE, we need a fresh path to be created // so don't append to an existing one selection->clear(); @@ -529,22 +528,22 @@ static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bev // 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); + this->_endpointSnap(p, bevent.state); + this->green_anchor = sp_draw_anchor_new(this, this->green_curve, TRUE, p); } - spdc_pen_set_initial_point(pc, p); + this->_setInitialPoint(p); } else { // Set end anchor - pc->ea = anchor; + this->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; + this->state = PenTool::CLOSE; - if (pc->green_anchor && pc->green_anchor->active) { + 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; @@ -554,13 +553,13 @@ static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bev } 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); + this->_endpointSnap(p, bevent.state); // Snap node only if not hitting anchor. + this->_setSubsequentPoint(p, true); } } //spanish: evitamos la creación de un punto de control para que se cree el nodo en el evento de soltar - pc->state = (pc->spiro || pc->bspline || pc->polylines_only) ? PenTool::POINT : PenTool::CONTROL; + this->state = (this->spiro || this->bspline || this->polylines_only) ? PenTool::POINT : PenTool::CONTROL; ret = TRUE; break; @@ -577,26 +576,26 @@ static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bev default: break; } - } else if (pc->expecting_clicks_for_LPE == 1 && pc->npoints != 0) { + } else if (this->expecting_clicks_for_LPE == 1 && this->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) { + this->_finishSegment(event_dt, bevent.state); + if (this->green_closed) { // finishing at the start anchor, close curve - spdc_pen_finish(pc, TRUE); + this->_finish(TRUE); } else { // finishing at some other anchor, finish curve but not close - spdc_pen_finish(pc, FALSE); + this->_finish(FALSE); } ret = TRUE; - } else if (bevent.button == 3 && pc->npoints != 0) { + } else if (bevent.button == 3 && this->npoints != 0) { // right click - finish path - spdc_pen_finish(pc, FALSE); + this->_finish(FALSE); ret = TRUE; } - if (pc->expecting_clicks_for_LPE > 0) { - --pc->expecting_clicks_for_LPE; + if (this->expecting_clicks_for_LPE > 0) { + --this->expecting_clicks_for_LPE; } return ret; @@ -605,11 +604,10 @@ static gint pen_handle_button_press(PenTool *const pc, GdkEventButton const &bev /** * Handle motion_notify event. */ -static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &mevent) -{ +gint PenTool::_handleMotionNotify(GdkEventMotion const &mevent) { gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(pc); + ToolBase *event_context = SP_EVENT_CONTEXT(this); SPDesktop * const dt = event_context->desktop; if (event_context->space_panning || mevent.state & GDK_BUTTON2_MASK || mevent.state & GDK_BUTTON3_MASK) { @@ -617,7 +615,7 @@ static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &me return FALSE; } - if (pc->events_disabled) { + if (this->events_disabled) { // skip motion events if pen events are disabled return FALSE; } @@ -641,18 +639,18 @@ static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &me Geom::Point p = dt->w2d(event_w); // Test, whether we hit any anchor - SPDrawAnchor *anchor = spdc_test_inside(pc, event_w); + SPDrawAnchor *anchor = spdc_test_inside(this, event_w); - switch (pc->mode) { + switch (this->mode) { case PenTool::MODE_CLICK: - switch (pc->state) { + switch (this->state) { case PenTool::POINT: - if ( pc->npoints != 0 ) { + if ( this->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); + this->_endpointSnap(p, mevent.state); + this->_setSubsequentPoint(p, true); ret = TRUE; - } else if (!sp_event_context_knot_mouseover(pc)) { + } else if (!this->sp_event_context_knot_mouseover()) { SnapManager &m = dt->namedview->snap_manager; m.setup(dt); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); @@ -662,8 +660,8 @@ static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &me 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); + this->_endpointSnap(p, mevent.state); + this->_setCtrl(p, mevent.state); ret = TRUE; break; case PenTool::STOP: @@ -674,44 +672,45 @@ static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &me } break; case PenTool::MODE_DRAG: - switch (pc->state) { + switch (this->state) { case PenTool::POINT: - if ( pc->npoints > 0 ) { + if ( this->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); + this->_endpointSnap(p, mevent.state); + this->_setSubsequentPoint(p, true, mevent.state); } else { - spdc_pen_set_subsequent_point(pc, anchor->dp, false, mevent.state); + this->_setSubsequentPoint(anchor->dp, false, mevent.state); } - if (anchor && !pc->anchor_statusbar) { - if(!pc->spiro && !pc->bspline){ - pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to close and finish the path.")); + if (anchor && !this->anchor_statusbar) { + if(!this->spiro && !this->bspline){ + this->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to close and finish the path.")); }else{ - pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to close and finish the path. Shift to cusp node")); + this->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to close and finish the path. Shift to cusp node")); } - pc->anchor_statusbar = true; - } else if (!anchor && pc->anchor_statusbar) { - pc->message_context->clear(); - pc->anchor_statusbar = false; + this->anchor_statusbar = true; + } else if (!anchor && this->anchor_statusbar) { + this->message_context->clear(); + this->anchor_statusbar = false; } ret = TRUE; } else { - if (anchor && !pc->anchor_statusbar) { - if(!pc->spiro && !pc->bspline){ - pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to continue the path from this point.")); + if (anchor && !this->anchor_statusbar) { + if(!this->spiro && !this->bspline){ + this->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to continue the path from this point.")); }else{ - pc->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to continue the path from this point. Shift to cusp node")); + this->message_context->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to continue the path from this point. Shift to cusp node")); } - pc->anchor_statusbar = true; - } else if (!anchor && pc->anchor_statusbar) { - pc->message_context->clear(); - pc->anchor_statusbar = false; + this->anchor_statusbar = true; + } else if (!anchor && this->anchor_statusbar) { + this->message_context->clear(); + this->anchor_statusbar = false; + } - if (!sp_event_context_knot_mouseover(pc)) { + if (!this->sp_event_context_knot_mouseover()) { SnapManager &m = dt->namedview->snap_manager; m.setup(dt); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); @@ -725,11 +724,12 @@ static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &me // snap the handle - spdc_endpoint_snap_handle(pc, p, mevent.state); - if (!pc->polylines_only) { - spdc_pen_set_ctrl(pc, p, mevent.state); + this->_endpointSnapHandle(p, mevent.state); + + if (!this->polylines_only) { + this->_setCtrl(p, mevent.state); } else { - spdc_pen_set_ctrl(pc, pc->p[1], mevent.state); + this->_setCtrl(this->p[1], mevent.state); } gobble_motion_events(GDK_BUTTON1_MASK); @@ -739,7 +739,7 @@ static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &me // This is perfectly valid break; default: - if (!sp_event_context_knot_mouseover(pc)) { + if (!this->sp_event_context_knot_mouseover()) { SnapManager &m = dt->namedview->snap_manager; m.setup(dt); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); @@ -752,7 +752,7 @@ static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &me break; } //spanish: lanzamos la función "bspline_spiro_motion" al moverse el ratón o cuando se para. - if(pc->bspline){ + if(this->bspline){ bspline_spiro_color(pc); bspline_spiro_motion(pc,(mevent.state & GDK_SHIFT_MASK)); }else{ @@ -769,84 +769,84 @@ static gint pen_handle_motion_notify(PenTool *const pc, GdkEventMotion const &me /** * Handle mouse button release event. */ -static gint pen_handle_button_release(PenTool *const pc, GdkEventButton const &revent) -{ - if (pc->events_disabled) { +gint PenTool::_handleButtonRelease(GdkEventButton const &revent) { + if (this->events_disabled) { // skip event processing if events are disabled return FALSE; } gint ret = FALSE; - ToolBase *event_context = SP_EVENT_CONTEXT(pc); + ToolBase *event_context = SP_EVENT_CONTEXT(this); if ( revent.button == 1 && !event_context->space_panning) { - FreehandBase *dc = SP_DRAW_CONTEXT (pc); + FreehandBase *dc = SP_DRAW_CONTEXT (this); Geom::Point const event_w(revent.x, revent.y); // Find desktop coordinates - Geom::Point p = pc->desktop->w2d(event_w); + Geom::Point p = this->desktop->w2d(event_w); // Test whether we hit any anchor. - SPDrawAnchor *anchor = spdc_test_inside(pc, event_w); + + SPDrawAnchor *anchor = spdc_test_inside(this, event_w); //with this we avoid creating a new point over the existing one //spanish: si intentamos crear un nodo en el mismo sitio que el origen, paramos. - if((!anchor || anchor == pc->sa) && (pc->spiro || pc->bspline) && pc->npoints > 0 && pc->p[0] == pc->p[3]){ + if((!anchor || anchor == this->sa) && (this->spiro || this->bspline) && this->npoints > 0 && this->p[0] == this->p[3]){ return TRUE; } - switch (pc->mode) { + switch (this->mode) { case PenTool::MODE_CLICK: - switch (pc->state) { + switch (this->state) { case PenTool::POINT: - if ( pc->npoints == 0 ) { + if ( this->npoints == 0 ) { // Start new thread only with button release if (anchor) { p = anchor->dp; } - pc->sa = anchor; + this->sa = anchor; //spanish: continuamos una curva existente if (anchor) { - if(pc->bspline || pc->spiro){ + if(this->bspline || this->spiro){ bspline_spiro_start_anchor(pc,(revent.state & GDK_SHIFT_MASK)); } } - spdc_pen_set_initial_point(pc, p); + this->_setInitialPoint(p); } else { // Set end anchor here - pc->ea = anchor; + this->ea = anchor; if (anchor) { p = anchor->dp; } } - pc->state = PenTool::CONTROL; + this->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; + this->_endpointSnap(p, revent.state); + this->_finishSegment(p, revent.state); + this->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); + this->_endpointSnap(p, revent.state); } - spdc_pen_finish_segment(pc, p, revent.state); + this->_finishSegment(p, revent.state); //spanish: ocultamos la guia del penultimo nodo al cerrar la curva - if(pc->spiro){ - sp_canvas_item_hide(pc->c1); + if(this->spiro){ + sp_canvas_item_hide(this->c1); } - spdc_pen_finish(pc, TRUE); - pc->state = PenTool::POINT; + this->_finish(TRUE); + this->state = PenTool::POINT; ret = TRUE; break; case PenTool::STOP: // This is allowed, if we just canceled curve - pc->state = PenTool::POINT; + this->state = PenTool::POINT; ret = TRUE; break; default: @@ -854,25 +854,25 @@ static gint pen_handle_button_release(PenTool *const pc, GdkEventButton const &r } break; case PenTool::MODE_DRAG: - switch (pc->state) { + switch (this->state) { case PenTool::POINT: case PenTool::CONTROL: - spdc_endpoint_snap(pc, p, revent.state); - spdc_pen_finish_segment(pc, p, revent.state); + this->_endpointSnap(p, revent.state); + this->_finishSegment(p, revent.state); break; case PenTool::CLOSE: - spdc_endpoint_snap(pc, p, revent.state); - spdc_pen_finish_segment(pc, p, revent.state); + this->_endpointSnap(p, revent.state); + this->_finishSegment(p, revent.state); //spanish: ocultamos la guia del penultimo nodo al cerrar la curva - if(pc->spiro){ - sp_canvas_item_hide(pc->c1); + if(this->spiro){ + sp_canvas_item_hide(this->c1); } - if (pc->green_closed) { + if (this->green_closed) { // finishing at the start anchor, close curve - spdc_pen_finish(pc, TRUE); + this->_finish(TRUE); } else { // finishing at some other anchor, finish curve but not close - spdc_pen_finish(pc, FALSE); + this->_finish(FALSE); } break; case PenTool::STOP: @@ -881,16 +881,16 @@ static gint pen_handle_button_release(PenTool *const pc, GdkEventButton const &r default: break; } - pc->state = PenTool::POINT; + this->state = PenTool::POINT; ret = TRUE; break; default: break; } - if (pc->grab) { + if (this->grab) { // Release grab now - sp_canvas_item_ungrab(pc->grab, revent.time); - pc->grab = NULL; + sp_canvas_item_ungrab(this->grab, revent.time); + this->grab = NULL; } ret = TRUE; @@ -900,17 +900,17 @@ static gint pen_handle_button_release(PenTool *const pc, GdkEventButton const &r // 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); + if (this->expecting_clicks_for_LPE == 0 && this->hasWaitingLPE()) { + this->setPolylineMode(); - ToolBase *ec = SP_EVENT_CONTEXT(pc); + ToolBase *ec = SP_EVENT_CONTEXT(this); Inkscape::Selection *selection = sp_desktop_selection (ec->desktop); - if (pc->waiting_LPE) { + if (this->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; + this->waiting_LPE->acceptParamPath(SP_PATH(selection->singleItem())); + selection->add(SP_OBJECT(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 // handled in spdc_check_for_and_apply_waiting_LPE() in draw-context.cpp @@ -920,68 +920,66 @@ static gint pen_handle_button_release(PenTool *const pc, GdkEventButton const &r return ret; } -static gint pen_handle_2button_press(PenTool *const pc, GdkEventButton const &bevent) -{ +gint PenTool::_handle2ButtonPress(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); + if (this->npoints != 0 && bevent.button == 1) { + this->_finish(FALSE); ret = TRUE; } return ret; } -static void pen_redraw_all (PenTool *const pc) -{ +void PenTool::_redrawAll() { // green - if (pc->green_bpaths) { + if (this->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); + while (this->green_bpaths) { + sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data)); + this->green_bpaths = g_slist_remove(this->green_bpaths, this->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); + SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(this->desktop), this->green_curve); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), this->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); + this->green_bpaths = g_slist_prepend(this->green_bpaths, cshape); } - if (pc->green_anchor) - SP_CTRL(pc->green_anchor->ctrl)->moveto(pc->green_anchor->dp); + if (this->green_anchor) + SP_CTRL(this->green_anchor->ctrl)->moveto(this->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); + this->red_curve->reset(); + this->red_curve->moveto(this->p[0]); + this->red_curve->curveto(this->p[1], this->p[2], this->p[3]); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve); // handles //spanish: ocultamos los tiradores en modo bspline y spiro - if (pc->p[0] != pc->p[1] && !pc->spiro && !pc->bspline) { - 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); + if (this->p[0] != this->p[1] && !this->spiro && !this->bspline) { + SP_CTRL(this->c1)->moveto(this->p[1]); + this->cl1->setCoords(this->p[0], this->p[1]); + sp_canvas_item_show(this->c1); + sp_canvas_item_show(this->cl1); } else { - sp_canvas_item_hide(pc->c1); - sp_canvas_item_hide(pc->cl1); + sp_canvas_item_hide(this->c1); + sp_canvas_item_hide(this->cl1); } - Geom::Curve const * last_seg = pc->green_curve->last_segment(); + Geom::Curve const * last_seg = this->green_curve->last_segment(); if (last_seg) { Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>( last_seg ); //spanish: ocultamos los tiradores en modo bspline y spiro if ( cubic && - (*cubic)[2] != pc->p[0] && !pc->spiro && !pc->bspline ) + (*cubic)[2] != this->p[0] && !this->spiro && !this->bspline ) { 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); + SP_CTRL(this->c0)->moveto(p2); + this->cl0->setCoords(p2, this->p[0]); + sp_canvas_item_show(this->c0); + sp_canvas_item_show(this->cl0); } else { - sp_canvas_item_hide(pc->c0); - sp_canvas_item_hide(pc->cl0); + sp_canvas_item_hide(this->c0); + sp_canvas_item_hide(this->cl0); } } @@ -991,137 +989,134 @@ static void pen_redraw_all (PenTool *const pc) bspline_spiro_build(pc); } -static void pen_lastpoint_move (PenTool *const pc, gdouble x, gdouble y) -{ - if (pc->npoints != 5) +void PenTool::_lastpointMove(gdouble x, gdouble y) { + if (this->npoints != 5) return; // green - if (!pc->green_curve->is_empty()) { - pc->green_curve->last_point_additive_move( Geom::Point(x,y) ); + if (!this->green_curve->is_empty()) { + this->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); + if (this->green_anchor) { + this->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); + + this->p[0] += Geom::Point(x, y); + this->p[1] += Geom::Point(x, y); + this->_redrawAll(); } -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()); +void PenTool::_lastpointMoveScreen(gdouble x, gdouble y) { + this->_lastpointMove(x / this->desktop->current_zoom(), y / this->desktop->current_zoom()); } -static void pen_lastpoint_tocurve (PenTool *const pc) -{ +void PenTool::_lastpointToCurve() { //spanish: evitamos que si la "red_curve" tiene solo dos puntos -recta- no se pare aqui. - if (pc->npoints != 5 && !pc->spiro && !pc->bspline) + if (this->npoints != 5 && !this->spiro && !this->bspline) return; Geom::CubicBezier const * cubic; - pc->p[1] = pc->red_curve->last_segment()->initialPoint() + (1./3)* (Geom::Point)(pc->red_curve->last_segment()->finalPoint() - pc->red_curve->last_segment()->initialPoint()); + this->p[1] = this->red_curve->last_segment()->initialPoint() + (1./3)* (Geom::Point)(this->red_curve->last_segment()->finalPoint() - this->red_curve->last_segment()->initialPoint()); //spanish: modificamos el último segmento de la curva verde para que forme el tipo de nodo que deseamos - if(pc->spiro||pc->bspline){ - if(!pc->green_curve->is_empty()){ + if(this->spiro||this->bspline){ + if(!this->green_curve->is_empty()){ Geom::Point A(0,0); Geom::Point B(0,0); Geom::Point C(0,0); Geom::Point D(0,0); SPCurve * previous = new SPCurve(); - cubic = dynamic_cast<Geom::CubicBezier const *>( pc->green_curve->last_segment() ); + cubic = dynamic_cast<Geom::CubicBezier const *>( this->green_curve->last_segment() ); //We obtain the last segment 4 points in the previous curve if ( cubic ){ A = (*cubic)[0]; B = (*cubic)[1]; - if(pc->spiro){ - C = pc->p[0] + (Geom::Point)(pc->p[0] - pc->p[1]); + if(this->spiro){ + C = this->p[0] + (Geom::Point)(this->p[0] - this->p[1]); }else - C = pc->green_curve->last_segment()->finalPoint() + (1./3)* (Geom::Point)(pc->green_curve->last_segment()->initialPoint() - pc->green_curve->last_segment()->finalPoint()); + C = this->green_curve->last_segment()->finalPoint() + (1./3)* (Geom::Point)(this->green_curve->last_segment()->initialPoint() - this->green_curve->last_segment()->finalPoint()); D = (*cubic)[3]; }else{ - A = pc->green_curve->last_segment()->initialPoint(); - B = pc->green_curve->last_segment()->initialPoint(); - if(pc->spiro) - C = pc->p[0] + (Geom::Point)(pc->p[0] - pc->p[1]); + A = this->green_curve->last_segment()->initialPoint(); + B = this->green_curve->last_segment()->initialPoint(); + if(this->spiro) + C = this->p[0] + (Geom::Point)(this->p[0] - this->p[1]); else - C = pc->green_curve->last_segment()->finalPoint() + (1./3)* (Geom::Point)(pc->green_curve->last_segment()->initialPoint() - pc->green_curve->last_segment()->finalPoint()); - D = pc->green_curve->last_segment()->finalPoint(); + C = this->green_curve->last_segment()->finalPoint() + (1./3)* (Geom::Point)(this->green_curve->last_segment()->initialPoint() - this->green_curve->last_segment()->finalPoint()); + D = this->green_curve->last_segment()->finalPoint(); } previous->moveto(A); previous->curveto(B, C, D); - if( pc->green_curve->get_segment_count() == 1){ - pc->green_curve = previous; + if( this->green_curve->get_segment_count() == 1){ + this->green_curve = previous; }else{ //we eliminate the last segment - pc->green_curve->backspace(); + this->green_curve->backspace(); //and we add it again with the recreation - pc->green_curve->append_continuous(previous, 0.0625); + this->green_curve->append_continuous(previous, 0.0625); } } //spanish: si el último nodo es una union con otra curva - if(pc->green_curve->is_empty() && pc->sa && !pc->sa->curve->is_empty()){ + if(this->green_curve->is_empty() && this->sa && !this->sa->curve->is_empty()){ bspline_spiro_start_anchor(pc, false); } } - pen_redraw_all(pc); + this->_redrawAll(); } -static void pen_lastpoint_toline (PenTool *const pc) -{ + +void PenTool::_lastpointToLine() { //spanish: evitamos que si la "red_curve" tiene solo dos puntos -recta- no se pare aqui. - if (pc->npoints != 5 && !pc->bspline) + if (this->npoints != 5 && !this->bspline) return; //spanish: modificamos el último segmento de la curva verde para que forme el tipo de nodo que deseamos - if(pc->spiro || pc->bspline){ - if(!pc->green_curve->is_empty()){ + if(this->spiro || this->bspline){ + if(!this->green_curve->is_empty()){ Geom::Point A(0,0); Geom::Point B(0,0); Geom::Point C(0,0); Geom::Point D(0,0); SPCurve * previous = new SPCurve(); - Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>( pc->green_curve->last_segment() ); + Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>( this->green_curve->last_segment() ); if ( cubic ) { - A = pc->green_curve->last_segment()->initialPoint(); + A = this->green_curve->last_segment()->initialPoint(); B = (*cubic)[1]; - C = pc->green_curve->last_segment()->finalPoint(); + C = this->green_curve->last_segment()->finalPoint(); D = C; } else { //We obtain the last segment 4 points in the previous curve - A = pc->green_curve->last_segment()->initialPoint(); + A = this->green_curve->last_segment()->initialPoint(); B = A; - C = pc->green_curve->last_segment()->finalPoint(); + C = this->green_curve->last_segment()->finalPoint(); D = C; } previous->moveto(A); previous->curveto(B, C, D); - if( pc->green_curve->get_segment_count() == 1){ - pc->green_curve = previous; + if( this->green_curve->get_segment_count() == 1){ + this->green_curve = previous; }else{ //we eliminate the last segment - pc->green_curve->backspace(); + this->green_curve->backspace(); //and we add it again with the recreation - pc->green_curve->append_continuous(previous, 0.0625); + this->green_curve->append_continuous(previous, 0.0625); } } //spanish: si el último nodo es una union con otra curva - if(pc->green_curve->is_empty() && pc->sa && !pc->sa->curve->is_empty()){ + if(this->green_curve->is_empty() && this->sa && !this->sa->curve->is_empty()){ bspline_spiro_start_anchor(pc, true); } } - pc->p[1] = pc->p[0]; - pen_redraw_all(pc); + this->p[1] = this->p[0]; + this->_redrawAll(); } -static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event) -{ +gint PenTool::_handleKeyPress(GdkEvent *event) { gint ret = FALSE; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -1133,12 +1128,12 @@ static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event) 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 + if (MOD__SHIFT(event)) this->_lastpointMoveScreen(-10, 0); // shift + else this->_lastpointMoveScreen(-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 + if (MOD__SHIFT(event)) this->_lastpointMove(-10*nudge, 0); // shift + else this->_lastpointMove(-nudge, 0); // no shift } ret = TRUE; } @@ -1147,12 +1142,12 @@ static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event) 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 + if (MOD__SHIFT(event)) this->_lastpointMoveScreen(0, 10); // shift + else this->_lastpointMoveScreen(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 + if (MOD__SHIFT(event)) this->_lastpointMove(0, 10*nudge); // shift + else this->_lastpointMove(0, nudge); // no shift } ret = TRUE; } @@ -1161,12 +1156,12 @@ static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event) 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 + if (MOD__SHIFT(event)) this->_lastpointMoveScreen(10, 0); // shift + else this->_lastpointMoveScreen(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 + if (MOD__SHIFT(event)) this->_lastpointMove(10*nudge, 0); // shift + else this->_lastpointMove(nudge, 0); // no shift } ret = TRUE; } @@ -1175,12 +1170,12 @@ static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event) 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 + if (MOD__SHIFT(event)) this->_lastpointMoveScreen(0, -10); // shift + else this->_lastpointMoveScreen(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 + if (MOD__SHIFT(event)) this->_lastpointMove(0, -10*nudge); // shift + else this->_lastpointMove(0, -nudge); // no shift } ret = TRUE; } @@ -1223,53 +1218,53 @@ static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event) case GDK_KEY_U: case GDK_KEY_u: if (MOD__SHIFT_ONLY(event)) { - pen_lastpoint_tocurve(pc); + this->_lastpointToCurve(); ret = TRUE; } break; case GDK_KEY_L: case GDK_KEY_l: if (MOD__SHIFT_ONLY(event)) { - pen_lastpoint_toline(pc); + this->_lastpointToLine(); ret = TRUE; } break; case GDK_KEY_Return: case GDK_KEY_KP_Enter: - if (pc->npoints != 0) { - spdc_pen_finish(pc, FALSE); + if (this->npoints != 0) { + this->_finish(FALSE); ret = TRUE; } break; case GDK_KEY_Escape: - if (pc->npoints != 0) { + if (this->npoints != 0) { // if drawing, cancel, otherwise pass it up for deselecting - pen_cancel (pc); + this->_cancel (); ret = TRUE; } break; case GDK_KEY_z: case GDK_KEY_Z: - if (MOD__CTRL_ONLY(event) && pc->npoints != 0) { + if (MOD__CTRL_ONLY(event) && this->npoints != 0) { // if drawing, cancel, otherwise pass it up for undo - pen_cancel (pc); + this->_cancel (); 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); + sp_selection_to_guides(SP_EVENT_CONTEXT(this)->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); + if ( this->green_curve->is_empty() || (this->green_curve->last_segment() == NULL) ) { + if (!this->red_curve->is_empty()) { + this->_cancel (); ret = TRUE; } else { // do nothing; this event should be handled upstream @@ -1277,63 +1272,64 @@ static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event) } else { // Reset red curve Geom::CubicBezier const * cubic = NULL; - pc->red_curve->reset(); + this->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); + if (this->green_bpaths) { + if (this->green_bpaths->data) + sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data)); + this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data); } // Get last segment - if ( pc->green_curve->is_empty() ) { + if ( this->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(); - cubic = dynamic_cast<Geom::CubicBezier const *>(crv); - if ( cubic ) { - pc->p[1] = (*cubic)[1]; + // The code below assumes that this->green_curve has only ONE path ! + Geom::Curve const * crv = this->green_curve->last_segment(); + this->p[0] = crv->initialPoint(); + if ( Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const *>(crv)) { + this->p[1] = (*cubic)[1]; + } else { - pc->p[1] = pc->p[0]; + this->p[1] = this->p[0]; } + //spanish: asignamos el valor a un tercio de distancia del último segmento. - if(pc->bspline){ - pc->p[1] = pc->p[0] + (1./3)*(pc->p[3] - pc->p[0]); + if(this->bspline){ + this->p[1] = this->p[0] + (1./3)*(this->p[3] - this->p[0]); } - Geom::Point const pt((pc->npoints < 4 + Geom::Point const pt((this->npoints < 4 ? (Geom::Point)(crv->finalPoint()) - : pc->p[3])); + : this->p[3])); - pc->npoints = 2; + this->npoints = 2; //spanish: eliminamos el último segmento de la curva verde - if( pc->green_curve->get_segment_count() == 1){ - pc->npoints = 5; - 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); + if( this->green_curve->get_segment_count() == 1){ + this->npoints = 5; + if (this->green_bpaths) { + if (this->green_bpaths->data) + sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data)); + this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data); } - pc->green_curve->reset(); + this->green_curve->reset(); }else{ - pc->green_curve->backspace(); + this->green_curve->backspace(); } - //spanish: asignamos el valor de pc->p[1] a el opuesto de el ultimo segmento de la línea verde - if(pc->spiro){ - cubic = dynamic_cast<Geom::CubicBezier const *>(pc->green_curve->last_segment()); + //spanish: asignamos el valor de this->p[1] a el opuesto de el ultimo segmento de la línea verde + if(this->spiro){ + cubic = dynamic_cast<Geom::CubicBezier const *>(this->green_curve->last_segment()); if ( cubic ) { - pc->p[1] = (*cubic)[3] + (Geom::Point)((*cubic)[3] - (*cubic)[2]); - SP_CTRL(pc->c1)->moveto(pc->p[0]); + this->p[1] = (*cubic)[3] + (Geom::Point)((*cubic)[3] - (*cubic)[2]); + SP_CTRL(this->c1)->moveto(this->p[0]); } else { - pc->p[1] = pc->p[0]; + this->p[1] = this->p[0]; } } - sp_canvas_item_hide(pc->cl0); - sp_canvas_item_hide(pc->cl1); - pc->state = PenTool::POINT; - spdc_pen_set_subsequent_point(pc, pt, true); + sp_canvas_item_hide(this->cl0); + sp_canvas_item_hide(this->cl1); + this->state = PenTool::POINT; + this->_setSubsequentPoint(pt, true); pen_last_paraxial_dir = !pen_last_paraxial_dir; //spanish: redibujamos bspline_spiro_build(pc); @@ -1346,40 +1342,38 @@ static gint pen_handle_key_press(PenTool *const pc, GdkEvent *event) return ret; } -static void spdc_reset_colors(PenTool *pc) -{ +void PenTool::_resetColors() { // Red - pc->red_curve->reset(); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), NULL); + this->red_curve->reset(); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL); // Blue - pc->blue_curve->reset(); - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->blue_bpath), NULL); + this->blue_curve->reset(); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->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; + while (this->green_bpaths) { + sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data)); + this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data); + } + this->green_curve->reset(); + if (this->green_anchor) { + this->green_anchor = sp_draw_anchor_destroy(this->green_anchor); + } + this->sa = NULL; + this->ea = NULL; + this->npoints = 0; + this->red_curve_is_valid = false; } -static void spdc_pen_set_initial_point(PenTool *const pc, Geom::Point const p) -{ - g_assert( pc->npoints == 0 ); +void PenTool::_setInitialPoint(Geom::Point const p) { + g_assert( this->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); + this->p[0] = p; + this->p[1] = p; + this->npoints = 2; + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL); - pc->desktop->canvas->forceFullRedrawAfterInterruptions(5); + this->desktop->canvas->forceFullRedrawAfterInterruptions(5); } /** @@ -1387,14 +1381,13 @@ static void spdc_pen_set_initial_point(PenTool *const pc, Geom::Point const p) * 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); +void PenTool::_setAngleDistanceStatusMessage(Geom::Point const p, int pc_point_to_compare, gchar const *message) { + g_assert(this != 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]; + 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()); double angle = atan2(rel[Geom::Y], rel[Geom::X]) * 180 / M_PI; @@ -1406,60 +1399,61 @@ static void spdc_pen_set_angle_distance_status_message(PenTool *const pc, Geom:: } } - pc->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, message, angle, dist->str); + this->message_context->setF(Inkscape::IMMEDIATE_MESSAGE, message, angle, dist->str); g_string_free(dist, FALSE); } + //spanish: esta función cambia los colores rojo,verde y azul haciendolos transparentes o no en función de si se usa spiro static void bspline_spiro_color(PenTool *const pc) { bool remake_green_bpaths = false; - if(pc->spiro){ + if(this->spiro){ //If the colour is not defined as trasparent, por example when changing //from drawing to spiro mode or when selecting the pen tool - if(pc->green_color != 0x00ff000){ + if(this->green_color != 0x00ff000){ //We change the green and red colours to transparent, so this lines are not necessary //to the drawing with spiro - pc->red_color = 0xff00000; - pc->green_color = 0x00ff000; + this->red_color = 0xff00000; + this->green_color = 0x00ff000; remake_green_bpaths = true; } }else{ //If we come from working with the spiro curve and change the mode the "green_curve" colour is transparent - if(pc->green_color != 0x00ff007f){ + if(this->green_color != 0x00ff007f){ //since we are not im spiro mode, we assign the original colours //to the red and the green curve, removing their transparency - pc->red_color = 0xff00007f; - pc->green_color = 0x00ff007f; + this->red_color = 0xff00007f; + this->green_color = 0x00ff007f; remake_green_bpaths = true; } //we hide the spiro/bspline rests - if(!pc->bspline){ - sp_canvas_item_hide(pc->blue_bpath); + if(!this->bspline){ + sp_canvas_item_hide(this->blue_bpath); } } //We erase all the "green_bpaths" to recreate them after with the colour //transparency recently modified - if (pc->green_bpaths && remake_green_bpaths) { + if (this->green_bpaths && remake_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); + while (this->green_bpaths) { + sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data)); + this->green_bpaths = g_slist_remove(this->green_bpaths, this->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); + SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(this->desktop), this->green_curve); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), this->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); + this->green_bpaths = g_slist_prepend(this->green_bpaths, cshape); } - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(pc->red_bpath), pc->red_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->red_bpath), this->red_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); } static void bspline_spiro(PenTool *const pc, bool shift) { - if(!pc->spiro && !pc->bspline) + if(!this->spiro && !this->bspline) return; shift?bspline_spiro_off(pc):bspline_spiro_on(pc); @@ -1468,24 +1462,24 @@ static void bspline_spiro(PenTool *const pc, bool shift) static void bspline_spiro_on(PenTool *const pc) { - if(!pc->red_curve->is_empty()){ + if(!this->red_curve->is_empty()){ using Geom::X; using Geom::Y; - pc->npoints = 5; - pc->p[0] = pc->red_curve->first_segment()->initialPoint(); - pc->p[3] = pc->red_curve->first_segment()->finalPoint(); - pc->p[2] = pc->p[3] + (1./3)*(pc->p[0] - pc->p[3]); - pc->p[2] = Geom::Point(pc->p[2][X] + 0.005,pc->p[2][Y] + 0.005); + this->npoints = 5; + this->p[0] = this->red_curve->first_segment()->initialPoint(); + this->p[3] = this->red_curve->first_segment()->finalPoint(); + this->p[2] = this->p[3] + (1./3)*(this->p[0] - this->p[3]); + this->p[2] = Geom::Point(this->p[2][X] + 0.005,this->p[2][Y] + 0.005); } } static void bspline_spiro_off(PenTool *const pc) { - if(!pc->red_curve->is_empty()){ - pc->npoints = 5; - pc->p[0] = pc->red_curve->first_segment()->initialPoint(); - pc->p[3] = pc->red_curve->first_segment()->finalPoint(); - pc->p[2] = pc->p[3]; + if(!this->red_curve->is_empty()){ + this->npoints = 5; + this->p[0] = this->red_curve->first_segment()->initialPoint(); + this->p[3] = this->red_curve->first_segment()->finalPoint(); + this->p[2] = this->p[3]; } } @@ -1493,34 +1487,34 @@ static void bspline_spiro_start_anchor(PenTool *const pc, bool shift) { LivePathEffect::LPEBSpline *lpe_bsp = NULL; - if (SP_IS_LPE_ITEM(pc->white_item) && SP_LPE_ITEM(pc->white_item)->hasPathEffect()){ - Inkscape::LivePathEffect::Effect* thisEffect = SP_LPE_ITEM(pc->white_item)->getPathEffectOfType(Inkscape::LivePathEffect::BSPLINE); + if (SP_IS_LPE_ITEM(this->white_item) && SP_LPE_ITEM(this->white_item)->hasPathEffect()){ + Inkscape::LivePathEffect::Effect* thisEffect = SP_LPE_ITEM(this->white_item)->getPathEffectOfType(Inkscape::LivePathEffect::BSPLINE); if(thisEffect){ lpe_bsp = dynamic_cast<LivePathEffect::LPEBSpline*>(thisEffect->getLPEObj()->get_lpe()); } } if(lpe_bsp){ - pc->bspline = true; + this->bspline = true; }else{ - pc->bspline = false; + this->bspline = false; } LivePathEffect::LPESpiro *lpe_spi = NULL; - if (SP_IS_LPE_ITEM(pc->white_item) && SP_LPE_ITEM(pc->white_item)->hasPathEffect()){ - Inkscape::LivePathEffect::Effect* thisEffect = SP_LPE_ITEM(pc->white_item)->getPathEffectOfType(Inkscape::LivePathEffect::SPIRO); + if (SP_IS_LPE_ITEM(this->white_item) && SP_LPE_ITEM(this->white_item)->hasPathEffect()){ + Inkscape::LivePathEffect::Effect* thisEffect = SP_LPE_ITEM(this->white_item)->getPathEffectOfType(Inkscape::LivePathEffect::SPIRO); if(thisEffect){ lpe_spi = dynamic_cast<LivePathEffect::LPESpiro*>(thisEffect->getLPEObj()->get_lpe()); } } if(lpe_spi){ - pc->spiro = true; + this->spiro = true; }else{ - pc->spiro = false; + this->spiro = false; } - if(!pc->spiro && !pc->bspline) + if(!this->spiro && !this->bspline) return; - if(pc->sa->curve->is_empty()) + if(this->sa->curve->is_empty()) return; if(shift) @@ -1534,8 +1528,8 @@ static void bspline_spiro_start_anchor_on(PenTool *const pc) using Geom::X; using Geom::Y; SPCurve *tmpCurve = new SPCurve(); - tmpCurve = pc->sa->curve->copy(); - if(pc->sa->start) + tmpCurve = this->sa->curve->copy(); + if(this->sa->start) tmpCurve = tmpCurve->create_reverse(); Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment()); SPCurve *lastSeg = new SPCurve(); @@ -1558,18 +1552,18 @@ static void bspline_spiro_start_anchor_on(PenTool *const pc) //and we add it again with the recreation tmpCurve->append_continuous(lastSeg, 0.0625); } - if (pc->sa->start) { + if (this->sa->start) { tmpCurve = tmpCurve->create_reverse(); } - pc->sa->curve->reset(); - pc->sa->curve = tmpCurve; + this->sa->curve->reset(); + this->sa->curve = tmpCurve; } static void bspline_spiro_start_anchor_off(PenTool *const pc) { SPCurve *tmpCurve = new SPCurve(); - tmpCurve = pc->sa->curve->copy(); - if(pc->sa->start) + tmpCurve = this->sa->curve->copy(); + if(this->sa->start) tmpCurve = tmpCurve->create_reverse(); Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment()); if(cubic){ @@ -1584,68 +1578,68 @@ static void bspline_spiro_start_anchor_off(PenTool *const pc) //and we add it again with the recreation tmpCurve->append_continuous(lastSeg, 0.0625); } - if (pc->sa->start) { + if (this->sa->start) { tmpCurve = tmpCurve->create_reverse(); } - pc->sa->curve->reset(); - pc->sa->curve = tmpCurve; + this->sa->curve->reset(); + this->sa->curve = tmpCurve; } } static void bspline_spiro_motion(PenTool *const pc, bool shift){ - if(!pc->spiro && !pc->bspline) + if(!this->spiro && !this->bspline) return; using Geom::X; using Geom::Y; - if(pc->red_curve->is_empty()) return; - pc->npoints = 5; + if(this->red_curve->is_empty()) return; + this->npoints = 5; SPCurve *tmpCurve = new SPCurve(); - pc->p[2] = pc->p[3] + (1./3)*(pc->p[0] - pc->p[3]); - pc->p[2] = Geom::Point(pc->p[2][X] + 0.005,pc->p[2][Y] + 0.005); - if(pc->green_curve->is_empty() && !pc->sa){ - pc->p[1] = pc->p[0] + (1./3)*(pc->p[3] - pc->p[0]); - pc->p[1] = Geom::Point(pc->p[1][X] + 0.005,pc->p[1][Y] + 0.005); - }else if(!pc->green_curve->is_empty()){ - tmpCurve = pc->green_curve->copy(); + this->p[2] = this->p[3] + (1./3)*(this->p[0] - this->p[3]); + this->p[2] = Geom::Point(this->p[2][X] + 0.005,this->p[2][Y] + 0.005); + if(this->green_curve->is_empty() && !this->sa){ + this->p[1] = this->p[0] + (1./3)*(this->p[3] - this->p[0]); + this->p[1] = Geom::Point(this->p[1][X] + 0.005,this->p[1][Y] + 0.005); + }else if(!this->green_curve->is_empty()){ + tmpCurve = this->green_curve->copy(); }else{ - tmpCurve = pc->sa->curve->copy(); - if(pc->sa->start) + tmpCurve = this->sa->curve->copy(); + if(this->sa->start) tmpCurve = tmpCurve->create_reverse(); } if(!tmpCurve->is_empty()){ Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment()); if(cubic){ - if(pc->bspline){ + if(this->bspline){ SPCurve * WPower = new SPCurve(); Geom::D2< Geom::SBasis > SBasisWPower; WPower->moveto(tmpCurve->last_segment()->finalPoint()); WPower->lineto(tmpCurve->last_segment()->initialPoint()); float WP = Geom::nearest_point((*cubic)[2],*WPower->first_segment()); WPower->reset(); - WPower->moveto(pc->red_curve->last_segment()->initialPoint()); - WPower->lineto(pc->red_curve->last_segment()->finalPoint()); + WPower->moveto(this->red_curve->last_segment()->initialPoint()); + WPower->lineto(this->red_curve->last_segment()->finalPoint()); SBasisWPower = WPower->first_segment()->toSBasis(); WPower->reset(); - pc->p[1] = SBasisWPower.valueAt(WP); - if(!Geom::are_near(pc->p[1],pc->p[0])) - pc->p[1] = Geom::Point(pc->p[1][X] + 0.005,pc->p[1][Y] + 0.005); + this->p[1] = SBasisWPower.valueAt(WP); + if(!Geom::are_near(this->p[1],this->p[0])) + this->p[1] = Geom::Point(this->p[1][X] + 0.005,this->p[1][Y] + 0.005); if(shift) - pc->p[2] = pc->p[3]; + this->p[2] = this->p[3]; }else{ - pc->p[1] = (*cubic)[3] + (Geom::Point)((*cubic)[3] - (*cubic)[2] ); - pc->p[1] = Geom::Point(pc->p[1][X] + 0.005,pc->p[1][Y] + 0.005); + this->p[1] = (*cubic)[3] + (Geom::Point)((*cubic)[3] - (*cubic)[2] ); + this->p[1] = Geom::Point(this->p[1][X] + 0.005,this->p[1][Y] + 0.005); } }else{ - pc->p[1] = pc->p[0]; + this->p[1] = this->p[0]; if(shift) - pc->p[2] = pc->p[3]; + this->p[2] = this->p[3]; } } - if(pc->anchor_statusbar && !pc->red_curve->is_empty()){ + if(this->anchor_statusbar && !this->red_curve->is_empty()){ if(shift){ bspline_spiro_end_anchor_off(pc); }else{ @@ -1661,20 +1655,20 @@ static void bspline_spiro_end_anchor_on(PenTool *const pc) using Geom::X; using Geom::Y; - pc->p[2] = pc->p[3] + (1./3)*(pc->p[0] - pc->p[3]); - pc->p[2] = Geom::Point(pc->p[2][X] + 0.005,pc->p[2][Y] + 0.005); + this->p[2] = this->p[3] + (1./3)*(this->p[0] - this->p[3]); + this->p[2] = Geom::Point(this->p[2][X] + 0.005,this->p[2][Y] + 0.005); SPCurve *tmpCurve = new SPCurve(); SPCurve *lastSeg = new SPCurve(); Geom::Point C(0,0); - if(!pc->sa || pc->sa->curve->is_empty()){ - tmpCurve = pc->green_curve->create_reverse(); - if(pc->green_curve->get_segment_count()==0)return; + if(!this->sa || this->sa->curve->is_empty()){ + tmpCurve = this->green_curve->create_reverse(); + if(this->green_curve->get_segment_count()==0)return; Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment()); - if(pc->bspline){ + if(this->bspline){ C = tmpCurve->last_segment()->finalPoint() + (1./3)*(tmpCurve->last_segment()->initialPoint() - tmpCurve->last_segment()->finalPoint()); C = Geom::Point(C[X] + 0.005,C[Y] + 0.005); }else{ - C = pc->p[3] + (Geom::Point)(pc->p[3] - pc->p[2] ); + C = this->p[3] + (Geom::Point)(this->p[3] - this->p[2] ); } if(cubic){ lastSeg->moveto((*cubic)[0]); @@ -1692,17 +1686,17 @@ static void bspline_spiro_end_anchor_on(PenTool *const pc) tmpCurve->append_continuous(lastSeg, 0.0625); } tmpCurve = tmpCurve->create_reverse(); - pc->green_curve->reset(); - pc->green_curve = tmpCurve; + this->green_curve->reset(); + this->green_curve = tmpCurve; }else { - tmpCurve = pc->sa->curve->copy(); - if(!pc->sa->start) tmpCurve = tmpCurve->create_reverse(); + tmpCurve = this->sa->curve->copy(); + if(!this->sa->start) tmpCurve = tmpCurve->create_reverse(); Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment()); - if(pc->bspline){ + if(this->bspline){ C = tmpCurve->last_segment()->finalPoint() + (1./3)*(tmpCurve->last_segment()->initialPoint() - tmpCurve->last_segment()->finalPoint()); C = Geom::Point(C[X] + 0.005,C[Y] + 0.005); }else{ - C = pc->p[3] + (Geom::Point)(pc->p[3] - pc->p[2] ); + C = this->p[3] + (Geom::Point)(this->p[3] - this->p[2] ); } if(cubic){ lastSeg->moveto((*cubic)[0]); @@ -1719,11 +1713,11 @@ static void bspline_spiro_end_anchor_on(PenTool *const pc) //and we add it again with the recreation tmpCurve->append_continuous(lastSeg, 0.0625); } - if (!pc->sa->start) { + if (!this->sa->start) { tmpCurve = tmpCurve->create_reverse(); } - pc->sa->curve->reset(); - pc->sa->curve = tmpCurve; + this->sa->curve->reset(); + this->sa->curve = tmpCurve; } } @@ -1732,11 +1726,11 @@ static void bspline_spiro_end_anchor_off(PenTool *const pc) SPCurve *tmpCurve = new SPCurve(); SPCurve *lastSeg = new SPCurve(); - pc->p[2] = pc->p[3]; - if(!pc->sa || pc->sa->curve->is_empty()){ + this->p[2] = this->p[3]; + if(!this->sa || this->sa->curve->is_empty()){ - tmpCurve = pc->green_curve->create_reverse(); - if(pc->green_curve->get_segment_count()==0)return; + tmpCurve = this->green_curve->create_reverse(); + if(this->green_curve->get_segment_count()==0)return; Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment()); if(cubic){ lastSeg->moveto((*cubic)[0]); @@ -1750,12 +1744,12 @@ static void bspline_spiro_end_anchor_off(PenTool *const pc) tmpCurve->append_continuous(lastSeg, 0.0625); } tmpCurve = tmpCurve->create_reverse(); - pc->green_curve->reset(); - pc->green_curve = tmpCurve; + this->green_curve->reset(); + this->green_curve = tmpCurve; } }else { - tmpCurve = pc->sa->curve->copy(); - if(!pc->sa->start) tmpCurve = tmpCurve->create_reverse(); + tmpCurve = this->sa->curve->copy(); + if(!this->sa->start) tmpCurve = tmpCurve->create_reverse(); Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmpCurve->last_segment()); if(cubic){ lastSeg->moveto((*cubic)[0]); @@ -1768,11 +1762,11 @@ static void bspline_spiro_end_anchor_off(PenTool *const pc) //and we add it again with the recreation tmpCurve->append_continuous(lastSeg, 0.0625); } - if (!pc->sa->start) { + if (!this->sa->start) { tmpCurve = tmpCurve->create_reverse(); } - pc->sa->curve->reset(); - pc->sa->curve = tmpCurve; + this->sa->curve->reset(); + this->sa->curve = tmpCurve; } } } @@ -1781,29 +1775,29 @@ static void bspline_spiro_end_anchor_off(PenTool *const pc) //spanish: preparates the curves for its trasformation into BSline curves. static void bspline_spiro_build(PenTool *const pc) { - if(!pc->spiro && !pc->bspline) + if(!this->spiro && !this->bspline) return; //We create the base curve SPCurve *curve = new SPCurve(); //If we continuate the existing curve we add it at the start - if(pc->sa && !pc->sa->curve->is_empty()){ - curve = pc->sa->curve->copy(); - if (pc->sa->start) { + if(this->sa && !this->sa->curve->is_empty()){ + curve = this->sa->curve->copy(); + if (this->sa->start) { curve = curve->create_reverse(); } } - if (!pc->green_curve->is_empty()) - curve->append_continuous(pc->green_curve, 0.0625); + if (!this->green_curve->is_empty()) + curve->append_continuous(this->green_curve, 0.0625); //and the red one - if (!pc->red_curve->is_empty()){ - 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); - curve->append_continuous(pc->red_curve, 0.0625); + if (!this->red_curve->is_empty()){ + this->red_curve->reset(); + this->red_curve->moveto(this->p[0]); + this->red_curve->curveto(this->p[1],this->p[2],this->p[3]); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve); + curve->append_continuous(this->red_curve, 0.0625); } if(!curve->is_empty()){ @@ -1817,29 +1811,29 @@ static void bspline_spiro_build(PenTool *const pc) //LivePathEffectObject *lpeobj = static_cast<LivePathEffectObject*> (curve); //Effect *spr = static_cast<Effect*> ( new LPEbspline(lpeobj) ); //spr->doEffect(curve); - if(pc->bspline){ + if(this->bspline){ bspline_doEffect(curve); }else{ spiro_doEffect(curve); } - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->blue_bpath), curve); - sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(pc->blue_bpath), pc->blue_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - sp_canvas_item_show(pc->blue_bpath); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->blue_bpath), curve); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->blue_bpath), this->blue_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); + sp_canvas_item_show(this->blue_bpath); curve->unref(); - pc->blue_curve->reset(); + this->blue_curve->reset(); //We hide the holders that doesn't contribute anything - if(pc->spiro){ - sp_canvas_item_show(pc->c1); - SP_CTRL(pc->c1)->moveto(pc->p[0]); + if(this->spiro){ + sp_canvas_item_show(this->c1); + SP_CTRL(this->c1)->moveto(this->p[0]); }else - sp_canvas_item_hide(pc->c1); - sp_canvas_item_hide(pc->cl1); - sp_canvas_item_hide(pc->c0); - sp_canvas_item_hide(pc->cl0); + sp_canvas_item_hide(this->c1); + sp_canvas_item_hide(this->cl1); + sp_canvas_item_hide(this->c0); + sp_canvas_item_hide(this->cl0); }else{ //if the curve is empty - sp_canvas_item_hide(pc->blue_bpath); + sp_canvas_item_hide(this->blue_bpath); } } @@ -2082,192 +2076,189 @@ static void spiro_doEffect(SPCurve * curve) g_free (path); } -static void spdc_pen_set_subsequent_point(PenTool *const pc, Geom::Point const p, bool statusbar, guint status) -{ - g_assert( pc->npoints != 0 ); +void PenTool::_setSubsequentPoint(Geom::Point const p, bool statusbar, guint status) { + g_assert( this->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(); + this->p[2] = p; + this->p[3] = p; + this->p[4] = p; + this->npoints = 5; + this->red_curve->reset(); bool is_curve; - pc->red_curve->moveto(pc->p[0]); - if (pc->polylines_paraxial && !statusbar) { + this->red_curve->moveto(this->p[0]); + if (this->polylines_paraxial && !statusbar) { // we are drawing horizontal/vertical lines and hit an anchor; - Geom::Point const origin = pc->p[0]; + Geom::Point const origin = this->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); + this->_setToNearestHorizVert(intermed, status, false); + this->red_curve->lineto(intermed); } - pc->red_curve->lineto(p); + this->red_curve->lineto(p); is_curve = false; } else { // one of the 'regular' modes - if (pc->p[1] != pc->p[0] || pc->spiro) { - pc->red_curve->curveto(pc->p[1], p, p); + if (this->p[1] != this->p[0] || this->spiro) { + this->red_curve->curveto(this->p[1], p, p); is_curve = true; } else { - pc->red_curve->lineto(p); + this->red_curve->lineto(p); is_curve = false; } } - sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(pc->red_bpath), pc->red_curve); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve); if (statusbar) { gchar *message = is_curve ? _("<b>Curve segment</b>: angle %3.2f°, distance %s; with <b>Ctrl</b> to snap angle, <b>Enter</b> to finish the path" ): _("<b>Line segment</b>: angle %3.2f°, distance %s; with <b>Ctrl</b> to snap angle, <b>Enter</b> to finish the path"); - if(pc->spiro || pc->bspline){ + if(this->spiro || this->bspline){ message = is_curve ? _("<b>Curve segment</b>: angle %3.2f°, distance %s; with <b>Shift</b> to cusp node, <b>Enter</b> to finish the path" ): _("<b>Line segment</b>: angle %3.2f°, distance %s; with <b>Shift</b> to cusp node, <b>Enter</b> to finish the path"); } - spdc_pen_set_angle_distance_status_message(pc, p, 0, message); + this->_setAngleDistanceStatusMessage(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, _("<b>Curve handle</b>: angle %3.2f°, length %s; with <b>Ctrl</b> to snap angle")); - } else if ( pc->npoints == 5 ) { - pc->p[4] = p; - sp_canvas_item_show(pc->c0); - sp_canvas_item_show(pc->cl0); + +void PenTool::_setCtrl(Geom::Point const p, guint const state) { + sp_canvas_item_show(this->c1); + sp_canvas_item_show(this->cl1); + + if ( this->npoints == 2 ) { + this->p[1] = p; + sp_canvas_item_hide(this->c0); + sp_canvas_item_hide(this->cl0); + SP_CTRL(this->c1)->moveto(this->p[1]); + this->cl1->setCoords(this->p[0], this->p[1]); + this->_setAngleDistanceStatusMessage(p, 0, _("<b>Curve handle</b>: angle %3.2f°, length %s; with <b>Ctrl</b> to snap angle")); + } else if ( this->npoints == 5 ) { + this->p[4] = p; + sp_canvas_item_show(this->c0); + sp_canvas_item_show(this->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; + if ( ( ( this->mode == PenTool::MODE_CLICK ) && ( state & GDK_CONTROL_MASK ) ) || + ( ( this->mode == PenTool::MODE_DRAG ) && !( state & GDK_SHIFT_MASK ) ) ) { + Geom::Point delta = p - this->p[3]; + this->p[2] = this->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); + this->red_curve->reset(); + this->red_curve->moveto(this->p[0]); + this->red_curve->curveto(this->p[1], this->p[2], this->p[3]); + sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->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]); + SP_CTRL(this->c0)->moveto(this->p[2]); + this->cl0 ->setCoords(this->p[3], this->p[2]); + SP_CTRL(this->c1)->moveto(this->p[4]); + this->cl1->setCoords(this->p[3], this->p[4]); + + + gchar *message = is_symm ? _("<b>Curve handle, symmetric</b>: angle %3.2f°, length %s; with <b>Ctrl</b> to snap angle, with <b>Shift</b> to move this handle only") : _("<b>Curve handle</b>: angle %3.2f°, length %s; with <b>Ctrl</b> to snap angle, with <b>Shift</b> to move this handle only"); - spdc_pen_set_angle_distance_status_message(pc, p, 3, message); + this->_setAngleDistanceStatusMessage(p, 3, message); } else { - g_warning("Something bad happened - npoints is %d", pc->npoints); + g_warning("Something bad happened - npoints is %d", this->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); +void PenTool::_finishSegment(Geom::Point const p, guint const state) { + if (this->polylines_paraxial) { + pen_last_paraxial_dir = this->nextParaxialDirection(p, this->p[0], state); } - ++pc->num_clicks; + ++this->num_clicks; + - if (!pc->red_curve->is_empty()) { + if (!this->red_curve->is_empty()) { bspline_spiro(pc,(state & GDK_SHIFT_MASK)); - pc->green_curve->append_continuous(pc->red_curve, 0.0625); - SPCurve *curve = pc->red_curve->copy(); + this->green_curve->append_continuous(this->red_curve, 0.0625); + SPCurve *curve = this->red_curve->copy(); + /// \todo fixme: - SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(pc->desktop), curve); + SPCanvasItem *cshape = sp_canvas_bpath_new(sp_desktop_sketch(this->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); + sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(cshape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT); - pc->green_bpaths = g_slist_prepend(pc->green_bpaths, cshape); + this->green_bpaths = g_slist_prepend(this->green_bpaths, cshape); - pc->p[0] = pc->p[3]; - pc->p[1] = pc->p[4]; - pc->npoints = 2; + this->p[0] = this->p[3]; + this->p[1] = this->p[4]; + this->npoints = 2; - pc->red_curve->reset(); + this->red_curve->reset(); } } -static void spdc_pen_finish(PenTool *const pc, gboolean const closed) -{ - if (pc->expecting_clicks_for_LPE > 1) { +void PenTool::_finish(gboolean const closed) { + if (this->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(); + this->num_clicks = 0; + + this->_disableEvents(); + + SPDesktop *const desktop = this->desktop; + this->message_context->clear(); + desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Drawing finished")); - if(pc->spiro || pc->bspline) pc->blue_curve->reset(); + + if(this->spiro || this->bspline) this->blue_curve->reset(); //spanish para cancelar linea sin un segmento creado - pc->red_curve->reset(); - spdc_concat_colors_and_flush(pc, closed); - pc->sa = NULL; - pc->ea = NULL; + this->red_curve->reset(); + spdc_concat_colors_and_flush(this, closed); + this->sa = NULL; + this->ea = NULL; - pc->npoints = 0; - pc->state = PenTool::POINT; + this->npoints = 0; + this->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); + sp_canvas_item_hide(this->c0); + sp_canvas_item_hide(this->c1); + sp_canvas_item_hide(this->cl0); + sp_canvas_item_hide(this->cl1); - if (pc->green_anchor) { - pc->green_anchor = sp_draw_anchor_destroy(pc->green_anchor); + if (this->green_anchor) { + this->green_anchor = sp_draw_anchor_destroy(this->green_anchor); } - pc->desktop->canvas->endForcedFullRedraws(); + this->desktop->canvas->endForcedFullRedraws(); - pen_enable_events(pc); + this->_enableEvents(); } -static void pen_disable_events(PenTool *const pc) { - pc->events_disabled = true; +void PenTool::_disableEvents() { + this->events_disabled = true; } -static void pen_enable_events(PenTool *const pc) { - g_return_if_fail(pc->events_disabled != 0); +void PenTool::_enableEvents() { + g_return_if_fail(this->events_disabled != 0); - pc->events_disabled = false; + this->events_disabled = false; } -void sp_pen_context_wait_for_LPE_mouse_clicks(PenTool *pc, Inkscape::LivePathEffect::EffectType effect_type, - unsigned int num_clicks, bool use_polylines) -{ +void PenTool::waitForLPEMouseClicks(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 + this->waiting_LPE_type = effect_type; + this->expecting_clicks_for_LPE = num_clicks; + this->polylines_only = use_polylines; + this->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) { +int PenTool::nextParaxialDirection(Geom::Point const &pt, Geom::Point const &origin, guint state) const { // // 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 @@ -2275,9 +2266,9 @@ static int pen_next_paraxial_direction(const PenTool *const pc, // // 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 (this->num_clicks == 0) { - if (pc->green_curve->is_empty()) { + if (this->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]); @@ -2290,11 +2281,10 @@ static int pen_next_paraxial_direction(const PenTool *const pc, } } -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]; +void PenTool::_setToNearestHorizVert(Geom::Point &pt, guint const state, bool snap) const { + Geom::Point const origin = this->p[0]; - int next_dir = pen_next_paraxial_direction(pc, pt, origin, state); + int next_dir = this->nextParaxialDirection(pt, origin, state); if (!snap) { if (next_dir == 0) { @@ -2309,13 +2299,13 @@ void pen_set_to_nearest_horiz_vert(const PenTool *const pc, Geom::Point &pt, gui 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; + SnapManager &m = this->desktop->namedview->snap_manager; - Inkscape::Selection *selection = sp_desktop_selection (pc->desktop); + Inkscape::Selection *selection = sp_desktop_selection (this->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.setup(this->desktop, true, selection->singleItem()); m.constrainedSnapReturnByRef(pt, Inkscape::SNAPSOURCE_NODE_HANDLE, cl); m.unSetup(); } |
