mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 10:05:44 -04:00
Webclient: WIP on properly supporting touchscreen input
When touch mode is off and a touchstart event is received, switch to touch mode. When touch mode is on and a mousedown event is received, disable touch mode. Unfortunately this still has a problem where touch mode will always get disabled if you touch while the keyboard is open. (because the game does NOT prevent the default behaviour of touchstart becoming a mousedown event when the keyboard is open, so that you can still click on the caret in text input box)
This commit is contained in:
parent
58380529f9
commit
3e49f0f2a7
@ -97,6 +97,7 @@ void Event_UnregisterAll(void) {
|
|||||||
InputEvents.Up.Count = 0;
|
InputEvents.Up.Count = 0;
|
||||||
InputEvents.Wheel.Count = 0;
|
InputEvents.Wheel.Count = 0;
|
||||||
InputEvents.TextChanged.Count = 0;
|
InputEvents.TextChanged.Count = 0;
|
||||||
|
InputEvents.ModeChanged.Count = 0;
|
||||||
|
|
||||||
PointerEvents.Moved.Count = 0;
|
PointerEvents.Moved.Count = 0;
|
||||||
PointerEvents.Down.Count = 0;
|
PointerEvents.Down.Count = 0;
|
||||||
|
@ -164,6 +164,7 @@ CC_VAR extern struct _InputEventsList {
|
|||||||
struct Event_Int Up; /* Key or button is released. Arg is a member of Key enumeration */
|
struct Event_Int Up; /* Key or button is released. Arg is a member of Key enumeration */
|
||||||
struct Event_Float Wheel; /* Mouse wheel is moved/scrolled (Arg is wheel delta) */
|
struct Event_Float Wheel; /* Mouse wheel is moved/scrolled (Arg is wheel delta) */
|
||||||
struct Event_String TextChanged; /* Text in the on-screen input keyboard changed (for Mobile) */
|
struct Event_String TextChanged; /* Text in the on-screen input keyboard changed (for Mobile) */
|
||||||
|
struct Event_Void ModeChanged; /* Input_TouchMode has changed */
|
||||||
} InputEvents;
|
} InputEvents;
|
||||||
|
|
||||||
CC_VAR extern struct _PointerEventsList {
|
CC_VAR extern struct _PointerEventsList {
|
||||||
|
18
src/Gui.c
18
src/Gui.c
@ -71,12 +71,22 @@ int Gui_ContainsPointers(int x, int y, int width, int height) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CC_BUILD_TOUCH
|
||||||
|
static void UpdateTouchMenu(void) {
|
||||||
|
if (Input_TouchMode) {
|
||||||
|
TouchScreen_Show();
|
||||||
|
} else {
|
||||||
|
TouchScreen_Remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static void UpdateTouchMenu(void) { }
|
||||||
|
#endif
|
||||||
|
|
||||||
void Gui_ShowDefault(void) {
|
void Gui_ShowDefault(void) {
|
||||||
HUDScreen_Show();
|
HUDScreen_Show();
|
||||||
ChatScreen_Show();
|
ChatScreen_Show();
|
||||||
#ifdef CC_BUILD_TOUCH
|
UpdateTouchMenu();
|
||||||
TouchScreen_Show();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LoadOptions(void) {
|
static void LoadOptions(void) {
|
||||||
@ -536,6 +546,7 @@ static void OnTextChanged(void* obj, const cc_string* str) {
|
|||||||
if (s->VTABLE->HandlesTextChanged(s, str)) return;
|
if (s->VTABLE->HandlesTextChanged(s, str)) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
static void OnModeChanged(void* obj) { UpdateTouchMenu(); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void OnContextLost(void* obj) {
|
static void OnContextLost(void* obj) {
|
||||||
@ -559,6 +570,7 @@ static void OnInit(void) {
|
|||||||
|
|
||||||
#ifdef CC_BUILD_TOUCH
|
#ifdef CC_BUILD_TOUCH
|
||||||
Event_Register_(&InputEvents.TextChanged, NULL, OnTextChanged);
|
Event_Register_(&InputEvents.TextChanged, NULL, OnTextChanged);
|
||||||
|
Event_Register_(&InputEvents.ModeChanged, NULL, OnModeChanged);
|
||||||
Gui._onscreenButtons = Options_GetInt(OPT_TOUCH_BUTTONS, 0, Int32_MaxValue, 0);
|
Gui._onscreenButtons = Options_GetInt(OPT_TOUCH_BUTTONS, 0, Int32_MaxValue, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -78,10 +78,13 @@ void Input_SetTouchMode(cc_bool enabled) {
|
|||||||
ClearTouches();
|
ClearTouches();
|
||||||
Input_TouchMode = enabled;
|
Input_TouchMode = enabled;
|
||||||
Pointers_Count = enabled ? 0 : 1;
|
Pointers_Count = enabled ? 0 : 1;
|
||||||
|
Event_RaiseVoid(&InputEvents.ModeChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input_AddTouch(long id, int x, int y) {
|
void Input_AddTouch(long id, int x, int y) {
|
||||||
int i;
|
int i;
|
||||||
|
if (!Input_TouchMode) Input_SetTouchMode(true);
|
||||||
|
|
||||||
for (i = 0; i < INPUT_MAX_POINTERS; i++) {
|
for (i = 0; i < INPUT_MAX_POINTERS; i++) {
|
||||||
if (touches[i].type) continue;
|
if (touches[i].type) continue;
|
||||||
|
|
||||||
@ -232,6 +235,11 @@ void Input_SetPressed(int key) {
|
|||||||
|
|
||||||
/* don't allow multiple left mouse down events */
|
/* don't allow multiple left mouse down events */
|
||||||
if (key != KEY_LMOUSE || wasPressed) return;
|
if (key != KEY_LMOUSE || wasPressed) return;
|
||||||
|
|
||||||
|
#ifdef CC_BUILD_TOUCH
|
||||||
|
/* If touch mode, disable it since using mouse now */
|
||||||
|
if (Input_TouchMode) Input_SetTouchMode(false);
|
||||||
|
#endif
|
||||||
Pointer_SetPressed(0, true);
|
Pointer_SetPressed(0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2186,8 +2186,8 @@ static const struct ScreenVTABLE TouchScreen_VTABLE = {
|
|||||||
void TouchScreen_Show(void) {
|
void TouchScreen_Show(void) {
|
||||||
struct TouchScreen* s = &TouchScreen;
|
struct TouchScreen* s = &TouchScreen;
|
||||||
s->VTABLE = &TouchScreen_VTABLE;
|
s->VTABLE = &TouchScreen_VTABLE;
|
||||||
|
|
||||||
if (!Input_TouchMode) return;
|
|
||||||
Gui_Add((struct Screen*)s, GUI_PRIORITY_TOUCH);
|
Gui_Add((struct Screen*)s, GUI_PRIORITY_TOUCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TouchScreen_Remove(void) { Gui_Remove((struct Screen*)&TouchScreen); }
|
||||||
#endif
|
#endif
|
||||||
|
@ -32,6 +32,7 @@ void DisconnectScreen_Show(const cc_string* title, const cc_string* message);
|
|||||||
#ifdef CC_BUILD_TOUCH
|
#ifdef CC_BUILD_TOUCH
|
||||||
void TouchScreen_Refresh(void);
|
void TouchScreen_Refresh(void);
|
||||||
void TouchScreen_Show(void);
|
void TouchScreen_Show(void);
|
||||||
|
void TouchScreen_Remove(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Opens chat input for the HUD with the given initial text. */
|
/* Opens chat input for the HUD with the given initial text. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user