summaryrefslogtreecommitdiffstats
path: root/src/live_effects
diff options
context:
space:
mode:
authorMaximilian Albert <maximilian.albert@gmail.com>2008-06-12 13:23:17 +0000
committercilix42 <cilix42@users.sourceforge.net>2008-06-12 13:23:17 +0000
commite2ebbb4f9c51fd4d4528899b761afe74f6f4dd42 (patch)
treecf08b1b3a2d345c346a14a2f203dd0e64cc2f174 /src/live_effects
parentPen context can now wait for a specified number of clicks and finish the path... (diff)
downloadinkscape-e2ebbb4f9c51fd4d4528899b761afe74f6f4dd42.tar.gz
inkscape-e2ebbb4f9c51fd4d4528899b761afe74f6f4dd42.zip
Infrastructure in class LivePathEffect::Effect to put Inkscape into 'wait for parameter path' mode; make LPEMirrorReflect use this to let the user specify the mirroring line
(bzr r5902)
Diffstat (limited to 'src/live_effects')
-rw-r--r--src/live_effects/effect.cpp47
-rw-r--r--src/live_effects/effect.h9
-rw-r--r--src/live_effects/lpe-mirror_reflect.cpp22
-rw-r--r--src/live_effects/lpe-mirror_reflect.h3
4 files changed, 66 insertions, 15 deletions
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp
index 0aaedab0a..18d05fe67 100644
--- a/src/live_effects/effect.cpp
+++ b/src/live_effects/effect.cpp
@@ -19,6 +19,10 @@
#include "document-private.h"
#include "xml/document.h"
#include <glibmm/i18n.h>
+#include "pen-context.h"
+#include "tools-switch.h"
+#include "message-stack.h"
+#include "desktop.h"
#include "live_effects/lpeobject.h"
#include "live_effects/parameter/parameter.h"
@@ -183,6 +187,7 @@ Effect::createAndApply(EffectType type, SPDocument *doc, SPItem *item)
Effect::Effect(LivePathEffectObject *lpeobject)
: oncanvasedit_it(0),
is_visible(_("Is visible?"), _("If unchecked, the effect remains applied to the object but is temporarily disabled on canvas"), "is_visible", &wr, this, true),
+ done_pathparam_set(false),
lpeobj(lpeobject),
concatenate_before_pwd2(false)
{
@@ -207,18 +212,48 @@ Effect::effectType() {
return lpeobj->effecttype;
}
+/**
+ * Is performed a single time when the effect is freshly applied to a path
+ */
void
Effect::doOnApply (SPLPEItem */*lpeitem*/)
{
- // This is performed once when the effect is freshly applied to a path
}
+/**
+ * Is performed each time before the effect is updated.
+ */
void
Effect::doBeforeEffect (SPLPEItem */*lpeitem*/)
{
//Do nothing for simple effects
}
+/**
+ * Effects have a parameter path set before they are applied by accepting a nonzero number of mouse
+ * clicks. This method activates the pen context, which waits for the specified number of clicks.
+ * Override Effect::acceptsNumParams() to set the number of expected mouse clicks.
+ */
+void
+Effect::doAcceptPathPreparations(SPLPEItem *lpeitem)
+{
+ // switch to pen context
+ SPDesktop *desktop = inkscape_active_desktop(); // TODO: Is there a better method to find the item's desktop?
+ if (!tools_isactive(desktop, TOOLS_FREEHAND_PEN)) {
+ tools_switch(desktop, TOOLS_FREEHAND_PEN);
+ }
+
+ SPEventContext *ec = desktop->event_context;
+ SPPenContext *pc = SP_PEN_CONTEXT(ec);
+ pc->expecting_clicks_for_LPE = this->acceptsNumParams();
+ pc->waiting_LPE = this;
+ pc->waiting_item = lpeitem;
+ pc->polylines_only = true;
+
+ ec->desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE,
+ g_strdup_printf(_("Please specify a parameter path for the LPE '%s' with %d mouse clicks"),
+ getName().c_str(), acceptsNumParams()));
+}
void
Effect::writeParamsToSVG() {
@@ -228,6 +263,16 @@ Effect::writeParamsToSVG() {
}
}
+/**
+ * If the effect expects a path parameter (specified by a number of mouse clicks) before it is
+ * applied, this is the method that processes the resulting path. Override it to customize it for
+ * your LPE. But don't forget to call the parent method so that done_pathparam_set is set to true!
+ */
+void
+Effect::acceptParamPath (SPPath *param_path) {
+ done_pathparam_set = true;
+}
+
/*
* Here be the doEffect function chain:
*/
diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h
index 665509fd1..f1241c54b 100644
--- a/src/live_effects/effect.h
+++ b/src/live_effects/effect.h
@@ -95,10 +95,16 @@ public:
EffectType effectType ();
virtual void doOnApply (SPLPEItem *lpeitem);
-
virtual void doBeforeEffect (SPLPEItem *lpeitem);
+
void writeParamsToSVG();
+ virtual void acceptParamPath (SPPath *param_path);
+ virtual int acceptsNumParams() { return 0; }
+ void doAcceptPathPreparations(SPLPEItem *lpeitem);
+
+ inline bool pathParamAccepted() { return done_pathparam_set; }
+
virtual void doEffect (SPCurve * curve);
virtual Gtk::Widget * newWidget(Gtk::Tooltips * tooltips);
@@ -148,6 +154,7 @@ protected:
std::vector<std::pair<KnotHolderEntity*, const char*> > kh_entity_vector;
int oncanvasedit_it;
BoolParam is_visible;
+ bool done_pathparam_set;
Inkscape::UI::Widget::Registry wr;
diff --git a/src/live_effects/lpe-mirror_reflect.cpp b/src/live_effects/lpe-mirror_reflect.cpp
index 438d012db..093841c8d 100644
--- a/src/live_effects/lpe-mirror_reflect.cpp
+++ b/src/live_effects/lpe-mirror_reflect.cpp
@@ -38,22 +38,20 @@ LPEMirrorReflect::~LPEMirrorReflect()
}
void
-LPEMirrorReflect::doOnApply (SPLPEItem *lpeitem)
-{
+LPEMirrorReflect::acceptParamPath (SPPath *param_path) {
using namespace Geom;
- SPCurve *curve = sp_path_get_curve_for_edit (SP_PATH(lpeitem));
- Point A(curve->first_point().to_2geom());
- Point B(curve->last_point().to_2geom());
-
- Point M = (2*A + B)/3; // some point between A and B (a bit closer to A)
- Point perp_dir = unit_vector((B - A).ccw());
+ SPCurve* curve = sp_path_get_curve_for_edit (param_path);
+ Geom::Point A(curve->first_point().to_2geom());
+ Geom::Point B(curve->last_point().to_2geom());
- Point C(M[X], M[Y] + 150);
- Point D(M[X], M[Y] - 150);
-
- Piecewise<D2<SBasis> > rline = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(C[X], D[X]), Linear(C[Y], D[Y])));
+ Piecewise<D2<SBasis> > rline = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(A[X], B[X]), Linear(A[Y], B[Y])));
reflection_line.param_set_and_write_new_value(rline);
+
+ SP_OBJECT(param_path)->deleteObject(true);
+
+ // don't remove this; needed for cleanup tasks
+ Effect::acceptParamPath(param_path);
}
std::vector<Geom::Path>
diff --git a/src/live_effects/lpe-mirror_reflect.h b/src/live_effects/lpe-mirror_reflect.h
index 79b1854f8..a19aafb89 100644
--- a/src/live_effects/lpe-mirror_reflect.h
+++ b/src/live_effects/lpe-mirror_reflect.h
@@ -28,7 +28,8 @@ public:
LPEMirrorReflect(LivePathEffectObject *lpeobject);
virtual ~LPEMirrorReflect();
- virtual void doOnApply (SPLPEItem *lpeitem);
+ virtual void acceptParamPath (SPPath *param_path);
+ virtual int acceptsNumParams() { return 2; }
virtual LPEPathFlashType pathFlashType() { return PERMANENT_FLASH; }