aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-17 13:34:19 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-17 13:34:19 +0100
commit69ca7fdd738fd4ed98aefc07bab5a43486a55619 (patch)
treed4c13778166d0ae0a038ca067a64b570df73ffb2 /src
parent34a773eb0f01379419900a3fe26527702146b890 (diff)
final changes
Diffstat (limited to 'src')
-rw-r--r--src/crepe/api/LoopManager.h3
-rw-r--r--src/crepe/api/Script.h1
-rw-r--r--src/crepe/api/Text.cpp8
-rw-r--r--src/crepe/api/Text.h11
-rw-r--r--src/crepe/facade/Font.cpp3
-rw-r--r--src/crepe/facade/FontFacade.cpp10
-rw-r--r--src/crepe/facade/FontFacade.h10
-rw-r--r--src/crepe/facade/SDLContext.cpp2
-rw-r--r--src/crepe/facade/SDLContext.h6
-rw-r--r--src/crepe/system/RenderSystem.cpp35
-rw-r--r--src/example/FontExample.cpp5
-rw-r--r--src/example/loadfont.cpp10
12 files changed, 47 insertions, 57 deletions
diff --git a/src/crepe/api/LoopManager.h b/src/crepe/api/LoopManager.h
index 1725810..1d23cbf 100644
--- a/src/crepe/api/LoopManager.h
+++ b/src/crepe/api/LoopManager.h
@@ -71,7 +71,7 @@ private:
private:
//! Global context
Mediator mediator;
-
+
//! SDLContext instance
SDLContext sdl_context{mediator};
//! Component manager instance
@@ -86,7 +86,6 @@ private:
ResourceManager resource_manager{mediator};
//! Save manager instance
SaveManager save_manager{mediator};
-
private:
/**
diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h
index 4503525..8bca38a 100644
--- a/src/crepe/api/Script.h
+++ b/src/crepe/api/Script.h
@@ -156,7 +156,6 @@ private:
void subscribe_internal(const EventHandler<EventType> & callback, event_channel_t channel);
protected:
-
// NOTE: This must be the only constructor on Script, see "Late references" below
Script() = default;
//! Only \c BehaviorScript instantiates Script
diff --git a/src/crepe/api/Text.cpp b/src/crepe/api/Text.cpp
index 0624c98..58dc6c6 100644
--- a/src/crepe/api/Text.cpp
+++ b/src/crepe/api/Text.cpp
@@ -4,11 +4,11 @@
using namespace crepe;
-Text::Text(game_object_id_t id, const vec2 & dimensions,const vec2 & offset, const std::string & font_family,
- const Data & data, const std::string & text, std::optional<Asset> font)
+Text::Text(game_object_id_t id, const vec2 & dimensions, const vec2 & offset,
+ const std::string & font_family, const Data & data, const std::string & text,
+ std::optional<Asset> font)
: UIObject(id, dimensions, offset),
text(text),
data(data),
font_family(font_family),
- font(font) {
-}
+ font(font) {}
diff --git a/src/crepe/api/Text.h b/src/crepe/api/Text.h
index ab72bc0..92cca18 100644
--- a/src/crepe/api/Text.h
+++ b/src/crepe/api/Text.h
@@ -1,7 +1,7 @@
#pragma once
+#include <optional>
#include <string>
-#include <optional>
#include "../Component.h"
@@ -50,10 +50,10 @@ public:
* \param data Data struct containing extra text parameters.
* \param font Optional font asset that can be passed or left empty.
*/
- Text(game_object_id_t id, const vec2 & dimensions, const vec2 & offset,
- const std::string & font_family, const Data & data,
- const std::string & text = "", std::optional<Asset> font = std::nullopt);
-
+ Text(game_object_id_t id, const vec2 & dimensions, const vec2 & offset,
+ const std::string & font_family, const Data & data, const std::string & text = "",
+ std::optional<Asset> font = std::nullopt);
+
//! Label text.
std::string text = "";
//! font family name
@@ -62,7 +62,6 @@ public:
std::optional<Asset> font;
//! Data instance
Data data;
-
};
} // namespace crepe
diff --git a/src/crepe/facade/Font.cpp b/src/crepe/facade/Font.cpp
index 558641f..f202c05 100644
--- a/src/crepe/facade/Font.cpp
+++ b/src/crepe/facade/Font.cpp
@@ -8,8 +8,7 @@
using namespace std;
using namespace crepe;
-Font::Font(const Asset & src, Mediator & mediator)
- : Resource(src, mediator){
+Font::Font(const Asset & src, Mediator & mediator) : Resource(src, mediator) {
Config & config = Config::get_instance();
const std::string FONT_PATH = src.get_path();
TTF_Font * loaded_font = TTF_OpenFont(FONT_PATH.c_str(), config.font.size);
diff --git a/src/crepe/facade/FontFacade.cpp b/src/crepe/facade/FontFacade.cpp
index 08ff31c..7edfeb8 100644
--- a/src/crepe/facade/FontFacade.cpp
+++ b/src/crepe/facade/FontFacade.cpp
@@ -6,16 +6,14 @@
using namespace crepe;
using namespace std;
-FontFacade::FontFacade(){
+FontFacade::FontFacade() {
if (!FcInit()) {
throw runtime_error("Failed to initialize Fontconfig.");
}
}
-FontFacade::~FontFacade(){
- FcFini();
-}
-Asset FontFacade::get_font_asset(const string& font_family) {
-
+FontFacade::~FontFacade() { FcFini(); }
+Asset FontFacade::get_font_asset(const string & font_family) {
+
// Create a pattern to search for the font family
FcPattern * pattern = FcNameParse(reinterpret_cast<const FcChar8 *>(font_family.c_str()));
if (pattern == NULL) {
diff --git a/src/crepe/facade/FontFacade.h b/src/crepe/facade/FontFacade.h
index 2e08f3f..9761070 100644
--- a/src/crepe/facade/FontFacade.h
+++ b/src/crepe/facade/FontFacade.h
@@ -15,10 +15,10 @@ class FontFacade {
public:
FontFacade();
~FontFacade();
- FontFacade(const FontFacade & other) = delete;
- FontFacade & operator=(const FontFacade & other) = delete;
- FontFacade(FontFacade && other) noexcept = delete;
- FontFacade & operator=(FontFacade && other) noexcept = delete;
+ FontFacade(const FontFacade & other) = delete;
+ FontFacade & operator=(const FontFacade & other) = delete;
+ FontFacade(FontFacade && other) noexcept = delete;
+ FontFacade & operator=(FontFacade && other) noexcept = delete;
/**
*
* \brief Facade function to convert a font_family into an asset.
@@ -28,7 +28,7 @@ public:
* \param font_family Name of the font family name.
* \return Asset with filepath to the corresponding font.
*/
- Asset get_font_asset(const std::string& font_family);
+ Asset get_font_asset(const std::string & font_family);
};
} // namespace crepe
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 8ffaad9..c88687e 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -440,6 +440,6 @@ void SDLContext::set_color_texture(const Texture & texture, const Color & color)
SDL_SetTextureAlphaMod(texture.get_img(), color.a);
}
-Asset SDLContext::get_font_from_name(const std::string& font_family){
+Asset SDLContext::get_font_from_name(const std::string & font_family) {
return this->font_facade.get_font_asset(font_family);
}
diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h
index e348ff6..6f6eddb 100644
--- a/src/crepe/facade/SDLContext.h
+++ b/src/crepe/facade/SDLContext.h
@@ -241,9 +241,11 @@ private:
* - this is defined in this class because get_events() needs this information aswell
*/
CameraAuxiliaryData cam_aux_data;
-private:
+
+private:
//! instance of the font_facade
FontFacade font_facade{};
+
public:
/**
* \brief Function to Get asset from font_family
@@ -254,7 +256,7 @@ public:
*
* \return asset with the font style absolute path
*/
- Asset get_font_from_name(const std::string& font_family);
+ Asset get_font_from_name(const std::string & font_family);
};
} // namespace crepe
diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp
index 5fc98a9..a03c636 100644
--- a/src/crepe/system/RenderSystem.cpp
+++ b/src/crepe/system/RenderSystem.cpp
@@ -10,8 +10,8 @@
#include "../api/ParticleEmitter.h"
#include "../api/Sprite.h"
#include "../api/Text.h"
-#include "../facade/Font.h"
#include "../api/Transform.h"
+#include "../facade/Font.h"
#include "../facade/SDLContext.h"
#include "../facade/Texture.h"
#include "../manager/ComponentManager.h"
@@ -23,7 +23,6 @@
using namespace crepe;
using namespace std;
-
void RenderSystem::clear_screen() {
SDLContext & ctx = this->mediator.sdl_context;
ctx.clear_screen();
@@ -126,12 +125,11 @@ void RenderSystem::render() {
RefVector<Sprite> sprites = mgr.get_components_by_type<Sprite>();
ResourceManager & resource_manager = this->mediator.resource_manager;
RefVector<Sprite> sorted_sprites = this->sort(sprites);
- RefVector<Text> text_components = mgr.get_components_by_type<Text>();
- for(Text& text : text_components){
+ RefVector<Text> text_components = mgr.get_components_by_type<Text>();
+ for (Text & text : text_components) {
const Transform & transform
= mgr.get_components_by_id<Transform>(text.game_object_id).front().get();
- this->render_text(text,transform);
-
+ this->render_text(text, transform);
}
for (const Sprite & sprite : sorted_sprites) {
if (!sprite.active) continue;
@@ -143,25 +141,20 @@ void RenderSystem::render() {
if (rendered_particles) continue;
this->render_normal(sprite, transform);
-
-
-
}
-
}
void RenderSystem::render_text(Text & text, const Transform & tm) {
- SDLContext & ctx = this->mediator.sdl_context;
+ SDLContext & ctx = this->mediator.sdl_context;
- if (!text.font.has_value()) {
- text.font = ctx.get_font_from_name(text.font_family);
- }
+ if (!text.font.has_value()) {
+ text.font = ctx.get_font_from_name(text.font_family);
+ }
- ResourceManager & resource_manager = this->mediator.resource_manager;
+ ResourceManager & resource_manager = this->mediator.resource_manager;
- if (!text.font.has_value()) {return;}
- const Asset& font_asset = text.font.value();
- const Font & res = resource_manager.get<Font>(font_asset);
+ if (!text.font.has_value()) {
+ return;
+ }
+ const Asset & font_asset = text.font.value();
+ const Font & res = resource_manager.get<Font>(font_asset);
}
-
-
-
diff --git a/src/example/FontExample.cpp b/src/example/FontExample.cpp
index 7b2dadb..6a334b1 100644
--- a/src/example/FontExample.cpp
+++ b/src/example/FontExample.cpp
@@ -1,6 +1,7 @@
#include <SDL2/SDL_ttf.h>
#include <chrono>
#include <crepe/api/Camera.h>
+#include <crepe/api/Config.h>
#include <crepe/api/GameObject.h>
#include <crepe/api/LoopManager.h>
#include <crepe/api/Scene.h>
@@ -11,7 +12,6 @@
#include <crepe/manager/EventManager.h>
#include <crepe/manager/Mediator.h>
#include <crepe/manager/ResourceManager.h>
-#include <crepe/api/Config.h>
#include <exception>
#include <iostream>
#include <memory>
@@ -37,7 +37,8 @@ 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), "OpenSymbol", Text::Data{});
+ text_object.add_component<Text>(vec2(100, 100), vec2(0, 0), "OpenSymbol",
+ Text::Data{});
text_object.add_component<BehaviorScript>().set_script<TestScript>();
text_object.add_component<Camera>(ivec2{300, 300}, vec2{100, 100}, Camera::Data{});
}
diff --git a/src/example/loadfont.cpp b/src/example/loadfont.cpp
index 36d00dd..ed67ffa 100644
--- a/src/example/loadfont.cpp
+++ b/src/example/loadfont.cpp
@@ -1,14 +1,14 @@
#include <SDL2/SDL_ttf.h>
+#include <crepe/api/Asset.h>
#include <crepe/api/Text.h>
#include <crepe/facade/Font.h>
#include <crepe/facade/SDLContext.h>
-#include <crepe/api/Asset.h>
#include <crepe/manager/Mediator.h>
#include <crepe/manager/ResourceManager.h>
#include <exception>
#include <iostream>
-#include <optional>
#include <memory>
+#include <optional>
using namespace crepe;
int main() {
@@ -20,11 +20,11 @@ int main() {
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", Asset(""));
+ 1, vec2(100, 100), vec2(0, 0), "OpenSymbol", Text::Data{}, "test text", Asset(""));
// std::cout << "Path: " << label->font.get_path() << std::endl;
- std::unique_ptr<Text> label2
- = std::make_unique<Text>(1, vec2(100, 100), vec2(0, 0),"fsaafdafsdafsdafsdasfdds", Text::Data{});
+ 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 = asset;
std::cout << label->font.value().get_path() << std::endl;