/[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 1225 - (show annotations) (download) (as text)
Sun Jun 10 10:56:11 2007 UTC (16 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 7046 byte(s)
moved gigedit sources from src/ -> src/gigedit/

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

  ViewVC Help
Powered by ViewVC