/[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 2169 - (hide annotations) (download) (as text)
Sun Mar 6 07:51:04 2011 UTC (13 years, 1 month ago) by persson
File MIME type: text/x-c++hdr
File size: 8180 byte(s)
* ported to gtkmm 3, keeping compatibility with gtkmm 2

1 schoenebeck 1225 /* -*- c++ -*-
2 persson 2169 * Copyright (C) 2006-2011 Andreas Persson
3 schoenebeck 1225 *
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 persson 2151 #include <cmath>
26 schoenebeck 1300
27 schoenebeck 1225 #include <gtkmm/adjustment.h>
28     #include <gtkmm/alignment.h>
29     #include <gtkmm/box.h>
30 persson 2169 #include <gtkmm/checkbutton.h>
31 schoenebeck 1225 #include <gtkmm/comboboxtext.h>
32 persson 1582 #include <gtkmm/frame.h>
33 schoenebeck 1225 #include <gtkmm/label.h>
34     #include <gtkmm/scale.h>
35     #include <gtkmm/spinbutton.h>
36 persson 1582 #include <gtkmm/textview.h>
37 persson 2151
38     #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 12) || GTKMM_MAJOR_VERSION < 2
39     #define OLD_TOOLTIPS
40 schoenebeck 1225 #include <gtkmm/tooltips.h>
41 persson 2151 #endif
42 schoenebeck 1225
43     class LabelWidget {
44     public:
45     Gtk::Label label;
46     Gtk::Widget& widget;
47    
48     LabelWidget(const char* labelText, Gtk::Widget& widget);
49     void set_sensitive(bool sensitive = true);
50 persson 1460 sigc::signal<void>& signal_value_changed() {
51 persson 1261 return sig_changed;
52     }
53 schoenebeck 1225 protected:
54 persson 2151 #ifdef OLD_TOOLTIPS
55 schoenebeck 1225 Gtk::Tooltips tooltips;
56 persson 2151 #endif
57 persson 1261 sigc::signal<void> sig_changed;
58 schoenebeck 1225 };
59    
60     class NumEntry : public LabelWidget {
61     protected:
62 persson 2169 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
63 schoenebeck 1225 Gtk::Adjustment adjust;
64 persson 2169 #else
65     Glib::RefPtr<Gtk::Adjustment> adjust;
66     #endif
67 schoenebeck 1225 Gtk::HScale scale;
68     Gtk::SpinButton spinbutton;
69     Gtk::HBox box;
70 persson 1261
71     int round_to_int(double x) {
72     return int(x < 0.0 ? x - 0.5 : x + 0.5);
73     }
74 schoenebeck 1225 public:
75     NumEntry(const char* labelText, double lower = 0, double upper = 127,
76     int decimals = 0);
77     void set_tip(const Glib::ustring& tip_text) {
78 persson 2151 #ifdef OLD_TOOLTIPS
79 schoenebeck 1225 tooltips.set_tip(spinbutton, tip_text);
80 persson 2151 #else
81     spinbutton.set_tooltip_text(tip_text);
82     #endif
83 schoenebeck 1225 }
84     void set_upper(double upper) {
85 persson 2169 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
86 schoenebeck 1225 adjust.set_upper(upper);
87 persson 2169 #else
88     adjust->set_upper(upper);
89     #endif
90 schoenebeck 1225 }
91     };
92    
93     class NumEntryGain : public NumEntry {
94     private:
95 persson 1460 int32_t value;
96 schoenebeck 1225 void value_changed();
97     double coeff;
98 persson 1460 bool connected;
99 schoenebeck 1225 public:
100     NumEntryGain(const char* labelText,
101     double lower, double upper, int decimals, double coeff);
102 persson 1460 int32_t get_value() const { return value; }
103     void set_value(int32_t value);
104 schoenebeck 1225 };
105    
106     template<typename T>
107     class NumEntryTemp : public NumEntry {
108     private:
109 persson 1460 T value;
110 schoenebeck 1225 void value_changed();
111     public:
112     NumEntryTemp(const char* labelText,
113     double lower = 0, double upper = 127, int decimals = 0);
114 persson 1460 T get_value() const { return value; }
115     void set_value(T value);
116 schoenebeck 1225 };
117    
118     template<typename T>
119     NumEntryTemp<T>::NumEntryTemp(const char* labelText,
120     double lower, double upper, int decimals) :
121 persson 1460 NumEntry(labelText, lower, upper, decimals),
122     value(0)
123 schoenebeck 1225 {
124     spinbutton.signal_value_changed().connect(
125     sigc::mem_fun(*this, &NumEntryTemp::value_changed));
126     }
127    
128     template<typename T>
129     void NumEntryTemp<T>::value_changed()
130     {
131 schoenebeck 1359 const double f = pow(10, spinbutton.get_digits());
132     int new_value = round_to_int(spinbutton.get_value() * f);
133 persson 1460 if (new_value != round_to_int(value * f)) {
134     value = T(new_value / f);
135     sig_changed();
136 schoenebeck 1225 }
137     }
138    
139     template<typename T>
140 persson 1460 void NumEntryTemp<T>::set_value(T value)
141 schoenebeck 1225 {
142 persson 2169 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
143 persson 1460 if (value > adjust.get_upper()) value = T(adjust.get_upper());
144 persson 2169 #else
145     if (value > adjust->get_upper()) value = T(adjust->get_upper());
146     #endif
147 persson 1460 if (this->value != value) {
148     this->value = value;
149     const double f = pow(10, spinbutton.get_digits());
150     if (round_to_int(spinbutton.get_value() * f) != round_to_int(value * f)) {
151     spinbutton.set_value(value);
152     }
153     sig_changed();
154     }
155 schoenebeck 1225 }
156    
157    
158     class NoteEntry : public NumEntryTemp<uint8_t> {
159     public:
160     NoteEntry(const char* labelText);
161     private:
162     int on_input(double* new_value);
163     bool on_output();
164     };
165    
166    
167     class NumEntryPermille : public NumEntry {
168     private:
169 persson 1460 uint16_t value;
170 schoenebeck 1225 void value_changed();
171     public:
172     NumEntryPermille(const char* labelText,
173     double lower = 0, double upper = 127, int decimals = 0);
174 persson 1460 uint16_t get_value() const { return value; }
175     void set_value(uint16_t value);
176 schoenebeck 1225 };
177    
178    
179     template<typename T>
180     class ChoiceEntry : public LabelWidget {
181     private:
182     Gtk::ComboBoxText combobox;
183     Gtk::Alignment align;
184     const T* values;
185     public:
186     ChoiceEntry(const char* labelText);
187 persson 1460 T get_value() const;
188     void set_value(T value);
189 schoenebeck 1225 void set_choices(const char** texts, const T* values);
190 persson 1460
191 schoenebeck 1225 void set_tip(const Glib::ustring& tip_text) {
192 persson 2151 #ifdef OLD_TOOLTIPS
193     tooltips.set_tip(combobox, tip_text);
194     #else
195     combobox.set_tooltip_text(tip_text);
196     #endif
197 schoenebeck 1225 }
198     };
199    
200     template<typename T>
201     ChoiceEntry<T>::ChoiceEntry(const char* labelText) :
202 persson 2151 LabelWidget(labelText, align),
203     align(0, 0, 0, 0)
204 schoenebeck 1225 {
205 persson 1460 combobox.signal_changed().connect(sig_changed.make_slot());
206 schoenebeck 1225 align.add(combobox);
207     }
208    
209     template<typename T>
210     void ChoiceEntry<T>::set_choices(const char** texts, const T* values)
211     {
212     for (int i = 0 ; texts[i] ; i++) {
213 persson 2169 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
214 schoenebeck 1225 combobox.append_text(texts[i]);
215 persson 2169 #else
216     combobox.append(texts[i]);
217     #endif
218 schoenebeck 1225 }
219     this->values = values;
220     }
221    
222     template<typename T>
223 persson 1460 T ChoiceEntry<T>::get_value() const
224 schoenebeck 1225 {
225 schoenebeck 1359 int rowno = combobox.get_active_row_number();
226 persson 1460 return values[rowno];
227 schoenebeck 1225 }
228    
229     template<typename T>
230 persson 1460 void ChoiceEntry<T>::set_value(T value)
231 schoenebeck 1225 {
232 persson 1460 int row = 0;
233     int nb_rows = combobox.get_model()->children().size();
234     for (; row < nb_rows ; row++) {
235     if (value == values[row]) break;
236     }
237     combobox.set_active(row == nb_rows ? -1 : row);
238 schoenebeck 1225 }
239    
240    
241     class ChoiceEntryLeverageCtrl : public LabelWidget {
242     private:
243 persson 1460 gig::leverage_ctrl_t value;
244 schoenebeck 1225 Gtk::ComboBoxText combobox;
245     Gtk::Alignment align;
246     void value_changed();
247     public:
248     ChoiceEntryLeverageCtrl(const char* labelText);
249 persson 1460 gig::leverage_ctrl_t get_value() const { return value; }
250     void set_value(gig::leverage_ctrl_t value);
251 schoenebeck 1225 };
252    
253    
254     class BoolEntry : public LabelWidget {
255     private:
256     Gtk::CheckButton checkbutton;
257     public:
258     BoolEntry(const char* labelText);
259 persson 1460 bool get_value() const { return checkbutton.get_active(); }
260     void set_value(bool value) { checkbutton.set_active(value); }
261    
262 schoenebeck 1225 void set_tip(const Glib::ustring& tip_text) {
263 persson 2151 #ifdef OLD_TOOLTIPS
264 schoenebeck 1225 tooltips.set_tip(checkbutton, tip_text);
265 persson 2151 #else
266     checkbutton.set_tooltip_text(tip_text);
267     #endif
268 schoenebeck 1225 }
269     };
270    
271    
272     class BoolEntryPlus6 : public LabelWidget {
273     private:
274     Gtk::CheckButton checkbutton;
275     void value_changed();
276     NumEntryGain& eGain;
277     int32_t plus6value;
278     public:
279     BoolEntryPlus6(const char* labelText, NumEntryGain& eGain, int32_t plus6value);
280 persson 1460 int32_t get_value() const;
281     void set_value(int32_t value);
282 schoenebeck 1225 };
283    
284     class StringEntry : public LabelWidget {
285     private:
286     Gtk::Entry entry;
287     public:
288     StringEntry(const char* labelText);
289 persson 1582 gig::String get_value() const { return entry.get_text(); }
290     void set_value(gig::String value) { entry.set_text(value); }
291     void set_width_chars(int n_chars) { entry.set_width_chars(n_chars); }
292 schoenebeck 1225 };
293    
294 persson 1582 class StringEntryMultiLine : public LabelWidget {
295     private:
296     Gtk::TextView text_view;
297     Glib::RefPtr<Gtk::TextBuffer> text_buffer;
298     Gtk::Frame frame;
299     public:
300     StringEntryMultiLine(const char* labelText);
301     gig::String get_value() const;
302     void set_value(gig::String value);
303     };
304 schoenebeck 1225
305 persson 1582
306 schoenebeck 1225 #endif

  ViewVC Help
Powered by ViewVC