Text-Renderer/main/main.cpp

71 lines
2.1 KiB
C++

#include "Font.hpp"
#include "internal.hpp"
#include "vkvm.hpp"
#include <thread>
/**
* @author: Julian Hinxlage
* @since: v0.0.0
* @brief: An image is loaded and used as a font.
*/
int main() {
vkvm::initialize(0);
vkvm::setLogLevel(vkvm::DEBUG);
Font font(std::string() + "../res/font" + std::to_string(vkvm::getFont()) + ".bmp", std::string() + "../res/font" + std::to_string(vkvm::getFont()) + ".toml");
vkvm::registerEvent(vkvm::EventType::RenderText, [&font]() {
std::string currentText = vkvm::getText();
int perRow = vkvm::getWidth() / font.width();
auto bc = vkvm::getBackgroundColor();
auto fc = vkvm::getForegroundColor();
//clear area
for(int y = 0; y < vkvm::getHeight();y++){
for(int x = 0; x < vkvm::getWidth();x++) {
vkvm::setPixel(x,y,bc);
}
}
int x = 0;
int y = 0;
for(char c : currentText){
if(c == '\n'){
y++;
x = 0;
}else if(c == -127){
//TODO(julian): cursor
}
else{
if(x == perRow){
y++;
x = 0;
}
for(int i = 0; i < font.height();i++){
for(int j = 0; j < font.width();j++){
if(font.getPixel(c, j, i)){
vkvm::setPixel(x * font.width() + j, y * font.height() + i, fc);
}else{
vkvm::setPixel(x * font.width() + j, y * font.height() + i, bc);
}
}
}
x++;
}
}
vkvm::callEvent(vkvm::EventType::Redraw);
});
vkvm::registerEvent(vkvm::EventType::UpdateControlRegisters, [&font]() {
font.load(std::string() + "../res/font" + std::to_string(vkvm::getFont()) + ".bmp", std::string() + "../res/font" + std::to_string(vkvm::getFont()) + ".toml");
});
while (true) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
return 0;
}