git repos / blockattack-game

commit 6258a442

sago007 · 2015-11-14 22:11
6258a442f7c1a549be1c8d14450f05ead424dee7 patch · browse files
parent 78ab168ed39f8f8a85269198ad3f84654a242854

Small adjustments

Changed files

M source/code/MenuSystem.cpp before
diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp index d53b1b4..86f8917 100644 --- a/source/code/MenuSystem.cpp +++ b/source/code/MenuSystem.cpp
@@ -45,12 +45,6 @@ inline void DrawIMG(SDL_Surface *img, SDL_Surface *target, int x, int y)
SDL_BlitSurface(img, NULL, target, &dest);
}
-/*CppSdl::CppSdlImageHolder ButtonGfx::_marked;
-CppSdl::CppSdlImageHolder ButtonGfx::_unmarked;
-int ButtonGfx::xsize;
-int ButtonGfx::ysize;
-NFont ButtonGfx::thefont;*/
-
ButtonGfx standardButton;
void ButtonGfx::setSurfaces(shared_ptr<CppSdl::CppSdlImageHolder> marked, shared_ptr<CppSdl::CppSdlImageHolder> unmarked)
@@ -97,18 +91,19 @@ void Button::setAction(void (*action2run)(Button*))
bool Button::isClicked(int x,int y)
{
- if ( x >= this->x && y >= this->y && x<= this->x+gfx->xsize && y <= this->y + gfx->ysize)
+ if ( x >= this->x && y >= this->y && x<= this->x+gfx->xsize && y <= this->y + gfx->ysize) {
return true;
- else
- return false;
+ }
+ return false;
}
void Button::doAction()
{
- if(action)
+ if (action) {
action(this);
- else
- cerr << "Warning: button \"" << label << "\" has no action assigned!";
+ return;
+ }
+ cerr << "Warning: button \"" << label << "\" has no action assigned!";
}
void Button::drawTo(SDL_Surface **surface)
@@ -116,13 +111,12 @@ void Button::drawTo(SDL_Surface **surface)
#if DEBUG
//cout << "Painting button: " << label << " at: " << x << "," << y << endl;
#endif
- if (marked)
+ if (marked) {
gfx->marked->PaintTo(*surface,x,y);
- else
+ }
+ else {
gfx->unmarked->PaintTo(*surface,x,y);
- //int stringx = x + (ButtonGfx::xsize)/2 - ButtonGfx::ttf->getTextWidth(label)/2;
- //int stringy = y + (ButtonGfx::ysize)/2 - ButtonGfx::ttf->getTextHeight()/2;
- //ButtonGfx::ttf->writeText(label,surface,stringx,stringy);
+ }
gfx->thefont.setDest(*surface);
gfx->thefont.drawCenter(x+gfx->xsize/2,y+gfx->ysize/2-gfx->thefont.getHeight(label.c_str())/2,label.c_str());
}
@@ -151,8 +145,9 @@ void Menu::drawSelf()
{
DrawIMG(backgroundImage,screen,0,0);
vector<Button*>::iterator it;
- for(it = buttons.begin(); it < buttons.end(); it++)
+ for (it = buttons.begin(); it < buttons.end(); it++) {
(*it)->drawTo(&screen);
+ }
exit.drawTo(&screen);
standardButton.thefont.draw(50,50,title.c_str());
mouse->PaintTo(screen,mousex,mousey);
@@ -164,13 +159,16 @@ void Menu::performClick(int x,int y)
for(it = buttons.begin(); it < buttons.end(); it++)
{
Button *b = (*it);
- if(b->isClicked(x,y))
+ if (b->isClicked(x,y)) {
b->doAction();
- if(b->isPopOnRun())
+ }
+ if (b->isPopOnRun()) {
running = false;
+ }
}
- if(exit.isClicked(x,y))
+ if (exit.isClicked(x,y)) {
running = false;
+ }
}
void Menu::placeButtons()