/[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 1261 by persson, Thu Jul 5 17:12:20 2007 UTC revision 1582 by persson, Sat Dec 8 12:28:53 2007 UTC
# Line 22  Line 22 
22    
23  #include <gig.h>  #include <gig.h>
24    
25    #include <math.h>
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  #include <gtkmm/tooltips.h>  #include <gtkmm/tooltips.h>
37    
38  class LabelWidget {  class LabelWidget {
# Line 38  public: Line 42  public:
42    
43      LabelWidget(const char* labelText, Gtk::Widget& widget);      LabelWidget(const char* labelText, Gtk::Widget& widget);
44      void set_sensitive(bool sensitive = true);      void set_sensitive(bool sensitive = true);
45      sigc::signal<void> signal_changed_by_user() {      sigc::signal<void>& signal_value_changed() {
46          return sig_changed;          return sig_changed;
47      }      }
48  protected:  protected:
# Line 59  protected: Line 63  protected:
63  public:  public:
64      NumEntry(const char* labelText, double lower = 0, double upper = 127,      NumEntry(const char* labelText, double lower = 0, double upper = 127,
65               int decimals = 0);               int decimals = 0);
     void set_value(double value) {  
         spinbutton.set_value(value);  
     }  
     double get_value() const {  
         return spinbutton.get_value();  
     }  
66      void set_tip(const Glib::ustring& tip_text) {      void set_tip(const Glib::ustring& tip_text) {
67          tooltips.set_tip(spinbutton, tip_text);          tooltips.set_tip(spinbutton, tip_text);
68      }      }
# Line 75  public: Line 73  public:
73    
74  class NumEntryGain : public NumEntry {  class NumEntryGain : public NumEntry {
75  private:  private:
76        int32_t value;
77      void value_changed();      void value_changed();
     int32_t* ptr;  
78      double coeff;      double coeff;
79        bool connected;
80  public:  public:
81      NumEntryGain(const char* labelText,      NumEntryGain(const char* labelText,
82                   double lower, double upper, int decimals, double coeff);                   double lower, double upper, int decimals, double coeff);
83      void set_ptr(int32_t* ptr);      int32_t get_value() const { return value; }
84        void set_value(int32_t value);
85  };  };
86    
87  template<typename T>  template<typename T>
88  class NumEntryTemp : public NumEntry {  class NumEntryTemp : public NumEntry {
89  private:  private:
90      T* ptr;      T value;
91      void value_changed();      void value_changed();
92  public:  public:
93      NumEntryTemp(const char* labelText,      NumEntryTemp(const char* labelText,
94                   double lower = 0, double upper = 127, int decimals = 0);                   double lower = 0, double upper = 127, int decimals = 0);
95      void set_ptr(T* ptr);      T get_value() const { return value; }
96        void set_value(T value);
97  };  };
98    
99  template<typename T>  template<typename T>
100  NumEntryTemp<T>::NumEntryTemp(const char* labelText,  NumEntryTemp<T>::NumEntryTemp(const char* labelText,
101                                double lower, double upper, int decimals) :                                double lower, double upper, int decimals) :
102      NumEntry(labelText, lower, upper, decimals)      NumEntry(labelText, lower, upper, decimals),
103        value(0)
104  {  {
105      spinbutton.signal_value_changed().connect(      spinbutton.signal_value_changed().connect(
106          sigc::mem_fun(*this, &NumEntryTemp::value_changed));          sigc::mem_fun(*this, &NumEntryTemp::value_changed));
# Line 107  NumEntryTemp<T>::NumEntryTemp(const char Line 109  NumEntryTemp<T>::NumEntryTemp(const char
109  template<typename T>  template<typename T>
110  void NumEntryTemp<T>::value_changed()  void NumEntryTemp<T>::value_changed()
111  {  {
112      if (ptr) {      const double f = pow(10, spinbutton.get_digits());
113          const double f = pow(10, spinbutton.get_digits());      int new_value = round_to_int(spinbutton.get_value() * f);
114          int new_value = round_to_int(spinbutton.get_value() * f);      if (new_value != round_to_int(value * f)) {
115          if (new_value != round_to_int(*ptr * f)) {          value = T(new_value / f);
116              *ptr = T(new_value / f);          sig_changed();
             sig_changed();  
         }  
117      }      }
118  }  }
119    
120  template<typename T>  template<typename T>
121  void NumEntryTemp<T>::set_ptr(T* ptr)  void NumEntryTemp<T>::set_value(T value)
122  {  {
123      this->ptr = 0;      if (value > adjust.get_upper()) value = T(adjust.get_upper());
124      if (ptr) set_value(*ptr);      if (this->value != value) {
125      this->ptr = ptr;          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  }  }
133    
134    
# Line 137  private: Line 143  private:
143    
144  class NumEntryPermille : public NumEntry {  class NumEntryPermille : public NumEntry {
145  private:  private:
146      uint16_t* ptr;      uint16_t value;
147      void value_changed();      void value_changed();
148  public:  public:
149      NumEntryPermille(const char* labelText,      NumEntryPermille(const char* labelText,
150                       double lower = 0, double upper = 127, int decimals = 0);                       double lower = 0, double upper = 127, int decimals = 0);
151      void set_ptr(uint16_t* ptr);      uint16_t get_value() const { return value; }
152        void set_value(uint16_t value);
153  };  };
154    
155    
# Line 151  class ChoiceEntry : public LabelWidget { Line 158  class ChoiceEntry : public LabelWidget {
158  private:  private:
159      Gtk::ComboBoxText combobox;      Gtk::ComboBoxText combobox;
160      Gtk::Alignment align;      Gtk::Alignment align;
     T* ptr;  
     void value_changed();  
161      const T* values;      const T* values;
162  public:  public:
163      ChoiceEntry(const char* labelText);      ChoiceEntry(const char* labelText);
164        T get_value() const;
165        void set_value(T value);
166      void set_choices(const char** texts, const T* values);      void set_choices(const char** texts, const T* values);
167      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();  
     }  
168      void set_tip(const Glib::ustring& tip_text) {      void set_tip(const Glib::ustring& tip_text) {
169          tooltips.set_tip(combobox, tip_text); //FIXME: don't Gtk::ComboBoxes support tooltips ???          tooltips.set_tip(combobox, tip_text); //FIXME: don't Gtk::ComboBoxes support tooltips ???
170      }      }
# Line 172  ChoiceEntry<T>::ChoiceEntry(const char* Line 175  ChoiceEntry<T>::ChoiceEntry(const char*
175      align(0, 0, 0, 0),      align(0, 0, 0, 0),
176      LabelWidget(labelText, align)      LabelWidget(labelText, align)
177  {  {
178      combobox.signal_changed().connect(      combobox.signal_changed().connect(sig_changed.make_slot());
         sigc::mem_fun(*this, &ChoiceEntry::value_changed));  
179      align.add(combobox);      align.add(combobox);
180  }  }
181    
# Line 187  void ChoiceEntry<T>::set_choices(const c Line 189  void ChoiceEntry<T>::set_choices(const c
189  }  }
190    
191  template<typename T>  template<typename T>
192  void ChoiceEntry<T>::value_changed()  T ChoiceEntry<T>::get_value() const
193  {  {
194      if (ptr) {      int rowno = combobox.get_active_row_number();
195          int rowno = combobox.get_active_row_number();      return values[rowno];
         if (rowno != -1) {  
             *ptr = values[rowno];  
             sig_changed();  
         }  
     }  
196  }  }
197    
198  template<typename T>  template<typename T>
199  void ChoiceEntry<T>::set_ptr(T* ptr)  void ChoiceEntry<T>::set_value(T value)
200  {  {
201      this->ptr = 0;      int row = 0;
202      if (ptr) {      int nb_rows = combobox.get_model()->children().size();
203          T value = *ptr;      for (; row < nb_rows ; row++) {
204          int row = 0;          if (value == values[row]) break;
205          int nb_rows = combobox.get_model()->children().size();      }
206          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;  
207  }  }
208    
209    
210  class ChoiceEntryLeverageCtrl : public LabelWidget {  class ChoiceEntryLeverageCtrl : public LabelWidget {
211  private:  private:
212        gig::leverage_ctrl_t value;
213      Gtk::ComboBoxText combobox;      Gtk::ComboBoxText combobox;
214      Gtk::Alignment align;      Gtk::Alignment align;
     gig::leverage_ctrl_t* ptr;  
215      void value_changed();      void value_changed();
216  public:  public:
217      ChoiceEntryLeverageCtrl(const char* labelText);      ChoiceEntryLeverageCtrl(const char* labelText);
218      void set_ptr(gig::leverage_ctrl_t* ptr);      gig::leverage_ctrl_t get_value() const { return value; }
219      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();  
     }  
220  };  };
221    
222    
223  class BoolEntry : public LabelWidget {  class BoolEntry : public LabelWidget {
224  private:  private:
225      Gtk::CheckButton checkbutton;      Gtk::CheckButton checkbutton;
     bool* ptr;  
     void value_changed();  
226  public:  public:
227      BoolEntry(const char* labelText);      BoolEntry(const char* labelText);
228      bool get_active() { return checkbutton.get_active(); }      bool get_value() const { return checkbutton.get_active(); }
229      bool set_active(bool b) { checkbutton.set_active(b); }      void set_value(bool value) { checkbutton.set_active(value); }
230      Glib::SignalProxy0<void> signal_toggled() {  
         return checkbutton.signal_toggled();  
     }  
     void set_ptr(bool* ptr);  
231      void set_tip(const Glib::ustring& tip_text) {      void set_tip(const Glib::ustring& tip_text) {
232          tooltips.set_tip(checkbutton, tip_text);          tooltips.set_tip(checkbutton, tip_text);
233      }      }
# Line 253  public: Line 237  public:
237  class BoolEntryPlus6 : public LabelWidget {  class BoolEntryPlus6 : public LabelWidget {
238  private:  private:
239      Gtk::CheckButton checkbutton;      Gtk::CheckButton checkbutton;
     int32_t* ptr;  
240      void value_changed();      void value_changed();
241      NumEntryGain& eGain;      NumEntryGain& eGain;
242      int32_t plus6value;      int32_t plus6value;
243  public:  public:
244      BoolEntryPlus6(const char* labelText, NumEntryGain& eGain, int32_t plus6value);      BoolEntryPlus6(const char* labelText, NumEntryGain& eGain, int32_t plus6value);
245      void set_ptr(int32_t* ptr);      int32_t get_value() const;
246      bool get_active() { return checkbutton.get_active(); }      void set_value(int32_t value);
     Glib::SignalProxy0<void> signal_toggled() {  
         return checkbutton.signal_toggled();  
     }  
247  };  };
248    
249  class StringEntry : public LabelWidget {  class StringEntry : public LabelWidget {
250  private:  private:
251      Gtk::Entry entry;      Gtk::Entry entry;
     gig::String* ptr;  
     void value_changed();  
252  public:  public:
253      StringEntry(const char* labelText);      StringEntry(const char* labelText);
254      void set_ptr(gig::String* ptr);      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    };
258    
259    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    
270    

Legend:
Removed from v.1261  
changed lines
  Added in v.1582

  ViewVC Help
Powered by ViewVC