summaryrefslogtreecommitdiffstats
path: root/src/ui/tools
diff options
context:
space:
mode:
authorMichael Soegtrop <MSoegtrop@yahoo.de>2017-06-05 13:01:17 +0000
committerMichael Soegtrop <MSoegtrop@yahoo.de>2017-06-05 13:01:17 +0000
commite7248b2fa042f42a5c4dd14cd86ab6a5b4524059 (patch)
tree9097520c54e355ded9bd0b4d6618af4e8dacdd91 /src/ui/tools
parentupdated to latest trunk (diff)
parent[Bug #1695016] Xaml export misses some radialGradients. (diff)
downloadinkscape-e7248b2fa042f42a5c4dd14cd86ab6a5b4524059.tar.gz
inkscape-e7248b2fa042f42a5c4dd14cd86ab6a5b4524059.zip
updated to latest trunk
(bzr r14876.2.4)
Diffstat (limited to 'src/ui/tools')
-rw-r--r--src/ui/tools/Makefile_insert34
-rw-r--r--src/ui/tools/arc-tool.cpp3
-rw-r--r--src/ui/tools/box3d-tool.cpp15
-rw-r--r--src/ui/tools/calligraphic-tool.cpp24
-rw-r--r--src/ui/tools/connector-tool.cpp23
-rw-r--r--src/ui/tools/dropper-tool.cpp13
-rw-r--r--src/ui/tools/dynamic-base.cpp6
-rw-r--r--src/ui/tools/eraser-tool.cpp179
-rw-r--r--src/ui/tools/eraser-tool.h4
-rw-r--r--src/ui/tools/flood-tool.cpp81
-rw-r--r--src/ui/tools/freehand-base.cpp161
-rw-r--r--src/ui/tools/freehand-base.h6
-rw-r--r--src/ui/tools/gradient-tool.cpp46
-rw-r--r--src/ui/tools/lpe-tool.cpp9
-rw-r--r--src/ui/tools/measure-tool.cpp135
-rw-r--r--src/ui/tools/measure-tool.h9
-rw-r--r--src/ui/tools/mesh-tool.cpp499
-rw-r--r--src/ui/tools/mesh-tool.h28
-rw-r--r--src/ui/tools/node-tool.cpp65
-rw-r--r--src/ui/tools/node-tool.h9
-rw-r--r--src/ui/tools/pen-tool.cpp84
-rw-r--r--src/ui/tools/pencil-tool.cpp13
-rw-r--r--src/ui/tools/rect-tool.cpp7
-rw-r--r--src/ui/tools/select-tool.cpp319
-rw-r--r--src/ui/tools/select-tool.h3
-rw-r--r--src/ui/tools/spiral-tool.cpp5
-rw-r--r--src/ui/tools/spray-tool.cpp72
-rw-r--r--src/ui/tools/spray-tool.h9
-rw-r--r--src/ui/tools/star-tool.cpp5
-rw-r--r--src/ui/tools/text-tool.cpp62
-rw-r--r--src/ui/tools/text-tool.h1
-rw-r--r--src/ui/tools/tool-base.cpp183
-rw-r--r--src/ui/tools/tool-base.h1
-rw-r--r--src/ui/tools/tweak-tool.cpp219
-rw-r--r--src/ui/tools/zoom-tool.cpp21
35 files changed, 1305 insertions, 1048 deletions
diff --git a/src/ui/tools/Makefile_insert b/src/ui/tools/Makefile_insert
deleted file mode 100644
index 686dfedd8..000000000
--- a/src/ui/tools/Makefile_insert
+++ /dev/null
@@ -1,34 +0,0 @@
-## Makefile.am fragment sourced by src/Makefile.am.
-
-ink_common_sources += \
- ui/tools/arc-tool.cpp ui/tools/arc-tool.h \
- ui/tools/box3d-tool.cpp ui/tools/box3d-tool.h \
- ui/tools/calligraphic-tool.cpp ui/tools/calligraphic-tool.h \
- ui/tools/connector-tool.cpp ui/tools/connector-tool.h \
- ui/tools/dropper-tool.cpp ui/tools/dropper-tool.h \
- ui/tools/dynamic-base.cpp ui/tools/dynamic-base.h \
- ui/tools/eraser-tool.cpp ui/tools/eraser-tool.h \
- ui/tools/freehand-base.cpp ui/tools/freehand-base.h \
- ui/tools/gradient-tool.cpp ui/tools/gradient-tool.h \
- ui/tools/lpe-tool.cpp ui/tools/lpe-tool.h \
- ui/tools/measure-tool.cpp ui/tools/measure-tool.h \
- ui/tools/mesh-tool.cpp ui/tools/mesh-tool.h \
- ui/tools/node-tool.cpp ui/tools/node-tool.h \
- ui/tools/pen-tool.cpp ui/tools/pen-tool.h \
- ui/tools/pencil-tool.cpp ui/tools/pencil-tool.h \
- ui/tools/rect-tool.cpp ui/tools/rect-tool.h \
- ui/tools/select-tool.cpp ui/tools/select-tool.h \
- ui/tools/spiral-tool.cpp ui/tools/spiral-tool.h \
- ui/tools/spray-tool.cpp ui/tools/spray-tool.h \
- ui/tools/star-tool.cpp ui/tools/star-tool.h \
- ui/tools/text-tool.cpp ui/tools/text-tool.h \
- ui/tools/tool-base.cpp ui/tools/tool-base.h \
- ui/tools/tweak-tool.cpp ui/tools/tweak-tool.h \
- ui/tools/zoom-tool.cpp ui/tools/zoom-tool.h
-
-if HAVE_POTRACE
-
-ink_common_sources += \
- ui/tools/flood-tool.cpp ui/tools/flood-tool.h
-
-endif
diff --git a/src/ui/tools/arc-tool.cpp b/src/ui/tools/arc-tool.cpp
index c6a9bb23a..6652f7ab5 100644
--- a/src/ui/tools/arc-tool.cpp
+++ b/src/ui/tools/arc-tool.cpp
@@ -17,7 +17,7 @@
*/
#ifdef HAVE_CONFIG_H
-# include <config.h>
+#include <config.h>
#endif
#include <gdk/gdkkeysyms.h>
@@ -30,7 +30,6 @@
#include "sp-namedview.h"
#include "selection.h"
-#include "snap.h"
#include "pixmaps/cursor-ellipse.xpm"
#include "xml/repr.h"
#include "xml/node-event-vector.h"
diff --git a/src/ui/tools/box3d-tool.cpp b/src/ui/tools/box3d-tool.cpp
index 27e755add..425695a2c 100644
--- a/src/ui/tools/box3d-tool.cpp
+++ b/src/ui/tools/box3d-tool.cpp
@@ -15,8 +15,6 @@
* Released under GNU GPL, read the file 'COPYING' for more information
*/
-#include "config.h"
-
#include <gdk/gdkkeysyms.h>
#include "macros.h"
@@ -27,8 +25,6 @@
#include "selection.h"
#include "selection-chemistry.h"
-#include "snap.h"
-#include "display/curve.h"
#include "display/sp-canvas-item.h"
#include "desktop.h"
#include "message-context.h"
@@ -36,17 +32,12 @@
#include "box3d.h"
#include "ui/tools/box3d-tool.h"
#include <glibmm/i18n.h>
-#include "xml/repr.h"
#include "xml/node-event-vector.h"
-#include "preferences.h"
#include "context-fns.h"
#include "desktop-style.h"
-#include "transf_mat_3x4.h"
#include "perspective-line.h"
-#include "persp3d.h"
#include "box3d-side.h"
#include "document-private.h"
-#include "line-geometry.h"
#include "ui/shape-editor.h"
#include "verbs.h"
@@ -118,8 +109,8 @@ static void sp_box3d_context_ensure_persp_in_defs(SPDocument *document) {
SPDefs *defs = document->getDefs();
bool has_persp = false;
- for ( SPObject *child = defs->firstChild(); child; child = child->getNext() ) {
- if (SP_IS_PERSP3D(child)) {
+ for (auto& child: defs->children) {
+ if (SP_IS_PERSP3D(&child)) {
has_persp = true;
break;
}
@@ -409,7 +400,7 @@ bool Box3dTool::root_handler(GdkEvent* event) {
case GDK_KEY_g:
case GDK_KEY_G:
if (MOD__SHIFT_ONLY(event)) {
- sp_selection_to_guides(desktop);
+ desktop->selection->toGuides();
ret = true;
}
break;
diff --git a/src/ui/tools/calligraphic-tool.cpp b/src/ui/tools/calligraphic-tool.cpp
index 28195eb75..7228a52bc 100644
--- a/src/ui/tools/calligraphic-tool.cpp
+++ b/src/ui/tools/calligraphic-tool.cpp
@@ -23,8 +23,6 @@
#define noDYNA_DRAW_VERBOSE
-#include "config.h"
-
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <glibmm/i18n.h>
@@ -35,12 +33,10 @@
#include "svg/svg.h"
#include "display/canvas-bpath.h"
#include "display/cairo-utils.h"
-#include <2geom/math-utils.h>
#include <2geom/pathvector.h>
#include <2geom/bezier-utils.h>
#include <2geom/circle.h>
#include "display/curve.h"
-#include <glib.h>
#include "macros.h"
#include "document.h"
#include "document-undo.h"
@@ -50,25 +46,21 @@
#include "desktop-style.h"
#include "message-context.h"
-#include "preferences.h"
#include "pixmaps/cursor-calligraphy.xpm"
-#include "xml/repr.h"
#include "context-fns.h"
-#include "sp-item.h"
#include "inkscape.h"
-#include "color.h"
#include "splivarot.h"
#include "sp-item-group.h"
#include "sp-shape.h"
#include "sp-path.h"
#include "sp-text.h"
#include "display/sp-canvas.h"
-#include "display/canvas-bpath.h"
#include "display/canvas-arena.h"
#include "livarot/Shape.h"
#include "verbs.h"
#include "ui/tools/calligraphic-tool.h"
+#include "ui/tools/freehand-base.h"
using Inkscape::DocumentUndo;
@@ -144,7 +136,7 @@ void CalligraphicTool::setup() {
SPCurve *c = new SPCurve(path);
- this->hatch_area = sp_canvas_bpath_new(this->desktop->getControls(), c);
+ this->hatch_area = sp_canvas_bpath_new(this->desktop->getControls(), c, true);
c->unref();
@@ -780,6 +772,8 @@ bool CalligraphicTool::root_handler(GdkEvent* event) {
this->message_context->clear();
ret = TRUE;
+ } else if (!this->dragging && event->button.button == 1 && !this->space_panning){
+ spdc_create_single_dot(this, this->desktop->w2d(motion_w), "/tools/calligraphic", event->button.state);
}
break;
}
@@ -930,10 +924,10 @@ void CalligraphicTool::set_to_accumulated(bool unionize, bool subtract) {
if (unionize) {
desktop->getSelection()->add(this->repr);
- sp_selected_path_union_skip_undo(desktop->getSelection(), desktop);
+ desktop->getSelection()->pathUnion(true);
} else if (subtract) {
desktop->getSelection()->add(this->repr);
- sp_selected_path_diff_skip_undo(desktop->getSelection(), desktop);
+ desktop->getSelection()->pathDiff(true);
} else {
if (this->keep_selected) {
desktop->getSelection()->set(this->repr);
@@ -1099,7 +1093,7 @@ void CalligraphicTool::fit_and_split(bool release) {
add_cap(this->currentcurve, b2[0], b1[0], this->cap_rounding);
}
this->currentcurve->closepath();
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->currentshape), this->currentcurve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->currentshape), this->currentcurve, true);
}
/* Current calligraphic */
@@ -1135,7 +1129,7 @@ void CalligraphicTool::fit_and_split(bool release) {
SP_TYPE_CANVAS_BPATH,
NULL);
SPCurve *curve = this->currentcurve->copy();
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH (cbp), curve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH (cbp), curve, true);
curve->unref();
guint32 fillColor = sp_desktop_get_color_tool (desktop, "/tools/calligraphic", true);
@@ -1179,7 +1173,7 @@ void CalligraphicTool::draw_temporary_box() {
}
this->currentcurve->closepath();
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->currentshape), this->currentcurve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->currentshape), this->currentcurve, true);
}
}
diff --git a/src/ui/tools/connector-tool.cpp b/src/ui/tools/connector-tool.cpp
index 74f2664fe..7e6fb4b72 100644
--- a/src/ui/tools/connector-tool.cpp
+++ b/src/ui/tools/connector-tool.cpp
@@ -75,7 +75,6 @@
#include "ui/tools/connector-tool.h"
#include "pixmaps/cursor-connector.xpm"
#include "xml/node-event-vector.h"
-#include "xml/repr.h"
#include "svg/svg.h"
#include "desktop.h"
#include "desktop-style.h"
@@ -86,19 +85,13 @@
#include "message-stack.h"
#include "selection.h"
#include "inkscape.h"
-#include "preferences.h"
#include "sp-path.h"
#include "display/sp-canvas.h"
#include "display/canvas-bpath.h"
-#include "display/sodipodi-ctrl.h"
#include <glibmm/i18n.h>
#include <glibmm/stringutils.h>
#include "snap.h"
-#include "knot.h"
#include "sp-conn-end.h"
-#include "sp-conn-end-pair.h"
-#include "conn-avoid-ref.h"
-#include "libavoid/vertices.h"
#include "libavoid/router.h"
#include "context-fns.h"
#include "sp-namedview.h"
@@ -627,7 +620,7 @@ bool ConnectorTool::_handleMotionNotify(GdkEventMotion const &mevent) {
this->red_curve = path->get_curve_for_edit();
this->red_curve->transform(i2d);
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve, true);
ret = true;
break;
}
@@ -818,7 +811,7 @@ void ConnectorTool::_setSubsequentPoint(Geom::Point const p) {
// Recreate curve from libavoid route.
recreateCurve( this->red_curve, this->newConnRef, this->curvature );
this->red_curve->transform(desktop->doc2dt());
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve, true);
}
@@ -1042,7 +1035,7 @@ endpt_handler(SPKnot */*knot*/, GdkEvent *event, ConnectorTool *cc)
cc->red_curve = SP_PATH(cc->clickeditem)->get_curve_for_edit();
Geom::Affine i2d = (cc->clickeditem)->i2dt_affine();
cc->red_curve->transform(i2d);
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(cc->red_bpath), cc->red_curve, true);
cc->clickeditem->setHidden(true);
@@ -1114,9 +1107,9 @@ void ConnectorTool::_setActiveShape(SPItem *item) {
// The idea here is to try and add a group's children to solidify
// connection handling. We react to path objects with only one node.
- for (SPObject *child = item->firstChild() ; child ; child = child->getNext() ) {
- if (SP_IS_PATH(child) && SP_PATH(child)->nodesInPath() == 1) {
- this->_activeShapeAddKnot((SPItem *) child);
+ for (auto& child: item->children) {
+ if (SP_IS_PATH(&child) && SP_PATH(&child)->nodesInPath() == 1) {
+ this->_activeShapeAddKnot((SPItem *) &child);
}
}
this->_activeShapeAddKnot(item);
@@ -1306,8 +1299,8 @@ void cc_selection_set_avoid(bool const set_avoid)
int changes = 0;
- std::vector<SPItem*> l = selection->itemList();
- for(std::vector<SPItem*>::const_iterator i=l.begin();i!=l.end(); ++i) {
+ auto l = selection->items();
+ for(auto i=l.begin();i!=l.end(); ++i) {
SPItem *item = *i;
char const *value = (set_avoid) ? "true" : NULL;
diff --git a/src/ui/tools/dropper-tool.cpp b/src/ui/tools/dropper-tool.cpp
index c838c27d5..99177dc75 100644
--- a/src/ui/tools/dropper-tool.cpp
+++ b/src/ui/tools/dropper-tool.cpp
@@ -12,7 +12,7 @@
*/
#ifdef HAVE_CONFIG_H
-# include <config.h>
+#include <config.h>
#endif
#include <glibmm/i18n.h>
@@ -27,7 +27,6 @@
#include "display/curve.h"
#include "display/cairo-utils.h"
#include "svg/svg-color.h"
-#include "color.h"
#include "color-rgba.h"
#include "desktop-style.h"
#include "preferences.h"
@@ -36,7 +35,6 @@
#include "desktop.h"
#include "selection.h"
-#include "document.h"
#include "document-undo.h"
#include "pixmaps/cursor-dropper-f.xpm"
@@ -45,7 +43,6 @@
#include "ui/tools/dropper-tool.h"
#include "message-context.h"
#include "verbs.h"
-#include "ui/tools/tool-base.h"
using Inkscape::DocumentUndo;
@@ -121,20 +118,12 @@ void DropperTool::finish() {
}
if (cursor_dropper_fill) {
-#if GTK_CHECK_VERSION(3,0,0)
g_object_unref(cursor_dropper_fill);
-#else
- gdk_cursor_unref (cursor_dropper_fill);
-#endif
cursor_dropper_fill = NULL;
}
if (cursor_dropper_stroke) {
-#if GTK_CHECK_VERSION(3,0,0)
g_object_unref(cursor_dropper_stroke);
-#else
- gdk_cursor_unref (cursor_dropper_stroke);
-#endif
cursor_dropper_fill = NULL;
}
diff --git a/src/ui/tools/dynamic-base.cpp b/src/ui/tools/dynamic-base.cpp
index eb789d850..6627a470e 100644
--- a/src/ui/tools/dynamic-base.cpp
+++ b/src/ui/tools/dynamic-base.cpp
@@ -1,13 +1,7 @@
#include "ui/tools/dynamic-base.h"
-#include <gtk/gtk.h>
-
-#include "config.h"
-
#include "message-context.h"
-#include "streq.h"
-#include "preferences.h"
#include "display/sp-canvas-item.h"
#include "desktop.h"
#include "display/curve.h"
diff --git a/src/ui/tools/eraser-tool.cpp b/src/ui/tools/eraser-tool.cpp
index 6b32b5901..ae312e054 100644
--- a/src/ui/tools/eraser-tool.cpp
+++ b/src/ui/tools/eraser-tool.cpp
@@ -24,8 +24,6 @@
#define noERASER_VERBOSE
-#include "config.h"
-
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <glibmm/i18n.h>
@@ -38,7 +36,6 @@
#include "display/canvas-bpath.h"
#include <2geom/bezier-utils.h>
-#include <glib.h>
#include "macros.h"
#include "document.h"
#include "selection.h"
@@ -47,30 +44,28 @@
#include "desktop-style.h"
#include "message-context.h"
-#include "preferences.h"
#include "pixmaps/cursor-eraser.xpm"
-#include "xml/repr.h"
#include "context-fns.h"
-#include "sp-item.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-clippath.h"
+#include "sp-rect.h"
#include "sp-text.h"
+#include "sp-root.h"
#include "display/canvas-bpath.h"
#include "display/canvas-arena.h"
-#include "livarot/Shape.h"
#include "document-undo.h"
#include "verbs.h"
#include "style.h"
-#include "style-enums.h"
-#include <2geom/math-utils.h>
#include <2geom/pathvector.h>
#include "path-chemistry.h"
+#include "selection-chemistry.h"
#include "display/curve.h"
-
+#include "layer-model.h"
+#include "layer-manager.h"
#include "ui/tools/eraser-tool.h"
using Inkscape::DocumentUndo;
@@ -380,7 +375,7 @@ void EraserTool::cancel() {
bool EraserTool::root_handler(GdkEvent* event) {
gint ret = FALSE;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- gint eraserMode = prefs->getBool("/tools/eraser/mode") ? 1 : 0;
+ gint eraser_mode = prefs->getInt("/tools/eraser/mode", 2);
switch (event->type) {
case GDK_BUTTON_PRESS:
if (event->button.button == 1 && !this->space_panning) {
@@ -400,7 +395,7 @@ bool EraserTool::root_handler(GdkEvent* event) {
if (this->repr) {
this->repr = NULL;
}
- if ( ! eraserMode ) {
+ if ( eraser_mode == ERASER_MODE_DELETE ) {
Inkscape::Rubberband::get(desktop)->start(desktop, button_dt);
Inkscape::Rubberband::get(desktop)->setMode(RUBBERBAND_MODE_TOUCHPATH);
}
@@ -448,7 +443,7 @@ bool EraserTool::root_handler(GdkEvent* event) {
ret = TRUE;
}
- if ( !eraserMode ) {
+ if ( eraser_mode == ERASER_MODE_DELETE ) {
this->accumulated->reset();
Inkscape::Rubberband::get(desktop)->move(motion_dt);
}
@@ -491,7 +486,7 @@ bool EraserTool::root_handler(GdkEvent* event) {
ret = TRUE;
}
- if (!eraserMode && Inkscape::Rubberband::get(desktop)->is_started()) {
+ if (eraser_mode == ERASER_MODE_DELETE && Inkscape::Rubberband::get(desktop)->is_started()) {
Inkscape::Rubberband::get(desktop)->stop();
}
@@ -578,7 +573,7 @@ bool EraserTool::root_handler(GdkEvent* event) {
break;
case GDK_KEY_Escape:
- if ( !eraserMode ) {
+ if ( eraser_mode == ERASER_MODE_DELETE ) {
Inkscape::Rubberband::get(desktop)->stop();
}
if (this->is_drawing) {
@@ -640,65 +635,66 @@ void EraserTool::clear_current() {
void EraserTool::set_to_accumulated() {
bool workDone = false;
-
+ SPDocument *document = this->desktop->doc();
if (!this->accumulated->is_empty()) {
if (!this->repr) {
/* Create object */
- Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
+ Inkscape::XML::Document *xml_doc = this->desktop->doc()->getReprDoc();
Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
/* Set style */
- sp_desktop_apply_style_tool (desktop, repr, "/tools/eraser", false);
+ sp_desktop_apply_style_tool (this->desktop, repr, "/tools/eraser", false);
this->repr = repr;
}
- SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(this->repr));
+ SPObject * top_layer = desktop->layer_manager->nthChildOf(desktop->layers->currentRoot(), 0);
+ SPItem *item_repr = SP_ITEM(top_layer->appendChildRepr(this->repr));
Inkscape::GC::release(this->repr);
- item->updateRepr();
- Geom::PathVector pathv = this->accumulated->get_pathvector() * desktop->dt2doc();
- pathv *= item->i2doc_affine().inverse();
+ item_repr->updateRepr();
+ Geom::PathVector pathv = this->accumulated->get_pathvector() * this->desktop->dt2doc();
+ pathv *= item_repr->i2doc_affine().inverse();
gchar *str = sp_svg_write_path(pathv);
g_assert( str != NULL );
this->repr->setAttribute("d", str);
g_free(str);
-
+ Geom::OptRect eraserBbox;
if ( this->repr ) {
bool wasSelection = false;
- Inkscape::Selection *selection = desktop->getSelection();
+ Inkscape::Selection *selection = this->desktop->getSelection();
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- gint eraserMode = prefs->getBool("/tools/eraser/mode") ? 1 : 0;
- Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
+ gint eraser_mode = prefs->getInt("/tools/eraser/mode", ERASER_MODE_CLIP);
+ Inkscape::XML::Document *xml_doc = this->desktop->doc()->getReprDoc();
- SPItem* acid = SP_ITEM(desktop->doc()->getObjectByRepr(this->repr));
- Geom::OptRect eraserBbox = acid->desktopVisualBounds();
+ SPItem* acid = SP_ITEM(this->desktop->doc()->getObjectByRepr(this->repr));
+ eraserBbox = acid->desktopVisualBounds();
std::vector<SPItem*> remainingItems;
std::vector<SPItem*> toWorkOn;
if (selection->isEmpty()) {
- if ( eraserMode ) {
- toWorkOn = desktop->getDocument()->getItemsPartiallyInBox(desktop->dkey, *eraserBbox);
+ if (eraser_mode == ERASER_MODE_CUT || eraser_mode == ERASER_MODE_CLIP) {
+ toWorkOn = document->getItemsPartiallyInBox(this->desktop->dkey, *eraserBbox);
} else {
- Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop);
- toWorkOn = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints());
+ Inkscape::Rubberband *r = Inkscape::Rubberband::get(this->desktop);
+ toWorkOn = document->getItemsAtPoints(this->desktop->dkey, r->getPoints());
}
toWorkOn.erase(std::remove(toWorkOn.begin(), toWorkOn.end(), acid), toWorkOn.end());
} else {
- if ( !eraserMode ) {
- Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop);
+ if (eraser_mode == ERASER_MODE_DELETE) {
+ Inkscape::Rubberband *r = Inkscape::Rubberband::get(this->desktop);
std::vector<SPItem*> touched;
- touched = desktop->getDocument()->getItemsAtPoints(desktop->dkey, r->getPoints());
+ touched = document->getItemsAtPoints(this->desktop->dkey, r->getPoints());
for (std::vector<SPItem*>::const_iterator i = touched.begin();i!=touched.end();++i) {
if(selection->includes(*i)){
toWorkOn.push_back((*i));
}
}
} else {
- toWorkOn = selection->itemList();
+ toWorkOn.insert(toWorkOn.end(), selection->items().begin(), selection->items().end());
}
wasSelection = true;
}
if ( !toWorkOn.empty() ) {
- if ( eraserMode ) {
+ if (eraser_mode == ERASER_MODE_CUT) {
for (std::vector<SPItem*>::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); ++i){
SPItem *item = *i;
SPUse *use = dynamic_cast<SPUse *>(item);
@@ -708,7 +704,6 @@ void EraserTool::set_to_accumulated() {
item->deleteObject(true);
sp_object_unref(item);
workDone = true;
- workDone = true;
} else if (SP_IS_GROUP(item) || use ) {
/*Do nothing*/
} else {
@@ -719,33 +714,33 @@ void EraserTool::set_to_accumulated() {
Inkscape::GC::release(dup); // parent takes over
selection->set(dup);
if (!this->nowidth) {
- sp_selected_path_union_skip_undo(selection, desktop);
+ selection->pathUnion(true);
}
selection->add(item);
if(item->style->fill_rule.value == SP_WIND_RULE_EVENODD){
SPCSSAttr *css = sp_repr_css_attr_new();
sp_repr_css_set_property(css, "fill-rule", "evenodd");
- sp_desktop_set_style(desktop, css);
+ sp_desktop_set_style(this->desktop, css);
sp_repr_css_attr_unref(css);
css = 0;
}
if (this->nowidth) {
- sp_selected_path_cut_skip_undo(selection, desktop);
+ selection->pathCut(true);
} else {
- sp_selected_path_diff_skip_undo(selection, desktop);
+ selection->pathDiff(true);
}
workDone = true; // TODO set this only if something was cut.
bool break_apart = prefs->getBool("/tools/eraser/break_apart", false);
if(!break_apart){
- sp_selected_path_combine(desktop, true);
+ selection->combine(true);
} else {
if(!this->nowidth){
- sp_selected_path_break_apart(desktop, true);
+ selection->breakApart(true);
}
}
if ( !selection->isEmpty() ) {
// If the item was not completely erased, track the new remainder.
- std::vector<SPItem*> nowSel(selection->itemList());
+ std::vector<SPItem*> nowSel(selection->items().begin(), selection->items().end());
for (std::vector<SPItem*>::const_iterator i2 = nowSel.begin();i2!=nowSel.end();++i2) {
remainingItems.push_back(*i2);
}
@@ -755,6 +750,78 @@ void EraserTool::set_to_accumulated() {
}
}
}
+ } else if (eraser_mode == ERASER_MODE_CLIP) {
+ if (!this->nowidth) {
+ remainingItems.clear();
+ for (std::vector<SPItem*>::const_iterator i = toWorkOn.begin(); i != toWorkOn.end(); ++i){
+ selection->clear();
+ SPItem *item = *i;
+ Geom::OptRect bbox = item->desktopVisualBounds();
+ Inkscape::XML::Document *xml_doc = this->desktop->doc()->getReprDoc();
+ Inkscape::XML::Node* dup = this->repr->duplicate(xml_doc);
+ this->repr->parent()->appendChild(dup);
+ Inkscape::GC::release(dup); // parent takes over
+ selection->set(dup);
+ selection->pathUnion(true);
+ if (bbox && bbox->intersects(*eraserBbox)) {
+ SPClipPath *clip_path = item->clip_ref->getObject();
+ if (clip_path) {
+ std::vector<SPItem*> selected;
+ selected.push_back(SP_ITEM(clip_path->firstChild()));
+ std::vector<Inkscape::XML::Node*> to_select;
+ std::vector<SPItem*> items(selected);
+ sp_item_list_to_curves(items, selected, to_select);
+ Inkscape::XML::Node * clip_data = SP_ITEM(clip_path->firstChild())->getRepr();
+ if (!clip_data && !to_select.empty()) {
+ clip_data = *(to_select.begin());
+ }
+ if (clip_data) {
+ Inkscape::XML::Node *dup_clip = clip_data->duplicate(xml_doc);
+ if (dup_clip) {
+ SPItem * dup_clip_obj = SP_ITEM(item_repr->parent->appendChildRepr(dup_clip));
+ if (dup_clip_obj) {
+ dup_clip_obj->doWriteTransform(dup_clip, item->transform);
+ sp_object_ref(clip_path, 0);
+ clip_path->deleteObject(true);
+ sp_object_unref(clip_path);
+ selection->raiseToTop(true);
+ selection->add(dup_clip);
+ selection->pathDiff(true);
+ SPItem * clip = SP_ITEM(*(selection->items().begin()));
+ }
+ }
+ }
+ } else {
+ Inkscape::XML::Node *rect_repr = xml_doc->createElement("svg:rect");
+ sp_desktop_apply_style_tool (this->desktop, rect_repr, "/tools/eraser", false);
+ SPRect * rect = SP_RECT(item_repr->parent->appendChildRepr(rect_repr));
+ Inkscape::GC::release(rect_repr);
+ rect->setPosition (bbox->left(), bbox->top(), bbox->width(), bbox->height());
+ rect->transform = SP_ITEM(rect->parent)->i2dt_affine().inverse();
+ rect->updateRepr();
+ rect->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
+ selection->raiseToTop(true);
+ selection->add(rect);
+ selection->pathDiff(true);
+ }
+ selection->raiseToTop(true);
+ selection->add(item);
+ selection->setMask(true, false, true);
+ } else {
+ SPItem *erase_clip = selection->singleItem();
+ if (erase_clip) {
+ sp_object_ref(erase_clip, 0);
+ erase_clip->deleteObject(true);
+ sp_object_unref(erase_clip);
+ }
+ }
+ workDone = true;
+ selection->clear();
+ if (wasSelection) {
+ remainingItems.push_back(item);
+ }
+ }
+ }
} else {
for (std::vector<SPItem*> ::const_iterator i = toWorkOn.begin();i!=toWorkOn.end();++i) {
sp_object_ref( *i, 0 );
@@ -768,8 +835,8 @@ void EraserTool::set_to_accumulated() {
}
}
- if ( !eraserMode ) {
- //sp_selection_delete(desktop);
+ if (eraser_mode == ERASER_MODE_DELETE) {
+ selection->deleteItems();
remainingItems.clear();
}
@@ -791,12 +858,10 @@ void EraserTool::set_to_accumulated() {
this->repr = 0;
}
}
-
-
if ( workDone ) {
- DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_ERASER, _("Draw eraser stroke"));
+ DocumentUndo::done(document, SP_VERB_CONTEXT_ERASER, _("Draw eraser stroke"));
} else {
- DocumentUndo::cancel(desktop->getDocument());
+ DocumentUndo::cancel(document);
}
}
@@ -955,7 +1020,7 @@ void EraserTool::fit_and_split(bool release) {
}
this->currentcurve->closepath();
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->currentshape), this->currentcurve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->currentshape), this->currentcurve, true);
}
/* Current eraser */
@@ -987,12 +1052,12 @@ void EraserTool::fit_and_split(bool release) {
g_print("[%d]Yup\n", this->npoints);
#endif
if (!release) {
- gint eraserMode = prefs->getBool("/tools/eraser/mode") ? 1 : 0;
+ gint eraser_mode = prefs->getInt("/tools/eraser/mode",2);
g_assert(!this->currentcurve->is_empty());
SPCanvasItem *cbp = sp_canvas_item_new(desktop->getSketch(), SP_TYPE_CANVAS_BPATH, NULL);
SPCurve *curve = this->currentcurve->copy();
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH (cbp), curve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH (cbp), curve, true);
curve->unref();
guint32 fillColor = sp_desktop_get_color_tool (desktop, "/tools/eraser", true);
@@ -1009,7 +1074,7 @@ void EraserTool::fit_and_split(bool release) {
this->segments = g_slist_prepend(this->segments, cbp);
- if ( !eraserMode ) {
+ if (eraser_mode == ERASER_MODE_DELETE) {
sp_canvas_item_hide(cbp);
sp_canvas_item_hide(this->currentshape);
}
@@ -1041,7 +1106,7 @@ void EraserTool::draw_temporary_box() {
}
this->currentcurve->closepath();
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->currentshape), this->currentcurve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->currentshape), this->currentcurve, true);
}
}
diff --git a/src/ui/tools/eraser-tool.h b/src/ui/tools/eraser-tool.h
index 50ce6b6e3..bd0e98057 100644
--- a/src/ui/tools/eraser-tool.h
+++ b/src/ui/tools/eraser-tool.h
@@ -31,6 +31,10 @@
#define ERC_MAX_TILT 1.0
#define ERC_DEFAULT_TILT 0.0
+#define ERASER_MODE_DELETE 0
+#define ERASER_MODE_CUT 1
+#define ERASER_MODE_CLIP 2
+
namespace Inkscape {
namespace UI {
namespace Tools {
diff --git a/src/ui/tools/flood-tool.cpp b/src/ui/tools/flood-tool.cpp
index 748c82717..6e1d085aa 100644
--- a/src/ui/tools/flood-tool.cpp
+++ b/src/ui/tools/flood-tool.cpp
@@ -18,14 +18,14 @@
*/
#ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
#endif
+#include <cmath>
#include "trace/potrace/inkscape-potrace.h"
#include <2geom/pathvector.h>
#include <gdk/gdkkeysyms.h>
#include <queue>
-#include <deque>
#include <glibmm/i18n.h>
#include "color.h"
@@ -36,7 +36,6 @@
#include "display/cairo-utils.h"
#include "display/drawing-context.h"
#include "display/drawing-image.h"
-#include "display/drawing-item.h"
#include "display/drawing.h"
#include "display/sp-canvas.h"
#include "document.h"
@@ -47,23 +46,15 @@
#include "macros.h"
#include "message-context.h"
#include "message-stack.h"
-#include "preferences.h"
#include "rubberband.h"
#include "selection.h"
#include "ui/shape-editor.h"
-#include "sp-defs.h"
-#include "sp-item.h"
#include "splivarot.h"
#include "sp-namedview.h"
-#include "sp-object.h"
-#include "sp-path.h"
-#include "sp-rect.h"
#include "sp-root.h"
#include "svg/svg.h"
#include "trace/imagemap.h"
-#include "trace/trace.h"
#include "xml/node-event-vector.h"
-#include "xml/repr.h"
#include "verbs.h"
#include "pixmaps/cursor-paintbucket.xpm"
@@ -99,10 +90,10 @@ Glib::ustring ch_init[8] = {
const std::vector<Glib::ustring> FloodTool::channel_list( ch_init, ch_init+8 );
Glib::ustring gap_init[4] = {
- C_("Flood autogap", "None"),
- C_("Flood autogap", "Small"),
- C_("Flood autogap", "Medium"),
- C_("Flood autogap", "Large")
+ NC_("Flood autogap", "None"),
+ NC_("Flood autogap", "Small"),
+ NC_("Flood autogap", "Medium"),
+ NC_("Flood autogap", "Large")
};
const std::vector<Glib::ustring> FloodTool::gap_list( gap_init, gap_init+4 );
@@ -196,6 +187,21 @@ inline unsigned char * get_trace_pixel(guchar *trace_px, int x, int y, int width
}
/**
+ * \brief Check whether two unsigned integers are close to each other
+ *
+ * \param[in] a The 1st unsigned int
+ * \param[in] b The 2nd unsigned int
+ * \param[in] d The threshold for comparison
+ *
+ * \return true if |a-b| <= d; false otherwise
+ */
+static bool compare_guint32(guint32 const a, guint32 const b, guint32 const d)
+{
+ const int difference = std::abs(static_cast<int>(a) - static_cast<int>(b));
+ return difference <= d;
+}
+
+/**
* Compare a pixel in a pixel buffer with another pixel to determine if a point should be included in the fill operation.
* @param check The pixel in the pixel buffer to check.
* @param orig The original selected pixel to use as the fill target color.
@@ -206,7 +212,6 @@ inline unsigned char * get_trace_pixel(guchar *trace_px, int x, int y, int width
*/
static bool compare_pixels(guint32 check, guint32 orig, guint32 merged_orig_pixel, guint32 dtc, int threshold, PaintBucketChannels method)
{
- int diff = 0;
float hsl_check[3] = {0,0,0}, hsl_orig[3] = {0,0,0};
guint32 ac = 0, rc = 0, gc = 0, bc = 0;
@@ -232,27 +237,35 @@ static bool compare_pixels(guint32 check, guint32 orig, guint32 merged_orig_pixe
switch (method) {
case FLOOD_CHANNELS_ALPHA:
- return abs(static_cast<int>(ac) - ao) <= threshold;
+ return compare_guint32(ac, ao, threshold);
case FLOOD_CHANNELS_R:
- return abs(static_cast<int>(ac ? unpremul_alpha(rc, ac) : 0) - (ao ? unpremul_alpha(ro, ao) : 0)) <= threshold;
+ return compare_guint32(ac ? unpremul_alpha(rc, ac) : 0,
+ ao ? unpremul_alpha(ro, ao) : 0,
+ threshold);
case FLOOD_CHANNELS_G:
- return abs(static_cast<int>(ac ? unpremul_alpha(gc, ac) : 0) - (ao ? unpremul_alpha(go, ao) : 0)) <= threshold;
+ return compare_guint32(ac ? unpremul_alpha(gc, ac) : 0,
+ ao ? unpremul_alpha(go, ao) : 0,
+ threshold);
case FLOOD_CHANNELS_B:
- return abs(static_cast<int>(ac ? unpremul_alpha(bc, ac) : 0) - (ao ? unpremul_alpha(bo, ao) : 0)) <= threshold;
+ return compare_guint32(ac ? unpremul_alpha(bc, ac) : 0,
+ ao ? unpremul_alpha(bo, ao) : 0,
+ threshold);
case FLOOD_CHANNELS_RGB:
- guint32 amc, rmc, bmc, gmc;
- //amc = 255*255 - (255-ac)*(255-ad); amc = (amc + 127) / 255;
- //amc = (255-ac)*ad + 255*ac; amc = (amc + 127) / 255;
- amc = 255; // Why are we looking at desktop? Cairo version ignores destop alpha
- rmc = (255-ac)*rd + 255*rc; rmc = (rmc + 127) / 255;
- gmc = (255-ac)*gd + 255*gc; gmc = (gmc + 127) / 255;
- bmc = (255-ac)*bd + 255*bc; bmc = (bmc + 127) / 255;
-
- diff += abs(static_cast<int>(amc ? unpremul_alpha(rmc, amc) : 0) - (amop ? unpremul_alpha(rmop, amop) : 0));
- diff += abs(static_cast<int>(amc ? unpremul_alpha(gmc, amc) : 0) - (amop ? unpremul_alpha(gmop, amop) : 0));
- diff += abs(static_cast<int>(amc ? unpremul_alpha(bmc, amc) : 0) - (amop ? unpremul_alpha(bmop, amop) : 0));
- return ((diff / 3) <= ((threshold * 3) / 4));
-
+ {
+ guint32 amc, rmc, bmc, gmc;
+ //amc = 255*255 - (255-ac)*(255-ad); amc = (amc + 127) / 255;
+ //amc = (255-ac)*ad + 255*ac; amc = (amc + 127) / 255;
+ amc = 255; // Why are we looking at desktop? Cairo version ignores destop alpha
+ rmc = (255-ac)*rd + 255*rc; rmc = (rmc + 127) / 255;
+ gmc = (255-ac)*gd + 255*gc; gmc = (gmc + 127) / 255;
+ bmc = (255-ac)*bd + 255*bc; bmc = (bmc + 127) / 255;
+
+ int diff = 0; // The total difference between each of the 3 color components
+ diff += std::abs(static_cast<int>(amc ? unpremul_alpha(rmc, amc) : 0) - static_cast<int>(amop ? unpremul_alpha(rmop, amop) : 0));
+ diff += std::abs(static_cast<int>(amc ? unpremul_alpha(gmc, amc) : 0) - static_cast<int>(amop ? unpremul_alpha(gmop, amop) : 0));
+ diff += std::abs(static_cast<int>(amc ? unpremul_alpha(bmc, amc) : 0) - static_cast<int>(amop ? unpremul_alpha(bmop, amop) : 0));
+ return ((diff / 3) <= ((threshold * 3) / 4));
+ }
case FLOOD_CHANNELS_H:
return ((int)(fabs(hsl_check[0] - hsl_orig[0]) * 100.0) <= threshold);
case FLOOD_CHANNELS_S:
@@ -456,7 +469,7 @@ static void do_trace(bitmap_coords_info bci, guchar *trace_px, SPDesktop *deskto
ngettext("Area filled, path with <b>%d</b> node created and unioned with selection.","Area filled, path with <b>%d</b> nodes created and unioned with selection.",
SP_PATH(reprobj)->nodesInPath()), SP_PATH(reprobj)->nodesInPath() );
selection->add(reprobj);
- sp_selected_path_union_skip_undo(desktop->getSelection(), desktop);
+ selection->pathUnion(true);
} else {
desktop->messageStack()->flashF( Inkscape::WARNING_MESSAGE,
ngettext("Area filled, path with <b>%d</b> node created.","Area filled, path with <b>%d</b> nodes created.",
diff --git a/src/ui/tools/freehand-base.cpp b/src/ui/tools/freehand-base.cpp
index c98ecb686..4af70a816 100644
--- a/src/ui/tools/freehand-base.cpp
+++ b/src/ui/tools/freehand-base.cpp
@@ -17,43 +17,29 @@
#define DRAW_VERBOSE
#ifdef HAVE_CONFIG_H
-# include "config.h"
+#include <config.h>
#endif
#include "live_effects/lpe-bendpath.h"
#include "live_effects/lpe-patternalongpath.h"
#include "live_effects/lpe-simplify.h"
#include "display/canvas-bpath.h"
-#include "xml/repr.h"
#include "svg/svg.h"
-#include <glibmm/i18n.h>
#include "display/curve.h"
-#include "desktop.h"
#include "desktop-style.h"
-#include "document.h"
#include "ui/draw-anchor.h"
#include "macros.h"
#include "message-stack.h"
#include "ui/tools/pen-tool.h"
#include "ui/tools/lpe-tool.h"
-#include "preferences.h"
-#include "selection.h"
#include "selection-chemistry.h"
-#include "snap.h"
-#include "sp-path.h"
-#include "sp-use.h"
#include "sp-item-group.h"
-#include "sp-namedview.h"
#include "live_effects/lpe-powerstroke.h"
#include "style.h"
#include "ui/control-manager.h"
-#include "util/units.h"
// clipboard support
#include "ui/clipboard.h"
-#include "ui/tools/freehand-base.h"
-
-#include <gdk/gdkkeysyms.h>
using Inkscape::DocumentUndo;
@@ -226,6 +212,10 @@ static void spdc_paste_curve_as_freehand_shape(Geom::PathVector const &newpath,
Effect::createAndApply(PATTERN_ALONG_PATH, dc->desktop->doc(), item);
Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE();
static_cast<LPEPatternAlongPath*>(lpe)->pattern.set_new_value(newpath,true);
+ double scale_doc = 1 / dc->desktop->doc()->getDocumentScale()[0];
+ Inkscape::SVGOStringStream os;
+ os << scale_doc;
+ lpe->getRepr()->setAttribute("prop_scale", os.str().c_str());
}
static void spdc_apply_powerstroke_shape(const std::vector<Geom::Point> & points, FreehandBase *dc, SPItem *item)
@@ -236,38 +226,14 @@ static void spdc_apply_powerstroke_shape(const std::vector<Geom::Point> & points
Effect* lpe = SP_LPE_ITEM(item)->getCurrentLPE();
static_cast<LPEPowerStroke*>(lpe)->offset_points.param_set_and_write_new_value(points);
- // find out stroke width (TODO: is there an easier way??)
- SPDesktop *desktop = dc->desktop;
- Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
- Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
- Inkscape::GC::release(repr);
-
- char const* tool = SP_IS_PEN_CONTEXT(dc) ? "/tools/freehand/pen" : "/tools/freehand/pencil";
-
- // apply the tool's current style
- sp_desktop_apply_style_tool(desktop, repr, tool, false);
-
- double stroke_width = 1.0;
- char const *style_str = NULL;
- style_str = repr->attribute("style");
- if (style_str) {
- SPStyle style(SP_ACTIVE_DOCUMENT);
- style.mergeString(style_str);
- stroke_width = style.stroke_width.computed;
- }
-
- std::ostringstream s;
- s.imbue(std::locale::classic());
- s << points[0][Geom::X] << "," << stroke_width / 2.;
-
// write powerstroke parameters:
lpe->getRepr()->setAttribute("start_linecap_type", "zerowidth");
lpe->getRepr()->setAttribute("end_linecap_type", "zerowidth");
- lpe->getRepr()->setAttribute("cusp_linecap_type", "round");
lpe->getRepr()->setAttribute("sort_points", "true");
lpe->getRepr()->setAttribute("interpolator_type", "CubicBezierJohan");
lpe->getRepr()->setAttribute("interpolator_beta", "0.2");
- lpe->getRepr()->setAttribute("offset_points", s.str().c_str());
+ lpe->getRepr()->setAttribute("miter_limit", "4");
+ lpe->getRepr()->setAttribute("linejoin_type", "extrp_arc");
}
static void spdc_apply_bend_shape(gchar const *svgd, FreehandBase *dc, SPItem *item)
@@ -307,12 +273,42 @@ static void spdc_apply_simplify(std::string threshold, FreehandBase *dc, SPItem
enum shapeType { NONE, TRIANGLE_IN, TRIANGLE_OUT, ELLIPSE, CLIPBOARD, BEND_CLIPBOARD, LAST_APPLIED };
static shapeType previous_shape_type = NONE;
-static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, SPCurve *curve)
+static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item, SPCurve *curve, bool is_bend)
{
using namespace Inkscape::LivePathEffect;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
if (item && SP_IS_LPE_ITEM(item)) {
+ //Store the clipboard path to apply in the future without the use of clipboard
+ static Geom::PathVector previous_shape_pathv;
+ static SPItem *bend_item;
+ shapeType shape = (shapeType)prefs->getInt(tool_name(dc) + "/shape", 0);
+ if (previous_shape_type == NONE) {
+ previous_shape_type = shape;
+ }
+ if(shape == LAST_APPLIED){
+
+ shape = previous_shape_type;
+ if(shape == CLIPBOARD || shape == BEND_CLIPBOARD){
+ shape = LAST_APPLIED;
+ }
+ }
+ Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get();
+ if (is_bend &&
+ (shape == BEND_CLIPBOARD || (shape == LAST_APPLIED && previous_shape_type != CLIPBOARD)) &&
+ cm->paste(SP_ACTIVE_DESKTOP,true))
+ {
+ bend_item = dc->selection->singleItem();
+ if(!bend_item || (!SP_IS_SHAPE(bend_item) && !SP_IS_GROUP(bend_item))){
+ previous_shape_type = NONE;
+ return;
+ }
+ } else if(is_bend) {
+ return;
+ }
+ if (!is_bend && previous_shape_type == BEND_CLIPBOARD && shape == BEND_CLIPBOARD) {
+ return;
+ }
bool simplify = prefs->getInt(tool_name(dc) + "/simplify", 0);
if(simplify){
double tol = prefs->getDoubleLimited("/tools/freehand/pencil/tolerance", 10.0, 1.0, 100.0);
@@ -334,27 +330,16 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
curve = sp_shape->getCurve();
}
- //Store the clipboard path to apply in the future without the use of clipboard
- static Geom::PathVector previous_shape_pathv;
-
- shapeType shape = (shapeType)prefs->getInt(tool_name(dc) + "/shape", 0);
bool shape_applied = false;
SPCSSAttr *css_item = sp_css_attr_from_object(item, SP_STYLE_FLAG_ALWAYS);
const char *cstroke = sp_repr_css_property(css_item, "stroke", "none");
- static SPItem *bend_item;
+ const char *stroke_width = sp_repr_css_property(css_item, "stroke-width", "0");
+ double swidth;
+ sp_svg_number_read_d(stroke_width, &swidth);
#define SHAPE_LENGTH 10
#define SHAPE_HEIGHT 10
-
- if(shape == LAST_APPLIED){
-
- shape = previous_shape_type;
- if(shape == CLIPBOARD || shape == BEND_CLIPBOARD){
- shape = LAST_APPLIED;
- }
- }
-
switch (shape) {
case NONE:
// don't apply any shape
@@ -363,7 +348,8 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
{
// "triangle in"
std::vector<Geom::Point> points(1);
- points[0] = Geom::Point(0., SHAPE_HEIGHT/2);
+ points[0] = Geom::Point(0., swidth/2);
+ //points[0] *= i2anc_affine(static_cast<SPItem *>(item->parent), NULL).inverse();
spdc_apply_powerstroke_shape(points, dc, item);
shape_applied = true;
@@ -374,7 +360,9 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
// "triangle out"
guint curve_length = curve->get_segment_count();
std::vector<Geom::Point> points(1);
- points[0] = Geom::Point((double)curve_length, SHAPE_HEIGHT/2);
+ points[0] = Geom::Point(0, swidth/2);
+ //points[0] *= i2anc_affine(static_cast<SPItem *>(item->parent), NULL).inverse();
+ points[0][Geom::X] = (double)curve_length;
spdc_apply_powerstroke_shape(points, dc, item);
shape_applied = true;
@@ -401,7 +389,7 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
{
// take shape from clipboard;
Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get();
- if(cm->paste(SP_ACTIVE_DESKTOP,true) == true){
+ if(cm->paste(SP_ACTIVE_DESKTOP,true)){
SPItem * pasted_clipboard = dc->selection->singleItem();
if(pasted_clipboard){
Inkscape::XML::Node *pasted_clipboard_root = pasted_clipboard->getRepr();
@@ -429,21 +417,14 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
}
case BEND_CLIPBOARD:
{
- Inkscape::UI::ClipboardManager *cm = Inkscape::UI::ClipboardManager::get();
- if(cm->paste(SP_ACTIVE_DESKTOP,true) == true){
- gchar const *svgd = item->getRepr()->attribute("d");
- bend_item = dc->selection->singleItem();
- if(bend_item && (SP_IS_SHAPE(bend_item) || SP_IS_GROUP(bend_item))){
- bend_item->moveTo(item,false);
- bend_item->transform.setTranslation(Geom::Point());
- spdc_apply_bend_shape(svgd, dc, bend_item);
- dc->selection->add(SP_OBJECT(bend_item));
-
- shape = BEND_CLIPBOARD;
- } else {
- bend_item = NULL;
- shape = NONE;
- }
+ gchar const *svgd = item->getRepr()->attribute("d");
+ if(bend_item && (SP_IS_SHAPE(bend_item) || SP_IS_GROUP(bend_item))){
+ bend_item->moveTo(item,false);
+ bend_item->transform.setTranslation(Geom::Point());
+ spdc_apply_bend_shape(svgd, dc, bend_item);
+ dc->selection->add(SP_OBJECT(bend_item));
+
+ shape = BEND_CLIPBOARD;
} else {
bend_item = NULL;
shape = NONE;
@@ -455,7 +436,6 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
if(previous_shape_type == CLIPBOARD){
if(previous_shape_pathv.size() != 0){
spdc_paste_curve_as_freehand_shape(previous_shape_pathv, dc, item);
-
shape_applied = true;
shape = CLIPBOARD;
} else{
@@ -465,7 +445,7 @@ static void spdc_check_for_and_apply_waiting_LPE(FreehandBase *dc, SPItem *item,
if(bend_item != NULL && bend_item->getRepr() != NULL){
gchar const *svgd = item->getRepr()->attribute("d");
dc->selection->add(SP_OBJECT(bend_item));
- sp_selection_duplicate(dc->desktop);
+ dc->selection->duplicate();
dc->selection->remove(SP_OBJECT(bend_item));
bend_item = dc->selection->singleItem();
if(bend_item){
@@ -672,7 +652,10 @@ void spdc_concat_colors_and_flush(FreehandBase *dc, gboolean forceclosed)
}
// Step A - test, whether we ended on green anchor
- if ( forceclosed || ( dc->green_anchor && dc->green_anchor->active ) ) {
+ if ( (forceclosed &&
+ (!dc->sa || (dc->sa && dc->sa->curve->is_empty()))) ||
+ ( dc->green_anchor && dc->green_anchor->active))
+ {
// We hit green anchor, closing Green-Blue-Red
dc->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Path is closed."));
c->closepath_current();
@@ -754,7 +737,11 @@ void spdc_concat_colors_and_flush(FreehandBase *dc, gboolean forceclosed)
e->unref();
}
-
+ if (forceclosed)
+ {
+ dc->desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Path is closed."));
+ c->closepath_current();
+ }
spdc_flush_white(dc, c);
c->unref();
@@ -812,16 +799,16 @@ static void spdc_flush_white(FreehandBase *dc, SPCurve *gc)
if (!dc->white_item) {
// Attach repr
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
SPItem *item = SP_ITEM(desktop->currentLayer()->appendChildRepr(repr));
-
- spdc_check_for_and_apply_waiting_LPE(dc, item, c);
- if(previous_shape_type != BEND_CLIPBOARD){
- dc->selection->set(repr);
- }
+ //Bend needs the transforms applied after, Other effects best before
+ spdc_check_for_and_apply_waiting_LPE(dc, item, c, true);
Inkscape::GC::release(repr);
item->transform = SP_ITEM(desktop->currentLayer())->i2doc_affine().inverse();
item->updateRepr();
item->doWriteTransform(item->getRepr(), item->transform, NULL, true);
+ spdc_check_for_and_apply_waiting_LPE(dc, item, c, false);
+ dc->selection->set(repr);
if(previous_shape_type == BEND_CLIPBOARD){
repr->parent()->removeChild(repr);
}
@@ -926,7 +913,8 @@ static void spdc_free_colors(FreehandBase *dc)
}
void spdc_create_single_dot(ToolBase *ec, Geom::Point const &pt, char const *tool, guint event_state) {
- g_return_if_fail(!strcmp(tool, "/tools/freehand/pen") || !strcmp(tool, "/tools/freehand/pencil"));
+ g_return_if_fail(!strcmp(tool, "/tools/freehand/pen") || !strcmp(tool, "/tools/freehand/pencil")
+ || !strcmp(tool, "/tools/calligraphic") );
Glib::ustring tool_path = tool;
SPDesktop *desktop = ec->desktop;
@@ -950,7 +938,8 @@ void spdc_create_single_dot(ToolBase *ec, Geom::Point const &pt, char const *too
// unset stroke and set fill color to former stroke color
gchar * str;
- str = g_strdup_printf("fill:#%06x;stroke:none;", sp_desktop_get_color_tool(desktop, tool, false) >> 8);
+ str = strcmp(tool, "/tools/calligraphic") ? g_strdup_printf("fill:#%06x;stroke:none;", sp_desktop_get_color_tool(desktop, tool, false) >> 8)
+ : g_strdup_printf("fill:#%06x;stroke:#%06x;", sp_desktop_get_color_tool(desktop, tool, true) >> 8, sp_desktop_get_color_tool(desktop, tool, false) >> 8);
repr->setAttribute("style", str);
g_free(str);
@@ -961,6 +950,8 @@ void spdc_create_single_dot(ToolBase *ec, Geom::Point const &pt, char const *too
Geom::Affine const i2d (item->i2dt_affine ());
Geom::Point pp = pt * i2d.inverse();
double rad = 0.5 * prefs->getDouble(tool_path + "/dot-size", 3.0);
+ if (!strcmp(tool, "/tools/calligraphic"))
+ rad = 0.1 * prefs->getDouble(tool_path + "/width", 3.0) / desktop->current_zoom();
if (event_state & GDK_MOD1_MASK) {
// TODO: We vary the dot size between 0.5*rad and 1.5*rad, where rad is the dot size
// as specified in prefs. Very simple, but it might be sufficient in practice. If not,
diff --git a/src/ui/tools/freehand-base.h b/src/ui/tools/freehand-base.h
index a3e7b42f9..3ee4cd7d0 100644
--- a/src/ui/tools/freehand-base.h
+++ b/src/ui/tools/freehand-base.h
@@ -76,8 +76,10 @@ public:
GSList *white_curves;
GSList *white_anchors;
- //ALternative curve to use on continuing exisiting curve in case of bspline or spirolive
- //because usigh anchor curves give memory and random bugs, - and obscure code- in some plataform reported by su_v in mac
+ // Alternative curve to use on continuing the exisiting curve in case of
+ // bspline or spirolive, because using anchor curves gives random memory
+ // bugs as reported by su_v when running this code on macOS (as well as
+ // making the code hard to understand).
SPCurve *overwrite_curve;
// Start anchor
diff --git a/src/ui/tools/gradient-tool.cpp b/src/ui/tools/gradient-tool.cpp
index 9d8101cc4..750596808 100644
--- a/src/ui/tools/gradient-tool.cpp
+++ b/src/ui/tools/gradient-tool.cpp
@@ -13,7 +13,7 @@
*/
#ifdef HAVE_CONFIG_H
-# include "config.h"
+#include <config.h>
#endif
@@ -31,17 +31,10 @@
#include "ui/tools/gradient-tool.h"
#include "gradient-chemistry.h"
#include <glibmm/i18n.h>
-#include "preferences.h"
#include "gradient-drag.h"
-#include "gradient-chemistry.h"
-#include "xml/repr.h"
-#include "sp-item.h"
#include "display/sp-ctrlline.h"
-#include "sp-linear-gradient.h"
-#include "sp-radial-gradient.h"
#include "sp-stop.h"
#include "svg/css-ostringstream.h"
-#include "svg/svg-color.h"
#include "snap.h"
#include "sp-namedview.h"
#include "rubberband.h"
@@ -86,6 +79,9 @@ GradientTool::~GradientTool() {
delete this->subselcon;
}
+// This must match GrPointType enum sp-gradient.h
+// We should move this to a shared header (can't simply move to gradient.h since that would require
+// including <glibmm/i18n.h> which messes up "N_" in extensions... argh!).
const gchar *gr_handle_descr [] = {
N_("Linear gradient <b>start</b>"), //POINT_LG_BEGIN
N_("Linear gradient <b>end</b>"),
@@ -95,7 +91,10 @@ const gchar *gr_handle_descr [] = {
N_("Radial gradient <b>radius</b>"),
N_("Radial gradient <b>focus</b>"), // POINT_RG_FOCUS
N_("Radial gradient <b>mid stop</b>"),
- N_("Radial gradient <b>mid stop</b>")
+ N_("Radial gradient <b>mid stop</b>"),
+ N_("Mesh gradient <b>corner</b>"),
+ N_("Mesh gradient <b>handle</b>"),
+ N_("Mesh gradient <b>tensor</b>")
};
void GradientTool::selection_changed(Inkscape::Selection*) {
@@ -106,7 +105,7 @@ void GradientTool::selection_changed(Inkscape::Selection*) {
if (selection == NULL) {
return;
}
- guint n_obj = selection->itemList().size();
+ guint n_obj = (guint) boost::distance(selection->items());
if (!drag->isNonEmpty() || selection->isEmpty())
return;
@@ -492,10 +491,10 @@ bool GradientTool::root_handler(GdkEvent* event) {
if (over_line) {
// we take the first item in selection, because with doubleclick, the first click
// always resets selection to the single object under cursor
- sp_gradient_context_add_stop_near_point(this, SP_ITEM(selection->itemList().front()), this->mousepoint_doc, event->button.time);
+ sp_gradient_context_add_stop_near_point(this, SP_ITEM(selection->items().front()), this->mousepoint_doc, event->button.time);
} else {
- std::vector<SPItem*> items=selection->itemList();
- for (std::vector<SPItem*>::const_iterator i = items.begin();i!=items.end();++i) {
+ auto items= selection->items();
+ for (auto i = items.begin();i!=items.end();++i) {
SPItem *item = *i;
SPGradientType new_type = (SPGradientType) prefs->getInt("/tools/gradient/newgradient", SP_GRADIENT_TYPE_LINEAR);
Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
@@ -838,6 +837,16 @@ bool GradientTool::root_handler(GdkEvent* event) {
ret = TRUE;
break;
+ case GDK_KEY_i:
+ case GDK_KEY_I:
+ if (MOD__SHIFT_ONLY(event)) {
+ // Shift+I - insert stops (alternate keybinding for keyboards
+ // that don't have the Insert key)
+ sp_gradient_context_add_stops_between_selected_stops (this);
+ ret = TRUE;
+ }
+ break;
+
case GDK_KEY_Delete:
case GDK_KEY_KP_Delete:
case GDK_KEY_BackSpace:
@@ -878,6 +887,7 @@ bool GradientTool::root_handler(GdkEvent* event) {
return ret;
}
+// Creates a new linear or radial gradient.
static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*state*/, guint32 etime)
{
SPDesktop *desktop = SP_EVENT_CONTEXT(&rc)->desktop;
@@ -897,7 +907,7 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta
} else {
// Starting from empty space:
// Sort items so that the topmost comes last
- std::vector<SPItem*> items(selection->itemList());
+ std::vector<SPItem*> items(selection->items().begin(), selection->items().end());
sort(items.begin(),items.end(),sp_item_repr_compare_position);
// take topmost
vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(items.back()), fill_or_stroke);
@@ -907,8 +917,8 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta
SPCSSAttr *css = sp_repr_css_attr_new();
sp_repr_css_set_property(css, "fill-opacity", "1.0");
- std::vector<SPItem*> itemlist = selection->itemList();
- for (std::vector<SPItem*>::const_iterator i = itemlist.begin();i!=itemlist.end();++i) {
+ auto itemlist = selection->items();
+ for (auto i = itemlist.begin();i!=itemlist.end();++i) {
//FIXME: see above
sp_repr_css_change_recursive((*i)->getRepr(), css, "style");
@@ -931,7 +941,7 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta
ec->_grdrag->local_change = true;
// give the grab out-of-bounds values of xp/yp because we're already dragging
// and therefore are already out of tolerance
- ec->_grdrag->grabKnot (selection->itemList()[0],
+ ec->_grdrag->grabKnot (selection->items().front(),
type == SP_GRADIENT_TYPE_LINEAR? POINT_LG_END : POINT_RG_R1,
-1, // ignore number (though it is always 1)
fill_or_stroke, 99999, 99999, etime);
@@ -940,7 +950,7 @@ static void sp_gradient_drag(GradientTool &rc, Geom::Point const pt, guint /*sta
// status text; we do not track coords because this branch is run once, not all the time
// during drag
- int n_objects = selection->itemList().size();
+ int n_objects = (int) boost::distance(selection->items());
rc.message_context->setF(Inkscape::NORMAL_MESSAGE,
ngettext("<b>Gradient</b> for %d object; with <b>Ctrl</b> to snap angle",
"<b>Gradient</b> for %d objects; with <b>Ctrl</b> to snap angle", n_objects),
diff --git a/src/ui/tools/lpe-tool.cpp b/src/ui/tools/lpe-tool.cpp
index 9bbc1ac20..29e4c9e74 100644
--- a/src/ui/tools/lpe-tool.cpp
+++ b/src/ui/tools/lpe-tool.cpp
@@ -15,19 +15,16 @@
*/
#ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
#endif
#include <2geom/sbasis-geometric.h>
-#include <gdk/gdkkeysyms.h>
#include <glibmm/i18n.h>
-#include "macros.h"
#include "pixmaps/cursor-crosshairs.xpm"
#include <gtk/gtk.h>
#include "desktop.h"
#include "message-context.h"
-#include "preferences.h"
#include "ui/shape-editor.h"
#include "selection.h"
@@ -396,8 +393,8 @@ lpetool_create_measuring_items(LpeTool *lc, Inkscape::Selection *selection)
SPCanvasGroup *tmpgrp = lc->desktop->getTempGroup();
gchar *arc_length;
double lengthval;
- std::vector<SPItem*> items=selection->itemList();
- for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){
+ auto items= selection->items();
+ for(auto i=items.begin();i!=items.end();++i){
if (SP_IS_PATH(*i)) {
path = SP_PATH(*i);
curve = path->getCurve();
diff --git a/src/ui/tools/measure-tool.cpp b/src/ui/tools/measure-tool.cpp
index 5900a2359..f3185649b 100644
--- a/src/ui/tools/measure-tool.cpp
+++ b/src/ui/tools/measure-tool.cpp
@@ -11,11 +11,10 @@
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
-# include <config.h>
+#include <config.h>
#endif
#include <gtkmm.h>
-#include <gdk/gdkkeysyms.h>
#include <boost/none_t.hpp>
#include "util/units.h"
#include "display/curve.h"
@@ -23,7 +22,6 @@
#include "display/sp-ctrlline.h"
#include "display/sp-ctrlcurve.h"
#include "display/sp-canvas.h"
-#include "display/sp-canvas-item.h"
#include "display/sp-canvas-util.h"
#include "svg/svg.h"
#include "svg/svg-color.h"
@@ -31,34 +29,20 @@
#include "ui/tools/freehand-base.h"
#include <2geom/line.h>
#include <2geom/path-intersection.h>
-#include <2geom/pathvector.h>
-#include <2geom/crossing.h>
-#include <2geom/angle.h>
-#include <2geom/transforms.h>
#include "ui/dialog/knot-properties.h"
#include "sp-namedview.h"
-#include "sp-shape.h"
#include "sp-text.h"
#include "sp-flowtext.h"
#include "sp-defs.h"
-#include "sp-item.h"
#include "sp-root.h"
-#include "macros.h"
#include "svg/stringstream.h"
#include "rubberband.h"
#include "path-chemistry.h"
#include "desktop.h"
-#include "document.h"
#include "document-undo.h"
-#include "viewbox.h"
-#include "snap.h"
-#include "knot.h"
#include "text-editing.h"
#include "pixmaps/cursor-measure.xpm"
-#include "preferences.h"
#include "inkscape.h"
-#include "enums.h"
-#include "knot-enums.h"
#include "desktop-style.h"
#include "verbs.h"
#include <glibmm/i18n.h>
@@ -346,13 +330,13 @@ MeasureTool::MeasureTool()
end_p = readMeasurePoint(false);
dimension_offset = 35;
// create the knots
- this->knot_start = new SPKnot(desktop, N_("Measure start, <b>Shift+Click</b> for position dialog"));
+ this->knot_start = new SPKnot(desktop, _("Measure start, <b>Shift+Click</b> for position dialog"));
this->knot_start->setMode(SP_KNOT_MODE_XOR);
this->knot_start->setFill(MT_KNOT_COLOR_NORMAL, MT_KNOT_COLOR_MOUSEOVER, MT_KNOT_COLOR_MOUSEOVER);
this->knot_start->setStroke(0x0000007f, 0x0000007f, 0x0000007f);
this->knot_start->setShape(SP_KNOT_SHAPE_CIRCLE);
this->knot_start->updateCtrl();
- this->knot_end = new SPKnot(desktop, N_("Measure end, <b>Shift+Click</b> for position dialog"));
+ this->knot_end = new SPKnot(desktop, _("Measure end, <b>Shift+Click</b> for position dialog"));
this->knot_end->setMode(SP_KNOT_MODE_XOR);
this->knot_end->setFill(MT_KNOT_COLOR_NORMAL, MT_KNOT_COLOR_MOUSEOVER, MT_KNOT_COLOR_MOUSEOVER);
this->knot_end->setStroke(0x0000007f, 0x0000007f, 0x0000007f);
@@ -394,6 +378,10 @@ MeasureTool::~MeasureTool()
sp_canvas_item_destroy(measure_tmp_items[idx]);
}
measure_tmp_items.clear();
+ for (size_t idx = 0; idx < measure_item.size(); ++idx) {
+ sp_canvas_item_destroy(measure_item[idx]);
+ }
+ measure_item.clear();
for (size_t idx = 0; idx < measure_phantom_items.size(); ++idx) {
sp_canvas_item_destroy(measure_phantom_items[idx]);
}
@@ -565,7 +553,6 @@ bool MeasureTool::root_handler(GdkEvent* event)
explicit_base = boost::none;
explicit_base_tmp = boost::none;
last_end = boost::none;
- start_p = desktop->w2d(button_w);
if (event->button.button == 1 && !this->space_panning) {
// save drag origin
@@ -608,6 +595,12 @@ bool MeasureTool::root_handler(GdkEvent* event)
snap_manager.preSnap(scp);
snap_manager.unSetup();
}
+ Geom::Point const motion_w(event->motion.x, event->motion.y);
+ if(event->motion.state & GDK_SHIFT_MASK) {
+ showInfoBox(motion_w, true);
+ } else {
+ showInfoBox(motion_w, false);
+ }
} else {
ret = TRUE;
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
@@ -1128,6 +1121,108 @@ void MeasureTool::setMeasureCanvasControlLine(Geom::Point start, Geom::Point end
}
}
+void MeasureTool::showItemInfoText(Geom::Point pos, gchar *measure_str, double fontsize)
+{
+ SPCanvasText *canvas_tooltip = sp_canvastext_new(desktop->getTempGroup(),
+ desktop,
+ pos,
+ measure_str);
+ sp_canvastext_set_fontsize(canvas_tooltip, fontsize);
+ canvas_tooltip->rgba = 0xffffffff;
+ canvas_tooltip->outline = false;
+ canvas_tooltip->background = true;
+ canvas_tooltip->anchor_position = TEXT_ANCHOR_LEFT;
+ canvas_tooltip->rgba_background = 0x00000099;
+ measure_item.push_back(SP_CANVAS_ITEM(canvas_tooltip));
+ sp_canvas_item_show(SP_CANVAS_ITEM(canvas_tooltip));
+}
+
+void MeasureTool::showInfoBox(Geom::Point cursor, bool into_groups)
+{
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ Inkscape::Util::Unit const * unit = desktop->getNamedView()->getDisplayUnit();
+ for (size_t idx = 0; idx < measure_item.size(); ++idx) {
+ sp_canvas_item_destroy(measure_item[idx]);
+ }
+ measure_item.clear();
+
+ SPItem *newover = desktop->getItemAtPoint(cursor, into_groups);
+ if (newover) {
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ double fontsize = prefs->getDouble("/tools/measure/fontsize", 10.0);
+ double scale = prefs->getDouble("/tools/measure/scale", 100.0) / 100.0;
+ int precision = prefs->getInt("/tools/measure/precision", 2);
+ Glib::ustring unit_name = prefs->getString("/tools/measure/unit");
+ if (!unit_name.compare("")) {
+ unit_name = "px";
+ }
+ Geom::Scale zoom = Geom::Scale(Inkscape::Util::Quantity::convert(desktop->current_zoom(), "px", unit->abbr)).inverse();
+ if(newover != over){
+ over = newover;
+ Preferences *prefs = Preferences::get();
+ int prefs_bbox = prefs->getBool("/tools/bounding_box", 0);
+ SPItem::BBoxType bbox_type = !prefs_bbox ? SPItem::VISUAL_BBOX : SPItem::GEOMETRIC_BBOX;
+ Geom::OptRect bbox = over->bounds(bbox_type);
+ if (bbox) {
+
+ item_width = Inkscape::Util::Quantity::convert((*bbox).width() * scale, unit->abbr, unit_name);
+ item_height = Inkscape::Util::Quantity::convert((*bbox).height() * scale, unit->abbr, unit_name);
+ item_x = Inkscape::Util::Quantity::convert((*bbox).left(), unit->abbr, unit_name);
+ Geom::Point y_point(0,Inkscape::Util::Quantity::convert((*bbox).bottom() * scale, unit->abbr, "px"));
+ y_point *= desktop->doc2dt();
+ item_y = Inkscape::Util::Quantity::convert(y_point[Geom::Y] * scale, "px", unit_name);
+ if (SP_IS_SHAPE(over)) {
+ Geom::PathVector shape = SP_SHAPE(over)->getCurve()->get_pathvector();
+ item_length = Geom::length(paths_to_pw(shape));
+ item_length = Inkscape::Util::Quantity::convert(item_length * scale, unit->abbr, unit_name);
+ }
+ }
+ }
+ gchar *measure_str = NULL;
+ std::stringstream precision_str;
+ precision_str.imbue(std::locale::classic());
+ double origin = Inkscape::Util::Quantity::convert(14, "px", unit->abbr);
+ Geom::Point rel_position = Geom::Point(origin, origin);
+ Geom::Point pos = desktop->w2d(cursor);
+ double gap = Inkscape::Util::Quantity::convert(7 + fontsize, "px", unit->abbr);
+ if (SP_IS_SHAPE(over)) {
+ precision_str << _("Length") << ": %." << precision << "f %s";
+ measure_str = g_strdup_printf(precision_str.str().c_str(), item_length, unit_name.c_str());
+ precision_str.str("");
+ showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize);
+ rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap);
+ } else if (SP_IS_GROUP(over)) {
+ measure_str = _("Shift to measure into group");
+ showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize);
+ rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap);
+ }
+
+ precision_str << "Y: %." << precision << "f %s";
+ measure_str = g_strdup_printf(precision_str.str().c_str(), item_y, unit_name.c_str());
+ precision_str.str("");
+ showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize);
+ rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap);
+
+ precision_str << "X: %." << precision << "f %s";
+ measure_str = g_strdup_printf(precision_str.str().c_str(), item_x, unit_name.c_str());
+ precision_str.str("");
+ showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize);
+ rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap);
+
+ precision_str << _("Height") << ": %." << precision << "f %s";
+ measure_str = g_strdup_printf(precision_str.str().c_str(), item_height, unit_name.c_str());
+ precision_str.str("");
+ showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize);
+ rel_position = Geom::Point(rel_position[Geom::X], rel_position[Geom::Y] + gap);
+
+ precision_str << _("Width") << ": %." << precision << "f %s";
+ measure_str = g_strdup_printf(precision_str.str().c_str(), item_width, unit_name.c_str());
+ precision_str.str("");
+ showItemInfoText(pos + (rel_position * zoom),measure_str,fontsize);
+ g_free(measure_str);
+ }
+}
+
void MeasureTool::showCanvasItems(bool to_guides, bool to_item, bool to_phantom, Inkscape::XML::Node *measure_repr)
{
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
diff --git a/src/ui/tools/measure-tool.h b/src/ui/tools/measure-tool.h
index 14fc9f81a..42122dca1 100644
--- a/src/ui/tools/measure-tool.h
+++ b/src/ui/tools/measure-tool.h
@@ -54,6 +54,8 @@ public:
virtual void setMarker(bool isStart);
virtual const std::string& getPrefsPath();
Geom::Point readMeasurePoint(bool is_start);
+ void showInfoBox(Geom::Point cursor, bool into_groups);
+ void showItemInfoText(Geom::Point pos, gchar *measure_str, double fontsize);
void writeMeasurePoint(Geom::Point point, bool is_start);
void setGuide(Geom::Point origin, double angle, const char *label);
void setPoint(Geom::Point origin, Inkscape::XML::Node *measure_repr);
@@ -77,6 +79,13 @@ private:
Geom::Point end_p;
std::vector<SPCanvasItem *> measure_tmp_items;
std::vector<SPCanvasItem *> measure_phantom_items;
+ std::vector<SPCanvasItem *> measure_item;
+ double item_width;
+ double item_height;
+ double item_x;
+ double item_y;
+ double item_length;
+ SPItem *over;
sigc::connection _knot_start_moved_connection;
sigc::connection _knot_start_ungrabbed_connection;
sigc::connection _knot_start_click_connection;
diff --git a/src/ui/tools/mesh-tool.cpp b/src/ui/tools/mesh-tool.cpp
index 47927667c..ac43b6c9d 100644
--- a/src/ui/tools/mesh-tool.cpp
+++ b/src/ui/tools/mesh-tool.cpp
@@ -15,7 +15,7 @@
*/
#ifdef HAVE_CONFIG_H
-# include "config.h"
+#include <config.h>
#endif
//#define DEBUG_MESH
@@ -33,12 +33,15 @@
#include "macros.h"
#include "message-context.h"
#include "message-stack.h"
-#include "preferences.h"
#include "rubberband.h"
#include "selection.h"
#include "snap.h"
#include "sp-namedview.h"
#include "verbs.h"
+#include "sp-text.h"
+#include "sp-defs.h"
+#include "style.h"
+#include "ui/control-manager.h"
// Gradient specific
#include "gradient-drag.h"
@@ -48,8 +51,9 @@
// Mesh specific
#include "ui/tools/mesh-tool.h"
-#include "sp-mesh.h"
+#include "sp-mesh-gradient.h"
#include "display/sp-ctrlcurve.h"
+#include "display/curve.h"
using Inkscape::DocumentUndo;
@@ -57,7 +61,7 @@ namespace Inkscape {
namespace UI {
namespace Tools {
-static void sp_mesh_end_drag(MeshTool &rc);
+static void sp_mesh_new_default(MeshTool &rc);
const std::string& MeshTool::getPrefsPath() {
return MeshTool::prefsPath;
@@ -71,6 +75,9 @@ MeshTool::MeshTool()
: ToolBase(cursor_gradient_xpm, 4, 4)
, cursor_addnode(false)
, node_added(false)
+ , show_handles(true)
+ , edit_fill(true)
+ , edit_stroke(true)
// TODO: Why are these connections stored as pointers?
, selcon(NULL)
, subselcon(NULL)
@@ -89,7 +96,19 @@ MeshTool::~MeshTool() {
delete this->subselcon;
}
+// This must match GrPointType enum sp-gradient.h
+// We should move this to a shared header (can't simply move to gradient.h since that would require
+// including <glibmm/i18n.h> which messes up "N_" in extensions... argh!).
const gchar *ms_handle_descr [] = {
+ N_("Linear gradient <b>start</b>"), //POINT_LG_BEGIN
+ N_("Linear gradient <b>end</b>"),
+ N_("Linear gradient <b>mid stop</b>"),
+ N_("Radial gradient <b>center</b>"),
+ N_("Radial gradient <b>radius</b>"),
+ N_("Radial gradient <b>radius</b>"),
+ N_("Radial gradient <b>focus</b>"), // POINT_RG_FOCUS
+ N_("Radial gradient <b>mid stop</b>"),
+ N_("Radial gradient <b>mid stop</b>"),
N_("Mesh gradient <b>corner</b>"),
N_("Mesh gradient <b>handle</b>"),
N_("Mesh gradient <b>tensor</b>")
@@ -103,7 +122,7 @@ void MeshTool::selection_changed(Inkscape::Selection* /*sel*/) {
return;
}
- guint n_obj = selection->itemList().size();
+ guint n_obj = (guint) boost::distance(selection->items());
if (!drag->isNonEmpty() || selection->isEmpty()) {
return;
@@ -162,9 +181,9 @@ void MeshTool::selection_changed(Inkscape::Selection* /*sel*/) {
// if (style && (style->fill.isPaintserver())) {
// SPPaintServer *server = item->style->getFillPaintServer();
- // if ( SP_IS_MESH(server) ) {
+ // if ( SP_IS_MESHGRADIENT(server) ) {
- // SPMesh *mg = SP_MESH(server);
+ // SPMeshGradient *mg = SP_MESHGRADIENT(server);
// guint rows = 0;//mg->array.patches.size();
// for ( guint i = 0; i < rows; ++i ) {
@@ -237,7 +256,25 @@ void MeshTool::setup() {
)
));
+ sp_event_context_read(this, "show_handles");
+ sp_event_context_read(this, "edit_fill");
+ sp_event_context_read(this, "edit_stroke");
+
this->selection_changed(selection);
+
+}
+
+void MeshTool::set(const Inkscape::Preferences::Entry& value) {
+ Glib::ustring entry_name = value.getEntryName();
+ if (entry_name == "show_handles") {
+ this->show_handles = value.getBool(true);
+ } else if (entry_name == "edit_fill") {
+ this->edit_fill = value.getBool(true);
+ } else if (entry_name == "edit_stroke") {
+ this->edit_stroke = value.getBool(true);
+ } else {
+ ToolBase::set(value);
+ }
}
void
@@ -263,28 +300,39 @@ sp_mesh_context_select_prev (ToolBase *event_context)
}
/**
-Returns true if mouse cursor over mesh edge.
+Returns vector of control lines mouse is over. Returns only first if 'first' is true.
*/
-static bool
-sp_mesh_context_is_over_line (MeshTool *rc, SPItem *item, Geom::Point event_p)
+static std::vector<SPCtrlCurve *>
+sp_mesh_context_over_line (MeshTool *rc, Geom::Point event_p, bool first = true)
{
SPDesktop *desktop = SP_EVENT_CONTEXT (rc)->desktop;
//Translate mouse point into proper coord system
rc->mousepoint_doc = desktop->w2d(event_p);
- SPCtrlCurve *curve = SP_CTRLCURVE(item);
- Geom::BezierCurveN<3> b( curve->p0, curve->p1, curve->p2, curve->p3 );
- Geom::Coord coord = b.nearestTime( rc->mousepoint_doc ); // Coord == double
- Geom::Point nearest = b( coord );
+ double tolerance = (double) SP_EVENT_CONTEXT(rc)->tolerance;
+
+ GrDrag *drag = rc->_grdrag;
- double dist_screen = Geom::L2 (rc->mousepoint_doc - nearest) * desktop->current_zoom();
+ std::vector<SPCtrlCurve *> selected;
- double tolerance = (double) SP_EVENT_CONTEXT(rc)->tolerance;
+ for (std::vector<SPCtrlLine *>::const_iterator l = drag->lines.begin(); l != drag->lines.end(); ++l) {
+ if (!SP_IS_CTRLCURVE(*l)) continue;
- bool close = (dist_screen < tolerance);
+ SPCtrlCurve *curve = SP_CTRLCURVE(*l);
+ Geom::BezierCurveN<3> b( curve->p0, curve->p1, curve->p2, curve->p3 );
+ Geom::Coord coord = b.nearestTime( rc->mousepoint_doc ); // Coord == double
+ Geom::Point nearest = b( coord );
- return close;
+ double dist_screen = Geom::L2 (rc->mousepoint_doc - nearest) * desktop->current_zoom();
+ if (dist_screen < tolerance) {
+ selected.push_back(curve);
+ if (first) {
+ break;
+ }
+ }
+ }
+ return selected;
}
@@ -327,14 +375,15 @@ sp_mesh_context_corner_operation (MeshTool *rc, MeshCornerOperation operation )
SPDocument *doc = NULL;
GrDrag *drag = rc->_grdrag;
- std::map<SPMesh*, std::vector<guint> > points;
- std::map<SPMesh*, SPItem*> items;
-
+ std::map<SPMeshGradient*, std::vector<guint> > points;
+ std::map<SPMeshGradient*, SPItem*> items;
+ std::map<SPMeshGradient*, Inkscape::PaintTarget> fill_or_stroke;
+
// Get list of selected draggers for each mesh.
- // For all selected draggers
+ // For all selected draggers (a dragger may include draggerables from different meshes).
for (std::set<GrDragger *>::const_iterator i = drag->selected.begin(); i != drag->selected.end(); ++i) {
GrDragger *dragger = *i;
- // For all draggables of dragger
+ // For all draggables of dragger (a draggable corresponds to a unique mesh).
for (std::vector<GrDraggable *>::const_iterator j = dragger->draggables.begin(); j != dragger->draggables.end() ; ++j) {
GrDraggable *d = *j;
@@ -342,17 +391,18 @@ sp_mesh_context_corner_operation (MeshTool *rc, MeshCornerOperation operation )
if( d->point_type != POINT_MG_CORNER ) continue;
// Find the gradient
- SPMesh *gradient = SP_MESH( getGradient (d->item, d->fill_or_stroke) );
+ SPMeshGradient *gradient = SP_MESHGRADIENT( getGradient (d->item, d->fill_or_stroke) );
// Collect points together for same gradient
points[gradient].push_back( d->point_i );
items[gradient] = d->item;
+ fill_or_stroke[gradient] = d->fill_or_stroke ? Inkscape::FOR_FILL: Inkscape::FOR_STROKE;
}
}
// Loop over meshes.
- for( std::map<SPMesh*, std::vector<guint> >::const_iterator iter = points.begin(); iter != points.end(); ++iter) {
- SPMesh *mg = SP_MESH( iter->first );
+ for( std::map<SPMeshGradient*, std::vector<guint> >::const_iterator iter = points.begin(); iter != points.end(); ++iter) {
+ SPMeshGradient *mg = SP_MESHGRADIENT( iter->first );
if( iter->second.size() > 0 ) {
guint noperation = 0;
switch (operation) {
@@ -382,6 +432,11 @@ sp_mesh_context_corner_operation (MeshTool *rc, MeshCornerOperation operation )
noperation += mg->array.color_pick( iter->second, items[iter->first] );
break;
+ case MG_CORNER_INSERT:
+ // std::cout << "INSERT" << std::endl;
+ noperation += mg->array.insert( iter->second );
+ break;
+
default:
std::cout << "sp_mesh_corner_operation: unknown operation" << std::endl;
}
@@ -395,22 +450,31 @@ sp_mesh_context_corner_operation (MeshTool *rc, MeshCornerOperation operation )
case MG_CORNER_SIDE_TOGGLE:
DocumentUndo::done(doc, SP_VERB_CONTEXT_MESH, _("Toggled mesh path type."));
+ drag->local_change = true; // Don't create new draggers.
break;
case MG_CORNER_SIDE_ARC:
DocumentUndo::done(doc, SP_VERB_CONTEXT_MESH, _("Approximated arc for mesh side."));
+ drag->local_change = true; // Don't create new draggers.
break;
case MG_CORNER_TENSOR_TOGGLE:
DocumentUndo::done(doc, SP_VERB_CONTEXT_MESH, _("Toggled mesh tensors."));
+ drag->local_change = true; // Don't create new draggers.
break;
case MG_CORNER_COLOR_SMOOTH:
DocumentUndo::done(doc, SP_VERB_CONTEXT_MESH, _("Smoothed mesh corner color."));
+ drag->local_change = true; // Don't create new draggers.
break;
case MG_CORNER_COLOR_PICK:
DocumentUndo::done(doc, SP_VERB_CONTEXT_MESH, _("Picked mesh corner color."));
+ drag->local_change = true; // Don't create new draggers.
+ break;
+
+ case MG_CORNER_INSERT:
+ DocumentUndo::done(doc, SP_VERB_CONTEXT_MESH, _("Inserted new row or column."));
break;
default:
@@ -419,13 +483,76 @@ sp_mesh_context_corner_operation (MeshTool *rc, MeshCornerOperation operation )
}
}
}
- drag->updateDraggers();
+
+ // Not needed. Update is done via gr_drag_sel_modified().
+ // drag->updateDraggers();
}
/**
+ * Scale mesh to just fit into bbox of selected items.
+ */
+void
+sp_mesh_context_fit_mesh_in_bbox (MeshTool *rc)
+{
+
+#ifdef DEBUG_MESH
+ std::cout << "sp_mesh_context_fit_mesh_in_bbox: entrance: Entrance"<< std::endl;
+#endif
+
+ SPDesktop *desktop = SP_EVENT_CONTEXT (rc)->desktop;
+
+ Inkscape::Selection *selection = desktop->getSelection();
+ if (selection == NULL) {
+ return;
+ }
+
+ bool changed = false;
+ auto itemlist = selection->items();
+ for (auto i=itemlist.begin(); i!=itemlist.end(); ++i) {
+
+ SPItem *item = *i;
+ SPStyle *style = item->style;
+
+ if (style) {
+
+ if (style->fill.isPaintserver()) {
+ SPPaintServer *server = item->style->getFillPaintServer();
+ if ( SP_IS_MESHGRADIENT(server) ) {
+
+ Geom::OptRect item_bbox = item->geometricBounds();
+ SPMeshGradient *gradient = SP_MESHGRADIENT(server);
+ if (gradient->array.fill_box( item_bbox )) {
+ changed = true;
+ }
+ }
+ }
+
+ if (style->stroke.isPaintserver()) {
+ SPPaintServer *server = item->style->getStrokePaintServer();
+ if ( SP_IS_MESHGRADIENT(server) ) {
+
+ Geom::OptRect item_bbox = item->visualBounds();
+ SPMeshGradient *gradient = SP_MESHGRADIENT(server);
+ if (gradient->array.fill_box( item_bbox )) {
+ changed = true;
+ }
+ }
+ }
+
+ }
+ }
+ if (changed) {
+ DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MESH,
+ _("Fit mesh inside bounding box."));
+ }
+}
+
+
+/**
Handles all keyboard and mouse input for meshs.
+Note: node/handle events are take care of elsewhere.
*/
bool MeshTool::root_handler(GdkEvent* event) {
static bool dragging;
@@ -450,43 +577,42 @@ bool MeshTool::root_handler(GdkEvent* event) {
// Double click:
// If over a mesh line, divide mesh row/column
- // If not over a line, create new gradients for selected objects.
+ // If not over a line and no mesh, create new mesh for top selected object.
if ( event->button.button == 1 ) {
- // Are we over a mesh line?
- bool over_line = false;
- SPCtrlCurve *line = NULL;
- if (! drag->lines.empty()) {
- for (std::vector<SPCtrlLine *>::const_iterator l = drag->lines.begin(); l != drag->lines.end() && (!over_line); ++l) {
- line = (SPCtrlCurve*) (*l);
- over_line |= sp_mesh_context_is_over_line (this, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y));
- }
- }
+ // Are we over a mesh line?
+ std::vector<SPCtrlCurve *> over_line =
+ sp_mesh_context_over_line(this, Geom::Point(event->motion.x, event->motion.y));
- if (over_line) {
+ if (!over_line.empty()) {
// We take the first item in selection, because with doubleclick, the first click
// always resets selection to the single object under cursor
- sp_mesh_context_split_near_point(this, selection->itemList()[0], this->mousepoint_doc, event->button.time);
+ sp_mesh_context_split_near_point(this, selection->items().front(), this->mousepoint_doc, event->button.time);
} else {
// Create a new gradient with default coordinates.
- std::vector<SPItem*> items=selection->itemList();
- for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){
- SPItem *item = *i;
- SPGradientType new_type = SP_GRADIENT_TYPE_MESH;
- Inkscape::PaintTarget fsmode = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
-#ifdef DEBUG_MESH
- std::cout << "sp_mesh_context_root_handler: creating new mesh on: " << (fsmode == Inkscape::FOR_FILL ? "Fill" : "Stroke") << std::endl;
-#endif
- SPGradient *vector = sp_gradient_vector_for_object(desktop->getDocument(), desktop, item, fsmode);
-
- SPGradient *priv = sp_item_set_gradient(item, vector, new_type, fsmode);
- sp_gradient_reset_to_userspace(priv, item);
+ // Check if object already has mesh... if it does,
+ // don't create new mesh with click-drag.
+ bool has_mesh = false;
+ if (!selection->isEmpty()) {
+ SPStyle *style = selection->items().front()->style;
+ if (style) {
+ Inkscape::PaintTarget fill_or_stroke =
+ (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ?
+ Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
+ SPPaintServer *server =
+ (fill_or_stroke == Inkscape::FOR_FILL) ?
+ style->getFillPaintServer():
+ style->getStrokePaintServer();
+ if (server && SP_IS_MESHGRADIENT(server))
+ has_mesh = true;
+ }
}
- DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MESH,
- _("Create default mesh"));
+ if (!has_mesh) {
+ sp_mesh_new_default(*this);
+ }
}
ret = TRUE;
@@ -498,10 +624,36 @@ bool MeshTool::root_handler(GdkEvent* event) {
#ifdef DEBUG_MESH
std::cout << "sp_mesh_context_root_handler: GDK_BUTTON_PRESS" << std::endl;
#endif
+
// Button down
- // If Shift key down: do rubber band selection
- // Else set origin for drag. A drag creates a new gradient if one does not exist
+ // If mesh already exists, do rubber band selection.
+ // Else set origin for drag which will create a new gradient.
if ( event->button.button == 1 && !this->space_panning ) {
+
+ // Are we over a mesh line?
+ std::vector<SPCtrlCurve *> over_line =
+ sp_mesh_context_over_line(this, Geom::Point(event->motion.x, event->motion.y), false);
+
+ if (!over_line.empty()) {
+ for (std::vector<SPCtrlCurve *>::const_iterator it = over_line.begin();
+ it != over_line.end(); ++it ) {
+ SPItem *item = (*it)->item;
+ Inkscape::PaintTarget fill_or_stroke =
+ (*it)->is_fill ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
+ GrDragger* dragger0 = drag->getDraggerFor(item, POINT_MG_CORNER, (*it)->corner0, fill_or_stroke);
+ GrDragger* dragger1 = drag->getDraggerFor(item, POINT_MG_CORNER, (*it)->corner1, fill_or_stroke);
+ bool add = (event->button.state & GDK_SHIFT_MASK);
+ bool toggle = (event->button.state & GDK_CONTROL_MASK);
+ if ( !add && !toggle ) {
+ drag->deselectAll();
+ }
+ drag->setSelected( dragger0, true, !toggle );
+ drag->setSelected( dragger1, true, !toggle );
+ }
+ ret = true;
+ break; // To avoid putting the following code in an else block.
+ }
+
Geom::Point button_w(event->button.x, event->button.y);
// save drag origin
@@ -512,25 +664,43 @@ bool MeshTool::root_handler(GdkEvent* event) {
dragging = true;
Geom::Point button_dt = desktop->w2d(button_w);
- if (event->button.state & GDK_SHIFT_MASK) {
- Inkscape::Rubberband::get(desktop)->start(desktop, button_dt);
- } else {
- // remember clicked item, disregarding groups, honoring Alt; do nothing with Crtl to
- // enable Ctrl+doubleclick of exactly the selected item(s)
- if (!(event->button.state & GDK_CONTROL_MASK)) {
- this->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, TRUE);
+ // Check if object already has mesh... if it does,
+ // don't create new mesh with click-drag.
+ bool has_mesh = false;
+ if (!selection->isEmpty()) {
+ SPStyle *style = selection->items().front()->style;
+ if (style) {
+ Inkscape::PaintTarget fill_or_stroke =
+ (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ?
+ Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
+ SPPaintServer *server =
+ (fill_or_stroke == Inkscape::FOR_FILL) ?
+ style->getFillPaintServer():
+ style->getStrokePaintServer();
+ if (server && SP_IS_MESHGRADIENT(server))
+ has_mesh = true;
}
+ }
- if (!selection->isEmpty()) {
- SnapManager &m = desktop->namedview->snap_manager;
- m.setup(desktop);
- m.freeSnapReturnByRef(button_dt, Inkscape::SNAPSOURCE_NODE_HANDLE);
- m.unSetup();
- }
+ if (has_mesh) {
+ Inkscape::Rubberband::get(desktop)->start(desktop, button_dt);
+ }
- this->origin = button_dt;
+ // remember clicked item, disregarding groups, honoring Alt; do nothing with Crtl to
+ // enable Ctrl+doubleclick of exactly the selected item(s)
+ if (!(event->button.state & GDK_CONTROL_MASK)) {
+ this->item_to_select = sp_event_context_find_item (desktop, button_w, event->button.state & GDK_MOD1_MASK, TRUE);
}
+ if (!selection->isEmpty()) {
+ SnapManager &m = desktop->namedview->snap_manager;
+ m.setup(desktop);
+ m.freeSnapReturnByRef(button_dt, Inkscape::SNAPSOURCE_NODE_HANDLE);
+ m.unSetup();
+ }
+
+ this->origin = button_dt;
+
ret = TRUE;
}
break;
@@ -591,19 +761,14 @@ bool MeshTool::root_handler(GdkEvent* event) {
}
// Change cursor shape if over line
- bool over_line = false;
+ std::vector<SPCtrlCurve *> over_line =
+ sp_mesh_context_over_line(this, Geom::Point(event->motion.x, event->motion.y));
- if (!drag->lines.empty()) {
- for (std::vector<SPCtrlLine *>::const_iterator l = drag->lines.begin(); l != drag->lines.end() ; ++l) {
- over_line |= sp_mesh_context_is_over_line (this, (SPItem*)(*l), Geom::Point(event->motion.x, event->motion.y));
- }
- }
-
- if (this->cursor_addnode && !over_line) {
+ if (this->cursor_addnode && over_line.empty()) {
this->cursor_shape = cursor_gradient_xpm;
this->sp_event_context_update_cursor();
this->cursor_addnode = false;
- } else if (!this->cursor_addnode && over_line) {
+ } else if (!this->cursor_addnode && !over_line.empty()) {
this->cursor_shape = cursor_gradient_add_xpm;
this->sp_event_context_update_cursor();
this->cursor_addnode = true;
@@ -620,24 +785,15 @@ bool MeshTool::root_handler(GdkEvent* event) {
this->xp = this->yp = 0;
if ( event->button.button == 1 && !this->space_panning ) {
- // Check if over line
- bool over_line = false;
- SPCtrlLine *line = NULL;
- if (!drag->lines.empty()) {
- for (std::vector<SPCtrlLine *>::const_iterator l = drag->lines.begin(); l != drag->lines.end() && (!over_line); ++l) {
- line = (SPCtrlLine*)(*l);
- over_line = sp_mesh_context_is_over_line (this, (SPItem*) line, Geom::Point(event->motion.x, event->motion.y));
-
- if (over_line) {
- break;
- }
- }
- }
+ // Check if over line
+ std::vector<SPCtrlCurve *> over_line =
+ sp_mesh_context_over_line(this, Geom::Point(event->motion.x, event->motion.y));
if ( (event->button.state & GDK_CONTROL_MASK) && (event->button.state & GDK_MOD1_MASK ) ) {
- if (over_line && line) {
- sp_mesh_context_split_near_point(this, line->item, this->mousepoint_doc, 0);
+ if (!over_line.empty()) {
+ sp_mesh_context_split_near_point(this, over_line[0]->item,
+ this->mousepoint_doc, 0);
ret = TRUE;
}
} else {
@@ -650,22 +806,47 @@ bool MeshTool::root_handler(GdkEvent* event) {
}
if (!this->within_tolerance) {
- // we've been dragging, either create a new gradient
- // or rubberband-select if we have rubberband
- Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop);
-
- if (r->is_started() && !this->within_tolerance) {
- // this was a rubberband drag
- if (r->getMode() == RUBBERBAND_MODE_RECT) {
- Geom::OptRect const b = r->getRectangle();
- drag->selectRect(*b);
+
+ // Check if object already has mesh... if it does,
+ // don't create new mesh with click-drag.
+ bool has_mesh = false;
+ if (!selection->isEmpty()) {
+ SPStyle *style = selection->items().front()->style;
+ if (style) {
+ Inkscape::PaintTarget fill_or_stroke =
+ (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ?
+ Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
+ SPPaintServer *server =
+ (fill_or_stroke == Inkscape::FOR_FILL) ?
+ style->getFillPaintServer():
+ style->getStrokePaintServer();
+ if (server && SP_IS_MESHGRADIENT(server))
+ has_mesh = true;
}
+ }
+
+ if (!has_mesh) {
+ sp_mesh_new_default(*this);
} else {
- // Create a new mesh gradient
- sp_mesh_end_drag(*this);
+
+ // we've been dragging, either create a new gradient
+ // or rubberband-select if we have rubberband
+ Inkscape::Rubberband *r = Inkscape::Rubberband::get(desktop);
+
+ if (r->is_started() && !this->within_tolerance) {
+ // this was a rubberband drag
+ if (r->getMode() == RUBBERBAND_MODE_RECT) {
+ Geom::OptRect const b = r->getRectangle();
+ if (!(event->button.state & GDK_SHIFT_MASK)) {
+ drag->deselectAll();
+ }
+ drag->selectRect(*b);
+ }
+ }
}
+
} else if (this->item_to_select) {
- if (over_line && line) {
+ if (!over_line.empty()) {
// Clicked on an existing mesh line, don't change selection. This stops
// possible change in selection during a double click with overlapping objects
} else {
@@ -673,15 +854,21 @@ bool MeshTool::root_handler(GdkEvent* event) {
if (event->button.state & GDK_SHIFT_MASK) {
selection->toggle(this->item_to_select);
} else {
+ drag->deselectAll();
selection->set(this->item_to_select);
}
}
} else {
- // click in an empty space; do the same as Esc
- if (!drag->selected.empty()) {
- drag->deselectAll();
+ if (!over_line.empty()) {
+ // Clicked on an existing mesh line, don't change selection. This stops
+ // possible change in selection during a double click with overlapping objects
} else {
- selection->clear();
+ // click in an empty space; do the same as Esc
+ if (!drag->selected.empty()) {
+ drag->deselectAll();
+ } else {
+ selection->clear();
+ }
}
}
@@ -709,10 +896,11 @@ bool MeshTool::root_handler(GdkEvent* event) {
case GDK_KEY_Shift_R:
case GDK_KEY_Meta_L: // Meta is when you press Shift+Alt (at least on my machine)
case GDK_KEY_Meta_R:
- sp_event_show_modifier_tip (this->defaultMessageContext(), event,
- _("FIXME<b>Ctrl</b>: snap mesh angle"),
- _("FIXME<b>Shift</b>: draw mesh around the starting point"),
- NULL);
+
+ // sp_event_show_modifier_tip (this->defaultMessageContext(), event,
+ // _("FIXME<b>Ctrl</b>: snap mesh angle"),
+ // _("FIXME<b>Shift</b>: draw mesh around the starting point"),
+ // NULL);
break;
case GDK_KEY_A:
@@ -830,25 +1018,33 @@ bool MeshTool::root_handler(GdkEvent* event) {
}
break;
+ // Mesh Operations --------------------------------------------
+
case GDK_KEY_Insert:
case GDK_KEY_KP_Insert:
// with any modifiers:
- //sp_gradient_context_add_stops_between_selected_stops (rc);
- std::cout << "Inserting stops between selected stops not implemented yet" << std::endl;
+ sp_mesh_context_corner_operation ( this, MG_CORNER_INSERT );
ret = TRUE;
break;
+ case GDK_KEY_i:
+ case GDK_KEY_I:
+ if (MOD__SHIFT_ONLY(event)) {
+ // Shift+I - insert corners (alternate keybinding for keyboards
+ // that don't have the Insert key)
+ sp_mesh_context_corner_operation ( this, MG_CORNER_INSERT );
+ ret = TRUE;
+ }
+ break;
+
case GDK_KEY_Delete:
case GDK_KEY_KP_Delete:
case GDK_KEY_BackSpace:
if ( !drag->selected.empty() ) {
- std::cout << "Deleting mesh stops not implemented yet" << std::endl;
ret = TRUE;
}
break;
- // Mesh Operations --------------------------------------------
-
case GDK_KEY_b: // Toggle mesh side between lineto and curveto.
case GDK_KEY_B:
if (MOD__ALT(event) && drag->isNonEmpty() && drag->hasSelection()) {
@@ -926,7 +1122,8 @@ bool MeshTool::root_handler(GdkEvent* event) {
return ret;
}
-static void sp_mesh_end_drag(MeshTool &rc) {
+// Creates a new mesh gradient.
+static void sp_mesh_new_default(MeshTool &rc) {
SPDesktop *desktop = SP_EVENT_CONTEXT(&rc)->desktop;
Inkscape::Selection *selection = desktop->getSelection();
SPDocument *document = desktop->getDocument();
@@ -935,44 +1132,65 @@ static void sp_mesh_end_drag(MeshTool &rc) {
if (!selection->isEmpty()) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- int type = SP_GRADIENT_TYPE_MESH;
- Inkscape::PaintTarget fill_or_stroke = (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ? Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
-
- SPGradient *vector;
- if (ec->item_to_select) {
- // pick color from the object where drag started
- vector = sp_gradient_vector_for_object(document, desktop, ec->item_to_select, fill_or_stroke);
+ Inkscape::PaintTarget fill_or_stroke =
+ (prefs->getInt("/tools/gradient/newfillorstroke", 1) != 0) ?
+ Inkscape::FOR_FILL : Inkscape::FOR_STROKE;
+
+ // Ensure mesh is immediately editable.
+ // Editing both fill and stroke at same time doesn't work well so avoid.
+ if (fill_or_stroke == Inkscape::FOR_FILL) {
+ prefs->setBool("/tools/mesh/edit_fill", true );
+ prefs->setBool("/tools/mesh/edit_stroke", false);
} else {
- // Starting from empty space:
- // Sort items so that the topmost comes last
- std::vector<SPItem*> items(selection->itemList());
- sort(items.begin(),items.end(),sp_item_repr_compare_position);
- // take topmost
- vector = sp_gradient_vector_for_object(document, desktop, SP_ITEM(items.back()), fill_or_stroke);
+ prefs->setBool("/tools/mesh/edit_fill", false);
+ prefs->setBool("/tools/mesh/edit_stroke", true );
}
- // HACK: reset fill-opacity - that 0.75 is annoying; BUT remove this when we have an opacity slider for all tabs
+// HACK: reset fill-opacity - that 0.75 is annoying; BUT remove this when we have an opacity slider for all tabs
SPCSSAttr *css = sp_repr_css_attr_new();
sp_repr_css_set_property(css, "fill-opacity", "1.0");
- std::vector<SPItem*> items=selection->itemList();
- for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){
+ Inkscape::XML::Document *xml_doc = document->getReprDoc();
+ SPDefs *defs = document->getDefs();
+
+ auto items= selection->items();
+ for(auto i=items.begin();i!=items.end();++i){
//FIXME: see above
sp_repr_css_change_recursive((*i)->getRepr(), css, "style");
- sp_item_set_gradient(*i, vector, (SPGradientType) type, fill_or_stroke);
+ // Create mesh element
+ Inkscape::XML::Node *repr = xml_doc->createElement("svg:meshgradient");
- // We don't need to do anything. Mesh is already sized appropriately.
-
- (*i)->requestModified(SP_OBJECT_MODIFIED_FLAG);
+ // privates are garbage-collectable
+ repr->setAttribute("inkscape:collect", "always");
+
+ // Attach to document
+ defs->getRepr()->appendChild(repr);
+ Inkscape::GC::release(repr);
+
+ // Get corresponding object
+ SPMeshGradient *mg = static_cast<SPMeshGradient *>(document->getObjectByRepr(repr));
+ mg->array.create(mg, *i, (fill_or_stroke == Inkscape::FOR_FILL) ?
+ (*i)->geometricBounds() : (*i)->visualBounds());
+
+ bool isText = SP_IS_TEXT(*i);
+ sp_style_set_property_url (*i, ((fill_or_stroke == Inkscape::FOR_FILL) ? "fill":"stroke"),
+ mg, isText);
+
+ (*i)->requestModified(SP_OBJECT_MODIFIED_FLAG|SP_OBJECT_STYLE_MODIFIED_FLAG);
+ }
+
+ if (css) {
+ sp_repr_css_attr_unref(css);
+ css = 0;
}
DocumentUndo::done(desktop->getDocument(), SP_VERB_CONTEXT_MESH, _("Create mesh"));
// status text; we do not track coords because this branch is run once, not all the time
// during drag
- int n_objects = selection->itemList().size();
+ int n_objects = (int) boost::distance(selection->items());
rc.message_context->setF(Inkscape::NORMAL_MESSAGE,
ngettext("<b>Gradient</b> for %d object; with <b>Ctrl</b> to snap angle",
"<b>Gradient</b> for %d objects; with <b>Ctrl</b> to snap angle", n_objects),
@@ -982,7 +1200,6 @@ static void sp_mesh_end_drag(MeshTool &rc) {
}
}
-
}
}
}
diff --git a/src/ui/tools/mesh-tool.h b/src/ui/tools/mesh-tool.h
index 91b35b3af..1f012dc53 100644
--- a/src/ui/tools/mesh-tool.h
+++ b/src/ui/tools/mesh-tool.h
@@ -31,34 +31,40 @@ namespace Tools {
class MeshTool : public ToolBase {
public:
- MeshTool();
- virtual ~MeshTool();
+ MeshTool();
+ virtual ~MeshTool();
Geom::Point origin;
- bool cursor_addnode;
-
- bool node_added;
-
Geom::Point mousepoint_doc; // stores mousepoint when over_line in doc coords
sigc::connection *selcon;
sigc::connection *subselcon;
- static const std::string prefsPath;
+ static const std::string prefsPath;
- virtual void setup();
- virtual bool root_handler(GdkEvent* event);
+ virtual void setup();
+ virtual void set(const Inkscape::Preferences::Entry& val);
+ virtual bool root_handler(GdkEvent* event);
- virtual const std::string& getPrefsPath();
+ virtual const std::string& getPrefsPath();
private:
- void selection_changed(Inkscape::Selection* sel);
+ void selection_changed(Inkscape::Selection* sel);
+
+ bool cursor_addnode;
+ bool node_added;
+ bool show_handles;
+ bool edit_fill;
+ bool edit_stroke;
+
+
};
void sp_mesh_context_select_next(ToolBase *event_context);
void sp_mesh_context_select_prev(ToolBase *event_context);
void sp_mesh_context_corner_operation(MeshTool *event_context, MeshCornerOperation operation );
+void sp_mesh_context_fit_mesh_in_bbox(MeshTool *event_context);
}
}
diff --git a/src/ui/tools/node-tool.cpp b/src/ui/tools/node-tool.cpp
index 23aaf6bb1..0c948c91c 100644
--- a/src/ui/tools/node-tool.cpp
+++ b/src/ui/tools/node-tool.cpp
@@ -24,25 +24,21 @@
#include "message-context.h"
#include "selection.h"
#include "ui/shape-editor.h" // temporary!
-#include "live_effects/effect.h"
-#include "display/curve.h"
#include "snap.h"
#include "sp-namedview.h"
#include "sp-clippath.h"
#include "sp-item-group.h"
#include "sp-mask.h"
-#include "sp-object-group.h"
-#include "sp-path.h"
#include "sp-text.h"
#include "ui/control-manager.h"
#include "ui/tools/node-tool.h"
+#include "ui/tools-switch.h"
+#include "ui/tools/tool-base.h"
#include "ui/tool/control-point-selection.h"
#include "ui/tool/event-utils.h"
-#include "ui/tool/manipulator.h"
#include "ui/tool/multi-path-manipulator.h"
#include "ui/tool/path-manipulator.h"
#include "ui/tool/selector.h"
-#include "ui/tool/shape-record.h"
#include "pixmaps/cursor-node.xpm"
#include "pixmaps/cursor-node-d.xpm"
@@ -215,7 +211,7 @@ void NodeTool::setup() {
this->_sizeUpdatedConn = ControlManager::getManager().connectCtrlSizeChanged(
sigc::mem_fun(this, &NodeTool::handleControlUiStyleChange)
);
-
+ this->helperpath_tmpitem = NULL;
this->_selected_nodes = new Inkscape::UI::ControlPointSelection(this->desktop, this->_transform_handle_group);
data.node_data.selection = this->_selected_nodes;
@@ -243,14 +239,12 @@ void NodeTool::setup() {
)))
);
- this->helperpath_tmpitem = NULL;
this->cursor_drag = false;
this->show_transform_handles = true;
this->single_node_transform_handles = false;
this->flash_tempitem = NULL;
this->flashed_item = NULL;
this->_last_over = NULL;
- this->helperpath_tmpitem = NULL;
// read prefs before adding items to selection to prevent momentarily showing the outline
sp_event_context_read(this, "show_handles");
@@ -277,31 +271,34 @@ void NodeTool::setup() {
}
this->desktop->emitToolSubselectionChanged(NULL); // sets the coord entry fields to inactive
- this->update_helperpath();
+ sp_update_helperpath();
}
// show helper paths of the applied LPE, if any
-void NodeTool::update_helperpath () {
- Inkscape::Selection *selection = this->desktop->getSelection();
-
- if (this->helperpath_tmpitem) {
- this->desktop->remove_temporary_canvasitem(this->helperpath_tmpitem);
- this->helperpath_tmpitem = NULL;
+void sp_update_helperpath() {
+ SPDesktop * desktop = SP_ACTIVE_DESKTOP;
+ if (!desktop || !tools_isactive(desktop, TOOLS_NODES)) {
+ return;
+ }
+ Inkscape::UI::Tools::NodeTool *nt = static_cast<Inkscape::UI::Tools::NodeTool*>(desktop->event_context);
+ Inkscape::Selection *selection = desktop->getSelection();
+ if (nt->helperpath_tmpitem) {
+ desktop->remove_temporary_canvasitem(nt->helperpath_tmpitem);
+ nt->helperpath_tmpitem = NULL;
}
if (SP_IS_LPE_ITEM(selection->singleItem())) {
Inkscape::LivePathEffect::Effect *lpe = SP_LPE_ITEM(selection->singleItem())->getCurrentLPE();
if (lpe && lpe->isVisible()/* && lpe->showOrigPath()*/) {
- Inkscape::UI::ControlPointSelection::Set &selectionNodes = _selected_nodes->allPoints();
+
+ Inkscape::UI::ControlPointSelection *selectionNodes = nt->_selected_nodes;
std::vector<Geom::Point> selectedNodesPositions;
- for (Inkscape::UI::ControlPointSelection::Set::iterator i = selectionNodes.begin(); i != selectionNodes.end(); ++i) {
- if ((*i)->selected()) {
- Inkscape::UI::Node *n = dynamic_cast<Inkscape::UI::Node *>(*i);
- selectedNodesPositions.push_back(n->position());
- }
+ for (Inkscape::UI::ControlPointSelection::iterator i = selectionNodes->begin(); i != selectionNodes->end(); ++i) {
+ Inkscape::UI::Node *n = dynamic_cast<Inkscape::UI::Node *>(*i);
+ selectedNodesPositions.push_back(n->position());
}
lpe->setSelectedNodePoints(selectedNodesPositions);
- lpe->setCurrentZoom(this->desktop->current_zoom());
+ lpe->setCurrentZoom(desktop->current_zoom());
SPCurve *c = new SPCurve();
SPCurve *cc = new SPCurve();
std::vector<Geom::PathVector> cs = lpe->getCanvasIndicators(SP_LPE_ITEM(selection->singleItem()));
@@ -311,11 +308,11 @@ void NodeTool::update_helperpath () {
cc->reset();
}
if (!c->is_empty()) {
- SPCanvasItem *helperpath = sp_canvas_bpath_new(this->desktop->getTempGroup(), c);
+ SPCanvasItem *helperpath = sp_canvas_bpath_new(desktop->getTempGroup(), c, true);
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(helperpath), 0x0000ff9A, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(helperpath), 0, SP_WIND_RULE_NONZERO);
sp_canvas_item_affine_absolute(helperpath, selection->singleItem()->i2dt_affine());
- this->helperpath_tmpitem = this->desktop->add_temporary_canvasitem(helperpath, 0);
+ nt->helperpath_tmpitem = desktop->add_temporary_canvasitem(helperpath, 0);
}
c->unref();
cc->unref();
@@ -378,8 +375,8 @@ void gather_items(NodeTool *nt, SPItem *base, SPObject *obj, Inkscape::UI::Shape
r.role = role;
s.insert(r);
} else if (role != SHAPE_ROLE_NORMAL && (SP_IS_GROUP(obj) || SP_IS_OBJECTGROUP(obj))) {
- for (SPObject *c = obj->children; c; c = c->next) {
- gather_items(nt, base, c, role, s);
+ for (auto& c: obj->children) {
+ gather_items(nt, base, &c, role, s);
}
} else if (SP_IS_ITEM(obj)) {
SPItem *item = static_cast<SPItem*>(obj);
@@ -407,8 +404,8 @@ void NodeTool::selection_changed(Inkscape::Selection *sel) {
std::set<ShapeRecord> shapes;
- std::vector<SPItem*> items=sel->itemList();
- for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();++i){
+ auto items= sel->items();
+ for(auto i=items.begin();i!=items.end();++i){
SPObject *obj = *i;
if (SP_IS_ITEM(obj)) {
@@ -443,8 +440,9 @@ void NodeTool::selection_changed(Inkscape::Selection *sel) {
}
}
+ std::vector<SPItem *> vec(sel->items().begin(), sel->items().end());
_previous_selection = _current_selection;
- _current_selection = sel->itemList();
+ _current_selection = vec;
this->_multipath->setItems(shapes);
this->update_tip(NULL);
@@ -473,13 +471,11 @@ bool NodeTool::root_handler(GdkEvent* event) {
if (this->_selected_nodes->event(this, event)) {
return true;
}
-
switch (event->type)
{
case GDK_MOTION_NOTIFY: {
- this->update_helperpath();
+ sp_update_helperpath();
combine_motion_events(desktop->canvas, event->motion, 0);
- this->update_helperpath();
SPItem *over_item = sp_event_context_find_item (desktop, event_point(event->button),
FALSE, TRUE);
@@ -532,7 +528,7 @@ bool NodeTool::root_handler(GdkEvent* event) {
}
c->transform(over_item->i2dt_affine());
- SPCanvasItem *flash = sp_canvas_bpath_new(desktop->getTempGroup(), c);
+ SPCanvasItem *flash = sp_canvas_bpath_new(desktop->getTempGroup(), c, true);
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(flash),
//prefs->getInt("/tools/nodes/highlight_color", 0xff0000ff), 1.0,
@@ -634,7 +630,6 @@ bool NodeTool::root_handler(GdkEvent* event) {
void NodeTool::update_tip(GdkEvent *event) {
using namespace Inkscape::UI;
-
if (event && (event->type == GDK_KEY_PRESS || event->type == GDK_KEY_RELEASE)) {
unsigned new_state = state_after_event(event);
diff --git a/src/ui/tools/node-tool.h b/src/ui/tools/node-tool.h
index 8342d66a6..983ba6cee 100644
--- a/src/ui/tools/node-tool.h
+++ b/src/ui/tools/node-tool.h
@@ -49,14 +49,14 @@ public:
Inkscape::UI::ControlPointSelection* _selected_nodes;
Inkscape::UI::MultiPathManipulator* _multipath;
-
+ Inkscape::Display::TemporaryItem *helperpath_tmpitem;
+
bool edit_clipping_paths;
bool edit_masks;
static const std::string prefsPath;
virtual void setup();
- virtual void update_helperpath();
virtual void set(const Inkscape::Preferences::Entry& val);
virtual bool root_handler(GdkEvent* event);
@@ -68,7 +68,7 @@ private:
sigc::connection _sizeUpdatedConn;
SPItem *flashed_item;
- Inkscape::Display::TemporaryItem *helperpath_tmpitem;
+
Inkscape::Display::TemporaryItem *flash_tempitem;
Inkscape::UI::Selector* _selector;
Inkscape::UI::PathSharedData* _path_data;
@@ -96,8 +96,9 @@ private:
void update_tip(GdkEvent *event);
void handleControlUiStyleChange();
};
-
+ void sp_update_helperpath();
}
+
}
}
diff --git a/src/ui/tools/pen-tool.cpp b/src/ui/tools/pen-tool.cpp
index 18af8e105..caf6faec2 100644
--- a/src/ui/tools/pen-tool.cpp
+++ b/src/ui/tools/pen-tool.cpp
@@ -32,8 +32,6 @@
#include "ui/draw-anchor.h"
#include "message-stack.h"
#include "message-context.h"
-#include "preferences.h"
-#include "sp-path.h"
#include "display/sp-canvas.h"
#include "display/curve.h"
#include "pixmaps/cursor-pen.xpm"
@@ -46,7 +44,6 @@
#include "ui/tools-switch.h"
#include "ui/control-manager.h"
// we include the necessary files for BSpline & Spiro
-#include "live_effects/effect.h"
#include "live_effects/lpeobject.h"
#include "live_effects/lpeobject-reference.h"
#include "live_effects/parameter/path.h"
@@ -54,25 +51,16 @@
#include "live_effects/lpe-spiro.h"
-#include <typeinfo>
-#include <2geom/pathvector.h>
-#include <2geom/affine.h>
#include <2geom/curves.h>
#include "helper/geom-nodetype.h"
-#include "helper/geom-curves.h"
// For handling un-continuous paths:
-#include "message-stack.h"
#include "inkscape.h"
-#include "desktop.h"
#include "live_effects/spiro.h"
#define INKSCAPE_LPE_BSPLINE_C
#include "live_effects/lpe-bspline.h"
-#include <2geom/nearest-time.h>
-
-#include "live_effects/effect.h"
using Inkscape::ControlManager;
@@ -379,7 +367,7 @@ bool PenTool::_handleButtonPress(GdkEventButton const &bevent) {
//with this we avoid creating a new point over the existing one
if(bevent.button != 3 && (this->spiro || this->bspline) && this->npoints > 0 && this->p[0] == this->p[3]){
- if( anchor && anchor == this->sa && this->green_curve->is_empty()){
+ if( anchor && anchor == this->sa && this->green_curve->is_unset()){
//remove the following line to avoid having one node on top of another
_finishSegment(event_dt, bevent.state);
_finish(true);
@@ -877,7 +865,7 @@ void PenTool::_redrawAll() {
this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data);
}
// one canvas bpath for all of green_curve
- SPCanvasItem *canvas_shape = sp_canvas_bpath_new(this->desktop->getSketch(), this->green_curve);
+ SPCanvasItem *canvas_shape = sp_canvas_bpath_new(this->desktop->getSketch(), this->green_curve, true);
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvas_shape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(canvas_shape), 0, SP_WIND_RULE_NONZERO);
@@ -889,7 +877,7 @@ void PenTool::_redrawAll() {
this->red_curve->reset();
this->red_curve->moveto(this->p[0]);
this->red_curve->curveto(this->p[1], this->p[2], this->p[3]);
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve, true);
// handles
// hide the handlers in bspline and spiro modes
@@ -931,7 +919,7 @@ void PenTool::_lastpointMove(gdouble x, gdouble y) {
return;
// green
- if (!this->green_curve->is_empty()) {
+ if (!this->green_curve->is_unset()) {
this->green_curve->last_point_additive_move( Geom::Point(x,y) );
} else {
// start anchor too
@@ -959,7 +947,7 @@ void PenTool::_lastpointToCurve() {
this->p[1] = this->red_curve->last_segment()->initialPoint() + (1./3.)*(this->red_curve->last_segment()->finalPoint() - this->red_curve->last_segment()->initialPoint());
//modificate the last segment of the green curve so it creates the type of node we need
if (this->spiro||this->bspline) {
- if (!this->green_curve->is_empty()) {
+ if (!this->green_curve->is_unset()) {
Geom::Point A(0,0);
Geom::Point B(0,0);
Geom::Point C(0,0);
@@ -998,7 +986,7 @@ void PenTool::_lastpointToCurve() {
}
}
//if the last node is an union with another curve
- if (this->green_curve->is_empty() && this->sa && !this->sa->curve->is_empty()) {
+ if (this->green_curve->is_unset() && this->sa && !this->sa->curve->is_unset()) {
this->_bsplineSpiroStartAnchor(false);
}
}
@@ -1014,7 +1002,7 @@ void PenTool::_lastpointToLine() {
// modify the last segment of the green curve so the type of node we want is created.
if(this->spiro || this->bspline){
- if(!this->green_curve->is_empty()){
+ if(!this->green_curve->is_unset()){
Geom::Point A(0,0);
Geom::Point B(0,0);
Geom::Point C(0,0);
@@ -1045,7 +1033,7 @@ void PenTool::_lastpointToLine() {
}
}
// if the last node is an union with another curve
- if(this->green_curve->is_empty() && this->sa && !this->sa->curve->is_empty()){
+ if(this->green_curve->is_unset() && this->sa && !this->sa->curve->is_unset()){
this->_bsplineSpiroStartAnchor(true);
}
}
@@ -1224,7 +1212,7 @@ bool PenTool::_handleKeyPress(GdkEvent *event) {
// All this is needed to stop the last control
// point dispeating and stop making an n-1 shape.
Geom::Point const p(0, 0);
- if(this->red_curve->is_empty()) {
+ if(this->red_curve->is_unset()) {
this->red_curve->moveto(p);
}
this->_finishSegment(p, 0);
@@ -1245,7 +1233,7 @@ bool PenTool::_handleKeyPress(GdkEvent *event) {
case GDK_KEY_g:
case GDK_KEY_G:
if (MOD__SHIFT_ONLY(event)) {
- sp_selection_to_guides(this->desktop);
+ this->desktop->selection->toGuides();
ret = true;
}
break;
@@ -1263,10 +1251,10 @@ bool PenTool::_handleKeyPress(GdkEvent *event) {
void PenTool::_resetColors() {
// Red
this->red_curve->reset();
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL, true);
// Blue
this->blue_curve->reset();
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->blue_bpath), NULL);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->blue_bpath), NULL, true);
// Green
while (this->green_bpaths) {
sp_canvas_item_destroy(SP_CANVAS_ITEM(this->green_bpaths->data));
@@ -1289,7 +1277,7 @@ void PenTool::_setInitialPoint(Geom::Point const p) {
this->p[0] = p;
this->p[1] = p;
this->npoints = 2;
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL, true);
this->desktop->canvas->forceFullRedrawAfterInterruptions(5);
}
@@ -1355,7 +1343,7 @@ void PenTool::_bsplineSpiroColor()
this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data);
}
// one canvas bpath for all of green_curve
- SPCanvasItem *canvas_shape = sp_canvas_bpath_new(this->desktop->getSketch(), this->green_curve);
+ SPCanvasItem *canvas_shape = sp_canvas_bpath_new(this->desktop->getSketch(), this->green_curve, true);
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvas_shape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(canvas_shape), 0, SP_WIND_RULE_NONZERO);
this->green_bpaths = g_slist_prepend(this->green_bpaths, canvas_shape);
@@ -1376,7 +1364,7 @@ void PenTool::_bsplineSpiro(bool shift)
void PenTool::_bsplineSpiroOn()
{
- if(!this->red_curve->is_empty()){
+ if(!this->red_curve->is_unset()){
using Geom::X;
using Geom::Y;
this->npoints = 5;
@@ -1389,7 +1377,7 @@ void PenTool::_bsplineSpiroOn()
void PenTool::_bsplineSpiroOff()
{
- if(!this->red_curve->is_empty()){
+ if(!this->red_curve->is_unset()){
this->npoints = 5;
this->p[0] = this->red_curve->first_segment()->initialPoint();
this->p[3] = this->red_curve->first_segment()->finalPoint();
@@ -1399,7 +1387,7 @@ void PenTool::_bsplineSpiroOff()
void PenTool::_bsplineSpiroStartAnchor(bool shift)
{
- if(this->sa->curve->is_empty()){
+ if(this->sa->curve->is_unset()){
return;
}
@@ -1509,18 +1497,18 @@ void PenTool::_bsplineSpiroMotion(bool shift){
}
using Geom::X;
using Geom::Y;
- if(this->red_curve->is_empty()) return;
+ if(this->red_curve->is_unset()) return;
this->npoints = 5;
SPCurve *tmp_curve = new SPCurve();
this->p[2] = this->p[3] + (1./3)*(this->p[0] - this->p[3]);
this->p[2] = Geom::Point(this->p[2][X] + HANDLE_CUBIC_GAP,this->p[2][Y] + HANDLE_CUBIC_GAP);
- if(this->green_curve->is_empty() && !this->sa){
+ if(this->green_curve->is_unset() && !this->sa){
this->p[1] = this->p[0] + (1./3)*(this->p[3] - this->p[0]);
this->p[1] = Geom::Point(this->p[1][X] + HANDLE_CUBIC_GAP,this->p[1][Y] + HANDLE_CUBIC_GAP);
if(shift){
this->p[2] = this->p[3];
}
- }else if(!this->green_curve->is_empty()){
+ }else if(!this->green_curve->is_unset()){
tmp_curve = this->green_curve->copy();
}else{
tmp_curve = this->overwrite_curve->copy();
@@ -1528,7 +1516,7 @@ void PenTool::_bsplineSpiroMotion(bool shift){
tmp_curve = tmp_curve ->create_reverse();
}
- if(!tmp_curve ->is_empty()){
+ if(!tmp_curve ->is_unset()){
Geom::CubicBezier const * cubic = dynamic_cast<Geom::CubicBezier const*>(&*tmp_curve ->last_segment());
if(cubic){
if(this->bspline){
@@ -1560,7 +1548,7 @@ void PenTool::_bsplineSpiroMotion(bool shift){
}
}
- if(this->anchor_statusbar && !this->red_curve->is_empty()){
+ if(this->anchor_statusbar && !this->red_curve->is_unset()){
if(shift){
this->_bsplineSpiroEndAnchorOff();
}else{
@@ -1693,19 +1681,19 @@ void PenTool::_bsplineSpiroBuild()
//We create the base curve
SPCurve *curve = new SPCurve();
//If we continuate the existing curve we add it at the start
- if(this->sa && !this->sa->curve->is_empty()){
+ if(this->sa && !this->sa->curve->is_unset()){
curve = this->overwrite_curve->copy();
if (this->sa->start) {
curve = curve->create_reverse();
}
}
- if (!this->green_curve->is_empty()){
+ if (!this->green_curve->is_unset()){
curve->append_continuous(this->green_curve, 0.0625);
}
//and the red one
- if (!this->red_curve->is_empty()){
+ if (!this->red_curve->is_unset()){
this->red_curve->reset();
this->red_curve->moveto(this->p[0]);
if(this->anchor_statusbar && !this->sa && !(this->green_anchor && this->green_anchor->active)){
@@ -1713,11 +1701,11 @@ void PenTool::_bsplineSpiroBuild()
}else{
this->red_curve->curveto(this->p[1],this->p[2],this->p[3]);
}
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve, true);
curve->append_continuous(this->red_curve, 0.0625);
}
- if(!curve->is_empty()){
+ if(!curve->is_unset()){
// close the curve if the final points of the curve are close enough
if(Geom::are_near(curve->first_path()->initialPoint(), curve->last_path()->finalPoint())){
curve->closepath_current();
@@ -1734,7 +1722,7 @@ void PenTool::_bsplineSpiroBuild()
LivePathEffect::sp_spiro_do_effect(curve);
}
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->blue_bpath), curve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->blue_bpath), curve, true);
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(this->blue_bpath), this->blue_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
sp_canvas_item_show(this->blue_bpath);
curve->unref();
@@ -1790,7 +1778,7 @@ void PenTool::_setSubsequentPoint(Geom::Point const p, bool statusbar, guint sta
}
}
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve, true);
if (statusbar) {
gchar *message = is_curve ?
@@ -1830,7 +1818,7 @@ void PenTool::_setCtrl(Geom::Point const p, guint const state) {
this->red_curve->reset();
this->red_curve->moveto(this->p[0]);
this->red_curve->curveto(this->p[1], this->p[2], this->p[3]);
- sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve);
+ sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), this->red_curve, true);
}
SP_CTRL(this->c0)->moveto(this->p[2]);
this->cl0 ->setCoords(this->p[3], this->p[2]);
@@ -1856,13 +1844,13 @@ void PenTool::_finishSegment(Geom::Point const p, guint const state) {
++num_clicks;
- if (!this->red_curve->is_empty()) {
+ if (!this->red_curve->is_unset()) {
this->_bsplineSpiro(state & GDK_SHIFT_MASK);
this->green_curve->append_continuous(this->red_curve, 0.0625);
SPCurve *curve = this->red_curve->copy();
/// \todo fixme:
- SPCanvasItem *canvas_shape = sp_canvas_bpath_new(this->desktop->getSketch(), curve);
+ SPCanvasItem *canvas_shape = sp_canvas_bpath_new(this->desktop->getSketch(), curve, true);
curve->unref();
sp_canvas_bpath_set_stroke(SP_CANVAS_BPATH(canvas_shape), this->green_color, 1.0, SP_STROKE_LINEJOIN_MITER, SP_STROKE_LINECAP_BUTT);
@@ -1881,8 +1869,8 @@ void PenTool::_finishSegment(Geom::Point const p, guint const state) {
bool PenTool::_undoLastPoint() {
bool ret = false;
- if ( this->green_curve->is_empty() || (this->green_curve->last_segment() == NULL) ) {
- if (!this->red_curve->is_empty()) {
+ if ( this->green_curve->is_unset() || (this->green_curve->last_segment() == NULL) ) {
+ if (!this->red_curve->is_unset()) {
this->_cancel ();
ret = true;
} else {
@@ -1899,7 +1887,7 @@ bool PenTool::_undoLastPoint() {
this->green_bpaths = g_slist_remove(this->green_bpaths, this->green_bpaths->data);
}
// Get last segment
- if ( this->green_curve->is_empty() ) {
+ if ( this->green_curve->is_unset() ) {
g_warning("pen_handle_key_press, case GDK_KP_Delete: Green curve is empty");
return false;
}
@@ -2031,7 +2019,7 @@ int PenTool::nextParaxialDirection(Geom::Point const &pt, Geom::Point const &ori
// (on first mouse release), in which case num_clicks immediately becomes 1.
// if (this->num_clicks == 0) {
- if (this->green_curve->is_empty()) {
+ if (this->green_curve->is_unset()) {
// first mouse click
double dist_h = fabs(pt[Geom::X] - origin[Geom::X]);
double dist_v = fabs(pt[Geom::Y] - origin[Geom::Y]);
diff --git a/src/ui/tools/pencil-tool.cpp b/src/ui/tools/pencil-tool.cpp
index b029ca613..ec2874823 100644
--- a/src/ui/tools/pencil-tool.cpp
+++ b/src/ui/tools/pencil-tool.cpp
@@ -27,7 +27,6 @@
#include "message-stack.h"
#include "message-context.h"
#include "sp-path.h"
-#include "preferences.h"
#include "snap.h"
#include "pixmaps/cursor-pencil.xpm"
#include <2geom/sbasis-to-bezier.h>
@@ -36,13 +35,9 @@
#include <glibmm/i18n.h>
#include "context-fns.h"
#include "sp-namedview.h"
-#include "xml/repr.h"
-#include "document.h"
#include "desktop-style.h"
-#include "macros.h"
#include "display/sp-canvas.h"
#include "display/curve.h"
-#include "livarot/Path.h"
#include "ui/tool/event-utils.h"
namespace Inkscape {
@@ -492,7 +487,7 @@ bool PencilTool::_handleKeyPress(GdkEventKey const &event) {
case GDK_KEY_g:
case GDK_KEY_G:
if (Inkscape::UI::held_only_shift(event)) {
- sp_selection_to_guides(this->desktop);
+ this->desktop->selection->toGuides();
ret = true;
}
break;
@@ -593,8 +588,8 @@ void PencilTool::_setEndpoint(Geom::Point const &p) {
* Still not sure, how it will make most sense.
*/
void PencilTool::_finishEndpoint() {
- if ( ( this->red_curve->is_empty() )
- || ( *(this->red_curve->first_point()) == *(this->red_curve->second_point()) ) )
+ if (this->red_curve->is_unset() ||
+ this->red_curve->first_point() == this->red_curve->second_point())
{
this->red_curve->reset();
sp_canvas_bpath_set_bpath(SP_CANVAS_BPATH(this->red_bpath), NULL);
@@ -852,7 +847,7 @@ void PencilTool::_fitAndSplit() {
SPCurve *curve = this->red_curve->copy();
/// \todo fixme:
- SPCanvasItem *cshape = sp_canvas_bpath_new(this->desktop->getSketch(), curve);
+ SPCanvasItem *cshape = sp_canvas_bpath_new(this->desktop->getSketch(), curve, true);
curve->unref();
this->highlight_color = SP_ITEM(this->desktop->currentLayer())->highlight_color();
diff --git a/src/ui/tools/rect-tool.cpp b/src/ui/tools/rect-tool.cpp
index 844965c4d..272531945 100644
--- a/src/ui/tools/rect-tool.cpp
+++ b/src/ui/tools/rect-tool.cpp
@@ -14,8 +14,6 @@
* Released under GNU GPL, read the file 'COPYING' for more information
*/
-#include "config.h"
-
#include <gdk/gdkkeysyms.h>
#include <cstring>
#include <string>
@@ -29,16 +27,13 @@
#include "selection.h"
#include "selection-chemistry.h"
-#include "snap.h"
#include "desktop.h"
#include "desktop-style.h"
#include "message-context.h"
#include "pixmaps/cursor-rect.xpm"
#include "ui/tools/rect-tool.h"
#include <glibmm/i18n.h>
-#include "xml/repr.h"
#include "xml/node-event-vector.h"
-#include "preferences.h"
#include "context-fns.h"
#include "ui/shape-editor.h"
#include "verbs.h"
@@ -299,7 +294,7 @@ bool RectTool::root_handler(GdkEvent* event) {
case GDK_KEY_g:
case GDK_KEY_G:
if (MOD__SHIFT_ONLY(event)) {
- sp_selection_to_guides(desktop);
+ desktop->selection->toGuides();
ret = true;
}
break;
diff --git a/src/ui/tools/select-tool.cpp b/src/ui/tools/select-tool.cpp
index 905e38f2b..bae1793ed 100644
--- a/src/ui/tools/select-tool.cpp
+++ b/src/ui/tools/select-tool.cpp
@@ -15,7 +15,7 @@
*/
#ifdef HAVE_CONFIG_H
-# include "config.h"
+#include <config.h>
#endif
#include <cstring>
#include <string>
@@ -40,14 +40,12 @@
#include "desktop.h"
#include "sp-root.h"
-#include "preferences.h"
#include "ui/tools-switch.h"
#include "message-stack.h"
#include "selection-describer.h"
#include "seltrans.h"
#include "box3d.h"
#include "display/sp-canvas.h"
-#include "display/sp-canvas-item.h"
#include "display/drawing-item.h"
using Inkscape::DocumentUndo;
@@ -65,7 +63,7 @@ static gint rb_escaped = 0; // if non-zero, rubberband was canceled by esc, so t
static gint drag_escaped = 0; // if non-zero, drag was canceled by esc
const std::string& SelectTool::getPrefsPath() {
- return SelectTool::prefsPath;
+ return SelectTool::prefsPath;
}
const std::string SelectTool::prefsPath = "/tools/select";
@@ -111,7 +109,6 @@ SelectTool::SelectTool()
//static gint tolerance = 0;
//static bool within_tolerance = false;
static bool is_cycling = false;
-static bool moved_while_cycling = false;
SelectTool::~SelectTool() {
@@ -129,20 +126,12 @@ SelectTool::~SelectTool() {
this->_describer = NULL;
if (CursorSelectDragging) {
-#if GTK_CHECK_VERSION(3,0,0)
g_object_unref(CursorSelectDragging);
-#else
- gdk_cursor_unref (CursorSelectDragging);
-#endif
CursorSelectDragging = NULL;
}
if (CursorSelectMouseover) {
-#if GTK_CHECK_VERSION(3,0,0)
g_object_unref(CursorSelectMouseover);
-#else
- gdk_cursor_unref (CursorSelectMouseover);
-#endif
CursorSelectMouseover = NULL;
}
}
@@ -153,7 +142,7 @@ void SelectTool::setup() {
this->_describer = new Inkscape::SelectionDescriber(
desktop->selection,
desktop->messageStack(),
- _("Click selection to toggle scale/rotation handles"),
+ _("Click selection to toggle scale/rotation handles (or Shift+s)"),
_("No objects selected. Click, Shift+click, Alt+scroll mouse on top of objects, or drag around objects to select.")
);
@@ -297,7 +286,7 @@ bool SelectTool::item_handler(SPItem* item, GdkEvent* event) {
} else {
GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas()));
- this->dragging = TRUE;
+ this->dragging = TRUE;
this->moved = FALSE;
gdk_window_set_cursor(window, CursorSelectDragging);
@@ -347,11 +336,11 @@ bool SelectTool::item_handler(SPItem* item, GdkEvent* event) {
break;
}
case GDK_LEAVE_NOTIFY:
- if (!desktop->isWaitingCursor() && !this->dragging) {
+ if (!desktop->isWaitingCursor() && !this->dragging) {
GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas()));
gdk_window_set_cursor(window, this->cursor);
- }
+ }
break;
case GDK_KEY_PRESS:
@@ -379,61 +368,75 @@ bool SelectTool::item_handler(SPItem* item, GdkEvent* event) {
}
if (!ret) {
- ret = ToolBase::item_handler(item, event);
+ ret = ToolBase::item_handler(item, event);
}
return ret;
}
void SelectTool::sp_select_context_cycle_through_items(Inkscape::Selection *selection, GdkEventScroll *scroll_event, bool shift_pressed) {
- if (this->cycling_cur_item == this->cycling_items.end()) {
+ if ( this->cycling_items.empty() )
return;
- }
Inkscape::DrawingItem *arenaitem;
- SPItem *item = *cycling_cur_item;
- g_assert(item != NULL);
- // Deactivate current item
- if (std::find(cycling_items_selected_before.begin(), cycling_items_selected_before.end(), item) == cycling_items_selected_before.end() && selection->includes(item)) {
- selection->remove(item);
+ if(cycling_cur_item) {
+ arenaitem = cycling_cur_item->get_arenaitem(desktop->dkey);
+ arenaitem->setOpacity(0.3);
}
- arenaitem = item->get_arenaitem(desktop->dkey);
- arenaitem->setOpacity(0.3);
-
// Find next item and activate it
- std::vector<SPItem *>::iterator next = this->cycling_cur_item;
+
+
+ std::vector<SPItem *>::iterator next = cycling_items.end();
+
if (scroll_event->direction == GDK_SCROLL_UP) {
- ++next;
- if (next == this->cycling_items.end() && this->cycling_wrap) {
- next = this->cycling_items.begin();
+ if (! cycling_cur_item) {
+ next = cycling_items.begin();
+ } else {
+ next = std::find( cycling_items.begin(), cycling_items.end(), cycling_cur_item );
+ g_assert (next != cycling_items.end());
+ next++;
+ if (next == cycling_items.end())
+ if ( cycling_wrap )
+ next = cycling_items.begin();
+ else
+ next--;
}
- } else {
- if(next == this->cycling_items.begin()) {
- next = this->cycling_items.end();
+ } else {
+ if (! cycling_cur_item) {
+ next = cycling_items.end();
+ next--;
+ } else {
+ next = std::find( cycling_items.begin(), cycling_items.end(), cycling_cur_item );
+ g_assert (next != cycling_items.end());
+ if (next == cycling_items.begin()){
+ if ( cycling_wrap ) {
+ next = cycling_items.end();
+ next--;
+ }
+ } else {
+ next--;
+ }
}
- --next;
}
- if (next!=this->cycling_items.end()) {
- this->cycling_cur_item = next;
- item = *next;
- g_assert(item != NULL);
- }
+ this->cycling_cur_item = *next;
+ g_assert(next != cycling_items.end());
+ g_assert(cycling_cur_item != NULL);
- arenaitem = item->get_arenaitem(desktop->dkey);
+ arenaitem = cycling_cur_item->get_arenaitem(desktop->dkey);
arenaitem->setOpacity(1.0);
if (shift_pressed) {
- selection->add(item);
+ selection->add(cycling_cur_item);
} else {
- selection->set(item);
+ selection->set(cycling_cur_item);
}
}
void SelectTool::sp_select_context_reset_opacities() {
- for (std::vector<SPItem *>::const_iterator l = this->cycling_items.begin(); l != this->cycling_items.end(); ++l ) {
+ for (std::vector<SPItem *>::const_iterator l = this->cycling_items_cmp.begin(); l != this->cycling_items_cmp.end(); ++l ) {
SPItem *item = *l;
if (item) {
Inkscape::DrawingItem *arenaitem = item->get_arenaitem(desktop->dkey);
@@ -443,10 +446,8 @@ void SelectTool::sp_select_context_reset_opacities() {
}
}
- this->cycling_items.clear();
- this->cycling_items_selected_before.clear();
- this->cycling_cur_item = this->cycling_items.end();
this->cycling_items_cmp.clear();
+ this->cycling_cur_item = NULL;
}
bool SelectTool::root_handler(GdkEvent* event) {
@@ -466,7 +467,7 @@ bool SelectTool::root_handler(GdkEvent* event) {
case GDK_2BUTTON_PRESS:
if (event->button.button == 1) {
if (!selection->isEmpty()) {
- SPItem *clicked_item = selection->itemList()[0];
+ SPItem *clicked_item = selection->items().front();
if (dynamic_cast<SPGroup *>(clicked_item) && !dynamic_cast<SPBox3D *>(clicked_item)) { // enter group if it's not a 3D box
desktop->setCurrentLayer(clicked_item);
@@ -533,11 +534,7 @@ bool SelectTool::root_handler(GdkEvent* event) {
case GDK_MOTION_NOTIFY:
{
- if (is_cycling) {
- moved_while_cycling = true;
- }
-
- tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
+ tolerance = prefs->getIntLimited("/options/dragtolerance/value", 0, 0, 100);
if ((event->motion.state & GDK_BUTTON1_MASK) && !this->space_panning) {
Geom::Point const motion_pt(event->motion.x, event->motion.y);
@@ -703,7 +700,7 @@ bool SelectTool::root_handler(GdkEvent* event) {
if (r->is_started() && !within_tolerance) {
// this was a rubberband drag
- std::vector<SPItem*> items;
+ std::vector<SPItem*> items;
if (r->getMode() == RUBBERBAND_MODE_RECT) {
Geom::OptRect const b = r->getRectangle();
@@ -796,107 +793,67 @@ bool SelectTool::root_handler(GdkEvent* event) {
break;
case GDK_SCROLL: {
- GdkEventScroll *scroll_event = (GdkEventScroll*) event;
-
- if (scroll_event->state & GDK_MOD1_MASK) { // alt modified pressed
- if (moved_while_cycling) {
- moved_while_cycling = false;
- this->sp_select_context_reset_opacities();
- }
-
- is_cycling = true;
-
- bool shift_pressed = scroll_event->state & GDK_SHIFT_MASK;
-
- /* Rebuild list of items underneath the mouse pointer */
- Geom::Point p = desktop->d2w(desktop->point());
- SPItem *item = desktop->getItemAtPoint(p, true, NULL);
-
- // Save pointer to current cycle-item so that we can find it again later, in the freshly built list
- SPItem *tmp_cur_item = this->cycling_cur_item!=this->cycling_items.end() ? (*(this->cycling_cur_item)) : NULL;
- this->cycling_items.clear();
- this->cycling_cur_item = this->cycling_items.end();
- while(item != NULL) {
- this->cycling_items.push_back(item);
- item = desktop->getItemAtPoint(p, true, item);
- }
-
- /* Compare current item list with item list during previous scroll ... */
- bool item_lists_differ = this->cycling_items != this->cycling_items_cmp;
- /* If list of items under mouse pointer hasn't changed ... */
- if (!item_lists_differ) {
- // ... find current item in the freshly built list and continue cycling ...
- // TODO: This wouldn't be necessary if cycling_cur_item pointed to an element of cycling_items_cmp instead
- this->cycling_cur_item = std::find(this->cycling_items.begin(), this->cycling_items.end(), tmp_cur_item);
- g_assert(this->cycling_cur_item != this->cycling_items.end() || this->cycling_items.empty());
- } else {
- // ... otherwise reset opacities for outdated items ...
- Inkscape::DrawingItem *arenaitem;
-
- for (std::vector<SPItem *>::const_iterator l = this->cycling_items_cmp.begin(); l != this->cycling_items_cmp.end(); ++l) {
- SPItem *item = *l;
- if (item) {
- arenaitem = item->get_arenaitem(desktop->dkey);
- arenaitem->setOpacity(1.0);
- //if (!shift_pressed && !g_list_find(this->cycling_items_selected_before, item) && selection->includes(item))
- if (std::find(this->cycling_items_selected_before.begin(),this->cycling_items_selected_before.end(), item)==this->cycling_items_selected_before.end() && selection->includes(item)) {
- selection->remove(item);
- }
- }
- }
+ GdkEventScroll *scroll_event = (GdkEventScroll*) event;
- // ... clear the lists ...
+ if ( ! (scroll_event->state & GDK_MOD1_MASK)) // do nothing specific if alt was not pressed
+ break;
- this->cycling_items_cmp.clear();
- this->cycling_items_selected_before.clear();
- this->cycling_cur_item = this->cycling_items.end();
+ bool shift_pressed = scroll_event->state & GDK_SHIFT_MASK;
+ is_cycling = true;
- // ... and rebuild them with the new items.
- this->cycling_items_cmp = (this->cycling_items);
+ /* Rebuild list of items underneath the mouse pointer */
+ Geom::Point p = desktop->d2w(desktop->point());
+ SPItem *item = desktop->getItemAtPoint(p, true, NULL);
+ this->cycling_items.clear();
- for(std::vector<SPItem *>::const_iterator l = this->cycling_items.begin(); l != this->cycling_items.end(); ++l) {
- SPItem *item =*l;
- if (item) {
- arenaitem = item->get_arenaitem(desktop->dkey);
- arenaitem->setOpacity(0.3);
+ SPItem *tmp = NULL;
+ while(item != NULL) {
+ this->cycling_items.push_back(item);
+ item = desktop->getItemAtPoint(p, true, item);
+ if (selection->includes(item)) tmp = item;
+ }
- if (selection->includes(item)) {
- // already selected items are stored separately, too
- this->cycling_items_selected_before.push_back(item);
- }
- } else {
- g_assert_not_reached();
- }
+ /* Compare current item list with item list during previous scroll ... */
+ bool item_lists_differ = this->cycling_items != this->cycling_items_cmp;
+
+ if(item_lists_differ) {
+ this->sp_select_context_reset_opacities();
+ for (std::vector<SPItem *>::const_iterator l = this->cycling_items_cmp.begin(); l != this->cycling_items_cmp.end(); ++l)
+ selection->remove(*l); // deselects the previous content of the cycling loop
+ this->cycling_items_cmp = (this->cycling_items);
+
+ // set opacities in new stack
+ for(std::vector<SPItem *>::const_iterator l = this->cycling_items.begin(); l != this->cycling_items.end(); ++l) {
+ SPItem *item =*l;
+ if (item) {
+ Inkscape::DrawingItem *arenaitem = item->get_arenaitem(desktop->dkey);
+ arenaitem->setOpacity(0.3);
}
-
- // set the current item to the bottommost one so that the cycling step below re-starts at the top
- this->cycling_cur_item = this->cycling_items.end();
- this->cycling_cur_item--;
}
+ }
+ if(!cycling_cur_item) cycling_cur_item = tmp;
- this->cycling_wrap = prefs->getBool("/options/selection/cycleWrap", true);
+ this->cycling_wrap = prefs->getBool("/options/selection/cycleWrap", true);
- // Cycle through the items underneath the mouse pointer, one-by-one
- this->sp_select_context_cycle_through_items(selection, scroll_event, shift_pressed);
+ // Cycle through the items underneath the mouse pointer, one-by-one
+ this->sp_select_context_cycle_through_items(selection, scroll_event, shift_pressed);
- ret = TRUE;
+ ret = TRUE;
- GtkWindow *w =GTK_WINDOW(gtk_widget_get_toplevel( GTK_WIDGET(desktop->canvas) ));
- if (w)
- {
- gtk_window_present(w);
- gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas));
- }
+ GtkWindow *w =GTK_WINDOW(gtk_widget_get_toplevel( GTK_WIDGET(desktop->canvas) ));
+ if (w) {
+ gtk_window_present(w);
+ gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas));
}
break;
}
case GDK_KEY_PRESS: // keybindings for select context
- {
- {
- guint keyval = get_group0_keyval(&event->key);
-
+ {
+ {
+ guint keyval = get_group0_keyval(&event->key);
+
bool alt = ( MOD__ALT(event)
|| (keyval == GDK_KEY_Alt_L)
|| (keyval == GDK_KEY_Alt_R)
@@ -924,7 +881,7 @@ bool SelectTool::root_handler(GdkEvent* event) {
// if Alt and nonempty selection, show moving cursor ("move selected"):
if (alt && !selection->isEmpty() && !desktop->isWaitingCursor()) {
- GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas()));
+ GdkWindow* window = gtk_widget_get_window (GTK_WIDGET (desktop->getCanvas()));
gdk_window_set_cursor(window, CursorSelectDragging);
}
@@ -945,15 +902,15 @@ bool SelectTool::root_handler(GdkEvent* event) {
if (MOD__ALT(event)) { // alt
if (MOD__SHIFT(event)) {
- sp_selection_move_screen(desktop->getSelection(), mul*-10, 0); // shift
+ desktop->getSelection()->moveScreen(mul*-10, 0); // shift
} else {
- sp_selection_move_screen(desktop->getSelection(), mul*-1, 0); // no shift
+ desktop->getSelection()->moveScreen(mul*-1, 0); // no shift
}
} else { // no alt
if (MOD__SHIFT(event)) {
- sp_selection_move(desktop->getSelection(), mul*-10*nudge, 0); // shift
+ desktop->getSelection()->move(mul*-10*nudge, 0); // shift
} else {
- sp_selection_move(desktop->getSelection(), mul*-nudge, 0); // no shift
+ desktop->getSelection()->move(mul*-nudge, 0); // no shift
}
}
@@ -968,15 +925,15 @@ bool SelectTool::root_handler(GdkEvent* event) {
if (MOD__ALT(event)) { // alt
if (MOD__SHIFT(event)) {
- sp_selection_move_screen(desktop->getSelection(), 0, mul*10); // shift
+ desktop->getSelection()->moveScreen(0, mul*10); // shift
} else {
- sp_selection_move_screen(desktop->getSelection(), 0, mul*1); // no shift
+ desktop->getSelection()->moveScreen(0, mul*1); // no shift
}
} else { // no alt
if (MOD__SHIFT(event)) {
- sp_selection_move(desktop->getSelection(), 0, mul*10*nudge); // shift
+ desktop->getSelection()->move(0, mul*10*nudge); // shift
} else {
- sp_selection_move(desktop->getSelection(), 0, mul*nudge); // no shift
+ desktop->getSelection()->move(0, mul*nudge); // no shift
}
}
@@ -991,15 +948,15 @@ bool SelectTool::root_handler(GdkEvent* event) {
if (MOD__ALT(event)) { // alt
if (MOD__SHIFT(event)) {
- sp_selection_move_screen(desktop->getSelection(), mul*10, 0); // shift
+ desktop->getSelection()->moveScreen(mul*10, 0); // shift
} else {
- sp_selection_move_screen(desktop->getSelection(), mul*1, 0); // no shift
+ desktop->getSelection()->moveScreen(mul*1, 0); // no shift
}
} else { // no alt
if (MOD__SHIFT(event)) {
- sp_selection_move(desktop->getSelection(), mul*10*nudge, 0); // shift
+ desktop->getSelection()->move(mul*10*nudge, 0); // shift
} else {
- sp_selection_move(desktop->getSelection(), mul*nudge, 0); // no shift
+ desktop->getSelection()->move(mul*nudge, 0); // no shift
}
}
@@ -1014,15 +971,15 @@ bool SelectTool::root_handler(GdkEvent* event) {
if (MOD__ALT(event)) { // alt
if (MOD__SHIFT(event)) {
- sp_selection_move_screen(desktop->getSelection(), 0, mul*-10); // shift
+ desktop->getSelection()->moveScreen(0, mul*-10); // shift
} else {
- sp_selection_move_screen(desktop->getSelection(), 0, mul*-1); // no shift
+ desktop->getSelection()->moveScreen(0, mul*-1); // no shift
}
} else { // no alt
if (MOD__SHIFT(event)) {
- sp_selection_move(desktop->getSelection(), 0, mul*-10*nudge); // shift
+ desktop->getSelection()->move(0, mul*-10*nudge); // shift
} else {
- sp_selection_move(desktop->getSelection(), 0, mul*-nudge); // no shift
+ desktop->getSelection()->move(0, mul*-nudge); // no shift
}
}
@@ -1066,11 +1023,11 @@ bool SelectTool::root_handler(GdkEvent* event) {
case GDK_KEY_bracketleft:
if (MOD__ALT(event)) {
gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask
- sp_selection_rotate_screen(selection, mul*1);
+ selection->rotateScreen(mul*1);
} else if (MOD__CTRL(event)) {
- sp_selection_rotate(selection, 90);
+ selection->rotate(90);
} else if (snaps) {
- sp_selection_rotate(selection, 180.0/snaps);
+ selection->rotate(180.0/snaps);
}
ret = TRUE;
@@ -1079,46 +1036,16 @@ bool SelectTool::root_handler(GdkEvent* event) {
case GDK_KEY_bracketright:
if (MOD__ALT(event)) {
gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask
- sp_selection_rotate_screen(selection, -1*mul);
+ selection->rotateScreen(-1*mul);
} else if (MOD__CTRL(event)) {
- sp_selection_rotate(selection, -90);
+ selection->rotate(-90);
} else if (snaps) {
- sp_selection_rotate(selection, -180.0/snaps);
+ selection->rotate(-180.0/snaps);
}
ret = TRUE;
break;
-
- case GDK_KEY_less:
- case GDK_KEY_comma:
- if (MOD__ALT(event)) {
- gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask
- sp_selection_scale_screen(selection, -2*mul);
- } else if (MOD__CTRL(event)) {
- sp_selection_scale_times(selection, 0.5);
- } else {
- gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask
- sp_selection_scale(selection, -offset*mul);
- }
-
- ret = TRUE;
- break;
-
- case GDK_KEY_greater:
- case GDK_KEY_period:
- if (MOD__ALT(event)) {
- gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask
- sp_selection_scale_screen(selection, 2*mul);
- } else if (MOD__CTRL(event)) {
- sp_selection_scale_times(selection, 2);
- } else {
- gint mul = 1 + gobble_key_events(get_group0_keyval(&event->key), 0); // with any mask
- sp_selection_scale(selection, offset*mul);
- }
-
- ret = TRUE;
- break;
-
+
case GDK_KEY_Return:
if (MOD__CTRL_ONLY(event)) {
if (selection->singleItem()) {
@@ -1157,7 +1084,7 @@ bool SelectTool::root_handler(GdkEvent* event) {
case GDK_KEY_g:
case GDK_KEY_G:
if (MOD__SHIFT_ONLY(event)) {
- sp_selection_to_guides(desktop);
+ desktop->selection->toGuides();
ret = true;
}
break;
@@ -1166,7 +1093,7 @@ bool SelectTool::root_handler(GdkEvent* event) {
break;
}
break;
- }
+ }
case GDK_KEY_RELEASE: {
guint keyval = get_group0_keyval(&event->key);
if (key_is_a_modifier (keyval)) {
@@ -1207,7 +1134,7 @@ bool SelectTool::root_handler(GdkEvent* event) {
}
if (!ret) {
- ret = ToolBase::root_handler(event);
+ ret = ToolBase::root_handler(event);
}
return ret;
diff --git a/src/ui/tools/select-tool.h b/src/ui/tools/select-tool.h
index af183b1ca..420374661 100644
--- a/src/ui/tools/select-tool.h
+++ b/src/ui/tools/select-tool.h
@@ -42,8 +42,7 @@ public:
std::vector<SPItem *> cycling_items;
std::vector<SPItem *> cycling_items_cmp;
- std::vector<SPItem *> cycling_items_selected_before;
- std::vector<SPItem *>::iterator cycling_cur_item;
+ SPItem *cycling_cur_item;
bool cycling_wrap;
SPItem *item;
diff --git a/src/ui/tools/spiral-tool.cpp b/src/ui/tools/spiral-tool.cpp
index 833fef18d..0ba08853e 100644
--- a/src/ui/tools/spiral-tool.cpp
+++ b/src/ui/tools/spiral-tool.cpp
@@ -14,8 +14,6 @@
* Released under GNU GPL
*/
-#include "config.h"
-
#include <gdk/gdkkeysyms.h>
#include <cstring>
#include <string>
@@ -28,16 +26,13 @@
#include "sp-namedview.h"
#include "selection.h"
-#include "snap.h"
#include "desktop.h"
#include "desktop-style.h"
#include "message-context.h"
#include "pixmaps/cursor-spiral.xpm"
#include "ui/tools/spiral-tool.h"
#include <glibmm/i18n.h>
-#include "xml/repr.h"
#include "xml/node-event-vector.h"
-#include "preferences.h"
#include "context-fns.h"
#include "ui/shape-editor.h"
#include "verbs.h"
diff --git a/src/ui/tools/spray-tool.cpp b/src/ui/tools/spray-tool.cpp
index 9adaf3879..ad006627c 100644
--- a/src/ui/tools/spray-tool.cpp
+++ b/src/ui/tools/spray-tool.cpp
@@ -13,21 +13,19 @@
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
* Jabiertxo Arraiza <jabier.arraiza@marker.es>
+ * Adrian Boguszewski
*
* Copyright (C) 2009 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
-#include "config.h"
-
#include <numeric>
#include "ui/dialog/dialog-manager.h"
#include "svg/svg.h"
-#include <glib.h>
#include "macros.h"
#include "document.h"
#include "document-undo.h"
@@ -37,10 +35,7 @@
#include "message-context.h"
#include "pixmaps/cursor-spray.xpm"
-#include <boost/optional.hpp>
-#include "xml/repr.h"
#include "context-fns.h"
-#include "sp-item.h"
#include "inkscape.h"
#include "splivarot.h"
@@ -57,17 +52,12 @@
#include "svg/svg-color.h"
#include "sp-text.h"
-#include "sp-root.h"
#include "sp-flowtext.h"
#include "display/sp-canvas.h"
-#include "display/canvas-bpath.h"
#include "display/canvas-arena.h"
#include "display/curve.h"
#include "livarot/Shape.h"
#include <2geom/circle.h>
-#include <2geom/transforms.h>
-#include "preferences.h"
-#include "style.h"
#include "box3d.h"
#include "sp-item-transform.h"
#include "filter-chemistry.h"
@@ -76,9 +66,6 @@
#include "helper/action.h"
#include "verbs.h"
-#include <iostream>
-
-#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <glibmm/i18n.h>
@@ -196,6 +183,7 @@ SprayTool::SprayTool()
}
SprayTool::~SprayTool() {
+ object_set.clear();
this->enableGrDrag(false);
this->style_set_connection.disconnect();
@@ -210,7 +198,7 @@ void SprayTool::update_cursor(bool /*with_shift*/) {
gchar *sel_message = NULL;
if (!desktop->selection->isEmpty()) {
- num = desktop->selection->itemList().size();
+ num = (guint) boost::distance(desktop->selection->items());
sel_message = g_strdup_printf(ngettext("<b>%i</b> object selected","<b>%i</b> objects selected",num), num);
} else {
sel_message = g_strdup_printf("%s", _("<b>Nothing</b> selected"));
@@ -591,7 +579,7 @@ static bool fit_item(SPDesktop *desktop,
if (selection->isEmpty()) {
return false;
}
- std::vector<SPItem*> const items_selected(selection->itemList());
+ std::vector<SPItem*> const items_selected(selection->items().begin(), selection->items().end());
std::vector<SPItem*> items_down_erased;
for (std::vector<SPItem*>::const_iterator i=items_down.begin(); i!=items_down.end(); ++i) {
SPItem *item_down = *i;
@@ -862,7 +850,7 @@ static bool fit_item(SPDesktop *desktop,
}
static bool sp_spray_recursive(SPDesktop *desktop,
- Inkscape::Selection *selection,
+ Inkscape::ObjectSet *set,
SPItem *item,
Geom::Point p,
Geom::Point /*vector*/,
@@ -907,7 +895,7 @@ static bool sp_spray_recursive(SPDesktop *desktop,
if (box) {
// convert 3D boxes to ordinary groups before spraying their shapes
item = box3d_convert_to_group(box);
- selection->add(item);
+ set->add(item);
}
}
@@ -996,23 +984,11 @@ static bool sp_spray_recursive(SPDesktop *desktop,
}
#ifdef ENABLE_SPRAY_MODE_SINGLE_PATH
} else if (mode == SPRAY_MODE_SINGLE_PATH) {
+ long setSize = boost::distance(set->items());
+ SPItem *parent_item = setSize > 0 ? set->items().front() : nullptr; // Initial object
+ SPItem *unionResult = setSize > 1 ? *(++set->items().begin()) : nullptr; // Previous union
+ SPItem *item_copied = nullptr; // Projected object
- SPItem *parent_item = NULL; // Initial object
- SPItem *item_copied = NULL; // Projected object
- SPItem *unionResult = NULL; // Previous union
-
- int i=1;
- std::vector<SPItem*> items=selection->itemList();
- for(std::vector<SPItem*>::const_iterator it=items.begin();it!=items.end(); ++it){
- SPItem *item1 = *it;
- if (i == 1) {
- parent_item = item1;
- }
- if (i == 2) {
- unionResult = item1;
- }
- i++;
- }
if (parent_item) {
SPDocument *doc = parent_item->document;
Inkscape::XML::Document* xml_doc = doc->getReprDoc();
@@ -1045,13 +1021,13 @@ static bool sp_spray_recursive(SPDesktop *desktop,
sp_item_move_rel(item_copied, Geom::Translate(move[Geom::X], -move[Geom::Y]));
// Union and duplication
- selection->clear();
- selection->add(item_copied);
+ set->clear();
+ set->add(item_copied);
if (unionResult) { // No need to add the very first item (initialized with NULL).
- selection->add(unionResult);
+ set->add(unionResult);
}
- sp_selected_path_union_skip_undo(selection, selection->desktop());
- selection->add(parent_item);
+ set->pathUnion(true);
+ set->add(parent_item);
Inkscape::GC::release(copy);
did = true;
}
@@ -1146,9 +1122,8 @@ static bool sp_spray_recursive(SPDesktop *desktop,
static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point p, Geom::Point vector, bool reverse)
{
SPDesktop *desktop = tc->desktop;
- Inkscape::Selection *selection = desktop->getSelection();
-
- if (selection->isEmpty()) {
+ Inkscape::ObjectSet *set = tc->objectSet();
+ if (set->isEmpty()) {
return false;
}
@@ -1170,7 +1145,7 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point
double move_standard_deviation = get_move_standard_deviation(tc);
{
- std::vector<SPItem*> const items(selection->itemList());
+ std::vector<SPItem*> const items(set->items().begin(), set->items().end());
for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end(); ++i){
SPItem *item = *i;
@@ -1182,7 +1157,7 @@ static bool sp_spray_dilate(SprayTool *tc, Geom::Point /*event_p*/, Geom::Point
SPItem *item = *i;
g_assert(item != NULL);
if (sp_spray_recursive(desktop
- , selection
+ , set
, item
, p, vector
, tc->mode
@@ -1276,6 +1251,11 @@ bool SprayTool::root_handler(GdkEvent* event) {
this->is_dilating = true;
this->has_dilated = false;
+ object_set = *desktop->getSelection();
+ if (mode == SPRAY_MODE_SINGLE_PATH) {
+ desktop->getSelection()->clear();
+ }
+
if(this->is_dilating && event->button.button == 1 && !this->space_panning) {
sp_spray_dilate(this, motion_w, desktop->dt2doc(motion_dt), Geom::Point(0,0), MOD__SHIFT(event));
}
@@ -1299,7 +1279,7 @@ bool SprayTool::root_handler(GdkEvent* event) {
guint num = 0;
if (!desktop->selection->isEmpty()) {
- num = desktop->selection->itemList().size();
+ num = (guint) boost::distance(desktop->selection->items());
}
if (num == 0) {
this->message_context->flash(Inkscape::ERROR_MESSAGE, _("<b>Nothing selected!</b> Select objects to spray."));
@@ -1384,6 +1364,8 @@ bool SprayTool::root_handler(GdkEvent* event) {
SP_VERB_CONTEXT_SPRAY, _("Spray with clones"));
break;
case SPRAY_MODE_SINGLE_PATH:
+ objectSet()->pathUnion(true);
+ desktop->getSelection()->add(object_set.objects().begin(), object_set.objects().end());
DocumentUndo::done(this->desktop->getDocument(),
SP_VERB_CONTEXT_SPRAY, _("Spray in single path"));
break;
diff --git a/src/ui/tools/spray-tool.h b/src/ui/tools/spray-tool.h
index c81110b37..d5504d565 100644
--- a/src/ui/tools/spray-tool.h
+++ b/src/ui/tools/spray-tool.h
@@ -13,6 +13,7 @@
* Vincent MONTAGNE
* Pierre BARBRY-BLOT
* Jabiertxo ARRAIZA
+ * Adrian Boguszewski
*
* Copyright (C) 2009 authors
*
@@ -120,8 +121,14 @@ public:
virtual const std::string& getPrefsPath();
-
void update_cursor(bool /*with_shift*/);
+
+ ObjectSet* objectSet() {
+ return &object_set;
+ }
+
+private:
+ ObjectSet object_set;
};
}
diff --git a/src/ui/tools/star-tool.cpp b/src/ui/tools/star-tool.cpp
index 9190ae57b..ddee08189 100644
--- a/src/ui/tools/star-tool.cpp
+++ b/src/ui/tools/star-tool.cpp
@@ -15,7 +15,7 @@
*/
#ifdef HAVE_CONFIG_H
-# include "config.h"
+#include <config.h>
#endif
#include <cstring>
@@ -31,14 +31,11 @@
#include "sp-namedview.h"
#include "selection.h"
-#include "snap.h"
#include "desktop.h"
#include "desktop-style.h"
#include "message-context.h"
#include "pixmaps/cursor-star.xpm"
#include <glibmm/i18n.h>
-#include "preferences.h"
-#include "xml/repr.h"
#include "xml/node-event-vector.h"
#include "context-fns.h"
#include "ui/shape-editor.h"
diff --git a/src/ui/tools/text-tool.cpp b/src/ui/tools/text-tool.cpp
index 1888551cf..649bbb045 100644
--- a/src/ui/tools/text-tool.cpp
+++ b/src/ui/tools/text-tool.cpp
@@ -14,7 +14,7 @@
*/
#ifdef HAVE_CONFIG_H
-# include <config.h>
+#include <config.h>
#endif
#include <gtkmm/clipboard.h>
@@ -23,7 +23,6 @@
#include <display/sp-ctrlquadr.h>
#include <gdk/gdkkeysyms.h>
#include <glibmm/i18n.h>
-#include <sstream>
#include "context-fns.h"
@@ -36,7 +35,6 @@
#include "message-stack.h"
#include "pixmaps/cursor-text-insert.xpm"
#include "pixmaps/cursor-text.xpm"
-#include "preferences.h"
#include "rubberband.h"
#include "selection-chemistry.h"
#include "selection.h"
@@ -50,8 +48,8 @@
#include "ui/control-manager.h"
#include "verbs.h"
#include "xml/node-event-vector.h"
-#include "xml/repr.h"
-#include <gtk/gtk.h>
+#include "xml/attribute-record.h"
+#include "xml/sp-css-attr.h"
using Inkscape::ControlManager;
using Inkscape::DocumentUndo;
@@ -1361,6 +1359,59 @@ SPCSSAttr *sp_text_get_style_at_cursor(ToolBase const *ec)
return NULL;
}
+static bool css_attrs_are_equal(SPCSSAttr const *first, SPCSSAttr const *second)
+{
+ Inkscape::Util::List<Inkscape::XML::AttributeRecord const> attrs = first->attributeList();
+ for ( ; attrs ; attrs++) {
+ gchar const *other_attr = second->attribute(g_quark_to_string(attrs->key));
+ if (other_attr == NULL || strcmp(attrs->value, other_attr))
+ return false;
+ }
+ attrs = second->attributeList();
+ for ( ; attrs ; attrs++) {
+ gchar const *other_attr = first->attribute(g_quark_to_string(attrs->key));
+ if (other_attr == NULL || strcmp(attrs->value, other_attr))
+ return false;
+ }
+ return true;
+}
+
+std::vector<SPCSSAttr*> sp_text_get_selected_style(ToolBase const *ec, unsigned *k, int *b, std::vector<unsigned> *positions)
+{
+ std::vector<SPCSSAttr*> vec;
+ SPCSSAttr *css, *css_new;
+ TextTool *tc = SP_TEXT_CONTEXT(ec);
+ Inkscape::Text::Layout::iterator i = std::min(tc->text_sel_start, tc->text_sel_end);
+ SPObject const *obj = sp_te_object_at_position(tc->text, i);
+ if (obj) {
+ css = take_style_from_item(const_cast<SPObject*>(obj));
+ }
+ vec.push_back(css);
+ positions->push_back(0);
+ i.nextCharacter();
+ *k = 1;
+ *b = 1;
+ while (i != std::max(tc->text_sel_start, tc->text_sel_end))
+ {
+ obj = sp_te_object_at_position(tc->text, i);
+ if (obj) {
+ css_new = take_style_from_item(const_cast<SPObject*>(obj));
+ }
+ if(!css_attrs_are_equal(css, css_new))
+ {
+ vec.push_back(css_new);
+ css = sp_repr_css_attr_new();
+ sp_repr_css_merge(css, css_new);
+ positions->push_back(*k);
+ (*b)++;
+ }
+ i.nextCharacter();
+ (*k)++;
+ }
+ positions->push_back(*k);
+ return vec;
+}
+
/**
Deletes the currently selected characters. Returns false if there is no
text selection currently.
@@ -1446,7 +1497,6 @@ bool TextTool::_styleSet(SPCSSAttr const *css)
_("Set text style"));
sp_text_context_update_cursor(this);
sp_text_context_update_text_selection(this);
-
return true;
}
diff --git a/src/ui/tools/text-tool.h b/src/ui/tools/text-tool.h
index 289ee180d..f2e6fea1a 100644
--- a/src/ui/tools/text-tool.h
+++ b/src/ui/tools/text-tool.h
@@ -94,6 +94,7 @@ private:
bool sp_text_paste_inline(ToolBase *ec);
Glib::ustring sp_text_get_selected_text(ToolBase const *ec);
SPCSSAttr *sp_text_get_style_at_cursor(ToolBase const *ec);
+std::vector<SPCSSAttr*> sp_text_get_selected_style(ToolBase const *ec, unsigned *k, int *b, std::vector<unsigned> *positions);
bool sp_text_delete_selection(ToolBase *ec);
void sp_text_context_place_cursor (TextTool *tc, SPObject *text, Inkscape::Text::Layout::iterator where);
void sp_text_context_place_cursor_at (TextTool *tc, SPObject *text, Geom::Point const p);
diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp
index 36fe26e76..3d755eadc 100644
--- a/src/ui/tools/tool-base.cpp
+++ b/src/ui/tools/tool-base.cpp
@@ -15,23 +15,28 @@
*/
#ifdef HAVE_CONFIG_H
-# include "config.h"
+#include <config.h>
#endif
#include "widgets/desktop-widget.h"
#include "shortcuts.h"
#include "file.h"
+
+#include "ui/interface.h"
+#include "ui/event-debug.h"
+#include "ui/tool/control-point.h"
+#include "ui/shape-editor.h"
#include "ui/tools/tool-base.h"
+#include "ui/tools-switch.h"
+#include "ui/tools/lpe-tool.h"
-#include <string.h>
#include <gdk/gdkkeysyms.h>
-#include <gtk/gtk.h>
#include <glibmm/i18n.h>
-#include <cstring>
-#include <string>
#include "display/sp-canvas.h"
+#include "display/sp-canvas-group.h"
+#include "display/canvas-rotate.h"
#include "xml/node-event-vector.h"
#include "sp-cursor.h"
#include "desktop.h"
@@ -40,21 +45,12 @@
#include "desktop-style.h"
#include "sp-namedview.h"
#include "selection.h"
-#include "ui/interface.h"
#include "macros.h"
-#include "ui/tools-switch.h"
-#include "preferences.h"
#include "message-context.h"
#include "gradient-drag.h"
-#include "attributes.h"
#include "rubberband.h"
#include "selcue.h"
-#include "ui/tools/lpe-tool.h"
-#include "ui/tool/control-point.h"
-#include "ui/shape-editor.h"
#include "sp-guide.h"
-#include "color.h"
-#include "knot.h"
#include "knot-ptr.h"
// globals for temporary switching to selector by space
@@ -118,11 +114,7 @@ ToolBase::~ToolBase() {
}
if (this->cursor != NULL) {
-#if GTK_CHECK_VERSION(3,0,0)
g_object_unref(this->cursor);
-#else
- gdk_cursor_unref(this->cursor);
-#endif
this->cursor = NULL;
}
@@ -149,16 +141,10 @@ void ToolBase::sp_event_context_set_cursor(GdkCursorType cursor_type) {
GdkDisplay *display = gdk_display_get_default();
GdkCursor *cursor = gdk_cursor_new_for_display(display, cursor_type);
-#if WITH_GTKMM_3_0
if (cursor) {
gdk_window_set_cursor (gtk_widget_get_window (w), cursor);
g_object_unref (cursor);
}
-#else
- gdk_window_set_cursor (gtk_widget_get_window (w), cursor);
- gdk_cursor_unref (cursor);
-#endif
-
}
/**
@@ -188,11 +174,7 @@ void ToolBase::sp_event_context_update_cursor() {
);
if (pixbuf != NULL) {
if (this->cursor) {
-#if GTK_CHECK_VERSION(3,0,0)
g_object_unref(this->cursor);
-#else
- gdk_cursor_unref(this->cursor);
-#endif
}
this->cursor = gdk_cursor_new_from_pixbuf(display, pixbuf, this->hot_x, this->hot_y);
g_object_unref(pixbuf);
@@ -202,11 +184,7 @@ void ToolBase::sp_event_context_update_cursor() {
if (pixbuf) {
if (this->cursor) {
-#if GTK_CHECK_VERSION(3,0,0)
g_object_unref(this->cursor);
-#else
- gdk_cursor_unref(this->cursor);
-#endif
}
this->cursor = gdk_cursor_new_from_pixbuf(display,
pixbuf, this->hot_x, this->hot_y);
@@ -349,6 +327,8 @@ static gdouble accelerate_scroll(GdkEvent *event, gdouble acceleration,
}
bool ToolBase::root_handler(GdkEvent* event) {
+
+ // ui_dump_event (event, "ToolBase::root_handler");
static Geom::Point button_w;
static unsigned int panning = 0;
static unsigned int panning_cursor = 0;
@@ -400,7 +380,22 @@ bool ToolBase::root_handler(GdkEvent* event) {
break;
case 2:
- if (event->button.state & GDK_SHIFT_MASK) {
+ if (event->button.state & GDK_CONTROL_MASK) {
+ // On screen canvas rotation preview
+
+ // Grab background before doing anything else
+ sp_canvas_rotate_start (SP_CANVAS_ROTATE(desktop->canvas_rotate),
+ desktop->canvas->_backing_store);
+ sp_canvas_item_ungrab (desktop->acetate, event->button.time);
+ sp_canvas_item_show (desktop->canvas_rotate);
+ sp_canvas_item_grab (desktop->canvas_rotate,
+ GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
+ GDK_BUTTON_RELEASE_MASK |
+ GDK_POINTER_MOTION_MASK,
+ NULL, event->button.time );
+ // sp_canvas_item_hide (desktop->drawing);
+
+ } else if (event->button.state & GDK_SHIFT_MASK) {
zoom_rb = 2;
} else {
// When starting panning, make sure there are no snap events pending because these might disable the panning again
@@ -410,9 +405,9 @@ bool ToolBase::root_handler(GdkEvent* event) {
panning = 2;
sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
- GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK
- | GDK_POINTER_MOTION_HINT_MASK, NULL,
- event->button.time - 1);
+ GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK |
+ GDK_POINTER_MOTION_HINT_MASK,
+ NULL, event->button.time - 1);
}
@@ -491,7 +486,7 @@ bool ToolBase::root_handler(GdkEvent* event) {
Geom::Point const motion_w(event->motion.x, event->motion.y);
Geom::Point const moved_w(motion_w - button_w);
- this->desktop->scroll_world(moved_w, true); // we're still scrolling, do not redraw
+ this->desktop->scroll_relative(moved_w, true); // we're still scrolling, do not redraw
ret = TRUE;
}
} else if (zoom_rb) {
@@ -522,6 +517,7 @@ bool ToolBase::root_handler(GdkEvent* event) {
break;
case GDK_BUTTON_RELEASE:
+
xp = yp = 0;
if (panning_cursor == 1) {
@@ -562,7 +558,7 @@ bool ToolBase::root_handler(GdkEvent* event) {
Geom::Point const motion_w(event->button.x, event->button.y);
Geom::Point const moved_w(motion_w - button_w);
- this->desktop->scroll_world(moved_w);
+ this->desktop->scroll_relative(moved_w);
desktop->updateNow();
ret = TRUE;
} else if (zoom_rb == event->button.button) {
@@ -639,7 +635,7 @@ bool ToolBase::root_handler(GdkEvent* event) {
acceleration, desktop->getCanvas()));
gobble_key_events(get_group0_keyval(&event->key), GDK_CONTROL_MASK);
- this->desktop->scroll_world(i, 0);
+ this->desktop->scroll_relative(Geom::Point(i, 0));
ret = TRUE;
}
break;
@@ -652,7 +648,7 @@ bool ToolBase::root_handler(GdkEvent* event) {
acceleration, desktop->getCanvas()));
gobble_key_events(get_group0_keyval(&event->key), GDK_CONTROL_MASK);
- this->desktop->scroll_world(0, i);
+ this->desktop->scroll_relative(Geom::Point(0, i));
ret = TRUE;
}
break;
@@ -665,7 +661,7 @@ bool ToolBase::root_handler(GdkEvent* event) {
acceleration, desktop->getCanvas()));
gobble_key_events(get_group0_keyval(&event->key), GDK_CONTROL_MASK);
- this->desktop->scroll_world(-i, 0);
+ this->desktop->scroll_relative(Geom::Point(-i, 0));
ret = TRUE;
}
break;
@@ -678,7 +674,7 @@ bool ToolBase::root_handler(GdkEvent* event) {
acceleration, desktop->getCanvas()));
gobble_key_events(get_group0_keyval(&event->key), GDK_CONTROL_MASK);
- this->desktop->scroll_world(0, -i);
+ this->desktop->scroll_relative(Geom::Point(0, -i));
ret = TRUE;
}
break;
@@ -772,34 +768,60 @@ bool ToolBase::root_handler(GdkEvent* event) {
case GDK_SCROLL: {
bool ctrl = (event->scroll.state & GDK_CONTROL_MASK);
+ bool shift = (event->scroll.state & GDK_SHIFT_MASK);
bool wheelzooms = prefs->getBool("/options/wheelzooms/value");
int const wheel_scroll = prefs->getIntLimited(
"/options/wheelscroll/value", 40, 0, 1000);
-#if GTK_CHECK_VERSION(3,0,0)
// Size of smooth-scrolls (only used in GTK+ 3)
gdouble delta_x = 0;
gdouble delta_y = 0;
-#endif
- /* shift + wheel, pan left--right */
- if (event->scroll.state & GDK_SHIFT_MASK) {
+ if (ctrl & shift) {
+ /* ctrl + shift, rotate */
+
+ double rotate_inc = prefs->getDoubleLimited(
+ "/options/rotateincrement/value", 15, 1, 90, "°" );
+ rotate_inc *= M_PI/180.0;
+
switch (event->scroll.direction) {
case GDK_SCROLL_UP:
- desktop->scroll_world(wheel_scroll, 0);
+ // Do nothing
break;
case GDK_SCROLL_DOWN:
- desktop->scroll_world(-wheel_scroll, 0);
+ rotate_inc = -rotate_inc;
+ break;
+
+ default:
+ rotate_inc = 0.0;
+ break;
+ }
+
+ if (rotate_inc != 0.0) {
+ Geom::Point const scroll_dt = desktop->point();
+ desktop->rotate_relative_keep_point(scroll_dt, rotate_inc);
+ }
+
+ } else if (event->scroll.state & GDK_SHIFT_MASK) {
+ /* shift + wheel, pan left--right */
+
+ switch (event->scroll.direction) {
+ case GDK_SCROLL_UP:
+ desktop->scroll_relative(Geom::Point(wheel_scroll, 0));
+ break;
+
+ case GDK_SCROLL_DOWN:
+ desktop->scroll_relative(Geom::Point(-wheel_scroll, 0));
break;
default:
break;
}
- /* ctrl + wheel, zoom in--out */
} else if ((ctrl && !wheelzooms) || (!ctrl && wheelzooms)) {
+ /* ctrl + wheel, zoom in--out */
double rel_zoom;
double const zoom_inc = prefs->getDoubleLimited(
"/options/zoomincrement/value", M_SQRT2, 1.01, 10);
@@ -827,27 +849,25 @@ bool ToolBase::root_handler(GdkEvent* event) {
} else {
switch (event->scroll.direction) {
case GDK_SCROLL_UP:
- desktop->scroll_world(0, wheel_scroll);
+ desktop->scroll_relative(Geom::Point(0, wheel_scroll));
break;
case GDK_SCROLL_DOWN:
- desktop->scroll_world(0, -wheel_scroll);
+ desktop->scroll_relative(Geom::Point(0, -wheel_scroll));
break;
case GDK_SCROLL_LEFT:
- desktop->scroll_world(wheel_scroll, 0);
+ desktop->scroll_relative(Geom::Point(wheel_scroll, 0));
break;
case GDK_SCROLL_RIGHT:
- desktop->scroll_world(-wheel_scroll, 0);
+ desktop->scroll_relative(Geom::Point(-wheel_scroll, 0));
break;
-#if GTK_CHECK_VERSION(3,0,0)
case GDK_SCROLL_SMOOTH:
gdk_event_get_scroll_deltas(event, &delta_x, &delta_y);
- desktop->scroll_world(delta_x, delta_y);
+ desktop->scroll_relative(Geom::Point(delta_x, delta_y));
break;
-#endif
}
}
break;
@@ -1081,9 +1101,8 @@ void sp_event_root_menu_popup(SPDesktop *desktop, SPItem *item, GdkEvent *event)
item = sp_event_context_find_item (desktop,
Geom::Point(event->button.x, event->button.y), FALSE, FALSE);
- /* fixme: This is not what I want but works for now (Lauris) */
- if (event->type == GDK_KEY_PRESS) {
- item = desktop->getSelection()->singleItem();
+ if (event->type == GDK_KEY_PRESS && !desktop->getSelection()->isEmpty()) {
+ item = desktop->getSelection()->items().front();
}
ContextMenu* CM = new ContextMenu(desktop, item);
@@ -1157,8 +1176,9 @@ SPItem *sp_event_context_find_item(SPDesktop *desktop, Geom::Point const &p,
SPItem *item = 0;
if (select_under) {
- SPItem *selected_at_point = desktop->getItemFromListAtPointBottom(
- desktop->selection->itemList(), p);
+ auto tmp = desktop->selection->items();
+ std::vector<SPItem *> vec(tmp.begin(), tmp.end());
+ SPItem *selected_at_point = desktop->getItemFromListAtPointBottom(vec, p);
item = desktop->getItemAtPoint(p, into_groups, selected_at_point);
if (item == NULL) { // we may have reached bottom, flip over to the top
item = desktop->getItemAtPoint(p, into_groups, NULL);
@@ -1189,47 +1209,6 @@ sp_event_context_get_shape_editor(ToolBase *ec) {
return ec->shape_editor;
}
-void event_context_print_event_info(GdkEvent *event, bool print_return) {
- switch (event->type) {
- case GDK_BUTTON_PRESS:
- g_print("GDK_BUTTON_PRESS");
- break;
- case GDK_2BUTTON_PRESS:
- g_print("GDK_2BUTTON_PRESS");
- break;
- case GDK_3BUTTON_PRESS:
- g_print("GDK_3BUTTON_PRESS");
- break;
-
- case GDK_MOTION_NOTIFY:
- g_print("GDK_MOTION_NOTIFY");
- break;
- case GDK_ENTER_NOTIFY:
- g_print("GDK_ENTER_NOTIFY");
- break;
-
- case GDK_LEAVE_NOTIFY:
- g_print("GDK_LEAVE_NOTIFY");
- break;
- case GDK_BUTTON_RELEASE:
- g_print("GDK_BUTTON_RELEASE");
- break;
-
- case GDK_KEY_PRESS:
- g_print("GDK_KEY_PRESS: %d", get_group0_keyval(&event->key));
- break;
- case GDK_KEY_RELEASE:
- g_print("GDK_KEY_RELEASE: %d", get_group0_keyval(&event->key));
- break;
- default:
- //g_print ("even type not recognized");
- break;
- }
-
- if (print_return) {
- g_print("\n");
- }
-}
/**
* Analyses the current event, calculates the mouse speed, turns snapping off (temporarily) if the
diff --git a/src/ui/tools/tool-base.h b/src/ui/tools/tool-base.h
index 58eb6f88e..3d22fc66f 100644
--- a/src/ui/tools/tool-base.h
+++ b/src/ui/tools/tool-base.h
@@ -176,6 +176,7 @@ public:
ShapeEditor* shape_editor;
bool space_panning;
+ bool rotating_mode;
DelayedSnapEvent *_delayed_snap_event;
bool _dse_callback_in_process;
diff --git a/src/ui/tools/tweak-tool.cpp b/src/ui/tools/tweak-tool.cpp
index 39a7a3f0b..ff5d623c2 100644
--- a/src/ui/tools/tweak-tool.cpp
+++ b/src/ui/tools/tweak-tool.cpp
@@ -11,8 +11,6 @@
* Released under GNU GPL, read the file 'COPYING' for more information
*/
-#include "config.h"
-
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <glibmm/i18n.h>
@@ -21,7 +19,6 @@
#include "svg/svg.h"
-#include <glib.h>
#include "macros.h"
#include "document.h"
#include "document-undo.h"
@@ -48,34 +45,27 @@
#include "pixmaps/cursor-push.xpm"
#include "pixmaps/cursor-roughen.xpm"
#include "pixmaps/cursor-color.xpm"
-#include <boost/optional.hpp>
-#include "xml/repr.h"
#include "context-fns.h"
-#include "sp-item.h"
#include "inkscape.h"
-#include "color.h"
-#include "svg/svg-color.h"
#include "splivarot.h"
#include "sp-item-group.h"
#include "sp-shape.h"
#include "sp-path.h"
#include "path-chemistry.h"
-#include "sp-gradient.h"
#include "sp-stop.h"
#include "sp-gradient-reference.h"
#include "sp-linear-gradient.h"
#include "sp-radial-gradient.h"
+#include "sp-mesh-gradient.h"
+#include "sp-mesh-array.h"
#include "gradient-chemistry.h"
#include "sp-text.h"
#include "sp-flowtext.h"
#include "display/sp-canvas.h"
-#include "display/canvas-bpath.h"
#include "display/canvas-arena.h"
#include "display/curve.h"
#include "livarot/Shape.h"
-#include <2geom/transforms.h>
#include <2geom/circle.h>
-#include "preferences.h"
#include "style.h"
#include "box3d.h"
#include "sp-item-transform.h"
@@ -153,7 +143,7 @@ void TweakTool::update_cursor (bool with_shift) {
gchar *sel_message = NULL;
if (!desktop->selection->isEmpty()) {
- num = desktop->selection->itemList().size();
+ num = (guint) boost::distance(desktop->selection->items());
sel_message = g_strdup_printf(ngettext("<b>%i</b> object selected","<b>%i</b> objects selected",num), num);
} else {
sel_message = g_strdup_printf("%s", _("<b>Nothing</b> selected"));
@@ -385,9 +375,9 @@ sp_tweak_dilate_recursive (Inkscape::Selection *selection, SPItem *item, Geom::P
if (dynamic_cast<SPGroup *>(item) && !dynamic_cast<SPBox3D *>(item)) {
GSList *children = NULL;
- for (SPObject *child = item->firstChild() ; child; child = child->getNext() ) {
- if (dynamic_cast<SPItem *>(static_cast<SPObject *>(child))) {
- children = g_slist_prepend(children, child);
+ for (auto& child: item->children) {
+ if (dynamic_cast<SPItem *>(static_cast<SPObject *>(&child))) {
+ children = g_slist_prepend(children, &child);
}
}
@@ -773,112 +763,132 @@ static void tweak_colors_in_gradient(SPItem *item, Inkscape::PaintTarget fill_or
p *= (gradient->gradientTransform).inverse();
// now p is in gradient's original coordinates
- double pos = 0;
- double r = 0;
-
SPLinearGradient *lg = dynamic_cast<SPLinearGradient *>(gradient);
- if (lg) {
- Geom::Point p1(lg->x1.computed, lg->y1.computed);
- Geom::Point p2(lg->x2.computed, lg->y2.computed);
- Geom::Point pdiff(p2 - p1);
- double vl = Geom::L2(pdiff);
+ SPRadialGradient *rg = dynamic_cast<SPRadialGradient *>(gradient);
+ if (lg || rg) {
- // This is the matrix which moves and rotates the gradient line
- // so it's oriented along the X axis:
- Geom::Affine norm = Geom::Affine(Geom::Translate(-p1)) * Geom::Affine(Geom::Rotate(-atan2(pdiff[Geom::Y], pdiff[Geom::X])));
+ double pos = 0;
+ double r = 0;
- // Transform the mouse point by it to find out its projection onto the gradient line:
- Geom::Point pnorm = p * norm;
+ if (lg) {
+ Geom::Point p1(lg->x1.computed, lg->y1.computed);
+ Geom::Point p2(lg->x2.computed, lg->y2.computed);
+ Geom::Point pdiff(p2 - p1);
+ double vl = Geom::L2(pdiff);
- // Scale its X coordinate to match the length of the gradient line:
- pos = pnorm[Geom::X] / vl;
- // Calculate radius in lenfth-of-gradient-line units
- r = radius / vl;
+ // This is the matrix which moves and rotates the gradient line
+ // so it's oriented along the X axis:
+ Geom::Affine norm = Geom::Affine(Geom::Translate(-p1)) *
+ Geom::Affine(Geom::Rotate(-atan2(pdiff[Geom::Y], pdiff[Geom::X])));
- } else {
- SPRadialGradient *rg = dynamic_cast<SPRadialGradient *>(gradient);
+ // Transform the mouse point by it to find out its projection onto the gradient line:
+ Geom::Point pnorm = p * norm;
+
+ // Scale its X coordinate to match the length of the gradient line:
+ pos = pnorm[Geom::X] / vl;
+ // Calculate radius in lenfth-of-gradient-line units
+ r = radius / vl;
+
+ }
if (rg) {
Geom::Point c (rg->cx.computed, rg->cy.computed);
pos = Geom::L2(p - c) / rg->r.computed;
r = radius / rg->r.computed;
}
- }
- // Normalize pos to 0..1, taking into accound gradient spread:
- double pos_e = pos;
- if (gradient->getSpread() == SP_GRADIENT_SPREAD_PAD) {
- if (pos > 1) {
- pos_e = 1;
- }
- if (pos < 0) {
- pos_e = 0;
- }
- } else if (gradient->getSpread() == SP_GRADIENT_SPREAD_REPEAT) {
- if (pos > 1 || pos < 0) {
- pos_e = pos - floor(pos);
- }
- } else if (gradient->getSpread() == SP_GRADIENT_SPREAD_REFLECT) {
- if (pos > 1 || pos < 0) {
- bool odd = ((int)(floor(pos)) % 2 == 1);
- pos_e = pos - floor(pos);
- if (odd) {
- pos_e = 1 - pos_e;
+ // Normalize pos to 0..1, taking into accound gradient spread:
+ double pos_e = pos;
+ if (gradient->getSpread() == SP_GRADIENT_SPREAD_PAD) {
+ if (pos > 1) {
+ pos_e = 1;
+ }
+ if (pos < 0) {
+ pos_e = 0;
+ }
+ } else if (gradient->getSpread() == SP_GRADIENT_SPREAD_REPEAT) {
+ if (pos > 1 || pos < 0) {
+ pos_e = pos - floor(pos);
+ }
+ } else if (gradient->getSpread() == SP_GRADIENT_SPREAD_REFLECT) {
+ if (pos > 1 || pos < 0) {
+ bool odd = ((int)(floor(pos)) % 2 == 1);
+ pos_e = pos - floor(pos);
+ if (odd) {
+ pos_e = 1 - pos_e;
+ }
}
}
- }
- SPGradient *vector = sp_gradient_get_forked_vector_if_necessary(gradient, false);
+ SPGradient *vector = sp_gradient_get_forked_vector_if_necessary(gradient, false);
- double offset_l = 0;
- double offset_h = 0;
- SPObject *child_prev = NULL;
- for (SPObject *child = vector->firstChild(); child; child = child->getNext()) {
- SPStop *stop = dynamic_cast<SPStop *>(child);
- if (!stop) {
- continue;
- }
+ double offset_l = 0;
+ double offset_h = 0;
+ SPObject *child_prev = NULL;
+ for (auto& child: vector->children) {
+ SPStop *stop = dynamic_cast<SPStop *>(&child);
+ if (!stop) {
+ continue;
+ }
- offset_h = stop->offset;
-
- if (child_prev) {
- SPStop *prevStop = dynamic_cast<SPStop *>(child_prev);
- g_assert(prevStop != NULL);
-
- if (offset_h - offset_l > r && pos_e >= offset_l && pos_e <= offset_h) {
- // the summit falls in this interstop, and the radius is small,
- // so it only affects the ends of this interstop;
- // distribute the force between the two endstops so that they
- // get all the painting even if they are not touched by the brush
- tweak_color (mode, stop->specified_color.v.c, rgb_goal,
- force * (pos_e - offset_l) / (offset_h - offset_l),
- do_h, do_s, do_l);
- tweak_color(mode, prevStop->specified_color.v.c, rgb_goal,
- force * (offset_h - pos_e) / (offset_h - offset_l),
- do_h, do_s, do_l);
- stop->updateRepr();
- child_prev->updateRepr();
- break;
- } else {
- // wide brush, may affect more than 2 stops,
- // paint each stop by the force from the profile curve
- if (offset_l <= pos_e && offset_l > pos_e - r) {
+ offset_h = stop->offset;
+
+ if (child_prev) {
+ SPStop *prevStop = dynamic_cast<SPStop *>(child_prev);
+ g_assert(prevStop != NULL);
+
+ if (offset_h - offset_l > r && pos_e >= offset_l && pos_e <= offset_h) {
+ // the summit falls in this interstop, and the radius is small,
+ // so it only affects the ends of this interstop;
+ // distribute the force between the two endstops so that they
+ // get all the painting even if they are not touched by the brush
+ tweak_color (mode, stop->specified_color.v.c, rgb_goal,
+ force * (pos_e - offset_l) / (offset_h - offset_l),
+ do_h, do_s, do_l);
tweak_color(mode, prevStop->specified_color.v.c, rgb_goal,
- force * tweak_profile (fabs (pos_e - offset_l), r),
+ force * (offset_h - pos_e) / (offset_h - offset_l),
do_h, do_s, do_l);
+ stop->updateRepr();
child_prev->updateRepr();
+ break;
+ } else {
+ // wide brush, may affect more than 2 stops,
+ // paint each stop by the force from the profile curve
+ if (offset_l <= pos_e && offset_l > pos_e - r) {
+ tweak_color(mode, prevStop->specified_color.v.c, rgb_goal,
+ force * tweak_profile (fabs (pos_e - offset_l), r),
+ do_h, do_s, do_l);
+ child_prev->updateRepr();
+ }
+
+ if (offset_h >= pos_e && offset_h < pos_e + r) {
+ tweak_color (mode, stop->specified_color.v.c, rgb_goal,
+ force * tweak_profile (fabs (pos_e - offset_h), r),
+ do_h, do_s, do_l);
+ stop->updateRepr();
+ }
}
+ }
- if (offset_h >= pos_e && offset_h < pos_e + r) {
+ offset_l = offset_h;
+ child_prev = &child;
+ }
+ } else {
+ // Mesh
+ SPMeshGradient *mg = dynamic_cast<SPMeshGradient *>(gradient);
+ if (mg) {
+ SPMeshGradient *mg_array = dynamic_cast<SPMeshGradient *>(mg->getArray());
+ SPMeshNodeArray *array = &(mg_array->array);
+ // Every third node is a corner node
+ for( unsigned i=0; i < array->nodes.size(); i+=3 ) {
+ for( unsigned j=0; j < array->nodes[i].size(); j+=3 ) {
+ SPStop *stop = array->nodes[i][j]->stop;
+ double distance = Geom::L2(Geom::Point(p - array->nodes[i][j]->p));
tweak_color (mode, stop->specified_color.v.c, rgb_goal,
- force * tweak_profile (fabs (pos_e - offset_h), r),
- do_h, do_s, do_l);
+ force * tweak_profile (distance, radius), do_h, do_s, do_l);
stop->updateRepr();
}
}
}
-
- offset_l = offset_h;
- child_prev = child;
}
}
@@ -894,8 +904,8 @@ sp_tweak_color_recursive (guint mode, SPItem *item, SPItem *item_at_point,
bool did = false;
if (dynamic_cast<SPGroup *>(item)) {
- for (SPObject *child = item->firstChild() ; child; child = child->getNext() ) {
- SPItem *childItem = dynamic_cast<SPItem *>(child);
+ for (auto& child: item->children) {
+ SPItem *childItem = dynamic_cast<SPItem *>(&child);
if (childItem) {
if (sp_tweak_color_recursive (mode, childItem, item_at_point,
fill_goal, do_fill,
@@ -951,9 +961,8 @@ sp_tweak_color_recursive (guint mode, SPItem *item, SPItem *item_at_point,
Geom::Affine i2dt = item->i2dt_affine ();
if (style->filter.set && style->getFilter()) {
//cycle through filter primitives
- SPObject *primitive_obj = style->getFilter()->children;
- while (primitive_obj) {
- SPFilterPrimitive *primitive = dynamic_cast<SPFilterPrimitive *>(primitive_obj);
+ for (auto& primitive_obj: style->getFilter()->children) {
+ SPFilterPrimitive *primitive = dynamic_cast<SPFilterPrimitive *>(&primitive_obj);
if (primitive) {
//if primitive is gaussianblur
SPGaussianBlur * spblur = dynamic_cast<SPGaussianBlur *>(primitive);
@@ -962,7 +971,6 @@ sp_tweak_color_recursive (guint mode, SPItem *item, SPItem *item_at_point,
blur_now += num * i2dt.descrim(); // sum all blurs in the filter
}
}
- primitive_obj = primitive_obj->next;
}
}
double perimeter = bbox->dimensions()[Geom::X] + bbox->dimensions()[Geom::Y];
@@ -1076,8 +1084,9 @@ sp_tweak_dilate (TweakTool *tc, Geom::Point event_p, Geom::Point p, Geom::Point
double move_force = get_move_force(tc);
double color_force = MIN(sqrt(path_force)/20.0, 1);
- std::vector<SPItem*> items=selection->itemList();
- for(std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end(); ++i){
+// auto items= selection->items();
+ std::vector<SPItem*> items(selection->items().begin(), selection->items().end());
+ for(auto i=items.begin();i!=items.end(); ++i){
SPItem *item = *i;
if (is_color_mode (tc->mode)) {
@@ -1185,7 +1194,7 @@ bool TweakTool::root_handler(GdkEvent* event) {
guint num = 0;
if (!desktop->selection->isEmpty()) {
- num = desktop->selection->itemList().size();
+ num = (guint) boost::distance(desktop->selection->items());
}
if (num == 0) {
this->message_context->flash(Inkscape::ERROR_MESSAGE, _("<b>Nothing selected!</b> Select objects to tweak."));
diff --git a/src/ui/tools/zoom-tool.cpp b/src/ui/tools/zoom-tool.cpp
index 13e097c18..d40d2e969 100644
--- a/src/ui/tools/zoom-tool.cpp
+++ b/src/ui/tools/zoom-tool.cpp
@@ -21,7 +21,6 @@
#include "desktop.h"
#include "pixmaps/cursor-zoom.xpm"
#include "pixmaps/cursor-zoom-out.xpm"
-#include "preferences.h"
#include "selection-chemistry.h"
#include "ui/tools/zoom-tool.h"
@@ -104,12 +103,14 @@ bool ZoomTool::root_handler(GdkEvent* event) {
desktop->zoom_relative_keep_point(button_dt, zoom_rel);
ret = true;
}
-
- sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
- GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK,
- NULL, event->button.time);
- this->grabbed = SP_CANVAS_ITEM(desktop->acetate);
+ sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
+ GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |
+ GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
+ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK,
+ NULL, event->button.time);
+
+ this->grabbed = SP_CANVAS_ITEM(desktop->acetate);
break;
}
@@ -157,10 +158,10 @@ bool ZoomTool::root_handler(GdkEvent* event) {
Inkscape::Rubberband::get(desktop)->stop();
- if (this->grabbed) {
- sp_canvas_item_ungrab(this->grabbed, event->button.time);
- this->grabbed = NULL;
- }
+ if (this->grabbed) {
+ sp_canvas_item_ungrab(this->grabbed, event->button.time);
+ this->grabbed = NULL;
+ }
xp = yp = 0;
escaped = false;