diff --git a/main/main.cpp b/main/main.cpp index b5a177b..b218977 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -40,7 +40,7 @@ int main(int argc, char *argv[]) { renderText(textRenderer); }); -// test1(); + test1(); return 0; } @@ -52,6 +52,7 @@ void redraw(TextRenderer textRenderer) { void renderText(TextRenderer textRenderer) { textRenderer.update(vkvm::getText()); + vkvm::callEvent(vkvm::EventType::Redraw); } TextRenderer generateTextRender() { @@ -91,6 +92,8 @@ void test1() { else { vkvm::setText(command); } + std::cout << "TextRender: "; + std::getline(std::cin, command); } std::cout << "TextRender finished." << std::endl;} diff --git a/res/font3.bmp b/res/font3.bmp new file mode 100644 index 0000000..c7eb8ec Binary files /dev/null and b/res/font3.bmp differ diff --git a/src/TextRenderer.cpp b/src/TextRenderer.cpp index 74d0f73..c9e5852 100644 --- a/src/TextRenderer.cpp +++ b/src/TextRenderer.cpp @@ -31,22 +31,33 @@ void TextRenderer::update(std::string newText) { currentX = 0; currentY = 0; int i; + int space = 0; 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); + } else { - currentX = (i % fontNumbersInOneLine) * (fontWidth + left_margin); - currentY = (i / fontNumbersInOneLine) * (fontHeight + bottom_margin); + currentX = ((i + space) % fontNumbersInOneLine) * (fontWidth + left_margin); + currentY = ((i + space) / fontNumbersInOneLine) * (fontHeight + bottom_margin); - characterBitmap = getCharacter(newText[i], font); + characterBitmap = getCharacter(newText[i], font); // fontProcessing(characterBitmap); - translateToSharedMemory(characterBitmap, currentX, currentY); + translateToSharedMemory(characterBitmap, currentX, currentY); + } + } } + oldTextsize = newText.size(); setOldText(newText); } diff --git a/src/TextRenderer.h b/src/TextRenderer.h index 2f428ea..3726dfd 100644 --- a/src/TextRenderer.h +++ b/src/TextRenderer.h @@ -55,6 +55,7 @@ private: int fontHeight; int currentX; int currentY; + int oldTextsize; bool isBold(); bool isItalics(); bool isUnderline();