git repos / blockattack-game

blame: source/code/MenuSystem.cc

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
c53e6443 sago007 2012-04-17 11:04 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.
c53e6443 sago007 2012-04-17 11:04 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.
c53e6443 sago007 2012-04-17 11:04 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/
c53e6443 sago007 2012-04-17 11:04 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
b7590374 sago007 2011-05-19 16:15 24
#include <SDL/SDL_events.h>
b7590374 sago007 2011-05-19 16:15 25
f3ef3495 sago007 2008-11-13 20:00 26
#include "MenuSystem.h"
f3ef3495 sago007 2008-11-13 20:00 27
#include "common.h"
605138b3 sago007 2012-04-14 15:12 28
#include "CppSdlImageHolder.hpp"
f3ef3495 sago007 2008-11-13 20:00 29
b7590374 sago007 2011-05-19 16:15 30
extern CppSdl::CppSdlImageHolder mouse;
f3ef3495 sago007 2008-11-13 20:00 31
extern SDL_Surface *backgroundImage;
f3ef3495 sago007 2008-11-13 20:00 32
extern bool highPriority;
56241205 sago007 2012-08-05 11:15 33
extern int verboseLevel;
f3ef3495 sago007 2008-11-13 20:00 34
int mousex;
f3ef3495 sago007 2008-11-13 20:00 35
int mousey;
f3ef3495 sago007 2008-11-13 20:00 36
f3ef3495 sago007 2008-11-13 20:00 37
/*Draws a image from on a given Surface. Takes source image, destination surface and coordinates*/
f3ef3495 sago007 2008-11-13 20:00 38
inline void DrawIMG(SDL_Surface *img, SDL_Surface *target, int x, int y)
f3ef3495 sago007 2008-11-13 20:00 39
{
c53e6443 sago007 2012-04-17 11:04 40
	SDL_Rect dest;
c53e6443 sago007 2012-04-17 11:04 41
	dest.x = x;
c53e6443 sago007 2012-04-17 11:04 42
	dest.y = y;
c53e6443 sago007 2012-04-17 11:04 43
	SDL_BlitSurface(img, NULL, target, &dest);
f3ef3495 sago007 2008-11-13 20:00 44
}
f3ef3495 sago007 2008-11-13 20:00 45
b283e0f7 sago007 2012-07-29 14:01 46
/*CppSdl::CppSdlImageHolder ButtonGfx::_marked;
b7590374 sago007 2011-05-19 16:15 47
CppSdl::CppSdlImageHolder ButtonGfx::_unmarked;
f3ef3495 sago007 2008-11-13 20:00 48
int ButtonGfx::xsize;
f3ef3495 sago007 2008-11-13 20:00 49
int ButtonGfx::ysize;
b283e0f7 sago007 2012-07-29 14:01 50
NFont ButtonGfx::thefont;*/
b283e0f7 sago007 2012-07-29 14:01 51
b283e0f7 sago007 2012-07-29 14:01 52
ButtonGfx standardButton;
f3ef3495 sago007 2008-11-13 20:00 53
b7590374 sago007 2011-05-19 16:15 54
void ButtonGfx::setSurfaces(CppSdl::CppSdlImageHolder marked,CppSdl::CppSdlImageHolder unmarked)
f3ef3495 sago007 2008-11-13 20:00 55
{
c53e6443 sago007 2012-04-17 11:04 56
	ButtonGfx::_marked = marked;
c53e6443 sago007 2012-04-17 11:04 57
	ButtonGfx::_unmarked = unmarked;
c53e6443 sago007 2012-04-17 11:04 58
	xsize=(marked).GetWidth();
c53e6443 sago007 2012-04-17 11:04 59
	ysize=(marked).GetHeight();
56241205 sago007 2012-08-05 11:15 60
	if(verboseLevel)
56241205 sago007 2012-08-05 11:15 61
		cout << "Surfaces set, size: " <<xsize << " , " << ysize << endl;
f3ef3495 sago007 2008-11-13 20:00 62
}
f3ef3495 sago007 2008-11-13 20:00 63
f3ef3495 sago007 2008-11-13 20:00 64
Button::Button()
f3ef3495 sago007 2008-11-13 20:00 65
{
b283e0f7 sago007 2012-07-29 14:01 66
	gfx = &standardButton;
c53e6443 sago007 2012-04-17 11:04 67
	label = "";
c53e6443 sago007 2012-04-17 11:04 68
	marked = false;
c53e6443 sago007 2012-04-17 11:04 69
	action = NULL;
67a32395 sago007 2012-04-19 18:40 70
	popOnRun = false;
f3ef3495 sago007 2008-11-13 20:00 71
}
f3ef3495 sago007 2008-11-13 20:00 72
f3ef3495 sago007 2008-11-13 20:00 73
Button::~Button()
f3ef3495 sago007 2008-11-13 20:00 74
{
f3ef3495 sago007 2008-11-13 20:00 75
}
f3ef3495 sago007 2008-11-13 20:00 76
f3ef3495 sago007 2008-11-13 20:00 77
Button::Button(const Button& b)
f3ef3495 sago007 2008-11-13 20:00 78
{
b283e0f7 sago007 2012-07-29 14:01 79
	gfx = b.gfx;
c53e6443 sago007 2012-04-17 11:04 80
	label = b.label;
c53e6443 sago007 2012-04-17 11:04 81
	marked = b.marked;
c53e6443 sago007 2012-04-17 11:04 82
	action = b.action;
67a32395 sago007 2012-04-19 18:40 83
	popOnRun = false;
f3ef3495 sago007 2008-11-13 20:00 84
}
f3ef3495 sago007 2008-11-13 20:00 85
f3ef3495 sago007 2008-11-13 20:00 86
void Button::setLabel(string text)
f3ef3495 sago007 2008-11-13 20:00 87
{
c53e6443 sago007 2012-04-17 11:04 88
	label = text;
f3ef3495 sago007 2008-11-13 20:00 89
}
f3ef3495 sago007 2008-11-13 20:00 90
26ddb424 sago007 2011-06-09 20:06 91
void Button::setAction(void (*action2run)(Button*))
f3ef3495 sago007 2008-11-13 20:00 92
{
c53e6443 sago007 2012-04-17 11:04 93
	action = action2run;
f3ef3495 sago007 2008-11-13 20:00 94
}
f3ef3495 sago007 2008-11-13 20:00 95
f3ef3495 sago007 2008-11-13 20:00 96
bool Button::isClicked(int x,int y)
f3ef3495 sago007 2008-11-13 20:00 97
{
b283e0f7 sago007 2012-07-29 14:01 98
	if ( x >= this->x && y >= this->y && x<= this->x+gfx->xsize && y <= this->y + gfx->ysize)
c53e6443 sago007 2012-04-17 11:04 99
		return true;
c53e6443 sago007 2012-04-17 11:04 100
	else
c53e6443 sago007 2012-04-17 11:04 101
		return false;
f3ef3495 sago007 2008-11-13 20:00 102
}
f3ef3495 sago007 2008-11-13 20:00 103
f3ef3495 sago007 2008-11-13 20:00 104
void Button::doAction()
f3ef3495 sago007 2008-11-13 20:00 105
{
c53e6443 sago007 2012-04-17 11:04 106
	if(action)
c53e6443 sago007 2012-04-17 11:04 107
		action(this);
c53e6443 sago007 2012-04-17 11:04 108
	else
56241205 sago007 2012-08-05 11:15 109
		cerr << "Warning: button \"" << label << "\" has no action assigned!";
f3ef3495 sago007 2008-11-13 20:00 110
}
f3ef3495 sago007 2008-11-13 20:00 111
b7590374 sago007 2011-05-19 16:15 112
void Button::drawTo(SDL_Surface **surface)
f3ef3495 sago007 2008-11-13 20:00 113
{
c53e6443 sago007 2012-04-17 11:04 114
#if DEBUG
c53e6443 sago007 2012-04-17 11:04 115
	//cout << "Painting button: " << label << " at: " << x << "," << y << endl;
c53e6443 sago007 2012-04-17 11:04 116
#endif
c53e6443 sago007 2012-04-17 11:04 117
	if (marked)
b283e0f7 sago007 2012-07-29 14:01 118
		gfx->_marked.PaintTo(*surface,x,y);
c53e6443 sago007 2012-04-17 11:04 119
	else
b283e0f7 sago007 2012-07-29 14:01 120
		gfx->_unmarked.PaintTo(*surface,x,y);
c53e6443 sago007 2012-04-17 11:04 121
	//int stringx = x + (ButtonGfx::xsize)/2 - ButtonGfx::ttf->getTextWidth(label)/2;
c53e6443 sago007 2012-04-17 11:04 122
	//int stringy = y + (ButtonGfx::ysize)/2 - ButtonGfx::ttf->getTextHeight()/2;
c53e6443 sago007 2012-04-17 11:04 123
	//ButtonGfx::ttf->writeText(label,surface,stringx,stringy);
b283e0f7 sago007 2012-07-29 14:01 124
	gfx->thefont.setDest(*surface);
b283e0f7 sago007 2012-07-29 14:01 125
	gfx->thefont.drawCenter(x+gfx->xsize/2,y+gfx->ysize/2-gfx->thefont.getHeight(label.c_str())/2,label.c_str());
f3ef3495 sago007 2008-11-13 20:00 126
}
f3ef3495 sago007 2008-11-13 20:00 127
67a32395 sago007 2012-04-19 18:40 128
void Button::setPopOnRun(bool popOnRun)
67a32395 sago007 2012-04-19 18:40 129
{
67a32395 sago007 2012-04-19 18:40 130
	this->popOnRun = popOnRun;
67a32395 sago007 2012-04-19 18:40 131
}
67a32395 sago007 2012-04-19 18:40 132
67a32395 sago007 2012-04-19 18:40 133
bool Button::isPopOnRun() const
67a32395 sago007 2012-04-19 18:40 134
{
67a32395 sago007 2012-04-19 18:40 135
	return popOnRun;
67a32395 sago007 2012-04-19 18:40 136
}
67a32395 sago007 2012-04-19 18:40 137
b283e0f7 sago007 2012-07-29 14:01 138
void Button::setGfx(ButtonGfx* gfx)
b283e0f7 sago007 2012-07-29 14:01 139
{
b283e0f7 sago007 2012-07-29 14:01 140
	this->gfx = gfx;
b283e0f7 sago007 2012-07-29 14:01 141
}
b283e0f7 sago007 2012-07-29 14:01 142
80b830cd sago007 2012-08-19 17:51 143
int Button::getHeight()
80b830cd sago007 2012-08-19 17:51 144
{
b283e0f7 sago007 2012-07-29 14:01 145
	return this->gfx->ysize;
b283e0f7 sago007 2012-07-29 14:01 146
}
b283e0f7 sago007 2012-07-29 14:01 147
f3ef3495 sago007 2008-11-13 20:00 148
void Menu::drawSelf()
f3ef3495 sago007 2008-11-13 20:00 149
{
c53e6443 sago007 2012-04-17 11:04 150
	DrawIMG(backgroundImage,screen,0,0);
c53e6443 sago007 2012-04-17 11:04 151
	vector<Button*>::iterator it;
c53e6443 sago007 2012-04-17 11:04 152
	for(it = buttons.begin(); it < buttons.end(); it++)
c53e6443 sago007 2012-04-17 11:04 153
		(*it)->drawTo(&screen);
c53e6443 sago007 2012-04-17 11:04 154
	exit.drawTo(&screen);
b283e0f7 sago007 2012-07-29 14:01 155
	standardButton.thefont.draw(50,50,title.c_str());
c53e6443 sago007 2012-04-17 11:04 156
	mouse.PaintTo(screen,mousex,mousey);
f3ef3495 sago007 2008-11-13 20:00 157
}
f3ef3495 sago007 2008-11-13 20:00 158
f3ef3495 sago007 2008-11-13 20:00 159
void Menu::performClick(int x,int y)
f3ef3495 sago007 2008-11-13 20:00 160
{
c53e6443 sago007 2012-04-17 11:04 161
	vector<Button*>::iterator it;
c53e6443 sago007 2012-04-17 11:04 162
	for(it = buttons.begin(); it < buttons.end(); it++)
c53e6443 sago007 2012-04-17 11:04 163
	{
c53e6443 sago007 2012-04-17 11:04 164
		Button *b = (*it);
c53e6443 sago007 2012-04-17 11:04 165
		if(b->isClicked(x,y))
c53e6443 sago007 2012-04-17 11:04 166
			b->doAction();
67a32395 sago007 2012-04-19 18:40 167
		if(b->isPopOnRun())
67a32395 sago007 2012-04-19 18:40 168
			running = false;
c53e6443 sago007 2012-04-17 11:04 169
	}
c53e6443 sago007 2012-04-17 11:04 170
	if(exit.isClicked(x,y))
c53e6443 sago007 2012-04-17 11:04 171
		running = false;
f3ef3495 sago007 2008-11-13 20:00 172
}
f3ef3495 sago007 2008-11-13 20:00 173
f3ef3495 sago007 2008-11-13 20:00 174
void Menu::placeButtons()
f3ef3495 sago007 2008-11-13 20:00 175
{
c53e6443 sago007 2012-04-17 11:04 176
	int nextY = 100;
c53e6443 sago007 2012-04-17 11:04 177
	const int X = 50;
c53e6443 sago007 2012-04-17 11:04 178
	vector<Button*>::iterator it;
c53e6443 sago007 2012-04-17 11:04 179
	for(it = buttons.begin(); it < buttons.end(); it++)
c53e6443 sago007 2012-04-17 11:04 180
	{
c53e6443 sago007 2012-04-17 11:04 181
		(*it)->x = X;
c53e6443 sago007 2012-04-17 11:04 182
		(*it)->y = nextY;
b283e0f7 sago007 2012-07-29 14:01 183
		nextY += (*it)->getHeight()+10;
c53e6443 sago007 2012-04-17 11:04 184
	}
c53e6443 sago007 2012-04-17 11:04 185
	exit.x = X;
c53e6443 sago007 2012-04-17 11:04 186
	exit.y = nextY;
f3ef3495 sago007 2008-11-13 20:00 187
}
f3ef3495 sago007 2008-11-13 20:00 188
fc8e3d6a sago007 2011-06-25 16:31 189
void Menu::addButton(Button *b)
f3ef3495 sago007 2008-11-13 20:00 190
{
c53e6443 sago007 2012-04-17 11:04 191
	buttons.push_back(b);
c53e6443 sago007 2012-04-17 11:04 192
	b->marked = false;
c53e6443 sago007 2012-04-17 11:04 193
	placeButtons();
f3ef3495 sago007 2008-11-13 20:00 194
}
f3ef3495 sago007 2008-11-13 20:00 195
f3ef3495 sago007 2008-11-13 20:00 196
Menu::Menu(SDL_Surface **screen)
f3ef3495 sago007 2008-11-13 20:00 197
{
c53e6443 sago007 2012-04-17 11:04 198
	this->screen = *screen;
c53e6443 sago007 2012-04-17 11:04 199
	buttons = vector<Button*>(10);
c53e6443 sago007 2012-04-17 11:04 200
	isSubmenu = true;
c53e6443 sago007 2012-04-17 11:04 201
	exit.setLabel( _("Back") );
f3ef3495 sago007 2008-11-13 20:00 202
}
f3ef3495 sago007 2008-11-13 20:00 203
f3ef3495 sago007 2008-11-13 20:00 204
Menu::Menu(SDL_Surface **screen,bool submenu)
f3ef3495 sago007 2008-11-13 20:00 205
{
c53e6443 sago007 2012-04-17 11:04 206
	this->screen = *screen;
c53e6443 sago007 2012-04-17 11:04 207
	buttons = vector<Button*>(0);
c53e6443 sago007 2012-04-17 11:04 208
	isSubmenu = submenu;
c53e6443 sago007 2012-04-17 11:04 209
	if(isSubmenu)
c53e6443 sago007 2012-04-17 11:04 210
		exit.setLabel( _("Back") );
c53e6443 sago007 2012-04-17 11:04 211
	else
c53e6443 sago007 2012-04-17 11:04 212
		exit.setLabel( _("Exit") );
f3ef3495 sago007 2008-11-13 20:00 213
}
f3ef3495 sago007 2008-11-13 20:00 214
c53e6443 sago007 2012-04-17 11:04 215
Menu::Menu(SDL_Surface** screen, string title, bool submenu)
c53e6443 sago007 2012-04-17 11:04 216
{
c53e6443 sago007 2012-04-17 11:04 217
	this->screen = *screen;
c53e6443 sago007 2012-04-17 11:04 218
	buttons = vector<Button*>(0);
c53e6443 sago007 2012-04-17 11:04 219
	isSubmenu = submenu;
c53e6443 sago007 2012-04-17 11:04 220
	this->title = title;
c53e6443 sago007 2012-04-17 11:04 221
	if(isSubmenu)
c53e6443 sago007 2012-04-17 11:04 222
		exit.setLabel(_("Back") );
c53e6443 sago007 2012-04-17 11:04 223
	else
c53e6443 sago007 2012-04-17 11:04 224
		exit.setLabel(_("Exit") );
cc3ef158 sago007 2011-07-03 16:13 225
}
cc3ef158 sago007 2011-07-03 16:13 226
f3ef3495 sago007 2008-11-13 20:00 227
void Menu::run()
f3ef3495 sago007 2008-11-13 20:00 228
{
c53e6443 sago007 2012-04-17 11:04 229
	running = true;
c53e6443 sago007 2012-04-17 11:04 230
	bool bMouseUp = false;
c53e6443 sago007 2012-04-17 11:04 231
	long oldmousex = mousex;
c53e6443 sago007 2012-04-17 11:04 232
	long oldmousey = mousey;
c53e6443 sago007 2012-04-17 11:04 233
	while(running && !Config::getInstance()->isShuttingDown())
c53e6443 sago007 2012-04-17 11:04 234
	{
c53e6443 sago007 2012-04-17 11:04 235
		if (!(highPriority)) SDL_Delay(10);
c53e6443 sago007 2012-04-17 11:04 236
c53e6443 sago007 2012-04-17 11:04 237
c53e6443 sago007 2012-04-17 11:04 238
		SDL_Event event;
c53e6443 sago007 2012-04-17 11:04 239
c53e6443 sago007 2012-04-17 11:04 240
		while ( SDL_PollEvent(&event) )
c53e6443 sago007 2012-04-17 11:04 241
		{
c53e6443 sago007 2012-04-17 11:04 242
			if ( event.type == SDL_QUIT )
c53e6443 sago007 2012-04-17 11:04 243
			{
c53e6443 sago007 2012-04-17 11:04 244
				Config::getInstance()->setShuttingDown(5);
c53e6443 sago007 2012-04-17 11:04 245
				running = false;
c53e6443 sago007 2012-04-17 11:04 246
			}
c53e6443 sago007 2012-04-17 11:04 247
c53e6443 sago007 2012-04-17 11:04 248
			if ( event.type == SDL_KEYDOWN )
c53e6443 sago007 2012-04-17 11:04 249
			{
c53e6443 sago007 2012-04-17 11:04 250
				if ( event.key.keysym.sym == SDLK_ESCAPE )
c53e6443 sago007 2012-04-17 11:04 251
				{
c53e6443 sago007 2012-04-17 11:04 252
					running = false;
c53e6443 sago007 2012-04-17 11:04 253
				}
c53e6443 sago007 2012-04-17 11:04 254
c53e6443 sago007 2012-04-17 11:04 255
				if (event.key.keysym.sym == SDLK_UP)
c53e6443 sago007 2012-04-17 11:04 256
				{
c53e6443 sago007 2012-04-17 11:04 257
					marked--;
c53e6443 sago007 2012-04-17 11:04 258
					if(marked<0)
c53e6443 sago007 2012-04-17 11:04 259
						marked = buttons.size(); //not -1, since exit is after the last element in the list
c53e6443 sago007 2012-04-17 11:04 260
				}
c53e6443 sago007 2012-04-17 11:04 261
c53e6443 sago007 2012-04-17 11:04 262
				if (event.key.keysym.sym == SDLK_DOWN)
c53e6443 sago007 2012-04-17 11:04 263
				{
c53e6443 sago007 2012-04-17 11:04 264
					marked++;
c53e6443 sago007 2012-04-17 11:04 265
					if(marked>buttons.size())
c53e6443 sago007 2012-04-17 11:04 266
						marked = 0;
c53e6443 sago007 2012-04-17 11:04 267
				}
c53e6443 sago007 2012-04-17 11:04 268
c53e6443 sago007 2012-04-17 11:04 269
				if(event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_KP_ENTER )
c53e6443 sago007 2012-04-17 11:04 270
				{
80b830cd sago007 2012-08-19 17:51 271
					if(marked < buttons.size())
80b830cd sago007 2012-08-19 17:51 272
					{
c53e6443 sago007 2012-04-17 11:04 273
						buttons.at(marked)->doAction();
67a32395 sago007 2012-04-19 18:40 274
						if(buttons.at(marked)->isPopOnRun())
67a32395 sago007 2012-04-19 18:40 275
							running = false;
67a32395 sago007 2012-04-19 18:40 276
					}
c53e6443 sago007 2012-04-17 11:04 277
					if(marked == buttons.size())
c53e6443 sago007 2012-04-17 11:04 278
						running = false;
c53e6443 sago007 2012-04-17 11:04 279
				}
c53e6443 sago007 2012-04-17 11:04 280
			}
c53e6443 sago007 2012-04-17 11:04 281
c53e6443 sago007 2012-04-17 11:04 282
c53e6443 sago007 2012-04-17 11:04 283
		}
c53e6443 sago007 2012-04-17 11:04 284
c53e6443 sago007 2012-04-17 11:04 285
		for(int i=0; i<buttons.size(); i++)
c53e6443 sago007 2012-04-17 11:04 286
		{
c53e6443 sago007 2012-04-17 11:04 287
			buttons.at(i)->marked = (i == marked);
c53e6443 sago007 2012-04-17 11:04 288
		}
c53e6443 sago007 2012-04-17 11:04 289
		exit.marked = (marked == buttons.size());
c53e6443 sago007 2012-04-17 11:04 290
		Uint8 buttonState = SDL_GetMouseState(&mousex,&mousey);
c53e6443 sago007 2012-04-17 11:04 291
		// If the mouse button is released, make bMouseUp equal true
c53e6443 sago007 2012-04-17 11:04 292
		if ( (buttonState&SDL_BUTTON(1))==0)
c53e6443 sago007 2012-04-17 11:04 293
		{
c53e6443 sago007 2012-04-17 11:04 294
			bMouseUp=true;
c53e6443 sago007 2012-04-17 11:04 295
		}
c53e6443 sago007 2012-04-17 11:04 296
c53e6443 sago007 2012-04-17 11:04 297
		if(abs(mousex-oldmousex)>5 || abs(mousey-oldmousey)>5)
c53e6443 sago007 2012-04-17 11:04 298
		{
c53e6443 sago007 2012-04-17 11:04 299
			for(int i=0; i< buttons.size(); ++i)
c53e6443 sago007 2012-04-17 11:04 300
			{
c53e6443 sago007 2012-04-17 11:04 301
				if(buttons.at(i)->isClicked(mousex,mousey))
c53e6443 sago007 2012-04-17 11:04 302
				{
c53e6443 sago007 2012-04-17 11:04 303
					marked = i;
c53e6443 sago007 2012-04-17 11:04 304
				}
c53e6443 sago007 2012-04-17 11:04 305
			}
c53e6443 sago007 2012-04-17 11:04 306
			if(exit.isClicked(mousex,mousey))
c53e6443 sago007 2012-04-17 11:04 307
			{
c53e6443 sago007 2012-04-17 11:04 308
				marked = buttons.size();
c53e6443 sago007 2012-04-17 11:04 309
			}
c53e6443 sago007 2012-04-17 11:04 310
			oldmousex = mousex;
c53e6443 sago007 2012-04-17 11:04 311
			oldmousey = mousey;
c53e6443 sago007 2012-04-17 11:04 312
		}
c53e6443 sago007 2012-04-17 11:04 313
c53e6443 sago007 2012-04-17 11:04 314
		//mouse clicked
c53e6443 sago007 2012-04-17 11:04 315
		if(buttonState&SDL_BUTTON(1)==SDL_BUTTON(1) && bMouseUp)
c53e6443 sago007 2012-04-17 11:04 316
		{
c53e6443 sago007 2012-04-17 11:04 317
			bMouseUp = false;
c53e6443 sago007 2012-04-17 11:04 318
			for(int i=0; i< buttons.size(); ++i)
c53e6443 sago007 2012-04-17 11:04 319
			{
c53e6443 sago007 2012-04-17 11:04 320
				if(buttons.at(i)->isClicked(mousex,mousey))
c53e6443 sago007 2012-04-17 11:04 321
				{
c53e6443 sago007 2012-04-17 11:04 322
					buttons.at(i)->doAction();
67a32395 sago007 2012-04-19 18:40 323
					if(buttons.at(i)->isPopOnRun())
67a32395 sago007 2012-04-19 18:40 324
						running = false;
67a32395 sago007 2012-04-19 18:40 325
					mousex = 0;
c53e6443 sago007 2012-04-17 11:04 326
				}
c53e6443 sago007 2012-04-17 11:04 327
			}
c53e6443 sago007 2012-04-17 11:04 328
			if(exit.isClicked(mousex,mousey))
c53e6443 sago007 2012-04-17 11:04 329
			{
c53e6443 sago007 2012-04-17 11:04 330
				running = false;
c53e6443 sago007 2012-04-17 11:04 331
			}
c53e6443 sago007 2012-04-17 11:04 332
		}
c53e6443 sago007 2012-04-17 11:04 333
c53e6443 sago007 2012-04-17 11:04 334
		drawSelf();
c53e6443 sago007 2012-04-17 11:04 335
		SDL_Flip(screen);
c53e6443 sago007 2012-04-17 11:04 336
	}
f3ef3495 sago007 2008-11-13 20:00 337
}
1970-01-01 00:00 338