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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1582 - (hide annotations) (download) (as text)
Sat Dec 8 12:28:53 2007 UTC (16 years, 4 months ago) by persson
File MIME type: text/x-c++hdr
File size: 7246 byte(s)
* fixed file properties dialog - properties can now be edited

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

  ViewVC Help
Powered by ViewVC