Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
eraser-toolbar.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
6/* Authors:
7 * MenTaLguY <mental@rydia.net>
8 * Lauris Kaplinski <lauris@kaplinski.com>
9 * bulia byak <buliabyak@users.sf.net>
10 * Frank Felfe <innerspace@iname.com>
11 * John Cliff <simarilius@yahoo.com>
12 * David Turner <novalis@gnu.org>
13 * Josh Andler <scislac@scislac.com>
14 * Jon A. Cruz <jon@joncruz.org>
15 * Maximilian Albert <maximilian.albert@gmail.com>
16 * Tavmjong Bah <tavmjong@free.fr>
17 * Abhishek Sharma
18 * Kris De Gussem <Kris.DeGussem@gmail.com>
19 * Vaibhav Malik <vaibhavmalik2018@gmail.com>
20 *
21 * Copyright (C) 2004 David Turner
22 * Copyright (C) 2003 MenTaLguY
23 * Copyright (C) 1999-2011 authors
24 * Copyright (C) 2001-2002 Ximian, Inc.
25 *
26 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
27 */
28
29#include "eraser-toolbar.h"
30
31#include <glibmm/i18n.h>
32#include <gtkmm/adjustment.h>
33#include <gtkmm/togglebutton.h>
34
35#include "desktop.h"
36#include "document-undo.h"
37#include "ui/builder-utils.h"
40#include "ui/util.h"
42
44
45namespace Inkscape::UI::Toolbar {
46
50
51EraserToolbar::EraserToolbar(Glib::RefPtr<Gtk::Builder> const &builder)
52 : Toolbar{get_widget<Gtk::Box>(builder, "eraser-toolbar")}
53 , _width_item(get_derived_widget<UI::Widget::SpinButton>(builder, "_width_item"))
54 , _thinning_item(get_derived_widget<UI::Widget::SpinButton>(builder, "_thinning_item"))
55 , _cap_rounding_item(get_derived_widget<UI::Widget::SpinButton>(builder, "_cap_rounding_item"))
56 , _tremor_item(get_derived_widget<UI::Widget::SpinButton>(builder, "_tremor_item"))
57 , _mass_item(get_derived_widget<UI::Widget::SpinButton>(builder, "_mass_item"))
58 , _usepressure_btn(&get_widget<Gtk::ToggleButton>(builder, "_usepressure_btn"))
59 , _split_btn(get_widget<Gtk::ToggleButton>(builder, "_split_btn"))
60{
61 auto prefs = Preferences::get();
62 int const eraser_mode = prefs->getInt("/tools/eraser/mode", _modeAsInt(Tools::DEFAULT_ERASER_MODE));
63
64 // Setup the spin buttons.
70
72 { 0, _("(no width)")},
73 { 1, _("(hairline)")},
74 { 3, ""},
75 { 5, ""},
76 { 10, ""},
77 { 15, _("(default)")},
78 { 20, ""},
79 { 30, ""},
80 { 50, ""},
81 { 75, ""},
82 {100, _("(broad stroke)")}
83 });
84
86 {-100, _("(speed blows up stroke)")},
87 { -40, ""},
88 { -20, ""},
89 { -10, _("(slight widening)")},
90 { 0, _("(constant width)")},
91 { 10, _("(slight thinning, default)")},
92 { 20, ""},
93 { 40, ""},
94 { 100, _("(speed deflates stroke)")}
95 });
96
98 { 0, _("(blunt caps, default)")},
99 {0.3, _("(slightly bulging)")},
100 {0.5, ""},
101 {1.0, ""},
102 {1.4, _("(approximately round)")},
103 {5.0, _("(long protruding caps)")}
104 });
105
107 { 0, _("(smooth line)")},
108 { 10, _("(slight tremor)")},
109 { 20, _("(noticeable tremor)")},
110 { 40, ""},
111 { 60, ""},
112 {100, _("(maximum tremor)")}
113 });
114
116 { 0, _("(no inertia)")},
117 { 2, _("(slight smoothing, default)")},
118 { 10, _("(noticeable lagging)")},
119 { 20, ""},
120 { 50, ""},
121 {100, _("(maximum inertia)")}
122 });
123
124 // Configure mode buttons
125 int btn_index = 0;
126 for_each_child(get_widget<Gtk::Box>(builder, "mode_buttons_box"), [&](Gtk::Widget &item){
127 auto &btn = dynamic_cast<Gtk::ToggleButton &>(item);
128 btn.set_active(btn_index == eraser_mode);
129 btn.signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &EraserToolbar::mode_changed), btn_index++));
131 });
132
133 // Pressure button
134 _pressure_pusher = std::make_unique<UI::SimplePrefPusher>(_usepressure_btn, "/tools/eraser/usepressure");
135
136 // Split button
137 _split_btn.set_active(prefs->getBool("/tools/eraser/break_apart", false));
138
140
141 // Signals.
142 _usepressure_btn->signal_toggled().connect(sigc::mem_fun(*this, &EraserToolbar::usepressure_toggled));
143 _split_btn.signal_toggled().connect(sigc::mem_fun(*this, &EraserToolbar::toggle_break_apart));
144
145 set_eraser_mode_visibility(eraser_mode);
146}
147
149
151 double default_value, ValueChangedMemFun const value_changed_mem_fun)
152{
153 auto const path = "/tools/eraser/" + name;
154 auto const val = Preferences::get()->getDouble(path, default_value);
155
156 auto adj = btn.get_adjustment();
157 adj->set_value(val);
158 adj->signal_value_changed().connect(sigc::mem_fun(*this, value_changed_mem_fun));
159
160 btn.setDefocusTarget(this);
161}
162
169{
170 using namespace Inkscape::UI::Tools;
171
172 if (mode == EraserToolMode::DELETE) {
173 return 0;
174 } else if (mode == EraserToolMode::CUT) {
175 return 1;
176 } else if (mode == EraserToolMode::CLIP) {
177 return 2;
178 } else {
179 return _modeAsInt(DEFAULT_ERASER_MODE);
180 }
181}
182
184{
186 Preferences::get()->setInt("/tools/eraser/mode", mode);
187 }
188
190
191 // only take action if run by the attr_changed listener
192 /*if (!_blocker.pending()) {
193 // in turn, prevent listener from responding
194 auto guard = _blocker.block();
195
196 if ( eraser_mode != ERASER_MODE_DELETE ) {
197 } else {
198 }
199 // TODO finish implementation
200 }*/
201}
202
203void EraserToolbar::set_eraser_mode_visibility(unsigned const eraser_mode)
204{
205 using namespace Inkscape::UI::Tools;
206
207 bool const visibility = eraser_mode != _modeAsInt(EraserToolMode::DELETE);
208 auto children = UI::get_children(_toolbar);
209 constexpr int visible_children_count = 2;
210
211 // Set all the children except the modes as invisible.
212 int child_index = 0;
213 for (auto child : children) {
214 if (child_index++ < visible_children_count) {
215 continue;
216 }
217
218 child->set_visible(visibility);
219 }
220
221 _split_btn.set_visible(eraser_mode == _modeAsInt(EraserToolMode::CUT));
222}
223
225{
226 Preferences::get()->setDouble("/tools/eraser/width", _width_item.get_adjustment()->get_value());
227}
228
230{
231 Preferences::get()->setDouble("/tools/eraser/mass", _mass_item.get_adjustment()->get_value());
232}
233
235{
236 Preferences::get()->setDouble("/tools/eraser/thinning", _thinning_item.get_adjustment()->get_value());
237}
238
240{
241 Preferences::get()->setDouble("/tools/eraser/cap_rounding", _cap_rounding_item.get_adjustment()->get_value());
242}
243
245{
246 Preferences::get()->setDouble("/tools/eraser/tremor", _tremor_item.get_adjustment()->get_value());
247}
248
250{
251 Preferences::get()->setBool("/tools/eraser/break_apart", _split_btn.get_active());
252}
253
255{
256 Preferences::get()->setBool("/tools/eraser/usepressure", _usepressure_btn->get_active());
257}
258
259} // namespace Inkscape::UI::Toolbar
260
261/*
262 Local Variables:
263 mode:c++
264 c-file-style:"stroustrup"
265 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
266 indent-tabs-mode:nil
267 fill-column:99
268 End:
269*/
270// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Gtk builder utilities.
static bool getUndoSensitive(SPDocument const *document)
double getDouble(Glib::ustring const &pref_path, double def=0.0, Glib::ustring const &unit="")
Retrieve a floating point value.
static Preferences * get()
Access the singleton Preferences object.
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.
std::unique_ptr< SimplePrefPusher > _pressure_pusher
UI::Widget::SpinButton & _mass_item
UI::Widget::SpinButton & _cap_rounding_item
static unsigned _modeAsInt(Tools::EraserToolMode mode)
Computes the integer value representing eraser mode.
UI::Widget::SpinButton & _thinning_item
UI::Widget::SpinButton & _tremor_item
void setup_derived_spin_button(UI::Widget::SpinButton &btn, Glib::ustring const &name, double default_value, ValueChangedMemFun value_changed_mem_fun)
void set_eraser_mode_visibility(unsigned eraser_mode)
UI::Widget::SpinButton & _width_item
void(EraserToolbar::*)() ValueChangedMemFun
Base class for all tool toolbars.
Definition toolbar.h:72
SpinButton widget, that allows entry of simple math expressions (also units, when linked with UnitMen...
Definition spinbutton.h:52
void setDefocusTarget(decltype(_defocus_target) target)
Definition spinbutton.h:127
void set_custom_numeric_menu_data(NumericMenuData &&custom_menu_data)
SPDocument * getDocument() const
Definition desktop.h:189
Editable view implementation.
TODO: insert short description here.
Eraser toolbar.
SPItem * item
Definition desktop.h:50
static constexpr auto DEFAULT_ERASER_MODE
Definition eraser-tool.h:43
std::vector< Gtk::Widget * > get_children(Gtk::Widget &widget)
Get a vector of the widgetʼs children, from get_first_child() through each get_next_sibling().
Definition util.cpp:156
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.
Definition util.h:103
W & get_derived_widget(const Glib::RefPtr< Gtk::Builder > &builder, const char *id, Args &&... args)
Glib::RefPtr< Gtk::Builder > create_builder(const char *filename)
int mode
Ocnode * child[8]
Definition quantize.cpp:33
Glib::ustring name
Definition toolbars.cpp:55
Glib::RefPtr< Gtk::Builder > builder