added cursor

This commit is contained in:
Julian Hinxlage 2020-01-07 13:56:27 +01:00
parent f6b0e7abe7
commit ecdbb30d3e
2 changed files with 30 additions and 2 deletions

View File

@ -30,13 +30,14 @@ include_directories(${LIB_PATH}/include)
add_executable(TextRenderer ${SOURCES} ${HEADERS} main/main.cpp) add_executable(TextRenderer ${SOURCES} ${HEADERS} main/main.cpp)
target_link_libraries(TextRenderer ${LIB_PATH}/lib/liblibrary.a) target_link_libraries(TextRenderer ${LIB_PATH}/lib/liblibrary.a)
target_link_libraries(TextRenderer pthread)
enable_testing() enable_testing()
find_package(Catch2 REQUIRED) find_package(Catch2 REQUIRED)
add_executable(UnitTests ${SOURCES} ${HEADERS} ${TESTS}) add_executable(UnitTests ${SOURCES} ${HEADERS} ${TESTS})
target_link_libraries(UnitTests ${LIB_PATH}/lib/liblibrary.a) target_link_libraries(UnitTests ${LIB_PATH}/lib/liblibrary.a)
target_link_libraries(UnitTests Catch2::Catch2) target_link_libraries(UnitTests Catch2::Catch2)
target_link_libraries(UnitTests pthread)
include(CTest) include(CTest)
include(Catch) include(Catch)

View File

@ -3,6 +3,8 @@
#include "vkvm.hpp" #include "vkvm.hpp"
#include <thread> #include <thread>
int cursorPosX = 0;
int cursorPosY = 0;
/** /**
* @author: Julian Hinxlage * @author: Julian Hinxlage
@ -10,11 +12,35 @@
* @brief: An image is loaded and used as a font. * @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() { int main() {
vkvm::initialize(0); vkvm::initialize(0);
vkvm::setLogLevel(vkvm::DEBUG); 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"); 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]() { vkvm::registerEvent(vkvm::EventType::RenderText, [&font]() {
std::string currentText = vkvm::getText(); std::string currentText = vkvm::getText();
@ -36,7 +62,8 @@ int main() {
y++; y++;
x = 0; x = 0;
}else if(c == -127){ }else if(c == -127){
//TODO(julian): cursor cursorPosX = x * font.width();
cursorPosY = y * font.height();
} }
else{ else{
if(x == perRow){ if(x == perRow){