fixed config
added toml(again) fixed init
This commit is contained in:
parent
b920c95c8c
commit
f9aa3e35b0
@ -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;
|
||||
|
@ -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
|
||||
|
35
src/Font.cpp
35
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<std::string> 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<int>("firstChar").value_or(0);
|
||||
pixelSize = config->get_as<int>("pixelSize").value_or(0);
|
||||
gap = config->get_as<int>("gap").value_or(-1);
|
||||
invertedColors = config->get_as<int>("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) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user