summaryrefslogtreecommitdiffstats
path: root/src/ui/widget
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2007-09-02 16:37:15 +0000
committerjohanengelen <johanengelen@users.sourceforge.net>2007-09-02 16:37:15 +0000
commit8521695565e41f5cce4f5b8cba6754d8cd0c8854 (patch)
treeb96bdc9da16ed194b3016c77eb58727294fafd73 /src/ui/widget
parentEnsure active unit member pointer is always initialized, fixes 1784559 (diff)
downloadinkscape-8521695565e41f5cce4f5b8cba6754d8cd0c8854.tar.gz
inkscape-8521695565e41f5cce4f5b8cba6754d8cd0c8854.zip
LPE: add RandomParam type.
(bzr r3662)
Diffstat (limited to 'src/ui/widget')
-rw-r--r--src/ui/widget/random.cpp148
-rw-r--r--src/ui/widget/random.h72
-rw-r--r--src/ui/widget/registered-widget.cpp72
-rw-r--r--src/ui/widget/registered-widget.h27
4 files changed, 319 insertions, 0 deletions
diff --git a/src/ui/widget/random.cpp b/src/ui/widget/random.cpp
new file mode 100644
index 000000000..1d99f406c
--- /dev/null
+++ b/src/ui/widget/random.cpp
@@ -0,0 +1,148 @@
+/**
+ * \brief Scalar Widget - A labelled text box, with spin buttons and optional
+ * icon or suffix, for entering arbitrary number values. It adds an extra
+ * number called "startseed", that is not UI edittable, but should be put in SVG.
+ * This does NOT generate a random number, but provides merely the saving of
+ * the startseed value.
+ *
+ * Authors:
+ * Carl Hetherington <inkscape@carlh.net>
+ * Derek P. Moore <derekm@hackunix.org>
+ * Bryce Harrington <bryce@bryceharrington.org>
+ *
+ * Copyright (C) 2004 Carl Hetherington
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+
+#include "random.h"
+#include "widgets/icon.h"
+
+#include <glibmm/i18n.h>
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+/**
+ * Construct a Random scalar Widget.
+ *
+ * \param label Label.
+ * \param suffix Suffix, placed after the widget (defaults to "").
+ * \param icon Icon filename, placed before the label (defaults to "").
+ * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
+ * indicates the next character should be used for the
+ * mnemonic accelerator key (defaults to false).
+ */
+Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,
+ Glib::ustring const &suffix,
+ Glib::ustring const &icon,
+ bool mnemonic)
+ : Scalar(label, tooltip, suffix, icon, mnemonic)
+{
+ startseed = 0;
+ addReseedButton();
+}
+
+/**
+ * Construct a Random Scalar Widget.
+ *
+ * \param label Label.
+ * \param digits Number of decimal digits to display.
+ * \param suffix Suffix, placed after the widget (defaults to "").
+ * \param icon Icon filename, placed before the label (defaults to "").
+ * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
+ * indicates the next character should be used for the
+ * mnemonic accelerator key (defaults to false).
+ */
+Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,
+ unsigned digits,
+ Glib::ustring const &suffix,
+ Glib::ustring const &icon,
+ bool mnemonic)
+ : Scalar(label, tooltip, digits, suffix, icon, mnemonic)
+{
+ startseed = 0;
+ addReseedButton();
+}
+
+/**
+ * Construct a Random Scalar Widget.
+ *
+ * \param label Label.
+ * \param adjust Adjustment to use for the SpinButton.
+ * \param digits Number of decimal digits to display (defaults to 0).
+ * \param suffix Suffix, placed after the widget (defaults to "").
+ * \param icon Icon filename, placed before the label (defaults to "").
+ * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
+ * indicates the next character should be used for the
+ * mnemonic accelerator key (defaults to true).
+ */
+Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,
+ Gtk::Adjustment &adjust,
+ unsigned digits,
+ Glib::ustring const &suffix,
+ Glib::ustring const &icon,
+ bool mnemonic)
+ : Scalar(label, tooltip, adjust, digits, suffix, icon, mnemonic)
+{
+ startseed = 0;
+ addReseedButton();
+}
+
+/** Gets the startseed */
+long
+Random::getStartSeed() const
+{
+ return startseed;
+}
+
+/** Sets the startseed number */
+void
+Random::setStartSeed(long newseed)
+{
+ startseed = newseed;
+}
+
+/** Add reseed button to the widget */
+void
+Random::addReseedButton()
+{
+ Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "draw_spiral", Inkscape::ICON_SIZE_BUTTON) );
+ Gtk::Button * pButton = Gtk::manage(new Gtk::Button());
+ pButton->set_relief(Gtk::RELIEF_NONE);
+ pIcon->show();
+ pButton->add(*pIcon);
+ pButton->show();
+ pButton->signal_clicked().connect(sigc::mem_fun(*this, &Random::onReseedButtonClick));
+ _tooltips.set_tip(*pButton, _("Reseed the random number generator; this creates a different sequence of random numbers."));
+
+ pack_start(*pButton, Gtk::PACK_SHRINK, 0);
+}
+
+void
+Random::onReseedButtonClick()
+{
+ startseed = g_random_int();
+ signal_reseeded.emit();
+}
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/ui/widget/random.h b/src/ui/widget/random.h
new file mode 100644
index 000000000..56c39ccc1
--- /dev/null
+++ b/src/ui/widget/random.h
@@ -0,0 +1,72 @@
+/**
+ * \brief Random Scalar Widget - A labelled text box, with spin buttons and optional
+ * icon or suffix, for entering arbitrary number values and generating a random number from it.
+ *
+ * Authors:
+ * Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *
+ * Copyright (C) 2007 Author
+ *
+ * Released under GNU GPL. Read the file 'COPYING' for more information.
+ */
+
+#ifndef INKSCAPE_UI_WIDGET_RANDOM_H
+#define INKSCAPE_UI_WIDGET_RANDOM_H
+
+#include "scalar.h"
+
+namespace Inkscape {
+namespace UI {
+namespace Widget {
+
+class Random : public Scalar
+{
+public:
+ Random(Glib::ustring const &label,
+ Glib::ustring const &tooltip,
+ Glib::ustring const &suffix = "",
+ Glib::ustring const &icon = "",
+ bool mnemonic = true);
+ Random(Glib::ustring const &label,
+ Glib::ustring const &tooltip,
+ unsigned digits,
+ Glib::ustring const &suffix = "",
+ Glib::ustring const &icon = "",
+ bool mnemonic = true);
+ Random(Glib::ustring const &label,
+ Glib::ustring const &tooltip,
+ Gtk::Adjustment &adjust,
+ unsigned digits = 0,
+ Glib::ustring const &suffix = "",
+ Glib::ustring const &icon = "",
+ bool mnemonic = true);
+
+ long getStartSeed() const;
+ void setStartSeed(long newseed);
+
+ sigc::signal <void> signal_reseeded;
+
+protected:
+ long startseed;
+
+private:
+ void addReseedButton();
+ void onReseedButtonClick();
+};
+
+} // namespace Widget
+} // namespace UI
+} // namespace Inkscape
+
+#endif // INKSCAPE_UI_WIDGET_RANDOM_H
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp
index 8a569bc32..4db4363ca 100644
--- a/src/ui/widget/registered-widget.cpp
+++ b/src/ui/widget/registered-widget.cpp
@@ -23,6 +23,7 @@
#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"
@@ -542,6 +543,77 @@ RegisteredPoint::on_value_changed()
_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
diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h
index 008ca0077..7d71165da 100644
--- a/src/ui/widget/registered-widget.h
+++ b/src/ui/widget/registered-widget.h
@@ -38,6 +38,7 @@ class Scalar;
class ScalarUnit;
class UnitMenu;
class Point;
+class Random;
class RegisteredWidget {
public:
@@ -298,6 +299,32 @@ protected:
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