diff options
| author | Jabier Arraiza <jabier.arraiza@marker.es> | 2017-11-22 22:58:26 +0000 |
|---|---|---|
| committer | Jabier Arraiza <jabier.arraiza@marker.es> | 2017-11-22 22:58:26 +0000 |
| commit | 157d892c95684c195bfe9ad050e8c881cc3d4555 (patch) | |
| tree | e1532b70dc23096ddc663c0c25f6652a8c01d88d /src | |
| parent | Smoothing start and end (diff) | |
| download | inkscape-157d892c95684c195bfe9ad050e8c881cc3d4555.tar.gz inkscape-157d892c95684c195bfe9ad050e8c881cc3d4555.zip | |
Working on continuous paths
Diffstat (limited to 'src')
| -rw-r--r-- | src/ui/dialog/inkscape-preferences.cpp | 10 | ||||
| -rw-r--r-- | src/ui/dialog/inkscape-preferences.h | 2 | ||||
| -rw-r--r-- | src/ui/tools/freehand-base.cpp | 18 | ||||
| -rw-r--r-- | src/ui/tools/pencil-tool.cpp | 90 | ||||
| -rw-r--r-- | src/ui/tools/pencil-tool.h | 2 |
5 files changed, 71 insertions, 51 deletions
diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index ef69fdade..99312f8c8 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -204,12 +204,12 @@ void InkscapePreferences::AddBaseSimplifySpinbutton(DialogPage &p, Glib::ustring false ); } -void InkscapePreferences::AddPowerStrokeGapPressureFactor(DialogPage &p, Glib::ustring const &prefs_path, gint def_value) +void InkscapePreferences::AddPencilPowerStrokePressureStep(DialogPage &p, Glib::ustring const &prefs_path, gint def_value) { PrefSpinButton* sb = Gtk::manage( new PrefSpinButton); - sb->init ( prefs_path + "/gap-pressure", 1, 100, 1, 10, def_value, true, false); - p.add_line( false, _("Pressure diference on knots:"), *sb, _("%"), - _("Pressure diference percent that is required to create a new PowerStroke knot."), + sb->init ( prefs_path + "/ps-step-pressure", 1, 100, 1, 10, def_value, true, false); + p.add_line( false, _("Pressure change for new knot:"), *sb, _("%"), + _("Percentage increase / decrease of stylus pressure that is required to create a new PowerStroke knot."), false ); } @@ -432,7 +432,7 @@ void InkscapePreferences::initPageTools() this->AddDotSizeSpinbutton(_page_pencil, "/tools/freehand/pencil", 3.0); this->AddBaseSimplifySpinbutton(_page_pencil, "/tools/freehand/pencil", 25.0); _page_pencil.add_group_header( _("Pressure sensitivity settings")); - this->AddPowerStrokeGapPressureFactor(_page_pencil, "/tools/freehand/pencil", 10); + this->AddPencilPowerStrokePressureStep(_page_pencil, "/tools/freehand/pencil", 10); _page_pencil.add_group_header( _("Sketch mode")); _page_pencil.add_line( true, "", _pencil_average_all_sketches, "", diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index 0f78a49a4..639c3af68 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -500,7 +500,7 @@ protected: static void AddFirstAndLastCheckbox(UI::Widget::DialogPage& p, Glib::ustring const &prefs_path, bool def_value); static void AddDotSizeSpinbutton(UI::Widget::DialogPage& p, Glib::ustring const &prefs_path, double def_value); static void AddBaseSimplifySpinbutton(UI::Widget::DialogPage& p, Glib::ustring const &prefs_path, double def_value); - static void AddPowerStrokeGapPressureFactor(UI::Widget::DialogPage& p, Glib::ustring const &prefs_path, gint def_value); + static void AddPencilPowerStrokePressureStep(UI::Widget::DialogPage& p, Glib::ustring const &prefs_path, gint def_value); static void AddNewObjectsStyle(UI::Widget::DialogPage& p, Glib::ustring const &prefs_path, const gchar* banner = NULL); void on_pagelist_selection_changed(); diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp index 1259d411f..15027b6f3 100644 --- a/src/ui/tools/freehand-base.cpp +++ b/src/ui/tools/freehand-base.cpp @@ -330,7 +330,6 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, { using namespace Inkscape::LivePathEffect; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (item && SP_IS_LPE_ITEM(item)) { //Store the clipboard path to apply in the future without the use of clipboard static Geom::PathVector previous_shape_pathv; @@ -397,11 +396,16 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, } if (SP_IS_PENCIL_CONTEXT(dc)) { if (dc->input_has_pressure) { - std::vector<Geom::Point> points; - spdc_apply_powerstroke_shape(points, dc, item); - shape = NONE; - //To allow retain color - shape_applied = true; + if (shape == NONE) { + std::vector<Geom::Point> points; + spdc_apply_powerstroke_shape(points, dc, item); + //To allow retain color + shape_applied = true; + } else { + PencilTool *pt = SP_PENCIL_CONTEXT(dc); + pt->removePowerStrokePreview(); + shape == NONE; + } } } #define SHAPE_LENGTH 10 @@ -865,7 +869,7 @@ static void spdc_flush_white(FreehandBase *dc, SPCurve *gc) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr)); //Bend needs the transforms applied after, Other effects best before - spdc_check_for_and_apply_waiting_LPE(dc, item, c, true); + (dc, item, c, true); Inkscape::GC::release(repr); item->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse(); item->updateRepr(); diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index ae6fd6c17..1e1650d44 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -74,7 +74,7 @@ PencilTool::PencilTool() , sketch_n(0) , _powerpreviewtail(NULL) , _powerpreview(NULL) - , _previewok(true) + , _preview_ok(true) { } @@ -281,6 +281,10 @@ bool PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { // Once the user has moved farther than tolerance from the original location // (indicating they intend to move the object, not click), then always process the // motion notify coordinates as given (no snapping back to origin) + if (input_has_pressure && pencil_within_tolerance) { + p = desktop->w2d(pencil_drag_origin_w); + anchor = spdc_test_inside(this, pencil_drag_origin_w); + } pencil_within_tolerance = false; switch (this->state) { @@ -288,8 +292,8 @@ bool PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { /* Set red endpoint */ if (input_has_pressure) { this->state = SP_PENCIL_CONTEXT_FREEHAND; - return true; - } + return false; + } if (anchor) { p = anchor->dp; } else { @@ -313,6 +317,7 @@ bool PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { this->green_anchor = sp_draw_anchor_new(this, this->green_curve, TRUE, this->p[0]); } if (anchor) { + std::cout << "aaaaaaaaaaaaaaaaaaaaaaaaaa" << std::endl; p = anchor->dp; } if ( this->npoints != 0) { // buttonpress may have happened before we entered draw context! @@ -350,7 +355,7 @@ bool PencilTool::_handleMotionNotify(GdkEventMotion const &mevent) { // Show the pre-snap indicator to communicate to the user where we would snap to if he/she were to // a) press the mousebutton to start a freehand drawing, or // b) release the mousebutton to finish a freehand drawing - if (!this->sp_event_context_knot_mouseover() && !input_has_pressure) { + if (!this->sp_event_context_knot_mouseover()) { SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop, true); m.preSnap(Inkscape::SnapCandidatePoint(p, Inkscape::SNAPSOURCE_NODE_HANDLE)); @@ -712,9 +717,9 @@ PencilTool::_powerStrokePreview(Geom::Path const path, std::vector<Geom::Point> } if (!curve->is_empty()) { _powerpreviewtail->setCurve(curve, true); - _previewok = true; + _preview_ok = true; } else {//if (!_second_chance_preview) { - _previewok = false; + _preview_ok = false; } } curve->unref(); @@ -747,7 +752,7 @@ PencilTool::addPowerStrokePencil(SPCurve * c) this->points.clear(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); double tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0); - double gap_pressure = prefs->getIntLimited("/tools/freehand/pencil/gap-pressure",10, 1, 100)/100.0; + double gap_pressure = prefs->getIntLimited("/tools/freehand/pencil/ps-step-pressure",10, 1, 100)/100.0; double min = prefs->getIntLimited("/tools/freehand/pencil/minpressure", 0, 1, 100) / 100.0; double max = prefs->getIntLimited("/tools/freehand/pencil/maxpressure", 100, 1, 100) / 100.0; if (min > max){ @@ -797,7 +802,7 @@ PencilTool::addPowerStrokePencil(SPCurve * c) if (curve->is_empty()) { curve = green_curve->copy(); } else { - green_curve->move_endpoints(curve->first_path()->finalPoint(), *green_curve->last_point()); + green_curve->move_endpoints(curve->first_path()->finalPoint(), green_curve->first_path()->finalPoint()); curve->append_continuous( green_curve, 0.0625); } if (!red_curve->is_empty()) { @@ -846,21 +851,13 @@ PencilTool::addPowerStrokePencil(SPCurve * c) double pos = Geom::nearest_time(position, path); for (auto point = this->ps.begin(); point != this->ps.end(); ++point, ++pressure) { counter++; -// //remove end pressure gap -// if (this->ps.size() > 4 && this->ps.size()-4 < counter) { -// break; -// } double pressure_shrunk = (*pressure * (max - min)) + min; //We need half width for power stroke pressure_computed = pressure_shrunk * dezoomify_factor/2.0; //remove start pressure gap - if (counter < 2) { - if (start) { - start = false; - this->points.push_back(Geom::Point(pos + 0.01, pressure_computed)); - } else { - this->points[this->points.size()-1] = Geom::Point(pos + 0.01, pressure_computed); - } + if (start) { + start = false; + this->points.push_back(Geom::Point(pos + 0.01, pressure_computed)); previous_pressure = pressure_shrunk; continue; } @@ -869,14 +866,14 @@ PencilTool::addPowerStrokePencil(SPCurve * c) position *= transformCoordinate.inverse(); } pos = Geom::nearest_time(position, path); - if (pos < 1e6 && std::abs(previous_pressure - pressure_shrunk) > gap_pressure) { + if (pos < 1e6 && std::abs(previous_pressure - pressure_shrunk) > gap_pressure && pos < path.size() - 1) { previous_pressure = pressure_shrunk; this->points.push_back(Geom::Point(pos, pressure_computed)); } } if (live && this->points.size() > 0) { bool write = false; - if (points_parsed != this->points.size() || !_previewok) { + if (points_parsed != this->points.size() || !_preview_ok) { points_parsed = this->points.size(); write = true; } @@ -939,22 +936,41 @@ void PencilTool::_interpolate(bool realize) { if (tol < 18.0 * 0.4) { tol = 18.0 * 0.4; } - //Smooth start segments + //we dont need a exact calulation set up a high precission + //we remove pointa at start and end nearest to 1/20 of total length + double distance = 0; + Geom::Point prev = this->ps[0]; + for (auto i:this->ps) { + if (i == prev) { + continue; + } + distance += Geom::distance(i, prev); + prev = i; + } + double smoothlenght = (distance/this->ps.size()); + std::cout << smoothlenght << "smoothlenght" << std::endl; + +// //Double check to limit on large strokes +// double limitlenght = desktop->get_display_area().diameter()/20.0; +// std::cout << limitlenght << "limitlenght" << std::endl; +// //smoothlenght = std::min(smoothlenght, limitlenght); +// //Smooth start segments + + + + if (realize && this->ps.size() > 3) { - this->ps.erase(this->ps.begin() + 1, this->ps.begin() + 2); - this->wps.erase(this->wps.begin() + 1, this->wps.begin() + 2); + Geom::Point start_point = *this->ps.begin(); + while ( this->ps.size() > 6 && Geom::distance(*(this->ps.begin()+1), start_point) < smoothlenght) { + this->ps.erase(this->ps.begin() + 1); + this->wps.erase(this->wps.begin() + 1); + } } //Smooth last segments if (realize && this->ps.size() > 3) { - double start_distance = Geom::distance(this->ps[0], this->ps[1]); Geom::Point last_point = *this->ps.end(); - std::cout << start_distance << "start_distance" << std::endl; - std::cout << Geom::distance(*this->ps.end(), last_point) << "distance" << std::endl; - std::cout << "::::::::::::::::::::::::::::::::::::::distance" << std::endl; bool erased = false; - while ( this->ps.size() > 9 && Geom::distance(*this->ps.end(), last_point) < start_distance) { - std::cout << Geom::distance(*this->ps.end(), last_point) << "distance" << std::endl; - std::cout << start_distance << "start_distance" << std::endl; + while ( this->ps.size() > 6 && Geom::distance(*this->ps.end(), last_point) < smoothlenght) { this->ps.pop_back(); this->wps.pop_back(); erased = true; @@ -999,13 +1015,13 @@ void PencilTool::_interpolate(bool realize) { this->green_curve->curveto(point_at1,point_at2,b[4*c+3]); } else { //force retracted handle at end if power stroke -// if (c == n_segs - 1 && input_has_pressure) { -// this->green_curve->curveto(b[4 * c + 1], b[4 * c + 3], b[4 * c + 3]); -// } else if (c == 0 && input_has_pressure) { -// this->green_curve->curveto(b[4 * c], b[4 * c + 2], b[4 * c + 3]); -// } else { + if (c == n_segs - 1 && input_has_pressure) { + this->green_curve->curveto(b[4 * c + 1], b[4 * c + 3], b[4 * c + 3]); + } else if (c == 0 && input_has_pressure) { + this->green_curve->curveto(b[4 * c], b[4 * c + 2], b[4 * c + 3]); + } else { this->green_curve->curveto(b[4 * c + 1], b[4 * c + 2], b[4 * c + 3]); - //} + } } } if (!input_has_pressure) { diff --git a/src/ui/tools/pencil-tool.h b/src/ui/tools/pencil-tool.h index 56604eaca..e15289ad1 100644 --- a/src/ui/tools/pencil-tool.h +++ b/src/ui/tools/pencil-tool.h @@ -73,7 +73,7 @@ private: void _powerStrokePreview(Geom::Path const path, std::vector<Geom::Point> points, bool write); SPShape *_powerpreview; SPShape *_powerpreviewtail; - bool _previewok; + bool _preview_ok; gchar const * end_linecap_type; void _setEndpoint(Geom::Point const &p); void _finishEndpoint(); |
