git repos / blockattack-game

blame: source/code/MenuSystem.cpp

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