Virtual keyboard: X for backspace, Y for space

This commit is contained in:
UnknownShadow200 2024-05-02 21:03:39 +10:00
parent 82529852f4
commit 7af80a9223
6 changed files with 37 additions and 33 deletions

View File

@ -291,6 +291,15 @@ void Input_Clear(void) {
ClearTouches(); ClearTouches();
} }
int Input_CalcDelta(int key, int horDelta, int verDelta) {
if (Input_IsLeftButton(key) || key == CCKEY_KP4) return -horDelta;
if (Input_IsRightButton(key) || key == CCKEY_KP6) return +horDelta;
if (Input_IsUpButton(key) || key == CCKEY_KP8) return -verDelta;
if (Input_IsDownButton(key) || key == CCKEY_KP2) return +verDelta;
return 0;
}
/*########################################################################################################################* /*########################################################################################################################*
*----------------------------------------------------------Mouse----------------------------------------------------------* *----------------------------------------------------------Mouse----------------------------------------------------------*

View File

@ -106,6 +106,7 @@ void Input_Clear(void);
#else #else
#define Input_IsActionPressed() Input_IsCtrlPressed() #define Input_IsActionPressed() Input_IsCtrlPressed()
#endif #endif
int Input_CalcDelta(int btn, int horDelta, int verDelta);
#ifdef CC_BUILD_TOUCH #ifdef CC_BUILD_TOUCH

View File

@ -380,14 +380,9 @@ static void ColoursScreen_MouseWheel(struct LScreen* s_, float delta) {
} }
static void ColoursScreen_KeyDown(struct LScreen* s, int key, cc_bool was) { static void ColoursScreen_KeyDown(struct LScreen* s, int key, cc_bool was) {
if (Input_IsLeftButton(key)) { int delta = Input_CalcDelta(key, 1, 10);
ColoursScreen_AdjustSelected(s, -1); if (delta) {
} else if (Input_IsRightButton(key)) { ColoursScreen_AdjustSelected(s, delta);
ColoursScreen_AdjustSelected(s, +1);
} else if (Input_IsUpButton(key)) {
ColoursScreen_AdjustSelected(s, +10);
} else if (Input_IsDownButton(key)) {
ColoursScreen_AdjustSelected(s, -10);
} else { } else {
LScreen_KeyDown(s, key, was); LScreen_KeyDown(s, key, was);
} }

View File

@ -154,6 +154,12 @@ static void VirtualKeyboard_AppendChar(char c) {
if (kb_shift) { VirtualKeyboard_ToggleTable(); kb_shift = false; } if (kb_shift) { VirtualKeyboard_ToggleTable(); kb_shift = false; }
} }
static void VirtualKeyboard_Backspace(void) {
if (kb_str.length) kb_str.length--;
Event_RaiseString(&InputEvents.TextChanged, &kb_str);
KB_MarkDirty();
}
static void VirtualKeyboard_ClickSelected(void) { static void VirtualKeyboard_ClickSelected(void) {
int selected = VirtualKeyboard_GetSelected(); int selected = VirtualKeyboard_GetSelected();
if (selected < 0) return; if (selected < 0) return;
@ -161,9 +167,7 @@ static void VirtualKeyboard_ClickSelected(void) {
/* TODO kinda hacky, redo this */ /* TODO kinda hacky, redo this */
switch (selected) { switch (selected) {
case KB_INDEX(KB_LAST_CELL, 0): case KB_INDEX(KB_LAST_CELL, 0):
if (kb_str.length) kb_str.length--; VirtualKeyboard_Backspace();
Event_RaiseString(&InputEvents.TextChanged, &kb_str);
KB_MarkDirty();
break; break;
case KB_INDEX(KB_LAST_CELL, 2): case KB_INDEX(KB_LAST_CELL, 2):
OnscreenKeyboard_Close(); OnscreenKeyboard_Close();
@ -192,20 +196,20 @@ static void VirtualKeyboard_ClickSelected(void) {
} }
static void VirtualKeyboard_ProcessDown(void* obj, int key, cc_bool was) { static void VirtualKeyboard_ProcessDown(void* obj, int key, cc_bool was) {
if (Input_IsLeftButton(key)) { int delta = Input_CalcDelta(key, 1, KB_CELLS_PER_ROW);
VirtualKeyboard_Scroll(-1); if (delta) {
} else if (Input_IsRightButton(key)) { VirtualKeyboard_Scroll(delta);
VirtualKeyboard_Scroll(+1); } else if (key == CCPAD_START || key == CCPAD_A) {
} else if (Input_IsUpButton(key)) {
VirtualKeyboard_Scroll(-KB_CELLS_PER_ROW);
} else if (Input_IsDownButton(key)) {
VirtualKeyboard_Scroll(+KB_CELLS_PER_ROW);
} else if (Input_IsEnterButton(key) || key == CCPAD_A) {
VirtualKeyboard_ClickSelected(); VirtualKeyboard_ClickSelected();
} else if (Input_IsEscapeButton(key) || key == CCPAD_B) { } else if (key == CCPAD_SELECT || key == CCPAD_B) {
VirtualKeyboard_Close(); VirtualKeyboard_Close();
} else if (key == CCPAD_X) {
VirtualKeyboard_Backspace();
} else if (key == CCPAD_Y) {
VirtualKeyboard_AppendChar(' ');
} }
} }
}
static void VirtualKeyboard_PadAxis(void* obj, int port, int axis, float x, float y) { static void VirtualKeyboard_PadAxis(void* obj, int port, int axis, float x, float y) {
int xSteps, ySteps; int xSteps, ySteps;

View File

@ -975,20 +975,15 @@ static int TableWidget_PointerMove(void* widget, int id, int x, int y) {
static int TableWidget_KeyDown(void* widget, int key) { static int TableWidget_KeyDown(void* widget, int key) {
struct TableWidget* w = (struct TableWidget*)widget; struct TableWidget* w = (struct TableWidget*)widget;
int delta;
if (w->selectedIndex == -1) return false; if (w->selectedIndex == -1) return false;
if (Input_IsLeftButton(key) || key == CCKEY_KP4) { delta = Input_CalcDelta(key, 1, w->blocksPerRow);
TableWidget_ScrollRelative(w, -1); if (delta) {
} else if (Input_IsRightButton(key) || key == CCKEY_KP6) { TableWidget_ScrollRelative(w, delta);
TableWidget_ScrollRelative(w, 1); return true;
} else if (Input_IsUpButton(key) || key == CCKEY_KP8) {
TableWidget_ScrollRelative(w, -w->blocksPerRow);
} else if (Input_IsDownButton(key) || key == CCKEY_KP2) {
TableWidget_ScrollRelative(w, w->blocksPerRow);
} else {
return false;
} }
return true; return false;
} }
static int TableWidget_PadAxis(void* widget, int axis, float x, float y) { static int TableWidget_PadAxis(void* widget, int axis, float x, float y) {

View File

@ -53,7 +53,7 @@ static cc_bool is_ansiWindow, grabCursor;
static int windowX, windowY; static int windowX, windowY;
static const cc_uint8 key_map[14 * 16] = { static const cc_uint8 key_map[14 * 16] = {
0, 0, 0, 0, 0, 0, 0, 0, CCKEY_BACKSPACE, CCKEY_TAB, 0, 0, 0, CCKEY_ENTER, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CCKEY_BACKSPACE, CCKEY_TAB, 0, 0, CCKEY_F5, CCKEY_ENTER, 0, 0,
0, 0, 0, CCKEY_PAUSE, CCKEY_CAPSLOCK, 0, 0, 0, 0, 0, 0, CCKEY_ESCAPE, 0, 0, 0, 0, 0, 0, 0, CCKEY_PAUSE, CCKEY_CAPSLOCK, 0, 0, 0, 0, 0, 0, CCKEY_ESCAPE, 0, 0, 0, 0,
CCKEY_SPACE, CCKEY_PAGEUP, CCKEY_PAGEDOWN, CCKEY_END, CCKEY_HOME, CCKEY_LEFT, CCKEY_UP, CCKEY_RIGHT, CCKEY_DOWN, 0, CCKEY_PRINTSCREEN, 0, CCKEY_PRINTSCREEN, CCKEY_INSERT, CCKEY_DELETE, 0, CCKEY_SPACE, CCKEY_PAGEUP, CCKEY_PAGEDOWN, CCKEY_END, CCKEY_HOME, CCKEY_LEFT, CCKEY_UP, CCKEY_RIGHT, CCKEY_DOWN, 0, CCKEY_PRINTSCREEN, 0, CCKEY_PRINTSCREEN, CCKEY_INSERT, CCKEY_DELETE, 0,
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 0, 0, 0, 0, 0, 0, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 0, 0, 0, 0, 0, 0,