From 903d68d4df1de1ae21e124d6e9c12770085ea087 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 25 Feb 2014 17:08:30 +0100 Subject: Rewrite of symbol creation code. Partial fix for 1201325. Symbols cannot have 'tranform' attribute. The old code copied the group 'transform' attribute to the symbol. The new code creates an intermediate group with the required 'transform' if it is not a simple translation. A simple translation is removed and applied instead to the new element. Multiple objects can now be turned into a symbol without first grouping the objects. (At the cost that multiple groups can no longer be turned into multiple symbols at one go.) This better matches marker and pattern creation. (bzr r13057) --- configure.ac | 2 +- src/extension/internal/cairo-renderer.cpp | 6 +- src/selection-chemistry.cpp | 223 +++++++++++++++++++----------- src/selection-chemistry.h | 3 +- src/verbs.cpp | 2 +- 5 files changed, 150 insertions(+), 86 deletions(-) diff --git a/configure.ac b/configure.ac index dbffcfbde..529ac24f9 100644 --- a/configure.ac +++ b/configure.ac @@ -101,7 +101,7 @@ if test "$GCC" = "yes"; then fi # Uncomment for SVG2 stuff - # CPPFLAGS="-DWITH_MESH -DWITH_CSSBLEND -DWITH_CSSCOMPOSITE $CPPFLAGS" + CPPFLAGS="-DWITH_MESH -DWITH_CSSBLEND -DWITH_CSSCOMPOSITE -DWITH_SVG2 $CPPFLAGS" #### # C-specific flags... diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index 6fbc85c05..aa47d8169 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -77,8 +77,8 @@ #include #endif -//#define TRACE(_args) g_printf _args -#define TRACE(_args) +#define TRACE(_args) g_printf _args +//#define TRACE(_args) //#define TEST(_args) _args #define TEST(_args) @@ -628,7 +628,7 @@ CairoRenderer::setupDocument(CairoRenderContext *ctx, SPDocument *doc, bool page ctx->_width = d.width(); ctx->_height = d.height(); - TRACE(("setupDocument: %f x %f\n", ctx->_width, ctx->_height)); + TRACE(("Cairo Renderer: setupDocument: %f x %f\n", ctx->_width, ctx->_height)); bool ret = ctx->setupSurface(ctx->_width, ctx->_height); diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index ecf814f60..c3d37af72 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -2934,96 +2934,145 @@ void sp_selection_to_guides(SPDesktop *desktop) } /* - * Convert to , leaving all elements referencing group unchanged. + * Convert objects to . How that happens depends on what is selected: + * + * 1) A random selection of objects will be embedded into a single element. + * + * 2) Except, a single will have its content directly embedded into a ; the 'id' and + * 'style' of the are transferred to the . + * + * 3) Except, a single with a transform that isn't a translation will keep the group when + * embedded into a (with 'id' and 'style' transferred to ). This is because a + * cannot have a transform. (If the transform is a pure translation, the translation + * is moved to the referencing element that is created.) + * + * Possible improvements: + * + * Move objects inside symbol so bbox corner at 0,0 (see marker/pattern) + * + * For SVG2, set 'refX' 'refY' to object center (with compensating shift in + * transformation). */ -void sp_selection_symbols(SPDesktop *desktop, bool /*apply*/ ) +void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) { if (desktop == NULL) { return; } SPDocument *doc = sp_desktop_document(desktop); - doc->ensureUpToDate(); + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); Inkscape::Selection *selection = sp_desktop_selection(desktop); // Check if something is selected. if (selection->isEmpty()) { - desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select groups to convert to symbols.")); + desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select objects to convert to symbol.")); return; } - GSList *items = g_slist_copy(const_cast(selection->list())); - bool hasWorked = false; + doc->ensureUpToDate(); - for ( GSList const *iter=items; iter != NULL ; iter = iter->next ) { - SPObject *object = reinterpret_cast( iter->data ); + GSList *items = g_slist_copy(const_cast(selection->list())); - // Require that we really have a group. - if( SP_IS_GROUP( object ) ) { - sp_selection_symbol( doc, object ); - hasWorked = true; - } + // Keep track of parent, this is where will be inserted. + Inkscape::XML::Node *the_first_repr = reinterpret_cast( items->data )->getRepr(); + Inkscape::XML::Node *the_parent_repr = the_first_repr->parent(); + + // Find out if we have a single group + bool single_group = false; + SPObject *the_group = NULL; + Geom::Affine transform; + if( g_slist_length( items ) == 1 ) { + SPObject *object = reinterpret_cast( items->data ); + if( SP_IS_GROUP( object ) ) { + single_group = true; + the_group = object; + + if( !sp_svg_transform_read( object->getAttribute("transform"), &transform )) + transform = Geom::identity(); + + if( transform.isTranslation() ) { + + // Create new list from group children. + g_slist_free(items); + items = object->childList(false); + + // Hack: Temporarily set clone compensation to unmoved, so that we can move clone-originals + // without disturbing clones. + // See ActorAlign::on_button_click() in src/ui/dialog/align-and-distribute.cpp + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); + prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); + + // Remove transform on group, updating clones. + SP_ITEM(object)->doWriteTransform(object->getRepr(), Geom::identity()); + + // restore compensation setting + prefs->setInt("/options/clonecompensation/value", saved_compensation); + } + } } - g_slist_free(items); + // Create new + Inkscape::XML::Node *defsrepr = doc->getDefs()->getRepr(); + Inkscape::XML::Node *symbol_repr = xml_doc->createElement("svg:symbol"); + defsrepr->appendChild(symbol_repr); - if( !hasWorked ) { - desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No groups converted to symbols.")); - return; - } + // For a single group, copy relevant attributes. + if( single_group ) { - selection->clear(); - // Group just disappears, nothing to select. + symbol_repr->setAttribute("style", the_group->getAttribute("style")); + symbol_repr->setAttribute("class", the_group->getAttribute("class")); + symbol_repr->setAttribute("id", the_group->getAttribute("id") ); - DocumentUndo::done(doc, SP_VERB_EDIT_SYMBOL, _("Group to symbol")); -} + // This should eventually be replaced by 'refX' and 'refY' once SVG WG approves it. + // It is done here for round-tripping + symbol_repr->setAttribute("inkscape:transform-center-x", + the_group->getAttribute("inkscape:transform-center-x")); + symbol_repr->setAttribute("inkscape:transform-center-y", + the_group->getAttribute("inkscape:transform-center-y")); -void sp_selection_symbol(SPDocument *doc, SPObject *group) -{ - Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + the_group->setAttribute("style", NULL); + std::string id = symbol_repr->attribute("id"); + id += "_transform"; + the_group->setAttribute("id", id.c_str()); - Inkscape::XML::Node *symbol = xml_doc->createElement("svg:symbol"); - symbol->setAttribute("style", group->getAttribute("style")); - symbol->setAttribute("title", group->getAttribute("title")); - symbol->setAttribute("transform", group->getAttribute("transform")); - - Glib::ustring id = group->getAttribute("id"); + } - // Now we need to copy all children of group - GSList* children = group->childList(false); - children = g_slist_reverse(children); - for (GSList* i = children; i != NULL; i = i->next ) { - SPObject* child = SP_OBJECT(i->data); - Inkscape::XML::Node *dup = child->getRepr()->duplicate(xml_doc); - symbol->appendChild(dup); - child->deleteObject(true); + // Move selected items to new + for (GSList *i = items; i != NULL; i = i->next) { + Inkscape::XML::Node *repr = SP_OBJECT(i->data)->getRepr(); + repr->parent()->removeChild(repr); + symbol_repr->addChild(repr,NULL); } - // Need to delete ; all elements that referenced should - // auto-magically reference . - doc->getDefs()->getRepr()->appendChild(symbol); - // Mysterious, must set symbol ID before deleting group or all items - // get turned into groups. (Linked to unlinking clones?) - symbol->setAttribute("id",id.c_str()); + if( single_group && transform.isTranslation() ) { + the_group->deleteObject(true); + } - // Create a clone of the symbol to replace the deleted group. + // Create pointing to new symbol (to replace the moved objects). Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); - clone->setAttribute("x", "0", false); - clone->setAttribute("y", "0", false); - gchar *href_str = g_strdup_printf("#%s", id.c_str()); + + const gchar *symbol_id = symbol_repr->attribute("id"); + gchar *href_str = g_strdup_printf("#%s", symbol_id); clone->setAttribute("xlink:href", href_str, false); g_free(href_str); - clone->setAttribute("inkscape:transform-center-x", group->getAttribute("inkscape:transform-center-x"), false); - clone->setAttribute("inkscape:transform-center-y", group->getAttribute("inkscape:transform-center-y"), false); - group->parent->getRepr()->appendChild(clone); + the_parent_repr->appendChild(clone); - group->deleteObject(true); + if( single_group && transform.isTranslation() ) { + if( !transform.isIdentity() ) + clone->setAttribute("transform", sp_svg_transform_write( transform )); + } - g_slist_free(children); + // Change selection to new element. + selection->set(clone); + + // Clean up + Inkscape::GC::release(symbol_repr); + g_slist_free(items); - Inkscape::GC::release(symbol); + DocumentUndo::done(doc, SP_VERB_EDIT_SYMBOL, _("Group to symbol")); } /* @@ -3049,48 +3098,64 @@ void sp_selection_unsymbol(SPDesktop *desktop) SPObject* symbol = selection->single(); // Make sure we have only one object in selection. - // Require that we really have a that references a . + // Require that we really have a . if( symbol == NULL || !SP_IS_SYMBOL( symbol )) { - desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select only one symbol to convert to group.")); + desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select only one symbol in Symbol dialog to convert to group.")); return; } doc->ensureUpToDate(); + // Create new and insert in current layer Inkscape::XML::Node *group = xml_doc->createElement("svg:g"); - group->setAttribute("style", symbol->getAttribute("style")); - group->setAttribute("title", symbol->getAttribute("title")); - group->setAttribute("transform", symbol->getAttribute("transform")); - - Glib::ustring id = symbol->getAttribute("id"); + desktop->currentLayer()->getRepr()->appendChild(group); - // Now we need to copy all children of symbol + // Move all children of symbol to group GSList* children = symbol->childList(false); - children = g_slist_reverse(children); + + // Converting a group to a symbol inserts a group for non-translational transform. + // In converting a symbol back to a group we strip out the inserted group (or any other + // group that only adds a transform to the symbol content). + if( g_slist_length( children ) == 1 ) { + SPObject *object = reinterpret_cast( children->data ); + if( SP_IS_GROUP( object ) ) { + if( object->getAttribute("style") == NULL || + object->getAttribute("class") == NULL ) { + + group->setAttribute("transform", object->getAttribute("transform")); + g_slist_free(children); + children = object->childList(false); + } + } + } + for (GSList* i = children; i != NULL; i = i->next ) { - SPObject* child = SP_OBJECT(i->data); - Inkscape::XML::Node *dup = child->getRepr()->duplicate(xml_doc); - group->appendChild(dup); - child->deleteObject(true); + Inkscape::XML::Node *repr = SP_OBJECT(i->data)->getRepr(); + repr->parent()->removeChild(repr); + group->addChild(repr,NULL); } - // So we insert inside the current layer - SPObject *parent = desktop->currentLayer(); + // Copy relevant attributes + group->setAttribute("style", symbol->getAttribute("style")); + group->setAttribute("class", symbol->getAttribute("class")); + group->setAttribute("inkscape:transform-center-x", + symbol->getAttribute("inkscape:transform-center-x")); + group->setAttribute("inkscape:transform-center-y", + symbol->getAttribute("inkscape:transform-center-y")); + - // Need to delete ; all other elements that referenced should - // auto-magically reference . - symbol->setAttribute("id","todelete"); - group->setAttribute("id",id.c_str()); // After we delete symbol with same id. + // Need to delete ; all elements that referenced should + // auto-magically reference (if deleted after setting 'id'). + Glib::ustring id = symbol->getAttribute("id"); + group->setAttribute("id",id.c_str()); symbol->deleteObject(true); - parent->getRepr()->appendChild(group); + // Change selection to new element. SPItem *group_item = static_cast(sp_desktop_document(desktop)->getObjectByRepr(group)); - Inkscape::GC::release(group); - selection->clear(); selection->set(group_item); - // Need to signal Symbol dialog to update - + // Clean up + Inkscape::GC::release(group); g_slist_free(children); DocumentUndo::done(doc, SP_VERB_EDIT_UNSYMBOL, _("Group from symbol")); diff --git a/src/selection-chemistry.h b/src/selection-chemistry.h index e86000f70..d76a67a9d 100644 --- a/src/selection-chemistry.h +++ b/src/selection-chemistry.h @@ -69,8 +69,7 @@ void sp_selection_clone_original_path_lpe(SPDesktop *desktop); void sp_selection_to_marker(SPDesktop *desktop, bool apply = true); void sp_selection_to_guides(SPDesktop *desktop); -void sp_selection_symbols(SPDesktop *desktop, bool apply = true); -void sp_selection_symbol(SPDocument *doc, SPObject *group); +void sp_selection_symbol(SPDesktop *desktop, bool apply = true); void sp_selection_unsymbol(SPDesktop *desktop); void sp_selection_tile(SPDesktop *desktop, bool apply = true); diff --git a/src/verbs.cpp b/src/verbs.cpp index 8b333383f..653d5f892 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -996,7 +996,7 @@ void EditVerb::perform(SPAction *action, void *data) sp_selection_untile(dt); break; case SP_VERB_EDIT_SYMBOL: - sp_selection_symbols(dt); + sp_selection_symbol(dt); break; case SP_VERB_EDIT_UNSYMBOL: sp_selection_unsymbol(dt); -- cgit v1.2.3 From ba65200ce8e3225340d729902c26dce142c65e57 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 25 Feb 2014 17:12:22 +0100 Subject: Revert unintended checkin. (bzr r13058) --- configure.ac | 2 +- src/extension/internal/cairo-renderer.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 529ac24f9..dbffcfbde 100644 --- a/configure.ac +++ b/configure.ac @@ -101,7 +101,7 @@ if test "$GCC" = "yes"; then fi # Uncomment for SVG2 stuff - CPPFLAGS="-DWITH_MESH -DWITH_CSSBLEND -DWITH_CSSCOMPOSITE -DWITH_SVG2 $CPPFLAGS" + # CPPFLAGS="-DWITH_MESH -DWITH_CSSBLEND -DWITH_CSSCOMPOSITE $CPPFLAGS" #### # C-specific flags... diff --git a/src/extension/internal/cairo-renderer.cpp b/src/extension/internal/cairo-renderer.cpp index aa47d8169..6fbc85c05 100644 --- a/src/extension/internal/cairo-renderer.cpp +++ b/src/extension/internal/cairo-renderer.cpp @@ -77,8 +77,8 @@ #include #endif -#define TRACE(_args) g_printf _args -//#define TRACE(_args) +//#define TRACE(_args) g_printf _args +#define TRACE(_args) //#define TEST(_args) _args #define TEST(_args) @@ -628,7 +628,7 @@ CairoRenderer::setupDocument(CairoRenderContext *ctx, SPDocument *doc, bool page ctx->_width = d.width(); ctx->_height = d.height(); - TRACE(("Cairo Renderer: setupDocument: %f x %f\n", ctx->_width, ctx->_height)); + TRACE(("setupDocument: %f x %f\n", ctx->_width, ctx->_height)); bool ret = ctx->setupSurface(ctx->_width, ctx->_height); -- cgit v1.2.3 From 1f45b19153029772dc47af380a4c2d60e33090aa Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 25 Feb 2014 17:38:52 +0100 Subject: Allow 'transform' on flowRoot, flowPara, and flowSpan. (bzr r13059) --- share/attributes/genMapDataSVG.pl | 2 +- share/attributes/svgprops | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/share/attributes/genMapDataSVG.pl b/share/attributes/genMapDataSVG.pl index 1dd9327e3..8cd18128e 100755 --- a/share/attributes/genMapDataSVG.pl +++ b/share/attributes/genMapDataSVG.pl @@ -82,7 +82,7 @@ push @{$attributes{ "class" }->{elements}}, "flowRoot","flowPara","flowSpan","fl push @{$attributes{ "id" }->{elements}}, "flowRoot","flowPara","flowSpan","flowRect","flowRegion"; push @{$attributes{ "style" }->{elements}}, "flowRoot","flowPara","flowSpan","flowRect","flowRegion"; push @{$attributes{ "xml:space" }->{elements}}, "flowRoot","flowPara","flowSpan"; - +push @{$attributes{ "transform" }->{elements}}, "flowRoot","flowPara","flowSpan"; # Output diff --git a/share/attributes/svgprops b/share/attributes/svgprops index 1de16b6a5..3e72fc65f 100644 --- a/share/attributes/svgprops +++ b/share/attributes/svgprops @@ -340,7 +340,7 @@ "to" - "set","animate","animateColor","animateMotion","animateTransform" -"transform" - "a","circle","clipPath","defs","ellipse","foreignObject","g","image","line","path","polygon","polyline","rect","switch","text","use" +"transform" - "a","circle","clipPath","defs","ellipse","foreignObject","g","image","line","path","polygon","polyline","rect","switch","text","use","flowRoot","flowPara","flowSpan" "type" - "animateTransform","feColorMatrix","feTurbulence","script","style","feFuncA","feFuncB","feFuncG","feFuncR" @@ -490,6 +490,8 @@ "image-rendering" - "pattern","image","feImage","a","defs","glyph","g","marker","mask","missing-glyph","pattern","svg","switch","symbol","use" +"isolation" - "a","defs","glyph","g","marker","mask","missing-glyph","pattern","svg","switch","symbol","use","circle","ellipse","image","line","path","polygon","polyline","rect","text","use" + "kerning" - "altGlyph","textPath","text","tref","tspan","flowRoot","flowPara","flowSpan","a","defs","glyph","g","marker","mask","missing-glyph","pattern","svg","switch","symbol","use" "letter-spacing" - "altGlyph","textPath","text","tref","tspan","flowRoot","flowPara","flowSpan","a","defs","glyph","g","marker","mask","missing-glyph","pattern","svg","switch","symbol","use" @@ -508,10 +510,14 @@ "mask" - "a","defs","glyph","g","marker","mask","missing-glyph","pattern","svg","switch","symbol","use","circle","ellipse","image","line","path","polygon","polyline","rect","text","use" +"mix-blend-mode" - "a","defs","glyph","g","marker","mask","missing-glyph","pattern","svg","switch","symbol","use","circle","ellipse","image","line","path","polygon","polyline","rect","text","use" + "opacity" - "a","defs","glyph","g","marker","mask","missing-glyph","pattern","svg","switch","symbol","use","circle","ellipse","image","line","path","polygon","polyline","rect","text","use" "overflow" - "svg","symbol","foreignObject","pattern","marker" +"paint-order" - "a","defs","glyph","g","marker","mask","missing-glyph","pattern","svg","switch","symbol","use","circle","ellipse","image","line","path","polygon","polyline","rect","text","use","a","defs","glyph","g","marker","mask","missing-glyph","pattern","svg","switch","symbol","use" + "pointer-events" - "circle","ellipse","image","line","path","polygon","polyline","rect","text","use","a","defs","glyph","g","marker","mask","missing-glyph","pattern","svg","switch","symbol","use" "shape-rendering" - "path","rect","circle","ellipse","line","polyline","polygon","a","defs","glyph","g","marker","mask","missing-glyph","pattern","svg","switch","symbol","use" -- cgit v1.2.3 From 7e85379f54292595afe296e5f0be240f6c8f7835 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Wed, 26 Feb 2014 02:08:53 +0100 Subject: Made constructors of tools use initializer lists. (bzr r13060) --- src/ui/tools/arc-tool.cpp | 49 +++++++++---------------- src/ui/tools/box3d-tool.cpp | 23 ++++-------- src/ui/tools/calligraphic-tool.cpp | 34 ++++++++---------- src/ui/tools/connector-tool.cpp | 73 +++++++++++++++----------------------- src/ui/tools/dropper-tool.cpp | 26 ++++++-------- src/ui/tools/dynamic-base.cpp | 69 +++++++++++++++++------------------ src/ui/tools/dynamic-base.h | 8 ++--- src/ui/tools/eraser-tool.cpp | 7 ++-- src/ui/tools/flood-tool.cpp | 15 +++----- src/ui/tools/freehand-base.cpp | 56 +++++++++++++---------------- src/ui/tools/freehand-base.h | 4 +-- src/ui/tools/gradient-tool.cpp | 22 +++++------- src/ui/tools/lpe-tool.cpp | 18 +++++----- src/ui/tools/measure-tool.cpp | 10 +++--- src/ui/tools/mesh-tool.cpp | 24 ++++++------- src/ui/tools/node-tool.cpp | 45 +++++++++++------------ src/ui/tools/pen-tool.cpp | 65 ++++++++++++++++++++------------- src/ui/tools/pen-tool.h | 3 +- src/ui/tools/pencil-tool.cpp | 21 +++++------ src/ui/tools/rect-tool.cpp | 20 ++++------- src/ui/tools/select-tool.cpp | 36 +++++++++---------- src/ui/tools/select-tool.h | 4 +-- src/ui/tools/spiral-tool.cpp | 22 ++++-------- src/ui/tools/spray-tool.cpp | 53 +++++++++++++-------------- src/ui/tools/spray-tool.h | 8 ++--- src/ui/tools/star-tool.cpp | 28 +++++---------- src/ui/tools/text-tool.cpp | 51 +++++++++++--------------- src/ui/tools/text-tool.h | 10 +++--- src/ui/tools/tool-base.cpp | 42 +++++++++++----------- src/ui/tools/tool-base.h | 8 +++-- src/ui/tools/tweak-tool.cpp | 45 ++++++++++------------- src/ui/tools/tweak-tool.h | 6 ++-- src/ui/tools/zoom-tool.cpp | 11 +++--- 33 files changed, 402 insertions(+), 514 deletions(-) diff --git a/src/ui/tools/arc-tool.cpp b/src/ui/tools/arc-tool.cpp index bb7dfa21c..435f4aa4b 100644 --- a/src/ui/tools/arc-tool.cpp +++ b/src/ui/tools/arc-tool.cpp @@ -69,18 +69,10 @@ const std::string& ArcTool::getPrefsPath() { const std::string ArcTool::prefsPath = "/tools/shapes/arc"; -ArcTool::ArcTool() : ToolBase() { - this->cursor_shape = cursor_ellipse_xpm; - this->hot_x = 4; - this->hot_y = 4; - this->xp = 0; - this->yp = 0; - this->tolerance = 0; - this->within_tolerance = false; - this->item_to_select = NULL; - //this->tool_url = "/tools/shapes/arc"; - - this->arc = NULL; +ArcTool::ArcTool() + : ToolBase(cursor_ellipse_xpm, 4, 4) + , arc(NULL) +{ } void ArcTool::finish() { @@ -142,13 +134,10 @@ void ArcTool::setup() { } bool ArcTool::item_handler(SPItem* item, GdkEvent* event) { - gint ret = FALSE; - switch (event->type) { case GDK_BUTTON_PRESS: if (event->button.button == 1 && !this->space_panning) { Inkscape::setup_for_drag_start(desktop, this, event); - ret = TRUE; } break; // motion and release are always on root (why?) @@ -156,13 +145,7 @@ bool ArcTool::item_handler(SPItem* item, GdkEvent* event) { break; } -// if ((SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->item_handler) { -// ret = (SP_EVENT_CONTEXT_CLASS(sp_arc_context_parent_class))->item_handler(event_context, item, event); -// } - // CPPIFY: ret is overwritten... - ret = ToolBase::item_handler(item, event); - - return ret; + return ToolBase::item_handler(item, event); } bool ArcTool::root_handler(GdkEvent* event) { @@ -173,7 +156,7 @@ bool ArcTool::root_handler(GdkEvent* event) { this->tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100); - gint ret = FALSE; + bool handled = false; switch (event->type) { case GDK_BUTTON_PRESS: @@ -191,7 +174,7 @@ bool ArcTool::root_handler(GdkEvent* event) { GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK, NULL, event->button.time); - ret = TRUE; + handled = true; m.unSetup(); } break; @@ -214,7 +197,7 @@ bool ArcTool::root_handler(GdkEvent* event) { gobble_motion_events(GDK_BUTTON1_MASK); - ret = TRUE; + handled = true; } else if (!sp_event_context_knot_mouseover(this)){ SnapManager &m = desktop->namedview->snap_manager; m.setup(desktop); @@ -249,7 +232,7 @@ bool ArcTool::root_handler(GdkEvent* event) { this->xp = 0; this->yp = 0; this->item_to_select = NULL; - ret = TRUE; + handled = true; } sp_canvas_item_ungrab(SP_CANVAS_ITEM(desktop->acetate), event->button.time); break; @@ -278,14 +261,14 @@ bool ArcTool::root_handler(GdkEvent* event) { case GDK_KEY_KP_Down: // prevent the zoom field from activation if (!MOD__CTRL_ONLY(event)) - ret = TRUE; + handled = true; break; case GDK_KEY_x: case GDK_KEY_X: if (MOD__ALT_ONLY(event)) { desktop->setToolboxFocusTo ("altx-arc"); - ret = TRUE; + handled = true; } break; @@ -295,7 +278,7 @@ bool ArcTool::root_handler(GdkEvent* event) { sp_event_context_discard_delayed_snap_event(this); // if drawing, cancel, otherwise pass it up for deselecting this->cancel(); - ret = TRUE; + handled = true; } break; @@ -316,7 +299,7 @@ bool ArcTool::root_handler(GdkEvent* event) { case GDK_KEY_Delete: case GDK_KEY_KP_Delete: case GDK_KEY_BackSpace: - ret = this->deleteSelectedDrag(MOD__CTRL_ONLY(event)); + handled = this->deleteSelectedDrag(MOD__CTRL_ONLY(event)); break; default: @@ -346,11 +329,11 @@ bool ArcTool::root_handler(GdkEvent* event) { break; } - if (!ret) { - ret = ToolBase::root_handler(event); + if (!handled) { + handled = ToolBase::root_handler(event); } - return ret; + return handled; } void ArcTool::drag(Geom::Point pt, guint state) { diff --git a/src/ui/tools/box3d-tool.cpp b/src/ui/tools/box3d-tool.cpp index 2e345fef1..f0381a4a5 100644 --- a/src/ui/tools/box3d-tool.cpp +++ b/src/ui/tools/box3d-tool.cpp @@ -72,22 +72,13 @@ const std::string& Box3dTool::getPrefsPath() { const std::string Box3dTool::prefsPath = "/tools/shapes/3dbox"; -Box3dTool::Box3dTool() : ToolBase() { - this->cursor_shape = cursor_3dbox_xpm; - this->hot_x = 4; - this->hot_y = 4; - this->xp = 0; - this->yp = 0; - this->tolerance = 0; - this->within_tolerance = false; - this->item_to_select = NULL; - - this->box3d = NULL; - - this->ctrl_dragged = false; - this->extruded = false; - - this->_vpdrag = NULL; +Box3dTool::Box3dTool() + : ToolBase(cursor_3dbox_xpm, 4, 4) + , _vpdrag(NULL) + , box3d(NULL) + , ctrl_dragged(false) + , extruded(false) +{ } void Box3dTool::finish() { diff --git a/src/ui/tools/calligraphic-tool.cpp b/src/ui/tools/calligraphic-tool.cpp index 2c5e6561c..64097e834 100644 --- a/src/ui/tools/calligraphic-tool.cpp +++ b/src/ui/tools/calligraphic-tool.cpp @@ -105,30 +105,24 @@ const std::string& CalligraphicTool::getPrefsPath() { const std::string CalligraphicTool::prefsPath = "/tools/calligraphic"; -CalligraphicTool::CalligraphicTool() : DynamicBase() { - this->cursor_shape = cursor_calligraphy_xpm; - this->hot_x = 4; - this->hot_y = 4; - +CalligraphicTool::CalligraphicTool() + : DynamicBase(cursor_calligraphy_xpm, 4, 4) + , keep_selected(true) + , hatch_spacing(0) + , hatch_spacing_step(0) + , hatch_item(NULL) + , hatch_livarot_path(NULL) + , hatch_last_nearest(Geom::Point(0,0)) + , hatch_last_pointer(Geom::Point(0,0)) + , hatch_escaped(false) + , hatch_area(NULL) + , just_started_drawing(false) + , trace_bg(false) +{ this->vel_thin = 0.1; this->flatness = 0.9; this->cap_rounding = 0.0; - this->abs_width = false; - this->keep_selected = true; - - this->hatch_spacing = 0; - this->hatch_spacing_step = 0; - - this->hatch_last_nearest = Geom::Point(0,0); - this->hatch_last_pointer = Geom::Point(0,0); - this->hatch_escaped = false; - this->hatch_area = NULL; - this->hatch_item = NULL; - this->hatch_livarot_path = NULL; - - this->trace_bg = false; - this->just_started_drawing = false; } CalligraphicTool::~CalligraphicTool() { diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp index 50cb00360..391bae2e5 100644 --- a/src/ui/tools/connector-tool.cpp +++ b/src/ui/tools/connector-tool.cpp @@ -182,54 +182,39 @@ const std::string& ConnectorTool::getPrefsPath() { const std::string ConnectorTool::prefsPath = "/tools/connector"; -ConnectorTool::ConnectorTool() : ToolBase() { - this->red_curve = 0; - this->isOrthogonal = false; - this->c1 = 0; - this->red_bpath = 0; - this->green_curve = 0; - this->selection = 0; - this->cl0 = 0; - this->cl1 = 0; - this->c0 = 0; - - this->cursor_shape = cursor_connector_xpm; - this->hot_x = 1; - this->hot_y = 1; - this->xp = 0; - this->yp = 0; - - this->red_color = 0xff00007f; - - this->newconn = NULL; - this->newConnRef = NULL; - this->curvature = 0.0; - - this->sel_changed_connection = sigc::connection(); - - this->active_shape = NULL; - this->active_shape_repr = NULL; - this->active_shape_layer_repr = NULL; - - this->active_conn = NULL; - this->active_conn_repr = NULL; - - this->active_handle = NULL; - - this->selected_handle = NULL; - - this->clickeditem = NULL; - this->clickedhandle = NULL; - +ConnectorTool::ConnectorTool() + : ToolBase(cursor_connector_xpm, 1, 1) + , selection(NULL) + , npoints(0) + , state(SP_CONNECTOR_CONTEXT_IDLE) + , red_bpath(NULL) + , red_curve(NULL) + , red_color(0xff00007f) + , green_curve(NULL) + , newconn(NULL) + , newConnRef(NULL) + , curvature(0.0) + , isOrthogonal(false) + , active_shape(NULL) + , active_shape_repr(NULL) + , active_shape_layer_repr(NULL) + , active_conn(NULL) + , active_conn_repr(NULL) + , active_handle(NULL) + , selected_handle(NULL) + , clickeditem(NULL) + , clickedhandle(NULL) + , shref(NULL) + , ehref(NULL) + , c0(NULL) + , c1(NULL) + , cl0(NULL) + , cl1(NULL) +{ for (int i = 0; i < 2; ++i) { this->endpt_handle[i] = NULL; this->endpt_handler_id[i] = 0; } - - this->shref = NULL; - this->ehref = NULL; - this->npoints = 0; - this->state = SP_CONNECTOR_CONTEXT_IDLE; } ConnectorTool::~ConnectorTool() { diff --git a/src/ui/tools/dropper-tool.cpp b/src/ui/tools/dropper-tool.cpp index 88ed342df..e9e2d6c39 100644 --- a/src/ui/tools/dropper-tool.cpp +++ b/src/ui/tools/dropper-tool.cpp @@ -72,21 +72,17 @@ const std::string& DropperTool::getPrefsPath() { const std::string DropperTool::prefsPath = "/tools/dropper"; -DropperTool::DropperTool() : ToolBase() { - this->R = 0; - this->G = 0; - this->B = 0; - this->alpha = 0; - this->dragging = false; - - this->grabbed = 0; - this->area = 0; - this->centre = Geom::Point(0, 0); - - this->cursor_shape = cursor_dropper_f_xpm; - this->hot_x = 7; - this->hot_y = 7; - +DropperTool::DropperTool() + : ToolBase(cursor_dropper_f_xpm, 7, 7) + , R(0) + , G(0) + , B(0) + , alpha(0) + , dragging(false) + , grabbed(NULL) + , area(NULL) + , centre(0, 0) +{ cursor_dropper_fill = sp_cursor_new_from_xpm(cursor_dropper_f_xpm , 7, 7); cursor_dropper_stroke = sp_cursor_new_from_xpm(cursor_dropper_s_xpm , 7, 7); } diff --git a/src/ui/tools/dynamic-base.cpp b/src/ui/tools/dynamic-base.cpp index cec58dce9..21b4b0532 100644 --- a/src/ui/tools/dynamic-base.cpp +++ b/src/ui/tools/dynamic-base.cpp @@ -23,40 +23,41 @@ namespace Inkscape { namespace UI { namespace Tools { -DynamicBase::DynamicBase() : - ToolBase(), - accumulated(NULL), - segments(NULL), - currentshape(NULL), - currentcurve(NULL), - cal1(NULL), - cal2(NULL), - point1(), - point2(), - repr(NULL), - cur(0,0), - vel(0,0), - vel_max(0), - acc(0,0), - ang(0,0), - last(0,0), - del(0,0), - pressure(DEFAULT_PRESSURE), - xtilt(0), - ytilt(0), - dragging(FALSE), - usepressure(FALSE), - usetilt(FALSE), - mass(0.3), - drag(DRAG_DEFAULT), - angle(30.0), - width(0.2), - vel_thin(0.1), - flatness(0.9), - tremor(0), - cap_rounding(0), - is_drawing(false), - abs_width(false) +DynamicBase::DynamicBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y) + : ToolBase(cursor_shape, hot_x, hot_y) + , accumulated(NULL) + , segments(NULL) + , currentshape(NULL) + , currentcurve(NULL) + , cal1(NULL) + , cal2(NULL) + , point1() + , point2() + , npoints(0) + , repr(NULL) + , cur(0, 0) + , vel(0, 0) + , vel_max(0) + , acc(0, 0) + , ang(0, 0) + , last(0, 0) + , del(0, 0) + , pressure(DEFAULT_PRESSURE) + , xtilt(0) + , ytilt(0) + , dragging(false) + , usepressure(false) + , usetilt(false) + , mass(0.3) + , drag(DRAG_DEFAULT) + , angle(30.0) + , width(0.2) + , vel_thin(0.1) + , flatness(0.9) + , tremor(0) + , cap_rounding(0) + , is_drawing(false) + , abs_width(false) { } diff --git a/src/ui/tools/dynamic-base.h b/src/ui/tools/dynamic-base.h index 9218eabd3..76fcd0f02 100644 --- a/src/ui/tools/dynamic-base.h +++ b/src/ui/tools/dynamic-base.h @@ -31,7 +31,7 @@ namespace Tools { class DynamicBase : public ToolBase { public: - DynamicBase(); + DynamicBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y); virtual ~DynamicBase(); virtual void set(const Inkscape::Preferences::Entry& val); @@ -81,9 +81,9 @@ protected: gdouble ytilt; /* attributes */ - guint dragging : 1; /* mouse state: mouse is dragging */ - guint usepressure : 1; - guint usetilt : 1; + bool dragging; /* mouse state: mouse is dragging */ + bool usepressure; + bool usetilt; double mass, drag; double angle; double width; diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp index 270987d27..011d28663 100644 --- a/src/ui/tools/eraser-tool.cpp +++ b/src/ui/tools/eraser-tool.cpp @@ -103,10 +103,9 @@ const std::string& EraserTool::getPrefsPath() { const std::string EraserTool::prefsPath = "/tools/eraser"; -EraserTool::EraserTool() : DynamicBase() { - this->cursor_shape = cursor_eraser_xpm; - this->hot_x = 4; - this->hot_y = 4; +EraserTool::EraserTool() + : DynamicBase(cursor_eraser_xpm, 4, 4) +{ } EraserTool::~EraserTool() { diff --git a/src/ui/tools/flood-tool.cpp b/src/ui/tools/flood-tool.cpp index 4e29b8856..d74848dc6 100644 --- a/src/ui/tools/flood-tool.cpp +++ b/src/ui/tools/flood-tool.cpp @@ -94,17 +94,12 @@ const std::string& FloodTool::getPrefsPath() { const std::string FloodTool::prefsPath = "/tools/paintbucket"; -FloodTool::FloodTool() : ToolBase() { - this->cursor_shape = cursor_paintbucket_xpm; - this->hot_x = 11; - this->hot_y = 30; - this->xp = 0; - this->yp = 0; +FloodTool::FloodTool() + : ToolBase(cursor_paintbucket_xpm, 11, 30) + , item(NULL) +{ + // TODO: Why does the flood tool use a hardcoded tolerance instead of a pref? this->tolerance = 4; - this->within_tolerance = false; - this->item_to_select = NULL; - - this->item = NULL; } FloodTool::~FloodTool() { diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp index 1e0e6b3b6..2fb4a3481 100644 --- a/src/ui/tools/freehand-base.cpp +++ b/src/ui/tools/freehand-base.cpp @@ -70,37 +70,31 @@ static void spdc_flush_white(FreehandBase *dc, SPCurve *gc); static void spdc_reset_white(FreehandBase *dc); static void spdc_free_colors(FreehandBase *dc); -FreehandBase::FreehandBase() : ToolBase() { - this->selection = 0; - this->grab = 0; - this->anchor_statusbar = false; - - this->attach = FALSE; - - this->red_color = 0xff00007f; - this->blue_color = 0x0000ff7f; - this->green_color = 0x00ff007f; - this->red_curve_is_valid = false; - - this->red_bpath = NULL; - this->red_curve = NULL; - - this->blue_bpath = NULL; - this->blue_curve = NULL; - - this->green_bpaths = NULL; - this->green_curve = NULL; - this->green_anchor = NULL; - this->green_closed = false; - - this->white_item = NULL; - this->white_curves = NULL; - this->white_anchors = NULL; - - this->sa = NULL; - this->ea = NULL; - - this->waiting_LPE_type = Inkscape::LivePathEffect::INVALID_LPE; +FreehandBase::FreehandBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y) + : ToolBase(cursor_shape, hot_x, hot_y) + , selection(NULL) + , grab(NULL) + , attach(false) + , red_color(0xff00007f) + , blue_color(0x0000ff7f) + , green_color(0x00ff007f) + , red_bpath(NULL) + , red_curve(NULL) + , blue_bpath(NULL) + , blue_curve(NULL) + , green_bpaths(NULL) + , green_curve(NULL) + , green_anchor(NULL) + , green_closed(false) + , white_item(NULL) + , white_curves(NULL) + , white_anchors(NULL) + , sa(NULL) + , ea(NULL) + , waiting_LPE_type(Inkscape::LivePathEffect::INVALID_LPE) + , red_curve_is_valid(false) + , anchor_statusbar(false) +{ } FreehandBase::~FreehandBase() { diff --git a/src/ui/tools/freehand-base.h b/src/ui/tools/freehand-base.h index 7e53684e3..c8da9faed 100644 --- a/src/ui/tools/freehand-base.h +++ b/src/ui/tools/freehand-base.h @@ -37,13 +37,13 @@ namespace Tools { class FreehandBase : public ToolBase { public: - FreehandBase(); + FreehandBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y); virtual ~FreehandBase(); Inkscape::Selection *selection; SPCanvasItem *grab; - guint attach : 1; + bool attach; guint32 red_color; guint32 blue_color; diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp index 10f78a8a8..a0bbfbaf1 100644 --- a/src/ui/tools/gradient-tool.cpp +++ b/src/ui/tools/gradient-tool.cpp @@ -74,20 +74,16 @@ const std::string& GradientTool::getPrefsPath() { const std::string GradientTool::prefsPath = "/tools/gradient"; -GradientTool::GradientTool() : ToolBase() { - this->node_added = false; - this->subselcon = 0; - this->selcon = 0; - - this->cursor_addnode = false; - this->cursor_shape = cursor_gradient_xpm; - this->hot_x = 4; - this->hot_y = 4; - this->xp = 0; - this->yp = 0; +GradientTool::GradientTool() + : ToolBase(cursor_gradient_xpm, 4, 4) + , cursor_addnode(false) + , node_added(false) +// TODO: Why are these connections stored as pointers? + , selcon(NULL) + , subselcon(NULL) +{ + // TODO: This value is overwritten in the root handler this->tolerance = 6; - this->within_tolerance = false; - this->item_to_select = NULL; } GradientTool::~GradientTool() { diff --git a/src/ui/tools/lpe-tool.cpp b/src/ui/tools/lpe-tool.cpp index a5406f1c5..6c41bb160 100644 --- a/src/ui/tools/lpe-tool.cpp +++ b/src/ui/tools/lpe-tool.cpp @@ -81,16 +81,14 @@ const std::string& LpeTool::getPrefsPath() { const std::string LpeTool::prefsPath = "/tools/lpetool"; -LpeTool::LpeTool() : PenTool() { - this->mode = Inkscape::LivePathEffect::BEND_PATH; - this->shape_editor = 0; - - this->cursor_shape = cursor_crosshairs_xpm; - this->hot_x = 7; - this->hot_y = 7; - - this->canvas_bbox = NULL; - this->measuring_items = new std::map; +LpeTool::LpeTool() + : PenTool(cursor_crosshairs_xpm, 7, 7) + , shape_editor(NULL) + , canvas_bbox(NULL) + , mode(Inkscape::LivePathEffect::BEND_PATH) +// TODO: pointer? + , measuring_items(new std::map) +{ } LpeTool::~LpeTool() { diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp index 4d7f1e074..380aa79e3 100644 --- a/src/ui/tools/measure-tool.cpp +++ b/src/ui/tools/measure-tool.cpp @@ -236,12 +236,10 @@ void createAngleDisplayCurve(SPDesktop *desktop, Geom::Point const ¢er, Geom } // namespace -MeasureTool::MeasureTool() : ToolBase() { - this->grabbed = 0; - - this->cursor_shape = cursor_measure_xpm; - this->hot_x = 4; - this->hot_y = 4; +MeasureTool::MeasureTool() + : ToolBase(cursor_measure_xpm, 4, 4) + , grabbed(NULL) +{ } MeasureTool::~MeasureTool() { diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp index 4e7617f44..7d6d3bc23 100644 --- a/src/ui/tools/mesh-tool.cpp +++ b/src/ui/tools/mesh-tool.cpp @@ -75,20 +75,18 @@ const std::string& MeshTool::getPrefsPath() { const std::string MeshTool::prefsPath = "/tools/mesh"; -MeshTool::MeshTool() : ToolBase() { - this->selcon = 0; - this->node_added = false; - this->subselcon = 0; - - this->cursor_addnode = false; - this->cursor_shape = cursor_gradient_xpm; - this->hot_x = 4; - this->hot_y = 4; - this->xp = 0; - this->yp = 0; +// TODO: The gradient tool class looks like a 1:1 copy. + +MeshTool::MeshTool() + : ToolBase(cursor_gradient_xpm, 4, 4) + , cursor_addnode(false) + , node_added(false) +// TODO: Why are these connections stored as pointers? + , selcon(NULL) + , subselcon(NULL) +{ + // TODO: This value is overwritten in the root handler this->tolerance = 6; - this->within_tolerance = false; - this->item_to_select = NULL; } MeshTool::~MeshTool() { diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp index 7e33b1a4c..b1e11bd66 100644 --- a/src/ui/tools/node-tool.cpp +++ b/src/ui/tools/node-tool.cpp @@ -126,30 +126,27 @@ const std::string NodeTool::prefsPath = "/tools/nodes"; SPCanvasGroup *create_control_group(SPDesktop *d); -NodeTool::NodeTool() : ToolBase() { - this->show_handles = false; - this->single_node_transform_handles = false; - this->show_transform_handles = false; - this->cursor_drag = false; - this->live_objects = false; - this->edit_clipping_paths = false; - this->live_outline = false; - this->flashed_item = 0; - this->_transform_handle_group = 0; - this->show_path_direction = false; - this->_last_over = 0; - this->edit_masks = false; - this->show_outline = false; - this->flash_tempitem = 0; - - this->cursor_shape = cursor_node_xpm; - this->hot_x = 1; - this->hot_y = 1; - - this->_selected_nodes = 0; - this->_multipath = 0; - this->_selector = 0; - this->_path_data = 0; +NodeTool::NodeTool() + : ToolBase(cursor_node_xpm, 1, 1) + , _selected_nodes(NULL) + , _multipath(NULL) + , edit_clipping_paths(false) + , edit_masks(false) + , flashed_item(NULL) + , flash_tempitem(NULL) + , _selector(NULL) + , _path_data(NULL) + , _transform_handle_group(NULL) + , _last_over(NULL) + , cursor_drag(false) + , show_handles(false) + , show_outline(false) + , live_outline(false) + , live_objects(false) + , show_path_direction(false) + , show_transform_handles(false) + , single_node_transform_handles(false) +{ } SPCanvasGroup *create_control_group(SPDesktop *d) diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp index dc5e801c0..39b69f576 100644 --- a/src/ui/tools/pen-tool.cpp +++ b/src/ui/tools/pen-tool.cpp @@ -89,29 +89,44 @@ const std::string& PenTool::getPrefsPath() { const std::string PenTool::prefsPath = "/tools/freehand/pen"; -PenTool::PenTool() : FreehandBase() { - this->polylines_only = false; - this->polylines_paraxial = false; - this->expecting_clicks_for_LPE = 0; - - this->cursor_shape = cursor_pen_xpm; - this->hot_x = 4; - this->hot_y = 4; - - this->npoints = 0; - this->mode = MODE_CLICK; - this->state = POINT; - - this->c0 = NULL; - this->c1 = NULL; - this->cl0 = NULL; - this->cl1 = NULL; - - this->events_disabled = 0; +PenTool::PenTool() + : FreehandBase(cursor_pen_xpm, 4, 4) + , p() + , npoints(0) + , mode(MODE_CLICK) + , state(POINT) + , polylines_only(false) + , polylines_paraxial(false) + , num_clicks(0) + , expecting_clicks_for_LPE(0) + , waiting_LPE(NULL) + , waiting_item(NULL) + , c0(NULL) + , c1(NULL) + , cl0(NULL) + , cl1(NULL) + , events_disabled(false) +{ +} - this->num_clicks = 0; - this->waiting_LPE = NULL; - this->waiting_item = NULL; +PenTool::PenTool(gchar const *const *cursor_shape, gint hot_x, gint hot_y) + : FreehandBase(cursor_shape, hot_x, hot_y) + , p() + , npoints(0) + , mode(MODE_CLICK) + , state(POINT) + , polylines_only(false) + , polylines_paraxial(false) + , num_clicks(0) + , expecting_clicks_for_LPE(0) + , waiting_LPE(NULL) + , waiting_item(NULL) + , c0(NULL) + , c1(NULL) + , cl0(NULL) + , cl1(NULL) + , events_disabled(false) +{ } PenTool::~PenTool() { @@ -1305,13 +1320,13 @@ static void spdc_pen_finish(PenTool *const pc, gboolean const closed) } static void pen_disable_events(PenTool *const pc) { - pc->events_disabled++; + pc->events_disabled = true; } static void pen_enable_events(PenTool *const pc) { - g_return_if_fail(pc->events_disabled != 0); + g_return_if_fail(pc->events_disabled != 0); - pc->events_disabled--; + pc->events_disabled = false; } void sp_pen_context_wait_for_LPE_mouse_clicks(PenTool *pc, Inkscape::LivePathEffect::EffectType effect_type, diff --git a/src/ui/tools/pen-tool.h b/src/ui/tools/pen-tool.h index 4452dbd68..f2b1ee04a 100644 --- a/src/ui/tools/pen-tool.h +++ b/src/ui/tools/pen-tool.h @@ -23,6 +23,7 @@ namespace Tools { class PenTool : public FreehandBase { public: PenTool(); + PenTool(gchar const *const *cursor_shape, gint hot_x, gint hot_y); virtual ~PenTool(); enum Mode { @@ -60,7 +61,7 @@ public: SPCtrlLine *cl0; SPCtrlLine *cl1; - unsigned int events_disabled : 1; + bool events_disabled; static const std::string prefsPath; diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp index 52779d551..4fbaa50f3 100644 --- a/src/ui/tools/pencil-tool.cpp +++ b/src/ui/tools/pencil-tool.cpp @@ -83,20 +83,15 @@ const std::string& PencilTool::getPrefsPath() { const std::string PencilTool::prefsPath = "/tools/freehand/pencil"; -PencilTool::PencilTool() : - FreehandBase(), - p(), - npoints(0), - state(SP_PENCIL_CONTEXT_IDLE), - req_tangent(0,0), - is_drawing(false), - ps(), - sketch_interpolation(Geom::Piecewise >())// since PencilTool is not properly constructed... +PencilTool::PencilTool() + : FreehandBase(cursor_pencil_xpm, 4, 4) + , p() + , npoints(0) + , state(SP_PENCIL_CONTEXT_IDLE) + , req_tangent(0, 0) + , is_drawing(false) + , sketch_n(0) { - this->cursor_shape = cursor_pencil_xpm; - this->hot_x = 4; - this->hot_y = 4; - this->sketch_n = 0; } void PencilTool::setup() { diff --git a/src/ui/tools/rect-tool.cpp b/src/ui/tools/rect-tool.cpp index 263fdea84..f5153e8ce 100644 --- a/src/ui/tools/rect-tool.cpp +++ b/src/ui/tools/rect-tool.cpp @@ -66,20 +66,12 @@ const std::string& RectTool::getPrefsPath() { const std::string RectTool::prefsPath = "/tools/shapes/rect"; -RectTool::RectTool() : ToolBase() { - this->cursor_shape = cursor_rect_xpm; - this->hot_x = 4; - this->hot_y = 4; - this->xp = 0; - this->yp = 0; - this->tolerance = 0; - this->within_tolerance = false; - this->item_to_select = NULL; - - this->rect = NULL; - - this->rx = 0.0; - this->ry = 0.0; +RectTool::RectTool() + : ToolBase(cursor_rect_xpm, 4, 4) + , rect(NULL) + , rx(0) + , ry(0) +{ } void RectTool::finish() { diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp index 498882417..85bc3fd4a 100644 --- a/src/ui/tools/select-tool.cpp +++ b/src/ui/tools/select-tool.cpp @@ -90,24 +90,24 @@ sp_load_handles(int start, int count, char const **xpm) { } } -SelectTool::SelectTool() : ToolBase() { - this->grabbed = 0; - this->item = 0; - - this->dragging = FALSE; - this->moved = FALSE; - this->button_press_shift = false; - this->button_press_ctrl = false; - this->button_press_alt = false; - this->cycling_items = NULL; - this->cycling_items_cmp = NULL; - this->cycling_items_selected_before = NULL; - this->cycling_cur_item = NULL; - this->cycling_wrap = true; - this->_seltrans = NULL; - this->_describer = NULL; - - +SelectTool::SelectTool() + // Don't load a default cursor + : ToolBase(NULL, 0, 0) + , dragging(false) + , moved(false) + , button_press_shift(false) + , button_press_ctrl(false) + , button_press_alt(false) + , cycling_items(NULL) + , cycling_items_cmp(NULL) + , cycling_items_selected_before(NULL) + , cycling_cur_item(NULL) + , cycling_wrap(true) + , item(NULL) + , grabbed(NULL) + , _seltrans(NULL) + , _describer(NULL) +{ // cursors in select context CursorSelectMouseover = sp_cursor_new_from_xpm(cursor_select_m_xpm , 1, 1); CursorSelectDragging = sp_cursor_new_from_xpm(cursor_select_d_xpm , 1, 1); diff --git a/src/ui/tools/select-tool.h b/src/ui/tools/select-tool.h index b26fc03bc..81763e8b1 100644 --- a/src/ui/tools/select-tool.h +++ b/src/ui/tools/select-tool.h @@ -35,8 +35,8 @@ public: SelectTool(); virtual ~SelectTool(); - guint dragging : 1; - guint moved : 1; + bool dragging; + bool moved; bool button_press_shift; bool button_press_ctrl; bool button_press_alt; diff --git a/src/ui/tools/spiral-tool.cpp b/src/ui/tools/spiral-tool.cpp index 005b2d239..7d33b0f67 100644 --- a/src/ui/tools/spiral-tool.cpp +++ b/src/ui/tools/spiral-tool.cpp @@ -65,21 +65,13 @@ const std::string& SpiralTool::getPrefsPath() { const std::string SpiralTool::prefsPath = "/tools/shapes/spiral"; -SpiralTool::SpiralTool() : ToolBase() { - this->cursor_shape = cursor_spiral_xpm; - this->hot_x = 4; - this->hot_y = 4; - this->xp = 0; - this->yp = 0; - this->tolerance = 0; - this->within_tolerance = false; - this->item_to_select = NULL; - - this->spiral = NULL; - - this->revo = 3.0; - this->exp = 1.0; - this->t0 = 0.0; +SpiralTool::SpiralTool() + : ToolBase(cursor_spiral_xpm, 4, 4) + , spiral(NULL) + , revo(3) + , exp(1) + , t0(0) +{ } void SpiralTool::finish() { diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp index 14a3acd9a..2fc3f1c91 100644 --- a/src/ui/tools/spray-tool.cpp +++ b/src/ui/tools/spray-tool.cpp @@ -134,35 +134,30 @@ static void sp_spray_scale_rel(Geom::Point c, SPDesktop */*desktop*/, SPItem *it item->doWriteTransform(item->getRepr(), item->transform); } -SprayTool::SprayTool() : ToolBase() { - this->usetilt = 0; - this->dilate_area = 0; - this->usetext = false; - this->population = 0; - this->is_drawing = false; - this->mode = 0; - this->usepressure = 0; - - this->cursor_shape = cursor_spray_xpm; - this->hot_x = 4; - this->hot_y = 4; - - /* attributes */ - this->dragging = FALSE; - this->distrib = 1; - this->width = 0.2; - this->force = 0.2; - this->ratio = 0; - this->tilt = 0; - this->mean = 0.2; - this->rotation_variation = 0; - this->standard_deviation = 0.2; - this->scale = 1; - this->scale_variation = 1; - this->pressure = TC_DEFAULT_PRESSURE; - - this->is_dilating = false; - this->has_dilated = false; +SprayTool::SprayTool() + : ToolBase(cursor_spray_xpm, 4, 4) + , pressure(TC_DEFAULT_PRESSURE) + , dragging(false) + , usepressure(0) + , usetilt(0) + , usetext(false) + , width(0.2) + , ratio(0) + , tilt(0) + , rotation_variation(0) + , force(0.2) + , population(0) + , scale_variation(1) + , scale(1) + , mean(0.2) + , standard_deviation(0.2) + , distrib(1) + , mode(0) + , is_drawing(false) + , is_dilating(false) + , has_dilated(false) + , dilate_area(NULL) +{ } SprayTool::~SprayTool() { diff --git a/src/ui/tools/spray-tool.h b/src/ui/tools/spray-tool.h index e7362fd50..1a8f98006 100644 --- a/src/ui/tools/spray-tool.h +++ b/src/ui/tools/spray-tool.h @@ -61,10 +61,10 @@ public: gdouble pressure; /* attributes */ - guint dragging : 1; /* mouse state: mouse is dragging */ - guint usepressure : 1; - guint usetilt : 1; - bool usetext ; + bool dragging; /* mouse state: mouse is dragging */ + bool usepressure; + bool usetilt; + bool usetext; double width; double ratio; diff --git a/src/ui/tools/star-tool.cpp b/src/ui/tools/star-tool.cpp index b5d8c4418..42010788f 100644 --- a/src/ui/tools/star-tool.cpp +++ b/src/ui/tools/star-tool.cpp @@ -69,25 +69,15 @@ const std::string& StarTool::getPrefsPath() { const std::string StarTool::prefsPath = "/tools/shapes/star"; -StarTool::StarTool() : ToolBase() { - this->randomized = 0; - this->rounded = 0; - - this->cursor_shape = cursor_star_xpm; - this->hot_x = 4; - this->hot_y = 4; - this->xp = 0; - this->yp = 0; - this->tolerance = 0; - this->within_tolerance = false; - this->item_to_select = NULL; - //this->tool_url = "/tools/shapes/star"; - - this->star = NULL; - - this->magnitude = 5; - this->proportion = 0.5; - this->isflatsided = false; +StarTool::StarTool() + : ToolBase(cursor_star_xpm, 4, 4) + , star(NULL) + , magnitude(5) + , proportion(0.5) + , isflatsided(false) + , rounded(0) + , randomized(0) +{ } void StarTool::finish() { diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp index ba68c7829..00f6a853c 100644 --- a/src/ui/tools/text-tool.cpp +++ b/src/ui/tools/text-tool.cpp @@ -91,37 +91,26 @@ const std::string& TextTool::getPrefsPath() { const std::string TextTool::prefsPath = "/tools/text"; -TextTool::TextTool() : ToolBase() { - this->preedit_string = 0; - this->unipos = 0; - - this->cursor_shape = cursor_text_xpm; - this->hot_x = 7; - this->hot_y = 7; - - this->xp = 0; - this->yp = 0; - this->tolerance = 0; - this->within_tolerance = false; - - this->imc = NULL; - - this->text = NULL; - this->pdoc = Geom::Point(0, 0); - - this->unimode = false; - - this->cursor = NULL; - this->indicator = NULL; - this->frame = NULL; - this->grabbed = NULL; - this->timeout = 0; - this->show = FALSE; - this->phase = 0; - this->nascent_object = 0; - this->over_text = 0; - this->dragging = 0; - this->creating = 0; +TextTool::TextTool() + : ToolBase(cursor_text_xpm, 7, 7) + , imc(NULL) + , text(NULL) + , pdoc(0, 0) + , unimode(false) + , unipos(0) + , cursor(NULL) + , indicator(NULL) + , frame(NULL) + , timeout(0) + , show(false) + , phase(false) + , nascent_object(false) + , over_text(false) + , dragging(0) + , creating(false) + , grabbed(NULL) + , preedit_string(NULL) +{ } TextTool::~TextTool() { diff --git a/src/ui/tools/text-tool.h b/src/ui/tools/text-tool.h index ef8a67984..c5336d378 100644 --- a/src/ui/tools/text-tool.h +++ b/src/ui/tools/text-tool.h @@ -61,15 +61,15 @@ public: SPCanvasItem *frame; // hiliting the first frame of flowtext; FIXME: make this a list to accommodate arbitrarily many chained shapes std::vector text_selection_quads; gint timeout; - guint show : 1; - guint phase : 1; - guint nascent_object : 1; // true if we're clicked on canvas to put cursor, but no text typed yet so ->text is still NULL + bool show; + bool phase; + bool nascent_object; // true if we're clicked on canvas to put cursor, but no text typed yet so ->text is still NULL - guint over_text : 1; // true if cursor is over a text object + bool over_text; // true if cursor is over a text object guint dragging : 2; // dragging selection over text - guint creating : 1; // dragging rubberband to create flowtext + bool creating; // dragging rubberband to create flowtext SPCanvasItem *grabbed; // we grab while we are creating, to get events even if the mouse goes out of the window Geom::Point p0; // initial point if the flowtext rect diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp index cc028724a..dc10e9388 100644 --- a/src/ui/tools/tool-base.cpp +++ b/src/ui/tools/tool-base.cpp @@ -90,28 +90,26 @@ SPDesktop const& ToolBase::getDesktop() const { return *desktop; } -ToolBase::ToolBase() { - this->hot_y = 0; - this->xp = 0; - this->cursor_shape = 0; - this->pref_observer = 0; - this->hot_x = 0; - this->yp = 0; - this->within_tolerance = false; - this->tolerance = 0; - //this->key = 0; - this->item_to_select = 0; - - this->desktop = NULL; - this->cursor = NULL; - this->message_context = NULL; - this->_selcue = NULL; - this->_grdrag = NULL; - this->space_panning = false; - this->shape_editor = NULL; - this->_delayed_snap_event = NULL; - this->_dse_callback_in_process = false; - //this->tool_url = NULL; +ToolBase::ToolBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y) + : pref_observer(NULL) + , cursor(NULL) + , xp(0) + , yp(0) + , tolerance(0) + , within_tolerance(false) + , item_to_select(NULL) + , message_context(NULL) + , _selcue(NULL) + , _grdrag(NULL) + , shape_editor(NULL) + , space_panning(false) + , _delayed_snap_event(NULL) + , _dse_callback_in_process(false) + , desktop(NULL) + , cursor_shape(cursor_shape) + , hot_x(hot_x) + , hot_y(hot_y) +{ } ToolBase::~ToolBase() { diff --git a/src/ui/tools/tool-base.h b/src/ui/tools/tool-base.h index 43edc4bd7..a4a27a06c 100644 --- a/src/ui/tools/tool-base.h +++ b/src/ui/tools/tool-base.h @@ -110,7 +110,8 @@ public: void enableGrDrag (bool enable=true); bool deleteSelectedDrag(bool just_one); - ToolBase(); + ToolBase(gchar const *const *cursor_shape, gint hot_x, gint hot_y); + virtual ~ToolBase(); Inkscape::Preferences::Observer *pref_observer; @@ -179,8 +180,11 @@ public: SPDesktop *desktop; protected: + /// An xpm containing the shape of the tool's cursor. gchar const *const *cursor_shape; - gint hot_x, hot_y; ///< indicates the cursor's hot spot + + /// The cursor's hot spot + gint hot_x, hot_y; private: ToolBase(const ToolBase&); diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp index 0791eff5a..75650d3af 100644 --- a/src/ui/tools/tweak-tool.cpp +++ b/src/ui/tools/tweak-tool.cpp @@ -111,32 +111,25 @@ const std::string& TweakTool::getPrefsPath() { const std::string TweakTool::prefsPath = "/tools/tweak"; -TweakTool::TweakTool() : ToolBase() { - this->mode = 0; - this->dilate_area = 0; - this->usetilt = 0; - this->usepressure = 0; - this->is_drawing = false; - this->fidelity = 0; - - this->cursor_shape = cursor_push_xpm; - this->hot_x = 4; - this->hot_y = 4; - - /* attributes */ - this->dragging = FALSE; - - this->width = 0.2; - this->force = 0.2; - this->pressure = TC_DEFAULT_PRESSURE; - - this->is_dilating = false; - this->has_dilated = false; - - this->do_h = true; - this->do_s = true; - this->do_l = true; - this->do_o = false; +TweakTool::TweakTool() + : ToolBase(cursor_push_xpm, 4, 4) + , pressure(TC_DEFAULT_PRESSURE) + , dragging(false) + , usepressure(false) + , usetilt(false) + , width(0.2) + , force(0.2) + , fidelity(0) + , mode(0) + , is_drawing(false) + , is_dilating(false) + , has_dilated(false) + , dilate_area(NULL) + , do_h(true) + , do_s(true) + , do_l(true) + , do_o(false) +{ } TweakTool::~TweakTool() { diff --git a/src/ui/tools/tweak-tool.h b/src/ui/tools/tweak-tool.h index 6cbb9aded..7fe4b1856 100644 --- a/src/ui/tools/tweak-tool.h +++ b/src/ui/tools/tweak-tool.h @@ -50,9 +50,9 @@ public: gdouble pressure; /* attributes */ - guint dragging : 1; /* mouse state: mouse is dragging */ - guint usepressure : 1; - guint usetilt : 1; + bool dragging; /* mouse state: mouse is dragging */ + bool usepressure; + bool usetilt; double width; double force; diff --git a/src/ui/tools/zoom-tool.cpp b/src/ui/tools/zoom-tool.cpp index 0996e6cf4..9f99cfe2e 100644 --- a/src/ui/tools/zoom-tool.cpp +++ b/src/ui/tools/zoom-tool.cpp @@ -45,12 +45,11 @@ const std::string& ZoomTool::getPrefsPath() { const std::string ZoomTool::prefsPath = "/tools/zoom"; -ZoomTool::ZoomTool() : ToolBase() { - this->grabbed = 0; - this->cursor_shape = cursor_zoom_xpm; - this->hot_x = 6; - this->hot_y = 6; - this->escaped = false; +ZoomTool::ZoomTool() + : ToolBase(cursor_zoom_xpm, 6, 6) + , grabbed(NULL) + , escaped(false) +{ } ZoomTool::~ZoomTool() { -- cgit v1.2.3 From 21fa74799d08edc54fa6506e3f78fab04215241a Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Wed, 26 Feb 2014 20:31:49 +0100 Subject: Added template functions as a casting-macro replacement. (bzr r13061) --- src/ui/tools/tool-base.h | 24 +++++++++++++++++++++++- src/widgets/pencil-toolbar.cpp | 12 ++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/ui/tools/tool-base.h b/src/ui/tools/tool-base.h index a4a27a06c..79bdfe89d 100644 --- a/src/ui/tools/tool-base.h +++ b/src/ui/tools/tool-base.h @@ -215,9 +215,31 @@ void sp_toggle_dropper(SPDesktop *dt); bool sp_event_context_knot_mouseover(ToolBase *ec); +} // namespace Tools + +//#include + +namespace Tool { + +template +bool is_a(const T* t) { + //static_assert(std::is_base_of(), "Destination type not derived from ToolBase."); + //static_assert(std::is_convertible(), "Cannot cast passed pointer to ToolBase*."); + + return dynamic_cast(static_cast(t)) != NULL; } + +template +Derived* to(T* t) { + //static_assert(std::is_base_of(), "Destination type not derived from ToolBase."); + //static_assert(std::is_convertible(), "Cannot cast passed pointer to ToolBase*."); + + return dynamic_cast(static_cast(t)); } -} + +} // namespace Tool +} // namespace UI +} // namespace Inkscape #endif // SEEN_SP_EVENT_CONTEXT_H diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp index e8296f735..7ad23bbbd 100644 --- a/src/widgets/pencil-toolbar.cpp +++ b/src/widgets/pencil-toolbar.cpp @@ -102,8 +102,16 @@ static void freehand_mode_changed(EgeSelectOneAction* act, GObject* tbl) // in pen tool we have more options than in pencil tool; if one of them was chosen, we do any // preparatory work here - if (SP_IS_PEN_CONTEXT(desktop->event_context)) { - Inkscape::UI::Tools::PenTool *pc = SP_PEN_CONTEXT(desktop->event_context); + //if (SP_IS_PEN_CONTEXT(desktop->event_context)) { + // Inkscape::UI::Tools::PenTool *pc = SP_PEN_CONTEXT(desktop->event_context); + // sp_pen_context_set_polyline_mode(pc); + //} + + using namespace Inkscape::UI; + using Inkscape::UI::Tools::PenTool; + + if (Tool::is_a(desktop->event_context)) { + PenTool* pc = Tool::to(desktop->event_context); sp_pen_context_set_polyline_mode(pc); } } -- cgit v1.2.3