/[svn]/gigedit/trunk/src/gigedit/paramedit.h
ViewVC logotype

Annotation of /gigedit/trunk/src/gigedit/paramedit.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1460 - (hide annotations) (download) (as text)
Sat Oct 27 12:28:33 2007 UTC (16 years, 6 months ago) by persson
File MIME type: text/x-c++hdr
File size: 6783 byte(s)
* code refactoring: preparing for being able to edit multiple
  dimension regions simultaneously

1 schoenebeck 1225 /* -*- c++ -*-
2     * Copyright (C) 2006, 2007 Andreas Persson
3     *
4     * This program is free software; you can redistribute it and/or
5     * modify it under the terms of the GNU General Public License as
6     * published by the Free Software Foundation; either version 2, or (at
7     * your option) any later version.
8     *
9     * This program is distributed in the hope that it will be useful, but
10     * WITHOUT ANY WARRANTY; without even the implied warranty of
11     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12     * General Public License for more details.
13     *
14     * You should have received a copy of the GNU General Public License
15     * along with program; see the file COPYING. If not, write to the Free
16     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17     * 02110-1301 USA.
18     */
19    
20     #ifndef GIGEDIT_PARAMEDIT_H
21     #define GIGEDIT_PARAMEDIT_H
22    
23     #include <gig.h>
24    
25 schoenebeck 1300 #include <math.h>
26    
27 schoenebeck 1225 #include <gtkmm/adjustment.h>
28     #include <gtkmm/alignment.h>
29     #include <gtkmm/box.h>
30     #include <gtkmm/comboboxtext.h>
31     #include <gtkmm/label.h>
32     #include <gtkmm/scale.h>
33     #include <gtkmm/spinbutton.h>
34     #include <gtkmm/tooltips.h>
35    
36     class LabelWidget {
37     public:
38     Gtk::Label label;
39     Gtk::Widget& widget;
40    
41     LabelWidget(const char* labelText, Gtk::Widget& widget);
42     void set_sensitive(bool sensitive = true);
43 persson 1460 sigc::signal<void>& signal_value_changed() {
44 persson 1261 return sig_changed;
45     }
46 schoenebeck 1225 protected:
47     Gtk::Tooltips tooltips;
48 persson 1261 sigc::signal<void> sig_changed;
49 schoenebeck 1225 };
50    
51     class NumEntry : public LabelWidget {
52     protected:
53     Gtk::Adjustment adjust;
54     Gtk::HScale scale;
55     Gtk::SpinButton spinbutton;
56     Gtk::HBox box;
57 persson 1261
58     int round_to_int(double x) {
59     return int(x < 0.0 ? x - 0.5 : x + 0.5);
60     }
61 schoenebeck 1225 public:
62     NumEntry(const char* labelText, double lower = 0, double upper = 127,
63     int decimals = 0);
64     void set_tip(const Glib::ustring& tip_text) {
65     tooltips.set_tip(spinbutton, tip_text);
66     }
67     void set_upper(double upper) {
68     adjust.set_upper(upper);
69     }
70     };
71    
72     class NumEntryGain : public NumEntry {
73     private:
74 persson 1460 int32_t value;
75 schoenebeck 1225 void value_changed();
76     double coeff;
77 persson 1460 bool connected;
78 schoenebeck 1225 public:
79     NumEntryGain(const char* labelText,
80     double lower, double upper, int decimals, double coeff);
81 persson 1460 int32_t get_value() const { return value; }
82     void set_value(int32_t value);
83 schoenebeck 1225 };
84    
85     template<typename T>
86     class NumEntryTemp : public NumEntry {
87     private:
88 persson 1460 T value;
89 schoenebeck 1225 void value_changed();
90     public:
91     NumEntryTemp(const char* labelText,
92     double lower = 0, double upper = 127, int decimals = 0);
93 persson 1460 T get_value() const { return value; }
94     void set_value(T value);
95 schoenebeck 1225 };
96    
97     template<typename T>
98     NumEntryTemp<T>::NumEntryTemp(const char* labelText,
99     double lower, double upper, int decimals) :
100 persson 1460 NumEntry(labelText, lower, upper, decimals),
101     value(0)
102 schoenebeck 1225 {
103     spinbutton.signal_value_changed().connect(
104     sigc::mem_fun(*this, &NumEntryTemp::value_changed));
105     }
106    
107     template<typename T>
108     void NumEntryTemp<T>::value_changed()
109     {
110 schoenebeck 1359 const double f = pow(10, spinbutton.get_digits());
111     int new_value = round_to_int(spinbutton.get_value() * f);
112 persson 1460 if (new_value != round_to_int(value * f)) {
113     value = T(new_value / f);
114     sig_changed();
115 schoenebeck 1225 }
116     }
117    
118     template<typename T>
119 persson 1460 void NumEntryTemp<T>::set_value(T value)
120 schoenebeck 1225 {
121 persson 1460 if (value > adjust.get_upper()) value = T(adjust.get_upper());
122     if (this->value != value) {
123     this->value = value;
124     const double f = pow(10, spinbutton.get_digits());
125     if (round_to_int(spinbutton.get_value() * f) != round_to_int(value * f)) {
126     spinbutton.set_value(value);
127     }
128     sig_changed();
129     }
130 schoenebeck 1225 }
131    
132    
133     class NoteEntry : public NumEntryTemp<uint8_t> {
134     public:
135     NoteEntry(const char* labelText);
136     private:
137     int on_input(double* new_value);
138     bool on_output();
139     };
140    
141    
142     class NumEntryPermille : public NumEntry {
143     private:
144 persson 1460 uint16_t value;
145 schoenebeck 1225 void value_changed();
146     public:
147     NumEntryPermille(const char* labelText,
148     double lower = 0, double upper = 127, int decimals = 0);
149 persson 1460 uint16_t get_value() const { return value; }
150     void set_value(uint16_t value);
151 schoenebeck 1225 };
152    
153    
154     template<typename T>
155     class ChoiceEntry : public LabelWidget {
156     private:
157     Gtk::ComboBoxText combobox;
158     Gtk::Alignment align;
159     const T* values;
160     public:
161     ChoiceEntry(const char* labelText);
162 persson 1460 T get_value() const;
163     void set_value(T value);
164 schoenebeck 1225 void set_choices(const char** texts, const T* values);
165 persson 1460
166 schoenebeck 1225 void set_tip(const Glib::ustring& tip_text) {
167     tooltips.set_tip(combobox, tip_text); //FIXME: don't Gtk::ComboBoxes support tooltips ???
168     }
169     };
170    
171     template<typename T>
172     ChoiceEntry<T>::ChoiceEntry(const char* labelText) :
173     align(0, 0, 0, 0),
174     LabelWidget(labelText, align)
175     {
176 persson 1460 combobox.signal_changed().connect(sig_changed.make_slot());
177 schoenebeck 1225 align.add(combobox);
178     }
179    
180     template<typename T>
181     void ChoiceEntry<T>::set_choices(const char** texts, const T* values)
182     {
183     for (int i = 0 ; texts[i] ; i++) {
184     combobox.append_text(texts[i]);
185     }
186     this->values = values;
187     }
188    
189     template<typename T>
190 persson 1460 T ChoiceEntry<T>::get_value() const
191 schoenebeck 1225 {
192 schoenebeck 1359 int rowno = combobox.get_active_row_number();
193 persson 1460 return values[rowno];
194 schoenebeck 1225 }
195    
196     template<typename T>
197 persson 1460 void ChoiceEntry<T>::set_value(T value)
198 schoenebeck 1225 {
199 persson 1460 int row = 0;
200     int nb_rows = combobox.get_model()->children().size();
201     for (; row < nb_rows ; row++) {
202     if (value == values[row]) break;
203     }
204     combobox.set_active(row == nb_rows ? -1 : row);
205 schoenebeck 1225 }
206    
207    
208     class ChoiceEntryLeverageCtrl : public LabelWidget {
209     private:
210 persson 1460 gig::leverage_ctrl_t value;
211 schoenebeck 1225 Gtk::ComboBoxText combobox;
212     Gtk::Alignment align;
213     void value_changed();
214     public:
215     ChoiceEntryLeverageCtrl(const char* labelText);
216 persson 1460 gig::leverage_ctrl_t get_value() const { return value; }
217     void set_value(gig::leverage_ctrl_t value);
218 schoenebeck 1225 };
219    
220    
221     class BoolEntry : public LabelWidget {
222     private:
223     Gtk::CheckButton checkbutton;
224     public:
225     BoolEntry(const char* labelText);
226 persson 1460 bool get_value() const { return checkbutton.get_active(); }
227     void set_value(bool value) { checkbutton.set_active(value); }
228    
229 schoenebeck 1225 void set_tip(const Glib::ustring& tip_text) {
230     tooltips.set_tip(checkbutton, tip_text);
231     }
232     };
233    
234    
235     class BoolEntryPlus6 : public LabelWidget {
236     private:
237     Gtk::CheckButton checkbutton;
238     void value_changed();
239     NumEntryGain& eGain;
240     int32_t plus6value;
241     public:
242     BoolEntryPlus6(const char* labelText, NumEntryGain& eGain, int32_t plus6value);
243 persson 1460 int32_t get_value() const;
244     void set_value(int32_t value);
245 schoenebeck 1225 };
246    
247     class StringEntry : public LabelWidget {
248     private:
249     Gtk::Entry entry;
250     gig::String* ptr;
251     void value_changed();
252     public:
253     StringEntry(const char* labelText);
254     void set_ptr(gig::String* ptr);
255     };
256    
257    
258     #endif

  ViewVC Help
Powered by ViewVC