-
Notifications
You must be signed in to change notification settings - Fork 5
/
option.h
136 lines (117 loc) · 3.44 KB
/
option.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
Copyright (C) 2008 Rian Shelley
Part of the Adonthell Project http://adonthell.linuxgames.com
Adonthell is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Adonthell is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Adonthell; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* @file gui/option.h
* @author Rian Shelley
* @brief Defines the option class.
*/
#ifndef GUI_OPTION_H
#define GUI_OPTION_H
#include "button.h"
namespace gui
{
/**
* A selectable widget that remembers its
* selection state. Can be used to represent
* toggle buttons or check boxes.
*/
class option: public button
{
public:
/**
* Create a option widget of the given size.
* @param width the width of the widget.
* @param height the height of the widget.
*/
option(const u_int16 & width, const u_int16 & height)
: button(width, height), State(false)
{ }
/**
* Create option widget from the given data file.
* Size will be set to the background size.
* @param style filename of widget decoration.
*/
option(const std::string & style)
: button(style), State(false)
{ }
/**
* @name Selection state
*/
//@{
/**
* Set selection state of option widget. This
* does not trigger an event.
* @param s true to select, false otherwise.
*/
void set_state(const bool & s) { Clicked = s; }
/**
* Get selection state of option widget.
* @return true if selected, false otherwise.
*/
bool get_state() const { return Clicked; }
//@}
/**
* Called when the widget has been activated.
* If present, executes the callback with the
* selection state and the user defined data.
*/
virtual void activate();
#ifndef SWIG
GET_TYPE_NAME_VIRTUAL(gui::option);
#endif
protected:
/**
* @name Keyboard Callbacks.
*
* Called when a keystroke happens. returns whether or not the
* object used the keystroke
*/
//@{
/**
* Called when a key has been released by the user.
* @param k the keyboard event.
* @return true if the event was consumed, false otherwise.
*/
virtual bool keyup(input::keyboard_event& k);
/**
* Called when a key has been pressed by the user.
* @param k the keyboard event.
* @return true if the event was consumed, false otherwise.
*/
virtual bool keydown(input::keyboard_event& k);
//@}
/**
* @name Focus Handling
*/
//@{
/**
* Notification that the object will no longer receive keyboard
* events. Unlike a button, keep the selection state when focus
* is lost.
*/
virtual void unfocus() { }
//@}
//waiting for mouse support
/*
virtual bool mouseup(SDL_MouseButtonEvent & m);
virtual bool mousedown(SDL_MouseButtonEvent & m);
// */
private:
/// state of option widget (selected or not)
bool State;
};
}
#endif//GUI_LABEL_H