diff --git a/src/LWidgets.c b/src/LWidgets.c index ac8414dfc..974db27f6 100644 --- a/src/LWidgets.c +++ b/src/LWidgets.c @@ -420,12 +420,15 @@ static void LInput_MoveCaretToCursor(struct LInput* w, int idx) { static void LInput_Select(void* widget, int idx, cc_bool wasSelected) { struct LInput* w = (struct LInput*)widget; + struct OpenKeyboardArgs args; caretStart = DateTime_CurrentUTC_MS(); LInput_MoveCaretToCursor(w, idx); /* TODO: Only draw outer border */ if (wasSelected) return; + LWidget_Draw(widget); - Window_OpenKeyboard(&w->text, w->type); + OpenKeyboardArgs_Init(&args, &w->text, w->type); + Window_OpenKeyboard(&args); } static void LInput_Unselect(void* widget, int idx) { diff --git a/src/Menus.c b/src/Menus.c index 33cb8efb3..37700e290 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -950,6 +950,7 @@ static void EditHotkeyScreen_Layout(void* screen) { static void EditHotkeyScreen_Init(void* screen) { struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen; + struct OpenKeyboardArgs args; struct MenuInputDesc desc; cc_string text; @@ -971,7 +972,8 @@ static void EditHotkeyScreen_Init(void* screen) { TextInputWidget_Create(&s->input, 500, &text, &desc); Menu_InitBack(&s->cancel, Menu_SwitchHotkeys); - Window_OpenKeyboard(&text, KEYBOARD_TYPE_TEXT); + OpenKeyboardArgs_Init(&args, &text, KEYBOARD_TYPE_TEXT); + Window_OpenKeyboard(&args); } static const struct ScreenVTABLE EditHotkeyScreen_VTABLE = { @@ -1161,6 +1163,7 @@ static void GenLevelScreen_Layout(void* screen) { static void GenLevelScreen_Init(void* screen) { struct GenLevelScreen* s = (struct GenLevelScreen*)screen; + struct OpenKeyboardArgs args; s->widgets = gen_widgets; s->numWidgets = Array_Elems(gen_widgets); s->selected = NULL; @@ -1175,7 +1178,8 @@ static void GenLevelScreen_Init(void* screen) { ButtonWidget_Init(&s->flatgrass, 200, GenLevelScreen_Flatgrass); ButtonWidget_Init(&s->vanilla, 200, GenLevelScreen_Notchy); Menu_InitBack(&s->cancel, Menu_SwitchPause); - Window_OpenKeyboard(&String_Empty, KEYBOARD_TYPE_NUMBER); + OpenKeyboardArgs_Init(&args, &String_Empty, KEYBOARD_TYPE_NUMBER); + Window_OpenKeyboard(&args); } static const struct ScreenVTABLE GenLevelScreen_VTABLE = { @@ -1511,6 +1515,7 @@ static void SaveLevelScreen_Layout(void* screen) { static void SaveLevelScreen_Init(void* screen) { struct SaveLevelScreen* s = (struct SaveLevelScreen*)screen; + struct OpenKeyboardArgs args; struct MenuInputDesc desc; s->widgets = save_widgets; @@ -1530,7 +1535,8 @@ static void SaveLevelScreen_Init(void* screen) { Menu_InitBack(&s->cancel, Menu_SwitchPause); TextInputWidget_Create(&s->input, 500, &String_Empty, &desc); TextWidget_Init(&s->desc); - Window_OpenKeyboard(&String_Empty, KEYBOARD_TYPE_TEXT); + OpenKeyboardArgs_Init(&args, &String_Empty, KEYBOARD_TYPE_TEXT); + Window_OpenKeyboard(&args); } static const struct ScreenVTABLE SaveLevelScreen_VTABLE = { @@ -2133,6 +2139,7 @@ static void MenuInputOverlay_Default(void* screen, void* widget) { static void MenuInputOverlay_Init(void* screen) { struct MenuInputOverlay* s = (struct MenuInputOverlay*)screen; + struct OpenKeyboardArgs args; s->widgets = menuInput_widgets; s->numWidgets = Array_Elems(menuInput_widgets); s->maxVertices = MENUINPUT_MAX_VERTICES; @@ -2141,9 +2148,10 @@ static void MenuInputOverlay_Init(void* screen) { ButtonWidget_Init(&s->Default, 200, MenuInputOverlay_Default); ButtonWidget_Init(&s->ok, Input_TouchMode ? 200 : 40, MenuInputOverlay_OK); - Window_OpenKeyboard(&s->value, + OpenKeyboardArgs_Init(&args, &s->value, (s->desc->VTABLE == &IntInput_VTABLE || s->desc->VTABLE == &FloatInput_VTABLE) ? KEYBOARD_TYPE_NUMBER : KEYBOARD_TYPE_TEXT); + Window_OpenKeyboard(&args); } static void MenuInputOverlay_Update(void* screen, double delta) { diff --git a/src/Platform.c b/src/Platform.c index 19e759215..479045108 100644 --- a/src/Platform.c +++ b/src/Platform.c @@ -414,7 +414,7 @@ static cc_result DoFile(cc_file* file, const cc_string* path, DWORD access, DWOR if (*file && *file != INVALID_HANDLE_VALUE) return 0; if ((res = GetLastError()) != ERROR_CALL_NOT_IMPLEMENTED) return res; - /* Windows 98 does not support W API functions */ + /* Windows 9x does not support W API functions */ Platform_EncodeAnsi(str, path); *file = CreateFileA((LPCSTR)str, access, FILE_SHARE_READ, NULL, createMode, 0, NULL); return *file != INVALID_HANDLE_VALUE ? 0 : GetLastError(); @@ -918,6 +918,8 @@ cc_result Socket_Connect(cc_socket s, const cc_string* ip, int port) { Stream_SetU16_BE( (cc_uint8*)&addr.sa_data[0], port); Utils_ParseIP(ip, (cc_uint8*)&addr.sa_data[2]); + WSAStringToAddress() + res = connect(s, &addr, sizeof(addr)); return res == -1 ? Socket__Error() : 0; } diff --git a/src/Platform.h b/src/Platform.h index 15cdfac5e..be5a9e35c 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -100,9 +100,9 @@ CC_API cc_bool DynamicLib_DescribeError(cc_string* dst); extern const cc_string DynamicLib_Ext; CC_API cc_result DynamicLib_Load(const cc_string* path, void** lib); /* OBSOLETE */ CC_API cc_result DynamicLib_Get(void* lib, const char* name, void** symbol); /* OBSOLETE */ -/* Represents a name, and a pointer to variable that will hold the loaded symbol */ -/* static int (APIENTRY *_myGetError)(void); --- (for example) */ -/* static struct DynamicLibSym sym = { "myGetError", (void**)&_myGetError }; */ +/* Contains a name and a pointer to variable that will hold the loaded symbol */ +/* static int (APIENTRY *_myGetError)(void); --- (for example) */ +/* static struct DynamicLibSym sym = { "myGetError", (void**)&_myGetError }; */ struct DynamicLibSym { const char* name; void** symAddr; }; /* Loads all symbols using DynamicLib_Get2 in the given list */ /* Returns true if all symbols were successfully retrieved */ diff --git a/src/Screens.c b/src/Screens.c index 8a99bfa1d..d40554939 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -1307,10 +1307,13 @@ void ChatScreen_Show(void) { void ChatScreen_OpenInput(const cc_string* text) { struct ChatScreen* s = &ChatScreen_Instance; + struct OpenKeyboardArgs args; s->suppressNextPress = true; s->grabsInput = true; + Gui_UpdateInputGrab(); - Window_OpenKeyboard(text, KEYBOARD_TYPE_TEXT); + OpenKeyboardArgs_Init(&args, text, KEYBOARD_TYPE_TEXT); + Window_OpenKeyboard(&args); String_Copy(&s->input.base.text, text); InputWidget_UpdateText(&s->input.base); diff --git a/src/Window.c b/src/Window.c index 8d0126a90..79c6e81fd 100644 --- a/src/Window.c +++ b/src/Window.c @@ -81,6 +81,12 @@ void Window_ShowDialog(const char* title, const char* msg) { if (!visible) Cursor_SetVisible(false); } +void OpenKeyboardArgs_Init(struct OpenKeyboardArgs* args, STRING_REF const cc_string* text, int type) { + args->text = text; + args->type = type; + args->placeholder = ""; +} + struct GraphicsMode { int R, G, B, A, IsIndexed; }; /* Creates a GraphicsMode compatible with the default display device */ @@ -402,7 +408,7 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) { /* TODO: Do we still need to unlock it though? */ } -void Window_OpenKeyboard(const cc_string* text, int type) { SDL_StartTextInput(); } +void Window_OpenKeyboard(const struct OpenKeyboardArgs* args) { SDL_StartTextInput(); } void Window_SetKeyboardText(const cc_string* text) { } void Window_CloseKeyboard(void) { SDL_StopTextInput(); } @@ -698,7 +704,7 @@ static ATOM DoRegisterClass(void) { wc.hCursor = LoadCursor(NULL, IDC_ARROW); if ((atom = RegisterClassExW(&wc))) return atom; - /* Windows 98 does not support W API functions */ + /* Windows 9x does not support W API functions */ return RegisterClassExA((const WNDCLASSEXA*)&wc); } @@ -714,7 +720,7 @@ static void DoCreateWindow(ATOM atom, int width, int height) { r.left, r.top, Rect_Width(r), Rect_Height(r), NULL, NULL, win_instance, NULL))) return; res = GetLastError(); - /* Windows 98 does not support W API functions */ + /* Windows 9x does not support W API functions */ if (res == ERROR_CALL_NOT_IMPLEMENTED) { is_ansiWindow = true; if ((win_handle = CreateWindowExA(0, MAKEINTATOM(atom), NULL, CC_WIN_STYLE, @@ -922,6 +928,7 @@ void Window_AllocFramebuffer(struct Bitmap* bmp) { BITMAPINFO hdr = { 0 }; if (!draw_DC) draw_DC = CreateCompatibleDC(win_DC); + /* sizeof(BITMAPINFO) does not work on Windows 9x */ hdr.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); hdr.bmiHeader.biWidth = bmp->width; hdr.bmiHeader.biHeight = -bmp->height; @@ -965,7 +972,7 @@ static void InitRawMouse(void) { rawMouseSupported = false; } -void Window_OpenKeyboard(const cc_string* text, int type) { } +void Window_OpenKeyboard(const struct OpenKeyboardArgs* args) { } void Window_SetKeyboardText(const cc_string* text) { } void Window_CloseKeyboard(void) { } @@ -1933,7 +1940,7 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) { Mem_Free(bmp->scan0); } -void Window_OpenKeyboard(const cc_string* text, int type) { } +void Window_OpenKeyboard(const struct OpenKeyboardArgs* args) { } void Window_SetKeyboardText(const cc_string* text) { } void Window_CloseKeyboard(void) { } @@ -2179,7 +2186,7 @@ static void Cursor_DoSetVisible(cc_bool visible) { } } -void Window_OpenKeyboard(const cc_string* text, int type) { } +void Window_OpenKeyboard(const struct OpenKeyboardArgs* args) { } void Window_SetKeyboardText(const cc_string* text) { } void Window_CloseKeyboard(void) { } @@ -3798,11 +3805,11 @@ EMSCRIPTEN_KEEPALIVE void Window_OnTextChanged(const char* src) { Event_RaiseString(&InputEvents.TextChanged, &str); } -void Window_OpenKeyboard(const cc_string* text, int type) { +void Window_OpenKeyboard(const struct OpenKeyboardArgs* args) { char str[NATIVE_STR_LEN]; keyboardOpen = true; if (!Input_TouchMode) return; - Platform_EncodeUtf8(str, text); + Platform_EncodeUtf8(str, args->text); Platform_LogConst("OPEN SESAME"); EM_ASM_({ @@ -3831,7 +3838,7 @@ void Window_OpenKeyboard(const cc_string* text, int type) { } elem.focus(); elem.click(); - }, str, type); + }, str, args->type); } void Window_SetKeyboardText(const cc_string* text) { @@ -4248,13 +4255,13 @@ void Window_FreeFramebuffer(struct Bitmap* bmp) { Mem_Free(bmp->scan0); } -void Window_OpenKeyboard(const cc_string* text, int type) { +void Window_OpenKeyboard(const struct OpenKeyboardArgs* args) { JNIEnv* env; jvalue args[2]; JavaGetCurrentEnv(env); - args[0].l = JavaMakeString(env, text); - args[1].i = type; + args[0].l = JavaMakeString(env, args->text); + args[1].i = args->type; JavaCallVoid(env, "openKeyboard", "(Ljava/lang/String;I)V", args); (*env)->DeleteLocalRef(env, args[0].l); } diff --git a/src/Window.h b/src/Window.h index 92d7f904a..2d80abfb5 100644 --- a/src/Window.h +++ b/src/Window.h @@ -33,10 +33,10 @@ struct Bitmap; struct DynamicLibSym; /* The states the window can be in. */ -enum WindowState { WINDOW_STATE_NORMAL, WINDOW_STATE_FULLSCREEN, WINDOW_STATE_MINIMISED }; +enum WindowState { WINDOW_STATE_NORMAL, WINDOW_STATE_FULLSCREEN, WINDOW_STATE_MINIMISED }; enum KeyboardType { KEYBOARD_TYPE_TEXT, KEYBOARD_TYPE_NUMBER, KEYBOARD_TYPE_PASSWORD }; enum SoftKeyboard { SOFT_KEYBOARD_NONE, SOFT_KEYBOARD_RESIZE, SOFT_KEYBOARD_SHIFT }; -/* Can't name these structs Window/Display, because it conflicts with X11's Window/Display typedef */ +/* (can't name these structs Window/Display, as that conflicts with X11's Window/Display typedef) */ /* Data for the display monitor. */ CC_VAR extern struct _DisplayData { @@ -114,8 +114,8 @@ void Window_ProcessEvents(void); /* NOTE: This should be avoided because it is unsupported on some platforms. */ void Cursor_SetPosition(int x, int y); /* Sets whether the cursor is visible when over this window. */ -/* NOTE: You MUST BE VERY CAREFUL with this! OS typically uses a counter for visibility, -so setting invisible multiple times means you must then set visible multiple times. */ +/* NOTE: You MUST BE VERY CAREFUL with this! OS typically uses a counter for visibility, */ +/* so setting invisible multiple times means you must then set visible multiple times. */ void Cursor_SetVisible(cc_bool visible); /* Shows a dialog box window. */ @@ -134,14 +134,16 @@ 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; }; +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 cc_string* text, int type); +void Window_OpenKeyboard(const 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. */ +/* because it is backed by a HTML input, rather than true keyboard input events. */ /* As such, this is necessary to ensure the HTML input is consistent with */ -/* whatever text input widget is actually being displayed on screen. */ +/* whatever text input widget is actually being displayed on screen. */ void Window_SetKeyboardText(const cc_string* text); /* Hides/Removes the previously displayed on-screen keyboard. */ void Window_CloseKeyboard(void);