Add a extra generic button class.

This base class is used by tbutton and will also be used by a
repeating button variant. (That button will be added once finished.)
This commit is contained in:
Mark de Wever 2009-12-13 13:55:57 +00:00
parent 5f4a592c68
commit 83666cb94d
4 changed files with 72 additions and 1 deletions

View file

@ -23,6 +23,7 @@ Version 1.7.9+svn:
* MP lobby refresh to the new timer engine
* Change Drake Flare and Flameheart weapon names to match new weapons
* Add a minimap cache for gui2
* Add a new super class for the button
Version 1.7.9-beta2:
* AI:

View file

@ -29,6 +29,7 @@ namespace gui2 {
tbutton::tbutton()
: tcontrol(COUNT)
, tclickable_()
, state_(ENABLED)
, retval_(0)
, callback_mouse_left_click_(0)

View file

@ -16,13 +16,16 @@
#define GUI_WIDGETS_BUTTON_HPP_INCLUDED
#include "gui/widgets/control.hpp"
#include "gui/widgets/clickable.hpp"
namespace gui2 {
/**
* Simple push button.
*/
class tbutton : public tcontrol
class tbutton
: public tcontrol
, public tclickable_
{
public:
tbutton();
@ -64,6 +67,18 @@ public:
/** Inherited from tcontrol. */
unsigned get_state() const { return state_; }
/** Inherited from tclickable. */
void connect_click_handler(const event::tsignal_function& signal)
{
connect_signal_mouse_left_click(signal);
}
/** Inherited from tclickable. */
void disconnect_click_handler(const event::tsignal_function& signal)
{
disconnect_signal_mouse_left_click(signal);
}
/***** ***** ***** setters / getters for members ***** ****** *****/
void set_retval(const int retval) { retval_ = retval; }

View file

@ -0,0 +1,54 @@
/* $Id$ */
/*
Copyright (C) 2009 by Mark de Wever <koraq@xs4all.nl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef GUI_WIDGETS_CLICKABLE_HPP_INCLUDED
#define GUI_WIDGETS_CLICKABLE_HPP_INCLUDED
namespace gui2 {
/**
* Small abstract helper class.
*
* Parts of the engine inherit this class so we can have generic
* clickable items. This is mainly for the button and the repeating button
* classes.
*/
class tclickable_
{
public:
virtual ~tclickable_() {}
/**
* Connects a signal handler for a 'click' event.
*
* What the click is depends on the subclass.
*
* @param signal The signal to connect.
*/
virtual void connect_click_handler(const event::tsignal_function& signal) = 0;
/**
* Disconnects a signal handler for a 'click' event.
*
* What the click is depends on the subclass.
*
* @param signal The signal to disconnect (should be the same
* as send to the connect call.
*/
virtual void disconnect_click_handler(const event::tsignal_function& signal) = 0;
};
} // namespace gui2
#endif