aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe')
-rw-r--r--src/crepe/api/Text.cpp3
-rw-r--r--src/crepe/api/Text.h4
-rw-r--r--src/crepe/facade/Font.cpp17
-rw-r--r--src/crepe/facade/Font.h2
-rw-r--r--src/crepe/facade/SDLFontContext.cpp4
-rw-r--r--src/crepe/facade/SDLFontContext.h6
6 files changed, 18 insertions, 18 deletions
diff --git a/src/crepe/api/Text.cpp b/src/crepe/api/Text.cpp
index c072ee7..9de9038 100644
--- a/src/crepe/api/Text.cpp
+++ b/src/crepe/api/Text.cpp
@@ -3,7 +3,8 @@
using namespace crepe;
Text::Text(game_object_id_t id, const vec2 & dimensions, const vec2 & offset, const std::string & text,
- const std::string & font_family)
+ const std::string & font_family,const Data & data)
: UIObject(id, dimensions, offset),
text(text),
+ data(data),
font_family(font_family) {}
diff --git a/src/crepe/api/Text.h b/src/crepe/api/Text.h
index 2ad1db3..96e1265 100644
--- a/src/crepe/api/Text.h
+++ b/src/crepe/api/Text.h
@@ -15,8 +15,6 @@ namespace crepe {
*/
class Text : public UIObject {
public:
- Text(game_object_id_t id, const vec2 & dimensions, const vec2 & offset, const std::string &,
- const std::string & font_family);
//! Text data that does not have to be set in the constructor
struct Data {
/**
@@ -41,6 +39,8 @@ public:
};
public:
+ Text(game_object_id_t id, const vec2 & dimensions, const vec2 & offset, const std::string &,
+ const std::string & font_family, const Data& data);
//! font family name such as (Arial,Helvetica,Inter)
std::string font_family = "";
//! Label text.
diff --git a/src/crepe/facade/Font.cpp b/src/crepe/facade/Font.cpp
index a39af75..f111af9 100644
--- a/src/crepe/facade/Font.cpp
+++ b/src/crepe/facade/Font.cpp
@@ -8,17 +8,12 @@ using namespace crepe;
Font::Font(const Asset & src, Mediator & mediator)
: Resource(src, mediator),
font(nullptr, TTF_CloseFont) {
- // Get the font file path from the Asset
- const std::string font_path = src.get_path();
-
- // Attempt to load the font
- this->font.reset(TTF_OpenFont(font_path.c_str(), Config::get_instance().font.size));
-
- // Check if font loading failed
- if (!this->font) {
- throw runtime_error(format("Failed to load font from path: {}. SDL_ttf error: {}",
- font_path, TTF_GetError()));
- }
+ Config & config = Config::get_instance();
+ const std::string FONT_PATH = src.get_path();
+ TTF_Font * font = TTF_OpenFont(FONT_PATH.c_str(), config.font.size);
+ if (font == NULL)
+ throw runtime_error(format("Font: {} (path: {})", TTF_GetError(), FONT_PATH));
+ this->font = { font, [] (TTF_Font * font) { TTF_CloseFont(font); } };
}
TTF_Font * Font::get_font() const { return this->font.get(); }
diff --git a/src/crepe/facade/Font.h b/src/crepe/facade/Font.h
index 983ef31..f7d5b50 100644
--- a/src/crepe/facade/Font.h
+++ b/src/crepe/facade/Font.h
@@ -35,7 +35,7 @@ public:
private:
//! The SDL_ttf font object with custom deleter.
- std::unique_ptr<TTF_Font, decltype(&TTF_CloseFont)> font;
+ std::unique_ptr<TTF_Font, std::function<void(TTF_Font*)>> font;
};
} // namespace crepe
diff --git a/src/crepe/facade/SDLFontContext.cpp b/src/crepe/facade/SDLFontContext.cpp
index 1037ac4..5123b3b 100644
--- a/src/crepe/facade/SDLFontContext.cpp
+++ b/src/crepe/facade/SDLFontContext.cpp
@@ -13,7 +13,7 @@ SDLFontContext::SDLFontContext() {
SDLFontContext::~SDLFontContext() { FcFini(); }
-unique_ptr<Asset> SDLFontContext::get_font_asset(const string font_family) {
+Asset SDLFontContext::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()));
@@ -49,5 +49,5 @@ unique_ptr<Asset> SDLFontContext::get_font_asset(const string font_family) {
// Convert the file path to a string
string font_file_path(reinterpret_cast<const char *>(file_path));
FcPatternDestroy(matched_pattern);
- return move(make_unique<Asset>(font_file_path));
+ return Asset(font_file_path);
}
diff --git a/src/crepe/facade/SDLFontContext.h b/src/crepe/facade/SDLFontContext.h
index efeaa33..cb3ca9d 100644
--- a/src/crepe/facade/SDLFontContext.h
+++ b/src/crepe/facade/SDLFontContext.h
@@ -11,6 +11,10 @@ class SDLFontContext {
public:
SDLFontContext();
~SDLFontContext();
+ SDLFontContext(const SDLFontContext &) = delete;
+ SDLFontContext(SDLFontContext &&) = delete;
+ SDLFontContext & operator=(const SDLFontContext &) = delete;
+ SDLFontContext & operator=(SDLFontContext &&) = delete;
/**
*
* \brief Facade function to convert a font_family into an asset.
@@ -19,7 +23,7 @@ public:
*
* \param font_family Name of the font family name.
*/
- std::unique_ptr<Asset> get_font_asset(const std::string font_family);
+ Asset get_font_asset(const std::string font_family);
private:
};