aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe')
-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.h7
-rw-r--r--src/crepe/system/RenderSystem.cpp34
10 files changed, 39 insertions, 50 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 1620247..2e248de 100644
--- a/src/crepe/api/Text.cpp
+++ b/src/crepe/api/Text.cpp
@@ -5,11 +5,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 9c1a800..81a9e7a 100644
--- a/src/crepe/facade/Font.cpp
+++ b/src/crepe/facade/Font.cpp
@@ -9,8 +9,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();
diff --git a/src/crepe/facade/FontFacade.cpp b/src/crepe/facade/FontFacade.cpp
index 9919032..cec3507 100644
--- a/src/crepe/facade/FontFacade.cpp
+++ b/src/crepe/facade/FontFacade.cpp
@@ -7,16 +7,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) {
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 c19f0aa..a5ccdae 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -467,6 +467,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 fcf3559..33a4ff9 100644
--- a/src/crepe/facade/SDLContext.h
+++ b/src/crepe/facade/SDLContext.h
@@ -18,6 +18,7 @@
#include "types.h"
#include "FontFacade.h"
+
namespace crepe {
class Texture;
@@ -244,9 +245,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
@@ -257,7 +260,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 578a4c0..872ba29 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"
@@ -25,7 +25,6 @@
using namespace crepe;
using namespace std;
-
void RenderSystem::clear_screen() {
SDLContext & ctx = this->mediator.sdl_context;
ctx.clear_screen();
@@ -145,12 +144,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;
@@ -162,26 +160,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;
- // Check if font is available in text
- if (!text.font.has_value()) {
- }
+ 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()) {
- 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);
}
-
-
-