Code

Make curvature work again by fixing a minor omission
[inkscape.git] / src / tools-switch.cpp
1 /*
2  * Utility functions for switching tools (= contexts)
3  *
4  * Authors:
5  *   bulia byak <buliabyak@users.sf.net>
6  *   Josh Andler <scislac@users.sf.net>
7  *
8  * Copyright (C) 2003-2007 authors
9  *
10  * Released under GNU GPL, read the file 'COPYING' for more information
11  */
14 #ifdef HAVE_CONFIG_H
15 # include "config.h"
16 #endif
18 #include <cstring>
19 #include <string>
21 #include "inkscape-private.h"
22 #include "desktop.h"
23 #include "desktop-handles.h"
24 #include <glibmm/i18n.h>
26 #include <xml/repr.h>
28 #include "select-context.h"
29 #include "node-context.h"
30 #include "tweak-context.h"
31 #include "spray-context.h"
32 #include "sp-path.h"
33 #include "rect-context.h"
34 #include "sp-rect.h"
35 #include "box3d-context.h"
36 #include "box3d.h"
37 #include "arc-context.h"
38 #include "sp-ellipse.h"
39 #include "star-context.h"
40 #include "sp-star.h"
41 #include "spiral-context.h"
42 #include "sp-spiral.h"
43 #include "dyna-draw-context.h"
44 #include "eraser-context.h"
45 #include "pen-context.h"
46 #include "pencil-context.h"
47 #include "lpe-tool-context.h"
48 #include "text-context.h"
49 #include "sp-text.h"
50 #include "sp-flowtext.h"
51 #include "gradient-context.h"
52 #include "zoom-context.h"
53 #include "dropper-context.h"
54 #include "connector-context.h"
55 #include "flood-context.h"
56 #include "sp-offset.h"
57 #include "message-context.h"
59 #include "tools-switch.h"
61 static char const *const tool_names[] = {
62     NULL,
63     "/tools/select",
64     "/tools/nodes",
65     "/tools/tweak",
66     "/tools/spray",
67     "/tools/shapes/rect",
68     "/tools/shapes/3dbox",
69     "/tools/shapes/arc",
70     "/tools/shapes/star",
71     "/tools/shapes/spiral",
72     "/tools/freehand/pencil",
73     "/tools/freehand/pen",
74     "/tools/calligraphic",
75     "/tools/text",
76     "/tools/gradient",
77     "/tools/zoom",
78     "/tools/dropper",
79     "/tools/connector",
80     "/tools/paintbucket",
81     "/tools/eraser",
82     "/tools/lpetool",
83     NULL
84 };
86 static int
87 tools_prefpath2num(char const *id)
88 {
89     int i = 1;
90     while (tool_names[i]) {
91         if (strcmp(tool_names[i], id) == 0)
92             return i;
93         else i++;
94     }
95     g_assert( 0 == TOOLS_INVALID );
96     return 0; //nothing found
97 }
99 int
100 tools_isactive(SPDesktop *dt, unsigned num)
102     g_assert( num < G_N_ELEMENTS(tool_names) );
103     if (SP_IS_EVENT_CONTEXT(dt->event_context))
104         return dt->event_context->pref_observer->observed_path == tool_names[num];
105     else return FALSE;
108 int
109 tools_active(SPDesktop *dt)
111     return tools_prefpath2num(dt->event_context->pref_observer->observed_path.data());
114 void
115 tools_switch(SPDesktop *dt, int num)
117     if (dt) {
118         dt->_tool_changed.emit(num);
119     }
121     switch (num) {
122         case TOOLS_SELECT:
123             dt->set_event_context(SP_TYPE_SELECT_CONTEXT, tool_names[num]);
124             /* fixme: This is really ugly hack. We should bind and unbind class methods */
125             dt->activate_guides(true);
126             inkscape_eventcontext_set(sp_desktop_event_context(dt));
127             break;
128         case TOOLS_NODES:
129             dt->set_event_context(SP_TYPE_NODE_CONTEXT, tool_names[num]);
130             dt->activate_guides(true);
131             inkscape_eventcontext_set(sp_desktop_event_context(dt));
132             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             break;
134         case TOOLS_TWEAK:
135             dt->set_event_context(SP_TYPE_TWEAK_CONTEXT, tool_names[num]);
136             dt->activate_guides(true);
137             inkscape_eventcontext_set(sp_desktop_event_context(dt));
138             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("To tweak a path by pushing, select it and drag over it."));
139             break;
140         case TOOLS_SPRAY:
141             dt->set_event_context(SP_TYPE_SPRAY_CONTEXT, tool_names[num]);
142             dt->activate_guides(true);
143             inkscape_eventcontext_set(sp_desktop_event_context(dt));
144             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("To spray a path by pushing, select it and drag over it."));
145             break;
146         case TOOLS_SHAPES_RECT:
147             dt->set_event_context(SP_TYPE_RECT_CONTEXT, tool_names[num]);
148             dt->activate_guides(false);
149             inkscape_eventcontext_set(sp_desktop_event_context(dt));
150             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."));
151             break;
152         case TOOLS_SHAPES_3DBOX:
153             dt->set_event_context(SP_TYPE_BOX3D_CONTEXT, tool_names[num]);
154             dt->activate_guides(false);
155             inkscape_eventcontext_set(sp_desktop_event_context(dt));
156             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)."));
157             break;
158         case TOOLS_SHAPES_ARC:
159             dt->set_event_context(SP_TYPE_ARC_CONTEXT, tool_names[num]);
160             dt->activate_guides(false);
161             inkscape_eventcontext_set(sp_desktop_event_context(dt));
162             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."));
163             break;
164         case TOOLS_SHAPES_STAR:
165             dt->set_event_context(SP_TYPE_STAR_CONTEXT, tool_names[num]);
166             dt->activate_guides(false);
167             inkscape_eventcontext_set(sp_desktop_event_context(dt));
168             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."));
169             break;
170         case TOOLS_SHAPES_SPIRAL:
171             dt->set_event_context(SP_TYPE_SPIRAL_CONTEXT, tool_names[num]);
172             dt->activate_guides(false);
173             inkscape_eventcontext_set(sp_desktop_event_context(dt));
174             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."));
175             break;
176         case TOOLS_FREEHAND_PENCIL:
177             dt->set_event_context(SP_TYPE_PENCIL_CONTEXT, tool_names[num]);
178             dt->activate_guides(false);
179             inkscape_eventcontext_set(sp_desktop_event_context(dt));
180             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."));
181             break;
182         case TOOLS_FREEHAND_PEN:
183             dt->set_event_context(SP_TYPE_PEN_CONTEXT, tool_names[num]);
184             dt->activate_guides(false);
185             inkscape_eventcontext_set(sp_desktop_event_context(dt));
186             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)."));
187             break;
188         case TOOLS_CALLIGRAPHIC:
189             dt->set_event_context(SP_TYPE_DYNA_DRAW_CONTEXT, tool_names[num]);
190             dt->activate_guides(false);
191             inkscape_eventcontext_set(sp_desktop_event_context(dt));
192             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)."));
193             break;
194         case TOOLS_TEXT:
195             dt->set_event_context(SP_TYPE_TEXT_CONTEXT, tool_names[num]);
196             dt->activate_guides(false);
197             inkscape_eventcontext_set(sp_desktop_event_context(dt));
198             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click</b> to select or create text, <b>drag</b> to create flowed text; then type."));
199             break;
200         case TOOLS_GRADIENT:
201             dt->set_event_context(SP_TYPE_GRADIENT_CONTEXT, tool_names[num]);
202             dt->activate_guides(false);
203             inkscape_eventcontext_set(sp_desktop_event_context(dt));
204             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."));
205             break;
206         case TOOLS_ZOOM:
207             dt->set_event_context(SP_TYPE_ZOOM_CONTEXT, tool_names[num]);
208             dt->activate_guides(false);
209             inkscape_eventcontext_set(sp_desktop_event_context(dt));
210             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."));
211             break;
212         case TOOLS_DROPPER:
213             dt->set_event_context(SP_TYPE_DROPPER_CONTEXT, tool_names[num]);
214             dt->activate_guides(false);
215             inkscape_eventcontext_set(sp_desktop_event_context(dt));
216             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"));
217             break;
218         case TOOLS_CONNECTOR:
219             dt->set_event_context(SP_TYPE_CONNECTOR_CONTEXT, tool_names[num]);
220             dt->activate_guides(false);
221             inkscape_eventcontext_set(sp_desktop_event_context(dt));
222             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Click and drag</b> between shapes to create a connector."));
223             break;
224         case TOOLS_PAINTBUCKET:
225             dt->set_event_context(SP_TYPE_FLOOD_CONTEXT, tool_names[num]);
226             dt->activate_guides(false);
227             inkscape_eventcontext_set(sp_desktop_event_context(dt));
228             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."));
229             break;
230         case TOOLS_ERASER:
231             dt->set_event_context(SP_TYPE_ERASER_CONTEXT, tool_names[num]);
232             dt->activate_guides(false);
233             inkscape_eventcontext_set(sp_desktop_event_context(dt));
234             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("<b>Drag</b> to erase."));
235             break;
236         case TOOLS_LPETOOL:
237             dt->set_event_context(SP_TYPE_LPETOOL_CONTEXT, tool_names[num]);
238             dt->activate_guides(false);
239             inkscape_eventcontext_set(sp_desktop_event_context(dt));
240             dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Choose a subtool from the toolbar"));
241             break;
242     }
245 void tools_switch_by_item(SPDesktop *dt, SPItem *item, Geom::Point const p)
247     if (SP_IS_RECT(item)) {
248         tools_switch(dt, TOOLS_SHAPES_RECT);
249     } else if (SP_IS_BOX3D(item)) {
250         tools_switch(dt, TOOLS_SHAPES_3DBOX);
251     } else if (SP_IS_GENERICELLIPSE(item)) {
252         tools_switch(dt, TOOLS_SHAPES_ARC);
253     } else if (SP_IS_STAR(item)) {
254         tools_switch(dt, TOOLS_SHAPES_STAR);
255     } else if (SP_IS_SPIRAL(item)) {
256         tools_switch(dt, TOOLS_SHAPES_SPIRAL);
257     } else if (SP_IS_PATH(item)) {
258         if (cc_item_is_connector(item)) {
259             tools_switch(dt, TOOLS_CONNECTOR);
260         }
261         else {
262             tools_switch(dt, TOOLS_NODES);
263         }
264     } else if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item))  {
265         tools_switch(dt, TOOLS_TEXT);
266         sp_text_context_place_cursor_at (SP_TEXT_CONTEXT(dt->event_context), SP_OBJECT(item), p);
267     } else if (SP_IS_OFFSET(item))  {
268         tools_switch(dt, TOOLS_NODES);
269     }
272 /*
273   Local Variables:
274   mode:c++
275   c-file-style:"stroustrup"
276   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
277   indent-tabs-mode:nil
278   fill-column:99
279   End:
280 */
281 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :