+ Font Config File

+ toml
This commit is contained in:
Julian Hinxlage 2019-10-23 13:03:16 +02:00
parent cf0e6a082d
commit 4b1afac94d
5 changed files with 38 additions and 15 deletions

View File

@ -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)

View File

@ -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: ";

9
res/font.toml Normal file
View File

@ -0,0 +1,9 @@
xOffset = 2
yOffset = 2
xSize = 5
ySize = 7
xCount = 18
yCount = 4
xStart = 1
yStart = 2
fillValue = 0xffffff

View File

@ -3,25 +3,36 @@
//
#include "Font.h"
#include <cpptoml.h>
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<int>("xOffset").value_or(0);
yOffset = config->get_as<int>("yOffset").value_or(0);
xSize = config->get_as<int>("xSize").value_or(0);
ySize = config->get_as<int>("ySize").value_or(0);
xCount = config->get_as<int>("xCount").value_or(0);
yCount = config->get_as<int>("yOffset").value_or(0);
xStart = config->get_as<int>("xStart").value_or(0);
yStart = config->get_as<int>("yStart").value_or(0);
fillValue = config->get_as<unsigned int>("fillValue").value_or(0);
}
int Font::width() {

View File

@ -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();