1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Authors:
4  *   Carl Hetherington <inkscape@carlh.net>
5  *   Derek P. Moore <derekm@hackunix.org>
6  *   Bryce Harrington <bryce@bryceharrington.org>
7  *
8  * Copyright (C) 2004 Carl Hetherington
9  *
10  * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11  */
12 
13 #include "random.h"
14 #include "ui/icon-loader.h"
15 #include <glibmm/i18n.h>
16 
17 #include <gtkmm/button.h>
18 #include <gtkmm/image.h>
19 
20 namespace Inkscape {
21 namespace UI {
22 namespace Widget {
23 
Random(Glib::ustring const & label,Glib::ustring const & tooltip,Glib::ustring const & suffix,Glib::ustring const & icon,bool mnemonic)24 Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,
25                Glib::ustring const &suffix,
26                Glib::ustring const &icon,
27                bool mnemonic)
28     : Scalar(label, tooltip, suffix, icon, mnemonic)
29 {
30     startseed = 0;
31     addReseedButton();
32 }
33 
Random(Glib::ustring const & label,Glib::ustring const & tooltip,unsigned digits,Glib::ustring const & suffix,Glib::ustring const & icon,bool mnemonic)34 Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,
35                unsigned digits,
36                Glib::ustring const &suffix,
37                Glib::ustring const &icon,
38                bool mnemonic)
39     : Scalar(label, tooltip, digits, suffix, icon, mnemonic)
40 {
41     startseed = 0;
42     addReseedButton();
43 }
44 
Random(Glib::ustring const & label,Glib::ustring const & tooltip,Glib::RefPtr<Gtk::Adjustment> & adjust,unsigned digits,Glib::ustring const & suffix,Glib::ustring const & icon,bool mnemonic)45 Random::Random(Glib::ustring const &label, Glib::ustring const &tooltip,
46                Glib::RefPtr<Gtk::Adjustment> &adjust,
47                unsigned digits,
48                Glib::ustring const &suffix,
49                Glib::ustring const &icon,
50                bool mnemonic)
51     : Scalar(label, tooltip, adjust, digits, suffix, icon, mnemonic)
52 {
53     startseed = 0;
54     addReseedButton();
55 }
56 
getStartSeed() const57 long Random::getStartSeed() const
58 {
59     return startseed;
60 }
61 
setStartSeed(long newseed)62 void Random::setStartSeed(long newseed)
63 {
64     startseed = newseed;
65 }
66 
addReseedButton()67 void Random::addReseedButton()
68 {
69     Gtk::Image *pIcon = Gtk::manage(sp_get_icon_image("randomize", Gtk::ICON_SIZE_BUTTON));
70     Gtk::Button * pButton = Gtk::manage(new Gtk::Button());
71     pButton->set_relief(Gtk::RELIEF_NONE);
72     pIcon->show();
73     pButton->add(*pIcon);
74     pButton->show();
75     pButton->signal_clicked().connect(sigc::mem_fun(*this, &Random::onReseedButtonClick));
76     pButton->set_tooltip_text(_("Reseed the random number generator; this creates a different sequence of random numbers."));
77 
78     pack_start(*pButton, Gtk::PACK_SHRINK, 0);
79 }
80 
81 void
onReseedButtonClick()82 Random::onReseedButtonClick()
83 {
84     startseed = g_random_int();
85     signal_reseeded.emit();
86 }
87 
88 } // namespace Widget
89 } // namespace UI
90 } // namespace Inkscape
91 
92 /*
93   Local Variables:
94   mode:c++
95   c-file-style:"stroustrup"
96   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
97   indent-tabs-mode:nil
98   fill-column:99
99   End:
100 */
101 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
102