31#include <glibmm/i18n.h>
32#include <gtkmm/adjustment.h>
33#include <gtkmm/togglebutton.h>
61 , _tool_is_pencil(pencil_mode)
79 auto &btn =
dynamic_cast<Gtk::ToggleButton &
>(
item);
87 _flattenLPE<LivePathEffect::LPEBSpline, LivePathEffect::LPESpiro>();
107 {1, _(
"(many nodes, rough)")},
108 {10, _(
"(default)")},
113 {100, _(
"(few nodes, smooth)")}
117 bool pressure = prefs->getBool(
"/tools/freehand/pencil/pressure",
false);
125 _simplify_btn.set_active(prefs->getInt(
"/tools/freehand/pencil/simplify", 0));
129 _flatten_simplify_btn.signal_clicked().connect([
this] { _flattenLPE<LivePathEffect::LPESimplify>(); });
151 auto store = Gtk::ListStore::create(columns);
153 for (
auto item : std::vector<char const *>{C_(
"Cap",
"Butt"), _(
"Square"), _(
"Round"), _(
"Peak"), _(
"Zero width")}) {
154 Gtk::TreeModel::Row row = *
store->append();
160 _(
"Caps"), _(
"Line endings when drawing with pressure-sensitive PowerPencil"),
"Not Used",
store));
164 int cap = prefs->getInt(
"/live_effects/powerstroke/powerpencilcap", 2);
177 auto store = Gtk::ListStore::create(columns);
179 std::vector<char const *> freehand_shape_dropdown_items_list = {(C_(
"Freehand shape",
"None")),
184 _(
"Bend from clipboard"),
187 for (
auto item : freehand_shape_dropdown_items_list) {
188 Gtk::TreeModel::Row row = *
store->append();
209 auto const path =
"/tools/freehand/pencil/" +
name;
210 auto const val = prefs->getDouble(path, default_value);
212 auto adj = btn.get_adjustment();
214 adj->signal_value_changed().connect(sigc::mem_fun(*
this, value_changed_mem_fun));
221 auto const pen_only_items = std::vector<Gtk::Widget *>{
222 &get_widget<Gtk::Widget>(
builder,
"zigzag_btn"),
223 &get_widget<Gtk::Widget>(
builder,
"paraxial_btn")
226 auto const pencil_only_items = std::vector<Gtk::Widget *>{
227 &get_widget<Gtk::Widget>(
builder,
"pencil_only_box")
230 for (
auto child : pen_only_items) {
234 for (
auto child : pencil_only_items) {
241 if (freehandMode != 1 && freehandMode != 2) {
277 pt->setPolylineMode();
284 return _tool_is_pencil ?
"/tools/freehand/pencil" :
"/tools/freehand/pen";
320 auto lpeitem = cast<SPLPEItem>(selection->singleItem());
323 using namespace LivePathEffect;
327 prefs->setDouble(
"/live_effects/powerstroke/width",
width);
329 if (
auto effect =
dynamic_cast<LPEPowerStroke *
>(lpeitem->getFirstPathEffectOfType(POWERSTROKE))) {
330 auto points = effect->offset_points.data();
331 if (points.size() == 1) {
332 points[0].y() =
width;
333 effect->offset_points.param_set_and_write_new_value(points);
341 prefs->setDouble(
"/live_effects/skeletal/width",
width);
343 if (
auto effect =
dynamic_cast<LPEPatternAlongPath *
>(lpeitem->getFirstPathEffectOfType(PATTERN_ALONG_PATH))) {
344 effect->prop_scale.param_set_value(
width);
350 prefs->setDouble(
"/live_effects/bend_path/width",
width);
352 if (
auto effect =
dynamic_cast<LPEBendPath *
>(lpeitem->getFirstPathEffectOfType(BEND_PATH))) {
353 effect->prop_scale.param_set_value(
width);
371 prefs->setBool(
"/tools/freehand/pencil/pressure", pressure);
384 int freehandMode = prefs->getInt(
"/tools/freehand/pencil/freehand-mode", 0);
385 bool simplify_visible = freehandMode != 2;
392 button->set_sensitive(!pressure);
412 width = prefs->getDouble(
"/live_effects/powerstroke/width", powerstrokedefsize);
416 width = prefs->getDouble(
"/live_effects/skeletal/width", 1.0);
419 width = prefs->getDouble(
"/live_effects/bend_path/width", 1.0);
442template <
typename... T>
446 auto const shape = cast<SPShape>(
item);
447 if (shape && shape->hasPathEffect()){
448 auto const lpelist = shape->getEffectList();
449 for (
auto const i : lpelist) {
450 if (
auto const lpeobj = i->lpeobject) {
451 auto const lpe = lpeobj->get_lpe();
452 if ((
dynamic_cast<T
const *
>(lpe) || ...)) {
453 auto c = *shape->curveForEdit();
455 shape->setCurrentPathEffect(i);
456 if (lpelist.size() > 1) {
457 shape->removeCurrentPathEffect(
true);
458 shape->setCurveBeforeLPE(std::move(
c));
460 shape->removeCurrentPathEffect(
false);
461 shape->setCurve(std::move(
c));
482 auto const tol = tol_pref / (100.0 * (102.0 - tol_pref));
483 auto const tol_str = (std::ostringstream{} << tol).str();
492 auto const lpeitem = cast<SPLPEItem>(
item);
493 if (lpeitem && lpeitem->hasPathEffect()) {
497 bool simplified =
false;
500 lpe_powerstroke->getRepr()->setAttribute(
"is_visible",
"false");
502 if (
auto const sp_shape = cast<SPShape>(lpeitem)) {
503 auto const previous_curve_length = sp_shape->curve()->curveCount();
504 lpe_simplify->getRepr()->setAttribute(
"threshold", tol_str);
507 auto const curve_length = sp_shape->curve()->curveCount();
508 auto const factor = (double)curve_length / previous_curve_length;
509 auto ts = lpe_powerstroke->offset_points.data();
513 lpe_powerstroke->offset_points.param_setValue(ts);
515 lpe_powerstroke->getRepr()->setAttribute(
"is_visible",
"true");
521 lpe_simplify->getRepr()->setAttribute(
"threshold", tol_str);
SPItemRange items()
Returns a range of selected SPItems.
static Preferences * get()
Access the singleton Preferences object.
int getInt(Glib::ustring const &pref_path, int def=0)
Retrieve an integer.
void setDouble(Glib::ustring const &pref_path, double value)
Set a floating point value.
void setInt(Glib::ustring const &pref_path, int value)
Set an integer value.
void setBool(Glib::ustring const &pref_path, bool value)
Set a Boolean value.
To do: update description of desktop.
SPDocument * getDocument() const
Inkscape::Selection * getSelection() const
Inkscape::UI::Tools::ToolBase * getTool() const
Geom::Scale getDocumentScale(bool computed=true) const
Returns document scale as defined by width/height (in pixels) and viewBox (real world to user-units).
Editable view implementation.
PowerStroke LPE effect, see lpe-powerstroke.cpp.
W & get_widget(const Glib::RefPtr< Gtk::Builder > &builder, const char *id)
Gtk::Widget * for_each_child(Gtk::Widget &widget, Func &&func, bool const plus_self=false, bool const recurse=false, int const level=0)
Call Func with a reference to each child of parent, until it returns _break.
W & get_derived_widget(const Glib::RefPtr< Gtk::Builder > &builder, const char *id, Args &&... args)
Glib::RefPtr< Gtk::Builder > create_builder(const char *filename)
void sp_lpe_item_update_patheffect(SPLPEItem *lpeitem, bool wholetree, bool write, bool with_satellites)
Calls any registered handlers for the update_patheffect action.
Glib::RefPtr< Gtk::Builder > builder