commit e55d039f
Fixed problems with format strings to NFont.
Changed files
| M | source/code/Libs/NFont.h before |
| M | source/code/MenuSystem.cpp before |
| M | source/code/ReadKeyboard.cpp before |
| M | source/code/main.cpp before |
diff --git a/source/code/Libs/NFont.h b/source/code/Libs/NFont.h
index c8f5d4e..0d6d581 100644
--- a/source/code/Libs/NFont.h
+++ b/source/code/Libs/NFont.h
@@ -191,24 +191,24 @@ public:
void freeSurface();
// Drawing
- SDL_Rect draw(int x, int y, const char* formatted_text, ...) const;
- SDL_Rect drawCenter(int x, int y, const char* formatted_text, ...) const;
- SDL_Rect drawRight(int x, int y, const char* formatted_text, ...) const;
- SDL_Rect drawPos(int x, int y, NFont::AnimFn posFn, const char* text, ...) const;
- SDL_Rect drawAll(int x, int y, NFont::AnimFn allFn, const char* text, ...) const;
+ SDL_Rect draw(int x, int y, const char* formatted_text, ...) const __attribute__ ((format (printf, 4, 5)));
+ SDL_Rect drawCenter(int x, int y, const char* formatted_text, ...) const __attribute__ ((format (printf, 4, 5)));
+ SDL_Rect drawRight(int x, int y, const char* formatted_text, ...) const __attribute__ ((format (printf, 4, 5)));
+ SDL_Rect drawPos(int x, int y, NFont::AnimFn posFn, const char* text, ...) const __attribute__ ((format (printf, 5, 6)));
+ SDL_Rect drawAll(int x, int y, NFont::AnimFn allFn, const char* text, ...) const __attribute__ ((format (printf, 5, 6)));
// Getters
SDL_Surface* getDest() const;
SDL_Surface* getSurface() const;
- int getHeight(const char* formatted_text = NULL, ...) const;
- int getWidth(const char* formatted_text, ...) const;
+ int getHeight(const char* formatted_text = NULL, ...) const __attribute__ ((format (printf, 2, 3)));
+ int getWidth(const char* formatted_text, ...) const __attribute__ ((format (printf, 2, 3)));
int getSpacing() const;
int getLineSpacing() const;
int getBaseline() const;
int getAscent(const char character) const;
- int getAscent(const char* formatted_text = NULL, ...) const;
+ int getAscent(const char* formatted_text = NULL, ...) const __attribute__ ((format (printf, 2, 3)));
int getDescent(const char character) const;
- int getDescent(const char* formatted_text = NULL, ...) const;
+ int getDescent(const char* formatted_text = NULL, ...) const __attribute__ ((format (printf, 2, 3)));
int getMaxWidth() const;
// Setters
diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp
index e9ce9b5..0a61132 100644
--- a/source/code/MenuSystem.cpp
+++ b/source/code/MenuSystem.cpp
@@ -106,7 +106,7 @@ void Button::drawTo(SDL_Surface** surface) {
gfx->unmarked->PaintTo(*surface,x,y);
}
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());
+ gfx->thefont.drawCenter(x+gfx->xsize/2,y+gfx->ysize/2-gfx->thefont.getHeight("%s", label.c_str())/2, "%s", label.c_str());
}
void Button::setPopOnRun(bool popOnRun) {
@@ -132,7 +132,7 @@ void Menu::drawSelf() {
(*it)->drawTo(&screen);
}
exit.drawTo(&screen);
- standardButton.thefont.draw(50,50,title.c_str());
+ standardButton.thefont.draw(50, 50, "%s", title.c_str());
mouse->PaintTo(screen,mousex,mousey);
}
diff --git a/source/code/ReadKeyboard.cpp b/source/code/ReadKeyboard.cpp
index 71b1837..a7860de 100644
--- a/source/code/ReadKeyboard.cpp
+++ b/source/code/ReadKeyboard.cpp
@@ -121,8 +121,6 @@ bool ReadKeyboard::ReadKey(SDLKey keyPressed) {
}
return false;
}
- Uint8* keys;
- keys = SDL_GetKeyState(nullptr);
if (keyPressed == SDLK_HOME) {
position=0;
return true;
diff --git a/source/code/main.cpp b/source/code/main.cpp
index 9322628..a9f5074 100644
--- a/source/code/main.cpp
+++ b/source/code/main.cpp
@@ -696,7 +696,7 @@ void DrawIMG(SDL_Surface* img, SDL_Surface* target, int x, int y, int w, int h,
void NFont_Write(SDL_Surface* target, int x, int y, const string& text) {
nf_standard_blue_font.setDest(target);
- nf_standard_blue_font.draw(x, y, text.c_str());
+ nf_standard_blue_font.draw(x, y, "%s", text.c_str());
nf_standard_blue_font.setDest(screen);
}
@@ -1252,7 +1252,7 @@ public:
if (puzzleMode&&(!bGameOver)) {
//We need to write nr. of moves left!
strHolder = "Moves left: " + itoa(MovesLeft);
- nf_standard_blue_font.draw(5,5,strHolder.c_str());
+ nf_standard_blue_font.draw(5,5, "%s",strHolder.c_str());
}
if (puzzleMode && stageButtonStatus == SBpuzzleMode) {
@@ -1267,7 +1267,7 @@ public:
}
else {
strHolder = "Last puzzle";
- nf_standard_blue_font.draw(5,5,strHolder.c_str());
+ nf_standard_blue_font.draw(5,5, "%s",strHolder.c_str());
}
}
if (stageClear && stageButtonStatus == SBstageClear) {
@@ -1282,7 +1282,7 @@ public:
}
else {
strHolder = "Last stage";
- nf_standard_blue_font.draw(5,5,strHolder.c_str());
+ nf_standard_blue_font.draw(5,5, "%s",strHolder.c_str());
}
}
@@ -1290,7 +1290,7 @@ public:
if (AI_Enabled&&(!bGameOver)) {
strHolder = "AI_status: " + itoa(AIstatus)+ ", "+ itoa(AIlineToClear);
//NFont_Write(sBoard, 5, 5, strHolder.c_str());
- nf_standard_blue_font.draw(5,5,strHolder.c_str());
+ nf_standard_blue_font.draw(5,5, "%s",strHolder.c_str());
}
#endif
if (!bGameOver) {
@@ -1419,7 +1419,7 @@ bool OpenDialogbox(int x, int y, char* name) {
strHolder.erase((int)rk.CharsBeforeCursor());
if (((SDL_GetTicks()/600)%2)==1) {
- NFont_Write(screen, x+40+nf_standard_blue_font.getWidth( strHolder.c_str()),y+76,"|");
+ NFont_Write(screen, x+40+nf_standard_blue_font.getWidth( "%s", strHolder.c_str()),y+76,"|");
}
SDL_Event event;
@@ -1468,10 +1468,10 @@ void DrawHighscores(int x, int y, bool endless) {
MakeBackground(xsize,ysize);
DrawIMG(background,screen,0,0);
if (endless) {
- nf_standard_blue_font.draw(x+100,y+100,_("Endless:") );
+ nf_standard_blue_font.draw(x+100,y+100, "%s",_("Endless:") );
}
else {
- nf_standard_blue_font.draw(x+100,y+100,_("Time Trial:") );
+ nf_standard_blue_font.draw(x+100,y+100, "%s",_("Time Trial:") );
}
for (int i =0; i<10; i++) {
char playerScore[32];
@@ -1488,8 +1488,8 @@ void DrawHighscores(int x, int y, bool endless) {
else {
strcpy(playerName,theTopScoresTimeTrial.getScoreName(i));
}
- nf_standard_blue_font.draw(x+420,y+150+i*35,playerScore);
- nf_standard_blue_font.draw(x+60,y+150+i*35,playerName);
+ nf_standard_blue_font.draw(x+420,y+150+i*35, "%s",playerScore);
+ nf_standard_blue_font.draw(x+60,y+150+i*35, "%s",playerName);
}
}
@@ -1589,7 +1589,7 @@ void OpenScoresDisplay() {
//Draw page number
string pageXofY = (boost::format(_("Page %1% of %2%") )%(page+1)%numberOfPages).str();
- NFont_Write(screen, xsize/2-nf_standard_blue_font.getWidth( pageXofY.c_str())/2,ysize-60,pageXofY.c_str());
+ NFont_Write(screen, xsize/2-nf_standard_blue_font.getWidth( "%s", pageXofY.c_str())/2,ysize-60,pageXofY.c_str());
SDL_Delay(10);
SDL_Event event;
@@ -1776,7 +1776,7 @@ static void DrawBalls() {
int x = theTextManeger.textArray[i].getX()-12;
int y = theTextManeger.textArray[i].getY()-12;
DrawIMG(iChainBack,screen,x,y);
- nf_standard_small_font.drawCenter(x+12,y+7,theTextManeger.textArray[i].getText());
+ nf_standard_small_font.drawCenter(x+12,y+7, "%s",theTextManeger.textArray[i].getText());
}
} //for
} //DrawBalls