From efe8c624932f54618ca77c8e040d32466ada6677 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Wed, 4 Dec 2019 10:18:13 +0100 Subject: [PATCH] ~ use values from shared mem instead of hardcoded ones ~ update ci to latest version --- .ci/clang-tidy.sh | 2 +- .clang-tidy | 2 +- .gitlab-ci.yml | 10 ++++++- main/main.cpp | 56 ++++++++--------------------------- src/TextRenderer.cpp | 70 ++++++++++++++------------------------------ src/TextRenderer.h | 16 ++-------- 6 files changed, 48 insertions(+), 108 deletions(-) diff --git a/.ci/clang-tidy.sh b/.ci/clang-tidy.sh index 720a8fb..71994b5 100644 --- a/.ci/clang-tidy.sh +++ b/.ci/clang-tidy.sh @@ -5,7 +5,7 @@ bool=false # explicitly set IFS to contain only a line feed IFS=' ' -filelist="$(find . -not \( -path './*build*' -prune \) -type f ! -name "$(printf "*\n*")")" +filelist="$(find . -not \( -path './*build*' -prune \) -not \( -path './include' -prune \) -type f ! -name "$(printf "*\n*")")" for file in $filelist; do if echo "$file" | grep -q -E ".*(\.cpp|\.hpp)$" ; then #Extra check missing dependencies due to clang-tidy doesn't toggle exit code. diff --git a/.clang-tidy b/.clang-tidy index d7cc14e..6e8db98 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,2 +1,2 @@ -Checks: '*,-llvm-header-guard,-fuchsia*,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init,-google-readability-namespace-comments,-llvm-namespace-comment,-cppcoreguidelines-pro-type-vararg,-hicpp-vararg,-modernize-use-trailing-return-type,-clang-diagnostic-error' +Checks: '*,-llvm-header-guard,-fuchsia*,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-bounds-constant-array-index,-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-hicpp-signed-bitwise,-bugprone-exception-escape,-cppcoreguidelines-pro-type-member-init,-cppcoreguidelines-pro-type-cstyle-cast,-hicpp-member-init,-google-readability-namespace-comments,-llvm-namespace-comment,-cppcoreguidelines-pro-type-vararg,-hicpp-vararg,-modernize-use-trailing-return-type,-readability-magic-numbers,-cppcoreguidelines-avoid-magic-numbers' WarningsAsErrors: 'true' diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 522f05f..f5f6d89 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,7 +14,15 @@ clang_tidy: tags: - docker-ci script: - - sh .ci/clang-tidy.sh; + - mkdir current + - ls -d .[!.]* | grep -v current | xargs mv -t current + - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.repo.digitech.hs-emden-leer.de/link/projekte/ws19/vkvm-new/library.git + - mkdir library/build + - cd library/build + - cmake .. + - make + - cd ../../current/.ci + - sh clang-tidy.sh make_test: stage: test diff --git a/main/main.cpp b/main/main.cpp index cd16cca..7d25eeb 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -20,52 +20,34 @@ int main() { std::string currentText; - - /*************************set back to shared memory(only for test)********************************************/ - int windowWidth = vkvm::getWidth(); - int windowHeight = vkvm::getHeight(); - vkvm::setWidth(windowWidth); - vkvm::setHeight(windowHeight); - - 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); - vkvm::Color fontColor = vkvm::getForegroundColor(); - vkvm::Color backgroundColor = vkvm::getBackgroundColor(); - TextRenderer textRenderer(windowWidth, windowHeight, backgroundColor, fontColor, font); + + TextRenderer textRenderer = TextRenderer(); textRenderer.setLeftMargin(1); textRenderer.setBottomMargin(1); /*************************get Text and update back to shared meomory********************************************/ - vkvm::registerEvent(vkvm::EventType::RenderText, [&textRenderer](){ + vkvm::registerEvent(vkvm::EventType::RenderText, [&textRenderer]() { std::string currentText = vkvm::getText(); textRenderer.update(currentText); vkvm::callEvent(vkvm::EventType::Redraw); }); - std::string command; std::cout << "TextRender: "; std::getline(std::cin, command); - while(!isQuit(command)) { - if(command.compare("clear")) { - vkvm::setText(command); - currentText = vkvm::getText(); - textRenderer.update(currentText); - outPutPixel(windowHeight, windowWidth, fontColor); - std::cout << "TextRender: "; - std::getline(std::cin, command); - } else { + while (!isQuit(command)) { + if (command == "clear") { textRenderer.clear(); } + + vkvm::setText(command); + currentText = vkvm::getText(); + textRenderer.update(currentText); + std::cout << "TextRender: "; + std::getline(std::cin, command); + } @@ -74,20 +56,6 @@ int main() { return 0; } -/***************************read pixel in shared memory and test output in console******************************************/ -void outPutPixel(int windowHeight, int windowWidth, vkvm::Color fontColor) { - for(int y = 0; y < windowHeight; y++) { - for(int x = 0; x < windowWidth; x++) { - if(vkvm::getPixel(x, y).getRed() == fontColor.getRed()) { - std::cout << "*"; - } else { - std::cout << " "; - } - } - std::cout << "\n"; - } -} - // std::string str; // std::cout << "string to draw: "; diff --git a/src/TextRenderer.cpp b/src/TextRenderer.cpp index c827131..28e6296 100644 --- a/src/TextRenderer.cpp +++ b/src/TextRenderer.cpp @@ -3,26 +3,25 @@ // #include "TextRenderer.h" -TextRenderer::TextRenderer(int windowWidth, int windowHeight, vkvm::Color backgroundColor, vkvm::Color fontColor, Font font) - : backgroundColor(backgroundColor), fontColor(fontColor), font(font) { - this-> windowWidth = windowWidth; - this-> windowHeight = windowHeight; - fontWidth = font.width(); - fontHeight = font.height(); -} + +TextRenderer::TextRenderer() {} + void TextRenderer::update(std::string newText) { int startX = 0; int startY = 0; int i; - int fontNumbersInOneLine = windowWidth / (fontWidth + left_margin); + 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(fontResourcePath, fontConfigureFilePath); + int fontNumbersInOneLine = vkvm::getWidth() / (vkvm::getFont().getWidth() + left_margin); std::vector> characterBitmap; for(i = 0; i < newText.size(); i++) { if(i > oldText.size() || oldText[i] != newText[i]) { - startX = (i % fontNumbersInOneLine) * (fontWidth + left_margin); - startY = (i / fontNumbersInOneLine) * (fontHeight + bottom_margin); - characterBitmap = getCharacter(newText[i], font); + startX = (i % fontNumbersInOneLine) * (font.width() + left_margin); + startY = (i / fontNumbersInOneLine) * (font.height() + bottom_margin); + characterBitmap = getCharacter(newText[i]); // fontProcessing(characterBitmap); translateToSharedMemory(characterBitmap, startX, startY); } @@ -33,9 +32,9 @@ void TextRenderer::update(std::string newText) { void TextRenderer::clear() { int x, y; - for(y = 0; y < windowHeight; y++) { - for(x = 0; x < windowWidth; x++) { - vkvm::setPixel(x, y, backgroundColor); + for(y = 0; y < vkvm::getHeight(); y++) { + for(x = 0; x < vkvm::getWidth(); x++) { + vkvm::setPixel(x, y, vkvm::getBackgroundColor()); } } } @@ -44,7 +43,7 @@ void TextRenderer::setOldText(std::string text) { oldText = text; } -std::vector> TextRenderer::getCharacter(unsigned char character, Font font) { +std::vector> TextRenderer::getCharacter(unsigned char character) { int fontHeight = font.height(); int fontWidth = font.width(); std::vector> bitmap_character; @@ -62,43 +61,18 @@ std::vector> TextRenderer::getCharacter(unsigned char characte return bitmap_character; } -void TextRenderer::fontProcessing(std::vector> characterBitmap) { -// if(isBold()) { - for (int i = fontHeight - 1; i >= 0; i--) { - for (int j = fontWidth - 1; j >= 0; j--) { - if (i != fontHeight - 1 && j != fontWidth - 1 && characterBitmap[i][j]) { - characterBitmap[i + 1][j] = true; - characterBitmap[i][j + 1] = true; - } - } - } -// } -// if(isUnderline()) { -// for (int j = 0; j < fontWidth; j++) -// characterBitmap[fontHeight - 1][j] = true; -// } -} - -bool TextRenderer::isBold() { - return type & BOLD != 0; -} - -bool TextRenderer::isUnderline() { - return type & UNDERLINE != 0; -} - void TextRenderer::translateToSharedMemory(std::vector> characterBitmap, int startX, int startY) { int x, y; int currentX = startX; int currentY = startY; - for(y = 0; y < fontHeight; y++) { - for(x = 0; x < fontWidth; x++) { + for(y = 0; y < font.height(); y++) { + for(x = 0; x < font.width(); x++) { if(characterBitmap[y][x]) { - vkvm::setPixel(currentX, currentY, fontColor); + vkvm::setPixel(currentX, currentY, vkvm::getForegroundColor()); } else { - vkvm::setPixel(currentX, currentY, backgroundColor); + vkvm::setPixel(currentX, currentY, vkvm::getBackgroundColor()); } currentX++; } @@ -107,14 +81,14 @@ void TextRenderer::translateToSharedMemory(std::vector> charac } for(x = 0; x < left_margin; x++) { - for(y = 0; y < fontHeight; y++) { - vkvm::setPixel(startX + fontWidth + x, startY + y, backgroundColor); + for(y = 0; y < font.height(); y++) { + vkvm::setPixel(startX + font.width() + x, startY + y, vkvm::getBackgroundColor()); } } for(y = 0; y < bottom_margin; y++) { - for(x = 0; x < fontWidth + left_margin; x++) { - vkvm::setPixel(startX + x, startY + fontHeight + y, backgroundColor); + for(x = 0; x < font.width() + left_margin; x++) { + vkvm::setPixel(startX + x, startY + font.height() + y, vkvm::getBackgroundColor()); } } } diff --git a/src/TextRenderer.h b/src/TextRenderer.h index 1195563..b362c76 100644 --- a/src/TextRenderer.h +++ b/src/TextRenderer.h @@ -22,31 +22,21 @@ */ class TextRenderer { public: - TextRenderer(int windowWidth, int windowHeight, vkvm::Color defaultBackgroundColor, vkvm::Color fontColor, Font font); + TextRenderer(); void update(std::string text); void setOldText(std::string text); - std::vector> getCharacter(unsigned char character, Font font); + std::vector> getCharacter(unsigned char character); void setLeftMargin(int margin); void setBottomMargin(int margin); void clear(); private: std::string oldText; - vkvm::Color backgroundColor; - vkvm::Color fontColor; - Font font; int left_margin = 1; int bottom_margin = 1; int type; - int windowWidth; - int windowHeight; - int fontWidth; - int fontHeight; - bool isBold(); - bool isItalics(); - bool isUnderline(); - void fontProcessing(std::vector> characterBitmap); + Font font; void translateToSharedMemory(std::vector> characterBitmap, int startX, int startY); };