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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1300 by schoenebeck, Fri Aug 24 19:11:41 2007 UTC revision 2151 by persson, Sun Nov 21 12:38:41 2010 UTC
# Line 1  Line 1 
1  /*                                                         -*- c++ -*-  /*                                                         -*- c++ -*-
2   * Copyright (C) 2006, 2007 Andreas Persson   * Copyright (C) 2006-2010 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 22  Line 22 
22    
23  #include <gig.h>  #include <gig.h>
24    
25  #include <math.h>  #include <cmath>
26    
27  #include <gtkmm/adjustment.h>  #include <gtkmm/adjustment.h>
28  #include <gtkmm/alignment.h>  #include <gtkmm/alignment.h>
29  #include <gtkmm/box.h>  #include <gtkmm/box.h>
30  #include <gtkmm/comboboxtext.h>  #include <gtkmm/comboboxtext.h>
31    #include <gtkmm/frame.h>
32  #include <gtkmm/label.h>  #include <gtkmm/label.h>
33  #include <gtkmm/scale.h>  #include <gtkmm/scale.h>
34  #include <gtkmm/spinbutton.h>  #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>  #include <gtkmm/tooltips.h>
40    #endif
41    
42  class LabelWidget {  class LabelWidget {
43  public:  public:
# Line 40  public: Line 46  public:
46    
47      LabelWidget(const char* labelText, Gtk::Widget& widget);      LabelWidget(const char* labelText, Gtk::Widget& widget);
48      void set_sensitive(bool sensitive = true);      void set_sensitive(bool sensitive = true);
49      sigc::signal<void> signal_changed_by_user() {      sigc::signal<void>& signal_value_changed() {
50          return sig_changed;          return sig_changed;
51      }      }
52  protected:  protected:
53    #ifdef OLD_TOOLTIPS
54      Gtk::Tooltips tooltips;      Gtk::Tooltips tooltips;
55    #endif
56      sigc::signal<void> sig_changed;      sigc::signal<void> sig_changed;
57  };  };
58    
# Line 61  protected: Line 69  protected:
69  public:  public:
70      NumEntry(const char* labelText, double lower = 0, double upper = 127,      NumEntry(const char* labelText, double lower = 0, double upper = 127,
71               int decimals = 0);               int decimals = 0);
     void set_value(double value) {  
         spinbutton.set_value(value);  
     }  
     double get_value() const {  
         return spinbutton.get_value();  
     }  
72      void set_tip(const Glib::ustring& tip_text) {      void set_tip(const Glib::ustring& tip_text) {
73    #ifdef OLD_TOOLTIPS
74          tooltips.set_tip(spinbutton, tip_text);          tooltips.set_tip(spinbutton, tip_text);
75    #else
76            spinbutton.set_tooltip_text(tip_text);
77    #endif
78      }      }
79      void set_upper(double upper) {      void set_upper(double upper) {
80          adjust.set_upper(upper);          adjust.set_upper(upper);
# Line 77  public: Line 83  public:
83    
84  class NumEntryGain : public NumEntry {  class NumEntryGain : public NumEntry {
85  private:  private:
86        int32_t value;
87      void value_changed();      void value_changed();
     int32_t* ptr;  
88      double coeff;      double coeff;
89        bool connected;
90  public:  public:
91      NumEntryGain(const char* labelText,      NumEntryGain(const char* labelText,
92                   double lower, double upper, int decimals, double coeff);                   double lower, double upper, int decimals, double coeff);
93      void set_ptr(int32_t* ptr);      int32_t get_value() const { return value; }
94        void set_value(int32_t value);
95  };  };
96    
97  template<typename T>  template<typename T>
98  class NumEntryTemp : public NumEntry {  class NumEntryTemp : public NumEntry {
99  private:  private:
100      T* ptr;      T value;
101      void value_changed();      void value_changed();
102  public:  public:
103      NumEntryTemp(const char* labelText,      NumEntryTemp(const char* labelText,
104                   double lower = 0, double upper = 127, int decimals = 0);                   double lower = 0, double upper = 127, int decimals = 0);
105      void set_ptr(T* ptr);      T get_value() const { return value; }
106        void set_value(T value);
107  };  };
108    
109  template<typename T>  template<typename T>
110  NumEntryTemp<T>::NumEntryTemp(const char* labelText,  NumEntryTemp<T>::NumEntryTemp(const char* labelText,
111                                double lower, double upper, int decimals) :                                double lower, double upper, int decimals) :
112      NumEntry(labelText, lower, upper, decimals)      NumEntry(labelText, lower, upper, decimals),
113        value(0)
114  {  {
115      spinbutton.signal_value_changed().connect(      spinbutton.signal_value_changed().connect(
116          sigc::mem_fun(*this, &NumEntryTemp::value_changed));          sigc::mem_fun(*this, &NumEntryTemp::value_changed));
# Line 109  NumEntryTemp<T>::NumEntryTemp(const char Line 119  NumEntryTemp<T>::NumEntryTemp(const char
119  template<typename T>  template<typename T>
120  void NumEntryTemp<T>::value_changed()  void NumEntryTemp<T>::value_changed()
121  {  {
122      if (ptr) {      const double f = pow(10, spinbutton.get_digits());
123          const double f = pow(10, spinbutton.get_digits());      int new_value = round_to_int(spinbutton.get_value() * f);
124          int new_value = round_to_int(spinbutton.get_value() * f);      if (new_value != round_to_int(value * f)) {
125          if (new_value != round_to_int(*ptr * f)) {          value = T(new_value / f);
126              *ptr = T(new_value / f);          sig_changed();
             sig_changed();  
         }  
127      }      }
128  }  }
129    
130  template<typename T>  template<typename T>
131  void NumEntryTemp<T>::set_ptr(T* ptr)  void NumEntryTemp<T>::set_value(T value)
132  {  {
133      this->ptr = 0;      if (value > adjust.get_upper()) value = T(adjust.get_upper());
134      if (ptr) set_value(*ptr);      if (this->value != value) {
135      this->ptr = ptr;          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    
# Line 139  private: Line 153  private:
153    
154  class NumEntryPermille : public NumEntry {  class NumEntryPermille : public NumEntry {
155  private:  private:
156      uint16_t* ptr;      uint16_t value;
157      void value_changed();      void value_changed();
158  public:  public:
159      NumEntryPermille(const char* labelText,      NumEntryPermille(const char* labelText,
160                       double lower = 0, double upper = 127, int decimals = 0);                       double lower = 0, double upper = 127, int decimals = 0);
161      void set_ptr(uint16_t* ptr);      uint16_t get_value() const { return value; }
162        void set_value(uint16_t value);
163  };  };
164    
165    
# Line 153  class ChoiceEntry : public LabelWidget { Line 168  class ChoiceEntry : public LabelWidget {
168  private:  private:
169      Gtk::ComboBoxText combobox;      Gtk::ComboBoxText combobox;
170      Gtk::Alignment align;      Gtk::Alignment align;
     T* ptr;  
     void value_changed();  
171      const T* values;      const T* values;
172  public:  public:
173      ChoiceEntry(const char* labelText);      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);      void set_choices(const char** texts, const T* values);
177      void set_ptr(T* ptr);  
     int get_active_row_number() { return combobox.get_active_row_number(); }  
     Glib::SignalProxy0<void> signal_changed() {  
         return combobox.signal_changed();  
     }  
178      void set_tip(const Glib::ustring& tip_text) {      void set_tip(const Glib::ustring& tip_text) {
179          tooltips.set_tip(combobox, tip_text); //FIXME: don't Gtk::ComboBoxes support tooltips ???  #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>  template<typename T>
188  ChoiceEntry<T>::ChoiceEntry(const char* labelText) :  ChoiceEntry<T>::ChoiceEntry(const char* labelText) :
189      align(0, 0, 0, 0),      LabelWidget(labelText, align),
190      LabelWidget(labelText, align)      align(0, 0, 0, 0)
191  {  {
192      combobox.signal_changed().connect(      combobox.signal_changed().connect(sig_changed.make_slot());
         sigc::mem_fun(*this, &ChoiceEntry::value_changed));  
193      align.add(combobox);      align.add(combobox);
194  }  }
195    
# Line 189  void ChoiceEntry<T>::set_choices(const c Line 203  void ChoiceEntry<T>::set_choices(const c
203  }  }
204    
205  template<typename T>  template<typename T>
206  void ChoiceEntry<T>::value_changed()  T ChoiceEntry<T>::get_value() const
207  {  {
208      if (ptr) {      int rowno = combobox.get_active_row_number();
209          int rowno = combobox.get_active_row_number();      return values[rowno];
         if (rowno != -1) {  
             *ptr = values[rowno];  
             sig_changed();  
         }  
     }  
210  }  }
211    
212  template<typename T>  template<typename T>
213  void ChoiceEntry<T>::set_ptr(T* ptr)  void ChoiceEntry<T>::set_value(T value)
214  {  {
215      this->ptr = 0;      int row = 0;
216      if (ptr) {      int nb_rows = combobox.get_model()->children().size();
217          T value = *ptr;      for (; row < nb_rows ; row++) {
218          int row = 0;          if (value == values[row]) break;
219          int nb_rows = combobox.get_model()->children().size();      }
220          for (; row < nb_rows ; row++) {      combobox.set_active(row == nb_rows ? -1 : row);
             if (value == values[row]) break;  
         }  
         combobox.set_active(row == nb_rows ? -1 : row);  
     } else combobox.set_active(-1);  
     this->ptr = ptr;  
221  }  }
222    
223    
224  class ChoiceEntryLeverageCtrl : public LabelWidget {  class ChoiceEntryLeverageCtrl : public LabelWidget {
225  private:  private:
226        gig::leverage_ctrl_t value;
227      Gtk::ComboBoxText combobox;      Gtk::ComboBoxText combobox;
228      Gtk::Alignment align;      Gtk::Alignment align;
     gig::leverage_ctrl_t* ptr;  
229      void value_changed();      void value_changed();
230  public:  public:
231      ChoiceEntryLeverageCtrl(const char* labelText);      ChoiceEntryLeverageCtrl(const char* labelText);
232      void set_ptr(gig::leverage_ctrl_t* ptr);      gig::leverage_ctrl_t get_value() const { return value; }
233      int get_active_row_number() { return combobox.get_active_row_number(); }      void set_value(gig::leverage_ctrl_t value);
     Glib::SignalProxy0<void> signal_changed() {  
         return combobox.signal_changed();  
     }  
234  };  };
235    
236    
237  class BoolEntry : public LabelWidget {  class BoolEntry : public LabelWidget {
238  private:  private:
239      Gtk::CheckButton checkbutton;      Gtk::CheckButton checkbutton;
     bool* ptr;  
     void value_changed();  
240  public:  public:
241      BoolEntry(const char* labelText);      BoolEntry(const char* labelText);
242      bool get_active() { return checkbutton.get_active(); }      bool get_value() const { return checkbutton.get_active(); }
243      bool set_active(bool b) { checkbutton.set_active(b); }      void set_value(bool value) { checkbutton.set_active(value); }
244      Glib::SignalProxy0<void> signal_toggled() {  
         return checkbutton.signal_toggled();  
     }  
     void set_ptr(bool* ptr);  
245      void set_tip(const Glib::ustring& tip_text) {      void set_tip(const Glib::ustring& tip_text) {
246    #ifdef OLD_TOOLTIPS
247          tooltips.set_tip(checkbutton, tip_text);          tooltips.set_tip(checkbutton, tip_text);
248    #else
249            checkbutton.set_tooltip_text(tip_text);
250    #endif
251      }      }
252  };  };
253    
# Line 255  public: Line 255  public:
255  class BoolEntryPlus6 : public LabelWidget {  class BoolEntryPlus6 : public LabelWidget {
256  private:  private:
257      Gtk::CheckButton checkbutton;      Gtk::CheckButton checkbutton;
     int32_t* ptr;  
258      void value_changed();      void value_changed();
259      NumEntryGain& eGain;      NumEntryGain& eGain;
260      int32_t plus6value;      int32_t plus6value;
261  public:  public:
262      BoolEntryPlus6(const char* labelText, NumEntryGain& eGain, int32_t plus6value);      BoolEntryPlus6(const char* labelText, NumEntryGain& eGain, int32_t plus6value);
263      void set_ptr(int32_t* ptr);      int32_t get_value() const;
264      bool get_active() { return checkbutton.get_active(); }      void set_value(int32_t value);
     Glib::SignalProxy0<void> signal_toggled() {  
         return checkbutton.signal_toggled();  
     }  
265  };  };
266    
267  class StringEntry : public LabelWidget {  class StringEntry : public LabelWidget {
268  private:  private:
269      Gtk::Entry entry;      Gtk::Entry entry;
     gig::String* ptr;  
     void value_changed();  
270  public:  public:
271      StringEntry(const char* labelText);      StringEntry(const char* labelText);
272      void set_ptr(gig::String* ptr);      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    

Legend:
Removed from v.1300  
changed lines
  Added in v.2151

  ViewVC Help
Powered by ViewVC