/[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 2169 by persson, Sun Mar 6 07:51:04 2011 UTC
# Line 1  Line 1 
1  /*                                                         -*- c++ -*-  /*                                                         -*- c++ -*-
2   * Copyright (C) 2006, 2007 Andreas Persson   * Copyright (C) 2006-2011 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 <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/checkbutton.h>
31  #include <gtkmm/comboboxtext.h>  #include <gtkmm/comboboxtext.h>
32    #include <gtkmm/frame.h>
33  #include <gtkmm/label.h>  #include <gtkmm/label.h>
34  #include <gtkmm/scale.h>  #include <gtkmm/scale.h>
35  #include <gtkmm/spinbutton.h>  #include <gtkmm/spinbutton.h>
36    #include <gtkmm/textview.h>
37    
38    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 12) || GTKMM_MAJOR_VERSION < 2
39    #define OLD_TOOLTIPS
40  #include <gtkmm/tooltips.h>  #include <gtkmm/tooltips.h>
41    #endif
42    
43  class LabelWidget {  class LabelWidget {
44  public:  public:
# Line 38  public: Line 47  public:
47    
48      LabelWidget(const char* labelText, Gtk::Widget& widget);      LabelWidget(const char* labelText, Gtk::Widget& widget);
49      void set_sensitive(bool sensitive = true);      void set_sensitive(bool sensitive = true);
50      sigc::signal<void> signal_changed_by_user() {      sigc::signal<void>& signal_value_changed() {
51          return sig_changed;          return sig_changed;
52      }      }
53  protected:  protected:
54    #ifdef OLD_TOOLTIPS
55      Gtk::Tooltips tooltips;      Gtk::Tooltips tooltips;
56    #endif
57      sigc::signal<void> sig_changed;      sigc::signal<void> sig_changed;
58  };  };
59    
60  class NumEntry : public LabelWidget {  class NumEntry : public LabelWidget {
61  protected:  protected:
62    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
63      Gtk::Adjustment adjust;      Gtk::Adjustment adjust;
64    #else
65        Glib::RefPtr<Gtk::Adjustment> adjust;
66    #endif
67      Gtk::HScale scale;      Gtk::HScale scale;
68      Gtk::SpinButton spinbutton;      Gtk::SpinButton spinbutton;
69      Gtk::HBox box;      Gtk::HBox box;
# Line 59  protected: Line 74  protected:
74  public:  public:
75      NumEntry(const char* labelText, double lower = 0, double upper = 127,      NumEntry(const char* labelText, double lower = 0, double upper = 127,
76               int decimals = 0);               int decimals = 0);
     void set_value(double value) {  
         spinbutton.set_value(value);  
     }  
     double get_value() const {  
         return spinbutton.get_value();  
     }  
77      void set_tip(const Glib::ustring& tip_text) {      void set_tip(const Glib::ustring& tip_text) {
78    #ifdef OLD_TOOLTIPS
79          tooltips.set_tip(spinbutton, tip_text);          tooltips.set_tip(spinbutton, tip_text);
80    #else
81            spinbutton.set_tooltip_text(tip_text);
82    #endif
83      }      }
84      void set_upper(double upper) {      void set_upper(double upper) {
85    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
86          adjust.set_upper(upper);          adjust.set_upper(upper);
87    #else
88            adjust->set_upper(upper);
89    #endif
90      }      }
91  };  };
92    
93  class NumEntryGain : public NumEntry {  class NumEntryGain : public NumEntry {
94  private:  private:
95        int32_t value;
96      void value_changed();      void value_changed();
     int32_t* ptr;  
97      double coeff;      double coeff;
98        bool connected;
99  public:  public:
100      NumEntryGain(const char* labelText,      NumEntryGain(const char* labelText,
101                   double lower, double upper, int decimals, double coeff);                   double lower, double upper, int decimals, double coeff);
102      void set_ptr(int32_t* ptr);      int32_t get_value() const { return value; }
103        void set_value(int32_t value);
104  };  };
105    
106  template<typename T>  template<typename T>
107  class NumEntryTemp : public NumEntry {  class NumEntryTemp : public NumEntry {
108  private:  private:
109      T* ptr;      T value;
110      void value_changed();      void value_changed();
111  public:  public:
112      NumEntryTemp(const char* labelText,      NumEntryTemp(const char* labelText,
113                   double lower = 0, double upper = 127, int decimals = 0);                   double lower = 0, double upper = 127, int decimals = 0);
114      void set_ptr(T* ptr);      T get_value() const { return value; }
115        void set_value(T value);
116  };  };
117    
118  template<typename T>  template<typename T>
119  NumEntryTemp<T>::NumEntryTemp(const char* labelText,  NumEntryTemp<T>::NumEntryTemp(const char* labelText,
120                                double lower, double upper, int decimals) :                                double lower, double upper, int decimals) :
121      NumEntry(labelText, lower, upper, decimals)      NumEntry(labelText, lower, upper, decimals),
122        value(0)
123  {  {
124      spinbutton.signal_value_changed().connect(      spinbutton.signal_value_changed().connect(
125          sigc::mem_fun(*this, &NumEntryTemp::value_changed));          sigc::mem_fun(*this, &NumEntryTemp::value_changed));
# Line 107  NumEntryTemp<T>::NumEntryTemp(const char Line 128  NumEntryTemp<T>::NumEntryTemp(const char
128  template<typename T>  template<typename T>
129  void NumEntryTemp<T>::value_changed()  void NumEntryTemp<T>::value_changed()
130  {  {
131      if (ptr) {      const double f = pow(10, spinbutton.get_digits());
132          const double f = pow(10, spinbutton.get_digits());      int new_value = round_to_int(spinbutton.get_value() * f);
133          int new_value = round_to_int(spinbutton.get_value() * f);      if (new_value != round_to_int(value * f)) {
134          if (new_value != round_to_int(*ptr * f)) {          value = T(new_value / f);
135              *ptr = T(new_value / f);          sig_changed();
             sig_changed();  
         }  
136      }      }
137  }  }
138    
139  template<typename T>  template<typename T>
140  void NumEntryTemp<T>::set_ptr(T* ptr)  void NumEntryTemp<T>::set_value(T value)
141  {  {
142      this->ptr = 0;  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
143      if (ptr) set_value(*ptr);      if (value > adjust.get_upper()) value = T(adjust.get_upper());
144      this->ptr = ptr;  #else
145        if (value > adjust->get_upper()) value = T(adjust->get_upper());
146    #endif
147        if (this->value != value) {
148            this->value = value;
149            const double f = pow(10, spinbutton.get_digits());
150            if (round_to_int(spinbutton.get_value() * f) != round_to_int(value * f)) {
151                spinbutton.set_value(value);
152            }
153            sig_changed();
154        }
155  }  }
156    
157    
# Line 137  private: Line 166  private:
166    
167  class NumEntryPermille : public NumEntry {  class NumEntryPermille : public NumEntry {
168  private:  private:
169      uint16_t* ptr;      uint16_t value;
170      void value_changed();      void value_changed();
171  public:  public:
172      NumEntryPermille(const char* labelText,      NumEntryPermille(const char* labelText,
173                       double lower = 0, double upper = 127, int decimals = 0);                       double lower = 0, double upper = 127, int decimals = 0);
174      void set_ptr(uint16_t* ptr);      uint16_t get_value() const { return value; }
175        void set_value(uint16_t value);
176  };  };
177    
178    
# Line 151  class ChoiceEntry : public LabelWidget { Line 181  class ChoiceEntry : public LabelWidget {
181  private:  private:
182      Gtk::ComboBoxText combobox;      Gtk::ComboBoxText combobox;
183      Gtk::Alignment align;      Gtk::Alignment align;
     T* ptr;  
     void value_changed();  
184      const T* values;      const T* values;
185  public:  public:
186      ChoiceEntry(const char* labelText);      ChoiceEntry(const char* labelText);
187        T get_value() const;
188        void set_value(T value);
189      void set_choices(const char** texts, const T* values);      void set_choices(const char** texts, const T* values);
190      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();  
     }  
191      void set_tip(const Glib::ustring& tip_text) {      void set_tip(const Glib::ustring& tip_text) {
192          tooltips.set_tip(combobox, tip_text); //FIXME: don't Gtk::ComboBoxes support tooltips ???  #ifdef OLD_TOOLTIPS
193            tooltips.set_tip(combobox, tip_text);
194    #else
195            combobox.set_tooltip_text(tip_text);
196    #endif
197      }      }
198  };  };
199    
200  template<typename T>  template<typename T>
201  ChoiceEntry<T>::ChoiceEntry(const char* labelText) :  ChoiceEntry<T>::ChoiceEntry(const char* labelText) :
202      align(0, 0, 0, 0),      LabelWidget(labelText, align),
203      LabelWidget(labelText, align)      align(0, 0, 0, 0)
204  {  {
205      combobox.signal_changed().connect(      combobox.signal_changed().connect(sig_changed.make_slot());
         sigc::mem_fun(*this, &ChoiceEntry::value_changed));  
206      align.add(combobox);      align.add(combobox);
207  }  }
208    
# Line 181  template<typename T> Line 210  template<typename T>
210  void ChoiceEntry<T>::set_choices(const char** texts, const T* values)  void ChoiceEntry<T>::set_choices(const char** texts, const T* values)
211  {  {
212      for (int i = 0 ; texts[i] ; i++) {      for (int i = 0 ; texts[i] ; i++) {
213    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
214          combobox.append_text(texts[i]);          combobox.append_text(texts[i]);
215    #else
216            combobox.append(texts[i]);
217    #endif
218      }      }
219      this->values = values;      this->values = values;
220  }  }
221    
222  template<typename T>  template<typename T>
223  void ChoiceEntry<T>::value_changed()  T ChoiceEntry<T>::get_value() const
224  {  {
225      if (ptr) {      int rowno = combobox.get_active_row_number();
226          int rowno = combobox.get_active_row_number();      return values[rowno];
         if (rowno != -1) {  
             *ptr = values[rowno];  
             sig_changed();  
         }  
     }  
227  }  }
228    
229  template<typename T>  template<typename T>
230  void ChoiceEntry<T>::set_ptr(T* ptr)  void ChoiceEntry<T>::set_value(T value)
231  {  {
232      this->ptr = 0;      int row = 0;
233      if (ptr) {      int nb_rows = combobox.get_model()->children().size();
234          T value = *ptr;      for (; row < nb_rows ; row++) {
235          int row = 0;          if (value == values[row]) break;
236          int nb_rows = combobox.get_model()->children().size();      }
237          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;  
238  }  }
239    
240    
241  class ChoiceEntryLeverageCtrl : public LabelWidget {  class ChoiceEntryLeverageCtrl : public LabelWidget {
242  private:  private:
243        gig::leverage_ctrl_t value;
244      Gtk::ComboBoxText combobox;      Gtk::ComboBoxText combobox;
245      Gtk::Alignment align;      Gtk::Alignment align;
     gig::leverage_ctrl_t* ptr;  
246      void value_changed();      void value_changed();
247  public:  public:
248      ChoiceEntryLeverageCtrl(const char* labelText);      ChoiceEntryLeverageCtrl(const char* labelText);
249      void set_ptr(gig::leverage_ctrl_t* ptr);      gig::leverage_ctrl_t get_value() const { return value; }
250      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();  
     }  
251  };  };
252    
253    
254  class BoolEntry : public LabelWidget {  class BoolEntry : public LabelWidget {
255  private:  private:
256      Gtk::CheckButton checkbutton;      Gtk::CheckButton checkbutton;
     bool* ptr;  
     void value_changed();  
257  public:  public:
258      BoolEntry(const char* labelText);      BoolEntry(const char* labelText);
259      bool get_active() { return checkbutton.get_active(); }      bool get_value() const { return checkbutton.get_active(); }
260      bool set_active(bool b) { checkbutton.set_active(b); }      void set_value(bool value) { checkbutton.set_active(value); }
261      Glib::SignalProxy0<void> signal_toggled() {  
         return checkbutton.signal_toggled();  
     }  
     void set_ptr(bool* ptr);  
262      void set_tip(const Glib::ustring& tip_text) {      void set_tip(const Glib::ustring& tip_text) {
263    #ifdef OLD_TOOLTIPS
264          tooltips.set_tip(checkbutton, tip_text);          tooltips.set_tip(checkbutton, tip_text);
265    #else
266            checkbutton.set_tooltip_text(tip_text);
267    #endif
268      }      }
269  };  };
270    
# Line 253  public: Line 272  public:
272  class BoolEntryPlus6 : public LabelWidget {  class BoolEntryPlus6 : public LabelWidget {
273  private:  private:
274      Gtk::CheckButton checkbutton;      Gtk::CheckButton checkbutton;
     int32_t* ptr;  
275      void value_changed();      void value_changed();
276      NumEntryGain& eGain;      NumEntryGain& eGain;
277      int32_t plus6value;      int32_t plus6value;
278  public:  public:
279      BoolEntryPlus6(const char* labelText, NumEntryGain& eGain, int32_t plus6value);      BoolEntryPlus6(const char* labelText, NumEntryGain& eGain, int32_t plus6value);
280      void set_ptr(int32_t* ptr);      int32_t get_value() const;
281      bool get_active() { return checkbutton.get_active(); }      void set_value(int32_t value);
     Glib::SignalProxy0<void> signal_toggled() {  
         return checkbutton.signal_toggled();  
     }  
282  };  };
283    
284  class StringEntry : public LabelWidget {  class StringEntry : public LabelWidget {
285  private:  private:
286      Gtk::Entry entry;      Gtk::Entry entry;
     gig::String* ptr;  
     void value_changed();  
287  public:  public:
288      StringEntry(const char* labelText);      StringEntry(const char* labelText);
289      void set_ptr(gig::String* ptr);      gig::String get_value() const { return entry.get_text(); }
290        void set_value(gig::String value) { entry.set_text(value); }
291        void set_width_chars(int n_chars) { entry.set_width_chars(n_chars); }
292    };
293    
294    class StringEntryMultiLine : public LabelWidget {
295    private:
296        Gtk::TextView text_view;
297        Glib::RefPtr<Gtk::TextBuffer> text_buffer;
298        Gtk::Frame frame;
299    public:
300        StringEntryMultiLine(const char* labelText);
301        gig::String get_value() const;
302        void set_value(gig::String value);
303  };  };
304    
305    

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

  ViewVC Help
Powered by ViewVC