summaryrefslogtreecommitdiffstats
path: root/src/live_effects/parameter/point.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/live_effects/parameter/point.cpp')
-rw-r--r--src/live_effects/parameter/point.cpp100
1 files changed, 67 insertions, 33 deletions
diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp
index 302818e55..4c4d2cd9c 100644
--- a/src/live_effects/parameter/point.cpp
+++ b/src/live_effects/parameter/point.cpp
@@ -26,7 +26,9 @@ namespace LivePathEffect {
PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip,
const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
Effect* effect, const gchar *htip, Geom::Point default_value)
- : Geom::Point(default_value), Parameter(label, tip, key, wr, effect), defvalue(default_value)
+ : Parameter(label, tip, key, wr, effect),
+ defvalue(default_value),
+ knoth(NULL)
{
knot_shape = SP_KNOT_SHAPE_DIAMOND;
knot_mode = SP_KNOT_MODE_XOR;
@@ -43,7 +45,34 @@ PointParam::~PointParam()
void
PointParam::param_set_default()
{
- param_setValue(defvalue);
+ param_setValue(defvalue,true);
+}
+
+Geom::Point
+PointParam::param_get_default() const{
+ return defvalue;
+}
+
+void
+PointParam::param_update_default(Geom::Point newpoint)
+{
+ defvalue = newpoint;
+}
+
+void
+PointParam::param_setValue(Geom::Point newpoint, bool write)
+{
+ *dynamic_cast<Geom::Point *>( this ) = newpoint;
+ if(write){
+ Inkscape::SVGOStringStream os;
+ os << newpoint;
+ gchar * str = g_strdup(os.str().c_str());
+ param_write_to_repr(str);
+ g_free(str);
+ }
+ if(knoth){
+ knoth->update_knots();
+ }
}
bool
@@ -70,6 +99,12 @@ PointParam::param_getSVGValue() const
return str;
}
+void
+PointParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/)
+{
+ param_setValue( (*this) * postmul, true);
+}
+
Gtk::Widget *
PointParam::param_newWidget()
{
@@ -96,29 +131,6 @@ PointParam::param_newWidget()
}
void
-PointParam::param_setValue(Geom::Point newpoint)
-{
- *dynamic_cast<Geom::Point *>( this ) = newpoint;
-}
-
-void
-PointParam::param_set_and_write_new_value (Geom::Point newpoint)
-{
- Inkscape::SVGOStringStream os;
- os << newpoint;
- gchar * str = g_strdup(os.str().c_str());
- param_write_to_repr(str);
- g_free(str);
-}
-
-void
-PointParam::param_transform_multiply(Geom::Affine const& postmul, bool /*set*/)
-{
- param_set_and_write_new_value( (*this) * postmul );
-}
-
-
-void
PointParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint32 color)
{
knot_shape = shape;
@@ -129,7 +141,7 @@ PointParam::set_oncanvas_looks(SPKnotShapeType shape, SPKnotModeType mode, guint
class PointParamKnotHolderEntity : public KnotHolderEntity {
public:
PointParamKnotHolderEntity(PointParam *p) { this->pparam = p; }
- virtual ~PointParamKnotHolderEntity() {}
+ virtual ~PointParamKnotHolderEntity() { this->pparam->knoth = NULL;}
virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
virtual Geom::Point knot_get() const;
@@ -140,11 +152,25 @@ private:
};
void
-PointParamKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
+PointParamKnotHolderEntity::knot_set(Geom::Point const &p, Geom::Point const &origin, guint state)
{
- Geom::Point const s = snap_knot_position(p, state);
- pparam->param_setValue(s);
- sp_lpe_item_update_patheffect(SP_LPE_ITEM(item), false, false);
+ Geom::Point s = snap_knot_position(p, state);
+ if (state & GDK_CONTROL_MASK) {
+ Geom::Point A(origin[Geom::X],p[Geom::Y]);
+ Geom::Point B(p[Geom::X],origin[Geom::Y]);
+ double distanceA = Geom::distance(A,p);
+ double distanceB = Geom::distance(B,p);
+ if(distanceA > distanceB){
+ s = B;
+ } else {
+ s = A;
+ }
+ }
+ pparam->param_setValue(s, true);
+ SPLPEItem * splpeitem = dynamic_cast<SPLPEItem *>(item);
+ if(splpeitem){
+ sp_lpe_item_update_patheffect(splpeitem, false, false);
+ }
}
Geom::Point
@@ -154,19 +180,27 @@ PointParamKnotHolderEntity::knot_get() const
}
void
-PointParamKnotHolderEntity::knot_click(guint /*state*/)
+PointParamKnotHolderEntity::knot_click(guint state)
{
- g_print ("This is the handle associated to parameter '%s'\n", pparam->param_key.c_str());
+ if (state & GDK_CONTROL_MASK) {
+ if (state & GDK_MOD1_MASK) {
+ this->pparam->param_set_default();
+ SPLPEItem * splpeitem = dynamic_cast<SPLPEItem *>(item);
+ if(splpeitem){
+ sp_lpe_item_update_patheffect(splpeitem, false, false);
+ }
+ }
+ }
}
void
PointParam::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item)
{
+ knoth = knotholder;
PointParamKnotHolderEntity *e = new PointParamKnotHolderEntity(this);
// TODO: can we ditch handleTip() etc. because we have access to handle_tip etc. itself???
e->create(desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN, handleTip(), knot_shape, knot_mode, knot_color);
knotholder->add(e);
-
}
} /* namespace LivePathEffect */