summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/live_effects/lpe-line_segment.cpp20
-rw-r--r--src/live_effects/lpe-line_segment.h2
-rw-r--r--src/lpe-tool-context.cpp23
-rw-r--r--src/lpe-tool-context.h1
-rw-r--r--src/widgets/toolbox.cpp43
5 files changed, 70 insertions, 19 deletions
diff --git a/src/live_effects/lpe-line_segment.cpp b/src/live_effects/lpe-line_segment.cpp
index 7c1cb9f3e..fee3607e1 100644
--- a/src/live_effects/lpe-line_segment.cpp
+++ b/src/live_effects/lpe-line_segment.cpp
@@ -14,6 +14,7 @@
*/
#include "live_effects/lpe-line_segment.h"
+#include "lpe-tool-context.h"
#include <2geom/pathvector.h>
#include <2geom/geom.h>
@@ -46,26 +47,19 @@ LPELineSegment::~LPELineSegment()
void
LPELineSegment::doBeforeEffect (SPLPEItem *lpeitem)
{
- SPDocument *document = SP_OBJECT_DOCUMENT(lpeitem);
- w = sp_document_width(document);
- h = sp_document_height(document);
-
+ lpetool_get_limiting_bbox_corners(SP_OBJECT_DOCUMENT(lpeitem), bboxA, bboxB);
}
std::vector<Geom::Path>
LPELineSegment::doEffect_path (std::vector<Geom::Path> const & path_in)
{
+ using namespace Geom;
std::vector<Geom::Path> output;
- A = Geom::initialPoint(path_in);
- B = Geom::finalPoint(path_in);
+ A = initialPoint(path_in);
+ B = finalPoint(path_in);
- Geom::Point E(0,0);
- Geom::Point F(0,h);
- Geom::Point G(w,h);
- Geom::Point H(w,0);
-
- std::vector<Geom::Point> intersections = Geom::rect_line_intersect(E, G, A, B);
+ std::vector<Point> intersections = rect_line_intersect(bboxA, bboxB, A, B);
if (intersections.size() < 2) {
g_print ("Possible error - no intersection with limiting bounding box.\n");
@@ -81,7 +75,7 @@ LPELineSegment::doEffect_path (std::vector<Geom::Path> const & path_in)
}
Geom::Path path(A);
- path.appendNew<Geom::LineSegment>(B);
+ path.appendNew<LineSegment>(B);
output.push_back(path);
diff --git a/src/live_effects/lpe-line_segment.h b/src/live_effects/lpe-line_segment.h
index a64eea4cb..ed57d17fe 100644
--- a/src/live_effects/lpe-line_segment.h
+++ b/src/live_effects/lpe-line_segment.h
@@ -41,7 +41,7 @@ public:
private:
Geom::Point A, B; // intersections of the line segment with the limiting bounding box
- Geom::Coord w, h; // document width and height
+ Geom::Point bboxA, bboxB; // upper left and lower right corner of limiting bounding box
LPELineSegment(const LPELineSegment&);
LPELineSegment& operator=(const LPELineSegment&);
diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp
index 0b3fb25bf..af92074b0 100644
--- a/src/lpe-tool-context.cpp
+++ b/src/lpe-tool-context.cpp
@@ -374,6 +374,20 @@ lpetool_context_switch_mode(SPLPEToolContext *lc, Inkscape::LivePathEffect::Effe
}
}
+void
+lpetool_get_limiting_bbox_corners(SPDocument *document, Geom::Point &A, Geom::Point &B) {
+ Geom::Coord w = sp_document_width(document);
+ Geom::Coord h = sp_document_height(document);
+
+ double ulx = prefs_get_double_attribute ("tools.lpetool", "bbox_upperleftx", 0);
+ double uly = prefs_get_double_attribute ("tools.lpetool", "bbox_upperlefty", 0);
+ double lrx = prefs_get_double_attribute ("tools.lpetool", "bbox_lowerrightx", w);
+ double lry = prefs_get_double_attribute ("tools.lpetool", "bbox_lowerrighty", h);
+
+ A = Geom::Point(ulx, uly);
+ B = Geom::Point(lrx, lry);
+}
+
/*
* Reads the limiting bounding box from preferences and draws it on the screen
*/
@@ -390,11 +404,12 @@ lpetool_context_reset_limiting_bbox(SPLPEToolContext *lc)
return;
SPDocument *document = sp_desktop_document(lc->desktop);
- Geom::Coord w = sp_document_width(document);
- Geom::Coord h = sp_document_height(document);
- Geom::Point A(0,0);
- Geom::Point B(w,h);
+ Geom::Point A, B;
+ lpetool_get_limiting_bbox_corners(document, A, B);
+ NR::Matrix doc2dt(lc->desktop->doc2dt());
+ A *= doc2dt;
+ B *= doc2dt;
Geom::Rect rect(A, B);
SPCurve *curve = SPCurve::new_from_rect(rect);
diff --git a/src/lpe-tool-context.h b/src/lpe-tool-context.h
index 5ee66dbad..8f46b3041 100644
--- a/src/lpe-tool-context.h
+++ b/src/lpe-tool-context.h
@@ -52,6 +52,7 @@ int lpetool_mode_to_index(Inkscape::LivePathEffect::EffectType const type);
int lpetool_item_has_construction(SPLPEToolContext *lc, SPItem *item);
bool lpetool_try_construction(SPLPEToolContext *lc, Inkscape::LivePathEffect::EffectType const type);
void lpetool_context_switch_mode(SPLPEToolContext *lc, Inkscape::LivePathEffect::EffectType const type);
+void lpetool_get_limiting_bbox_corners(SPDocument *document, Geom::Point &A, Geom::Point &B);
void lpetool_context_reset_limiting_bbox(SPLPEToolContext *lc);
GType sp_lpetool_context_get_type(void);
diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp
index 5676529c3..9f8cf1822 100644
--- a/src/widgets/toolbox.cpp
+++ b/src/widgets/toolbox.cpp
@@ -446,6 +446,7 @@ static gchar const * ui_descr =
" <toolitem action='LPEToolModeAction' />"
" <separator />"
" <toolitem action='LPEShowBBoxAction' />"
+ " <toolitem action='LPEBBoxFromSelectionAction' />"
" <separator />"
" <toolitem action='LPELineSegmentAction' />"
" </toolbar>"
@@ -4849,7 +4850,7 @@ sp_lpetool_toolbox_sel_changed(Inkscape::Selection *selection, GObject *tbl)
g_object_set_data(tbl, "currentlpe", lpe);
g_object_set_data(tbl, "currentlpeitem", lpeitem);
gtk_action_set_sensitive(w, TRUE);
- ege_select_one_action_set_active(act, lpels->end_type->get_value());
+ ege_select_one_action_set_active(EGE_SELECT_ONE_ACTION(w), lpels->end_type.get_value());
} else {
g_print (" - unsetting item\n");
g_object_set_data(tbl, "currentlpe", NULL);
@@ -4880,6 +4881,33 @@ lpetool_toggle_show_bbox (GtkToggleAction *act, gpointer data) {
}
static void
+lpetool_toggle_set_bbox (GtkToggleAction *act, gpointer data) {
+ g_print ("lpetool_toggle_set_bbox()\n");
+ SPDesktop *desktop = static_cast<SPDesktop *>(data);
+ Inkscape::Selection *selection = desktop->selection;
+
+ boost::optional<NR::Rect> bbox = selection->bounds();
+
+ if (bbox) {
+ Geom::Point A(bbox->min());
+ Geom::Point B(bbox->max());
+
+ A *= desktop->doc2dt();
+ B *= desktop->doc2dt();
+
+ // TODO: should we provide a way to store points in prefs?
+ prefs_set_double_attribute ("tools.lpetool", "bbox_upperleftx", A[Geom::X]);
+ prefs_set_double_attribute ("tools.lpetool", "bbox_upperlefty", A[Geom::Y]);
+ prefs_set_double_attribute ("tools.lpetool", "bbox_lowerrightx", B[Geom::X]);
+ prefs_set_double_attribute ("tools.lpetool", "bbox_lowerrighty", B[Geom::Y]);
+
+ lpetool_context_reset_limiting_bbox(SP_LPETOOL_CONTEXT(desktop->event_context));
+ }
+
+ gtk_toggle_action_set_active(act, false);
+}
+
+static void
sp_line_segment_build_list(GObject *tbl)
{
g_object_set_data(tbl, "line_segment_list_blocked", GINT_TO_POINTER(TRUE));
@@ -4991,6 +5019,19 @@ static void sp_lpetool_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActi
gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs_get_int_attribute( "tools.lpetool", "show_bbox", 1 ) );
}
+ /* Set limiting bounding box to bbox of current selection */
+ {
+ InkToggleAction* act = ink_toggle_action_new( "LPEBBoxFromSelectionAction",
+ _("Get limiting bounding box from selection"),
+ _("Set limiting bounding box (used to cut infinite lines) to the bounding box of current selection"),
+ "lpetool_set_bbox",
+ Inkscape::ICON_SIZE_DECORATION );
+ gtk_action_group_add_action( mainActions, GTK_ACTION( act ) );
+ g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(lpetool_toggle_set_bbox), desktop );
+ gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), FALSE );
+ }
+
+
/* Combo box to choose line segment type */
{
GtkListStore* model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);