-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmenu.hpp
71 lines (53 loc) · 2.25 KB
/
menu.hpp
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
/*
This file is part of Heroes of Wesnoth.
Copyright (C) 2007, 2008, 2009 Jon Ander Peñalba <[email protected]>
Heroes of Wesnoth is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.
Heroes of Wesnoth 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 Heroes of Wesnoth. If not, see <http://www.gnu.org/licenses/>
*/
/// @file
/// The Menu class.
/// @author Jonan
#ifndef MENU_HPP
#define MENU_HPP
#include <deque>
#include <SDL/SDL.h>
#include "game_loop.hpp"
/// Controls a set of various Button classes as a group.
class Menu : public GameLoop{
public:
/// @param[in] position Top left hand corner of the menu.
explicit Menu(SDL_Rect position); // Constructor
~Menu(void); // Destructor
/// Activates the menu.
void start(void) {loop();}
/// Adds a new button to the menu.
/// @param[in] text Text to be writen in the button.
/// @param[in] function Function to execute when the button is pressed.
void addButton(const char *text, void (&function)(void));
/// Sets a background for the menu.
/// From now on, the menu will call drawBackgroundFuntion()
/// for drawing the background every time this is needed.
/// @param[in] drawBackgroundFunction Funtion that draws the background.
void setBackground(void (&drawBackgroundFunction)(void));
private:
class Button;
// Draws the menu.
void draw(void);
// Funtion that will be called inside the loop
virtual bool frame(void);
SDL_Rect position; // Position of the top left hand corner of the menu.
SDL_Surface *button_surface[3]; // The three button images.
std::deque<Button*> buttons; // The buttons in the menu.
int active_button; // Number of the button with the mouse over.
int pressed_button; // Number of the button pressed.
void (*drawBackgroundFunction)(void); // Function that draws the background.
DISALLOW_COPY_AND_ASSIGN(Menu);
};
#endif // MENU_HPP