From 3e34665941867cb3b7691a3da864923e4366a3b8 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 10 Sep 2022 14:19:24 +1000 Subject: [PATCH] Web mobile: Make text input dark instead of light, and don't render chat input behind it at all --- src/Screens.c | 1 + src/Widgets.c | 35 +++++++++++++++++++++++------------ src/Window.h | 4 ++-- src/Window_Android.c | 2 +- src/Window_Carbon.c | 2 +- src/Window_SDL.c | 2 +- src/Window_Web.c | 3 ++- src/Window_Win.c | 2 +- src/Window_X11.c | 2 +- src/_WindowBase.h | 5 +++-- src/interop_cocoa.m | 2 +- src/interop_ios.m | 2 +- src/interop_web.js | 3 ++- 13 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/Screens.c b/src/Screens.c index ee17d328c..282f10a2a 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -1376,6 +1376,7 @@ void ChatScreen_OpenInput(const cc_string* text) { OpenKeyboardArgs_Init(&args, text, KEYBOARD_TYPE_TEXT | KEYBOARD_FLAG_SEND); args.placeholder = "Enter chat"; Window_OpenKeyboard(&args); + s->input.base.disabled = args.opaque; String_Copy(&s->input.base.text, text); InputWidget_UpdateText(&s->input.base); diff --git a/src/Widgets.c b/src/Widgets.c index b5b958d41..bf3d6615c 100644 --- a/src/Widgets.c +++ b/src/Widgets.c @@ -1658,23 +1658,13 @@ void TextInputWidget_SetFont(struct TextInputWidget* w, struct FontDesc* font) { *#########################################################################################################################*/ static const cc_string chatInputPrefix = String_FromConst("> "); -static void ChatInputWidget_RemakeTexture(void* widget) { +static void ChatInputWidget_MakeTexture(struct InputWidget* w, int width, int height) { cc_string line; char lineBuffer[STRING_SIZE + 2]; - struct InputWidget* w = (struct InputWidget*)widget; struct DrawTextArgs args; - int width = 0, height = 0; struct Context2D ctx; char lastCol; int i, x, y; - for (i = 0; i < w->GetMaxLines(); i++) { - if (!w->lines[i].length) break; - height += w->lineHeight; - width = max(width, w->lineWidths[i]); - } - - if (!width) width = w->prefixWidth; - if (!height) height = w->lineHeight; Context2D_Alloc(&ctx, width, height); DrawTextArgs_Make(&args, &chatInputPrefix, w->font, true); @@ -1701,6 +1691,27 @@ static void ChatInputWidget_RemakeTexture(void* widget) { Context2D_MakeTexture(&w->inputTex, &ctx); Context2D_Free(&ctx); +} + +static void ChatInputWidget_RemakeTexture(void* widget) { + struct InputWidget* w = (struct InputWidget*)widget; + int width = 0, height = 0; + int i; + + for (i = 0; i < w->GetMaxLines(); i++) { + if (!w->lines[i].length) break; + height += w->lineHeight; + width = max(width, w->lineWidths[i]); + } + + if (!width) width = w->prefixWidth; + if (!height) height = w->lineHeight; + + if (w->disabled) { + Gfx_DeleteTexture(&w->inputTex.ID); + } else { + ChatInputWidget_MakeTexture(w, width, height); + } w->caretAccumulator = 0; w->width = width; @@ -1716,8 +1727,8 @@ static void ChatInputWidget_Render(void* widget, double delta) { int x = w->x, y = w->y; cc_bool caretAtEnd; int i, width; + if (w->disabled) return; - Gfx_SetTexturing(false); for (i = 0; i < INPUTWIDGET_MAX_LINES; i++) { if (i > 0 && !w->lines[i].length) break; diff --git a/src/Window.h b/src/Window.h index 98d57239d..fcbdf3414 100644 --- a/src/Window.h +++ b/src/Window.h @@ -144,11 +144,11 @@ void Window_DrawFramebuffer(Rect2D r); /* Frees the previously allocated framebuffer. */ void Window_FreeFramebuffer(struct Bitmap* bmp); -struct OpenKeyboardArgs { const cc_string* text; int type; const char* placeholder; }; +struct OpenKeyboardArgs { const cc_string* text; int type; const char* placeholder; cc_bool opaque; }; void OpenKeyboardArgs_Init(struct OpenKeyboardArgs* args, STRING_REF const cc_string* text, int type); /* Displays on-screen keyboard for platforms that lack physical keyboard input. */ /* NOTE: On desktop platforms, this won't do anything. */ -void Window_OpenKeyboard(const struct OpenKeyboardArgs* args); +void Window_OpenKeyboard(struct OpenKeyboardArgs* args); /* Sets the text used for keyboard input. */ /* NOTE: This is only used for mobile on-screen keyboard input with the web client, */ /* because it is backed by a HTML input, rather than true keyboard input events. */ diff --git a/src/Window_Android.c b/src/Window_Android.c index 98cb2ea61..8eed32995 100644 --- a/src/Window_Android.c +++ b/src/Window_Android.c @@ -407,7 +407,7 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) { Mem_Free(bmp->scan0); } -void Window_OpenKeyboard(const struct OpenKeyboardArgs* kArgs) { +void Window_OpenKeyboard(struct OpenKeyboardArgs* kArgs) { JNIEnv* env; jvalue args[2]; JavaGetCurrentEnv(env); diff --git a/src/Window_Carbon.c b/src/Window_Carbon.c index 5996202fb..779d4bc0e 100644 --- a/src/Window_Carbon.c +++ b/src/Window_Carbon.c @@ -646,7 +646,7 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) { CGColorSpaceRelease(colorSpace); } -void Window_OpenKeyboard(const struct OpenKeyboardArgs* args) { } +void Window_OpenKeyboard(struct OpenKeyboardArgs* args) { } void Window_SetKeyboardText(const cc_string* text) { } void Window_CloseKeyboard(void) { } diff --git a/src/Window_SDL.c b/src/Window_SDL.c index e1f0008aa..361a43428 100644 --- a/src/Window_SDL.c +++ b/src/Window_SDL.c @@ -306,7 +306,7 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) { /* TODO: Do we still need to unlock it though? */ } -void Window_OpenKeyboard(const struct OpenKeyboardArgs* args) { SDL_StartTextInput(); } +void Window_OpenKeyboard(struct OpenKeyboardArgs* args) { SDL_StartTextInput(); } void Window_SetKeyboardText(const cc_string* text) { } void Window_CloseKeyboard(void) { SDL_StopTextInput(); } diff --git a/src/Window_Web.c b/src/Window_Web.c index 7d03c301a..2abfb24ab 100644 --- a/src/Window_Web.c +++ b/src/Window_Web.c @@ -581,7 +581,7 @@ EMSCRIPTEN_KEEPALIVE void Window_OnTextChanged(const char* src) { Event_RaiseString(&InputEvents.TextChanged, &str); } -void Window_OpenKeyboard(const struct OpenKeyboardArgs* args) { +void Window_OpenKeyboard(struct OpenKeyboardArgs* args) { char str[NATIVE_STR_LEN]; keyboardOpen = true; if (!Input_TouchMode) return; @@ -589,6 +589,7 @@ void Window_OpenKeyboard(const struct OpenKeyboardArgs* args) { Platform_EncodeUtf8(str, args->text); Platform_LogConst("OPEN SESAME"); interop_OpenKeyboard(str, args->type, args->placeholder); + args->opaque = true; } void Window_SetKeyboardText(const cc_string* text) { diff --git a/src/Window_Win.c b/src/Window_Win.c index 191268b76..037111c9b 100644 --- a/src/Window_Win.c +++ b/src/Window_Win.c @@ -642,7 +642,7 @@ static void InitRawMouse(void) { rawMouseSupported = false; } -void Window_OpenKeyboard(const struct OpenKeyboardArgs* args) { } +void Window_OpenKeyboard(struct OpenKeyboardArgs* args) { } void Window_SetKeyboardText(const cc_string* text) { } void Window_CloseKeyboard(void) { } diff --git a/src/Window_X11.c b/src/Window_X11.c index 354c9eb02..c42b3e5e6 100644 --- a/src/Window_X11.c +++ b/src/Window_X11.c @@ -1085,7 +1085,7 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) { if (bmp->scan0 != fb_data) Mem_Free(fb_data); } -void Window_OpenKeyboard(const struct OpenKeyboardArgs* args) { } +void Window_OpenKeyboard(struct OpenKeyboardArgs* args) { } void Window_SetKeyboardText(const cc_string* text) { } void Window_CloseKeyboard(void) { } diff --git a/src/_WindowBase.h b/src/_WindowBase.h index 18407d9bf..f52890645 100644 --- a/src/_WindowBase.h +++ b/src/_WindowBase.h @@ -68,9 +68,10 @@ void Window_ShowDialog(const char* title, const char* msg) { } void OpenKeyboardArgs_Init(struct OpenKeyboardArgs* args, STRING_REF const cc_string* text, int type) { - args->text = text; - args->type = type; + args->text = text; + args->type = type; args->placeholder = ""; + args->opaque = false; } diff --git a/src/interop_cocoa.m b/src/interop_cocoa.m index f590937c1..90476f741 100644 --- a/src/interop_cocoa.m +++ b/src/interop_cocoa.m @@ -599,7 +599,7 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) { Mem_Free(bmp->scan0); } -void Window_OpenKeyboard(const struct OpenKeyboardArgs* args) { } +void Window_OpenKeyboard(struct OpenKeyboardArgs* args) { } void Window_SetKeyboardText(const cc_string* text) { } void Window_CloseKeyboard(void) { } diff --git a/src/interop_ios.m b/src/interop_ios.m index 714df3472..7d7e5138e 100644 --- a/src/interop_ios.m +++ b/src/interop_ios.m @@ -415,7 +415,7 @@ static void LInput_SetPlaceholder(UITextField* fld, const char* placeholder); static UITextField* text_input; static CCKBController* kb_controller; -void Window_OpenKeyboard(const struct OpenKeyboardArgs* args) { +void Window_OpenKeyboard(struct OpenKeyboardArgs* args) { if (!kb_controller) { kb_controller = [[CCKBController alloc] init]; CFBridgingRetain(kb_controller); // prevent GC TODO even needed? diff --git a/src/interop_web.js b/src/interop_web.js index c2eb91502..b3ddaad8d 100644 --- a/src/interop_web.js +++ b/src/interop_web.js @@ -794,7 +794,8 @@ mergeInto(LibraryManager.library, { } if (flags & 0x100) { elem.setAttribute('enterkeyhint', 'send'); } - elem.setAttribute('style', 'position:absolute; left:0; bottom:0; margin: 0px; width: 100%'); + //elem.setAttribute('style', 'position:absolute; left:0.5%; bottom:1%; margin: 0px; width: 99%; background-color: #080808; border: none; color: white; opacity: 0.7'); + elem.setAttribute('style', 'position:absolute; left:0; bottom:0; margin: 0px; width: 100%; background-color: #222222; border: none; color: white;'); elem.setAttribute('placeholder', UTF8ToString(placeholder)); elem.value = UTF8ToString(text);