change CairoWidget API to be a more logical/intuitive for setting widget state, to...
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 27 Oct 2011 11:24:43 +0000 (11:24 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 27 Oct 2011 11:24:43 +0000 (11:24 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@10314 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/ardour3_ui_dark.rc.in
gtk2_ardour/ardour3_ui_light.rc.in
gtk2_ardour/ardour3_widget_list.rc
gtk2_ardour/ardour_button.cc
gtk2_ardour/ardour_button.h
gtk2_ardour/cairo_widget.cc
gtk2_ardour/cairo_widget.h
gtk2_ardour/led.cc
gtk2_ardour/led.h
gtk2_ardour/processor_box.cc
gtk2_ardour/route_ui.cc

index 2ad1d7c5d4ede49ef278d2ecf39895906ce8720e..131b57598cf9ee05443c1097d6906165ba73f085 100644 (file)
@@ -26,8 +26,6 @@
 #@color arm #F33
 #@color solo #A8F730
 #@color midi_channel_selector #A8F730
-#@color isolate #B9ECF2
-#@color solo_lock #3593DA
 #@color mute #FFFA87
 #@color mono #DEC
 #@color monitor #FFAB34
index b4501e89de23783bd5786f6575d96c6316551c5c..3852d571cab24acd87041eacbc1d156bf7f294d2 100644 (file)
@@ -26,8 +26,6 @@
 #@color arm #F33
 #@color solo #A8F730
 #@color midi_channel_selector #A8F730
-#@color isolate #B9ECF2
-#@color solo_lock #3593DA
 #@color mute #FFFA87
 #@color mono #DEC
 #@color monitor #7596DE
index 8daf1c2ceec3b4edefcd1aac1bc9caf6cc9a9efa..aa00962d1ec320e1e5c1ff24e7da21b665d0a56b 100644 (file)
@@ -400,4 +400,3 @@ widget "*MeasureLatencyButton" style:highest "default_toggle_button"
 widget "*processor prefader" style:highest "processor_prefader"
 widget "*processor fader" style:highest "processor_fader"
 widget "*processor postfader" style:highest "processor_postfader"
-widget "*ProcessorFrameActiveSend" style:highest "processor_frame_active_send"
index 042e5fae717a567dfe8089d3923b7b3bed91a1c8..5754624013231e9706df22bd4c0b6afffc5cc231 100644 (file)
@@ -37,8 +37,6 @@ using namespace Gtk;
 using namespace Glib;
 using std::max;
 using std::min;
-using std::cerr;
-using std::endl;
 
 ArdourButton::ArdourButton()
         : _text_width (0)
@@ -54,6 +52,7 @@ ArdourButton::ArdourButton()
          
 {
        ColorsChanged.connect (sigc::mem_fun (*this, &ArdourButton::color_handler));
+       StateChanged.connect (sigc::mem_fun (*this, &ArdourButton::state_handler));
 }
 
 ArdourButton::~ArdourButton()
@@ -160,9 +159,8 @@ ArdourButton::render (cairo_t* cr)
 }
 
 void
-ArdourButton::set_state (CairoWidget::State s, bool yn)
+ArdourButton::state_handler ()
 {
-       CairoWidget::set_state (s, yn);
        set_colors ();
 }
 
@@ -222,7 +220,7 @@ ArdourButton::set_colors ()
        }
 
        edge_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, _height);
-       if (_state & CairoWidget::Selected) {
+       if (visual_state() & CairoWidget::Selected) {
                start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 border start selected", get_name()));
                end_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 border end selected", get_name()));
        } else {
@@ -242,10 +240,11 @@ ArdourButton::set_colors ()
        }
 
        fill_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, _height);
