only show cursor if a cursor character is rendered

This commit is contained in:
Julian Hinxlage 2020-01-07 15:59:06 +01:00
parent 9b593ce231
commit 08b9c26dd1
1 changed files with 19 additions and 10 deletions

View File

@ -6,6 +6,7 @@
int cursorPosX = 0;
int cursorPosY = 0;
bool showCursor = false;
/**
* @author: Julian Hinxlage
@ -14,24 +15,30 @@ int cursorPosY = 0;
*/
void threadHandler(Font &font){
static bool showCurser{false};
static bool cursorState{false};
int start = font.height() / 4;
int end = font.height() * 3 / 4 + 1;
int start = 0;
int end = font.height();
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);
if(showCursor) {
int x = cursorPosX - 1;
if (x < 0) {
x = 0;
}
else {
vkvm::setPixel(cursorPosX, cursorPosY + i, fc);
for (int i = start; i < end; i++) {
if (cursorState) {
vkvm::setPixel(x, cursorPosY + i, bc);
} else {
vkvm::setPixel(x, cursorPosY + i, fc);
}
}
vkvm::callEvent(vkvm::EventType::Redraw);
showCurser = !showCurser;
cursorState = !cursorState;
}
std::this_thread::sleep_for(std::chrono::milliseconds(800));
}
}
@ -56,6 +63,7 @@ int main() {
}
}
showCursor = false;
int x = 0;
int y = 0;
for(char c : currentText){
@ -65,6 +73,7 @@ int main() {
}else if(c == -127){
cursorPosX = x * font.width();
cursorPosY = y * font.height();
showCursor = true;
}
else{
if(x == perRow){