Move keyboard cursor by touch (#182)

This commit is contained in:
Pk11 2022-08-02 21:04:19 -05:00 committed by GitHub
parent 9b06e85d90
commit 7647d311bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,7 +67,7 @@ std::string kbdGetString(std::string label, int maxSize, std::string oldStr) {
pressed = keysDownRepeat();
key = keyboardUpdate();
swiWaitForVBlank();
} while (!((pressed & (KEY_LEFT | KEY_RIGHT | KEY_B | KEY_START)) || (key != -1)));
} while (!((pressed & (KEY_LEFT | KEY_RIGHT | KEY_B | KEY_START | KEY_TOUCH)) || (key != -1)));
switch(key) {
case NOKEY:
@ -110,6 +110,33 @@ std::string kbdGetString(std::string label, int maxSize, std::string oldStr) {
break;
}
if(pressed & KEY_TOUCH) {
touchPosition touch;
touchRead(&touch);
int px = touch.px - (256 % font->width()) / 2;
int py = touch.py - (192 % font->height()) / 2;
if(py >= font->height() && py < font->height() * 2) {
if(px < font->width() * 2) {
pressed |= KEY_LEFT;
} else if(px > 256 - font->width()) {
pressed |= KEY_RIGHT;
} else {
int pos = (px / font->width()) - 2;
while(stringPosition - scrollPosition > pos && stringPosition > 0) {
stringPosition--;
while((output[stringPosition] & 0xC0) == 0x80) // UTF-8
stringPosition--;
}
while(stringPosition - scrollPosition < pos && stringPosition < (int)output.size()) {
stringPosition++;
while((output[stringPosition] & 0xC0) == 0x80) // UTF-8
stringPosition++;
}
}
}
}
if(pressed & KEY_LEFT) {
if(stringPosition > 0) {
stringPosition--;