mirror of
https://github.com/Maschell/SDL2_Playground.git
synced 2025-02-18 22:16:25 +01:00
Adopt to new GuiText implementation, display second text
This commit is contained in:
parent
8b35729c1c
commit
90a4b422b2
@ -4,6 +4,7 @@
|
||||
#include <gui/GuiButton.h>
|
||||
#include <gui/GuiController.h>
|
||||
#include "menu/MainWindow.h"
|
||||
#include "resources/Resources.h"
|
||||
#include <gui/input/SDLController.h>
|
||||
#include <gui/input/SDLControllerMouse.h>
|
||||
#include <gui/input/ControllerManager.h>
|
||||
@ -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());
|
||||
|
@ -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){
|
||||
|
@ -16,6 +16,7 @@ public:
|
||||
void process() override;
|
||||
private:
|
||||
GuiText *label = nullptr;
|
||||
GuiText *label2 = nullptr;
|
||||
GuiTrigger *touchTrigger = nullptr;
|
||||
GuiTrigger *buttonTrigger = nullptr;
|
||||
GuiSound *sound = nullptr;
|
||||
|
Loading…
x
Reference in New Issue
Block a user