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