summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4ff05d3)
raw | patch | inline | side by side (parent: 4ff05d3)
author | cilix42 <cilix42@users.sourceforge.net> | |
Mon, 18 Aug 2008 00:47:13 +0000 (00:47 +0000) | ||
committer | cilix42 <cilix42@users.sourceforge.net> | |
Mon, 18 Aug 2008 00:47:13 +0000 (00:47 +0000) |
index 7c1cb9f3edda226a299597ed496329c6113a7f55..fee3607e16b8080fdad5beadf9684f517c1722e6 100644 (file)
*/
#include "live_effects/lpe-line_segment.h"
+#include "lpe-tool-context.h"
#include <2geom/pathvector.h>
#include <2geom/geom.h>
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");
}
Geom::Path path(A);
- path.appendNew<Geom::LineSegment>(B);
+ path.appendNew<LineSegment>(B);
output.push_back(path);
index a64eea4cbc1a753e856b2720fb7f447131e3e82e..ed57d17fe277d6553ed1452f581807fee27b0897 100644 (file)
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&);
index 0b3fb25bf01d6c7739eab44a3f129c980dfdb401..af92074b050306472597eedc48cd4c7be7350afc 100644 (file)
--- 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
*/
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 5ee66dbadb0f5c3b1a3d5ce59d4e5af2b35d8205..8f46b3041297f7b7a4975898543666adb6d2b40e 100644 (file)
--- a/src/lpe-tool-context.h
+++ b/src/lpe-tool-context.h
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);
index 5676529c3c81e19dd9fe2a86083e092d98c72da9..9f8cf18221d727aa412d0fc16649fbe26b27334d 100644 (file)
--- a/src/widgets/toolbox.cpp
+++ b/src/widgets/toolbox.cpp
" <toolitem action='LPEToolModeAction' />"
" <separator />"
" <toolitem action='LPEShowBBoxAction' />"
+ " <toolitem action='LPEBBoxFromSelectionAction' />"
" <separator />"
" <toolitem action='LPELineSegmentAction' />"
" </toolbar>"
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);
}
}
+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)
{
@@ -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);