git repos / blockattack-game

commit e1b2e653

sago007 · 2017-11-28 18:10
e1b2e65372f9a242fc56c484229a078572057af3 patch · browse files
parent de766069d9d0a79f398a9edc4f9b66df9a525875

Changed two more fonts to use the wrapper

Changed files

M source/code/BlockGameSdl.inc before
M source/code/DialogBox.cpp before
M source/code/FontWrapper.hpp before
M source/code/ScoresDisplay.cpp before
M source/code/global.hpp before
M source/code/levelselect.cpp before
M source/code/main.cpp before
diff --git a/source/code/BlockGameSdl.inc b/source/code/BlockGameSdl.inc index bda9d6d..687609f 100644 --- a/source/code/BlockGameSdl.inc +++ b/source/code/BlockGameSdl.inc
@@ -303,7 +303,7 @@ public:
if (puzzleMode&&(!bGameOver)) {
//We need to write nr. of moves left!
strHolder = _("Moves left: ") + std::to_string(MovesLeft);
- globalData.nf_standard_blue_font.draw(globalData.screen, topx+5, topy+5, "%s", strHolder.c_str());
+ globalData.standard_blue_font.draw(globalData.screen, topx+5, topy+5, strHolder);
}
if (puzzleMode && stageButtonStatus == SBpuzzleMode) {
@@ -321,7 +321,7 @@ public:
}
else {
strHolder = "Last puzzle";
- globalData.nf_standard_blue_font.draw(globalData.screen, topx+5, topy+5, "%s",strHolder.c_str());
+ globalData.standard_blue_font.draw(globalData.screen, topx+5, topy+5, strHolder);
}
}
if (stageClear && stageButtonStatus == SBstageClear) {
@@ -339,7 +339,7 @@ public:
}
else {
strHolder = "Last stage";
- globalData.nf_standard_blue_font.draw(globalData.screen, topx+5, topy+5, "%s",strHolder.c_str());
+ globalData.standard_blue_font.draw(globalData.screen, topx+5, topy+5, strHolder);
}
}
if (!bGameOver && stop > 20) {
diff --git a/source/code/DialogBox.cpp b/source/code/DialogBox.cpp index 118f7b2..4cc997d 100644 --- a/source/code/DialogBox.cpp +++ b/source/code/DialogBox.cpp
@@ -27,7 +27,7 @@ http://www.blockattack.net
#include "ReadKeyboard.h"
static void NFont_Write(SDL_Renderer* target, int x, int y, const std::string& text) {
- globalData.nf_standard_blue_font.draw(target, x, y, "%s", text.c_str());
+ globalData.standard_blue_font.draw(target, x, y, text);
}
static void DrawRect(SDL_Renderer* target, int topx, int topy, int height, int width, const std::string& name) {
@@ -108,7 +108,7 @@ void DialogBox::Draw(SDL_Renderer* target) {
strHolder.erase((int)rk->CharsBeforeCursor());
if (((SDL_GetTicks()/600)%2)==1) {
- NFont_Write(target, x+40+globalData.nf_standard_blue_font.getWidth( "%s", strHolder.c_str()),y+76,"|");
+ NFont_Write(target, x+40+globalData.standard_blue_font.getWidth( strHolder),y+76,"|");
}
}
diff --git a/source/code/FontWrapper.hpp b/source/code/FontWrapper.hpp index 351ecf4..1eb6b55 100644 --- a/source/code/FontWrapper.hpp +++ b/source/code/FontWrapper.hpp
@@ -48,6 +48,14 @@ public:
theFont.draw(target, x, y, NFont::RIGHT, "%s", text.c_str());
}
+ NFont::Rectf drawBox(SDL_Renderer* dest, const NFont::Rectf& box, const std::string& formatted_text) {
+ return theFont.drawBox(dest, box, "%s", formatted_text.c_str());
+ }
+
+ size_t getWidth(const std::string& text) {
+ return theFont.getWidth("%s", text.c_str());
+ }
+
bool load(SDL_Renderer* target, TTF_Font* font, const NFont::Color& color) {
return theFont.load(target, font, color);
}
diff --git a/source/code/ScoresDisplay.cpp b/source/code/ScoresDisplay.cpp index 790e192..f279130 100644 --- a/source/code/ScoresDisplay.cpp +++ b/source/code/ScoresDisplay.cpp
@@ -31,8 +31,9 @@ using std::string;
using std::cerr;
using std::vector;
+
static void NFont_Write(SDL_Renderer* target, int x, int y, const char* text) {
- globalData.nf_standard_blue_font.draw(target, x, y, "%s", text);
+ globalData.standard_blue_font.draw(target, x, y, text);
}
const int numberOfPages = 3;
@@ -48,10 +49,10 @@ void ScoresDisplay::DrawBackgroundAndCalcPlacements() {
void ScoresDisplay::DrawHighscores(int x, int y, bool endless) {
DrawBackgroundAndCalcPlacements();
if (endless) {
- globalData.nf_standard_blue_font.draw(globalData.screen, x+100,y+100, "%s",_("Endless:") );
+ globalData.standard_blue_font.draw(globalData.screen, x+100,y+100, _("Endless:") );
}
else {
- globalData.nf_standard_blue_font.draw(globalData.screen, x+100,y+100, "%s",_("Time Trial:") );
+ globalData.standard_blue_font.draw(globalData.screen, x+100,y+100, _("Time Trial:") );
}
for (int i =0; i<10; i++) {
record r;
@@ -65,8 +66,8 @@ void ScoresDisplay::DrawHighscores(int x, int y, bool endless) {
char playerName[32];
snprintf(playerScore, sizeof(playerScore), "%i", r.score);
snprintf(playerName, sizeof(playerName), "%s", r.name.c_str());
- globalData.nf_standard_blue_font.draw(globalData.screen, x+420,y+150+i*35, "%s",playerScore);
- globalData.nf_standard_blue_font.draw(globalData.screen, x+60,y+150+i*35, "%s",playerName);
+ globalData.standard_blue_font.draw(globalData.screen, x+420,y+150+i*35, playerScore);
+ globalData.standard_blue_font.draw(globalData.screen, x+60,y+150+i*35, playerName);
}
}
@@ -165,7 +166,8 @@ void ScoresDisplay::Draw(SDL_Renderer*) {
//Draw page number
string pageXofY = SPrintStringF(_("Page %i of %i"), page+1, numberOfPages);
- NFont_Write(globalData.screen, globalData.xsize/2-globalData.nf_standard_blue_font.getWidth( "%s", pageXofY.c_str())/2, globalData.ysize-60, pageXofY.c_str());
+ //NFont_Write(globalData.screen, globalData.xsize/2-globalData.nf_standard_blue_font.getWidth( "%s", pageXofY.c_str())/2, globalData.ysize-60, pageXofY.c_str());
+ globalData.standard_blue_font.drawCenter(globalData.screen, globalData.xsize/2, globalData.ysize-60, pageXofY );
}
void ScoresDisplay::ProcessInput(const SDL_Event& event, bool& processed) {
diff --git a/source/code/global.hpp b/source/code/global.hpp index d0117a1..d9001c6 100644 --- a/source/code/global.hpp +++ b/source/code/global.hpp
@@ -55,7 +55,7 @@ struct GlobalData {
sago::SagoSprite iLevelCheckBoxMarked;
sago::SagoSprite iCheckBoxArea;
FontWrapper scoreboard_font;
- NFont nf_standard_blue_font;
+ FontWrapper standard_blue_font;
FontWrapper button_font;
bool MusicEnabled; //true if background music is enabled
bool SoundEnabled; //true if sound effects is enabled
diff --git a/source/code/levelselect.cpp b/source/code/levelselect.cpp index 85627a3..367181d 100644 --- a/source/code/levelselect.cpp +++ b/source/code/levelselect.cpp
@@ -39,7 +39,7 @@ using std::vector;
static bool bMouseUp; //true if the mouse(1) is unpressed
static void NFont_Write(SDL_Renderer* target, int x, int y, const std::string& text) {
- globalData.nf_standard_blue_font.draw(target, x, y, "%s", text.c_str());
+ globalData.standard_blue_font.draw(target, x, y, text);
}
//The function that allows the player to choose PuzzleLevel
diff --git a/source/code/main.cpp b/source/code/main.cpp index 670aa58..3cb346b 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -196,7 +196,7 @@ static int InitImages(sago::SagoSpriteHolder& holder) {
nf_standard_small_color.r = 200;
nf_standard_small_color.a = 255;
globalData.button_font.load(globalData.screen, holder.GetDataHolder().getFontPtr("freeserif", 24), nf_button_color);
- globalData.nf_standard_blue_font.load(globalData.screen, holder.GetDataHolder().getFontPtr("freeserif", 30), nf_standard_blue_color);
+ globalData.standard_blue_font.load(globalData.screen, holder.GetDataHolder().getFontPtr("freeserif", 30), nf_standard_blue_color);
nf_standard_small_font.load(globalData.screen, holder.GetDataHolder().getFontPtr("freeserif", 16), nf_standard_small_color);
globalData.scoreboard_font.load(globalData.screen, holder.GetDataHolder().getFontPtr("penguinattack", 20), nf_button_color);
@@ -240,11 +240,11 @@ void DrawIMG_Bounded(const sago::SagoSprite& sprite, SDL_Renderer* target, int x
static void NFont_Write(SDL_Renderer* target, int x, int y, const string& text) {
- globalData.nf_standard_blue_font.draw(target, x, y, "%s", text.c_str());
+ globalData.standard_blue_font.draw(target, x, y, text);
}
static void NFont_Write(SDL_Renderer* target, int x, int y, const char* text) {
- globalData.nf_standard_blue_font.draw(target, x, y, "%s", text);
+ globalData.standard_blue_font.draw(target, x, y, text);
}
SDL_Window* sdlWindow;
@@ -521,7 +521,7 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* th
if (infostring.length() > 0) {
NFont_Write(globalData.screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10, gametypeName);
NFont_Write(globalData.screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160, _("Objective:"));
- globalData.nf_standard_blue_font.drawBox(globalData.screen, { static_cast<float>(theGame2->GetTopX()+7),static_cast<float>(theGame2->GetTopY()+160+32), 280, 200}, "%s", infostring.c_str());
+ globalData.standard_blue_font.drawBox(globalData.screen, { static_cast<float>(theGame2->GetTopX()+7),static_cast<float>(theGame2->GetTopY()+160+32), 280, 200}, infostring);
}
//Write the keys that are in use