From f9aa3e35b0a6e0c5c056f2f9b62bdc67d4e67c2e Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Tue, 19 Nov 2019 13:47:30 +0100 Subject: [PATCH] fixed config added toml(again) fixed init --- main/main.cpp | 2 ++ res/font3.toml | 21 +++++++++++---------- src/Font.cpp | 35 ++++++----------------------------- src/Font.h | 6 +++--- 4 files changed, 22 insertions(+), 42 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index c3474ee..6accb89 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -17,6 +17,8 @@ bool isQuit(std::string command); #include "TextRenderer.h" int main() { + vkvm::initialize(0); + Font font("../res/font1.bmp", "../res/font1.toml"); std::string oldText; diff --git a/res/font3.toml b/res/font3.toml index f6596a2..102a09f 100644 --- a/res/font3.toml +++ b/res/font3.toml @@ -1,11 +1,12 @@ -xOffset = 0 -yOffset = 0 -xSize = 22 -ySize = 31 +xOffset = 6 +yOffset = 6 +xSize = 18 +ySize = 27 xCount = 32 -yCount = 7 -xStart = 0 -yStart = 0 -fillValue = 0xffffff -firstChar = 20 -pixelSize = 4 +yCount = 9 +xStart = 7 +yStart = 9 +fillValue = 4294967295 +firstChar = 25 +pixelSize = 1 +invertedColors = 1 diff --git a/src/Font.cpp b/src/Font.cpp index 14a6b72..0a601b7 100644 --- a/src/Font.cpp +++ b/src/Font.cpp @@ -20,15 +20,6 @@ Font::Font() { Font::Font(const std::string &file, const std::string &configFile) : Font() { load(file, configFile); -// std::vector tempString; - -// if(std::regex_match(file, std::regex("(.+)\\.ppm$"))) { -// loadPPMFile(file, configFile); -// } else { -// std::cout << "heloo1" << std::endl; -// load(file, configFile); -// } - } void Font::load(const std::string &file, const std::string &configFile) { @@ -46,6 +37,7 @@ void Font::load(const std::string &file, const std::string &configFile) { firstChar = (char)config->get_as("firstChar").value_or(0); pixelSize = config->get_as("pixelSize").value_or(0); gap = config->get_as("gap").value_or(-1); + invertedColors = config->get_as("invertedColors").value_or(0); } int Font::width() { @@ -78,26 +70,11 @@ bool Font::getPixel(char character, int x, int y) { int xPos = xIndex * (xSize + xOffset) + xStart; int yPos = yIndex * (ySize + yOffset) + yStart; - return bitmap.getPixel((xPos + x) * pixelSize, (yPos + y) * pixelSize) == fillValue; -} - -bool** Font::getCharacter(unsigned char character) { - int fontHeight = height(); - int fontWidth = width(); - bool **bitmap_character; - - bitmap_character = (bool**)malloc(fontHeight * sizeof(bool*)); - for (int i = 0; i < fontHeight; i++) { - bitmap_character[i] = (bool*)malloc(fontWidth * sizeof(bool)); - for (int j = 0; j < fontWidth; j++) { - bitmap_character[i][j] = getPixel(character, j, i); - } + bool value = bitmap.getPixel((xPos + x) * pixelSize, (yPos + y) * pixelSize) == fillValue; + if(invertedColors){ + return !value; + }else{ + return value; } - - return bitmap_character; -} - -void Font::loadPPMFile(const std::string &file, const std::string &configFile) { - } diff --git a/src/Font.h b/src/Font.h index 71e5e17..e4c45d5 100644 --- a/src/Font.h +++ b/src/Font.h @@ -12,7 +12,7 @@ * @since: v0.0.0 * @brief: this class provides pixel access based on characters */ -class Font{ +class Font { public: Bitmap bitmap; @@ -38,11 +38,11 @@ public: int pixelSize; int gap; + bool invertedColors; + Font(); explicit Font(const std::string &file, const std::string &configFile); void load(const std::string &file, const std::string &configFile); - void loadPPMFile(const std::string &file, const std::string &configFile); - bool** getCharacter(unsigned char character); int width(); int height();