diff options
| author | Jabier Arraiza <jabier.arraiza@marker.es> | 2017-08-28 22:19:09 +0000 |
|---|---|---|
| committer | Jabier Arraiza <jabier.arraiza@marker.es> | 2017-08-28 22:19:09 +0000 |
| commit | 1cece014ec24ec8447917fa31029fc70fab69a77 (patch) | |
| tree | 0410f1d6dbf8f18434309301df4d1827a8faa476 /src | |
| parent | Allow pressure in pencil in the tree modes, bezier, bspline and spiro (diff) | |
| download | inkscape-1cece014ec24ec8447917fa31029fc70fab69a77.tar.gz inkscape-1cece014ec24ec8447917fa31029fc70fab69a77.zip | |
Parametrice into preferences magic numbers and other staff
Diffstat (limited to 'src')
| -rw-r--r-- | src/ui/dialog/inkscape-preferences.cpp | 40 | ||||
| -rw-r--r-- | src/ui/dialog/inkscape-preferences.h | 4 | ||||
| -rw-r--r-- | src/ui/tools/freehand-base.cpp | 16 | ||||
| -rw-r--r-- | src/ui/tools/pencil-tool.cpp | 12 | ||||
| -rw-r--r-- | src/ui/tools/pencil-tool.h | 1 | ||||
| -rw-r--r-- | src/widgets/pencil-toolbar.cpp | 45 |
6 files changed, 82 insertions, 36 deletions
diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 13729cf0f..4c62cca91 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -202,6 +202,40 @@ void InkscapePreferences::AddBaseSimplifySpinbutton(DialogPage &p, Glib::ustring false ); } +void InkscapePreferences::AddPressureSensibility(DialogPage &p, Glib::ustring const &prefs_path, double def_value) +{ + PrefSpinButton* sb = Gtk::manage( new PrefSpinButton); + sb->init ( prefs_path + "/pressure-sensibility", 1, 100.0, 1.0, 10.0, def_value, true, false); + p.add_line( false, _("Pressure sensibility:"), *sb, _("on tablet usage"), + _("Pressure sensibility, 12 is a good value"), + false ); +} + +void InkscapePreferences::AddPowerStrokeKnotDistanceFactor(DialogPage &p, Glib::ustring const &prefs_path, double def_value) +{ + PrefSpinButton* sb = Gtk::manage( new PrefSpinButton); + sb->init ( prefs_path + "/knots-distance", 0.1, 9999.0, 1.0, 10.0, def_value, false, false); + p.add_line( false, _("Pressure min knot distance factor:"), *sb, _("on tablet usage"), + _("Min distance between knots, this is a factor computed by zoom so 135 give good results"), + false ); +} + +void InkscapePreferences::AddPowerStrokeGapPressureFactor(DialogPage &p, Glib::ustring const &prefs_path, double def_value) +{ + PrefSpinButton* sb = Gtk::manage( new PrefSpinButton); + sb->init ( prefs_path + "/gap-pressure", 0.01, 9999.0, 1.0, 10.0, def_value, false, false); + p.add_line( false, _("Pressure inputs difference for made knots:"), *sb, _("on tablet usage"), + _("Diference between input pressure to make a powerstroke knot, 1 is a good value"), + false ); +} + +void InkscapePreferences::AddPowerStrokeUseOptimusValues(DialogPage &p, Glib::ustring const &prefs_path, bool def_value) +{ + PrefCheckButton* cb = Gtk::manage( new PrefCheckButton); + cb->init ( _("Use optimiced powerstroke values instead the default ones:"), prefs_path + "/optimus-powerstroke", def_value); + p.add_line( false, "", *cb, "", _("Use optimized powerstroke parameters values in pencil tool por pressure inputs instead the default ones")); +} + static void StyleFromSelectionToTool(Glib::ustring const &prefs_path, StyleSwatch *swatch) { @@ -421,6 +455,12 @@ void InkscapePreferences::initPageTools() this->AddNewObjectsStyle(_page_pencil, "/tools/freehand/pencil"); this->AddDotSizeSpinbutton(_page_pencil, "/tools/freehand/pencil", 3.0); this->AddBaseSimplifySpinbutton(_page_pencil, "/tools/freehand/pencil", 25.0); + _page_pencil.add_group_header( _("Pencil pressure")); + this->AddPowerStrokeUseOptimusValues(_page_pencil, "/tools/freehand/pencil", true); + this->AddPressureSensibility(_page_pencil, "/tools/freehand/pencil", 12.0); + this->AddPowerStrokeKnotDistanceFactor(_page_pencil, "/tools/freehand/pencil", 135.0); + this->AddPowerStrokeGapPressureFactor(_page_pencil, "/tools/freehand/pencil", 1.0); + _page_pencil.add_group_header( _("Sketch mode")); _page_pencil.add_line( true, "", _pencil_average_all_sketches, "", _("If on, the sketch result will be the normal average of all sketches made, instead of averaging the old result with the new sketch")); diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index e6ba4e4b2..50465a9ec 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -497,6 +497,10 @@ 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 AddPressureSensibility(UI::Widget::DialogPage& p, Glib::ustring const &prefs_path, double def_value); + static void AddPowerStrokeKnotDistanceFactor(UI::Widget::DialogPage& p, Glib::ustring const &prefs_path, double def_value); + static void AddPowerStrokeGapPressureFactor(UI::Widget::DialogPage& p, Glib::ustring const &prefs_path, double def_value); + static void AddPowerStrokeUseOptimusValues(UI::Widget::DialogPage& p, Glib::ustring const &prefs_path, bool 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 072500144..2fdc8fade 100644 --- a/src/ui/tools/freehand-base.cpp +++ b/src/ui/tools/freehand-base.cpp @@ -262,13 +262,15 @@ static void spdc_apply_powerstroke_shape(std::vector<Geom::Point> points, Freeha } Effect::createAndApply(POWERSTROKE, dc->desktop->doc(), item); Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE(); - lpe->getRepr()->setAttribute("start_linecap_type", "round"); - lpe->getRepr()->setAttribute("end_linecap_type", "round"); - lpe->getRepr()->setAttribute("sort_points", "true"); - lpe->getRepr()->setAttribute("interpolator_type", "CentripetalCatmullRom"); - lpe->getRepr()->setAttribute("interpolator_beta", "0.2"); - lpe->getRepr()->setAttribute("miter_limit", "4"); - lpe->getRepr()->setAttribute("linejoin_type", "round"); + if(prefs->getBool("/tools/freehand/pencil/optimus-powerstroke",true)) { + lpe->getRepr()->setAttribute("start_linecap_type", "round"); + lpe->getRepr()->setAttribute("end_linecap_type", "round"); + lpe->getRepr()->setAttribute("sort_points", "true"); + lpe->getRepr()->setAttribute("interpolator_type", "CentripetalCatmullRom"); + lpe->getRepr()->setAttribute("interpolator_beta", "0.2"); + lpe->getRepr()->setAttribute("miter_limit", "4"); + lpe->getRepr()->setAttribute("linejoin_type", "round"); + } static_cast<LPEPowerStroke*>(lpe)->offset_points.param_set_and_write_new_value(pt->points); pt->points.clear(); return; diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 7fcbaa31e..3705d0f43 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -70,7 +70,6 @@ PencilTool::PencilTool() , req_tangent(0, 0) , is_drawing(false) , sketch_n(0) - , _gap_pressure(1.0) , _powerpreview(NULL) { } @@ -759,7 +758,13 @@ PencilTool::addPowerStrokePencil(SPCurve * c) if (min > max){ min = max; } + double gap_pressure = prefs->getDoubleLimited("/tools/freehand/pencil/gap-pressure",1.0, 0.1, 9999.0); + double knots_distance = prefs->getDoubleLimited("/tools/freehand/pencil/knots-distance",1.0, 0.1, 9999.0); + gint pressure_sensibility = prefs->getIntLimited("/tools/freehand/pencil/pressure-sensibility",12, 1, 100); + + double previous_pressure = 0.0; + double tol = knots_distance / zoom; Geom::Point previous_point = Geom::Point(0,0); bool start = true; auto pressure = this->wps.begin(); @@ -767,7 +772,7 @@ PencilTool::addPowerStrokePencil(SPCurve * c) //Maybe the 12 POW can be moved to a preferences 12 give a good results of sensibility on my tablet //But maybe is a tweakable value. less number = less sensibility //8 give an aceptable max witht to powerstoke - double pressure_base = pow(*pressure, 12); + double pressure_base = pow(*pressure, pressure_sensibility); double pressure_shirnked = (pressure_base * (max - min)) + min; double pressure_factor = pressure_base/pressure_shirnked; double pressure_computed = (pressure_shirnked * 8.0 * scale) / zoom; @@ -776,8 +781,7 @@ PencilTool::addPowerStrokePencil(SPCurve * c) pressure_computed = previous_pressure; buttonrelease = true; } - double tol = 135.0 / zoom; - if (start || std::abs(previous_pressure - pressure_computed) > _gap_pressure / (zoom * pressure_factor)) { + if (start || std::abs(previous_pressure - pressure_computed) > gap_pressure / (zoom * pressure_factor)) { Geom::Point position = *point; if (!live) { position *= transformCoordinate.inverse(); diff --git a/src/ui/tools/pencil-tool.h b/src/ui/tools/pencil-tool.h index 32eac2272..8f57cf4d0 100644 --- a/src/ui/tools/pencil-tool.h +++ b/src/ui/tools/pencil-tool.h @@ -69,7 +69,6 @@ private: bool _handleKeyPress(GdkEventKey const &event); bool _handleKeyRelease(GdkEventKey const &event); void _setStartpoint(Geom::Point const &p); - double _gap_pressure; SPItem *_powerpreview; void _setEndpoint(Geom::Point const &p); diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp index d86203ff8..936b75d75 100644 --- a/src/widgets/pencil-toolbar.cpp +++ b/src/widgets/pencil-toolbar.cpp @@ -161,30 +161,6 @@ static void sp_add_freehand_mode_toggle(GtkActionGroup* mainActions, GObject* ho g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(freehand_mode_changed), holder); } { - if (tool_is_pencil) { - /* Use pressure */ - { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - InkToggleAction* itact = ink_toggle_action_new( "PencilPressureAction", - _("Use pressure input"), - _("Use pressure input"), - INKSCAPE_ICON("draw-use-pressure"), - GTK_ICON_SIZE_SMALL_TOOLBAR ); - bool pressure = prefs->getBool(freehand_tool_name(holder) + "/pressure", true); - gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(itact), pressure ); - g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(use_pencil_pressure), holder) ; - gtk_action_group_add_action( mainActions, GTK_ACTION(itact) ); - if (pressure) { - gtk_action_set_visible( GTK_ACTION( g_object_get_data(holder, "minpressure") ), true ); - gtk_action_set_visible( GTK_ACTION( g_object_get_data(holder, "maxpressure") ), true ); - } else { - gtk_action_set_visible( GTK_ACTION( g_object_get_data(holder, "minpressure") ), false ); - gtk_action_set_visible( GTK_ACTION( g_object_get_data(holder, "maxpressure") ), false ); - } - } - } - } - { /* LPE bspline spiro flatten */ InkAction* inky = ink_action_new( tool_is_pencil ? "FlattenSpiroBsplinePencil" : "FlattenSpiroBsplinePen", @@ -495,6 +471,8 @@ void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb sp_add_freehand_mode_toggle(mainActions, holder, true); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); EgeAdjustmentAction* eact = 0; + + /* min pressure */ { eact = create_adjustment_action( "MinPressureAction", @@ -530,6 +508,25 @@ void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb gtk_action_set_visible( GTK_ACTION(eact), false ); } } + /* Use pressure */ + { + InkToggleAction* itact = ink_toggle_action_new( "PencilPressureAction", + _("Use pressure input"), + _("Use pressure input"), + INKSCAPE_ICON("draw-use-pressure"), + GTK_ICON_SIZE_SMALL_TOOLBAR ); + bool pressure = prefs->getBool(freehand_tool_name(holder) + "/pressure", true); + gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(itact), pressure ); + g_signal_connect_after( G_OBJECT(itact), "toggled", G_CALLBACK(use_pencil_pressure), holder) ; + gtk_action_group_add_action( mainActions, GTK_ACTION(itact) ); + if (pressure) { + gtk_action_set_visible( GTK_ACTION( g_object_get_data(holder, "minpressure") ), true ); + gtk_action_set_visible( GTK_ACTION( g_object_get_data(holder, "maxpressure") ), true ); + } else { + gtk_action_set_visible( GTK_ACTION( g_object_get_data(holder, "minpressure") ), false ); + gtk_action_set_visible( GTK_ACTION( g_object_get_data(holder, "maxpressure") ), false ); + } + } /* Tolerance */ { gchar const* labels[] = {_("(many nodes, rough)"), _("(default)"), 0, 0, 0, 0, _("(few nodes, smooth)")}; |
