This commit is contained in:
yukun 2019-12-17 13:48:18 +01:00
parent f5be350c87
commit e8c2cbdfee
4 changed files with 20 additions and 5 deletions

View File

@ -40,7 +40,7 @@ int main(int argc, char *argv[]) {
renderText(textRenderer); renderText(textRenderer);
}); });
// test1(); test1();
return 0; return 0;
} }
@ -52,6 +52,7 @@ void redraw(TextRenderer textRenderer) {
void renderText(TextRenderer textRenderer) { void renderText(TextRenderer textRenderer) {
textRenderer.update(vkvm::getText()); textRenderer.update(vkvm::getText());
vkvm::callEvent(vkvm::EventType::Redraw);
} }
TextRenderer generateTextRender() { TextRenderer generateTextRender() {
@ -91,6 +92,8 @@ void test1() {
else { else {
vkvm::setText(command); vkvm::setText(command);
} }
std::cout << "TextRender: ";
std::getline(std::cin, command);
} }
std::cout << "TextRender finished." << std::endl;} std::cout << "TextRender finished." << std::endl;}

BIN
res/font3.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 933 KiB

View File

@ -31,22 +31,33 @@ void TextRenderer::update(std::string newText) {
currentX = 0; currentX = 0;
currentY = 0; currentY = 0;
int i; int i;
int space = 0;
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') {
space += (fontNumbersInOneLine - ((i + space) % fontNumbersInOneLine) - 1);
} else {
currentX = (i % fontNumbersInOneLine) * (fontWidth + left_margin); currentX = ((i + space) % fontNumbersInOneLine) * (fontWidth + left_margin);
currentY = (i / fontNumbersInOneLine) * (fontHeight + bottom_margin); currentY = ((i + space) / fontNumbersInOneLine) * (fontHeight + bottom_margin);
characterBitmap = getCharacter(newText[i], font); characterBitmap = getCharacter(newText[i], font);
// fontProcessing(characterBitmap); // fontProcessing(characterBitmap);
translateToSharedMemory(characterBitmap, currentX, currentY); translateToSharedMemory(characterBitmap, currentX, currentY);
}
} }
} }
oldTextsize = newText.size();
setOldText(newText); setOldText(newText);
} }

View File

@ -55,6 +55,7 @@ private:
int fontHeight; int fontHeight;
int currentX; int currentX;
int currentY; int currentY;
int oldTextsize;
bool isBold(); bool isBold();
bool isItalics(); bool isItalics();
bool isUnderline(); bool isUnderline();