From 9770d102e55b63e84eef10a9a3614ab28f6326ad Mon Sep 17 00:00:00 2001 From: my Date: Tue, 17 Dec 2019 15:02:14 +0100 Subject: [PATCH] never mind, only commit for test by Yukun Chen. --- src/TextRenderer.cpp | 41 ++++++++++++++++++++++++++++++++++------- src/TextRenderer.h | 6 ++++++ 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/TextRenderer.cpp b/src/TextRenderer.cpp index c9e5852..8b2746a 100644 --- a/src/TextRenderer.cpp +++ b/src/TextRenderer.cpp @@ -35,32 +35,59 @@ void TextRenderer::update(std::string newText) { int fontNumbersInOneLine = windowWidth / (fontWidth + left_margin); std::vector> 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); - 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); - translateToSharedMemory(characterBitmap, currentX, currentY); + 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++) { diff --git a/src/TextRenderer.h b/src/TextRenderer.h index 3726dfd..404165c 100644 --- a/src/TextRenderer.h +++ b/src/TextRenderer.h @@ -13,6 +13,7 @@ #include #include #include +#include #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> characterBitmap); void translateToSharedMemory(std::vector> characterBitmap, int startX, int startY); void checkWindowSize(); + void blink(); void checkFontColor();