never mind, only commit for test by Yukun Chen.

This commit is contained in:
my 2019-12-17 15:02:14 +01:00
parent e8c2cbdfee
commit 9770d102e5
2 changed files with 40 additions and 7 deletions

View File

@ -35,32 +35,59 @@ void TextRenderer::update(std::string newText) {
int fontNumbersInOneLine = windowWidth / (fontWidth + left_margin); int fontNumbersInOneLine = windowWidth / (fontWidth + left_margin);
std::vector<std::vector<bool>> characterBitmap; std::vector<std::vector<bool>> characterBitmap;
if(newText.size() < oldTextsize) {
clear();
}
for(i = 0; i < newText.size(); i++) { for(i = 0; i < newText.size(); i++) {
if(i > oldText.size() || oldText[i] != newText[i]) { if(i > oldText.size() || oldText[i] != newText[i]) {
if(newText[i] == '\n') { if(newText[i] == '\n') {
space += (fontNumbersInOneLine - ((i + space) % fontNumbersInOneLine) - 1); space += (fontNumbersInOneLine - ((i + space) % fontNumbersInOneLine) - 1);
if(newText.size() < oldTextsize) {
clear(currentX, currentY, fontWidth, currentY + fontHeight);
}
} else { } else {
currentX = ((i + space) % fontNumbersInOneLine) * (fontWidth + left_margin); currentX = ((i + space) % fontNumbersInOneLine) * (fontWidth + left_margin);
currentY = ((i + space) / fontNumbersInOneLine) * (fontHeight + bottom_margin); currentY = ((i + space) / fontNumbersInOneLine) * (fontHeight + bottom_margin);
characterBitmap = getCharacter(newText[i], font); if(newText[i] == -127) {
blinkX = currentX;
blinkY = currentY + fontWidth - 1;
space -= 1;
} else {
characterBitmap = getCharacter(newText[i], font);
// fontProcessing(characterBitmap); // fontProcessing(characterBitmap);
translateToSharedMemory(characterBitmap, currentX, currentY); translateToSharedMemory(characterBitmap, currentX, currentY);
}
} }
} }
} }
if(newText.size() < oldTextsize) {
clear(currentX, currentY, fontWidth, currentY + fontHeight);
}
oldTextsize = newText.size(); oldTextsize = newText.size();
setOldText(newText); setOldText(newText);
} }
void TextRenderer::blink() {
bool signal;
while(true) {
for(int y = 0; y < fontHeight; y++) {
if(signal)
vkvm::setPixel(blinkX, blinkY + y, backgroundColor);
else
vkvm::setPixel(blinkX, blinkY + y, fontColor);
}
signal = !signal;
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}
void TextRenderer::clear() { void TextRenderer::clear() {
int x, y; int x, y;
for(y = 0; y < windowHeight; y++) { for(y = 0; y < windowHeight; y++) {

View File

@ -13,6 +13,7 @@
#include <Color.hpp> #include <Color.hpp>
#include <vkvm.hpp> #include <vkvm.hpp>
#include <iostream> #include <iostream>
#include <thread>
#include "Font.h" #include "Font.h"
/** /**
@ -41,6 +42,8 @@ public:
int getWindowHeight(); int getWindowHeight();
private: private:
std::mutex mutex;
std::string oldText; std::string oldText;
vkvm::Color backgroundColor; vkvm::Color backgroundColor;
vkvm::Color fontColor; vkvm::Color fontColor;
@ -56,12 +59,15 @@ private:
int currentX; int currentX;
int currentY; int currentY;
int oldTextsize; int oldTextsize;
int blinkX = 0;
int blinkY = 0;
bool isBold(); bool isBold();
bool isItalics(); bool isItalics();
bool isUnderline(); bool isUnderline();
void fontProcessing(std::vector<std::vector<bool>> characterBitmap); void fontProcessing(std::vector<std::vector<bool>> characterBitmap);
void translateToSharedMemory(std::vector<std::vector<bool>> characterBitmap, int startX, int startY); void translateToSharedMemory(std::vector<std::vector<bool>> characterBitmap, int startX, int startY);
void checkWindowSize(); void checkWindowSize();
void blink();
void checkFontColor(); void checkFontColor();