diff --git a/source/code/BlockGameSdl.inc b/source/code/BlockGameSdl.inc index 8fe0145..7460302 100644 --- a/source/code/BlockGameSdl.inc +++ b/source/code/BlockGameSdl.inc @@ -42,11 +42,11 @@ public: } void PrintTextCenteredBoard(int x, int y, const char* text) { - globalData.nf_button_font.draw(globalData.screen, x+topx+60, y+topy+10, NFont::CENTER, "%s", text); + globalData.button_font.drawCenter2(globalData.screen, x+topx+60, y+topy+10, text); } void PrintIntRightAlignedBoard(int x, int y, int number) { - globalData.nf_button_font.draw(globalData.screen, x+topx+60, y+topy+10, NFont::RIGHT, "%d", number); + globalData.button_font.drawRight(globalData.screen, x+topx+60, y+topy+10, std::to_string(number)); } void SetTopXY(int tx, int ty) { diff --git a/source/code/DialogBox.cpp b/source/code/DialogBox.cpp index 3390c54..ad6376c 100644 --- a/source/code/DialogBox.cpp +++ b/source/code/DialogBox.cpp @@ -99,9 +99,9 @@ void DialogBox::Draw(SDL_Renderer* target) { this->x = globalData.xsize/2-300; this->y = globalData.ysize/2-100; DrawRectYellow(target, x, y, 200, 600); - globalData.nf_button_font.draw(target, x+300, y+20, NFont::CENTER, "%s", header.c_str()); - globalData.nf_button_font.draw(target, x+150, y+140, NFont::CENTER, _("Enter to accept")); - globalData.nf_button_font.draw(target, x+450, y+140, NFont::CENTER, _("Esc to cancel")); + globalData.button_font.drawCenter2(target, x+300, y+20, header); + globalData.button_font.drawCenter2(target, x+150, y+140, _("Enter to accept")); + globalData.button_font.drawCenter2(target, x+450, y+140, _("Esc to cancel")); DrawRectWhite(target, x+26, y+64, 54, 600-2*26); NFont_Write(target, x+40, y+76,rk->GetString()); std::string strHolder = rk->GetString(); diff --git a/source/code/FontWrapper.hpp b/source/code/FontWrapper.hpp new file mode 100644 index 0000000..4a4a5c6 --- /dev/null +++ b/source/code/FontWrapper.hpp @@ -0,0 +1,57 @@ +/* +=========================================================================== +blockattack - Block Attack - Rise of the Blocks +Copyright (C) 2005-2017 Poul Sander + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see http://www.gnu.org/licenses/ + +Source information and contacts persons can be found at +http://www.blockattack.net +=========================================================================== +*/ + + +#ifndef FONTWRAPPER_HPP +#define FONTWRAPPER_HPP + +#include "Libs/NFont.h" +#include "sago/SagoDataHolder.hpp" + +class FontWrapper { + NFont theFont; + +public: + void draw(SDL_Renderer* target, int x, int y, const std::string& text) { + theFont.draw(target, x, y, "%s", text.c_str()); + } + + void drawCenter2(SDL_Renderer* target, int x, int y, const std::string& text) { + theFont.draw(target, x, y, NFont::CENTER, "%s", text.c_str()); + } + + void drawCenterAlsoHeight(SDL_Renderer* target, int x, int y, const std::string& text) { + theFont.draw(target, x, y-theFont.getHeight()/2, NFont::CENTER, "%s", text.c_str()); + } + + void drawRight(SDL_Renderer* target, int x, int y, const std::string& text) { + theFont.draw(target, x, y, NFont::RIGHT, "%s", text.c_str()); + } + + bool load(SDL_Renderer* target, TTF_Font* font, const NFont::Color& color) { + return theFont.load(target, font, color); + } +}; + +#endif /* FONTWRAPPER_HPP */ + diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp index ffe826f..494c2e4 100644 --- a/source/code/MenuSystem.cpp +++ b/source/code/MenuSystem.cpp @@ -98,7 +98,7 @@ static void drawToScreen(const Button& b) { globalData.spriteHolder->GetSprite(menu_unmarked).Draw(globalData.screen, SDL_GetTicks(), b.x, b.y); } - standardButton.thefont->draw(globalData.screen, b.x+standardButton.xsize/2,b.y+standardButton.ysize/2-standardButton.thefont->getHeight("%s", b.label.c_str())/2, NFont::CENTER, "%s", b.label.c_str()); + standardButton.thefont->drawCenterAlsoHeight(globalData.screen, b.x+standardButton.xsize/2,b.y+standardButton.ysize/2, b.label); } @@ -115,7 +115,7 @@ void Menu::drawSelf(SDL_Renderer* target) { drawToScreen(*b); } drawToScreen(exit); - standardButton.thefont->draw(target, 50, 50, "%s", title.c_str()); + standardButton.thefont->draw(target, 50, 50, title.c_str()); } diff --git a/source/code/MenuSystem.h b/source/code/MenuSystem.h index 8e35941..e95cd02 100644 --- a/source/code/MenuSystem.h +++ b/source/code/MenuSystem.h @@ -32,6 +32,7 @@ http://blockattack.net #include "sago/SagoSprite.hpp" #include "sago/GameStateInterface.hpp" #include +#include "FontWrapper.hpp" //The ButtonGfx object hold common media for all buttons, so we can reskin them by only changeing one pointer struct ButtonGfx @@ -40,7 +41,7 @@ struct ButtonGfx int xsize = 0; int ysize = 0; //A TTFont used for writing the label on the buttons - NFont* thefont = nullptr; + FontWrapper* thefont; void setSurfaces(); }; diff --git a/source/code/ScoresDisplay.cpp b/source/code/ScoresDisplay.cpp index a952dae..d3c286e 100644 --- a/source/code/ScoresDisplay.cpp +++ b/source/code/ScoresDisplay.cpp @@ -159,9 +159,11 @@ void ScoresDisplay::Draw(SDL_Renderer*) { //Draw buttons: globalData.bHighScore.Draw(globalData.screen, 0, scoreX,scoreY); globalData.bBack.Draw(globalData.screen, 0, backX, backY); - globalData.nf_button_font.draw(globalData.screen, backX+60,backY+10, NFont::CENTER,_("Back")); + //globalData.nf_button_font.draw(globalData.screen, backX+60,backY+10, NFont::CENTER,_("Back")); + globalData.button_font.drawCenter2(globalData.screen, backX+60,backY+10,_("Back")); globalData.bNext.Draw(globalData.screen, 0, nextX, nextY); - globalData.nf_button_font.draw(globalData.screen, nextX+60,nextY+10, NFont::CENTER,_("Next")); + //globalData.nf_button_font.draw(globalData.screen, nextX+60,nextY+10, NFont::CENTER,_("Next")); + globalData.button_font.drawCenter2(globalData.screen, nextX+60,nextY+10,_("Next")); //Draw page number string pageXofY = SPrintStringF(_("Page %i of %i"), page+1, numberOfPages); diff --git a/source/code/global.hpp b/source/code/global.hpp index c24454e..c8af0b0 100644 --- a/source/code/global.hpp +++ b/source/code/global.hpp @@ -29,6 +29,7 @@ http://www.blockattack.net #include "sago/SagoSpriteHolder.hpp" #include "highscore.h" #include "sago/GameStateInterface.hpp" +#include "FontWrapper.hpp" #include "TextManager.hpp" #include "ExplosionManager.hpp" @@ -55,7 +56,7 @@ struct GlobalData { sago::SagoSprite iCheckBoxArea; NFont nf_scoreboard_font; NFont nf_standard_blue_font; - NFont nf_button_font; + FontWrapper button_font; bool MusicEnabled; //true if background music is enabled bool SoundEnabled; //true if sound effects is enabled bool bFullscreen; //true if game is running fullscreen diff --git a/source/code/main.cpp b/source/code/main.cpp index ab332e5..7f7e7e1 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -195,7 +195,7 @@ static int InitImages(sago::SagoSpriteHolder& holder) { nf_standard_small_color.g = 0; nf_standard_small_color.r = 200; nf_standard_small_color.a = 255; - globalData.nf_button_font.load(globalData.screen, holder.GetDataHolder().getFontPtr("freeserif", 24), nf_button_color); + 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); nf_standard_small_font.load(globalData.screen, holder.GetDataHolder().getFontPtr("freeserif", 16), nf_standard_small_color); globalData.nf_scoreboard_font.load(globalData.screen, holder.GetDataHolder().getFontPtr("penguinattack", 20), nf_button_color); diff --git a/source/code/menudef.cpp b/source/code/menudef.cpp index 30288f9..0092344 100644 --- a/source/code/menudef.cpp +++ b/source/code/menudef.cpp @@ -96,7 +96,7 @@ void Button_changekey::doAction() { void InitMenues() { standardButton.setSurfaces(); - standardButton.thefont = &globalData.nf_button_font; + standardButton.thefont = &globalData.button_font; } static void runSinglePlayerEndless() {