summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMaximilian Albert <maximilian.albert@gmail.com>2008-01-16 00:12:43 +0000
committercilix42 <cilix42@users.sourceforge.net>2008-01-16 00:12:43 +0000
commit2366e7af893efd3b5a12a83c840d7d0fa04a36f9 (patch)
tree6905cb150a4cb1c303eb5a71311c0adb8b39d088 /src
parentcreate inkview on dist (diff)
downloadinkscape-2366e7af893efd3b5a12a83c840d7d0fa04a36f9.tar.gz
inkscape-2366e7af893efd3b5a12a83c840d7d0fa04a36f9.zip
Make path segments convertable to guides, too
(bzr r4503)
Diffstat (limited to 'src')
-rw-r--r--src/pen-context.cpp8
-rw-r--r--src/pencil-context.cpp9
-rw-r--r--src/sp-path.cpp36
3 files changed, 53 insertions, 0 deletions
diff --git a/src/pen-context.cpp b/src/pen-context.cpp
index 326791275..f56714eb7 100644
--- a/src/pen-context.cpp
+++ b/src/pen-context.cpp
@@ -23,6 +23,7 @@
#include "desktop.h"
#include "desktop-handles.h"
#include "selection.h"
+#include "selection-chemistry.h"
#include "draw-anchor.h"
#include "message-stack.h"
#include "message-context.h"
@@ -979,6 +980,13 @@ pen_handle_key_press(SPPenContext *const pc, GdkEvent *event)
ret = TRUE;
}
break;
+ case GDK_g:
+ case GDK_G:
+ if (MOD__SHIFT_ONLY) {
+ sp_selection_to_guides();
+ ret = true;
+ }
+ break;
case GDK_BackSpace:
case GDK_Delete:
case GDK_KP_Delete:
diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp
index 1ee39d530..f17337183 100644
--- a/src/pencil-context.cpp
+++ b/src/pencil-context.cpp
@@ -21,6 +21,7 @@
#include "desktop.h"
#include "desktop-handles.h"
#include "selection.h"
+#include "selection-chemistry.h"
#include "draw-anchor.h"
#include "message-stack.h"
#include "message-context.h"
@@ -39,6 +40,7 @@
#include "xml/repr.h"
#include "document.h"
#include "desktop-style.h"
+#include "macros.h"
static void sp_pencil_context_class_init(SPPencilContextClass *klass);
static void sp_pencil_context_init(SPPencilContext *pc);
@@ -509,6 +511,13 @@ pencil_handle_key_press(SPPencilContext *const pc, guint const keyval, guint con
}
}
break;
+ case GDK_g:
+ case GDK_G:
+ if (mod_shift_only(state)) {
+ sp_selection_to_guides();
+ ret = true;
+ }
+ break;
default:
break;
}
diff --git a/src/sp-path.cpp b/src/sp-path.cpp
index d97bbddb9..a8e3ad6ee 100644
--- a/src/sp-path.cpp
+++ b/src/sp-path.cpp
@@ -30,6 +30,7 @@
#include "attributes.h"
#include "sp-path.h"
+#include "sp-guide.h"
#include "document.h"
@@ -46,6 +47,7 @@ static void sp_path_set(SPObject *object, unsigned key, gchar const *value);
static Inkscape::XML::Node *sp_path_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
static NR::Matrix sp_path_set_transform(SPItem *item, NR::Matrix const &xform);
static gchar * sp_path_description(SPItem *item);
+static void sp_path_convert_to_guides(SPItem *item);
static void sp_path_update(SPObject *object, SPCtx *ctx, guint flags);
static void sp_path_update_patheffect(SPShape *shape, bool write);
@@ -101,6 +103,7 @@ sp_path_class_init(SPPathClass * klass)
item_class->description = sp_path_description;
item_class->set_transform = sp_path_set_transform;
+ item_class->convert_to_guides = sp_path_convert_to_guides;
shape_class->update_patheffect = sp_path_update_patheffect;
}
@@ -133,6 +136,39 @@ sp_path_description(SPItem * item)
}
}
+static void
+sp_path_convert_to_guides(SPItem *item)
+{
+ SPPath *path = SP_PATH(item);
+
+ SPDocument *doc = SP_OBJECT_DOCUMENT(path);
+ std::list<std::pair<Geom::Point, Geom::Point> > pts;
+
+ NR::Matrix const i2d (sp_item_i2d_affine(SP_ITEM(path)));
+
+ SPCurve *curve = SP_SHAPE(path)->curve;
+ if (!curve) return;
+ NArtBpath *bpath = SP_CURVE_BPATH(curve);
+
+ NR::Point last_pt;
+ NR::Point pt;
+ for (int i = 0; bpath[i].code != NR_END; i++){
+ if (bpath[i].code == NR_LINETO) {
+ /* we only convert straight line segments (converting curve segments would be unintuitive) */
+ pt = bpath[i].c(3) * i2d;
+ pts.push_back(std::make_pair(last_pt.to_2geom(), pt.to_2geom()));
+ }
+
+ /* remember current point for potential reuse in the next step
+ (e.g., in case this was an NR_MOVETO or NR_MOVETO_OPEN) */
+ last_pt = bpath[i].c(3) * i2d;
+ }
+
+ sp_guide_pt_pairs_to_guides(doc, pts);
+
+ SP_OBJECT(path)->deleteObject(true);
+}
+
/**
* Initializes an SPPath.
*/