summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 68153f1)
raw | patch | inline | side by side (parent: 68153f1)
author | johanengelen <johanengelen@users.sourceforge.net> | |
Sun, 2 Sep 2007 16:37:15 +0000 (16:37 +0000) | ||
committer | johanengelen <johanengelen@users.sourceforge.net> | |
Sun, 2 Sep 2007 16:37:15 +0000 (16:37 +0000) |
src/live_effects/lpe-curvestitch.cpp | patch | blob | history | |
src/live_effects/lpe-curvestitch.h | patch | blob | history | |
src/live_effects/parameter/parameter.cpp | patch | blob | history | |
src/live_effects/parameter/parameter.h | patch | blob | history | |
src/live_effects/parameter/random.cpp | [new file with mode: 0644] | patch | blob |
src/live_effects/parameter/random.h | [new file with mode: 0644] | patch | blob |
src/live_effects/parameter/todo.txt | patch | blob | history | |
src/ui/widget/random.cpp | [new file with mode: 0644] | patch | blob |
src/ui/widget/random.h | [new file with mode: 0644] | patch | blob |
src/ui/widget/registered-widget.cpp | patch | blob | history | |
src/ui/widget/registered-widget.h | patch | blob | history |
index f595a9553cd07b62cd2905d9fbdda9ff7fad9d0c..a0a473fe7fdcbdcc6fecabf24685d34a5235d789 100644 (file)
LPECurveStitch::doEffect (std::vector<Geom::Path> & path_in)\r
{\r
if (path_in.size() >= 2) {\r
+ startpoint_variation.resetRandomizer();\r
+ endpoint_variation.resetRandomizer();\r
+\r
D2<Piecewise<SBasis> > stroke = make_cuts_independant(strokepath);\r
Interval bndsStroke = bounds_exact(stroke[0]);\r
gdouble scaling = bndsStroke.max() - bndsStroke.min();\r
for (int i = 0; i < nrofpaths; i++) {\r
Point start = A(tA);\r
Point end = B(tB);\r
- if (startpoint_variation != 0)\r
- start = start + g_random_double_range(0, startpoint_variation) * (end - start);\r
- if (endpoint_variation != 0)\r
- end = end + g_random_double_range(0, endpoint_variation) * (end - start);\r
+ if (startpoint_variation.get_value() != 0)\r
+ start = start + startpoint_variation * (end - start);\r
+ if (endpoint_variation.get_value() != 0)\r
+ end = end + endpoint_variation * (end - start);\r
\r
Matrix transform;\r
transform.setXAxis( (end-start) / scaling );\r
index 571996a7cc89f770c157deb6757a9193ec960de4..2b3e4553e893edec9bcafa13c69f3c1da697956b 100644 (file)
#include "live_effects/parameter/path.h"\r
#include "live_effects/parameter/parameter.h"\r
#include "live_effects/parameter/bool.h"\r
+#include "live_effects/parameter/random.h"\r
\r
namespace Inkscape {\r
namespace LivePathEffect {\r
private:\r
PathParam strokepath;\r
ScalarParam nrofpaths;\r
- ScalarParam startpoint_variation;\r
- ScalarParam endpoint_variation;\r
+ RandomParam startpoint_variation;\r
+ RandomParam endpoint_variation;\r
BoolParam scale_y;\r
\r
LPECurveStitch(const LPECurveStitch&);\r
index 42dd219957738a01ee0de553844ea453403475de..94d5e3f8e3e26d4012cd1c8d4875ed62f33a7ecb 100644 (file)
if (rsu)\r
rsu->getS()->setRange(min, max);\r
\r
- param_set_value(value);\r
+ param_set_value(value); // reset value to see whether it is in ranges\r
}\r
\r
void\r
index d8659600abeca866d814b7e42742e596f4f1ec64..e6cabbdd99bf03c989e649bcc6a055707dff2dfd 100644 (file)
Inkscape::UI::Widget::Registry* wr,\r
Effect* effect,\r
gdouble default_value = 1.0);\r
- ~ScalarParam();\r
+ virtual ~ScalarParam();\r
\r
- bool param_readSVGValue(const gchar * strvalue);\r
- gchar * param_writeSVGValue() const;\r
+ virtual bool param_readSVGValue(const gchar * strvalue);\r
+ virtual gchar * param_writeSVGValue() const;\r
\r
- void param_set_default();\r
+ virtual void param_set_default();\r
void param_set_value(gdouble val);\r
void param_make_integer(bool yes = true);\r
void param_set_range(gdouble min, gdouble max);\r
\r
- Gtk::Widget * param_getWidget();\r
+ virtual Gtk::Widget * param_getWidget();\r
\r
inline operator gdouble()\r
{ return value; };\r
\r
-private:\r
- ScalarParam(const ScalarParam&);\r
- ScalarParam& operator=(const ScalarParam&);\r
-\r
+protected:\r
gdouble value;\r
gdouble min;\r
gdouble max;\r
bool integer;\r
gdouble defvalue;\r
Inkscape::UI::Widget::RegisteredScalar * rsu;\r
+\r
+private:\r
+ ScalarParam(const ScalarParam&);\r
+ ScalarParam& operator=(const ScalarParam&);\r
};\r
\r
} //namespace LivePathEffect\r
diff --git a/src/live_effects/parameter/random.cpp b/src/live_effects/parameter/random.cpp
--- /dev/null
@@ -0,0 +1,194 @@
+#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_RANDOM_CPP\r
+\r
+/*\r
+ * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>\r
+ *\r
+ * Released under GNU GPL, read the file 'COPYING' for more information\r
+ */\r
+\r
+#include "live_effects/parameter/random.h"\r
+#include "live_effects/effect.h"\r
+#include "svg/svg.h"\r
+#include "libnr/nr-values.h"\r
+\r
+#include <gtkmm.h>\r
+#include "ui/widget/random.h"\r
+\r
+#include "svg/stringstream.h"\r
+\r
+#include "verbs.h"\r
+\r
+#define noLPERANDOMPARAM_DEBUG\r
+\r
+namespace Inkscape {\r
+\r
+namespace LivePathEffect {\r
+\r
+\r
+RandomParam::RandomParam( const Glib::ustring& label, const Glib::ustring& tip,\r
+ const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,\r
+ Effect* effect, gdouble default_value, long default_seed)\r
+ : Parameter(label, tip, key, wr, effect)\r
+{\r
+ defvalue = default_value;\r
+ value = defvalue;\r
+ min = -NR_HUGE;\r
+ max = NR_HUGE;\r
+ integer = false;\r
+ regrandom = NULL;\r
+\r
+ defseed = default_seed;\r
+ startseed = defseed;\r
+ seed = startseed;\r
+}\r
+\r
+RandomParam::~RandomParam()\r
+{\r
+ if (regrandom)\r
+ delete regrandom;\r
+}\r
+\r
+bool\r
+RandomParam::param_readSVGValue(const gchar * strvalue)\r
+{\r
+ double newval, newstartseed;\r
+ gchar** stringarray = g_strsplit (strvalue, ";", 2);\r
+ unsigned int success = sp_svg_number_read_d(stringarray[0], &newval);\r
+ if (success == 1) {\r
+ success += sp_svg_number_read_d(stringarray[1], &newstartseed);\r
+ if (success == 2) {\r
+ param_set_value(newval, newstartseed);\r
+ } else {\r
+ param_set_value(newval, defseed);\r
+ }\r
+ g_strfreev(stringarray);\r
+ return true;\r
+ }\r
+ g_strfreev(stringarray);\r
+ return false;\r
+}\r
+\r
+gchar *\r
+RandomParam::param_writeSVGValue() const\r
+{\r
+ Inkscape::SVGOStringStream os;\r
+ os << value << ';' << startseed;\r
+ gchar * str = g_strdup(os.str().c_str());\r
+ return str;\r
+}\r
+\r
+void\r
+RandomParam::param_set_default() \r
+{\r
+ param_set_value(defvalue, defseed);\r
+}\r
+\r
+void\r
+RandomParam::param_set_value(gdouble val, long newseed) \r
+{\r
+ value = val;\r
+ if (integer)\r
+ value = round(value);\r
+ if (value > max)\r
+ value = max;\r
+ if (value < min)\r
+ value = min;\r
+\r
+ startseed = setup_seed(newseed);\r
+ seed = startseed;\r
+\r
+ if (regrandom)\r
+ regrandom->setValue(value, startseed);\r
+}\r
+\r
+void\r
+RandomParam::param_set_range(gdouble min, gdouble max) \r
+{\r
+ this->min = min;\r
+ this->max = max;\r
+ if (regrandom)\r
+ regrandom->getR()->setRange(min, max);\r
+\r
+ param_set_value(value, startseed); // reset value, to check whether it is in range\r
+}\r
+\r
+void\r
+RandomParam::param_make_integer(bool yes)\r
+{\r
+ integer = yes;\r
+ if (regrandom) {\r
+ regrandom->getR()->setDigits(0);\r
+ regrandom->getR()->setIncrements(1, 10);\r
+ }\r
+}\r
+\r
+void\r
+RandomParam::resetRandomizer()\r
+{\r
+ seed = startseed;\r
+}\r
+\r
+\r
+Gtk::Widget *\r
+RandomParam::param_getWidget()\r
+{\r
+ // TODO: add a button to set a different startseed\r
+ if (!regrandom) {\r
+ regrandom = new Inkscape::UI::Widget::RegisteredRandom();\r
+ regrandom->init(param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc());\r
+ regrandom->setValue(value, startseed);\r
+ if (integer)\r
+ param_make_integer();\r
+\r
+ regrandom->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change random parameter"));\r
+ }\r
+ return dynamic_cast<Gtk::Widget *> (regrandom->getR());\r
+}\r
+\r
+RandomParam::operator gdouble()\r
+{\r
+ return rand() * value;\r
+};\r
+\r
+/* RNG stolen from /display/nr-filter-turbulence.cpp */\r
+#define RAND_m 2147483647 /* 2**31 - 1 */\r
+#define RAND_a 16807 /* 7**5; primitive root of m */\r
+#define RAND_q 127773 /* m / a */\r
+#define RAND_r 2836 /* m % a */\r
+#define BSize 0x100\r
+\r
+long\r
+RandomParam::setup_seed(long lSeed)\r
+{\r
+ if (lSeed <= 0) lSeed = -(lSeed % (RAND_m - 1)) + 1;\r
+ if (lSeed > RAND_m - 1) lSeed = RAND_m - 1;\r
+ return lSeed;\r
+}\r
+\r
+// generates random number between 0 and 1\r
+gdouble\r
+RandomParam::rand()\r
+{\r
+ long result;\r
+ result = RAND_a * (seed % RAND_q) - RAND_r * (seed / RAND_q);\r
+ if (result <= 0) result += RAND_m;\r
+ seed = result;\r
+\r
+ gdouble dresult = (gdouble)(result % BSize) / BSize;\r
+ return dresult;\r
+}\r
+\r
+\r
+} /* namespace LivePathEffect */\r
+} /* namespace Inkscape */\r
+\r
+/*\r
+ Local Variables:\r
+ mode:c++\r
+ c-file-style:"stroustrup"\r
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
+ indent-tabs-mode:nil\r
+ fill-column:99\r
+ End:\r
+*/\r
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :\r
diff --git a/src/live_effects/parameter/random.h b/src/live_effects/parameter/random.h
--- /dev/null
@@ -0,0 +1,76 @@
+#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_RANDOM_H\r
+#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_RANDOM_H\r
+\r
+/*\r
+ * Inkscape::LivePathEffectParameters\r
+ *\r
+* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>\r
+ *\r
+ * Released under GNU GPL, read the file 'COPYING' for more information\r
+ */\r
+\r
+#include "live_effects/parameter/parameter.h"\r
+#include <glibmm/ustring.h>\r
+#include <2geom/point.h>\r
+#include <2geom/path.h>\r
+\r
+#include "ui/widget/registry.h"\r
+#include "ui/widget/registered-widget.h"\r
+\r
+namespace Inkscape {\r
+\r
+namespace LivePathEffect {\r
+\r
+class RandomParam : public Parameter {\r
+public:\r
+ RandomParam( const Glib::ustring& label,\r
+ const Glib::ustring& tip,\r
+ const Glib::ustring& key, \r
+ Inkscape::UI::Widget::Registry* wr,\r
+ Effect* effect,\r
+ gdouble default_value = 1.0,\r
+ long default_seed = 0);\r
+ virtual ~RandomParam();\r
+\r
+ virtual bool param_readSVGValue(const gchar * strvalue);\r
+ virtual gchar * param_writeSVGValue() const;\r
+ virtual void param_set_default();\r
+\r
+ virtual Gtk::Widget * param_getWidget();\r
+\r
+ void param_set_value(gdouble val, long newseed);\r
+ void param_make_integer(bool yes = true);\r
+ void param_set_range(gdouble min, gdouble max);\r
+\r
+ void resetRandomizer();\r
+\r
+ operator gdouble();\r
+ inline gdouble get_value()\r
+ { return value; } ;\r
+\r
+protected:\r
+ long startseed;\r
+ long seed;\r
+ long defseed;\r
+\r
+ gdouble value;\r
+ gdouble min;\r
+ gdouble max;\r
+ bool integer;\r
+ gdouble defvalue;\r
+\r
+ Inkscape::UI::Widget::RegisteredRandom * regrandom;\r
+\r
+private:\r
+ long setup_seed(long);\r
+ gdouble rand();\r
+\r
+ RandomParam(const RandomParam&);\r
+ RandomParam& operator=(const RandomParam&);\r
+};\r
+\r
+} //namespace LivePathEffect\r
+\r
+} //namespace Inkscape\r
+\r
+#endif\r
index f1a1b4220328370f5d79fd9b9e34f5dd88c22eb0..d82411db070b1191a4d512c969db7cae055c51d9 100644 (file)
\r
- add more types! \r
straightlinepaths: for example for the gears effect. (curves are not important there)\r
-random number: it must also store the random number generator seed!!!\r
+\r
\r
diff --git a/src/ui/widget/random.cpp b/src/ui/widget/random.cpp
--- /dev/null
+++ b/src/ui/widget/random.cpp
@@ -0,0 +1,148 @@
+/**\r
+ * \brief Scalar Widget - A labelled text box, with spin buttons and optional\r
+ * icon or suffix, for entering arbitrary number values. It adds an extra\r
+ * number called "startseed", that is not UI edittable, but should be put in SVG.\r
+ * This does NOT generate a random number, but provides merely the saving of \r
+ * the startseed value.\r
+ *\r
+ * Authors:\r
+ * Carl Hetherington <inkscape@carlh.net>\r
+ * Derek P. Moore <derekm@hackunix.org>\r
+ * Bryce Harrington <bryce@bryceharrington.org>\r
+ *\r
+ * Copyright (C) 2004 Carl Hetherington\r
+ *\r
+ * Released under GNU GPL. Read the file 'COPYING' for more information.\r
+ */\r
+\r
+#ifdef HAVE_CONFIG_H\r
+# include <config.h>\r
+#endif\r
+\r
+\r
+#include "random.h"\r
+#include "widgets/icon.h"\r
+\r
+#include <glibmm/i18n.h>\r
+\r
+namespace Inkscape {\r
+namespace UI {\r
+namespace Widget {\r
+\r
+/**\r
+ * Construct a Random scalar Widget.\r
+ *\r
+ * \param label Label.\r
+ * \param suffix Suffix, placed after the widget (defaults to "").\r
+ * \param icon Icon filename, placed before the label (defaults to "").\r
+ * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label\r
+ * indicates the next character should be used for the\r
+ * mnemonic accelerator key (defaults to false).\r
+ */\r
+Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,\r
+ Glib::ustring const &suffix,\r
+ Glib::ustring const &icon,\r
+ bool mnemonic)\r
+ : Scalar(label, tooltip, suffix, icon, mnemonic)\r
+{\r
+ startseed = 0;\r
+ addReseedButton();\r
+}\r
+\r
+/**\r
+ * Construct a Random Scalar Widget.\r
+ *\r
+ * \param label Label.\r
+ * \param digits Number of decimal digits to display.\r
+ * \param suffix Suffix, placed after the widget (defaults to "").\r
+ * \param icon Icon filename, placed before the label (defaults to "").\r
+ * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label\r
+ * indicates the next character should be used for the\r
+ * mnemonic accelerator key (defaults to false).\r
+ */\r
+Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,\r
+ unsigned digits,\r
+ Glib::ustring const &suffix,\r
+ Glib::ustring const &icon,\r
+ bool mnemonic)\r
+ : Scalar(label, tooltip, digits, suffix, icon, mnemonic)\r
+{\r
+ startseed = 0;\r
+ addReseedButton();\r
+}\r
+\r
+/**\r
+ * Construct a Random Scalar Widget.\r
+ *\r
+ * \param label Label.\r
+ * \param adjust Adjustment to use for the SpinButton.\r
+ * \param digits Number of decimal digits to display (defaults to 0).\r
+ * \param suffix Suffix, placed after the widget (defaults to "").\r
+ * \param icon Icon filename, placed before the label (defaults to "").\r
+ * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label\r
+ * indicates the next character should be used for the\r
+ * mnemonic accelerator key (defaults to true).\r
+ */\r
+Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,\r
+ Gtk::Adjustment &adjust,\r
+ unsigned digits,\r
+ Glib::ustring const &suffix,\r
+ Glib::ustring const &icon,\r
+ bool mnemonic)\r
+ : Scalar(label, tooltip, adjust, digits, suffix, icon, mnemonic)\r
+{\r
+ startseed = 0;\r
+ addReseedButton();\r
+}\r
+\r
+/** Gets the startseed */\r
+long\r
+Random::getStartSeed() const\r
+{\r
+ return startseed;\r
+}\r
+\r
+/** Sets the startseed number */\r
+void\r
+Random::setStartSeed(long newseed)\r
+{\r
+ startseed = newseed;\r
+}\r
+\r
+/** Add reseed button to the widget */\r
+void\r
+Random::addReseedButton()\r
+{\r
+ Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "draw_spiral", Inkscape::ICON_SIZE_BUTTON) );\r
+ Gtk::Button * pButton = Gtk::manage(new Gtk::Button());\r
+ pButton->set_relief(Gtk::RELIEF_NONE);\r
+ pIcon->show();\r
+ pButton->add(*pIcon);\r
+ pButton->show();\r
+ pButton->signal_clicked().connect(sigc::mem_fun(*this, &Random::onReseedButtonClick));\r
+ _tooltips.set_tip(*pButton, _("Reseed the random number generator; this creates a different sequence of random numbers."));\r
+\r
+ pack_start(*pButton, Gtk::PACK_SHRINK, 0);\r
+}\r
+\r
+void\r
+Random::onReseedButtonClick()\r
+{\r
+ startseed = g_random_int();\r
+ signal_reseeded.emit();\r
+}\r
+\r
+} // namespace Widget\r
+} // namespace UI\r
+} // namespace Inkscape\r
+\r
+/*\r
+ Local Variables:\r
+ mode:c++\r
+ c-file-style:"stroustrup"\r
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
+ indent-tabs-mode:nil\r
+ fill-column:99\r
+ End:\r
+*/\r
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :\r
diff --git a/src/ui/widget/random.h b/src/ui/widget/random.h
--- /dev/null
+++ b/src/ui/widget/random.h
@@ -0,0 +1,72 @@
+/**\r
+ * \brief Random Scalar Widget - A labelled text box, with spin buttons and optional\r
+ * icon or suffix, for entering arbitrary number values and generating a random number from it.\r
+ *\r
+ * Authors:\r
+ * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>\r
+ *\r
+ * Copyright (C) 2007 Author\r
+ *\r
+ * Released under GNU GPL. Read the file 'COPYING' for more information.\r
+ */\r
+\r
+#ifndef INKSCAPE_UI_WIDGET_RANDOM_H\r
+#define INKSCAPE_UI_WIDGET_RANDOM_H\r
+\r
+#include "scalar.h"\r
+\r
+namespace Inkscape {\r
+namespace UI {\r
+namespace Widget {\r
+\r
+class Random : public Scalar\r
+{\r
+public:\r
+ Random(Glib::ustring const &label,\r
+ Glib::ustring const &tooltip,\r
+ Glib::ustring const &suffix = "",\r
+ Glib::ustring const &icon = "",\r
+ bool mnemonic = true);\r
+ Random(Glib::ustring const &label,\r
+ Glib::ustring const &tooltip,\r
+ unsigned digits,\r
+ Glib::ustring const &suffix = "",\r
+ Glib::ustring const &icon = "",\r
+ bool mnemonic = true);\r
+ Random(Glib::ustring const &label,\r
+ Glib::ustring const &tooltip,\r
+ Gtk::Adjustment &adjust,\r
+ unsigned digits = 0,\r
+ Glib::ustring const &suffix = "",\r
+ Glib::ustring const &icon = "",\r
+ bool mnemonic = true);\r
+\r
+ long getStartSeed() const;\r
+ void setStartSeed(long newseed);\r
+\r
+ sigc::signal <void> signal_reseeded;\r
+\r
+protected:\r
+ long startseed;\r
+\r
+private:\r
+ void addReseedButton();\r
+ void onReseedButtonClick();\r
+};\r
+\r
+} // namespace Widget\r
+} // namespace UI\r
+} // namespace Inkscape\r
+\r
+#endif // INKSCAPE_UI_WIDGET_RANDOM_H\r
+\r
+/*\r
+ Local Variables:\r
+ mode:c++\r
+ c-file-style:"stroustrup"\r
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
+ indent-tabs-mode:nil\r
+ fill-column:99\r
+ End:\r
+*/\r
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :\r
index 8a569bc3271ac7ebff60035008b9c5d466e2426d..4db4363caf76ca7389de0fcfade9975ff0acdcb5 100644 (file)
#include "ui/widget/registry.h"
#include "ui/widget/scalar-unit.h"
#include "ui/widget/point.h"
+#include "ui/widget/random.h"
#include "widgets/spinbutton-events.h"
#include "helper/units.h"
_wr->setUpdating (false);
}
+/*#########################################
+ * Registered RANDOM
+ */
+
+RegisteredRandom::RegisteredRandom()
+{
+ _widget = NULL;
+}
+
+RegisteredRandom::~RegisteredRandom()
+{
+ if (_widget)
+ delete _widget;
+
+ _value_changed_connection.disconnect();
+ _reseeded_connection.disconnect();
+}
+
+void
+RegisteredRandom::init ( const Glib::ustring& label, const Glib::ustring& tip,
+ const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in,
+ SPDocument * doc_in )
+{
+ init_parent(key, wr, repr_in, doc_in);
+
+ _widget = new Random (label, tip);
+ _widget->setRange (-1e6, 1e6);
+ _widget->setDigits (2);
+ _widget->setIncrements(0.1, 1.0);
+ _value_changed_connection = _widget->signal_value_changed().connect (sigc::mem_fun (*this, &RegisteredRandom::on_value_changed));
+ _reseeded_connection = _widget->signal_reseeded.connect(sigc::mem_fun(*this, &RegisteredRandom::on_value_changed));
+}
+
+Random*
+RegisteredRandom::getR()
+{
+ return _widget;
+}
+
+void
+RegisteredRandom::setValue (double val, long startseed)
+{
+ _widget->setValue (val);
+ _widget->setStartSeed(startseed);
+ on_value_changed();
+}
+
+void
+RegisteredRandom::on_value_changed()
+{
+ if (_wr->isUpdating())
+ return;
+ _wr->setUpdating (true);
+
+ // FIXME: gtk bug?
+ // disable interruptibility: see http://inkscape.svn.sourceforge.net/viewvc/inkscape/inkscape/trunk/src/ui/widget/selected-style.cpp?r1=13149&r2=13257&sortby=date
+ SPDesktop* dt = SP_ACTIVE_DESKTOP;
+ sp_canvas_force_full_redraw_after_interruptions(sp_desktop_canvas(dt), 0);
+
+ Inkscape::SVGOStringStream os;
+ os << _widget->getValue() << ';' << _widget->getStartSeed();
+
+ write_to_xml(os.str().c_str());
+
+ // resume interruptibility
+ sp_canvas_end_forced_full_redraws(sp_desktop_canvas(dt));
+
+ _wr->setUpdating (false);
+}
+
+
} // namespace Dialog
} // namespace UI
} // namespace Inkscape
index 008ca0077f4e9d3423027aa0241fc06b4d2a30e3..7d71165dae947eac774355355d42cf0a4d13478d 100644 (file)
class ScalarUnit;
class UnitMenu;
class Point;
+class Random;
class RegisteredWidget {
public:
void on_value_changed();
};
+class RegisteredRandom : public RegisteredWidget {
+public:
+ RegisteredRandom();
+ ~RegisteredRandom();
+ void init (const Glib::ustring& label,
+ const Glib::ustring& tip,
+ const Glib::ustring& key,
+ Registry& wr,
+ Inkscape::XML::Node* repr_in,
+ SPDocument *doc_in);
+ inline void init ( const Glib::ustring& label,
+ const Glib::ustring& tip,
+ const Glib::ustring& key,
+ Registry& wr)
+ { init(label, tip, key, wr, NULL, NULL); };
+
+ Random* getR();
+ void setValue (double val, long startseed);
+
+protected:
+ Random *_widget;
+ sigc::connection _value_changed_connection;
+ sigc::connection _reseeded_connection;
+ void on_value_changed();
+};
+
} // namespace Widget
} // namespace UI
} // namespace Inkscape