From ecdbb30d3e39f7235878fbb37a18589f0189561c Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Tue, 7 Jan 2020 13:56:27 +0100 Subject: [PATCH] added cursor --- CMakeLists.txt | 3 ++- main/main.cpp | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bd88845..c5c769d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,13 +30,14 @@ include_directories(${LIB_PATH}/include) add_executable(TextRenderer ${SOURCES} ${HEADERS} main/main.cpp) target_link_libraries(TextRenderer ${LIB_PATH}/lib/liblibrary.a) - +target_link_libraries(TextRenderer pthread) enable_testing() find_package(Catch2 REQUIRED) add_executable(UnitTests ${SOURCES} ${HEADERS} ${TESTS}) target_link_libraries(UnitTests ${LIB_PATH}/lib/liblibrary.a) target_link_libraries(UnitTests Catch2::Catch2) +target_link_libraries(UnitTests pthread) include(CTest) include(Catch) diff --git a/main/main.cpp b/main/main.cpp index 4d324e0..a9fd2e1 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -3,6 +3,8 @@ #include "vkvm.hpp" #include +int cursorPosX = 0; +int cursorPosY = 0; /** * @author: Julian Hinxlage @@ -10,11 +12,35 @@ * @brief: An image is loaded and used as a font. */ +void threadHandler(Font &font){ + static bool showCurser{false}; + + int start = font.height() / 4; + int end = font.height() * 3 / 4 + 1; + auto bc = vkvm::getBackgroundColor(); + auto fc = vkvm::getForegroundColor(); + + while(true){ + for (int i = start; i < end; i++) { + if (showCurser) { + vkvm::setPixel(cursorPosX, cursorPosY + i, bc); + } + else { + vkvm::setPixel(cursorPosX, cursorPosY + i, fc); + } + } + vkvm::callEvent(vkvm::EventType::Redraw); + showCurser = !showCurser; + std::this_thread::sleep_for(std::chrono::milliseconds(800)); + } +} + int main() { vkvm::initialize(0); vkvm::setLogLevel(vkvm::DEBUG); Font font(std::string() + "../res/font" + std::to_string(vkvm::getFont()) + ".bmp", std::string() + "../res/font" + std::to_string(vkvm::getFont()) + ".toml"); + std::thread thread(std::bind(threadHandler, font)); vkvm::registerEvent(vkvm::EventType::RenderText, [&font]() { std::string currentText = vkvm::getText(); @@ -36,7 +62,8 @@ int main() { y++; x = 0; }else if(c == -127){ - //TODO(julian): cursor + cursorPosX = x * font.width(); + cursorPosY = y * font.height(); } else{ if(x == perRow){