2019-11-14 13:12:48 +01:00
|
|
|
//#include "add.h"
|
2019-10-15 16:12:56 +02:00
|
|
|
#include "Bitmap.h"
|
2019-11-19 13:27:18 +01:00
|
|
|
#include "Font.h"
|
2019-11-14 13:12:48 +01:00
|
|
|
|
|
|
|
#include <iostream>
|
2019-11-27 15:16:35 +01:00
|
|
|
#include <internal.hpp>
|
2019-10-15 14:00:06 +02:00
|
|
|
|
2019-11-19 13:27:18 +01:00
|
|
|
bool isQuit(std::string command);
|
|
|
|
|
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.
|
|
|
|
* A string is converted and displayed in the console.
|
|
|
|
* Currently only to test.
|
|
|
|
*/
|
2019-11-19 13:27:18 +01:00
|
|
|
|
|
|
|
#include "TextRenderer.h"
|
2019-11-27 15:16:35 +01:00
|
|
|
void outputWindow(int windowHeight, int windowWidth, vkvm::Color fontColor);
|
|
|
|
TextRenderer generateTextRender();
|
|
|
|
void renderText(TextRenderer textRenderer);
|
|
|
|
void test();
|
2019-11-19 13:27:18 +01:00
|
|
|
|
2019-11-27 15:16:35 +01:00
|
|
|
void test(TextRenderer renderer);
|
|
|
|
|
|
|
|
void redraw(TextRenderer renderer);
|
|
|
|
|
|
|
|
void test1();
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
2019-11-19 13:47:30 +01:00
|
|
|
vkvm::initialize(0);
|
|
|
|
|
2019-11-27 15:16:35 +01:00
|
|
|
TextRenderer textRenderer = generateTextRender();
|
|
|
|
|
|
|
|
textRenderer.clear();
|
|
|
|
|
|
|
|
// test(textRenderer);
|
|
|
|
|
|
|
|
vkvm::registerEvent(vkvm::EventType::RenderText, [&textRenderer]() {
|
|
|
|
renderText(textRenderer);
|
|
|
|
});
|
|
|
|
|
2019-12-17 13:48:18 +01:00
|
|
|
test1();
|
2019-11-27 15:16:35 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void redraw(TextRenderer textRenderer) {
|
|
|
|
textRenderer.clear();
|
|
|
|
textRenderer.update(vkvm::getText());
|
|
|
|
}
|
|
|
|
|
|
|
|
void renderText(TextRenderer textRenderer) {
|
|
|
|
textRenderer.update(vkvm::getText());
|
2019-12-17 13:48:18 +01:00
|
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
2019-11-27 15:16:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TextRenderer generateTextRender() {
|
|
|
|
std::string command;
|
|
|
|
std::cout << "fontSize: ";
|
|
|
|
std::getline(std::cin, command);
|
|
|
|
|
|
|
|
int windowWidth = vkvm::getWidth();
|
|
|
|
int windowHeight = vkvm::getHeight();
|
|
|
|
vkvm::Color fontColor = vkvm::getForegroundColor();
|
|
|
|
vkvm::Color backgroundColor = vkvm::getBackgroundColor();
|
|
|
|
|
|
|
|
vkvm::FontType fontType = vkvm::getFont();
|
|
|
|
int fontSize = std::stoi(command);
|
|
|
|
|
|
|
|
int font_id = fontType.getId();
|
|
|
|
std::string fontResourcePath = "../res/font" + std::to_string(3) + ".bmp";
|
|
|
|
std::string fontConfigureFilePath = "../res/font" + std::to_string(3) + ".toml";
|
|
|
|
Font font = Font(fontResourcePath, fontConfigureFilePath);
|
|
|
|
|
|
|
|
return TextRenderer(windowWidth, windowHeight, backgroundColor, fontColor, font, fontSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test1() {
|
|
|
|
std::string command;
|
|
|
|
std::cout << "TextRender: ";
|
|
|
|
std::getline(std::cin, command);
|
|
|
|
while(command.compare("quit") != 0) {
|
|
|
|
if(command.compare("RenderText") == 0) {
|
|
|
|
vkvm::callEvent(vkvm::EventType::RenderText);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(command.compare("Redraw") == 0) {
|
|
|
|
vkvm::callEvent(vkvm::EventType::Redraw);
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
vkvm::setText(command);
|
|
|
|
}
|
2019-12-17 13:48:18 +01:00
|
|
|
std::cout << "TextRender: ";
|
|
|
|
std::getline(std::cin, command);
|
2019-11-27 15:16:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "TextRender finished." << std::endl;}
|
|
|
|
|
|
|
|
void test(TextRenderer renderer) {
|
|
|
|
std::string currentText;
|
|
|
|
|
|
|
|
std::string command;
|
|
|
|
std::cout << "TextRender: ";
|
|
|
|
std::getline(std::cin, command);
|
|
|
|
while(!isQuit(command)) {
|
|
|
|
if(command.compare("clear")) {
|
|
|
|
vkvm::setText(command);
|
|
|
|
currentText = vkvm::getText();
|
|
|
|
renderer.update(currentText);
|
|
|
|
} else {
|
|
|
|
renderer.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
outputWindow(renderer.getWindowHeight(), renderer.getWindowWidth(), vkvm::getForegroundColor());
|
|
|
|
std::cout << "TextRender: ";
|
|
|
|
std::getline(std::cin, command);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "TextRender finished." << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void test() {
|
2019-11-19 13:27:18 +01:00
|
|
|
std::string currentText;
|
|
|
|
|
2019-11-20 12:50:32 +01:00
|
|
|
/*************************set back to shared memory(only for test)********************************************/
|
2019-11-20 15:51:01 +01:00
|
|
|
int windowWidth = 40;
|
|
|
|
int windowHeight = 15;
|
|
|
|
vkvm::setWidth(windowWidth);
|
|
|
|
vkvm::setHeight(windowHeight);
|
|
|
|
|
2019-11-20 12:50:32 +01:00
|
|
|
vkvm::Color fontColor1(0, 0, 0);
|
|
|
|
vkvm::Color backgroudColor1(255, 255, 255);
|
|
|
|
Font font1("../res/font3.bmp", "../res/font3.toml");
|
|
|
|
vkvm::setFont(vkvm::FontType(3, "font", font1.height(), font1.width()));
|
|
|
|
vkvm::setForegroundColor(fontColor1);
|
|
|
|
vkvm::setBackgroundColor(backgroudColor1);
|
|
|
|
/**************************get text and font from shared memory*******************************************/
|
|
|
|
std::string fontResourcePath = "../res/font" + std::to_string(vkvm::getFont().getId()) + ".bmp";
|
|
|
|
std::string fontConfigureFilePath = "../res/font" + std::to_string(vkvm::getFont().getId()) + ".toml";
|
|
|
|
Font font = Font(fontResourcePath, fontConfigureFilePath);
|
|
|
|
vkvm::Color fontColor = vkvm::getForegroundColor();
|
|
|
|
vkvm::Color backgroundColor = vkvm::getBackgroundColor();
|
2019-11-20 15:51:01 +01:00
|
|
|
TextRenderer textRenderer(windowWidth, windowHeight, backgroundColor, fontColor, font);
|
|
|
|
textRenderer.setLeftMargin(1);
|
|
|
|
textRenderer.setBottomMargin(1);
|
|
|
|
/*************************get Text and update back to shared meomory********************************************/
|
2019-11-20 12:50:32 +01:00
|
|
|
|
|
|
|
std::string command;
|
2019-11-20 15:51:01 +01:00
|
|
|
std::cout << "TextRender: ";
|
2019-11-19 13:27:18 +01:00
|
|
|
std::getline(std::cin, command);
|
|
|
|
while(!isQuit(command)) {
|
2019-11-20 15:51:01 +01:00
|
|
|
if(command.compare("clear")) {
|
|
|
|
vkvm::setText(command);
|
2019-11-19 13:27:18 +01:00
|
|
|
currentText = vkvm::getText();
|
|
|
|
textRenderer.update(currentText);
|
2019-11-27 15:16:35 +01:00
|
|
|
outputWindow(windowHeight, windowWidth, fontColor);
|
2019-11-20 15:51:01 +01:00
|
|
|
std::cout << "TextRender: ";
|
|
|
|
std::getline(std::cin, command);
|
|
|
|
} else {
|
|
|
|
textRenderer.clear();
|
2019-10-15 16:12:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 13:27:18 +01:00
|
|
|
std::cout << "TextRender finished." << std::endl;
|
2019-11-14 13:12:48 +01:00
|
|
|
}
|
2019-11-19 13:27:18 +01:00
|
|
|
|
2019-11-27 15:16:35 +01:00
|
|
|
|
2019-11-20 15:51:01 +01:00
|
|
|
/***************************read pixel in shared memory and test output in console******************************************/
|
2019-11-27 15:16:35 +01:00
|
|
|
void outputWindow(int windowHeight, int windowWidth, vkvm::Color fontColor) {
|
2019-11-20 15:51:01 +01:00
|
|
|
for(int y = 0; y < windowHeight; y++) {
|
|
|
|
for(int x = 0; x < windowWidth; x++) {
|
|
|
|
if(vkvm::getPixel(x, y).getRed() == fontColor.getRed()) {
|
|
|
|
std::cout << "*";
|
|
|
|
} else {
|
|
|
|
std::cout << " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 13:27:18 +01:00
|
|
|
bool isQuit(std::string command) {
|
|
|
|
return command.compare("quit") == 0;
|
|
|
|
}
|