2
* Utility functions for switching tools (= contexts)
5
* bulia byak <buliabyak@users.sf.net>
6
* Josh Andler <scislac@users.sf.net>
8
* Copyright (C) 2003-2007 authors
10
* Released under GNU GPL, read the file 'COPYING' for more information
21
#include "inkscape-private.h"
23
#include "desktop-handles.h"
24
#include <glibmm/i18n.h>
28
#include "select-context.h"
29
#include "node-context.h"
30
#include "tweak-context.h"
32
#include "rect-context.h"
34
#include "box3d-context.h"
36
#include "arc-context.h"
37
#include "sp-ellipse.h"
38
#include "star-context.h"
40
#include "spiral-context.h"
41
#include "sp-spiral.h"
42
#include "dyna-draw-context.h"
43
#include "eraser-context.h"
44
#include "pen-context.h"
45
#include "pencil-context.h"
46
#include "lpe-tool-context.h"
47
#include "text-context.h"
49
#include "sp-flowtext.h"
50
#include "gradient-context.h"
51
#include "zoom-context.h"
52
#include "dropper-context.h"
53
#include "connector-context.h"
54
#include "flood-context.h"
55
#include "sp-offset.h"
56
#include "message-context.h"
58
#include "tools-switch.h"
60
static char const *const tool_names[] = {
66
"/tools/shapes/3dbox",
69
"/tools/shapes/spiral",
70
"/tools/freehand/pencil",
71
"/tools/freehand/pen",
72
"/tools/calligraphic",
85
tools_prefpath2num(char const *id)
88
while (tool_names[i]) {
89
if (strcmp(tool_names[i], id) == 0)
93
g_assert( 0 == TOOLS_INVALID );
94
return 0; //nothing found
98
tools_isactive(SPDesktop *dt, unsigned num)
100
g_assert( num < G_N_ELEMENTS(tool_names) );
101
if (SP_IS_EVENT_CONTEXT(dt->event_context))
102
return dt->event_context->pref_observer->observed_path == tool_names[num];
107
tools_active(SPDesktop *dt)
109
return tools_prefpath2num(dt->event_context->pref_observer->observed_path.data());
113
tools_switch(SPDesktop *dt, int num)
116
dt->_tool_changed.emit(num);
121
dt->set_event_context(SP_TYPE_SELECT_CONTEXT, tool_names[num]);
122
/* fixme: This is really ugly hack. We should bind and unbind class methods */
123
dt->activate_guides(true);
124
inkscape_eventcontext_set(sp_desktop_event_context(dt));
127
dt->set_event_context(SP_TYPE_NODE_CONTEXT, tool_names[num]);
128
dt->activate_guides(true);
129
inkscape_eventcontext_set(sp_desktop_event_context(dt));
130
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("To edit a path, <b>click</b>, <b>Shift+click</b>, or <b>drag around</b> nodes to select them, then <b>drag</b> nodes and handles. <b>Click</b> on an object to select."));
133
dt->set_event_context(SP_TYPE_TWEAK_CONTEXT, tool_names[num]);
134
dt->activate_guides(true);
135
inkscape_eventcontext_set(sp_desktop_event_context(dt));
136
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("To tweak a path by pushing, select it and drag over it."));
138
case TOOLS_SHAPES_RECT:
139
dt->set_event_context(SP_TYPE_RECT_CONTEXT, tool_names[num]);
140
dt->activate_guides(false);
141
inkscape_eventcontext_set(sp_desktop_event_context(dt));
142
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create a rectangle. <b>Drag controls</b> to round corners and resize. <b>Click</b> to select."));
144
case TOOLS_SHAPES_3DBOX:
145
dt->set_event_context(SP_TYPE_BOX3D_CONTEXT, tool_names[num]);
146
dt->activate_guides(false);
147
inkscape_eventcontext_set(sp_desktop_event_context(dt));
148
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create a 3D box. <b>Drag controls</b> to resize in perspective. <b>Click</b> to select (with <b>Ctrl+Alt</b> for single faces)."));
150
case TOOLS_SHAPES_ARC:
151
dt->set_event_context(SP_TYPE_ARC_CONTEXT, tool_names[num]);
152
dt->activate_guides(false);
153
inkscape_eventcontext_set(sp_desktop_event_context(dt));
154
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create an ellipse. <b>Drag controls</b> to make an arc or segment. <b>Click</b> to select."));
156
case TOOLS_SHAPES_STAR:
157
dt->set_event_context(SP_TYPE_STAR_CONTEXT, tool_names[num]);
158
dt->activate_guides(false);
159
inkscape_eventcontext_set(sp_desktop_event_context(dt));
160
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create a star. <b>Drag controls</b> to edit the star shape. <b>Click</b> to select."));
162
case TOOLS_SHAPES_SPIRAL:
163
dt->set_event_context(SP_TYPE_SPIRAL_CONTEXT, tool_names[num]);
164
dt->activate_guides(false);
165
inkscape_eventcontext_set(sp_desktop_event_context(dt));
166
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create a spiral. <b>Drag controls</b> to edit the spiral shape. <b>Click</b> to select."));
168
case TOOLS_FREEHAND_PENCIL:
169
dt->set_event_context(SP_TYPE_PENCIL_CONTEXT, tool_names[num]);
170
dt->activate_guides(false);
171
inkscape_eventcontext_set(sp_desktop_event_context(dt));
172
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to create a freehand line. <b>Shift</b> appends to selected path, <b>Alt</b> activates sketch mode."));
174
case TOOLS_FREEHAND_PEN:
175
dt->set_event_context(SP_TYPE_PEN_CONTEXT, tool_names[num]);
176
dt->activate_guides(false);
177
inkscape_eventcontext_set(sp_desktop_event_context(dt));
178
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>click and drag</b> to start a path; with <b>Shift</b> to append to selected path. <b>Ctrl+click</b> to create single dots (straight line modes only)."));
180
case TOOLS_CALLIGRAPHIC:
181
dt->set_event_context(SP_TYPE_DYNA_DRAW_CONTEXT, tool_names[num]);
182
dt->activate_guides(false);
183
inkscape_eventcontext_set(sp_desktop_event_context(dt));
184
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to draw a calligraphic stroke; with <b>Ctrl</b> to track a guide path. <b>Arrow keys</b> adjust width (left/right) and angle (up/down)."));
187
dt->set_event_context(SP_TYPE_TEXT_CONTEXT, tool_names[num]);
188
dt->activate_guides(false);
189
inkscape_eventcontext_set(sp_desktop_event_context(dt));
190
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> to select or create text, <b>drag</b> to create flowed text; then type."));
193
dt->set_event_context(SP_TYPE_GRADIENT_CONTEXT, tool_names[num]);
194
dt->activate_guides(false);
195
inkscape_eventcontext_set(sp_desktop_event_context(dt));
196
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> or <b>double click</b> to create a gradient on selected objects, <b>drag handles</b> to adjust gradients."));
199
dt->set_event_context(SP_TYPE_ZOOM_CONTEXT, tool_names[num]);
200
dt->activate_guides(false);
201
inkscape_eventcontext_set(sp_desktop_event_context(dt));
202
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> or <b>drag around an area</b> to zoom in, <b>Shift+click</b> to zoom out."));
205
dt->set_event_context(SP_TYPE_DROPPER_CONTEXT, tool_names[num]);
206
dt->activate_guides(false);
207
inkscape_eventcontext_set(sp_desktop_event_context(dt));
208
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> to set fill, <b>Shift+click</b> to set stroke; <b>drag</b> to average color in area; with <b>Alt</b> to pick inverse color; <b>Ctrl+C</b> to copy the color under mouse to clipboard"));
210
case TOOLS_CONNECTOR:
211
dt->set_event_context(SP_TYPE_CONNECTOR_CONTEXT, tool_names[num]);
212
dt->activate_guides(false);
213
inkscape_eventcontext_set(sp_desktop_event_context(dt));
214
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click and drag</b> between shapes to create a connector."));
216
case TOOLS_PAINTBUCKET:
217
dt->set_event_context(SP_TYPE_FLOOD_CONTEXT, tool_names[num]);
218
dt->activate_guides(false);
219
inkscape_eventcontext_set(sp_desktop_event_context(dt));
220
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> to paint a bounded area, <b>Shift+click</b> to union the new fill with the current selection, <b>Ctrl+click</b> to change the clicked object's fill and stroke to the current setting."));
223
dt->set_event_context(SP_TYPE_ERASER_CONTEXT, tool_names[num]);
224
dt->activate_guides(false);
225
inkscape_eventcontext_set(sp_desktop_event_context(dt));
226
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to erase."));
229
dt->set_event_context(SP_TYPE_LPETOOL_CONTEXT, tool_names[num]);
230
dt->activate_guides(false);
231
inkscape_eventcontext_set(sp_desktop_event_context(dt));
232
dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Choose a subtool from the toolbar"));
237
void tools_switch_by_item(SPDesktop *dt, SPItem *item, Geom::Point const p)
239
if (SP_IS_RECT(item)) {
240
tools_switch(dt, TOOLS_SHAPES_RECT);
241
} else if (SP_IS_BOX3D(item)) {
242
tools_switch(dt, TOOLS_SHAPES_3DBOX);
243
} else if (SP_IS_GENERICELLIPSE(item)) {
244
tools_switch(dt, TOOLS_SHAPES_ARC);
245
} else if (SP_IS_STAR(item)) {
246
tools_switch(dt, TOOLS_SHAPES_STAR);
247
} else if (SP_IS_SPIRAL(item)) {
248
tools_switch(dt, TOOLS_SHAPES_SPIRAL);
249
} else if (SP_IS_PATH(item)) {
250
if (cc_item_is_connector(item)) {
251
tools_switch(dt, TOOLS_CONNECTOR);
254
tools_switch(dt, TOOLS_NODES);
256
} else if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) {
257
tools_switch(dt, TOOLS_TEXT);
258
sp_text_context_place_cursor_at (SP_TEXT_CONTEXT(dt->event_context), SP_OBJECT(item), p);
259
} else if (SP_IS_OFFSET(item)) {
260
tools_switch(dt, TOOLS_NODES);
267
c-file-style:"stroustrup"
268
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
273
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :