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