From 90a4b422b224679e8809c239c8e43c920efae6c9 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 3 Oct 2020 15:48:19 +0200 Subject: [PATCH] Adopt to new GuiText implementation, display second text --- src/main.cpp | 5 +++++ src/menu/MainWindow.cpp | 30 +++++++----------------------- src/menu/MainWindow.h | 1 + 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d239ae4..6382730 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,7 @@ #include #include #include "menu/MainWindow.h" +#include "resources/Resources.h" #include #include #include @@ -70,6 +71,10 @@ int main(int argc, char *args[]) { WHBLogUdpInit(); #endif + GuiFont font(Resources::GetFile("FreeSans.ttf"),Resources::GetFileSize("FreeSans.ttf"), system->getRenderer()); + + GuiText::setPresetFont(&font); + auto * frame = new MainWindow(system->getWidth(), system->getHeight(), system->getRenderer()); auto * controllerM = new ControllerManager(system->getWidth(), system->getHeight()); diff --git a/src/menu/MainWindow.cpp b/src/menu/MainWindow.cpp index 82d716c..69f7c9d 100644 --- a/src/menu/MainWindow.cpp +++ b/src/menu/MainWindow.cpp @@ -3,6 +3,7 @@ MainWindow::~MainWindow() { delete label; + delete label2; delete touchTrigger; delete buttonTrigger; delete sound; @@ -19,34 +20,17 @@ MainWindow::~MainWindow() { MainWindow::MainWindow(int32_t w, int32_t h, Renderer* renderer) : GuiFrame(w, h), bgImage({100, 0, 0, 255}, w, h) { auto picture_path = "button.png"; - auto font_path = "FreeSans.ttf"; auto bgMusic_path = "bgMusic.ogg"; auto music_click = "button_click.mp3"; append(&bgImage); + + label = new GuiText("This is a test.", 28, {255, 255, 0, 255}); - TTF_Font *font; - - SDL_RWops *rw = SDL_RWFromMem((void *) Resources::GetFile(font_path), Resources::GetFileSize(font_path)); - - DEBUG_FUNCTION_LINE("load font %08X %d", Resources::GetFile(font_path), Resources::GetFileSize(font_path)); - - font = TTF_OpenFontRW(rw, 0, 28); - if(!font){ - DEBUG_FUNCTION_LINE("Failed to load the font"); - return; - } - - FC_Font* fc_font = FC_CreateFont(); - if(!fc_font){ - DEBUG_FUNCTION_LINE("Failed to create font"); - } - - auto res = FC_LoadFontFromTTF(fc_font, renderer->getRenderer(), font, {255, 255, 255, 255}); - DEBUG_FUNCTION_LINE("FontCache init %d", res); - - label = new GuiText("This is a test.", {255, 255, 0, 255}, fc_font); - + label2 = new GuiText("This is a bigger text.", 48); + label2->setAlignment(ALIGN_CENTERED); + label2->setPosition(0,-100); + append(label2); bgMusic = Resources::GetSound(bgMusic_path); if(!bgMusic){ diff --git a/src/menu/MainWindow.h b/src/menu/MainWindow.h index c645be7..0dad757 100644 --- a/src/menu/MainWindow.h +++ b/src/menu/MainWindow.h @@ -16,6 +16,7 @@ public: void process() override; private: GuiText *label = nullptr; + GuiText *label2 = nullptr; GuiTrigger *touchTrigger = nullptr; GuiTrigger *buttonTrigger = nullptr; GuiSound *sound = nullptr;