mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-21 08:13:18 +00:00
Add helper class tselectable_ and let ttoggle_button derive from it.
This commit is contained in:
parent
061893af23
commit
1e4e33e27b
@ -43,7 +43,7 @@ void ttoggle_button::mouse_enter(tevent_handler&)
|
||||
{
|
||||
DBG_G_E << "Toggle button: mouse enter.\n";
|
||||
|
||||
if(is_up()) {
|
||||
if(is_selected()) {
|
||||
set_state(FOCUSSED_UP);
|
||||
} else {
|
||||
set_state(FOCUSSED_DOWN);
|
||||
@ -54,7 +54,7 @@ void ttoggle_button::mouse_leave(tevent_handler&)
|
||||
{
|
||||
DBG_G_E << "Toggle button: mouse leave.\n";
|
||||
|
||||
if(is_up()) {
|
||||
if(is_selected()) {
|
||||
set_state(ENABLED_UP);
|
||||
} else {
|
||||
set_state(ENABLED_DOWN);
|
||||
@ -65,7 +65,7 @@ void ttoggle_button::mouse_left_button_click(tevent_handler&)
|
||||
{
|
||||
DBG_G_E << "Toggle button: left mouse button click.\n";
|
||||
|
||||
if(is_up()) {
|
||||
if(is_selected()) {
|
||||
set_state(ENABLED_DOWN);
|
||||
} else {
|
||||
set_state(ENABLED_UP);
|
||||
@ -77,13 +77,13 @@ void ttoggle_button::mouse_left_button_click(tevent_handler&)
|
||||
void ttoggle_button::set_active(const bool active)
|
||||
{
|
||||
if(active) {
|
||||
if(is_up()) {
|
||||
if(is_selected()) {
|
||||
set_state(ENABLED_UP);
|
||||
} else {
|
||||
set_state(ENABLED_DOWN);
|
||||
}
|
||||
} else {
|
||||
if(is_up()) {
|
||||
if(is_selected()) {
|
||||
set_state(DISABLED_UP);
|
||||
} else {
|
||||
set_state(DISABLED_DOWN);
|
||||
@ -91,13 +91,13 @@ void ttoggle_button::set_active(const bool active)
|
||||
}
|
||||
}
|
||||
|
||||
void ttoggle_button::set_up(const bool up)
|
||||
void ttoggle_button::set_selected(const bool selected)
|
||||
{
|
||||
if(up == is_up()) {
|
||||
if(selected == is_selected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(up) {
|
||||
if(selected) {
|
||||
set_state(static_cast<tstate>(state_ - ENABLED_DOWN));
|
||||
} else {
|
||||
set_state(static_cast<tstate>(state_ + ENABLED_DOWN));
|
||||
|
@ -20,7 +20,7 @@
|
||||
namespace gui2 {
|
||||
|
||||
// Class for a toggle button
|
||||
class ttoggle_button : public tcontrol
|
||||
class ttoggle_button : public tcontrol, public tselectable_
|
||||
{
|
||||
public:
|
||||
ttoggle_button() :
|
||||
@ -40,11 +40,11 @@ public:
|
||||
{ return state_ != DISABLED_UP && state_ != DISABLED_DOWN; }
|
||||
unsigned get_state() const { return state_; }
|
||||
|
||||
/** Is the widget in the up state. */
|
||||
bool is_up() const { return state_ < ENABLED_DOWN; }
|
||||
/** Inherited from tselectable_ */
|
||||
bool is_selected() const { return state_ < ENABLED_DOWN; }
|
||||
|
||||
/** Set the button in the wanted state. */
|
||||
void set_up(const bool up = true);
|
||||
/** Inherited from tselectable_ */
|
||||
void set_selected(const bool selected = true);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -223,6 +223,24 @@ private:
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Small abstract helper class.
|
||||
*
|
||||
* Parts of the engine inherit this class so we can have generic
|
||||
* selectable items.
|
||||
*/
|
||||
class tselectable_
|
||||
{
|
||||
public:
|
||||
virtual ~tselectable_() {}
|
||||
|
||||
/** Is the control selected? */
|
||||
virtual bool is_selected() const = 0;
|
||||
|
||||
/** Select the control */
|
||||
virtual void set_selected(const bool = true) = 0;
|
||||
};
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user