summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2007-08-19 20:34:48 +0000
committerjohanengelen <johanengelen@users.sourceforge.net>2007-08-19 20:34:48 +0000
commitb9745837eda971495b8aa0b91988c8ee3adef109 (patch)
treeaa294309c3c348e35708a12b43032918c33ffadb /src
parentRemove the clipping path emitted before the 'sh' operator since that same pat... (diff)
downloadinkscape-b9745837eda971495b8aa0b91988c8ee3adef109.tar.gz
inkscape-b9745837eda971495b8aa0b91988c8ee3adef109.zip
Add default value stuff for LPE parameters
(bzr r3536)
Diffstat (limited to 'src')
-rw-r--r--src/live_effects/effect.cpp19
-rw-r--r--src/live_effects/parameter/enum.h24
-rw-r--r--src/live_effects/parameter/parameter.cpp24
-rw-r--r--src/live_effects/parameter/parameter.h8
-rw-r--r--src/live_effects/parameter/path.cpp11
-rw-r--r--src/live_effects/parameter/path.h6
-rw-r--r--src/live_effects/parameter/point.cpp10
-rw-r--r--src/live_effects/parameter/point.h5
8 files changed, 84 insertions, 23 deletions
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp
index 901b80fcc..1e86ab479 100644
--- a/src/live_effects/effect.cpp
+++ b/src/live_effects/effect.cpp
@@ -129,7 +129,7 @@ std::vector<Geom::Path>
Effect::doEffect (std::vector<Geom::Path> & path_in)
{
Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2_in;
- // FIXME: find standard function to convert std::vector<Geom::Path> ==> Piecewise< D2<SBasis> >
+
for (unsigned int i=0; i < path_in.size(); i++) {
pwd2_in.concat( path_in[i].toPwSb() );
}
@@ -169,11 +169,18 @@ Effect::setParameter(Inkscape::XML::Node * repr, const gchar * key, const gchar
param_map_type::iterator it = param_map.find(stringkey);
if (it != param_map.end()) {
- bool accepted = it->second->param_readSVGValue(new_value);
- /* think: can this backfire and create infinite loop when started with unacceptable old_value?
- if (!accepted) { // change was not accepted, so change it back.
- repr->setAttribute(key, old_value);
- } */
+ if (new_value) {
+ bool accepted = it->second->param_readSVGValue(new_value);
+ if (!accepted) {
+ g_warning("Effect::setParameter - '%s' not accepted for %s", new_value, key);
+ // change was not accepted, so change it back.
+ // think: can this backfire and create infinite loop when started with unacceptable old_value?
+ // repr->setAttribute(key, old_value);
+ }
+ } else {
+ // set default value
+ it->second->param_set_default();
+ }
}
}
diff --git a/src/live_effects/parameter/enum.h b/src/live_effects/parameter/enum.h
index bfc9fd352..9b8c0f91e 100644
--- a/src/live_effects/parameter/enum.h
+++ b/src/live_effects/parameter/enum.h
@@ -30,11 +30,12 @@ public:
const Util::EnumDataConverter<E>& c,
Inkscape::UI::Widget::Registry* wr,
Effect* effect,
- E defvalue)
+ E default_value)
: Parameter(label, tip, key, wr, effect)
{
regenum = NULL;
enumdataconv = &c;
+ defvalue = default_value;
value = defvalue;
};
~EnumParam() {
@@ -53,12 +54,12 @@ public:
};
bool param_readSVGValue(const gchar * strvalue) {
- if (!strvalue) return false;
+ if (!strvalue) {
+ param_set_default();
+ return true;
+ }
- value = enumdataconv->get_id_from_key(Glib::ustring(strvalue));
-
- if (regenum)
- regenum->combobox()->set_active_by_id(value);
+ param_set_value( enumdataconv->get_id_from_key(Glib::ustring(strvalue)) );
return true;
};
@@ -71,12 +72,23 @@ public:
return value;
}
+ void param_set_default() {
+ param_set_value(defvalue);
+ }
+
+ void param_set_value(E val) {
+ value = val;
+ if (regenum)
+ regenum->combobox()->set_active_by_id(value);
+ }
+
private:
EnumParam(const EnumParam&);
EnumParam& operator=(const EnumParam&);
UI::Widget::RegisteredEnum<E> * regenum;
E value;
+ E defvalue;
const Util::EnumDataConverter<E> * enumdataconv;
};
diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp
index beaafcc22..91df62e81 100644
--- a/src/live_effects/parameter/parameter.cpp
+++ b/src/live_effects/parameter/parameter.cpp
@@ -42,10 +42,11 @@ Parameter::Parameter( const Glib::ustring& label, const Glib::ustring& tip,
*/
RealParam::RealParam( const Glib::ustring& label, const Glib::ustring& tip,
const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
- Effect* effect, gdouble initial_value)
+ Effect* effect, gdouble default_value)
: Parameter(label, tip, key, wr, effect)
{
- value = initial_value;
+ defvalue = default_value;
+ value = defvalue;
rsu = NULL;
}
@@ -61,9 +62,7 @@ RealParam::param_readSVGValue(const gchar * strvalue)
double newval;
unsigned int success = sp_svg_number_read_d(strvalue, &newval);
if (success == 1) {
- value = newval;
- if (rsu)
- rsu->setValue(value);
+ param_set_value(newval);
return true;
}
return false;
@@ -78,6 +77,21 @@ RealParam::param_writeSVGValue() const
return str;
}
+void
+RealParam::param_set_default()
+{
+ param_set_value(defvalue);
+}
+
+void
+RealParam::param_set_value(gdouble val)
+{
+ value = val;
+ if (rsu)
+ rsu->setValue(value);
+}
+
+
Gtk::Widget *
RealParam::param_getWidget()
{
diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h
index 93cdc94ee..942def5b8 100644
--- a/src/live_effects/parameter/parameter.h
+++ b/src/live_effects/parameter/parameter.h
@@ -38,6 +38,8 @@ public:
virtual bool param_readSVGValue(const gchar * strvalue) = 0; // returns true if new value is valid / accepted.
virtual gchar * param_writeSVGValue() const = 0;
+ virtual void param_set_default() = 0;
+
// This returns pointer to the parameter's widget to be put in the live-effects dialog. Must also create the
// necessary widget if it does not exist yet.
virtual Gtk::Widget * param_getWidget() = 0;
@@ -65,12 +67,15 @@ public:
const Glib::ustring& key,
Inkscape::UI::Widget::Registry* wr,
Effect* effect,
- gdouble initial_value = 1.0);
+ gdouble default_value = 1.0);
~RealParam();
bool param_readSVGValue(const gchar * strvalue);
gchar * param_writeSVGValue() const;
+ void param_set_default();
+ void param_set_value(gdouble val);
+
Gtk::Widget * param_getWidget();
inline operator gdouble()
@@ -81,6 +86,7 @@ private:
RealParam& operator=(const RealParam&);
gdouble value;
+ gdouble defvalue;
Inkscape::UI::Widget::RegisteredScalar * rsu;
};
diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp
index d2615901f..f24fa933a 100644
--- a/src/live_effects/parameter/path.cpp
+++ b/src/live_effects/parameter/path.cpp
@@ -33,11 +33,12 @@ namespace LivePathEffect {
PathParam::PathParam( const Glib::ustring& label, const Glib::ustring& tip,
const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
- Effect* effect, const gchar * defvalue)
+ Effect* effect, const gchar * default_value)
: Parameter(label, tip, key, wr, effect)
{
_widget = NULL;
_tooltips = NULL;
+ defvalue = g_strdup(default_value);
param_readSVGValue(defvalue);
}
@@ -46,6 +47,14 @@ PathParam::~PathParam()
if (_tooltips)
delete _tooltips;
// _widget is managed by GTK so do not delete!
+
+ g_free(defvalue);
+}
+
+void
+PathParam::param_set_default()
+{
+ param_readSVGValue(defvalue);
}
bool
diff --git a/src/live_effects/parameter/path.h b/src/live_effects/parameter/path.h
index 18ffe5321..0b0d5f633 100644
--- a/src/live_effects/parameter/path.h
+++ b/src/live_effects/parameter/path.h
@@ -30,7 +30,7 @@ public:
const Glib::ustring& key,
Inkscape::UI::Widget::Registry* wr,
Effect* effect,
- const gchar * defvalue = "M0,0 L1,1");
+ const gchar * default_value = "M0,0 L1,1");
~PathParam();
Gtk::Widget * param_getWidget();
@@ -38,6 +38,8 @@ public:
bool param_readSVGValue(const gchar * strvalue);
gchar * param_writeSVGValue() const;
+ void param_set_default();
+
sigc::signal <void> signal_path_pasted;
private:
@@ -51,6 +53,8 @@ private:
void on_edit_button_click();
void on_paste_button_click();
+
+ gchar * defvalue;
};
diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp
index 39208ad62..3c42dcbfe 100644
--- a/src/live_effects/parameter/point.cpp
+++ b/src/live_effects/parameter/point.cpp
@@ -29,8 +29,8 @@ namespace LivePathEffect {
PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip,
const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
- Effect* effect, Geom::Point defvalue )
- : Geom::Point(defvalue), Parameter(label, tip, key, wr, effect)
+ Effect* effect, Geom::Point default_value )
+ : Geom::Point(default_value), Parameter(label, tip, key, wr, effect), defvalue(default_value)
{
_widget = NULL;
pointwdg = NULL;
@@ -49,6 +49,12 @@ PointParam::~PointParam()
g_object_unref (G_OBJECT (knot));
}
+void
+PointParam::param_set_default()
+{
+ param_setValue(defvalue);
+}
+
bool
PointParam::param_readSVGValue(const gchar * strvalue)
{
diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h
index 368ab63ed..c1d6681a2 100644
--- a/src/live_effects/parameter/point.h
+++ b/src/live_effects/parameter/point.h
@@ -32,7 +32,7 @@ public:
const Glib::ustring& key,
Inkscape::UI::Widget::Registry* wr,
Effect* effect,
- Geom::Point defvalue = Geom::Point(0,0));
+ Geom::Point default_value = Geom::Point(0,0));
~PointParam();
Gtk::Widget * param_getWidget();
@@ -41,6 +41,7 @@ public:
gchar * param_writeSVGValue() const;
void param_setValue(Geom::Point newpoint);
+ void param_set_default();
private:
PointParam(const PointParam&);
@@ -52,6 +53,8 @@ private:
void on_button_click();
SPKnot *knot;
+
+ Geom::Point defvalue;
};