aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/font.h
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-10 12:27:59 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-10 12:27:59 +0100
commitb2c72ee8ce282bb13b0fbeb2ddb01fdfd6ad1280 (patch)
treef3c678779f326f4b175f91a2b3c7db44d026cd2f /src/crepe/facade/font.h
parent29f2d4537cf4d4d4c74c16447a45a5d7034161f4 (diff)
font progress
Diffstat (limited to 'src/crepe/facade/font.h')
-rw-r--r--src/crepe/facade/font.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/crepe/facade/font.h b/src/crepe/facade/font.h
new file mode 100644
index 0000000..f5c7785
--- /dev/null
+++ b/src/crepe/facade/font.h
@@ -0,0 +1,47 @@
+#pragma once
+
+#include <memory>
+#include <SDL2/SDL_ttf.h>
+
+#include "../api/Asset.h"
+
+namespace crepe {
+
+/**
+ * \brief Font resource facade
+ *
+ * This class is a wrapper around an SDL_ttf font instance, encapsulating font loading and usage.
+ */
+class Font {
+public:
+ /**
+ * \param src The file path to the font file.
+ */
+ Font(const char* src);
+
+ /**
+ * \param res A unique pointer to an Asset holding the font resource.
+ */
+ Font(std::unique_ptr<Asset> res);
+
+ /**
+ * \brief Destructor to clean up font resources.
+ */
+ ~Font() = default;
+
+ void draw(const vec2& pos, const vec2&)
+private:
+ /**
+ * \brief Load the font from the given resource.
+ *
+ * This method is used by both constructors to load the font resource.
+ *
+ * \param res A unique pointer to an Asset holding the font resource.
+ */
+ void load(std::unique_ptr<Asset> res);
+
+private:
+ std::unique_ptr<TTF_Font, decltype(&TTF_CloseFont)> font; ///< The SDL_ttf font object with custom deleter.
+};
+
+} // namespace crepe