From 4b1afac94d815bb44fc0c8ac347b16e7709f6653 Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Wed, 23 Oct 2019 13:03:16 +0200 Subject: [PATCH] + Font Config File + toml --- CMakeLists.txt | 3 +++ main/main.cpp | 2 +- res/font.toml | 9 +++++++++ src/Font.cpp | 35 +++++++++++++++++++++++------------ src/Font.h | 4 ++-- 5 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 res/font.toml diff --git a/CMakeLists.txt b/CMakeLists.txt index b41e461..0a166fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,9 @@ file(GLOB_RECURSE TESTS test/*.cpp) include_directories(src) include_directories(test) +#toml +include_directories(lib/toml) + set(LIB_PATH "${CMAKE_SOURCE_DIR}/../library") include_directories(${LIB_PATH}/include) diff --git a/main/main.cpp b/main/main.cpp index da3cfe1..057c501 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -12,7 +12,7 @@ * Currently only to test. */ int main() { - Font font("../res/font.bmp"); + Font font("../res/font.bmp","../res/font.toml"); std::string str; std::cout << "string to draw: "; diff --git a/res/font.toml b/res/font.toml new file mode 100644 index 0000000..b56bd8a --- /dev/null +++ b/res/font.toml @@ -0,0 +1,9 @@ +xOffset = 2 +yOffset = 2 +xSize = 5 +ySize = 7 +xCount = 18 +yCount = 4 +xStart = 1 +yStart = 2 +fillValue = 0xffffff \ No newline at end of file diff --git a/src/Font.cpp b/src/Font.cpp index f29fdf0..9674f4a 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -3,25 +3,36 @@ // #include "Font.h" +#include Font::Font() { - xOffset = 2; - yOffset = 2; - xSize = 5; - ySize = 7; - xCount = 18; - yCount = 4; - xStart = 1; - yStart = 2; - fillValue = 0xffffff; + xOffset = 0; + yOffset = 0; + xSize = 0; + ySize = 0; + xCount = 0; + yCount = 0; + xStart = 0; + yStart = 0; + fillValue = 0; } -Font::Font(const std::string &file) : Font() { - bitmap.load(file); +Font::Font(const std::string &file, const std::string &configFile) : Font() { + load(file, configFile); } -void Font::load(const std::string &file) { +void Font::load(const std::string &file, const std::string &configFile) { bitmap.load(file); + auto config = cpptoml::parse_file(configFile); + xOffset = config->get_as("xOffset").value_or(0); + yOffset = config->get_as("yOffset").value_or(0); + xSize = config->get_as("xSize").value_or(0); + ySize = config->get_as("ySize").value_or(0); + xCount = config->get_as("xCount").value_or(0); + yCount = config->get_as("yOffset").value_or(0); + xStart = config->get_as("xStart").value_or(0); + yStart = config->get_as("yStart").value_or(0); + fillValue = config->get_as("fillValue").value_or(0); } int Font::width() { diff --git a/src/Font.h b/src/Font.h index 41459dd..8a7d3f9 100644 --- a/src/Font.h +++ b/src/Font.h @@ -31,8 +31,8 @@ public: unsigned int fillValue; Font(); - explicit Font(const std::string &file); - void load(const std::string &file); + explicit Font(const std::string &file, const std::string &configFile); + void load(const std::string &file, const std::string &configFile); int width(); int height();