diff options
| author | schwieni <mschwienbacher@gmail.com> | 2019-03-24 09:14:33 +0000 |
|---|---|---|
| committer | Markus Schwienbacher <mschwienbacher@gmail.com> | 2019-03-25 17:15:50 +0000 |
| commit | 2d2c778340997b1d4370bb583e40a0e8dbebfc57 (patch) | |
| tree | 40727666a7aced4425ebd557a659a8f31041846c /src | |
| parent | lpe-pts2ellipse: added perspective circle from 4 points (diff) | |
| download | inkscape-2d2c778340997b1d4370bb583e40a0e8dbebfc57.tar.gz inkscape-2d2c778340997b1d4370bb583e40a0e8dbebfc57.zip | |
lpe-pts2ellipse: added perspective circle from 4 points
improved tool-tips for better usability
Diffstat (limited to 'src')
| -rw-r--r-- | src/live_effects/lpe-pts2ellipse.cpp | 24 | ||||
| -rw-r--r-- | src/live_effects/parameter/parameter.cpp | 122 | ||||
| -rw-r--r-- | src/live_effects/parameter/parameter.h | 102 |
3 files changed, 112 insertions, 136 deletions
diff --git a/src/live_effects/lpe-pts2ellipse.cpp b/src/live_effects/lpe-pts2ellipse.cpp index e87b731b7..0e972c68e 100644 --- a/src/live_effects/lpe-pts2ellipse.cpp +++ b/src/live_effects/lpe-pts2ellipse.cpp @@ -49,17 +49,29 @@ static const Util::EnumDataConverter<EllipseMethod> EMConverter(EllipseMethodDat LPEPts2Ellipse::LPEPts2Ellipse(LivePathEffectObject *lpeobject) : Effect(lpeobject) - , method(_("Method:"), _("Methods to generate the ellipse\n- Auto ellipse: fits a circle (2..4 points) or an ellipse (at least 5 points)\n- Force circle: (at least 2 points) always fit to a circle\n- Isometric circle: (3 points) use first two edges\n- Perspective circle: (4 points) circle in a square in perspective view\n- Steiner ellipse: (3 points) ellipse on a triangle\n- Steiner inellipse: (3 points) ellipse inside a triangle"), "method", EMConverter, &wr, this, EM_AUTO) + , method( + _("Method:"), + _("Methods to generate the ellipse\n- Auto ellipse: fits a circle (2..4 points) or an ellipse (at least 5 " + "points)\n- Force circle: (at least 2 points) always fit to a circle\n- Isometric circle: (3 points) use " + "first two edges\n- Perspective circle: (4 points) circle in a square in perspective view\n- Steiner " + "ellipse: (3 points) ellipse on a triangle\n- Steiner inellipse: (3 points) ellipse inside a triangle"), + "method", EMConverter, &wr, this, EM_AUTO) , gen_isometric_frame(_("_Frame (isometric rectangle)"), _("Draw parallelogram around the ellipse"), "gen_isometric_frame", &wr, this, false) - , gen_perspective_frame(_("_Perspective square"), _("Draw square surrounding the circle in perspective view\n(only in method \"Perspective circle\")"), - "gen_perspective_frame", &wr, this, false) - , gen_arc(_("_Arc"), _("Generate open arc (open ellipse) based on first and last point\n(only for methods \"Auto ellipse\" and \"Force circle\")"), "gen_arc", &wr, this, false) + , gen_perspective_frame( + _("_Perspective square"), + _("Draw square surrounding the circle in perspective view\n(only in method \"Perspective circle\")"), + "gen_perspective_frame", &wr, this, false) + , gen_arc(_("_Arc"), + _("Generate open arc (open ellipse) based on first and last point\n(only for methods \"Auto ellipse\" " + "and \"Force circle\")"), + "gen_arc", &wr, this, false) , other_arc(_("_Other arc side"), _("Switch sides of the arc"), "arc_other", &wr, this, false) , slice_arc(_("_Slice arc"), _("Slice the arc"), "slice_arc", &wr, this, false) , draw_axes(_("A_xes"), _("Draw both semi-major and semi-minor axes"), "draw_axes", &wr, this, false) - , draw_perspective_axes(_("Perspective axes"), _("Draw the axes in perspective view\n(only in method \"Perspective circle\")"), "draw_perspective_axes", &wr, - this, false) + , draw_perspective_axes(_("Perspective axes"), + _("Draw the axes in perspective view\n(only in method \"Perspective circle\")"), + "draw_perspective_axes", &wr, this, false) , rot_axes(_("Axes rotation"), _("Axes rotation angle [deg]"), "rot_axes", &wr, this, 0) , draw_ori_path(_("Source _path"), _("Show the original source path"), "draw_ori_path", &wr, this, false) { diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index a235e6076..50137ec36 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -6,8 +6,8 @@ */ -#include "live_effects/effect.h" #include "live_effects/parameter/parameter.h" +#include "live_effects/effect.h" #include "svg/svg.h" #include "xml/repr.h" @@ -26,29 +26,27 @@ namespace Inkscape { namespace LivePathEffect { -Parameter::Parameter( Glib::ustring label, Glib::ustring tip, - Glib::ustring key, Inkscape::UI::Widget::Registry* wr, - Effect* effect ) - : param_key(std::move(key)), - param_wr(wr), - param_label(std::move(label)), - oncanvas_editable(false), - widget_is_visible(true), - widget_is_enabled(true), - param_tooltip(std::move(tip)), - param_effect(effect) +Parameter::Parameter(Glib::ustring label, Glib::ustring tip, Glib::ustring key, Inkscape::UI::Widget::Registry *wr, + Effect *effect) + : param_key(std::move(key)) + , param_wr(wr) + , param_label(std::move(label)) + , oncanvas_editable(false) + , widget_is_visible(true) + , widget_is_enabled(true) + , param_tooltip(std::move(tip)) + , param_effect(effect) { } -void -Parameter::param_write_to_repr(const char * svgd) +void Parameter::param_write_to_repr(const char *svgd) { param_effect->getRepr()->setAttribute(param_key.c_str(), svgd); } void Parameter::write_to_SVG() { - gchar * str = param_getSVGValue(); + gchar *str = param_getSVGValue(); param_write_to_repr(str); g_free(str); } @@ -56,28 +54,25 @@ void Parameter::write_to_SVG() /*########################################### * REAL PARAM */ -ScalarParam::ScalarParam( const Glib::ustring& label, const Glib::ustring& tip, - const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, gdouble default_value) - : Parameter(label, tip, key, wr, effect), - value(default_value), - min(-SCALARPARAM_G_MAXDOUBLE), - max(SCALARPARAM_G_MAXDOUBLE), - integer(false), - defvalue(default_value), - digits(2), - inc_step(0.1), - inc_page(1), - add_slider(false), - _set_undo(true) +ScalarParam::ScalarParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, + Inkscape::UI::Widget::Registry *wr, Effect *effect, gdouble default_value) + : Parameter(label, tip, key, wr, effect) + , value(default_value) + , min(-SCALARPARAM_G_MAXDOUBLE) + , max(SCALARPARAM_G_MAXDOUBLE) + , integer(false) + , defvalue(default_value) + , digits(2) + , inc_step(0.1) + , inc_page(1) + , add_slider(false) + , _set_undo(true) { } -ScalarParam::~ScalarParam() -= default; +ScalarParam::~ScalarParam() = default; -bool -ScalarParam::param_readSVGValue(const gchar * strvalue) +bool ScalarParam::param_readSVGValue(const gchar *strvalue) { double newval; unsigned int success = sp_svg_number_read_d(strvalue, &newval); @@ -88,36 +83,25 @@ ScalarParam::param_readSVGValue(const gchar * strvalue) return false; } -gchar * -ScalarParam::param_getSVGValue() const +gchar *ScalarParam::param_getSVGValue() const { Inkscape::SVGOStringStream os; os << value; return g_strdup(os.str().c_str()); } -gchar * -ScalarParam::param_getDefaultSVGValue() const +gchar *ScalarParam::param_getDefaultSVGValue() const { Inkscape::SVGOStringStream os; os << defvalue; - return g_strdup(os.str().c_str()); + return g_strdup(os.str().c_str()); } -void -ScalarParam::param_set_default() -{ - param_set_value(defvalue); -} +void ScalarParam::param_set_default() { param_set_value(defvalue); } -void -ScalarParam::param_update_default(gdouble default_value) -{ - defvalue = default_value; -} +void ScalarParam::param_update_default(gdouble default_value) { defvalue = default_value; } -void -ScalarParam::param_update_default(const gchar * default_value) +void ScalarParam::param_update_default(const gchar *default_value) { double newval; unsigned int success = sp_svg_number_read_d(default_value, &newval); @@ -126,8 +110,7 @@ ScalarParam::param_update_default(const gchar * default_value) } } -void -ScalarParam::param_set_value(gdouble val) +void ScalarParam::param_set_value(gdouble val) { value = val; if (integer) @@ -138,8 +121,7 @@ ScalarParam::param_set_value(gdouble val) value = min; } -void -ScalarParam::param_set_range(gdouble min, gdouble max) +void ScalarParam::param_set_range(gdouble min, gdouble max) { // if you look at client code, you'll see that many effects // has a tendency to set an upper range of Geom::infinity(). @@ -159,8 +141,7 @@ ScalarParam::param_set_range(gdouble min, gdouble max) param_set_value(value); // reset value to see whether it is in ranges } -void -ScalarParam::param_make_integer(bool yes) +void ScalarParam::param_make_integer(bool yes) { integer = yes; digits = 0; @@ -168,19 +149,14 @@ ScalarParam::param_make_integer(bool yes) inc_page = 10; } -void -ScalarParam::param_set_undo(bool set_undo) -{ - _set_undo = set_undo; -} +void ScalarParam::param_set_undo(bool set_undo) { _set_undo = set_undo; } -Gtk::Widget * -ScalarParam::param_newWidget() +Gtk::Widget *ScalarParam::param_newWidget() { if (widget_is_visible) { - Inkscape::UI::Widget::RegisteredScalar *rsu = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( - param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc() ) ); - + Inkscape::UI::Widget::RegisteredScalar *rsu = Gtk::manage(new Inkscape::UI::Widget::RegisteredScalar( + param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc())); + rsu->setValue(value); rsu->setDigits(digits); rsu->setIncrements(inc_step, inc_page); @@ -189,23 +165,18 @@ ScalarParam::param_newWidget() if (add_slider) { rsu->addSlider(); } - if(_set_undo){ + if (_set_undo) { rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); } - return dynamic_cast<Gtk::Widget *> (rsu); + return dynamic_cast<Gtk::Widget *>(rsu); } else { return nullptr; } } -void -ScalarParam::param_set_digits(unsigned digits) -{ - this->digits = digits; -} +void ScalarParam::param_set_digits(unsigned digits) { this->digits = digits; } -void -ScalarParam::param_set_increments(double step, double page) +void ScalarParam::param_set_increments(double step, double page) { inc_step = step; inc_page = page; @@ -213,7 +184,6 @@ ScalarParam::param_set_increments(double step, double page) - } /* namespace LivePathEffect */ } /* namespace Inkscape */ diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 62684b730..b3cbc039e 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -10,17 +10,18 @@ * Released under GNU GPL v2+, read the file 'COPYING' for more information. */ -#include <glibmm/ustring.h> +#include "ui/widget/registered-widget.h" #include <2geom/forward.h> #include <2geom/pathvector.h> -#include "ui/widget/registered-widget.h" +#include <glibmm/ustring.h> // In gtk2, this wasn't an issue; we could toss around // G_MAXDOUBLE and not worry about size allocations. But // in gtk3, it is an issue: it allocates widget size for the maxmium // value you pass to it, leading to some insane lengths. // If you need this to be more, please be conservative about it. -const double SCALARPARAM_G_MAXDOUBLE = 10000000000.0; // TODO fixme: using an arbitrary large number as a magic value seems fragile. +const double SCALARPARAM_G_MAXDOUBLE = + 10000000000.0; // TODO fixme: using an arbitrary large number as a magic value seems fragile. class KnotHolder; class SPLPEItem; @@ -28,97 +29,90 @@ class SPDesktop; class SPItem; namespace Gtk { - class Widget; +class Widget; } namespace Inkscape { namespace NodePath { - class Path ; +class Path; } namespace UI { namespace Widget { - class Registry; -} +class Registry; } +} // namespace UI namespace LivePathEffect { class Effect; class Parameter { -public: - Parameter( Glib::ustring label, - Glib::ustring tip, - Glib::ustring key, - Inkscape::UI::Widget::Registry* wr, - Effect* effect); - virtual ~Parameter() = default;; - - Parameter(const Parameter&) = delete; - Parameter& operator=(const Parameter&) = delete; - - virtual bool param_readSVGValue(const gchar * strvalue) = 0; // returns true if new value is valid / accepted. - virtual gchar * param_getSVGValue() const = 0; - virtual gchar * param_getDefaultSVGValue() const = 0; - virtual void param_widget_is_visible(bool is_visible) {widget_is_visible = is_visible;} - virtual void param_widget_is_enabled(bool is_enabled) {widget_is_enabled = is_enabled;} + public: + Parameter(Glib::ustring label, Glib::ustring tip, Glib::ustring key, Inkscape::UI::Widget::Registry *wr, + Effect *effect); + virtual ~Parameter() = default; + ; + + Parameter(const Parameter &) = delete; + Parameter &operator=(const Parameter &) = delete; + + virtual bool param_readSVGValue(const gchar *strvalue) = 0; // returns true if new value is valid / accepted. + virtual gchar *param_getSVGValue() const = 0; + virtual gchar *param_getDefaultSVGValue() const = 0; + virtual void param_widget_is_visible(bool is_visible) { widget_is_visible = is_visible; } + virtual void param_widget_is_enabled(bool is_enabled) { widget_is_enabled = is_enabled; } void write_to_SVG(); - + virtual void param_set_default() = 0; - virtual void param_update_default(const gchar * default_value) = 0; + virtual void param_update_default(const gchar *default_value) = 0; // This creates a new widget (newed with Gtk::manage(new ...);) - virtual Gtk::Widget * param_newWidget() = 0; + virtual Gtk::Widget *param_newWidget() = 0; - virtual Glib::ustring * param_getTooltip() { return ¶m_tooltip; }; + virtual Glib::ustring *param_getTooltip() { return ¶m_tooltip; }; // overload these for your particular parameter to make it provide knotholder handles or canvas helperpaths virtual bool providesKnotHolderEntities() const { return false; } - virtual void addKnotHolderEntities(KnotHolder */*knotholder*/, SPItem */*item*/) {}; - virtual void addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vector<Geom::PathVector> &/*hp_vec*/) {}; + virtual void addKnotHolderEntities(KnotHolder * /*knotholder*/, SPItem * /*item*/){}; + virtual void addCanvasIndicators(SPLPEItem const * /*lpeitem*/, std::vector<Geom::PathVector> & /*hp_vec*/){}; - virtual void param_editOncanvas(SPItem * /*item*/, SPDesktop * /*dt*/) {}; - virtual void param_setup_nodepath(Inkscape::NodePath::Path */*np*/) {}; + virtual void param_editOncanvas(SPItem * /*item*/, SPDesktop * /*dt*/){}; + virtual void param_setup_nodepath(Inkscape::NodePath::Path * /*np*/){}; - virtual void param_transform_multiply(Geom::Affine const& /*postmul*/, bool /*set*/) {}; + virtual void param_transform_multiply(Geom::Affine const & /*postmul*/, bool /*set*/){}; Glib::ustring param_key; Glib::ustring param_tooltip; - Inkscape::UI::Widget::Registry * param_wr; + Inkscape::UI::Widget::Registry *param_wr; Glib::ustring param_label; bool oncanvas_editable; bool widget_is_visible; bool widget_is_enabled; -protected: - - Effect* param_effect; + protected: + Effect *param_effect; - void param_write_to_repr(const char * svgd); + void param_write_to_repr(const char *svgd); }; class ScalarParam : public Parameter { -public: - ScalarParam( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Inkscape::UI::Widget::Registry* wr, - Effect* effect, - gdouble default_value = 1.0); + public: + ScalarParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, + Inkscape::UI::Widget::Registry *wr, Effect *effect, gdouble default_value = 1.0); ~ScalarParam() override; - ScalarParam(const ScalarParam&) = delete; - ScalarParam& operator=(const ScalarParam&) = delete; + ScalarParam(const ScalarParam &) = delete; + ScalarParam &operator=(const ScalarParam &) = delete; - bool param_readSVGValue(const gchar * strvalue) override; - gchar * param_getSVGValue() const override; - gchar * param_getDefaultSVGValue() const override; + bool param_readSVGValue(const gchar *strvalue) override; + gchar *param_getSVGValue() const override; + gchar *param_getDefaultSVGValue() const override; void param_set_default() override; void param_update_default(gdouble default_value); - void param_update_default(const gchar * default_value) override; + void param_update_default(const gchar *default_value) override; void param_set_value(gdouble val); void param_make_integer(bool yes = true); void param_set_range(gdouble min, gdouble max); @@ -128,11 +122,11 @@ public: double param_get_max() { return max; }; double param_get_min() { return min; }; void param_set_undo(bool set_undo); - Gtk::Widget * param_newWidget() override; + Gtk::Widget *param_newWidget() override; inline operator gdouble() const { return value; }; -protected: + protected: gdouble value; gdouble min; gdouble max; @@ -145,9 +139,9 @@ protected: bool _set_undo; }; -} //namespace LivePathEffect +} // namespace LivePathEffect -} //namespace Inkscape +} // namespace Inkscape #endif |
