/[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 2151 - (show 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 /* -*- c++ -*-
2 * Copyright (C) 2006-2010 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/comboboxtext.h>
31 #include <gtkmm/frame.h>
32 #include <gtkmm/label.h>
33 #include <gtkmm/scale.h>
34 #include <gtkmm/spinbutton.h>
35 #include <gtkmm/textview.h>
36
37 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 12) || GTKMM_MAJOR_VERSION < 2
38 #define OLD_TOOLTIPS
39 #include <gtkmm/tooltips.h>
40 #endif
41
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 sigc::signal<void>& signal_value_changed() {
50 return sig_changed;
51 }
52 protected:
53 #ifdef OLD_TOOLTIPS
54 Gtk::Tooltips tooltips;
55 #endif
56 sigc::signal<void> sig_changed;
57 };
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
66 int round_to_int(double x) {
67 return int(x < 0.0 ? x - 0.5 : x + 0.5);
68 }
69 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 #ifdef OLD_TOOLTIPS
74 tooltips.set_tip(spinbutton, tip_text);
75 #else
76 spinbutton.set_tooltip_text(tip_text);
77 #endif
78 }
79 void set_upper(double upper) {
80 adjust.set_upper(upper);
81 }
82 };
83
84 class NumEntryGain : public NumEntry {
85 private:
86 int32_t value;
87 void value_changed();
88 double coeff;
89 bool connected;
90 public:
91 NumEntryGain(const char* labelText,
92 double lower, double upper, int decimals, double coeff);
93 int32_t get_value() const { return value; }
94 void set_value(int32_t value);
95 };
96
97 template<typename T>
98 class NumEntryTemp : public NumEntry {
99 private:
100 T value;
101 void value_changed();
102 public:
103 NumEntryTemp(const char* labelText,
104 double lower = 0, double upper = 127, int decimals = 0);
105 T get_value() const { return value; }
106 void set_value(T value);
107 };
108
109 template<typename T>
110 NumEntryTemp<T>::NumEntryTemp(const char* labelText,
111 double lower, double upper, int decimals) :
112 NumEntry(labelText, lower, upper, decimals),
113 value(0)
114 {
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 const double f = pow(10, spinbutton.get_digits());
123 int new_value = round_to_int(spinbutton.get_value() * f);
124 if (new_value != round_to_int(value * f)) {
125 value = T(new_value / f);
126 sig_changed();
127 }
128 }
129
130 template<typename T>
131 void NumEntryTemp<T>::set_value(T value)
132 {
133 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 }
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 uint16_t value;
157 void value_changed();
158 public:
159 NumEntryPermille(const char* labelText,
160 double lower = 0, double upper = 127, int decimals = 0);
161 uint16_t get_value() const { return value; }
162 void set_value(uint16_t value);
163 };
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 T get_value() const;
175 void set_value(T value);
176 void set_choices(const char** texts, const T* values);
177
178 void set_tip(const Glib::ustring& tip_text) {
179 #ifdef OLD_TOOLTIPS
180 tooltips.set_tip(combobox, tip_text);
181 #else
182 combobox.set_tooltip_text(tip_text);
183 #endif
184 }
185 };
186
187 template<typename T>
188 ChoiceEntry<T>::ChoiceEntry(const char* labelText) :
189 LabelWidget(labelText, align),
190 align(0, 0, 0, 0)
191 {
192 combobox.signal_changed().connect(sig_changed.make_slot());
193 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 T ChoiceEntry<T>::get_value() const
207 {
208 int rowno = combobox.get_active_row_number();
209 return values[rowno];
210 }
211
212 template<typename T>
213 void ChoiceEntry<T>::set_value(T value)
214 {
215 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 }
222
223
224 class ChoiceEntryLeverageCtrl : public LabelWidget {
225 private:
226 gig::leverage_ctrl_t value;
227 Gtk::ComboBoxText combobox;
228 Gtk::Alignment align;
229 void value_changed();
230 public:
231 ChoiceEntryLeverageCtrl(const char* labelText);
232 gig::leverage_ctrl_t get_value() const { return value; }
233 void set_value(gig::leverage_ctrl_t value);
234 };
235
236
237 class BoolEntry : public LabelWidget {
238 private:
239 Gtk::CheckButton checkbutton;
240 public:
241 BoolEntry(const char* labelText);
242 bool get_value() const { return checkbutton.get_active(); }
243 void set_value(bool value) { checkbutton.set_active(value); }
244
245 void set_tip(const Glib::ustring& tip_text) {
246 #ifdef OLD_TOOLTIPS
247 tooltips.set_tip(checkbutton, tip_text);
248 #else
249 checkbutton.set_tooltip_text(tip_text);
250 #endif
251 }
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 int32_t get_value() const;
264 void set_value(int32_t value);
265 };
266
267 class StringEntry : public LabelWidget {
268 private:
269 Gtk::Entry entry;
270 public:
271 StringEntry(const char* labelText);
272 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 };
276
277 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
288
289 #endif

  ViewVC Help
Powered by ViewVC