diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-17 19:16:25 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-17 19:16:25 +0100 |
commit | b421eec1073c1fb4b99d46cc36c5c9cbd8d3c4a7 (patch) | |
tree | 461e290e0c2c3adf588f02d24031edc7f8114390 /src/example/loadfont.cpp | |
parent | c4c896c2995f2b74fca322736aa944b28b14a1f6 (diff) | |
parent | a8ccf7fe8662086bb223aa4eafd0f85e717d16cf (diff) |
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/button-improvement
Diffstat (limited to 'src/example/loadfont.cpp')
-rw-r--r-- | src/example/loadfont.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/example/loadfont.cpp b/src/example/loadfont.cpp new file mode 100644 index 0000000..e459332 --- /dev/null +++ b/src/example/loadfont.cpp @@ -0,0 +1,49 @@ +#include <SDL2/SDL_ttf.h> +#include <crepe/api/Asset.h> +#include <crepe/api/Text.h> +#include <crepe/facade/Font.h> +#include <crepe/facade/FontFacade.h> +#include <crepe/facade/SDLContext.h> +#include <crepe/manager/Mediator.h> +#include <crepe/manager/ResourceManager.h> +#include <exception> +#include <iostream> +#include <memory> +#include <optional> +using namespace crepe; +int main() { + + // SDLFontContext font_facade; + Mediator mediator; + FontFacade font_facade{}; + SDLContext sdl_context{mediator}; + // ComponentManager component_manager{mediator}; + ResourceManager resource_manager{mediator}; + try { + // Correct way to create a unique pointer for Text + std::unique_ptr<Text> label = std::make_unique<Text>( + 1, vec2(100, 100), vec2(0, 0), "OpenSymbol", Text::Data{}, "test text"); + // std::cout << "Path: " << label->font.get_path() << std::endl; + Asset asset1 = font_facade.get_font_asset("OpenSymbol"); + std::cout << asset1.get_path() << std::endl; + std::unique_ptr<Text> label2 = std::make_unique<Text>( + 1, vec2(100, 100), vec2(0, 0), "fsaafdafsdafsdafsdasfdds", Text::Data{}); + Asset asset = Asset("test test"); + label->font.emplace(asset); + std::cout << label->font.value().get_path() << std::endl; + // label2->font = std::make_optional(asset); + // std::cout << "Path: " << label2->font.get_path() << std::endl; + ResourceManager & resource_mgr = mediator.resource_manager; + const Font & res = resource_manager.get<Font>(label->font.value()); + // TTF_Font * test_font = res.get_font(); + // if (test_font == NULL) { + // std::cout << "error with font" << std::endl; + // } else { + // std::cout << "correct font retrieved" << std::endl; + // } + } catch (const std::exception & e) { + std::cout << "Standard exception thrown: " << e.what() << std::endl; + } + + return 0; +} |