1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
|
/**
* @file
* Pencil aux toolbar
*/
/* Authors:
* MenTaLguY <mental@rydia.net>
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Frank Felfe <innerspace@iname.com>
* John Cliff <simarilius@yahoo.com>
* David Turner <novalis@gnu.org>
* Josh Andler <scislac@scislac.com>
* Jon A. Cruz <jon@joncruz.org>
* Maximilian Albert <maximilian.albert@gmail.com>
* Tavmjong Bah <tavmjong@free.fr>
* Abhishek Sharma
* Kris De Gussem <Kris.DeGussem@gmail.com>
*
* Copyright (C) 2004 David Turner
* Copyright (C) 2003 MenTaLguY
* Copyright (C) 1999-2011 authors
* Copyright (C) 2001-2002 Ximian, Inc.
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <glibmm/i18n.h>
#include "pencil-toolbar.h"
#include "desktop.h"
#include "document-undo.h"
#include "widgets/ege-adjustment-action.h"
#include "widgets/ege-select-one-action.h"
#include "widgets/ink-action.h"
#include "preferences.h"
#include "toolbox.h"
#include "ui/tools-switch.h"
#include "ui/icon-names.h"
#include "ui/tools/pen-tool.h"
#include "ui/uxmanager.h"
#include "widgets/spinbutton-events.h"
using Inkscape::UI::UXManager;
using Inkscape::DocumentUndo;
using Inkscape::UI::ToolboxFactory;
using Inkscape::UI::PrefPusher;
//########################
//## Pen/Pencil ##
//########################
/* This is used in generic functions below to share large portions of code between pen and pencil tool */
static Glib::ustring const freehand_tool_name(GObject *dataKludge)
{
SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data(dataKludge, "desktop"));
return ( tools_isactive(desktop, TOOLS_FREEHAND_PEN)
? "/tools/freehand/pen"
: "/tools/freehand/pencil" );
}
static void freehand_mode_changed(EgeSelectOneAction* act, GObject* tbl)
{
gint mode = ege_select_one_action_get_active(act);
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setInt(freehand_tool_name(tbl) + "/freehand-mode", mode);
SPDesktop *desktop = static_cast<SPDesktop *>(g_object_get_data(tbl, "desktop"));
// in pen tool we have more options than in pencil tool; if one of them was chosen, we do any
// preparatory work here
if (SP_IS_PEN_CONTEXT(desktop->event_context)) {
Inkscape::UI::Tools::PenTool *pc = SP_PEN_CONTEXT(desktop->event_context);
pc->setPolylineMode();
}
}
static void sp_add_freehand_mode_toggle(GtkActionGroup* mainActions, GObject* holder, bool tool_is_pencil)
{
/* Freehand mode toggle buttons */
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
guint freehandMode = prefs->getInt(( tool_is_pencil ? "/tools/freehand/pencil/freehand-mode" : "/tools/freehand/pen/freehand-mode" ), 0);
Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1);
{
GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
GtkTreeIter iter;
gtk_list_store_append( model, &iter );
gtk_list_store_set( model, &iter,
0, _("Bezier"),
1, _("Create regular Bezier path"),
2, INKSCAPE_ICON("path-mode-bezier"),
-1 );
gtk_list_store_append( model, &iter );
gtk_list_store_set( model, &iter,
0, _("Spiro"),
1, _("Create Spiro path"),
2, INKSCAPE_ICON("path-mode-spiro"),
-1 );
gtk_list_store_append( model, &iter );
gtk_list_store_set( model, &iter,
0, _("BSpline"),
1, _("Create BSpline path"),
2, INKSCAPE_ICON("path-mode-bspline"),
-1 );
if (!tool_is_pencil) {
gtk_list_store_append( model, &iter );
gtk_list_store_set( model, &iter,
0, _("Zigzag"),
1, _("Create a sequence of straight line segments"),
2, INKSCAPE_ICON("path-mode-polyline"),
-1 );
gtk_list_store_append( model, &iter );
gtk_list_store_set( model, &iter,
0, _("Paraxial"),
1, _("Create a sequence of paraxial line segments"),
2, INKSCAPE_ICON("path-mode-polyline-paraxial"),
-1 );
}
EgeSelectOneAction* act = ege_select_one_action_new(tool_is_pencil ?
"FreehandModeActionPencil" :
"FreehandModeActionPen",
(_("Mode:")), (_("Mode of new lines drawn by this tool")), NULL, GTK_TREE_MODEL(model) );
gtk_action_group_add_action( mainActions, GTK_ACTION(act) );
ege_select_one_action_set_appearance( act, "full" );
ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE );
g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL );
ege_select_one_action_set_icon_column( act, 2 );
ege_select_one_action_set_icon_size( act, secondarySize );
ege_select_one_action_set_tooltip_column( act, 1 );
ege_select_one_action_set_active( act, freehandMode);
g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(freehand_mode_changed), holder);
}
}
}
static void freehand_change_shape(EgeSelectOneAction* act, GObject *dataKludge) {
gint shape = ege_select_one_action_get_active( act );
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
prefs->setInt(freehand_tool_name(dataKludge) + "/shape", shape);
}
/**
* Generate the list of freehand advanced shape option entries.
*/
static GList * freehand_shape_dropdown_items_list() {
GList *glist = NULL;
glist = g_list_append (glist, const_cast<gchar *>(C_("Freehand shape", "None")));
glist = g_list_append (glist, _("Triangle in"));
glist = g_list_append (glist, _("Triangle out"));
glist = g_list_append (glist, _("Ellipse"));
glist = g_list_append (glist, _("From clipboard"));
glist = g_list_append (glist, _("Last applied"));
return glist;
}
static void freehand_add_advanced_shape_options(GtkActionGroup* mainActions, GObject* holder, bool tool_is_pencil)
{
/*advanced shape options */
{
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
GtkListStore* model = gtk_list_store_new( 2, G_TYPE_STRING, G_TYPE_INT );
GList* items = 0;
gint count = 0;
for ( items = freehand_shape_dropdown_items_list(); items ; items = g_list_next(items) )
{
GtkTreeIter iter;
gtk_list_store_append( model, &iter );
gtk_list_store_set( model, &iter, 0, reinterpret_cast<gchar*>(items->data), 1, count, -1 );
count++;
}
g_list_free( items );
items = 0;
EgeSelectOneAction* act1 = ege_select_one_action_new(
tool_is_pencil ? "SetPencilShapeAction" : "SetPenShapeAction",
_("Shape:"), (_("Shape of new paths drawn by this tool")), NULL, GTK_TREE_MODEL(model));
g_object_set( act1, "short_label", _("Shape:"), NULL );
ege_select_one_action_set_appearance( act1, "compact" );
ege_select_one_action_set_active( act1, prefs->getInt(( tool_is_pencil ? "/tools/freehand/pencil/shape" : "/tools/freehand/pen/shape" ), 0) );
g_signal_connect( G_OBJECT(act1), "changed", G_CALLBACK(freehand_change_shape), holder );
gtk_action_group_add_action( mainActions, GTK_ACTION(act1) );
g_object_set_data( holder, "shape_action", act1 );
}
}
void sp_pen_toolbox_prep(SPDesktop * /*desktop*/, GtkActionGroup* mainActions, GObject* holder)
{
sp_add_freehand_mode_toggle(mainActions, holder, false);
freehand_add_advanced_shape_options(mainActions, holder, false);
}
static void sp_pencil_tb_defaults(GtkWidget * /*widget*/, GObject *obj)
{
GtkWidget *tbl = GTK_WIDGET(obj);
GtkAdjustment *adj;
// fixme: make settable
gdouble tolerance = 4;
adj = GTK_ADJUSTMENT(g_object_get_data(obj, "tolerance"));
gtk_adjustment_set_value(adj, tolerance);
gtk_adjustment_value_changed(adj);
spinbutton_defocus(tbl);
}
static void sp_pencil_tb_tolerance_value_changed(GtkAdjustment *adj, GObject *tbl)
{
// quit if run by the attr_changed listener
if (g_object_get_data( tbl, "freeze" )) {
return;
}
// in turn, prevent listener from responding
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
prefs->setDouble("/tools/freehand/pencil/tolerance",
gtk_adjustment_get_value(adj));
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
}
/*
class PencilToleranceObserver : public Inkscape::Preferences::Observer {
public:
PencilToleranceObserver(Glib::ustring const &path, GObject *x) : Observer(path), _obj(x)
{
g_object_set_data(_obj, "prefobserver", this);
}
virtual ~PencilToleranceObserver() {
if (g_object_get_data(_obj, "prefobserver") == this) {
g_object_set_data(_obj, "prefobserver", NULL);
}
}
virtual void notify(Inkscape::Preferences::Entry const &val) {
GObject* tbl = _obj;
if (g_object_get_data( tbl, "freeze" )) {
return;
}
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) );
GtkAdjustment * adj = GTK_ADJUSTMENT(g_object_get_data(tbl, "tolerance"));
double v = val.getDouble(adj->value);
gtk_adjustment_set_value(adj, v);
g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) );
}
private:
GObject *_obj;
};
*/
void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder)
{
sp_add_freehand_mode_toggle(mainActions, holder, true);
EgeAdjustmentAction* eact = 0;
/* Tolerance */
{
gchar const* labels[] = {_("(many nodes, rough)"), _("(default)"), 0, 0, 0, 0, _("(few nodes, smooth)")};
gdouble values[] = {1, 10, 20, 30, 50, 75, 100};
eact = create_adjustment_action( "PencilToleranceAction",
_("Smoothing:"), _("Smoothing: "),
_("How much smoothing (simplifying) is applied to the line"),
"/tools/freehand/pencil/tolerance",
3.0,
GTK_WIDGET(desktop->canvas),
holder, TRUE, "altx-pencil",
1, 100.0, 0.5, 1.0,
labels, values, G_N_ELEMENTS(labels),
sp_pencil_tb_tolerance_value_changed,
NULL /*unit tracker*/,
1, 2);
ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT );
gtk_action_group_add_action( mainActions, GTK_ACTION(eact) );
}
/* advanced shape options */
freehand_add_advanced_shape_options(mainActions, holder, true);
/* Reset */
{
InkAction* inky = ink_action_new( "PencilResetAction",
_("Defaults"),
_("Reset pencil parameters to defaults (use Inkscape Preferences > Tools to change defaults)"),
INKSCAPE_ICON("edit-clear"),
Inkscape::ICON_SIZE_SMALL_TOOLBAR );
g_signal_connect_after( G_OBJECT(inky), "activate", G_CALLBACK(sp_pencil_tb_defaults), holder );
gtk_action_group_add_action( mainActions, GTK_ACTION(inky) );
}
g_signal_connect( holder, "destroy", G_CALLBACK(purge_repr_listener), holder );
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
|