107 lines
3.4 KiB
C++
107 lines
3.4 KiB
C++
//#include "add.h"
|
|
#include "Bitmap.h"
|
|
#include "Font.h"
|
|
|
|
#include <iostream>
|
|
|
|
bool isQuit(std::string command);
|
|
|
|
/**
|
|
* @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.
|
|
*/
|
|
|
|
#include "TextRenderer.h"
|
|
void outPutPixel(int windowHeight, int windowWidth, vkvm::Color fontColor);
|
|
|
|
int main() {
|
|
vkvm::initialize(0);
|
|
|
|
std::string currentText;
|
|
|
|
/*************************set back to shared memory(only for test)********************************************/
|
|
int windowWidth = 40;
|
|
int windowHeight = 15;
|
|
vkvm::setWidth(windowWidth);
|
|
vkvm::setHeight(windowHeight);
|
|
|
|
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();
|
|
TextRenderer textRenderer(windowWidth, windowHeight, backgroundColor, fontColor, font);
|
|
textRenderer.setLeftMargin(1);
|
|
textRenderer.setBottomMargin(1);
|
|
/*************************get Text and update back to shared meomory********************************************/
|
|
|
|
std::string command;
|
|
std::cout << "TextRender: ";
|
|
std::getline(std::cin, command);
|
|
while(!isQuit(command)) {
|
|
if(command.compare("clear")) {
|
|
vkvm::setText(command);
|
|
currentText = vkvm::getText();
|
|
textRenderer.update(currentText);
|
|
outPutPixel(windowHeight, windowWidth, fontColor);
|
|
std::cout << "TextRender: ";
|
|
std::getline(std::cin, command);
|
|
} else {
|
|
textRenderer.clear();
|
|
}
|
|
}
|
|
|
|
std::cout << "TextRender finished." << std::endl;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/***************************read pixel in shared memory and test output in console******************************************/
|
|
void outPutPixel(int windowHeight, int windowWidth, vkvm::Color fontColor) {
|
|
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";
|
|
}
|
|
}
|
|
|
|
|
|
// std::string str;
|
|
// std::cout << "string to draw: ";
|
|
// std::getline(std::cin, str);
|
|
//
|
|
// for (int i = 0; i < font.height(); i++) {
|
|
// for (char c : str) {
|
|
// for (int j = 0; j < font.width(); j++) {
|
|
// if (font.getPixel(c,j,i)) {
|
|
// std::cout << "█";
|
|
// } else {
|
|
// std::cout << " ";
|
|
// }
|
|
// }
|
|
// std::cout << " ";
|
|
// }
|
|
// std::cout << std::endl;
|
|
// }
|
|
//
|
|
// return 0;
|
|
|
|
bool isQuit(std::string command) {
|
|
return command.compare("quit") == 0;
|
|
}
|