/[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 2151 - (hide annotations) (download) (as text)
Sun Nov 21 12:38:41 2010 UTC (13 years, 4 months ago) by persson
File MIME type: text/x-c++hdr
File size: 7573 byte(s)
* use Cairo instead of deprecated gdk drawing primitives
* avoid deprecated gtk methods when using newer gtk versions
* raised minimum supported gtkmm version to 2.8

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

  ViewVC Help
Powered by ViewVC