-       if (_state & Mid) {
+
+       if (active_state() == Mid) {
                start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 fill start mid", get_name()));
                end_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 fill end mid", get_name()));
-       } else if (_state & Active) {
+       } else if (active_state() == Active) {
                start_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 fill start active", get_name()));
                end_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 fill end active", get_name()));
        } else {
@@ -270,14 +269,14 @@ ArdourButton::set_colors ()
        }
 
        reflection_pattern = cairo_pattern_create_linear (0.0, 0.0, 0.0, _diameter/2-3);
-       cairo_pattern_add_color_stop_rgba (reflection_pattern, 0, 1,1,1, (_state & Active) ? 0.4 : 0.2);
+       cairo_pattern_add_color_stop_rgba (reflection_pattern, 0, 1,1,1, active_state() ? 0.4 : 0.2);
        cairo_pattern_add_color_stop_rgba (reflection_pattern, 1, 1,1,1, 0.0);
 
        /* text and LED colors depend on Active/Normal/Mid */
-       if (_state & Active) {
+       if (active_state() == Active) {
                text_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 text active", get_name()));
                led_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 led active", get_name()));
-       } else if (_state & Mid) {
+       } else if (active_state() == Mid) {
                text_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 text mid", get_name()));
                led_color = ARDOUR_UI::config()->color_by_name (string_compose ("%1 led active", get_name()));
        } else {
index a499f60b3a378c586ad8d55c33bf17513b391279..6f41a4191a5df30de7f4c5ba6a624867553b76db 100644 (file)
@@ -42,8 +42,6 @@ class ArdourButton : public CairoWidget, Gtk::Activatable
 
        sigc::signal<void> signal_clicked;
 
-       void set_state (State s, bool);
-
   protected:
        void render (cairo_t *);
         void on_size_request (Gtk::Requisition* req);
@@ -78,6 +76,7 @@ class ArdourButton : public CairoWidget, Gtk::Activatable
 
         void set_colors ();
        void color_handler ();
+       void state_handler ();
 };
 
 #endif /* __gtk2_ardour_ardour_button_h__ */
index 11fcfdffd6997ce9e5bdecee06ac4d76e20d40fd..025bb16ea69719fa974934627f975c2bfe9abe04 100644 (file)
@@ -23,7 +23,8 @@
 CairoWidget::CairoWidget ()
        : _width (1)
        , _height (1)
-       , _state (CairoWidget::State (0))
+       , _active_state (CairoWidget::ActiveState (0))
+       , _visual_state (CairoWidget::VisualState (0))
        , _dirty (true)
        , _pixmap (0)
          
@@ -131,17 +132,19 @@ CairoWidget::get_parent_bg ()
 }
 
 void
-CairoWidget::set_state (CairoWidget::State s, bool yn)
+CairoWidget::set_active_state (CairoWidget::ActiveState s)
 {
-       if (yn) {
-               if (!(_state & s)) {
-                       _state = CairoWidget::State (_state|s);
-                       StateChanged ();
-               }
-       } else {
-               if (_state & s) {
-                       _state = CairoWidget::State (_state & ~s);
-                       StateChanged ();
-               }
+       if (_active_state != s) {
+               _active_state = s;
+               StateChanged ();
+       }
+}
+
+void
+CairoWidget::set_visual_state (CairoWidget::VisualState s)
+{
+       if (_visual_state != s) {
+               _visual_state = s;
+               StateChanged ();
        }
 }
index e368a21a03454bd6d23bae5c2eca538a2ebac40f..61708e19cd337d8d14105273d0f076d96582b88d 100644 (file)
@@ -35,21 +35,29 @@ public:
 
        void set_dirty ();
 
-       /* widget states: unlike GTK, these OR-together so that
-          a widget can be both Active *and* Selected, rather than
-          each one being orthogonal.
+       /* widget states: unlike GTK, visual states like "Selected" or "Prelight"
+          are orthogonal to active states. 
        */
 
-       enum State {
-               Active = 0x1,
-               Mid = 0x2,
-               Selected = 0x4,
-               Prelight = 0x8,
-               Insensitive = 0x10,
+       enum ActiveState {
+               Active = 1,
+               Mid,
        };
+       
+       enum VisualState {
+               /* these can be OR-ed together */
+               Selected = 0x1,
+               Prelight = 0x2,
+               Insensitive = 0x4,
+       };
+
+       ActiveState active_state() const { return _active_state; }
+       VisualState visual_state() const { return _visual_state; }
+       virtual void set_active_state (ActiveState);
+       virtual void set_visual_state (VisualState);
+       virtual void unset_active_state () { set_active_state (ActiveState (0)); }
+       virtual void unset_visual_state () { set_visual_state (VisualState (0)); }
 
-       State state() const { return _state; }
-       virtual void set_state (State, bool);
        sigc::signal<void> StateChanged;
 
 protected:
@@ -61,7 +69,8 @@ protected:
 
        int _width; ///< pixmap width
        int _height; ///< pixmap height
-       State _state;
+       ActiveState _active_state;
+       VisualState _visual_state;
 
 private:
        bool _dirty; ///< true if the pixmap requires re-rendering
index 259ebccd2d3137f58fa6669f2212fc3d9163639c..8a8c5868f31375d0e18adcdbab7aeb2fb773963f 100644 (file)
@@ -28,9 +28,7 @@ using namespace Gtk;
 using namespace Glib;
 
 LED::LED()
-        : _visual_state (0)
-        , _active (false)
-        , _diameter (0.0)
+        : _diameter (0.0)
         , _fixed_diameter (false)
         , _red (0.0)
         , _green (1.0)
@@ -94,14 +92,14 @@ LED::render (cairo_t* cr)
        cairo_fill(cr);
 
        //knob color
-       cairo_set_source_rgba (cr, _red, _green, _blue, _active ? 0.8 : 0.2);
+       cairo_set_source_rgba (cr, _red, _green, _blue, (active_state() == Active) ? 0.8 : 0.2);
        cairo_arc (cr, 0, 0, _diameter/2-3, 0, 2 * M_PI);
        cairo_fill(cr);
 
        //reflection
        cairo_scale(cr, 0.7, 0.7);
        cairo_pattern_t *pat2 = cairo_pattern_create_linear (0.0, 0.0, 0.0, _diameter/2-3);
-       cairo_pattern_add_color_stop_rgba (pat2, 0, 1,1,1, _active ? 0.4 : 0.2);
+       cairo_pattern_add_color_stop_rgba (pat2, 0, 1,1,1, active_state() ? 0.4 : 0.2);
        cairo_pattern_add_color_stop_rgba (pat2, 1, 1,1,1, 0.0);
        cairo_arc (cr, 0, 0, _diameter/2-3, 0, 2 * M_PI);
        cairo_set_source (cr, pat2);
@@ -111,24 +109,6 @@ LED::render (cairo_t* cr)
        cairo_stroke (cr);
 }
 
-void
-LED::set_active (bool yn) 
-{
-       _active = yn;
-       _visual_state = (yn ? 1 : 0);
-       set_colors_from_style ();
-}
-
-void
-LED::set_visual_state (int32_t s)
-{
-        if (s != _visual_state) {
-
-                _visual_state = s;
-                set_colors_from_style ();
-        }
-}
-
 void
 LED::set_diameter (float d)
 {
index e8514d60c053017e2121bb7664204ebe338dcb41..c60e0761cf090a81da7a90826e4bee801dda2e2b 100644 (file)
@@ -30,10 +30,6 @@ class LED : public CairoWidget
        LED ();
        virtual ~LED ();
 
-       void set_active (bool yn);
-       bool active () const { return _active; }
-        void set_visual_state (int32_t s);
-        int32_t visual_state() const { return _visual_state; }
         void set_diameter (float);
 
   protected:
@@ -42,8 +38,6 @@ class LED : public CairoWidget
         void on_realize ();
 
   private:
-        int32_t _visual_state;
-        bool  _active;
         float _diameter;
         bool  _fixed_diameter;
         float _red;
index 0632147bbad67cabaa51dee2226d3f4cdd8fb676..b818b22c204c17eb1a83b89fc0bb7b174023c783 100644 (file)
@@ -104,7 +104,9 @@ ProcessorEntry::ProcessorEntry (boost::shared_ptr<Processor> p, Width w)
        _vbox.pack_start (_button, true, true);
        _vbox.show ();
        
-       _button.set_state (CairoWidget::Active, _processor->active());
+       if (_processor->active()) {
+               _button.set_active_state (CairoWidget::Active);
+       }
        _button.set_diameter (3);
        _button.signal_clicked.connect (sigc::mem_fun (*this, &ProcessorEntry::led_clicked));
        _button.set_text (name());
@@ -149,17 +151,18 @@ ProcessorEntry::set_visual_state (Gtk::StateType t)
 
        switch (t) {
        case Gtk::STATE_ACTIVE:
-               _button.set_state (CairoWidget::Active, true);
+               _button.set_active_state (CairoWidget::Active);
+               _button.unset_visual_state ();
                break;
 
        case Gtk::STATE_SELECTED:
-               _button.set_state (CairoWidget::Selected, true);
+               _button.set_visual_state (CairoWidget::Selected);
                break;
 
        case Gtk::STATE_NORMAL:
        default:
-               _button.set_state (CairoWidget::Selected, false);
-               _button.set_state (CairoWidget::Active, false);
+               _button.unset_visual_state ();
+               _button.unset_active_state ();
                break;
        }
 }
@@ -208,7 +211,11 @@ ProcessorEntry::led_clicked()
 void
 ProcessorEntry::processor_active_changed ()
 {
-       _button.set_state (CairoWidget::Active, _processor->active());
+       if (_processor->active()) {
+               _button.set_active_state (CairoWidget::Active);
+       } else {
+               _button.unset_active_state ();
+       }
 }
 
 void
index c0dd43404e9c77a1c3ceb0911d474890d69c899d..eda81d969e18392c4467af831dfd498821dec0e6 100644 (file)
@@ -608,26 +608,22 @@ RouteUI::update_monitoring_display ()
        MonitorState ms = t->monitoring_state();
 
        if (t->monitoring_choice() & MonitorInput) {
-               monitor_input_button->set_state (CairoWidget::Active, true);
-               monitor_input_button->set_state (CairoWidget::Mid, false);
+               monitor_input_button->set_active_state (CairoWidget::Active);
        } else {
                if (ms & MonitoringInput) {
-                       monitor_input_button->set_state (CairoWidget::Mid, true);
-                       monitor_input_button->set_state (CairoWidget::Active, false);
+                       monitor_input_button->set_active_state (CairoWidget::Mid);
                } else {
-                       monitor_input_button->set_state (CairoWidget::State (CairoWidget::Active|CairoWidget::Mid), false);
+                       monitor_input_button->unset_active_state ();
                }
        }
 
        if (t->monitoring_choice() & MonitorDisk) {
-               monitor_disk_button->set_state (CairoWidget::Active, true);
-                       monitor_disk_button->set_state (CairoWidget::Mid, false);
+               monitor_disk_button->set_active_state (CairoWidget::Active);
        } else {
                if (ms & MonitoringDisk) {
-                       monitor_disk_button->set_state (CairoWidget::Mid, true);
-                       monitor_disk_button->set_state (CairoWidget::Active, false);
+                       monitor_disk_button->set_active_state (CairoWidget::Mid);
                } else {
-                       monitor_disk_button->set_state (CairoWidget::State (CairoWidget::Active|CairoWidget::Mid), false);
+                       monitor_disk_button->unset_active_state ();
                }
        }
 }
@@ -1066,11 +1062,19 @@ RouteUI::update_solo_display ()
         set_button_names ();
 
         if (solo_isolated_led) {
-                solo_isolated_led->set_state (CairoWidget::Active, _route->solo_isolated());
+               if (_route->solo_isolated()) {
+                       solo_isolated_led->set_active_state (CairoWidget::Active);
+               } else {
+                       solo_isolated_led->unset_active_state ();
+               }
         }
 
         if (solo_safe_led) {
-                solo_safe_led->set_state (CairoWidget::Active, _route->solo_safe());
+               if (_route->solo_safe()) {
+                       solo_safe_led->set_active_state (CairoWidget::Active);
+               } else {
+                       solo_safe_led->unset_active_state ();
+               }
         }
 
        solo_button->set_visual_state (solo_visual_state (_route));
@@ -1340,7 +1344,7 @@ RouteUI::solo_isolate_button_release (GdkEventButton* ev)
                 return true;
         }
 
-        bool view = (solo_isolated_led->state() & (CairoWidget::Active|CairoWidget::Mid));
+        bool view = solo_isolated_led->active_state();
         bool model = _route->solo_isolated();
 
         /* called BEFORE the view has changed */
@@ -1371,7 +1375,7 @@ RouteUI::solo_isolate_button_release (GdkEventButton* ev)
 bool
 RouteUI::solo_safe_button_release (GdkEventButton*)
 {
-        _route->set_solo_safe (!(solo_safe_led->state() & (CairoWidget::Active|CairoWidget::Mid)), this);
+        _route->set_solo_safe (!solo_safe_led->active_state(), this);
         return true;
 }