if(btn==1)
{
pressed = true;
- state |= ACTIVE;
+ set_state(ACTIVE);
}
}
{
if(pressed && btn==1)
{
- state &= ~ACTIVE;
+ clear_state(ACTIVE);
pressed = false;
if(geom.is_inside_relative(x, y))
if(pressed)
{
if(!geom.is_inside_relative(x, y))
- state &= ~ACTIVE;
+ clear_state(ACTIVE);
else
- state |= ACTIVE;
+ set_state(ACTIVE);
}
}
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();
}
}
if(dropped)
{
dropped = false;
- state &= ~ACTIVE;
+ clear_state(ACTIVE);
signal_ungrab_pointer.emit();
}
void Indicator::set_active(bool a)
{
- if(a)
- state |= ACTIVE;
- else
- state &= ~ACTIVE;
+ set_state(ACTIVE, (a ? ACTIVE : NORMAL));
}
} // namespace GLtk
dragging = true;
drag_start_pos = p;
drag_start_value = value;
- state |= ACTIVE;
+ set_state(ACTIVE);
}
void Slider::drag(int p)
void Slider::end_drag()
{
dragging = false;
- state &= ~ACTIVE;
+ clear_state(ACTIVE);
}
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
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)
signal_request_focus.emit();
}
+void Widget::set_state(State mask, State bits)
+{
+ state = (state&~mask)|bits;
+}
+
void Widget::render() const
{
if(!style)
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);
}
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 { }