From 8521695565e41f5cce4f5b8cba6754d8cd0c8854 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sun, 2 Sep 2007 16:37:15 +0000 Subject: LPE: add RandomParam type. (bzr r3662) --- src/ui/widget/random.cpp | 148 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 src/ui/widget/random.cpp (limited to 'src/ui/widget/random.cpp') 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 + * Derek P. Moore + * Bryce Harrington + * + * Copyright (C) 2004 Carl Hetherington + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + + +#include "random.h" +#include "widgets/icon.h" + +#include + +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 : -- cgit v1.2.3