From c1d19c5d0727c25705badcbeefedb7612ff60ba2 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 23 Mar 2024 19:09:43 +1100 Subject: [PATCH] Allow separately toggling touch GUI from touch input support, mainly for DS --- src/Gui.c | 8 +++++++- src/Gui.h | 6 ++++++ src/Menus.c | 2 +- src/Screens.c | 16 ++++++++-------- src/Widgets.c | 16 ++++++++-------- src/Window_3DS.c | 2 ++ src/Window_Android.c | 2 ++ src/Window_NDS.c | 2 +- src/Window_Switch.c | 2 ++ src/Window_Web.c | 2 ++ 10 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/Gui.c b/src/Gui.c index d6287e69a..25d85bf97 100644 --- a/src/Gui.c +++ b/src/Gui.c @@ -35,7 +35,7 @@ static CC_NOINLINE int GetWindowScale(void) { /* Use larger UI scaling on mobile */ /* TODO move this DPI scaling elsewhere.,. */ #ifndef CC_BUILD_DUALSCREEN - if (!Input_TouchMode) { + if (!Gui.TouchUI) { #endif widthScale /= DisplayInfo.ScaleX; heightScale /= DisplayInfo.ScaleY; @@ -96,6 +96,12 @@ void Gui_ShowDefault(void) { #endif } +#ifdef CC_BUILD_TOUCH +void Gui_SetTouchUI(cc_bool enabled) { + Gui.TouchUI = enabled; /* TODO toggle or not */ +} +#endif + static void LoadOptions(void) { Gui.DefaultLines = Game_ClassicMode ? 10 : 12; Gui.Chatlines = Options_GetInt(OPT_CHATLINES, 0, GUI_MAX_CHATLINES, Gui.DefaultLines); diff --git a/src/Gui.h b/src/Gui.h index 089c80834..d3fd2e8f1 100644 --- a/src/Gui.h +++ b/src/Gui.h @@ -50,6 +50,8 @@ CC_VAR extern struct _GuiData { float RawTouchScale; /* The highest priority screen that has grabbed input. */ struct Screen* InputGrab; + /* Whether the touch UI is currently being displayed */ + cc_bool TouchUI; } Gui; float Gui_Scale(float value); @@ -227,6 +229,10 @@ int Gui_Contains(int recX, int recY, int width, int height, int x, int y); int Gui_ContainsPointers(int x, int y, int width, int height); /* Shows HUD and Status screens. */ void Gui_ShowDefault(void); +#ifdef CC_BUILD_TOUCH +/* Sets whether touch UI should be displayed or not */ +void Gui_SetTouchUI(cc_bool enabled); +#endif /* (internal) Removes the screen from the screens list. */ /* NOTE: This does NOT perform the usual 'screens changed' behaviour. */ diff --git a/src/Menus.c b/src/Menus.c index 8a2e1b640..8b87e7547 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -2589,7 +2589,7 @@ static void MenuOptionsScreen_Input(void* screen, void* widget) { String_InitArray(value, valueBuffer); btn->GetValue(&value); desc = &s->descs[s->activeI]; - MenuInputOverlay_Show(desc, &value, MenuOptionsScreen_OnDone, Input_TouchMode); + MenuInputOverlay_Show(desc, &value, MenuOptionsScreen_OnDone, Gui.TouchUI); } static void MenuOptionsScreen_OnHacksChanged(void* screen) { diff --git a/src/Screens.c b/src/Screens.c index 9657188e9..e1e797cf5 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -255,7 +255,7 @@ static void HUDScreen_InputUp(void* screen, int key) { static int HUDscreen_PointerDown(void* screen, int id, int x, int y) { struct HUDScreen* s = (struct HUDScreen*)screen; - if (Input_TouchMode || Gui.InputGrab) { + if (Gui.TouchUI || Gui.InputGrab) { return Elem_HandlesPointerDown(&s->hotbar, id, x, y); } return false; @@ -263,13 +263,13 @@ static int HUDscreen_PointerDown(void* screen, int id, int x, int y) { static void HUDScreen_PointerUp(void *screen, int id, int x, int y) { struct HUDScreen* s = (struct HUDScreen*)screen; - if(!Input_TouchMode) return; + if(!Gui.TouchUI) return; Elem_OnPointerUp(&s->hotbar, id, x, y); } static int HUDScreen_PointerMove(void *screen, int id, int x, int y) { struct HUDScreen* s = (struct HUDScreen*)screen; - if(!Input_TouchMode) return false; + if(!Gui.TouchUI) return false; return Elem_HandlesPointerMove(&s->hotbar, id, x, y); } @@ -1171,7 +1171,7 @@ static void ChatScreen_DrawChat(struct ChatScreen* s, double delta) { } #ifdef CC_BUILD_TOUCH - if (!Input_TouchMode) return; + if (!Gui.TouchUI) return; Gfx_3DS_SetRenderScreen(BOTTOM_SCREEN); Elem_Render(&s->more, delta); Elem_Render(&s->send, delta); @@ -1211,7 +1211,7 @@ static void ChatScreen_ContextRecreated(void* screen) { Screen_UpdateVb(s); #ifdef CC_BUILD_TOUCH - if (!Input_TouchMode) return; + if (!Gui.TouchUI) return; Gui_MakeTitleFont(&font); ButtonWidget_SetConst(&s->more, "More", &font); ButtonWidget_SetConst(&s->send, "Send", &font); @@ -1387,7 +1387,7 @@ static int ChatScreen_PointerDown(void* screen, int id, int x, int y) { if (Game_HideGui) return false; if (!s->grabsInput) { - if (!Input_TouchMode) return false; + if (!Gui.TouchUI) return false; String_InitArray(text, textBuffer); /* Should be able to click on links with touch */ @@ -1399,7 +1399,7 @@ static int ChatScreen_PointerDown(void* screen, int id, int x, int y) { } #ifdef CC_BUILD_TOUCH - if (Input_TouchMode) { + if (Gui.TouchUI) { if (Widget_Contains(&s->send, x, y)) { ChatScreen_EnterChatInput(s, false); return TOUCH_TYPE_GUI; } @@ -2467,7 +2467,7 @@ void TouchScreen_Show(void) { struct TouchScreen* s = &TouchScreen; s->VTABLE = &TouchScreen_VTABLE; - if (!Input_TouchMode) return; + if (!Gui.TouchUI) return; Gui_Add((struct Screen*)s, GUI_PRIORITY_TOUCH); } #endif \ No newline at end of file diff --git a/src/Widgets.c b/src/Widgets.c index f0329202e..99974edea 100644 --- a/src/Widgets.c +++ b/src/Widgets.c @@ -386,7 +386,7 @@ void ScrollbarWidget_Create(struct ScrollbarWidget* w, int width) { /* It's easy to accidentally touch a bit to the right of the */ /* scrollbar with your finger, so just add some padding */ - if (!Input_TouchMode) return; + if (!Gui.TouchUI) return; w->padding = Display_ScaleX(15); } @@ -417,7 +417,7 @@ static void HotbarWidget_BuildEntriesMesh(struct HotbarWidget* w, struct VertexT y = w->y + (w->height / 2); #ifdef CC_BUILD_TOUCH - if (i == HOTBAR_MAX_INDEX && Input_TouchMode) continue; + if (i == HOTBAR_MAX_INDEX && Gui.TouchUI) continue; #endif IsometricDrawer_AddBatch(Inventory_Get(i), scale, x, y); } @@ -455,7 +455,7 @@ static int HotbarWidget_Render2(void* widget, int offset) { HotbarWidget_RenderEntries(w, offset + 8); #ifdef CC_BUILD_TOUCH - if (Input_TouchMode) { + if (Gui.TouchUI) { w->ellipsisTex.x = HotbarWidget_TileX(w, HOTBAR_MAX_INDEX) - w->ellipsisTex.Width / 2; w->ellipsisTex.y = w->y + (w->height / 2) - w->ellipsisTex.Height / 2; Texture_Render(&w->ellipsisTex); @@ -471,7 +471,7 @@ static int HotbarWidget_MaxVertices(void* w) { return HOTBAR_MAX_VERTICES; } void HotbarWidget_Update(struct HotbarWidget* w, double delta) { #ifdef CC_BUILD_TOUCH int i; - if (!Input_TouchMode) return; + if (!Gui.TouchUI) return; for (i = 0; i < HOTBAR_MAX_INDEX; i++) { if(w->touchId[i] != -1) { @@ -591,7 +591,7 @@ static int HotbarWidget_PointerDown(void* widget, int id, int x, int y) { if (!Gui_Contains(cellX, cellY, width, height, x, y)) continue; #ifdef CC_BUILD_TOUCH - if(Input_TouchMode) { + if(Gui.TouchUI) { if (i == HOTBAR_MAX_INDEX) { InventoryScreen_Show(); return TOUCH_TYPE_GUI; } else { @@ -657,7 +657,7 @@ static int HotbarWidget_MouseScroll(void* widget, float delta) { static void HotbarWidget_Free(void* widget) { #ifdef CC_BUILD_TOUCH struct HotbarWidget* w = (struct HotbarWidget*)widget; - if (!Input_TouchMode) return; + if (!Gui.TouchUI) return; Gfx_DeleteTexture(&w->ellipsisTex.ID); #endif @@ -689,7 +689,7 @@ void HotbarWidget_SetFont(struct HotbarWidget* w, struct FontDesc* font) { #ifdef CC_BUILD_TOUCH static const cc_string dots = String_FromConst("..."); struct DrawTextArgs args; - if (!Input_TouchMode) return; + if (!Gui.TouchUI) return; DrawTextArgs_Make(&args, &dots, font, true); Drawer2D_MakeTextTexture(&w->ellipsisTex, &args); @@ -1685,7 +1685,7 @@ void TextInputWidget_Create(struct TextInputWidget* w, int width, const cc_strin w->base.convertPercents = false; w->base.padding = 3; - w->base.showCaret = !Input_TouchMode; + w->base.showCaret = !Gui.TouchUI; w->base.flags = WIDGET_FLAG_SELECTABLE; w->base.GetMaxLines = TextInputWidget_GetMaxLines; diff --git a/src/Window_3DS.c b/src/Window_3DS.c index ad5bb88a6..81931ea0b 100644 --- a/src/Window_3DS.c +++ b/src/Window_3DS.c @@ -10,6 +10,7 @@ #include "Bitmap.h" #include "Errors.h" #include "ExtMath.h" +#include "Gui.h" #include <3ds.h> static cc_bool launcherMode; @@ -45,6 +46,7 @@ void Window_Init(void) { Window_Main.Exists = true; Input_SetTouchMode(true); + Gui_SetTouchUI(true); Input.Sources = INPUT_SOURCE_GAMEPAD; irrst_result = irrstInit(); diff --git a/src/Window_Android.c b/src/Window_Android.c index 2d8273c4d..44e478265 100644 --- a/src/Window_Android.c +++ b/src/Window_Android.c @@ -6,6 +6,7 @@ #include "Bitmap.h" #include "Errors.h" #include "Graphics.h" +#include "Gui.h" #include #include #include @@ -282,6 +283,7 @@ void Window_Init(void) { Window_Main.SoftKeyboard = SOFT_KEYBOARD_RESIZE; Input_SetTouchMode(true); + Gui_SetTouchUI(true); Input.Sources = INPUT_SOURCE_NORMAL; DisplayInfo.Depth = 32; diff --git a/src/Window_NDS.c b/src/Window_NDS.c index c5ec52fd3..21ae6c03b 100644 --- a/src/Window_NDS.c +++ b/src/Window_NDS.c @@ -34,7 +34,7 @@ void Window_Init(void) { Window_Main.Focused = true; Window_Main.Exists = true; - //Input_SetTouchMode(true); TODO not UI + Input_SetTouchMode(true); Input.Sources = INPUT_SOURCE_GAMEPAD; consoleDemoInit(); diff --git a/src/Window_Switch.c b/src/Window_Switch.c index dc2ad940a..52e945071 100644 --- a/src/Window_Switch.c +++ b/src/Window_Switch.c @@ -12,6 +12,7 @@ #include "Errors.h" #include "ExtMath.h" #include "Input.h" +#include "Gui.h" #include static cc_bool launcherMode; @@ -66,6 +67,7 @@ void Window_Init(void) { Window_Main.Handle = nwindowGetDefault(); Input_SetTouchMode(true); + Gui_SetTouchUI(true); Input.Sources = INPUT_SOURCE_GAMEPAD; nwindowSetDimensions(Window_Main.Handle, 1920, 1080); diff --git a/src/Window_Web.c b/src/Window_Web.c index 4f4e71931..f51bbedae 100644 --- a/src/Window_Web.c +++ b/src/Window_Web.c @@ -7,6 +7,7 @@ #include "ExtMath.h" #include "Bitmap.h" #include "Errors.h" +#include "Gui.h" #include #include #include @@ -382,6 +383,7 @@ void Window_Init(void) { droid = interop_IsAndroid(); is_ios = interop_IsIOS(); Input_SetTouchMode(is_ios || droid); + Gui_SetTouchUI(is_ios || droid); /* iOS shifts the whole webpage up when opening chat, which causes problems */ /* as the chat/send butons are positioned at the top of the canvas - they */