git repos / blockattack-game

blame: source/code/MenuSystem.h

normal view · raw

f3ef3495 sago007 2008-11-13 20:00 1
/*
c53e6443 sago007 2012-04-17 11:04 2
===========================================================================
c53e6443 sago007 2012-04-17 11:04 3
blockattack - Block Attack - Rise of the Blocks
c53e6443 sago007 2012-04-17 11:04 4
Copyright (C) 2005-2012 Poul Sander
f3ef3495 sago007 2008-11-13 20:00 5
c53e6443 sago007 2012-04-17 11:04 6
This program is free software: you can redistribute it and/or modify
c53e6443 sago007 2012-04-17 11:04 7
it under the terms of the GNU General Public License as published by
c53e6443 sago007 2012-04-17 11:04 8
the Free Software Foundation, either version 2 of the License, or
c53e6443 sago007 2012-04-17 11:04 9
(at your option) any later version.
f3ef3495 sago007 2008-11-13 20:00 10
c53e6443 sago007 2012-04-17 11:04 11
This program is distributed in the hope that it will be useful,
c53e6443 sago007 2012-04-17 11:04 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
c53e6443 sago007 2012-04-17 11:04 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c53e6443 sago007 2012-04-17 11:04 14
GNU General Public License for more details.
f3ef3495 sago007 2008-11-13 20:00 15
c53e6443 sago007 2012-04-17 11:04 16
You should have received a copy of the GNU General Public License
c53e6443 sago007 2012-04-17 11:04 17
along with this program.  If not, see http://www.gnu.org/licenses/
f3ef3495 sago007 2008-11-13 20:00 18
c53e6443 sago007 2012-04-17 11:04 19
Source information and contacts persons can be found at
c53e6443 sago007 2012-04-17 11:04 20
http://blockattack.sf.net
c53e6443 sago007 2012-04-17 11:04 21
===========================================================================
f3ef3495 sago007 2008-11-13 20:00 22
*/
f3ef3495 sago007 2008-11-13 20:00 23
f3ef3495 sago007 2008-11-13 20:00 24
f3ef3495 sago007 2008-11-13 20:00 25
#ifndef _MENUSYSTEM_H
f3ef3495 sago007 2008-11-13 20:00 26
#define	_MENUSYSTEM_H
f3ef3495 sago007 2008-11-13 20:00 27
f3ef3495 sago007 2008-11-13 20:00 28
#include <string>
f3ef3495 sago007 2008-11-13 20:00 29
#include "SDL.h"
f3ef3495 sago007 2008-11-13 20:00 30
#include <vector>
b7590374 sago007 2011-05-19 16:15 31
#include "Libs/NFont.h"
605138b3 sago007 2012-04-14 15:12 32
#include "CppSdlImageHolder.hpp"
f3ef3495 sago007 2008-11-13 20:00 33
f3ef3495 sago007 2008-11-13 20:00 34
using namespace std;
f3ef3495 sago007 2008-11-13 20:00 35
f3ef3495 sago007 2008-11-13 20:00 36
//The ButtonGfx object hold common media for all buttons, so we can reskin them by only changeing one pointer
c53e6443 sago007 2012-04-17 11:04 37
class ButtonGfx
c53e6443 sago007 2012-04-17 11:04 38
{
c53e6443 sago007 2012-04-17 11:04 39
public:
c53e6443 sago007 2012-04-17 11:04 40
	//Holds the graphic for a button that is selected
b283e0f7 sago007 2012-07-29 14:01 41
	CppSdl::CppSdlImageHolder _marked;
c53e6443 sago007 2012-04-17 11:04 42
	//Holds the graphic for a button that is not selected
b283e0f7 sago007 2012-07-29 14:01 43
	CppSdl::CppSdlImageHolder _unmarked;
c53e6443 sago007 2012-04-17 11:04 44
	//The size of the buttons, so we don't have to ask w and h from the SDL Surfaces each time
b283e0f7 sago007 2012-07-29 14:01 45
	int xsize;
b283e0f7 sago007 2012-07-29 14:01 46
	int ysize;
c53e6443 sago007 2012-04-17 11:04 47
	//A TTFont used for writing the label on the buttons
b283e0f7 sago007 2012-07-29 14:01 48
	NFont thefont;
b283e0f7 sago007 2012-07-29 14:01 49
	void setSurfaces(CppSdl::CppSdlImageHolder marked,CppSdl::CppSdlImageHolder unmarked);
f3ef3495 sago007 2008-11-13 20:00 50
};
f3ef3495 sago007 2008-11-13 20:00 51
b283e0f7 sago007 2012-07-29 14:01 52
extern ButtonGfx standardButton;
b283e0f7 sago007 2012-07-29 14:01 53
f3ef3495 sago007 2008-11-13 20:00 54
//A button
c53e6443 sago007 2012-04-17 11:04 55
class Button
c53e6443 sago007 2012-04-17 11:04 56
{
c53e6443 sago007 2012-04-17 11:04 57
private:
c53e6443 sago007 2012-04-17 11:04 58
	//The label. This is written on the button
c53e6443 sago007 2012-04-17 11:04 59
	string label;
c53e6443 sago007 2012-04-17 11:04 60
	//Pointer to a callback function.
c53e6443 sago007 2012-04-17 11:04 61
	void (*action)(Button *b);
b4f1d3cf sago007 2012-08-20 21:28 62
67a32395 sago007 2012-04-19 18:40 63
	//If true the menu should also be closed then the button is clicked
67a32395 sago007 2012-04-19 18:40 64
	bool popOnRun;
b4f1d3cf sago007 2012-08-20 21:28 65
b283e0f7 sago007 2012-07-29 14:01 66
	ButtonGfx *gfx;
c53e6443 sago007 2012-04-17 11:04 67
c53e6443 sago007 2012-04-17 11:04 68
public:
c53e6443 sago007 2012-04-17 11:04 69
	//Is the button marked?
c53e6443 sago007 2012-04-17 11:04 70
	bool marked;
c53e6443 sago007 2012-04-17 11:04 71
	//Where is the button on the screen
c53e6443 sago007 2012-04-17 11:04 72
	int x;
c53e6443 sago007 2012-04-17 11:04 73
	int y;
c53e6443 sago007 2012-04-17 11:04 74
c53e6443 sago007 2012-04-17 11:04 75
	Button();
c53e6443 sago007 2012-04-17 11:04 76
	Button(const Button& b);
c53e6443 sago007 2012-04-17 11:04 77
	~Button();
c53e6443 sago007 2012-04-17 11:04 78
c53e6443 sago007 2012-04-17 11:04 79
c53e6443 sago007 2012-04-17 11:04 80
	//Set the text to write on the button
c53e6443 sago007 2012-04-17 11:04 81
	void setLabel(string text);
c53e6443 sago007 2012-04-17 11:04 82
	//Set the action to run
c53e6443 sago007 2012-04-17 11:04 83
	void setAction(void (*action2run)(Button*));
c53e6443 sago007 2012-04-17 11:04 84
c53e6443 sago007 2012-04-17 11:04 85
	bool isClicked(int x,int y); //Returns true if (x,y) is within the borders of the button
c53e6443 sago007 2012-04-17 11:04 86
	virtual void doAction(); //Run the callback function
67a32395 sago007 2012-04-19 18:40 87
	void drawTo(SDL_Surface **surface);
b4f1d3cf sago007 2012-08-20 21:28 88
	void setPopOnRun(bool popOnRun);
b4f1d3cf sago007 2012-08-20 21:28 89
	bool isPopOnRun() const;
b4f1d3cf sago007 2012-08-20 21:28 90
	void setGfx(ButtonGfx* gfx); //Draws to screen
b283e0f7 sago007 2012-07-29 14:01 91
	int getHeight();
b4f1d3cf sago007 2012-08-20 21:28 92
67a32395 sago007 2012-04-19 18:40 93
	//May hold any other information the callback might need
67a32395 sago007 2012-04-19 18:40 94
	int iGeneric1;
f3ef3495 sago007 2008-11-13 20:00 95
};
f3ef3495 sago007 2008-11-13 20:00 96
26ddb424 sago007 2011-06-09 20:06 97
c53e6443 sago007 2012-04-17 11:04 98
class Menu
c53e6443 sago007 2012-04-17 11:04 99
{
c53e6443 sago007 2012-04-17 11:04 100
private:
c53e6443 sago007 2012-04-17 11:04 101
	vector<Button*> buttons; //Vector holder the buttons
c53e6443 sago007 2012-04-17 11:04 102
	Button exit; //The exit button is special since it does not have a callback function
c53e6443 sago007 2012-04-17 11:04 103
	bool isSubmenu; //True if the menu is a submenu
c53e6443 sago007 2012-04-17 11:04 104
	int marked; //The index of the marked button (for keyboard up/down)
c53e6443 sago007 2012-04-17 11:04 105
	bool running; //The menu is running. The menu will terminate then this is false
c53e6443 sago007 2012-04-17 11:04 106
	SDL_Surface *screen; //Pointer to the screen to draw to
c53e6443 sago007 2012-04-17 11:04 107
	string title;
f3ef3495 sago007 2008-11-13 20:00 108
//        SDL_Surface *background; //Pointer to the background image
c53e6443 sago007 2012-04-17 11:04 109
c53e6443 sago007 2012-04-17 11:04 110
	void drawSelf();        //Private function to draw the screen
c53e6443 sago007 2012-04-17 11:04 111
	void performClick(int x, int y); //Private function to call then a click is detected.
c53e6443 sago007 2012-04-17 11:04 112
	void placeButtons(); //Rearanges the buttons to the correct place.
c53e6443 sago007 2012-04-17 11:04 113
public:
c53e6443 sago007 2012-04-17 11:04 114
	//numberOfItems is the expected numberOfItems for vector initialization
c53e6443 sago007 2012-04-17 11:04 115
	//SubMenu is true by default
c53e6443 sago007 2012-04-17 11:04 116
	Menu(SDL_Surface **screen,bool isSubmenu);
c53e6443 sago007 2012-04-17 11:04 117
	Menu(SDL_Surface **screen);
c53e6443 sago007 2012-04-17 11:04 118
	Menu(SDL_Surface **screen, string title, bool isSubmenu);
c53e6443 sago007 2012-04-17 11:04 119
c53e6443 sago007 2012-04-17 11:04 120
	//Add a button to the menu
c53e6443 sago007 2012-04-17 11:04 121
	void addButton(Button *b);
c53e6443 sago007 2012-04-17 11:04 122
c53e6443 sago007 2012-04-17 11:04 123
	//Run the menu
c53e6443 sago007 2012-04-17 11:04 124
	void run();
f3ef3495 sago007 2008-11-13 20:00 125
};
f3ef3495 sago007 2008-11-13 20:00 126
c53e6443 sago007 2012-04-17 11:04 127
class FileMenu
c53e6443 sago007 2012-04-17 11:04 128
{
cc3ef158 sago007 2011-07-03 16:13 129
private:
c53e6443 sago007 2012-04-17 11:04 130
	string pm_path;
c53e6443 sago007 2012-04-17 11:04 131
	string pm_fileending;
c53e6443 sago007 2012-04-17 11:04 132
	bool pm_hidden_files;
cc3ef158 sago007 2011-07-03 16:13 133
public:
c53e6443 sago007 2012-04-17 11:04 134
	FileMenu(string path,string fileending,bool hidden_files = false);
c53e6443 sago007 2012-04-17 11:04 135
c53e6443 sago007 2012-04-17 11:04 136
	string getFile(SDL_Surface **screen);
cc3ef158 sago007 2011-07-03 16:13 137
};
cc3ef158 sago007 2011-07-03 16:13 138
f3ef3495 sago007 2008-11-13 20:00 139
#endif	/* _MENUSYSTEM_H */
f3ef3495 sago007 2008-11-13 20:00 140
1970-01-01 00:00 141