SDL: Fix can't input text fields in the main menu

This commit is contained in:
UnknownShadow200 2024-06-23 08:05:25 +10:00
parent 09445f294c
commit 3a2c469c99
6 changed files with 11 additions and 3 deletions

View File

@ -704,7 +704,7 @@ void LBackend_InputSelect(struct LInput* w, int idx, cc_bool wasSelected) {
LInput_MoveCaretToCursor(w, idx);
LBackend_MarkDirty(w);
if (Window_Main.SoftKeyboard && Input_TouchMode)
if (Window_Main.SoftKeyboardInstant)
LInput_OpenKeyboard(w);
}

View File

@ -86,6 +86,9 @@ struct _WindowData {
cc_bool Inactive;
/* Whether input should be ignored due to soft keyboard being open */
cc_bool SoftKeyboardFocus;
/* Whether on-screen keyboard should be instantly opened when an input field is selected */
/* Otherwise, the on-screen keyboard is only opened when the input field is clicked */
cc_uint8 SoftKeyboardInstant;
/* Scale factors specifically for some in-game elements (e.g. chat) */
/* that vary their elements based on the window dimensions */
float UIScaleX, UIScaleY;

View File

@ -330,6 +330,7 @@ static void DoCreateWindow(void) {
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y;
Window_Main.SoftKeyboardInstant = true;
RemakeWindowSurface();
/* always start as fullscreen */
Window_EnterFullscreen();

View File

@ -9,7 +9,6 @@
#include <SDL2/SDL.h>
static SDL_Window* win_handle;
#warning "Some features are missing from the SDL backend. If possible, it is recommended that you use a native windowing backend instead"
#ifdef CC_BUILD_OS2
#define INCL_PM
@ -76,7 +75,7 @@ void Window_Free(void) { }
#include "../misc/sdl/CCIcon_SDL.h"
static void ApplyIcon(void) {
SDL_Surface* surface = SDL_CreateRGBSurfaceFrom(CCIcon_Data, CCIcon_Width, CCIcon_Height, 32, CCIcon_Pitch,
SDL_Surface* surface = SDL_CreateRGBSurfaceFrom((void*)CCIcon_Data, CCIcon_Width, CCIcon_Height, 32, CCIcon_Pitch,
0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
SDL_SetWindowIcon(win_handle, surface);
}
@ -94,6 +93,8 @@ static void DoCreateWindow(int width, int height, int flags) {
Window_Main.Handle = win_handle;
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y;
Window_Main.SoftKeyboardInstant = true;
ApplyIcon();
/* TODO grab using SDL_SetWindowGrab? seems to be unnecessary on Linux at least */
}

View File

@ -77,6 +77,8 @@ static void DoCreateWindow(int width, int height, int flags) {
Window_Main.Handle = win_handle;
Window_Main.UIScaleX = DEFAULT_UI_SCALE_X;
Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y;
Window_Main.SoftKeyboardInstant = true;
ApplyIcon();
/* TODO grab using SDL_SetWindowGrab? seems to be unnecessary on Linux at least */
}

View File

@ -476,6 +476,7 @@ static CGRect DoCreateWindow(void) {
Window_Main.Width = bounds.size.width;
Window_Main.Height = bounds.size.height;
Window_Main.SoftKeyboardInstant = true;
NSNotificationCenter* notifications = NSNotificationCenter.defaultCenter;
[notifications addObserver:cc_controller selector:@selector(keyboardDidShow:) name:UIKeyboardWillShowNotification object:nil];