never mind, only commit for test by Yukun Chen.
This commit is contained in:
parent
e8c2cbdfee
commit
9770d102e5
|
@ -35,32 +35,59 @@ void TextRenderer::update(std::string newText) {
|
|||
int fontNumbersInOneLine = windowWidth / (fontWidth + left_margin);
|
||||
std::vector<std::vector<bool>> characterBitmap;
|
||||
|
||||
if(newText.size() < oldTextsize) {
|
||||
clear();
|
||||
}
|
||||
|
||||
for(i = 0; i < newText.size(); i++) {
|
||||
if(i > oldText.size() || oldText[i] != newText[i]) {
|
||||
if(newText[i] == '\n') {
|
||||
space += (fontNumbersInOneLine - ((i + space) % fontNumbersInOneLine) - 1);
|
||||
|
||||
if(newText.size() < oldTextsize) {
|
||||
clear(currentX, currentY, fontWidth, currentY + fontHeight);
|
||||
}
|
||||
} else {
|
||||
|
||||
currentX = ((i + space) % fontNumbersInOneLine) * (fontWidth + left_margin);
|
||||
currentY = ((i + space) / fontNumbersInOneLine) * (fontHeight + bottom_margin);
|
||||
|
||||
if(newText[i] == -127) {
|
||||
blinkX = currentX;
|
||||
blinkY = currentY + fontWidth - 1;
|
||||
space -= 1;
|
||||
} else {
|
||||
characterBitmap = getCharacter(newText[i], font);
|
||||
|
||||
// fontProcessing(characterBitmap);
|
||||
translateToSharedMemory(characterBitmap, currentX, currentY);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(newText.size() < oldTextsize) {
|
||||
clear(currentX, currentY, fontWidth, currentY + fontHeight);
|
||||
}
|
||||
|
||||
oldTextsize = newText.size();
|
||||
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() {
|
||||
int x, y;
|
||||
for(y = 0; y < windowHeight; y++) {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <Color.hpp>
|
||||
#include <vkvm.hpp>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include "Font.h"
|
||||
|
||||
/**
|
||||
|
@ -41,6 +42,8 @@ public:
|
|||
int getWindowHeight();
|
||||
|
||||
private:
|
||||
std::mutex mutex;
|
||||
|
||||
std::string oldText;
|
||||
vkvm::Color backgroundColor;
|
||||
vkvm::Color fontColor;
|
||||
|
@ -56,12 +59,15 @@ private:
|
|||
int currentX;
|
||||
int currentY;
|
||||
int oldTextsize;
|
||||
int blinkX = 0;
|
||||
int blinkY = 0;
|
||||
bool isBold();
|
||||
bool isItalics();
|
||||
bool isUnderline();
|
||||
void fontProcessing(std::vector<std::vector<bool>> characterBitmap);
|
||||
void translateToSharedMemory(std::vector<std::vector<bool>> characterBitmap, int startX, int startY);
|
||||
void checkWindowSize();
|
||||
void blink();
|
||||
|
||||
void checkFontColor();
|
||||
|
||||
|
|
Loading…
Reference in New Issue