59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
//
|
|
// Copyright (c) 2019 Julian Hinxlage. All rights reserved.
|
|
//
|
|
|
|
#include "Font.h"
|
|
#include <cpptoml.h>
|
|
|
|
Font::Font() {
|
|
xOffset = 0;
|
|
yOffset = 0;
|
|
xSize = 0;
|
|
ySize = 0;
|
|
xCount = 0;
|
|
yCount = 0;
|
|
xStart = 0;
|
|
yStart = 0;
|
|
fillValue = 0;
|
|
}
|
|
|
|
Font::Font(const std::string &file, const std::string &configFile) : Font() {
|
|
load(file, configFile);
|
|
}
|
|
|
|
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() {
|
|
return xSize;
|
|
}
|
|
|
|
int Font::height() {
|
|
return ySize;
|
|
}
|
|
|
|
bool Font::getPixel(char character, int x, int y) {
|
|
//index of character(x and y)
|
|
int index = (character - ' ');
|
|
int xIndex = index % xCount;
|
|
int yIndex = index / xCount;
|
|
|
|
//character index to pixel index conversion
|
|
int xPos = xIndex * (xSize + xOffset) + xStart;
|
|
int yPos = yIndex * (ySize + yOffset) + yStart;
|
|
|
|
return bitmap.getPixel(xPos + x, yPos + y) == fillValue;
|
|
}
|
|
|