X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Ftools-switch.cpp;h=7902a79883f9da6e6231c7adfac3056ac54d79eb;hb=db689a0b475438503100fa8650367fd327c2d4f7;hp=d42354e8dae86083fc4e7cca0ebeafe84a02c1b2;hpb=6129af7cc5b723223e9617614c931936e5190421;p=inkscape.git diff --git a/src/tools-switch.cpp b/src/tools-switch.cpp index d42354e8d..7902a7988 100644 --- a/src/tools-switch.cpp +++ b/src/tools-switch.cpp @@ -2,9 +2,10 @@ * Utility functions for switching tools (= contexts) * * Authors: - * bulia byak + * bulia byak + * Josh Andler * - * Copyright (C) 2003 authors + * Copyright (C) 2003-2007 authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -14,6 +15,9 @@ # include "config.h" #endif +#include +#include + #include "inkscape-private.h" #include "desktop.h" #include "desktop-handles.h" @@ -23,9 +27,12 @@ #include "select-context.h" #include "node-context.h" +#include "tweak-context.h" #include "sp-path.h" #include "rect-context.h" #include "sp-rect.h" +#include "box3d-context.h" +#include "box3d.h" #include "arc-context.h" #include "sp-ellipse.h" #include "star-context.h" @@ -33,8 +40,10 @@ #include "spiral-context.h" #include "sp-spiral.h" #include "dyna-draw-context.h" +#include "eraser-context.h" #include "pen-context.h" #include "pencil-context.h" +#include "lpe-tool-context.h" #include "text-context.h" #include "sp-text.h" #include "sp-flowtext.h" @@ -42,54 +51,42 @@ #include "zoom-context.h" #include "dropper-context.h" #include "connector-context.h" +#include "flood-context.h" +#include "sp-offset.h" #include "message-context.h" #include "tools-switch.h" static char const *const tool_names[] = { NULL, - "tools.select", - "tools.nodes", - "tools.shapes.rect", - "tools.shapes.arc", - "tools.shapes.star", - "tools.shapes.spiral", - "tools.freehand.pencil", - "tools.freehand.pen", - "tools.calligraphic", - "tools.text", - "tools.gradient", - "tools.zoom", - "tools.dropper", - "tools.connector", - NULL -}; - -static char const *const tool_ids[] = { - NULL, - "select", - "nodes", - "rect", - "arc", - "star", - "spiral", - "pencil", - "pen", - "calligraphic", - "text", - "gradient", - "zoom", - "dropper", - "connector", + "/tools/select", + "/tools/nodes", + "/tools/tweak", + "/tools/shapes/rect", + "/tools/shapes/3dbox", + "/tools/shapes/arc", + "/tools/shapes/star", + "/tools/shapes/spiral", + "/tools/freehand/pencil", + "/tools/freehand/pen", + "/tools/calligraphic", + "/tools/text", + "/tools/gradient", + "/tools/zoom", + "/tools/dropper", + "/tools/connector", + "/tools/paintbucket", + "/tools/eraser", + "/tools/lpetool", NULL }; static int -tools_id2num(char const *id) +tools_prefpath2num(char const *id) { int i = 1; - while (tool_ids[i]) { - if (strcmp(tool_ids[i], id) == 0) + while (tool_names[i]) { + if (strcmp(tool_names[i], id) == 0) return i; else i++; } @@ -100,16 +97,16 @@ tools_id2num(char const *id) int tools_isactive(SPDesktop *dt, unsigned num) { - g_assert( num < G_N_ELEMENTS(tool_ids) ); + g_assert( num < G_N_ELEMENTS(tool_names) ); if (SP_IS_EVENT_CONTEXT(dt->event_context)) - return (!strcmp(dt->event_context->prefs_repr->attribute("id"), tool_ids[num])); + return dt->event_context->pref_observer->observed_path == tool_names[num]; else return FALSE; } int tools_active(SPDesktop *dt) { - return (tools_id2num(dt->event_context->prefs_repr->attribute("id"))); + return tools_prefpath2num(dt->event_context->pref_observer->observed_path.data()); } void @@ -132,12 +129,24 @@ tools_switch(SPDesktop *dt, int num) inkscape_eventcontext_set(sp_desktop_event_context(dt)); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("To edit a path, click, Shift+click, or drag around nodes to select them, then drag nodes and handles. Click on an object to select.")); break; + case TOOLS_TWEAK: + dt->set_event_context(SP_TYPE_TWEAK_CONTEXT, tool_names[num]); + dt->activate_guides(true); + inkscape_eventcontext_set(sp_desktop_event_context(dt)); + dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("To tweak a path by pushing, select it and drag over it.")); + break; case TOOLS_SHAPES_RECT: dt->set_event_context(SP_TYPE_RECT_CONTEXT, tool_names[num]); dt->activate_guides(false); inkscape_eventcontext_set(sp_desktop_event_context(dt)); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Drag to create a rectangle. Drag controls to round corners and resize. Click to select.")); break; + case TOOLS_SHAPES_3DBOX: + dt->set_event_context(SP_TYPE_BOX3D_CONTEXT, tool_names[num]); + dt->activate_guides(false); + inkscape_eventcontext_set(sp_desktop_event_context(dt)); + dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Drag to create a 3D box. Drag controls to resize in perspective. Click to select (with Ctrl+Alt for single faces).")); + break; case TOOLS_SHAPES_ARC: dt->set_event_context(SP_TYPE_ARC_CONTEXT, tool_names[num]); dt->activate_guides(false); @@ -160,19 +169,19 @@ tools_switch(SPDesktop *dt, int num) dt->set_event_context(SP_TYPE_PENCIL_CONTEXT, tool_names[num]); dt->activate_guides(false); inkscape_eventcontext_set(sp_desktop_event_context(dt)); - dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Drag to create a freehand line. Start drawing with Shift to append to selected path.")); + dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Drag to create a freehand line. Shift appends to selected path, Alt activates sketch mode.")); break; case TOOLS_FREEHAND_PEN: dt->set_event_context(SP_TYPE_PEN_CONTEXT, tool_names[num]); dt->activate_guides(false); inkscape_eventcontext_set(sp_desktop_event_context(dt)); - dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Click or click and drag to start a path; with Shift to append to selected path.")); + dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Click or click and drag to start a path; with Shift to append to selected path. Ctrl+click to create single dots (straight line modes only).")); break; case TOOLS_CALLIGRAPHIC: dt->set_event_context(SP_TYPE_DYNA_DRAW_CONTEXT, tool_names[num]); dt->activate_guides(false); inkscape_eventcontext_set(sp_desktop_event_context(dt)); - dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Drag to paint a calligraphic stroke. Left/right arrow keys adjust width, up/down adjust angle.")); + dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Drag to draw a calligraphic stroke; with Ctrl to track a guide path. Arrow keys adjust width (left/right) and angle (up/down).")); break; case TOOLS_TEXT: dt->set_event_context(SP_TYPE_TEXT_CONTEXT, tool_names[num]); @@ -204,20 +213,33 @@ tools_switch(SPDesktop *dt, int num) inkscape_eventcontext_set(sp_desktop_event_context(dt)); dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Click and drag between shapes to create a connector.")); break; + case TOOLS_PAINTBUCKET: + dt->set_event_context(SP_TYPE_FLOOD_CONTEXT, tool_names[num]); + dt->activate_guides(false); + inkscape_eventcontext_set(sp_desktop_event_context(dt)); + dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Click to paint a bounded area, Shift+click to union the new fill with the current selection, Ctrl+click to change the clicked object's fill and stroke to the current setting.")); + break; + case TOOLS_ERASER: + dt->set_event_context(SP_TYPE_ERASER_CONTEXT, tool_names[num]); + dt->activate_guides(false); + inkscape_eventcontext_set(sp_desktop_event_context(dt)); + dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Drag to erase.")); + break; + case TOOLS_LPETOOL: + dt->set_event_context(SP_TYPE_LPETOOL_CONTEXT, tool_names[num]); + dt->activate_guides(false); + inkscape_eventcontext_set(sp_desktop_event_context(dt)); + dt->tipsMessageContext()->set(Inkscape::NORMAL_MESSAGE, _("Choose a subtool from the toolbar")); + break; } } -void -tools_switch_current(int num) -{ - SPDesktop *dt = SP_ACTIVE_DESKTOP; - if (dt) tools_switch(dt, num); -} - -void tools_switch_by_item(SPDesktop *dt, SPItem *item) +void tools_switch_by_item(SPDesktop *dt, SPItem *item, Geom::Point const p) { if (SP_IS_RECT(item)) { tools_switch(dt, TOOLS_SHAPES_RECT); + } else if (SP_IS_BOX3D(item)) { + tools_switch(dt, TOOLS_SHAPES_3DBOX); } else if (SP_IS_GENERICELLIPSE(item)) { tools_switch(dt, TOOLS_SHAPES_ARC); } else if (SP_IS_STAR(item)) { @@ -233,6 +255,9 @@ void tools_switch_by_item(SPDesktop *dt, SPItem *item) } } else if (SP_IS_TEXT(item) || SP_IS_FLOWTEXT(item)) { tools_switch(dt, TOOLS_TEXT); + sp_text_context_place_cursor_at (SP_TEXT_CONTEXT(dt->event_context), SP_OBJECT(item), p); + } else if (SP_IS_OFFSET(item)) { + tools_switch(dt, TOOLS_NODES); } }