2020-01-07 13:23:25 +01:00
|
|
|
#include "Font.hpp"
|
|
|
|
#include "internal.hpp"
|
|
|
|
#include "vkvm.hpp"
|
|
|
|
#include <thread>
|
2020-01-07 15:05:32 +01:00
|
|
|
#include <iostream>
|
2020-01-07 13:23:25 +01:00
|
|
|
|
2020-01-07 13:56:27 +01:00
|
|
|
int cursorPosX = 0;
|
|
|
|
int cursorPosY = 0;
|
2020-01-07 15:59:06 +01:00
|
|
|
bool showCursor = false;
|
2019-11-19 13:27:18 +01:00
|
|
|
|
2019-10-16 15:44:13 +02:00
|
|
|
/**
|
2019-10-15 16:12:56 +02:00
|
|
|
* @author: Julian Hinxlage
|
|
|
|
* @since: v0.0.0
|
|
|
|
* @brief: An image is loaded and used as a font.
|
|
|
|
*/
|
2019-11-19 13:27:18 +01:00
|
|
|
|
2020-01-07 13:56:27 +01:00
|
|
|
void threadHandler(Font &font){
|
2020-01-07 15:59:06 +01:00
|
|
|
static bool cursorState{false};
|
2020-01-07 13:56:27 +01:00
|
|
|
|
2020-01-07 15:59:06 +01:00
|
|
|
int start = 0;
|
|
|
|
int end = font.height();
|
2020-01-07 13:56:27 +01:00
|
|
|
auto bc = vkvm::getBackgroundColor();
|
|
|
|
auto fc = vkvm::getForegroundColor();
|
|
|
|
|
|
|
|
while(true){
|
2020-01-07 15:59:06 +01:00
|
|
|
if(showCursor) {
|
|
|
|
int x = cursorPosX - 1;
|
|
|
|
if (x < 0) {
|
|
|
|
x = 0;
|
2020-01-07 13:56:27 +01:00
|
|
|
}
|
2020-01-07 15:59:06 +01:00
|
|
|
|
|
|
|
for (int i = start; i < end; i++) {
|
|
|
|
if (cursorState) {
|
|
|
|
vkvm::setPixel(x, cursorPosY + i, bc);
|
|
|
|
} else {
|
|
|
|
vkvm::setPixel(x, cursorPosY + i, fc);
|
|
|
|
}
|
2020-01-07 13:56:27 +01:00
|
|
|
}
|
2020-01-07 15:59:06 +01:00
|
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
|
|
cursorState = !cursorState;
|
2020-01-07 13:56:27 +01:00
|
|
|
}
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(800));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-15 14:00:06 +02:00
|
|
|
int main() {
|
2019-11-19 13:47:30 +01:00
|
|
|
vkvm::initialize(0);
|
2019-12-19 10:52:26 +01:00
|
|
|
vkvm::setLogLevel(vkvm::DEBUG);
|
2019-12-04 10:18:13 +01:00
|
|
|
|
2020-01-07 13:23:25 +01:00
|
|
|
Font font(std::string() + "../res/font" + std::to_string(vkvm::getFont()) + ".bmp", std::string() + "../res/font" + std::to_string(vkvm::getFont()) + ".toml");
|
2020-01-07 13:56:27 +01:00
|
|
|
std::thread thread(std::bind(threadHandler, font));
|
2019-11-20 12:50:32 +01:00
|
|
|
|
2020-01-07 13:23:25 +01:00
|
|
|
vkvm::registerEvent(vkvm::EventType::RenderText, [&font]() {
|
2019-11-27 12:02:14 +01:00
|
|
|
std::string currentText = vkvm::getText();
|
2020-01-07 13:23:25 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-07 15:59:06 +01:00
|
|
|
showCursor = false;
|
2020-01-07 13:23:25 +01:00
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
for(char c : currentText){
|
|
|
|
if(c == '\n'){
|
|
|
|
y++;
|
|
|
|
x = 0;
|
|
|
|
}else if(c == -127){
|
2020-01-07 13:56:27 +01:00
|
|
|
cursorPosX = x * font.width();
|
|
|
|
cursorPosY = y * font.height();
|
2020-01-07 15:59:06 +01:00
|
|
|
showCursor = true;
|
2020-01-07 13:23:25 +01:00
|
|
|
}
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 12:02:14 +01:00
|
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
|
|
});
|
|
|
|
|
2020-01-07 13:23:25 +01:00
|
|
|
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");
|
2019-12-19 10:52:26 +01:00
|
|
|
});
|
2019-12-04 10:18:13 +01:00
|
|
|
|
2020-01-07 13:23:25 +01:00
|
|
|
while (true) {
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
2019-10-15 16:12:56 +02:00
|
|
|
}
|
2019-10-15 14:00:06 +02:00
|
|
|
return 0;
|
2019-12-17 12:06:44 +01:00
|
|
|
}
|