diff --git a/main/main.cpp b/main/main.cpp index 6accb89..e698eb3 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -19,18 +19,31 @@ bool isQuit(std::string command); int main() { vkvm::initialize(0); - Font font("../res/font1.bmp", "../res/font1.toml"); - - std::string oldText; std::string currentText; - TextRenderer textRenderer(vkvm::Color(255, 255, 255), vkvm::Color(0, 0, 0)); + + + /*************************set back to shared memory(only for test)********************************************/ + vkvm::Color fontColor1(0, 0, 0); + vkvm::Color backgroudColor1(255, 255, 255); + Font font1("../res/font3.bmp", "../res/font3.toml"); + vkvm::setFont(vkvm::FontType(3, "font", font1.height(), font1.width())); + vkvm::setForegroundColor(fontColor1); + vkvm::setBackgroundColor(backgroudColor1); + /**************************get text and font from shared memory*******************************************/ + std::string fontResourcePath = "../res/font" + std::to_string(vkvm::getFont().getId()) + ".bmp"; + std::string fontConfigureFilePath = "../res/font" + std::to_string(vkvm::getFont().getId()) + ".toml"; + Font font = Font(fontResourcePath, fontConfigureFilePath); + TextRenderer textRenderer(vkvm::Color(255, 255, 255), vkvm::Color(0, 0, 0). font); + vkvm::Color fontColor = vkvm::getForegroundColor(); + vkvm::Color backgroundColor = vkvm::getBackgroundColor(); + /*********************************************************************/ std::string command; - std::cout << "TextRender: " << std::endl; std::getline(std::cin, command); while(!isQuit(command)) { if(command.compare("update")) { + vkvm::setText("Hello World."); currentText = vkvm::getText(); textRenderer.update(currentText); } diff --git a/res/font3.bmp b/res/font3.bmp deleted file mode 100644 index 609d266..0000000 Binary files a/res/font3.bmp and /dev/null differ diff --git a/src/TextRenderer.cpp b/src/TextRenderer.cpp index b3a90b1..ca0c4e0 100644 --- a/src/TextRenderer.cpp +++ b/src/TextRenderer.cpp @@ -3,14 +3,14 @@ // #include "TextRenderer.h" -TextRenderer::TextRenderer(vkvm::Color backgroundColor, vkvm::Color fontColor) - : backgroundColor(backgroundColor), fontColor(fontColor) { +TextRenderer::TextRenderer(vkvm::Color backgroundColor, vkvm::Color fontColor, Font font) + : backgroundColor(backgroundColor), fontColor(fontColor), font(font) { windowWidth = vkvm::getWidth(); fontWidth = font.width(); fontHeight = font.height(); } -void TextRenderer::update(std::string text) { +void TextRenderer::update(std::string newText) { int startX; int startY; int i; @@ -19,10 +19,6 @@ void TextRenderer::update(std::string text) { std::cout << "get window's width from shared memery: (" << windowWidth << ")" << std::endl; - std::string newText = vkvm::getText(); - - std::cout << "get text:" << newText << std::endl; - for(i = 0; i < newText.size(); i++) { if(i > oldText.size() || oldText[i] != newText[i]) { startX = i % fontNumbersInOneLine * fontWidth; @@ -32,6 +28,8 @@ void TextRenderer::update(std::string text) { translateToSharedMemory(characterBitmap, startX, startY); } } + + oldText = newText; } void TextRenderer::setOldText(std::string text) { diff --git a/src/TextRenderer.h b/src/TextRenderer.h index 8d3679b..65ced25 100644 --- a/src/TextRenderer.h +++ b/src/TextRenderer.h @@ -22,7 +22,7 @@ */ class TextRenderer { public: - TextRenderer(vkvm::Color defaultBackgroundColor, vkvm::Color fontColor); + TextRenderer(vkvm::Color defaultBackgroundColor, vkvm::Color fontColor, Font font); void update(std::string text); void setOldText(std::string text); @@ -33,7 +33,7 @@ private: vkvm::Color backgroundColor; vkvm::Color fontColor; vkvm::FontType fontType = vkvm::getFont(); - Font font = Font(fontType.getName(), "../res/font3.toml"); + Font font; int type; int windowWidth; int fontWidth;