mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 00:56:40 -04:00
Allow separately toggling touch GUI from touch input support, mainly for DS
This commit is contained in:
parent
e86d57f4f6
commit
c1d19c5d07
@ -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);
|
||||
|
@ -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. */
|
||||
|
@ -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) {
|
||||
|
@ -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
|
@ -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;
|
||||
|
@ -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();
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "Bitmap.h"
|
||||
#include "Errors.h"
|
||||
#include "Graphics.h"
|
||||
#include "Gui.h"
|
||||
#include <android/native_window.h>
|
||||
#include <android/native_window_jni.h>
|
||||
#include <android/keycodes.h>
|
||||
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "Errors.h"
|
||||
#include "ExtMath.h"
|
||||
#include "Input.h"
|
||||
#include "Gui.h"
|
||||
#include <switch.h>
|
||||
|
||||
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);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "ExtMath.h"
|
||||
#include "Bitmap.h"
|
||||
#include "Errors.h"
|
||||
#include "Gui.h"
|
||||
#include <emscripten/emscripten.h>
|
||||
#include <emscripten/html5.h>
|
||||
#include <emscripten/key_codes.h>
|
||||
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user