]> git.tdb.fi Git - libs/gltk.git/commitdiff
Add protected functions for manipulating widget state
authorMikko Rasa <tdb@tdb.fi>
Fri, 30 Nov 2012 17:57:46 +0000 (19:57 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 30 Nov 2012 17:57:46 +0000 (19:57 +0200)
source/button.cpp
source/dropdown.cpp
source/indicator.cpp
source/slider.cpp
source/toggle.cpp
source/widget.cpp
source/widget.h

index fb052629d626c7eae2ae9f22cc93d4cc94f87311..5f9b18bfdf3290a830d4bc392b126d0be3649a19 100644 (file)
@@ -85,7 +85,7 @@ void Button::button_press(int, int, unsigned btn)
        if(btn==1)
        {
                pressed = true;
-               state |= ACTIVE;
+               set_state(ACTIVE);
        }
 }
 
@@ -93,7 +93,7 @@ void Button::button_release(int x, int y, unsigned btn)
 {
        if(pressed && btn==1)
        {
-               state &= ~ACTIVE;
+               clear_state(ACTIVE);
                pressed = false;
 
                if(geom.is_inside_relative(x, y))
@@ -106,9 +106,9 @@ void Button::pointer_motion(int x, int y)
        if(pressed)
        {
                if(!geom.is_inside_relative(x, y))
-                       state &= ~ACTIVE;
+                       clear_state(ACTIVE);
                else
-                       state |= ACTIVE;
+                       set_state(ACTIVE);
        }
 }
 
index cab6d918e536210190a256b67b7965c0851c2f1b..47496f4bc385121d7c5c2862cec06947427cb799 100644 (file)
@@ -97,14 +97,14 @@ void Dropdown::button_press(int x, int y, unsigned btn)
                if(!click_focus)
                {
                        dropped = false;
-                       state &= ~ACTIVE;
+                       clear_state(ACTIVE);
                        signal_ungrab_pointer.emit();
                }
        }
        else if(btn==1)
        {
                dropped = true;
-               state |= ACTIVE;
+               set_state(ACTIVE);
                signal_grab_pointer.emit();
        }
 }
@@ -160,7 +160,7 @@ void Dropdown::list_item_selected(unsigned index, const std::string &item)
        if(dropped)
        {
                dropped = false;
-               state &= ~ACTIVE;
+               clear_state(ACTIVE);
                signal_ungrab_pointer.emit();
        }
 
index 568aafddc9af7feb3d4e054bcc90c2a0a2a03125..fba81665c2092a66cc057f5ff0f8882865b1f0ed 100644 (file)
@@ -10,10 +10,7 @@ Indicator::Indicator()
 
 void Indicator::set_active(bool a)
 {
-       if(a)
-               state |= ACTIVE;
-       else
-               state &= ~ACTIVE;
+       set_state(ACTIVE, (a ? ACTIVE : NORMAL));
 }
 
 } // namespace GLtk
index 7a0029e05b79e430839bf560d5ff1fe7757c33ba..de4d12e3d69646f4960d65c5ee4316901cbc9bcd 100644 (file)
@@ -48,7 +48,7 @@ void Slider::start_drag(int p)
        dragging = true;
        drag_start_pos = p;
        drag_start_value = value;
-       state |= ACTIVE;
+       set_state(ACTIVE);
 }
 
 void Slider::drag(int p)
@@ -60,7 +60,7 @@ void Slider::drag(int p)
 void Slider::end_drag()
 {
        dragging = false;
-       state &= ~ACTIVE;
+       clear_state(ACTIVE);
 }
 
 
index 6d2a10b16644d6254163b53b26c6f92ead7754ce..f2cf55202183f44d42cf132bb2d9746a165b096f 100644 (file)
@@ -59,12 +59,12 @@ void Toggle::set_value(bool v)
        value = v;
        if(value)
        {
-               state |= ACTIVE;
+               set_state(ACTIVE);
                if(exclusive && parent)
                        exclude_siblings();
        }
        else
-               state &= ~ACTIVE;
+               clear_state(ACTIVE);
 }
 
 void Toggle::render_special(const Part &part) const
@@ -115,10 +115,7 @@ Toggle &Toggle::Loader::get_object() const
 void Toggle::Loader::finish()
 {
        Toggle &tgl = get_object();
-       if(tgl.value)
-               tgl.state |= ACTIVE;
-       else
-               tgl.state &= ~ACTIVE;
+       tgl.set_state(ACTIVE, (tgl.value ? ACTIVE : NORMAL));
 }
 
 void Toggle::Loader::text(const string &t)
index 643331602b16069863d03e905bb17f455a12f695..b10b6b560d8226cd9e1ddd68cef905e7189cc0bf 100644 (file)
@@ -134,6 +134,11 @@ void Widget::set_focus()
        signal_request_focus.emit();
 }
 
+void Widget::set_state(State mask, State bits)
+{
+       state = (state&~mask)|bits;
+}
+
 void Widget::render() const
 {
        if(!style)
@@ -157,22 +162,22 @@ void Widget::render() const
 
 void Widget::pointer_enter()
 {
-       state |= HOVER;
+       set_state(HOVER);
 }
 
 void Widget::pointer_leave()
 {
-       state &= ~HOVER;
+       clear_state(HOVER);
 }
 
 void Widget::focus_in()
 {
-       state |= FOCUS;
+       set_state(FOCUS);
 }
 
 void Widget::focus_out()
 {
-       state &= ~FOCUS;
+       clear_state(FOCUS);
 }
 
 
index 665ca9d0e7605161ab8e5a3f0648e45d1d55994e..9bdc2c0e13eba4a24eca88e585b577a2a706e996 100644 (file)
@@ -97,6 +97,12 @@ public:
        bool is_focusable() const { return focusable; }
        void set_focus();
 
+protected:
+       void set_state(State s) { set_state(s, s); }
+       void clear_state(State s) { set_state(s, NORMAL); }
+       void set_state(State, State);
+
+public:
        void render() const;
 protected:
        virtual void render_special(const Part &) const { }