aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/launch.json28
-rw-r--r--mwe/events/include/event.h2
-rw-r--r--readme.md1
-rw-r--r--src/CMakeLists.txt4
-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
-rw-r--r--src/example/loadfont.cpp8
11 files changed, 54 insertions, 25 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..07bd65f
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,28 @@
+{
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "Debug test_main",
+ "type": "cppdbg",
+ "request": "launch",
+ "program": "${workspaceFolder}/src/build/test_main", // Path to your executable
+ "args": [], // Optional: add any arguments here if needed
+ "stopAtEntry": false, // Set to true if you want to break at the entry point
+ "cwd": "${workspaceFolder}", // Working directory for the program
+ "environment": [],
+ "externalConsole": false, // Set to true to use an external console
+ "MIMode": "gdb", // Use "lldb" if you're using LLDB instead of GDB
+ "setupCommands": [
+ {
+ "description": "Enable pretty-printing for gdb",
+ "text": "-enable-pretty-printing",
+ "ignoreFailures": true
+ }
+ ],
+ "miDebuggerPath": "/usr/bin/gdb", // Path to gdb, adjust based on your system
+ "preLaunchTask": "", // Optional: specify a pre-launch task like building your project
+ "sourceFileMap": {},
+ "logging": { "moduleLoad": false, "engineLogging": false }
+ }
+ ]
+}
diff --git a/mwe/events/include/event.h b/mwe/events/include/event.h
index ee1bf52..e1b220b 100644
--- a/mwe/events/include/event.h
+++ b/mwe/events/include/event.h
@@ -148,7 +148,7 @@ private:
};
class ShutDownEvent : public Event {
public:
- ShutDownEvent() : Event("ShutDownEvent") {};
+ ShutDownEvent() : Event("ShutDownEvent"){};
REGISTER_EVENT_TYPE(ShutDownEvent)
diff --git a/readme.md b/readme.md
index d309b30..984a368 100644
--- a/readme.md
+++ b/readme.md
@@ -60,6 +60,7 @@ Then, follow these steps for each library you want to install:
$ cd lib/googletest
$ cd lib/sdl2
$ cd lib/soloud/contrib
+ $ cd lib/sdl_ttf
$ cd lib/sdl_image
$ cd lib/sdl_ttf
$ cd lib/whereami
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index a525c74..696856c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -14,7 +14,7 @@ find_package(SoLoud REQUIRED)
find_package(GTest REQUIRED)
find_package(whereami REQUIRED)
find_library(BERKELEY_DB db)
-find_package(Fontconfig REQUIRED)
+find_library(FONTCONFIG_LIB fontconfig)
add_library(crepe SHARED)
add_executable(test_main EXCLUDE_FROM_ALL)
@@ -30,7 +30,7 @@ target_link_libraries(crepe
PUBLIC SDL2_image
PUBLIC ${BERKELEY_DB}
PUBLIC whereami
- PUBLIC ${Fontconfig_LIBRARIES}
+ PUBLIC ${FONTCONFIG_LIB}
)
add_subdirectory(crepe)
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:
};
diff --git a/src/example/loadfont.cpp b/src/example/loadfont.cpp
index 3cbe559..a52e7f0 100644
--- a/src/example/loadfont.cpp
+++ b/src/example/loadfont.cpp
@@ -15,10 +15,10 @@ 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), "test test", "OpenSymbol");
- std::unique_ptr<Asset> asset = font_facade.get_font_asset(label->font_family);
- std::cout << "path: " << asset->get_path() << std::endl;
- std::unique_ptr<Font> font = std::make_unique<Font>(*asset, mediator);
+ = std::make_unique<Text>(1, vec2(100, 100), vec2(0, 0), "test test", "OpenSymbol",Text::Data{});
+ Asset asset = font_facade.get_font_asset(label->font_family);
+ std::cout << "path: " << asset.get_path() << std::endl;
+ std::unique_ptr<Font> font = std::make_unique<Font>(asset, mediator);
// Get the TTF_Font from the Font object
TTF_Font* ttf_font = font->get_font();