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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1127 - (hide annotations) (download) (as text)
Sun Mar 25 07:16:01 2007 UTC (17 years, 1 month ago) by persson
File MIME type: text/x-c++hdr
File size: 9053 byte(s)
* fixed compilation with older gcc versions

1 persson 1100 /* -*- 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     #include <gtkmm/adjustment.h>
26     #include <gtkmm/alignment.h>
27     #include <gtkmm/box.h>
28     #include <gtkmm/comboboxtext.h>
29     #include <gtkmm/label.h>
30     #include <gtkmm/scale.h>
31     #include <gtkmm/spinbutton.h>
32    
33     extern bool update_gui;
34    
35     class LabelWidget {
36     public:
37     Gtk::Label label;
38     Gtk::Widget& widget;
39    
40     LabelWidget(char* labelText, Gtk::Widget& widget);
41     void set_sensitive(bool sensitive = true);
42     };
43    
44     template<typename T2>
45     class NumEntry : public LabelWidget {
46     protected:
47     Gtk::Adjustment adjust;
48     Gtk::HScale scale;
49     Gtk::SpinButton spinbutton;
50     Gtk::HBox box;
51     T2* dimreg;
52     public:
53     NumEntry(char* labelText, double lower = 0, double upper = 127,
54     int decimals = 0);
55     void set_value(double value) {
56     spinbutton.set_value(value);
57     }
58     Glib::SignalProxy0<void> signal_value_changed() {
59     return spinbutton.signal_value_changed();
60     }
61     double get_value() const {
62     return spinbutton.get_value();
63     }
64     };
65    
66     template<typename T2>
67     NumEntry<T2>::NumEntry(char* labelText, double lower, double upper,
68     int decimals) :
69     adjust(lower, lower, upper, 1, 10),
70     scale(adjust),
71     spinbutton(adjust),
72     LabelWidget(labelText, box)
73     {
74     spinbutton.set_digits(decimals);
75     scale.set_draw_value(false);
76     box.pack_start(spinbutton, Gtk::PACK_SHRINK);
77     box.add(scale);
78     }
79    
80     class NumEntryGain : public NumEntry<gig::DimensionRegion> {
81     private:
82     void value_changed();
83     public:
84     NumEntryGain(char* labelText,
85 persson 1117 double lower, double upper, int decimals);
86 persson 1100 void set_dimreg(gig::DimensionRegion* dimreg);
87     };
88    
89 persson 1117 template<typename T, typename T2 = gig::DimensionRegion>
90     class NumEntryX : public NumEntry<T2> {
91 persson 1127 protected:
92 persson 1117 using NumEntry<T2>::spinbutton;
93     using NumEntry<T2>::dimreg;
94 persson 1100 private:
95 persson 1117 T& (*access)(T2*);
96 persson 1100 void value_changed();
97     public:
98 persson 1117 NumEntryX(char* labelText, T& (*access)(T2*),
99 persson 1100 double lower = 0, double upper = 127, int decimals = 0);
100 persson 1117 void set_dimreg(T2* dimreg);
101 persson 1100 };
102    
103 persson 1117 template<typename T, typename T2>
104     NumEntryX<T, T2>::NumEntryX(char* labelText, T& (*access)(T2*),
105     double lower, double upper, int decimals) :
106     NumEntry<T2>(labelText, lower, upper, decimals),
107 persson 1100 access(access)
108     {
109     spinbutton.signal_value_changed().connect(
110     sigc::mem_fun(*this, &NumEntryX::value_changed));
111     }
112    
113 persson 1117 template<typename T, typename T2>
114     void NumEntryX<T, T2>::value_changed()
115 persson 1100 {
116     if (dimreg && update_gui) {
117     access(dimreg) = T(spinbutton.get_value());
118     }
119     }
120    
121 persson 1117 template<typename T, typename T2>
122     void NumEntryX<T, T2>::set_dimreg(T2* dimreg)
123 persson 1100 {
124     this->dimreg = 0;
125     set_value(access(dimreg));
126     this->dimreg = dimreg;
127     }
128    
129    
130     class NoteEntry : public NumEntryX<uint8_t> {
131     public:
132     NoteEntry(char* labelText, uint8_t& (*access)(gig::DimensionRegion*));
133     private:
134     int on_input(double* new_value);
135     bool on_output();
136     };
137    
138    
139     template<typename T, typename T2 = gig::DimensionRegion>
140     class NumEntryTemp : public NumEntry<T2> {
141     using NumEntry<T2>::spinbutton;
142     using NumEntry<T2>::dimreg;
143     private:
144     T T2::* param;
145     void value_changed();
146     public:
147     NumEntryTemp(char* labelText, T T2::* param,
148     double lower = 0, double upper = 127, int decimals = 0);
149 persson 1117 void set_dimreg(T2* dimreg);
150 persson 1100 };
151    
152     template<typename T, typename T2>
153     NumEntryTemp<T, T2>::NumEntryTemp(char* labelText, T T2::* param,
154     double lower, double upper, int decimals) :
155     NumEntry<T2>(labelText, lower, upper, decimals),
156     param(param)
157     {
158     spinbutton.signal_value_changed().connect(
159 persson 1117 sigc::mem_fun(*this, &NumEntryTemp::value_changed));
160 persson 1100 }
161    
162     template<typename T, typename T2>
163     void NumEntryTemp<T, T2>::value_changed()
164     {
165     if (dimreg && update_gui) {
166     dimreg->*param = T(spinbutton.get_value());
167     }
168     }
169    
170     template<typename T, typename T2>
171 persson 1117 void NumEntryTemp<T, T2>::set_dimreg(T2* dimreg)
172 persson 1100 {
173     this->dimreg = 0;
174     set_value(dimreg->*param);
175     this->dimreg = dimreg;
176     }
177    
178    
179    
180     class NumEntryPermille : public NumEntry<gig::DimensionRegion> {
181     private:
182     uint16_t gig::DimensionRegion::* param;
183     void value_changed();
184     public:
185     NumEntryPermille(char* labelText, uint16_t gig::DimensionRegion::* param,
186     double lower = 0, double upper = 127, int decimals = 0);
187     void set_dimreg(gig::DimensionRegion* dimreg);
188     };
189    
190    
191     template<typename T>
192     class ChoiceEntry : public LabelWidget {
193     private:
194     Gtk::ComboBoxText combobox;
195     Gtk::Alignment align;
196     T gig::DimensionRegion::* param;
197     gig::DimensionRegion* dimreg;
198     void value_changed();
199     const T* values;
200     public:
201     ChoiceEntry(char* labelText,
202     T gig::DimensionRegion::* param);
203     void set_choices(char** texts, const T* values);
204     void set_dimreg(gig::DimensionRegion* dimreg);
205     int get_active_row_number() { return combobox.get_active_row_number(); }
206     Glib::SignalProxy0<void> signal_changed() {
207     return combobox.signal_changed();
208     }
209     };
210    
211     template<typename T>
212     ChoiceEntry<T>::ChoiceEntry(char* labelText,
213     T gig::DimensionRegion::* param) :
214     align(0, 0, 0, 0),
215     LabelWidget(labelText, align),
216     param(param)
217     {
218     combobox.signal_changed().connect(
219     sigc::mem_fun(*this, &ChoiceEntry::value_changed));
220     align.add(combobox);
221     }
222    
223     template<typename T>
224     void ChoiceEntry<T>::set_choices(char** texts, const T* values)
225     {
226     for (int i = 0 ; texts[i] ; i++) {
227     combobox.append_text(texts[i]);
228     }
229     this->values = values;
230     }
231    
232     template<typename T>
233     void ChoiceEntry<T>::value_changed()
234     {
235     if (dimreg && update_gui) {
236     int rowno = combobox.get_active_row_number();
237     if (rowno != -1) dimreg->*param = values[rowno];
238     }
239     }
240    
241     template<typename T>
242     void ChoiceEntry<T>::set_dimreg(gig::DimensionRegion* dimreg)
243     {
244     this->dimreg = 0;
245     T value = dimreg->*param;
246     int row = 0;
247     int nb_rows = combobox.get_model()->children().size();
248     for (; row < nb_rows ; row++) {
249     if (value == values[row]) break;
250     }
251     combobox.set_active(row == nb_rows ? -1 : row);
252     this->dimreg = dimreg;
253     }
254    
255    
256     class ChoiceEntryLeverageCtrl : public LabelWidget {
257     private:
258     Gtk::ComboBoxText combobox;
259     Gtk::Alignment align;
260     gig::leverage_ctrl_t gig::DimensionRegion::* param;
261     gig::DimensionRegion* dimreg;
262     void value_changed();
263     public:
264     ChoiceEntryLeverageCtrl(char* labelText,
265     gig::leverage_ctrl_t gig::DimensionRegion::* param);
266     void set_dimreg(gig::DimensionRegion* dimreg);
267     int get_active_row_number() { return combobox.get_active_row_number(); }
268     Glib::SignalProxy0<void> signal_changed() {
269     return combobox.signal_changed();
270     }
271     };
272    
273    
274 persson 1117 template<typename T2>
275 persson 1100 class BoolEntry : public LabelWidget {
276     private:
277     Gtk::CheckButton checkbutton;
278 persson 1117 bool T2::* param;
279     T2* dimreg;
280     void value_changed();
281     public:
282     BoolEntry(char* labelText, bool T2::* param);
283     void set_dimreg(T2* dimreg);
284     bool get_active() { return checkbutton.get_active(); }
285     Glib::SignalProxy0<void> signal_toggled() {
286     return checkbutton.signal_toggled();
287     }
288     };
289    
290     template<typename T2>
291     BoolEntry<T2>::BoolEntry(char* labelText, bool T2::* param) :
292     LabelWidget(labelText, checkbutton),
293     param(param)
294     {
295     checkbutton.signal_toggled().connect(
296     sigc::mem_fun(*this, &BoolEntry::value_changed));
297     }
298    
299     template<typename T2>
300     void BoolEntry<T2>::value_changed()
301     {
302     if (dimreg && update_gui) {
303     dimreg->*param = checkbutton.get_active();
304     }
305     }
306    
307     template<typename T2>
308     void BoolEntry<T2>::set_dimreg(T2* dimreg)
309     {
310     this->dimreg = 0;
311     checkbutton.set_active(dimreg->*param);
312     this->dimreg = dimreg;
313     }
314    
315     class BoolEntryPlus6 : public LabelWidget {
316     private:
317     Gtk::CheckButton checkbutton;
318 persson 1100 gig::DimensionRegion* dimreg;
319     void value_changed();
320 persson 1117 NumEntryGain& eGain;
321 persson 1100 public:
322 persson 1117 BoolEntryPlus6(char* labelText, NumEntryGain& eGain);
323 persson 1100 void set_dimreg(gig::DimensionRegion* dimreg);
324     bool get_active() { return checkbutton.get_active(); }
325     Glib::SignalProxy0<void> signal_toggled() {
326     return checkbutton.signal_toggled();
327     }
328     };
329    
330     #endif

  ViewVC Help
Powered by ViewVC