From: cilix42 Date: Mon, 18 Aug 2008 00:34:25 +0000 (+0000) Subject: Groundwork for new LPETool tool (which consists of subtools that are constructed... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=304f51846342812ceea2b6d1f69c57585a5e412e;p=inkscape.git Groundwork for new LPETool tool (which consists of subtools that are constructed from LPEs) --- diff --git a/src/Makefile_insert b/src/Makefile_insert index f4aba89b9..876959798 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -102,6 +102,7 @@ libinkpre_a_SOURCES = \ layer-fns.cpp layer-fns.h \ layer-manager.cpp layer-manager.h \ line-geometry.cpp line-geometry.h \ + lpe-tool-context.cpp lpe-tool-context.h \ macros.h \ main-cmdlineact.cpp main-cmdlineact.h \ media.cpp media.h \ diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp new file mode 100644 index 000000000..a93176067 --- /dev/null +++ b/src/lpe-tool-context.cpp @@ -0,0 +1,401 @@ +/* + * LPEToolContext: a context for a generic tool composed of subtools that are given by LPEs + * + * Authors: + * Maximilian Albert + * Lauris Kaplinski + * + * Copyright (C) 1998 The Free Software Foundation + * Copyright (C) 1999-2005 authors + * Copyright (C) 2001-2002 Ximian, Inc. + * Copyright (C) 2008 Maximilian Albert + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "config.h" + +#include "forward.h" +#include "pixmaps/cursor-pencil.xpm" +#include +#include "desktop.h" +#include "message-context.h" +#include "prefs-utils.h" + +/** + +#include +#include +#include +#include +#include + +#include "svg/svg.h" +#include "display/canvas-bpath.h" +#include "display/bezier-utils.h" + +#include +#include "macros.h" +#include "document.h" +#include "selection.h" +#include "desktop-events.h" +#include "desktop-handles.h" +#include "desktop-affine.h" +#include "desktop-style.h" +#include "xml/repr.h" +#include "context-fns.h" +#include "sp-item.h" +#include "inkscape.h" +#include "color.h" +#include "rubberband.h" +#include "splivarot.h" +#include "sp-item-group.h" +#include "sp-shape.h" +#include "sp-path.h" +#include "sp-text.h" +#include "display/canvas-bpath.h" +#include "display/canvas-arena.h" +#include "livarot/Shape.h" +#include <2geom/isnan.h> +#include <2geom/pathvector.h> +**/ + +#include "lpe-tool-context.h" + +static void sp_lpetool_context_class_init(SPLPEToolContextClass *klass); +static void sp_lpetool_context_init(SPLPEToolContext *erc); +static void sp_lpetool_context_dispose(GObject *object); + +static void sp_lpetool_context_setup(SPEventContext *ec); +static void sp_lpetool_context_set(SPEventContext *ec, gchar const *key, gchar const *val); +static gint sp_lpetool_context_root_handler(SPEventContext *ec, GdkEvent *event); + + +static SPEventContextClass *lpetool_parent_class = 0; + +GType sp_lpetool_context_get_type(void) +{ + static GType type = 0; + if (!type) { + GTypeInfo info = { + sizeof(SPLPEToolContextClass), + 0, // base_init + 0, // base_finalize + (GClassInitFunc)sp_lpetool_context_class_init, + 0, // class_finalize + 0, // class_data + sizeof(SPLPEToolContext), + 0, // n_preallocs + (GInstanceInitFunc)sp_lpetool_context_init, + 0 // value_table + }; + type = g_type_register_static(SP_TYPE_EVENT_CONTEXT, "SPLPEToolContext", &info, static_cast(0)); + } + return type; +} + +static void +sp_lpetool_context_class_init(SPLPEToolContextClass *klass) +{ + GObjectClass *object_class = (GObjectClass *) klass; + SPEventContextClass *event_context_class = (SPEventContextClass *) klass; + + lpetool_parent_class = (SPEventContextClass*)g_type_class_peek_parent(klass); + + object_class->dispose = sp_lpetool_context_dispose; + + event_context_class->setup = sp_lpetool_context_setup; + event_context_class->set = sp_lpetool_context_set; + event_context_class->root_handler = sp_lpetool_context_root_handler; +} + +static void +sp_lpetool_context_init(SPLPEToolContext *erc) +{ + erc->cursor_shape = cursor_pencil_xpm; + erc->hot_x = 4; + erc->hot_y = 4; +} + +static void +sp_lpetool_context_dispose(GObject *object) +{ + //SPLPEToolContext *erc = SP_LPETOOL_CONTEXT(object); + + G_OBJECT_CLASS(lpetool_parent_class)->dispose(object); +} + +static void +sp_lpetool_context_setup(SPEventContext *ec) +{ + SPLPEToolContext *erc = SP_LPETOOL_CONTEXT(ec); + + if (((SPEventContextClass *) lpetool_parent_class)->setup) + ((SPEventContextClass *) lpetool_parent_class)->setup(ec); + + erc->_message_context = new Inkscape::MessageContext((ec->desktop)->messageStack()); + + if (prefs_get_int_attribute("tools.lpetool", "selcue", 0) != 0) { + ec->enableSelectionCue(); + } +// TODO temp force: + ec->enableSelectionCue(); +} + +static void +sp_lpetool_context_set(SPEventContext *ec, gchar const *key, gchar const *val) +{ + //pass on up to parent class to handle common attributes. + if ( lpetool_parent_class->set ) { + lpetool_parent_class->set(ec, key, val); + } +} + +/** +void +sp_erc_update_toolbox (SPDesktop *desktop, const gchar *id, double value) +{ + desktop->setToolboxAdjustmentValue (id, value); +} +**/ + +gint +sp_lpetool_context_root_handler(SPEventContext *event_context, + GdkEvent *event) +{ + //SPLPEToolContext *dc = SP_LPETOOL_CONTEXT(event_context); + //SPDesktop *desktop = event_context->desktop; + + gint ret = FALSE; + + /** + switch (event->type) { + case GDK_BUTTON_PRESS: + if (event->button.button == 1 && !event_context->space_panning) { + + SPDesktop *desktop = SP_EVENT_CONTEXT_DESKTOP(dc); + + if (Inkscape::have_viable_layer(desktop, dc->_message_context) == false) { + return TRUE; + } + + NR::Point const button_w(event->button.x, + event->button.y); + NR::Point const button_dt(desktop->w2d(button_w)); + sp_lpetool_reset(dc, button_dt); + sp_lpetool_extinput(dc, event); + sp_lpetool_apply(dc, button_dt); + dc->accumulated->reset(); + if (dc->repr) { + dc->repr = NULL; + } + + Inkscape::Rubberband::get()->start(desktop, button_dt); + Inkscape::Rubberband::get()->setMode(RUBBERBAND_MODE_TOUCHPATH); + + // initialize first point + dc->npoints = 0; + + sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate), + ( GDK_KEY_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_POINTER_MOTION_MASK | + GDK_BUTTON_PRESS_MASK ), + NULL, + event->button.time); + + ret = TRUE; + + sp_canvas_force_full_redraw_after_interruptions(desktop->canvas, 3); + dc->is_drawing = true; + } + break; + case GDK_MOTION_NOTIFY: + { + NR::Point const motion_w(event->motion.x, + event->motion.y); + NR::Point motion_dt(desktop->w2d(motion_w)); + sp_lpetool_extinput(dc, event); + + dc->_message_context->clear(); + + if ( dc->is_drawing && (event->motion.state & GDK_BUTTON1_MASK) && !event_context->space_panning) { + dc->dragging = TRUE; + + dc->_message_context->set(Inkscape::NORMAL_MESSAGE, _("Drawing an lpetool stroke")); + + if (!sp_lpetool_apply(dc, motion_dt)) { + ret = TRUE; + break; + } + + if ( dc->cur != dc->last ) { + sp_lpetool_brush(dc); + g_assert( dc->npoints > 0 ); + fit_and_split(dc, FALSE); + } + ret = TRUE; + } + Inkscape::Rubberband::get()->move(motion_dt); + } + break; + + + case GDK_BUTTON_RELEASE: + { + NR::Point const motion_w(event->button.x, event->button.y); + NR::Point const motion_dt(desktop->w2d(motion_w)); + + sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); + sp_canvas_end_forced_full_redraws(desktop->canvas); + dc->is_drawing = false; + + if (dc->dragging && event->button.button == 1 && !event_context->space_panning) { + dc->dragging = FALSE; + + NR::Maybe const b = Inkscape::Rubberband::get()->getRectangle(); + + sp_lpetool_apply(dc, motion_dt); + + // Remove all temporary line segments + while (dc->segments) { + gtk_object_destroy(GTK_OBJECT(dc->segments->data)); + dc->segments = g_slist_remove(dc->segments, dc->segments->data); + } + + // Create object + fit_and_split(dc, TRUE); + accumulate_lpetool(dc); + set_to_accumulated(dc); // performs document_done + + // reset accumulated curve + dc->accumulated->reset(); + + clear_current(dc); + if (dc->repr) { + dc->repr = NULL; + } + + Inkscape::Rubberband::get()->stop(); + dc->_message_context->clear(); + ret = TRUE; + } + break; + } + + case GDK_KEY_PRESS: + switch (get_group0_keyval (&event->key)) { + case GDK_Up: + case GDK_KP_Up: + if (!MOD__CTRL_ONLY) { + dc->angle += 5.0; + if (dc->angle > 90.0) + dc->angle = 90.0; + sp_erc_update_toolbox (desktop, "lpetool-angle", dc->angle); + ret = TRUE; + } + break; + case GDK_Down: + case GDK_KP_Down: + if (!MOD__CTRL_ONLY) { + dc->angle -= 5.0; + if (dc->angle < -90.0) + dc->angle = -90.0; + sp_erc_update_toolbox (desktop, "lpetool-angle", dc->angle); + ret = TRUE; + } + break; + case GDK_Right: + case GDK_KP_Right: + if (!MOD__CTRL_ONLY) { + dc->width += 0.01; + if (dc->width > 1.0) + dc->width = 1.0; + sp_erc_update_toolbox (desktop, "altx-lpetool", dc->width * 100); // the same spinbutton is for alt+x + ret = TRUE; + } + break; + case GDK_Left: + case GDK_KP_Left: + if (!MOD__CTRL_ONLY) { + dc->width -= 0.01; + if (dc->width < 0.01) + dc->width = 0.01; + sp_erc_update_toolbox (desktop, "altx-lpetool", dc->width * 100); + ret = TRUE; + } + break; + case GDK_Home: + case GDK_KP_Home: + dc->width = 0.01; + sp_erc_update_toolbox (desktop, "altx-lpetool", dc->width * 100); + ret = TRUE; + break; + case GDK_End: + case GDK_KP_End: + dc->width = 1.0; + sp_erc_update_toolbox (desktop, "altx-lpetool", dc->width * 100); + ret = TRUE; + break; + case GDK_x: + case GDK_X: + if (MOD__ALT_ONLY) { + desktop->setToolboxFocusTo ("altx-lpetool"); + ret = TRUE; + } + break; + case GDK_Escape: + Inkscape::Rubberband::get()->stop(); + if (dc->is_drawing) { + // if drawing, cancel, otherwise pass it up for deselecting + lpetool_cancel (dc); + ret = TRUE; + } + break; + case GDK_z: + case GDK_Z: + if (MOD__CTRL_ONLY && dc->is_drawing) { + // if drawing, cancel, otherwise pass it up for undo + lpetool_cancel (dc); + ret = TRUE; + } + break; + default: + break; + } + break; + + case GDK_KEY_RELEASE: + switch (get_group0_keyval(&event->key)) { + case GDK_Control_L: + case GDK_Control_R: + dc->_message_context->clear(); + break; + default: + break; + } + + default: + break; + } + **/ + + if (!ret) { + if (((SPEventContextClass *) lpetool_parent_class)->root_handler) { + ret = ((SPEventContextClass *) lpetool_parent_class)->root_handler(event_context, event); + } + } + + return ret; +} + +/* + 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:encoding=utf-8:textwidth=99 : diff --git a/src/lpe-tool-context.h b/src/lpe-tool-context.h new file mode 100644 index 000000000..73002143e --- /dev/null +++ b/src/lpe-tool-context.h @@ -0,0 +1,48 @@ +#ifndef SP_LPETOOL_CONTEXT_H_SEEN +#define SP_LPETOOL_CONTEXT_H_SEEN + +/* + * LPEToolContext: a context for a generic tool composed of subtools that are given by LPEs + * + * Authors: + * Maximilian Albert + * Lauris Kaplinski + * + * Copyright (C) 1998 The Free Software Foundation + * Copyright (C) 1999-2002 authors + * Copyright (C) 2001-2002 Ximian, Inc. + * Copyright (C) 2008 Maximilian Albert + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "event-context.h" + +#define SP_TYPE_LPETOOL_CONTEXT (sp_lpetool_context_get_type()) +#define SP_LPETOOL_CONTEXT(o) (GTK_CHECK_CAST((o), SP_TYPE_LPETOOL_CONTEXT, SPLPEToolContext)) +#define SP_LPETOOL_CONTEXT_CLASS(k) (GTK_CHECK_CLASS_CAST((k), SP_TYPE_LPETOOL_CONTEXT, SPLPEToolContextClass)) +#define SP_IS_LPETOOL_CONTEXT(o) (GTK_CHECK_TYPE((o), SP_TYPE_LPETOOL_CONTEXT)) +#define SP_IS_LPETOOL_CONTEXT_CLASS(k) (GTK_CHECK_CLASS_TYPE((k), SP_TYPE_LPETOOL_CONTEXT)) + +class SPLPEToolContext; +class SPLPEToolContextClass; + +struct SPLPEToolContext : public SPEventContext { +}; + +struct SPLPEToolContextClass : public SPEventContextClass{}; + +GType sp_lpetool_context_get_type(void); + +#endif // SP_LPETOOL_CONTEXT_H_SEEN + +/* + 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:encoding=utf-8:textwidth=99 : diff --git a/src/pen-context.cpp b/src/pen-context.cpp index 8e1f6947b..22f83a219 100644 --- a/src/pen-context.cpp +++ b/src/pen-context.cpp @@ -41,6 +41,7 @@ #include "helper/units.h" #include "macros.h" #include "context-fns.h" +#include "tools-switch.h" static void sp_pen_context_class_init(SPPenContextClass *klass); static void sp_pen_context_init(SPPenContext *pc); diff --git a/src/pen-context.h b/src/pen-context.h index 24afa701c..a358126ac 100644 --- a/src/pen-context.h +++ b/src/pen-context.h @@ -66,6 +66,8 @@ inline bool sp_pen_context_has_waiting_LPE(SPPenContext *pc) { void sp_pen_context_set_polyline_mode(SPPenContext *const pc); void sp_pen_context_wait_for_LPE_mouse_clicks(SPPenContext *pc, Inkscape::LivePathEffect::EffectType effect_type, unsigned int num_clicks, bool use_polylines = true); +void sp_pen_context_put_into_waiting_mode(SPDesktop *desktop, Inkscape::LivePathEffect::EffectType effect_type, + unsigned int num_clicks, bool use_polylines = true); #endif /* !SEEN_PEN_CONTEXT_H */ diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h index 1b9561ace..dfbbd61ee 100644 --- a/src/preferences-skeleton.h +++ b/src/preferences-skeleton.h @@ -85,6 +85,8 @@ static char const preferences_skeleton[] = " mass=\"0.02\" drag=\"1\" angle=\"30\" width=\"0.15\" thinning=\"0.1\" flatness=\"0.9\" cap_rounding=\"0.0\" usecurrent=\"0\"\n" " tracebackground=\"0\" usepressure=\"1\" usetilt=\"0\" selcue=\"1\">\n" " \n" +" \n" +" \n" " \n" diff --git a/src/tools-switch.cpp b/src/tools-switch.cpp index 4c51f4e10..6ee162f1d 100644 --- a/src/tools-switch.cpp +++ b/src/tools-switch.cpp @@ -43,6 +43,7 @@ #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" @@ -76,6 +77,7 @@ static char const *const tool_names[] = { "tools.connector", "tools.paintbucket", "tools.eraser", + "tools.lpetool", NULL }; @@ -99,6 +101,7 @@ static char const *const tool_ids[] = { "connector", "paintbucket", "eraser", + "lpetool", NULL }; @@ -246,6 +249,12 @@ tools_switch(SPDesktop *dt, int num) 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; } } diff --git a/src/tools-switch.h b/src/tools-switch.h index f5a3220ca..2026c1a3d 100644 --- a/src/tools-switch.h +++ b/src/tools-switch.h @@ -33,7 +33,8 @@ enum { TOOLS_DROPPER, TOOLS_CONNECTOR, TOOLS_PAINTBUCKET, - TOOLS_ERASER + TOOLS_ERASER, + TOOLS_LPETOOL }; int tools_isactive(SPDesktop *dt, unsigned num); diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index ecedf6003..8a2a44ccc 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -471,6 +471,10 @@ void InkscapePreferences::initPageTools() this->AddPage(_page_eraser, _("Eraser"), iter_tools, PREFS_PAGE_TOOLS_ERASER); this->AddNewObjectsStyle(_page_eraser, "tools.eraser"); + //LPETool + this->AddPage(_page_lpetool, _("LPE Tool"), iter_tools, PREFS_PAGE_TOOLS_LPETOOL); + this->AddNewObjectsStyle(_page_lpetool, "tools.lpetool"); + //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 6efebb742..ab4f78810 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -52,6 +52,7 @@ enum { PREFS_PAGE_TOOLS_CALLIGRAPHY, PREFS_PAGE_TOOLS_PAINTBUCKET, PREFS_PAGE_TOOLS_ERASER, + PREFS_PAGE_TOOLS_LPETOOL, PREFS_PAGE_TOOLS_TEXT, PREFS_PAGE_TOOLS_GRADIENT, PREFS_PAGE_TOOLS_CONNECTOR, @@ -113,7 +114,7 @@ protected: _page_importexport, _page_cms, _page_grids, _page_svgoutput, _page_misc, _page_ui, _page_autosave, _page_bitmaps; 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; + _page_calligraphy, _page_text, _page_gradient, _page_connector, _page_dropper, _page_lpetool; DialogPage _page_rectangle, _page_3dbox, _page_ellipse, _page_star, _page_spiral, _page_paintbucket, _page_eraser; PrefSpinButton _mouse_sens, _mouse_thres; diff --git a/src/verbs.cpp b/src/verbs.cpp index 5947ac2cf..a9840667e 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -1487,6 +1487,9 @@ ContextVerb::perform(SPAction *action, void *data, void */*pdata*/) case SP_VERB_CONTEXT_ERASER: tools_switch_current(TOOLS_ERASER); break; + case SP_VERB_CONTEXT_LPETOOL: + tools_switch_current(TOOLS_LPETOOL); + break; case SP_VERB_CONTEXT_SELECT_PREFS: prefs_set_int_attribute("dialogs.preferences", "page", PREFS_PAGE_TOOLS_SELECTOR); @@ -1560,6 +1563,11 @@ ContextVerb::perform(SPAction *action, void *data, void */*pdata*/) prefs_set_int_attribute("dialogs.preferences", "page", PREFS_PAGE_TOOLS_ERASER); dt->_dlg_mgr->showDialog("InkscapePreferences"); break; + case SP_VERB_CONTEXT_LPETOOL_PREFS: + g_print ("TODO: Create preferences page for LPETool\n"); + prefs_set_int_attribute("dialogs.preferences", "page", PREFS_PAGE_TOOLS_LPETOOL); + dt->_dlg_mgr->showDialog("InkscapePreferences"); + break; default: break; @@ -2497,6 +2505,8 @@ Verb *Verb::_base_verbs[] = { N_("Edit Live Path Effect parameters"), "draw_lpe"), new ContextVerb(SP_VERB_CONTEXT_ERASER, "ToolEraser", N_("Eraser"), N_("Erase existing paths"), "draw_erase"), + new ContextVerb(SP_VERB_CONTEXT_LPETOOL, "ToolLPETool", N_("LPE Tool"), + N_("Write something sensible here"), "draw_lpetool"), /* Tool prefs */ new ContextVerb(SP_VERB_CONTEXT_SELECT_PREFS, "SelectPrefs", N_("Selector Preferences"), N_("Open Preferences for the Selector tool"), NULL), @@ -2534,6 +2544,8 @@ Verb *Verb::_base_verbs[] = { 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), + new ContextVerb(SP_VERB_CONTEXT_LPETOOL_PREFS, "LPEToolPrefs", N_("LPE Tool Preferences"), + N_("Open Preferences for the LPETool 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 bb3cd3a3b..2362f23aa 100644 --- a/src/verbs.h +++ b/src/verbs.h @@ -168,6 +168,7 @@ enum { 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, + SP_VERB_CONTEXT_LPETOOL, /* note that this is very different from SP_VERB_CONTEXT_LPE above! */ /* Tool preferences */ SP_VERB_CONTEXT_SELECT_PREFS, SP_VERB_CONTEXT_NODE_PREFS, @@ -187,6 +188,7 @@ enum { SP_VERB_CONTEXT_CONNECTOR_PREFS, SP_VERB_CONTEXT_PAINTBUCKET_PREFS, SP_VERB_CONTEXT_ERASER_PREFS, + SP_VERB_CONTEXT_LPETOOL_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 a7591608f..18becfdb6 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -132,6 +132,7 @@ 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); +static void sp_lpetool_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder); namespace { GtkWidget *sp_text_toolbox_new (SPDesktop *desktop); } @@ -165,6 +166,7 @@ static struct { { "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 }, + { "SPLPEToolContext", "lpetool_tool", SP_VERB_CONTEXT_LPETOOL, SP_VERB_CONTEXT_LPETOOL_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 }, @@ -209,6 +211,8 @@ static struct { 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")}, + { "SPLPEToolContext", "lpetool_toolbox", 0, sp_lpetool_toolbox_prep, "LPEToolToolbar", + SP_VERB_CONTEXT_LPETOOL_PREFS, "tools.lpetool", _("TBD")}, { "SPTextContext", "text_toolbox", sp_text_toolbox_new, 0, 0, SP_VERB_INVALID, 0, 0}, { "SPDropperContext", "dropper_toolbox", 0, sp_dropper_toolbox_prep, "DropperToolbar", @@ -434,6 +438,10 @@ static gchar const * ui_descr = " " " " + " " + " " + " " + " " " " " " @@ -1564,6 +1572,7 @@ setup_tool_toolbox(GtkWidget *toolbox, SPDesktop *desktop) " " " " " " + " " " " " " " " @@ -4431,28 +4440,6 @@ static void sp_arctb_end_value_changed(GtkAdjustment *adj, GObject *tbl) } -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" ); @@ -4790,6 +4777,104 @@ static void sp_dropper_toolbox_prep(SPDesktop */*desktop*/, GtkActionGroup* main } +//######################## +//## LPETool ## +//######################## + +static void sp_lpetool_mode_changed(EgeSelectOneAction *act, GObject *tbl) +{ + SPDesktop *desktop = (SPDesktop *) g_object_get_data(tbl, "desktop"); + gint lpeToolMode = (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.lpetool", "mode", lpeToolMode ); + } + + // 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) ); + + switch (lpeToolMode) { + case 0: + // angle bisector + g_print ("angle bisector\n"); + break; + case 1: + // circle through 3 points + g_print ("circle through 3 points\n"); + sp_pen_context_put_into_waiting_mode(desktop, Inkscape::LivePathEffect::CIRCLE_3PTS, 3); + break; + default: + // don't do anything + break; + } + // TODO finish implementation + + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); + } +} + +static void sp_lpetool_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) +{ + { + 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, _("Angle bisector"), + 1, _("Angle bisector"), + 2, "delete_object", + -1 ); + + gtk_list_store_append( model, &iter ); + gtk_list_store_set( model, &iter, + 0, _("Circle through 3 points"), + 1, _("Circle through 3 points"), + 2, "difference", + -1 ); + + EgeSelectOneAction* act = ege_select_one_action_new( "LPEToolModeAction", (""), (""), NULL, GTK_TREE_MODEL(model) ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + g_object_set_data( holder, "lpetool_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 lpeToolMode = (prefs_get_int_attribute("tools.lpetool", "mode", 0) != 0) ? 1 : 0; + ege_select_one_action_set_active( act, lpeToolMode ); + g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_lpetool_mode_changed), holder ); + } +} + +//######################## +//## Eraser ## +//######################## + +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_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) {