summaryrefslogtreecommitdiffstats
path: root/src/ui/tools/pen-tool.cpp
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2017-12-01 21:31:36 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2017-12-01 21:31:36 +0000
commitc1bf7779c6a607c29fb6cca06e39d183e4de31c7 (patch)
treee1532b70dc23096ddc663c0c25f6652a8c01d88d /src/ui/tools/pen-tool.cpp
parentWorking on BSPline interpolator (diff)
downloadinkscape-c1bf7779c6a607c29fb6cca06e39d183e4de31c7.tar.gz
inkscape-c1bf7779c6a607c29fb6cca06e39d183e4de31c7.zip
Cleaninng
Diffstat (limited to 'src/ui/tools/pen-tool.cpp')
-rw-r--r--src/ui/tools/pen-tool.cpp152
1 files changed, 91 insertions, 61 deletions
diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp
index f42af8bb6..16cdf63b5 100644
--- a/src/ui/tools/pen-tool.cpp
+++ b/src/ui/tools/pen-tool.cpp
@@ -422,9 +422,8 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) {
case PenTool::STOP:
// This is allowed, if we just canceled curve
case PenTool::POINT:
- this->setPolylineMode();
- this->_bsplineSpiroColor();
if (this->npoints == 0) {
+ this->_bsplineSpiroColor();
Geom::Point p;
if ((bevent.state & GDK_CONTROL_MASK) && (this->polylines_only || this->polylines_paraxial)) {
p = event_dt;
@@ -445,13 +444,7 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) {
// Set start anchor
this->sa = anchor;
- if (anchor) {
- //Put the start overwrite curve always on the same direction
- if (anchor->start) {
- this->sa_overwrited = this->sa->curve->create_reverse();
- } else {
- this->sa_overwrited = this->sa->curve->copy();
- }
+ if(anchor){
this->_bsplineSpiroStartAnchor(bevent.state & GDK_SHIFT_MASK);
}
if (anchor && (!this->hasWaitingLPE()|| this->bspline || this->spiro)) {
@@ -480,6 +473,7 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) {
}
this->_setInitialPoint(p);
} else {
+
// Set end anchor
this->ea = anchor;
Geom::Point p;
@@ -740,30 +734,27 @@ bool PenTool::_handleButtonRelease(GdkEventButton const &revent) {
case PenTool::MODE_CLICK:
switch (this->state) {
case PenTool::POINT:
-// if ( this->npoints == 0 ) {
-// // Start new thread only with button release
-// this->_bsplineSpiroColor();
-// if (anchor) {
-// p = anchor->dp;
-// this->sa = anchor;
-// //Put the start overwrite curve always on the same direction
-// if (anchor->start) {
-// this->sa_overwrited = this->sa->curve->create_reverse();
-// } else {
-// this->sa_overwrited = this->sa->curve->copy();
-// }
-// if(this->bspline || this->spiro){
-// this->_bsplineSpiroStartAnchor(revent.state & GDK_SHIFT_MASK);;
-// }
-// }
-// this->_setInitialPoint(p);
-// } else {
+ if ( this->npoints == 0 ) {
+ // Start new thread only with button release
+ this->_bsplineSpiroColor();
+ if (anchor) {
+ p = anchor->dp;
+ }
+ this->sa = anchor;
+ // continue the existing curve
+ if (anchor) {
+ if(this->bspline || this->spiro){
+ this->_bsplineSpiroStartAnchor(revent.state & GDK_SHIFT_MASK);;
+ }
+ }
+ this->_setInitialPoint(p);
+ } else {
// Set end anchor here
this->ea = anchor;
if (anchor) {
p = anchor->dp;
}
- //}
+ }
this->state = PenTool::CONTROL;
break;
case PenTool::CONTROL:
@@ -1273,8 +1264,6 @@ void PenTool::_resetColors() {
}
this->sa = NULL;
this->ea = NULL;
- this->sa_overwrited->reset();
-
this->npoints = 0;
this->red_curve_is_valid = false;
}
@@ -1426,7 +1415,11 @@ void PenTool::_bsplineSpiroStartAnchor(bool shift)
this->spiro = false;
}
if(!this->spiro && !this->bspline){
- _bsplineSpiroColor();
+ SPCurve *tmp_curve = this->sa->curve->copy();
+ if (this->sa->start) {
+ tmp_curve = tmp_curve ->create_reverse();
+ }
+ this->overwrite_curve = tmp_curve ;
return;
}
if(shift){
@@ -1440,10 +1433,14 @@ void PenTool::_bsplineSpiroStartAnchorOn()
{
using Geom::X;
using Geom::Y;
- Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*this->sa_overwrited ->last_segment());
+ SPCurve *tmp_curve = this->sa->curve->copy();
+ if (this->sa->start) {
+ tmp_curve = tmp_curve ->create_reverse();
+ }
+ Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmp_curve ->last_segment());
SPCurve *last_segment = new SPCurve();
- Geom::Point point_a = this->sa_overwrited->last_segment()->initialPoint();
- Geom::Point point_d = *this->sa_overwrited->last_point();
+ Geom::Point point_a = tmp_curve->last_segment()->initialPoint();
+ Geom::Point point_d = *tmp_curve->last_point();
Geom::Point point_c = point_d + (1./3)*(point_a - point_d);
point_c = Geom::Point(point_c[X] + HANDLE_CUBIC_GAP, point_c[Y] + HANDLE_CUBIC_GAP);
if(cubic){
@@ -1453,34 +1450,43 @@ void PenTool::_bsplineSpiroStartAnchorOn()
last_segment->moveto(point_a);
last_segment->curveto(point_a,point_c,point_d);
}
- if( this->sa_overwrited->get_segment_count() == 1){
- this->sa_overwrited = last_segment->copy();
+ if( tmp_curve ->get_segment_count() == 1){
+ tmp_curve = last_segment;
}else{
//we eliminate the last segment
- this->sa_overwrited->backspace();
+ tmp_curve ->backspace();
//and we add it again with the recreation
- this->sa_overwrited->append_continuous(last_segment, 0.0625);
+ tmp_curve ->append_continuous(last_segment, 0.0625);
}
- last_segment->unref();
+ if (this->sa->start) {
+ tmp_curve = tmp_curve ->create_reverse();
+ }
+ this->overwrite_curve = tmp_curve ;
}
void PenTool::_bsplineSpiroStartAnchorOff()
{
- Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*this->sa_overwrited->last_segment());
+ SPCurve *tmp_curve = this->sa->curve->copy();
+ if(this->sa->start)
+ tmp_curve = tmp_curve ->create_reverse();
+ Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmp_curve ->last_segment());
if(cubic){
SPCurve *last_segment = new SPCurve();
last_segment->moveto((*cubic)[0]);
last_segment->curveto((*cubic)[1],(*cubic)[3],(*cubic)[3]);
- if( this->sa_overwrited->get_segment_count() == 1){
- this->sa_overwrited = last_segment->copy();
+ if( tmp_curve ->get_segment_count() == 1){
+ tmp_curve = last_segment;
}else{
//we eliminate the last segment
- this->sa_overwrited->backspace();
+ tmp_curve ->backspace();
//and we add it again with the recreation
- this->sa_overwrited->append_continuous(last_segment, 0.0625);
+ tmp_curve ->append_continuous(last_segment, 0.0625);
}
- last_segment->unref();
}
+ if (this->sa->start) {
+ tmp_curve = tmp_curve ->create_reverse();
+ }
+ this->overwrite_curve = tmp_curve;
}
void PenTool::_bsplineSpiroMotion(guint const state){
@@ -1504,7 +1510,10 @@ void PenTool::_bsplineSpiroMotion(guint const state){
} else if (!this->green_curve->is_unset()){
tmp_curve = this->green_curve->copy();
} else {
- tmp_curve = this->sa_overwrited->copy();
+ tmp_curve = this->overwrite_curve->copy();
+ if(this->sa->start) {
+ tmp_curve = tmp_curve ->create_reverse();
+ }
}
if ((state & GDK_MOD1_MASK ) && previous != Geom::Point(0,0)) { //ALT drag
this->p[0] = this->p[0] + (this->p[3] - previous);
@@ -1541,7 +1550,11 @@ void PenTool::_bsplineSpiroMotion(guint const state){
}
cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmp_curve ->last_segment());
if (this->sa && this->green_curve->is_unset()) {
- this->sa_overwrited = tmp_curve->copy();
+ if(this->sa->start) {
+ this->overwrite_curve = tmp_curve->copy()->create_reverse();
+ } else {
+ this->overwrite_curve = tmp_curve->copy();
+ }
}
if (!this->green_bpaths.empty()) {
this->green_curve = tmp_curve->copy();
@@ -1614,13 +1627,19 @@ void PenTool::_bsplineSpiroEndAnchorOn()
SPCurve *tmp_curve;
SPCurve *last_segment = new SPCurve();
Geom::Point point_c(0,0);
+ bool reverse = false;
if( this->green_anchor && this->green_anchor->active ){
tmp_curve = this->green_curve->create_reverse();
if(this->green_curve->get_segment_count()==0){
return;
}
+ reverse = true;
} else if(this->sa){
- tmp_curve = this->sa_overwrited->copy()->create_reverse();
+ tmp_curve = this->overwrite_curve->copy();
+ if(!this->sa->start){
+ tmp_curve = tmp_curve ->create_reverse();
+ reverse = true;
+ }
}else{
return;
}
@@ -1646,16 +1665,17 @@ void PenTool::_bsplineSpiroEndAnchorOn()
//and we add it again with the recreation
tmp_curve ->append_continuous(last_segment, 0.0625);
}
- tmp_curve = tmp_curve ->create_reverse();
+ if (reverse) {
+ tmp_curve = tmp_curve ->create_reverse();
+ }
if( this->green_anchor && this->green_anchor->active )
{
this->green_curve->reset();
- this->green_curve = tmp_curve->copy();
+ this->green_curve = tmp_curve ;
}else{
- this->sa_overwrited->reset();
- this->sa_overwrited = tmp_curve->copy();
+ this->overwrite_curve->reset();
+ this->overwrite_curve = tmp_curve ;
}
- tmp_curve->unref();
}
void PenTool::_bsplineSpiroEndAnchorOff()
@@ -1663,14 +1683,20 @@ void PenTool::_bsplineSpiroEndAnchorOff()
SPCurve *tmp_curve;
SPCurve *last_segment = new SPCurve();
+ bool reverse = false;
this->p[2] = this->p[3];
if( this->green_anchor && this->green_anchor->active ){
tmp_curve = this->green_curve->create_reverse();
if(this->green_curve->get_segment_count()==0){
return;
}
+ reverse = true;
} else if(this->sa){
- tmp_curve = this->sa_overwrited->copy()->create_reverse();
+ tmp_curve = this->overwrite_curve->copy();
+ if(!this->sa->start){
+ tmp_curve = tmp_curve ->create_reverse();
+ reverse = true;
+ }
}else{
return;
}
@@ -1690,17 +1716,17 @@ void PenTool::_bsplineSpiroEndAnchorOff()
//and we add it again with the recreation
tmp_curve ->append_continuous(last_segment, 0.0625);
}
- tmp_curve = tmp_curve ->create_reverse();
-
+ if (reverse) {
+ tmp_curve = tmp_curve ->create_reverse();
+ }
if( this->green_anchor && this->green_anchor->active )
{
this->green_curve->reset();
- this->green_curve = tmp_curve->copy();
+ this->green_curve = tmp_curve ;
}else{
- this->sa_overwrited->reset();
- this->sa_overwrited = tmp_curve->copy();
+ this->overwrite_curve->reset();
+ this->overwrite_curve = tmp_curve ;
}
- tmp_curve->unref();
}
//prepares the curves for its transformation into BSpline curve.
@@ -1714,7 +1740,10 @@ void PenTool::_bsplineSpiroBuild()
SPCurve *curve = new SPCurve();
//If we continuate the existing curve we add it at the start
if(this->sa && !this->sa->curve->is_unset()){
- curve = this->sa_overwrited->copy();
+ curve = this->overwrite_curve->copy();
+ if (this->sa->start) {
+ curve = curve->create_reverse();
+ }
}
if (!this->green_curve->is_unset()){
@@ -2009,6 +2038,7 @@ void PenTool::_finish(gboolean const closed) {
// cancelate line without a created segment
this->red_curve->reset();
spdc_concat_colors_and_flush(this, closed);
+ this->overwrite_curve = NULL;
this->sa = NULL;
this->ea = NULL;