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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2169 - (show 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 /* -*- c++ -*-
2 * Copyright (C) 2006-2011 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 <cmath>
26
27 #include <gtkmm/adjustment.h>
28 #include <gtkmm/alignment.h>
29 #include <gtkmm/box.h>
30 #include <gtkmm/checkbutton.h>
31 #include <gtkmm/comboboxtext.h>
32 #include <gtkmm/frame.h>
33 #include <gtkmm/label.h>
34 #include <gtkmm/scale.h>
35 #include <gtkmm/spinbutton.h>
36 #include <gtkmm/textview.h>
37
38 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 12) || GTKMM_MAJOR_VERSION < 2
39 #define OLD_TOOLTIPS
40 #include <gtkmm/tooltips.h>
41 #endif
42
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 sigc::signal<void>& signal_value_changed() {
51 return sig_changed;
52 }
53 protected:
54 #ifdef OLD_TOOLTIPS
55 Gtk::Tooltips tooltips;
56 #endif
57 sigc::signal<void> sig_changed;
58 };
59
60 class NumEntry : public LabelWidget {
61 protected:
62 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
63 Gtk::Adjustment adjust;
64 #else
65 Glib::RefPtr<Gtk::Adjustment> adjust;
66 #endif
67 Gtk::HScale scale;
68 Gtk::SpinButton spinbutton;
69 Gtk::HBox box;
70
71 int round_to_int(double x) {
72 return int(x < 0.0 ? x - 0.5 : x + 0.5);
73 }
74 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 #ifdef OLD_TOOLTIPS
79 tooltips.set_tip(spinbutton, tip_text);
80 #else
81 spinbutton.set_tooltip_text(tip_text);
82 #endif
83 }
84 void set_upper(double upper) {
85 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
86 adjust.set_upper(upper);
87 #else
88 adjust->set_upper(upper);
89 #endif
90 }
91 };
92
93 class NumEntryGain : public NumEntry {
94 private:
95 int32_t value;
96 void value_changed();
97 double coeff;
98 bool connected;
99 public:
100 NumEntryGain(const char* labelText,
101 double lower, double upper, int decimals, double coeff);
102 int32_t get_value() const { return value; }
103 void set_value(int32_t value);
104 };
105
106 template<typename T>
107 class NumEntryTemp : public NumEntry {
108 private:
109 T value;
110 void value_changed();
111 public:
112 NumEntryTemp(const char* labelText,
113 double lower = 0, double upper = 127, int decimals = 0);
114 T get_value() const { return value; }
115 void set_value(T value);
116 };
117
118 template<typename T>
119 NumEntryTemp<T>::NumEntryTemp(const char* labelText,
120 double lower, double upper, int decimals) :
121 NumEntry(labelText, lower, upper, decimals),
122 value(0)
123 {
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 const double f = pow(10, spinbutton.get_digits());
132 int new_value = round_to_int(spinbutton.get_value() * f);
133 if (new_value != round_to_int(value * f)) {
134 value = T(new_value / f);
135 sig_changed();
136 }
137 }
138
139 template<typename T>
140 void NumEntryTemp<T>::set_value(T value)
141 {
142 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
143 if (value > adjust.get_upper()) value = T(adjust.get_upper());
144 #else
145 if (value > adjust->get_upper()) value = T(adjust->get_upper());
146 #endif
147 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 }
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 uint16_t value;
170 void value_changed();
171 public:
172 NumEntryPermille(const char* labelText,
173 double lower = 0, double upper = 127, int decimals = 0);
174 uint16_t get_value() const { return value; }
175 void set_value(uint16_t value);
176 };
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 T get_value() const;
188 void set_value(T value);
189 void set_choices(const char** texts, const T* values);
190
191 void set_tip(const Glib::ustring& tip_text) {
192 #ifdef OLD_TOOLTIPS
193 tooltips.set_tip(combobox, tip_text);
194 #else
195 combobox.set_tooltip_text(tip_text);
196 #endif
197 }
198 };
199
200 template<typename T>
201 ChoiceEntry<T>::ChoiceEntry(const char* labelText) :
202 LabelWidget(labelText, align),
203 align(0, 0, 0, 0)
204 {
205 combobox.signal_changed().connect(sig_changed.make_slot());
206 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 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
214 combobox.append_text(texts[i]);
215 #else
216 combobox.append(texts[i]);
217 #endif
218 }
219 this->values = values;
220 }
221
222 template<typename T>
223 T ChoiceEntry<T>::get_value() const
224 {
225 int rowno = combobox.get_active_row_number();
226 return values[rowno];
227 }
228
229 template<typename T>
230 void ChoiceEntry<T>::set_value(T value)
231 {
232 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 }
239
240
241 class ChoiceEntryLeverageCtrl : public LabelWidget {
242 private:
243 gig::leverage_ctrl_t value;
244 Gtk::ComboBoxText combobox;
245 Gtk::Alignment align;
246 void value_changed();
247 public:
248 ChoiceEntryLeverageCtrl(const char* labelText);
249 gig::leverage_ctrl_t get_value() const { return value; }
250 void set_value(gig::leverage_ctrl_t value);
251 };
252
253
254 class BoolEntry : public LabelWidget {
255 private:
256 Gtk::CheckButton checkbutton;
257 public:
258 BoolEntry(const char* labelText);
259 bool get_value() const { return checkbutton.get_active(); }
260 void set_value(bool value) { checkbutton.set_active(value); }
261
262 void set_tip(const Glib::ustring& tip_text) {
263 #ifdef OLD_TOOLTIPS
264 tooltips.set_tip(checkbutton, tip_text);
265 #else
266 checkbutton.set_tooltip_text(tip_text);
267 #endif
268 }
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 int32_t get_value() const;
281 void set_value(int32_t value);
282 };
283
284 class StringEntry : public LabelWidget {
285 private:
286 Gtk::Entry entry;
287 public:
288 StringEntry(const char* labelText);
289 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 };
293
294 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
305
306 #endif

  ViewVC Help
Powered by ViewVC