From 1102c044647a145bf6530fd0a649258b8a95f82a Mon Sep 17 00:00:00 2001 From: Johan Date: Sun, 14 Feb 2010 22:56:16 +0100 Subject: [PATCH] add widget controls for LPE VectorParam. Hide these controls for LPE Hatches. --- src/live_effects/lpe-rough-hatches.cpp | 4 ++ src/live_effects/parameter/vector.cpp | 30 ++++----- src/ui/widget/labelled.h | 2 + src/ui/widget/point.cpp | 2 +- src/ui/widget/point.h | 2 +- src/ui/widget/registered-widget.cpp | 90 ++++++++++++++++++++++++++ src/ui/widget/registered-widget.h | 25 +++++++ 7 files changed, 136 insertions(+), 19 deletions(-) diff --git a/src/live_effects/lpe-rough-hatches.cpp b/src/live_effects/lpe-rough-hatches.cpp index 228857ebf..f110aa743 100644 --- a/src/live_effects/lpe-rough-hatches.cpp +++ b/src/live_effects/lpe-rough-hatches.cpp @@ -279,6 +279,10 @@ LPERoughHatches::LPERoughHatches(LivePathEffectObject *lpeobject) : front_thickness.param_set_range(0, NR_HUGE); back_thickness.param_set_range(0, NR_HUGE); + // hide the widgets for direction and bender vectorparams + direction.widget_is_visible = false; + bender.widget_is_visible = false; + concatenate_before_pwd2 = false; show_orig_path = true; } diff --git a/src/live_effects/parameter/vector.cpp b/src/live_effects/parameter/vector.cpp index 35afe7f5d..5496b52f2 100644 --- a/src/live_effects/parameter/vector.cpp +++ b/src/live_effects/parameter/vector.cpp @@ -13,8 +13,9 @@ #include "svg/stringstream.h" #include -// needed for on-canvas editting: -class SPDesktop; +#include "ui/widget/registered-widget.h" +#include "live_effects/effect.h" +#include "desktop.h" namespace Inkscape { @@ -82,28 +83,23 @@ VectorParam::param_getSVGValue() const Gtk::Widget * VectorParam::param_newWidget(Gtk::Tooltips * /*tooltips*/) { -/* - Inkscape::UI::Widget::RegisteredTransformedPoint * pointwdg = Gtk::manage( - new Inkscape::UI::Widget::RegisteredTransformedPoint( param_label, - param_tooltip, - param_key, - *param_wr, - param_effect->getRepr(), - param_effect->getSPDoc() ) ); - // TODO: fix to get correct desktop (don't use SP_ACTIVE_DESKTOP) - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Geom::Matrix transf = desktop->doc2dt(); - pointwdg->setTransform(transf); - pointwdg->setValue( *this ); + Inkscape::UI::Widget::RegisteredVector * pointwdg = Gtk::manage( + new Inkscape::UI::Widget::RegisteredVector( param_label, + param_tooltip, + param_key, + *param_wr, + param_effect->getRepr(), + param_effect->getSPDoc() ) ); + pointwdg->setPolarCoords(); + pointwdg->setValue( vector, origin ); pointwdg->clearProgrammatically(); - pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter")); + pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change vector parameter")); Gtk::HBox * hbox = Gtk::manage( new Gtk::HBox() ); static_cast(hbox)->pack_start(*pointwdg, true, true); static_cast(hbox)->show_all_children(); return dynamic_cast (hbox); - */ return NULL; } void diff --git a/src/ui/widget/labelled.h b/src/ui/widget/labelled.h index 3685944a4..5670af0b6 100644 --- a/src/ui/widget/labelled.h +++ b/src/ui/widget/labelled.h @@ -39,6 +39,8 @@ public: Gtk::Widget const *getWidget() const; Gtk::Label const *getLabel() const; + void setLabelText(const Glib::ustring &str) { _label->set_text(str); }; + protected: Gtk::Widget *_widget; Gtk::Label *_label; diff --git a/src/ui/widget/point.cpp b/src/ui/widget/point.cpp index 508a8d961..f27cfe8c6 100644 --- a/src/ui/widget/point.cpp +++ b/src/ui/widget/point.cpp @@ -194,7 +194,7 @@ Point::setRange(double min, double max) /** Sets the value of the spin button */ void -Point::setValue(Geom::Point & p) +Point::setValue(Geom::Point const & p) { xwidget.setValue(p[0]); ywidget.setValue(p[1]); diff --git a/src/ui/widget/point.h b/src/ui/widget/point.h index 57a46de76..94477d877 100644 --- a/src/ui/widget/point.h +++ b/src/ui/widget/point.h @@ -64,7 +64,7 @@ public: void setDigits(unsigned digits); void setIncrements(double step, double page); void setRange(double min, double max); - void setValue(Geom::Point & p); + void setValue(Geom::Point const & p); void update(); diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index 95ddec286..db31d08d3 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -586,6 +586,96 @@ RegisteredTransformedPoint::on_value_changed() _wr->setUpdating (false); } +/*######################################### + * Registered TRANSFORMEDPOINT + */ + +RegisteredVector::~RegisteredVector() +{ + _value_x_changed_connection.disconnect(); + _value_y_changed_connection.disconnect(); +} + +RegisteredVector::RegisteredVector ( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, + SPDocument* doc_in ) + : RegisteredWidget (label, tip), + _polar_coords(false) +{ + init_parent(key, wr, repr_in, doc_in); + + setRange (-1e6, 1e6); + setDigits (2); + setIncrements(0.1, 1.0); + _value_x_changed_connection = signal_x_value_changed().connect (sigc::mem_fun (*this, &RegisteredVector::on_value_changed)); + _value_y_changed_connection = signal_y_value_changed().connect (sigc::mem_fun (*this, &RegisteredVector::on_value_changed)); +} + +void +RegisteredVector::setValue(Geom::Point const & p) +{ + if (!_polar_coords) { + Point::setValue(p); + } else { + Geom::Point polar; + polar[Geom::X] = atan2(p) *180/M_PI; + polar[Geom::Y] = p.length(); + Point::setValue(polar); + } +} + +void +RegisteredVector::setValue(Geom::Point const & p, Geom::Point const & origin) +{ + RegisteredVector::setValue(p); + _origin = origin; +} + +/** + * Changes the widgets text to polar coordinates. The SVG output will still be a normal carthesian vector. + * Careful: when calling getValue(), the return value's X-coord will be the angle, Y-value will be the distance/length. + * After changing the coords type (polar/non-polar), the value has to be reset (setValue). + */ +void +RegisteredVector::setPolarCoords(bool polar_coords) +{ + _polar_coords = polar_coords; + if (polar_coords) { + xwidget.setLabelText("Angle:"); + ywidget.setLabelText("Distance:"); + } else { + xwidget.setLabelText("X:"); + ywidget.setLabelText("Y:"); + } +} + +void +RegisteredVector::on_value_changed() +{ + if (setProgrammatically()) { + clearProgrammatically(); + return; + } + + if (_wr->isUpdating()) + return; + + _wr->setUpdating (true); + + Geom::Point origin = _origin; + Geom::Point vector = getValue(); + if (_polar_coords) { + vector = Geom::Point::polar(vector[Geom::X]*M_PI/180, vector[Geom::Y]); + } + + Inkscape::SVGOStringStream os; + os << origin << " , " << vector; + + write_to_xml(os.str().c_str()); + + _wr->setUpdating (false); +} + /*######################################### * Registered RANDOM */ diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index a5c61f68a..7aefbb90e 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -334,6 +334,31 @@ protected: }; +class RegisteredVector : public RegisteredWidget { +public: + virtual ~RegisteredVector(); + RegisteredVector (const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Registry& wr, + Inkscape::XML::Node* repr_in = NULL, + SPDocument *doc_in = NULL ); + + // redefine setValue, because transform must be applied + void setValue(Geom::Point const & p); + void setValue(Geom::Point const & p, Geom::Point const & origin); + void setPolarCoords(bool polar_coords = true); + +protected: + sigc::connection _value_x_changed_connection; + sigc::connection _value_y_changed_connection; + void on_value_changed(); + + Geom::Point _origin; + bool _polar_coords; +}; + + class RegisteredRandom : public RegisteredWidget { public: virtual ~RegisteredRandom(); -- 2.30.2