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