diff options
-rw-r--r-- | src/crepe/api/Script.h | 2 | ||||
-rw-r--r-- | src/crepe/facade/Font.cpp | 2 | ||||
-rw-r--r-- | src/crepe/facade/FontFacade.cpp | 2 | ||||
-rw-r--r-- | src/example/FontExample.cpp | 52 | ||||
-rw-r--r-- | src/example/loadfont.cpp | 18 |
5 files changed, 36 insertions, 40 deletions
diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index ee45b8d..a24e32e 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -191,7 +191,7 @@ private: //! Reference to parent component OptionalRef<bool> active; //! Mediator reference - + //! \} private: diff --git a/src/crepe/facade/Font.cpp b/src/crepe/facade/Font.cpp index 74dfe18..d419974 100644 --- a/src/crepe/facade/Font.cpp +++ b/src/crepe/facade/Font.cpp @@ -1,5 +1,5 @@ -#include "../api/Config.h" #include "../api/Asset.h" +#include "../api/Config.h" #include "Font.h" diff --git a/src/crepe/facade/FontFacade.cpp b/src/crepe/facade/FontFacade.cpp index 4a991c6..aa9d00c 100644 --- a/src/crepe/facade/FontFacade.cpp +++ b/src/crepe/facade/FontFacade.cpp @@ -15,7 +15,7 @@ Asset FontFacade::get_font_asset(const string font_family) { if (pattern == NULL) { throw runtime_error("Failed to create font pattern."); } - + // Default configuration FcConfig * config = FcConfigGetCurrent(); if (config == NULL) { diff --git a/src/example/FontExample.cpp b/src/example/FontExample.cpp index c2f21c4..3f5af48 100644 --- a/src/example/FontExample.cpp +++ b/src/example/FontExample.cpp @@ -1,49 +1,45 @@ -#include <crepe/api/Text.h> #include <SDL2/SDL_ttf.h> +#include <chrono> +#include <crepe/api/Camera.h> +#include <crepe/api/GameObject.h> +#include <crepe/api/LoopManager.h> +#include <crepe/api/Scene.h> +#include <crepe/api/Script.h> +#include <crepe/api/Text.h> #include <crepe/facade/Font.h> #include <crepe/facade/SDLContext.h> +#include <crepe/manager/EventManager.h> #include <crepe/manager/Mediator.h> #include <crepe/manager/ResourceManager.h> -#include <crepe/manager/EventManager.h> -#include <crepe/api/Scene.h> -#include <crepe/api/Script.h> -#include <crepe/api/LoopManager.h> -#include <crepe/api/GameObject.h> -#include <crepe/api/Camera.h> #include <exception> #include <iostream> #include <memory> -#include <chrono> using namespace crepe; using namespace std; using namespace std::chrono; -class TestScript : public Script{ - public: +class TestScript : public Script { +public: steady_clock::time_point start_time; - virtual void init() override{ - start_time = steady_clock::now(); - } - virtual void update() override{ + virtual void init() override { start_time = steady_clock::now(); } + virtual void update() override { auto now = steady_clock::now(); - auto elapsed = duration_cast<seconds>(now - start_time).count(); + auto elapsed = duration_cast<seconds>(now - start_time).count(); - if (elapsed >= 5) { - Mediator& med = mediator; - EventManager& event_mgr = med.event_manager; + if (elapsed >= 5) { + Mediator & med = mediator; + EventManager & event_mgr = med.event_manager; event_mgr.trigger_event<ShutDownEvent>(); - } + } } }; -class TestScene : public Scene{ - public: - void load_scene() override{ - GameObject text_object = this->new_object("test","test",vec2{0,0},0,1); - text_object.add_component<Text>(vec2(100, 100), vec2(0, 0), "test test", - "Noto Sans", Text::Data{}); +class TestScene : public Scene { +public: + void load_scene() override { + GameObject text_object = this->new_object("test", "test", vec2{0, 0}, 0, 1); + text_object.add_component<Text>(vec2(100, 100), vec2(0, 0), "test test", "Noto Sans", + Text::Data{}); text_object.add_component<BehaviorScript>().set_script<TestScript>(); - text_object.add_component<Camera>(ivec2{300,300},vec2{100,100},Camera::Data{ - }); - + text_object.add_component<Camera>(ivec2{300, 300}, vec2{100, 100}, Camera::Data{}); } std::string get_name() const override { return "hey"; } }; diff --git a/src/example/loadfont.cpp b/src/example/loadfont.cpp index f863053..ce287b4 100644 --- a/src/example/loadfont.cpp +++ b/src/example/loadfont.cpp @@ -1,5 +1,5 @@ -#include <crepe/api/Text.h> #include <SDL2/SDL_ttf.h> +#include <crepe/api/Text.h> #include <crepe/facade/Font.h> #include <crepe/facade/SDLContext.h> #include <crepe/manager/Mediator.h> @@ -25,14 +25,14 @@ int main() { = std::make_unique<Text>(1, vec2(100, 100), vec2(0, 0), "test test", "fsaafdafsdafsdafsdasfdds", Text::Data{}); std::cout << "Path: " << label2->font.get_path() << std::endl; - ResourceManager & resource_mgr = mediator.resource_manager; - const Font & res = resource_manager.get<Font>(label->font); - 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; - } + ResourceManager & resource_mgr = mediator.resource_manager; + const Font & res = resource_manager.get<Font>(label->font); + 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; } |