From: joncruz Date: Sat, 26 Apr 2008 09:07:28 +0000 (+0000) Subject: Initial cut of eraser tool X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b26cc655b98659f4a33794ee9169b67d908b824b;hp=f487c6e531d14d8dc217d746b7576b064dc3a44d;p=inkscape.git Initial cut of eraser tool --- diff --git a/share/icons/icons.svg b/share/icons/icons.svg index 566796c2a..c743768ac 100644 --- a/share/icons/icons.svg +++ b/share/icons/icons.svg @@ -4765,21 +4765,52 @@ offset="1" id="stop7700" /> + + + + + + transform="translate(94.91614,59)" id="rect10884" /> + + + + + width="1250" height="1250" /> + + + + + + + diff --git a/src/Makefile_insert b/src/Makefile_insert index c4f196dd5..48201344e 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -72,6 +72,7 @@ libinkpre_a_SOURCES = \ dropper-context.cpp dropper-context.h \ dyna-draw-context.cpp dyna-draw-context.h \ enums.h \ + eraser-context.cpp eraser-context.h \ event-context.cpp event-context.h \ event-log.cpp event-log.h event.h \ extract-uri.cpp extract-uri.h \ diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h index f60101b4c..939be9a82 100644 --- a/src/preferences-skeleton.h +++ b/src/preferences-skeleton.h @@ -80,6 +80,10 @@ static char const preferences_skeleton[] = " \n" " \n" " \n" +" \n" +" \n" " \n" diff --git a/src/tools-switch.cpp b/src/tools-switch.cpp index 11e3ff5b4..e32d8d13d 100644 --- a/src/tools-switch.cpp +++ b/src/tools-switch.cpp @@ -40,6 +40,7 @@ #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 "text-context.h" @@ -74,6 +75,7 @@ static char const *const tool_names[] = { "tools.dropper", "tools.connector", "tools.paintbucket", + "tools.eraser", NULL }; @@ -96,6 +98,7 @@ static char const *const tool_ids[] = { "dropper", "connector", "paintbucket", + "eraser", NULL }; @@ -237,6 +240,12 @@ tools_switch(SPDesktop *dt, int num) 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; } } diff --git a/src/tools-switch.h b/src/tools-switch.h index 8107984a8..f5a3220ca 100644 --- a/src/tools-switch.h +++ b/src/tools-switch.h @@ -32,7 +32,8 @@ enum { TOOLS_ZOOM, TOOLS_DROPPER, TOOLS_CONNECTOR, - TOOLS_PAINTBUCKET + TOOLS_PAINTBUCKET, + TOOLS_ERASER }; int tools_isactive(SPDesktop *dt, unsigned num); diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index fbcdc665b..6660e6273 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -449,6 +449,8 @@ void InkscapePreferences::initPageTools() this->AddPage(_page_paintbucket, _("Paint Bucket"), iter_tools, PREFS_PAGE_TOOLS_PAINTBUCKET); this->AddSelcueCheckbox(_page_paintbucket, "tools.paintbucket", false); this->AddNewObjectsStyle(_page_paintbucket, "tools.paintbucket"); + //Calligraphy + this->AddPage(_page_eraser, _("Eraser"), iter_tools, PREFS_PAGE_TOOLS_ERASER); //Text this->AddPage(_page_text, _("Text"), iter_tools, PREFS_PAGE_TOOLS_TEXT); this->AddSelcueCheckbox(_page_text, "tools.text", true); diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index 6e8b6d000..a1a577b95 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -54,6 +54,7 @@ enum { PREFS_PAGE_TOOLS_PEN, PREFS_PAGE_TOOLS_CALLIGRAPHY, PREFS_PAGE_TOOLS_PAINTBUCKET, + PREFS_PAGE_TOOLS_ERASER, PREFS_PAGE_TOOLS_TEXT, PREFS_PAGE_TOOLS_GRADIENT, PREFS_PAGE_TOOLS_CONNECTOR, @@ -108,7 +109,7 @@ protected: _page_importexport, _page_cms, _page_grids, _page_misc; DialogPage _page_selector, _page_node, _page_tweak, _page_zoom, _page_shapes, _page_pencil, _page_pen, _page_calligraphy, _page_text, _page_gradient, _page_connector, _page_dropper; - DialogPage _page_rectangle, _page_3dbox, _page_ellipse, _page_star, _page_spiral, _page_paintbucket; + DialogPage _page_rectangle, _page_3dbox, _page_ellipse, _page_star, _page_spiral, _page_paintbucket, _page_eraser; PrefSpinButton _mouse_sens, _mouse_thres; PrefCheckButton _mouse_use_ext_input; diff --git a/src/verbs.cpp b/src/verbs.cpp index 1068472bd..60982e036 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -1443,6 +1443,9 @@ ContextVerb::perform(SPAction *action, void *data, void */*pdata*/) case SP_VERB_CONTEXT_PAINTBUCKET: tools_switch_current(TOOLS_PAINTBUCKET); break; + case SP_VERB_CONTEXT_ERASER: + tools_switch_current(TOOLS_ERASER); + break; case SP_VERB_CONTEXT_SELECT_PREFS: prefs_set_int_attribute("dialogs.preferences", "page", PREFS_PAGE_TOOLS_SELECTOR); @@ -1512,6 +1515,10 @@ ContextVerb::perform(SPAction *action, void *data, void */*pdata*/) prefs_set_int_attribute ("dialogs.preferences", "page", PREFS_PAGE_TOOLS_PAINTBUCKET); dt->_dlg_mgr->showDialog("InkscapePreferences"); break; + case SP_VERB_CONTEXT_ERASER_PREFS: + prefs_set_int_attribute("dialogs.preferences", "page", PREFS_PAGE_TOOLS_ERASER); + dt->_dlg_mgr->showDialog("InkscapePreferences"); + break; default: break; @@ -2436,6 +2443,8 @@ Verb *Verb::_base_verbs[] = { N_("Fill bounded areas"), "draw_paintbucket"), new ContextVerb(SP_VERB_CONTEXT_LPE, "ToolLPE", N_("LPE Edit"), N_("Edit Live Path Effect parameters"), "draw_lpe"), + new ContextVerb(SP_VERB_CONTEXT_ERASER, "ToolEraser", N_("Eraser"), + N_("Erase existing paths"), "draw_erase"), /* Tool prefs */ new ContextVerb(SP_VERB_CONTEXT_SELECT_PREFS, "SelectPrefs", N_("Selector Preferences"), N_("Open Preferences for the Selector tool"), NULL), @@ -2471,6 +2480,8 @@ Verb *Verb::_base_verbs[] = { N_("Open Preferences for the Connector tool"), NULL), new ContextVerb(SP_VERB_CONTEXT_PAINTBUCKET_PREFS, "PaintBucketPrefs", N_("Paint Bucket Preferences"), N_("Open Preferences for the Paint Bucket tool"), NULL), + new ContextVerb(SP_VERB_CONTEXT_ERASER_PREFS, "EraserPrefs", N_("Eraser Preferences"), + N_("Open Preferences for the Eraser tool"), NULL), /* Zoom/View */ new ZoomVerb(SP_VERB_ZOOM_IN, "ZoomIn", N_("Zoom In"), N_("Zoom in"), "zoom_in"), diff --git a/src/verbs.h b/src/verbs.h index 0a1826580..605cc732b 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -163,6 +163,7 @@ enum { SP_VERB_CONTEXT_CONNECTOR, SP_VERB_CONTEXT_PAINTBUCKET, SP_VERB_CONTEXT_LPE, /* not really a tool but used for editing LPE parameters on-canvas for example */ + SP_VERB_CONTEXT_ERASER, /* Tool preferences */ SP_VERB_CONTEXT_SELECT_PREFS, SP_VERB_CONTEXT_NODE_PREFS, @@ -181,6 +182,7 @@ enum { SP_VERB_CONTEXT_DROPPER_PREFS, SP_VERB_CONTEXT_CONNECTOR_PREFS, SP_VERB_CONTEXT_PAINTBUCKET_PREFS, + SP_VERB_CONTEXT_ERASER_PREFS, /* Zooming and desktop settings */ SP_VERB_ZOOM_IN, SP_VERB_ZOOM_OUT, diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 17d45e41f..e01d16875 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -125,6 +125,7 @@ static void sp_dropper_toolbox_prep(SPDesktop *desktop, GtkActionGroup* ma static GtkWidget *sp_empty_toolbox_new(SPDesktop *desktop); static void sp_connector_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder); static void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder); +static void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder); namespace { GtkWidget *sp_text_toolbox_new (SPDesktop *desktop); } @@ -157,6 +158,7 @@ static struct { { "SPPencilContext", "pencil_tool", SP_VERB_CONTEXT_PENCIL, SP_VERB_CONTEXT_PENCIL_PREFS }, { "SPPenContext", "pen_tool", SP_VERB_CONTEXT_PEN, SP_VERB_CONTEXT_PEN_PREFS }, { "SPDynaDrawContext", "dyna_draw_tool", SP_VERB_CONTEXT_CALLIGRAPHIC, SP_VERB_CONTEXT_CALLIGRAPHIC_PREFS }, + { "SPEraserContext", "eraser_tool", SP_VERB_CONTEXT_ERASER, SP_VERB_CONTEXT_ERASER_PREFS }, { "SPFloodContext", "paintbucket_tool", SP_VERB_CONTEXT_PAINTBUCKET, SP_VERB_CONTEXT_PAINTBUCKET_PREFS }, { "SPTextContext", "text_tool", SP_VERB_CONTEXT_TEXT, SP_VERB_CONTEXT_TEXT_PREFS }, { "SPConnectorContext","connector_tool", SP_VERB_CONTEXT_CONNECTOR, SP_VERB_CONTEXT_CONNECTOR_PREFS }, @@ -199,6 +201,8 @@ static struct { SP_VERB_CONTEXT_PEN_PREFS, "tools.freehand.pen", N_("Style of new paths created by Pen")}, { "SPDynaDrawContext", "calligraphy_toolbox", 0, sp_calligraphy_toolbox_prep,"CalligraphyToolbar", SP_VERB_CONTEXT_CALLIGRAPHIC_PREFS, "tools.calligraphic", N_("Style of new calligraphic strokes")}, + { "SPEraserContext", "eraser_toolbox", 0, sp_eraser_toolbox_prep,"EraserToolbar", + SP_VERB_CONTEXT_ERASER_PREFS, "tools.eraser", _("TBD")}, { "SPTextContext", "text_toolbox", sp_text_toolbox_new, 0, 0, SP_VERB_INVALID, 0, 0}, { "SPDropperContext", "dropper_toolbox", 0, sp_dropper_toolbox_prep, "DropperToolbar", @@ -408,6 +412,12 @@ static gchar const * ui_descr = " " " " + " " + " " + " " + " " + " " + " " " " " " @@ -3866,6 +3876,29 @@ static void sp_arctb_end_value_changed(GtkAdjustment *adj, GObject *tbl) sp_arctb_startend_value_changed(adj, tbl, "end", "start"); } + +static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl ) +{ + SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" ); + gint eraserMode = (ege_select_one_action_get_active( act ) != 0) ? 1 : 0; + if (sp_document_get_undo_sensitive(sp_desktop_document(desktop))) { + prefs_set_int_attribute( "tools.eraser", "mode", eraserMode ); + } + + // only take action if run by the attr_changed listener + if (!g_object_get_data( tbl, "freeze" )) { + // in turn, prevent listener from responding + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); + + if ( eraserMode != 0 ) { + } else { + } + // TODO finish implementation + + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); + } +} + static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) { SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" ); @@ -4203,6 +4236,60 @@ static void sp_dropper_toolbox_prep(SPDesktop */*desktop*/, GtkActionGroup* main } + +static void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) +{ + { + /* Width */ + gchar const* labels[] = {_("(hairline)"), 0, 0, 0, _("(default)"), 0, 0, 0, 0, _("(broad stroke)")}; + gdouble values[] = {1, 3, 5, 10, 15, 20, 30, 50, 75, 100}; + EgeAdjustmentAction *eact = create_adjustment_action( "EraserWidthAction", + _("Pen Width"), _("Width:"), + _("The width of the eraser pen (relative to the visible canvas area)"), + "tools.eraser", "width", 15, + GTK_WIDGET(desktop->canvas), NULL, holder, TRUE, "altx-eraser", + 1, 100, 1.0, 10.0, + labels, values, G_N_ELEMENTS(labels), + sp_ddc_width_value_changed, 0.01, 0, 100 ); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); + } + + { + 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, _("Delete"), + 1, _("Delete objects touched by the eraser"), + 2, "delete_object", + -1 ); + + gtk_list_store_append( model, &iter ); + gtk_list_store_set( model, &iter, + 0, _("Cut"), + 1, _("Cut out from objects"), + 2, "difference", + -1 ); + + EgeSelectOneAction* act = ege_select_one_action_new( "EraserModeAction", (""), (""), NULL, GTK_TREE_MODEL(model) ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + g_object_set_data( holder, "eraser_mode_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_tooltip_column( act, 1 ); + + gint eraserMode = (prefs_get_int_attribute("tools.eraser", "mode", 0) != 0) ? 1 : 0; + ege_select_one_action_set_active( act, eraserMode ); + g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_erasertb_mode_changed), holder ); + } + +} + //######################## //## Text Toolbox ## //########################