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