| f3ef3495 |
sago007 |
2008-11-13 20:00 |
1 |
/* |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
2 |
Block Attack - Rise of the Blocks, SDL game, besed on Nintendo's Tetris Attack |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
3 |
Copyright (C) 2008 Poul Sander |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
4 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
5 |
This program is free software; you can redistribute it and/or modify |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
6 |
it under the terms of the GNU General Public License as published by |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
7 |
the Free Software Foundation; either version 2 of the License, or |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
8 |
(at your option) any later version. |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
9 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
10 |
This program is distributed in the hope that it will be useful, |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
13 |
GNU General Public License for more details. |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
14 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
15 |
You should have received a copy of the GNU General Public License |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
16 |
along with this program; if not, write to the Free Software |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
17 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
18 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
19 |
Poul Sander |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
20 |
R�vehjvej 36, V. 1111 |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
21 |
2800 Kgs. Lyngby |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
22 |
DENMARK |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
23 |
blockattack@poulsander.com |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
24 |
http://blockattack.sf.net |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
25 |
*/ |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
26 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
27 |
// |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
28 |
// File: MenuSystem.h |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
29 |
// Author: poul |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
30 |
// |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
31 |
// Created on 28. september 2008, 17:06 |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
32 |
// |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
33 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
34 |
#ifndef _MENUSYSTEM_H |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
35 |
#define _MENUSYSTEM_H |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
36 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
37 |
#include <string> |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
38 |
#include "SDL.h" |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
39 |
#include <vector> |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
40 |
#include "ttfont.h" |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
41 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
42 |
using namespace std; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
43 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
44 |
//The ButtonGfx object hold common media for all buttons, so we can reskin them by only changeing one pointer |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
45 |
class ButtonGfx { |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
46 |
public: |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
47 |
//Holds the graphic for a button that is selected |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
48 |
static SDL_Surface *marked; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
49 |
//Holds the graphic for a button that is not selected |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
50 |
static SDL_Surface *unmarked; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
51 |
//The size of the buttons, so we don't have to ask w and h from the SDL Surfaces each time |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
52 |
static int xsize; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
53 |
static int ysize; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
54 |
//A TTFont used for writing the label on the buttons |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
55 |
static TTFont *ttf; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
56 |
//Yes I use pointer-to-pointer and yes it is inheriently insecure |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
57 |
static void setSurfaces(SDL_Surface **marked,SDL_Surface **unmarked); |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
58 |
}; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
59 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
60 |
//A button |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
61 |
class Button { |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
62 |
private: |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
63 |
//The label. This is written on the button |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
64 |
string label; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
65 |
SDL_Surface* surfaceMarked; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
66 |
SDL_Surface* surfaceUnmarked; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
67 |
//Pointer to a callback function. |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
68 |
void (*action)(); |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
69 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
70 |
public: |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
71 |
//Is the button marked? |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
72 |
bool marked; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
73 |
//Where is the button on the screen |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
74 |
int x; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
75 |
int y; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
76 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
77 |
Button(); |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
78 |
Button(const Button& b); |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
79 |
~Button(); |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
80 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
81 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
82 |
//Set the text to write on the button |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
83 |
void setLabel(string text); |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
84 |
//Set the action to run |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
85 |
void setAction(void (*action2run)()); |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
86 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
87 |
bool isClicked(int x,int y); //Returns true if (x,y) is within the borders of the button |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
88 |
void doAction(); //Run the callback function |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
89 |
void drawTo(SDL_Surface *surface); //Draws to screen |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
90 |
}; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
91 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
92 |
class Menu { |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
93 |
private: |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
94 |
vector<Button> buttons; //Vector holder the buttons |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
95 |
Button exit; //The exit button is special since it does not have a callback function |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
96 |
bool isSubmenu; //True if the menu is a submenu |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
97 |
int marked; //The index of the marked button (for keyboard up/down) |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
98 |
bool running; //The menu is running. The menu will terminate then this is false |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
99 |
SDL_Surface *screen; //Pointer to the screen to draw to |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
100 |
// SDL_Surface *background; //Pointer to the background image |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
101 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
102 |
void drawSelf(); //Private function to draw the screen |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
103 |
void performClick(int x, int y); //Private function to call then a click is detected. |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
104 |
void placeButtons(); //Rearanges the buttons to the correct place. |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
105 |
public: |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
106 |
//numberOfItems is the expected numberOfItems for vector initialization |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
107 |
//SubMenu is true by default |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
108 |
Menu(SDL_Surface **screen,bool isSubmenu); |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
109 |
Menu(SDL_Surface **screen); |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
110 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
111 |
//Add a button to the menu |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
112 |
void addButton(Button b); |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
113 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
114 |
//Run the menu |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
115 |
void run(); |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
116 |
}; |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
117 |
|
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
118 |
#endif /* _MENUSYSTEM_H */ |
| f3ef3495 |
sago007 |
2008-11-13 20:00 |
119 |
|
|
|
1970-01-01 00:00 |
120 |
|