From fdf92e047ba4f2dd11e5d75820fc32b35e6f4c9b Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 30 Jul 2020 13:20:33 +1000 Subject: [PATCH] Launcher input widget DPI scales properly --- misc/ClassicalSharp/known_bugs.txt | 3 ++- src/Block.c | 1 - src/Event.h | 1 - src/Gui.c | 7 +++++-- src/Gui.h | 1 + src/Input.c | 2 +- src/LWidgets.c | 20 +++++++++++++++----- src/Launcher.c | 2 +- src/Screens.c | 4 ++-- src/Window.c | 6 ------ 10 files changed, 27 insertions(+), 20 deletions(-) diff --git a/misc/ClassicalSharp/known_bugs.txt b/misc/ClassicalSharp/known_bugs.txt index 0036f980f..e90b69139 100644 --- a/misc/ClassicalSharp/known_bugs.txt +++ b/misc/ClassicalSharp/known_bugs.txt @@ -16,4 +16,5 @@ * Alt text is closed on window resize * Changing server texture packs sometimes still retains textures from previous one * Crashes at startup when another process has exclusively acquired Direct3D9 device -* Can't bind controls to mouse buttons \ No newline at end of file +* Can't bind controls to mouse buttons +* Does not work at all on 64 bit macOS \ No newline at end of file diff --git a/src/Block.c b/src/Block.c index b4402eaa8..669d98195 100644 --- a/src/Block.c +++ b/src/Block.c @@ -6,7 +6,6 @@ #include "Entity.h" #include "Inventory.h" #include "Event.h" -#include "Platform.h" #include "Picking.h" struct _BlockLists Blocks; diff --git a/src/Event.h b/src/Event.h index 20f71dfc2..3d9ae2070 100644 --- a/src/Event.h +++ b/src/Event.h @@ -74,7 +74,6 @@ struct Event_RawMove { /* NOTE: Trying to register a callback twice or over EVENT_MAX_CALLBACKS callbacks will terminate the game. */ CC_API void Event_Register(struct Event_Void* handlers, void* obj, Event_Void_Callback handler); /* Unregisters a callback function for the given event. */ -/* NOTE: Trying to unregister a non-registered callback will terminate the game. */ CC_API void Event_Unregister(struct Event_Void* handlers, void* obj, Event_Void_Callback handler); #define Event_Register_(handlers, obj, handler) Event_Register((struct Event_Void*)(handlers), obj, (Event_Void_Callback)(handler)) #define Event_Unregister_(handlers, obj, handler) Event_Unregister((struct Event_Void*)(handlers), obj, (Event_Void_Callback)(handler)) diff --git a/src/Gui.c b/src/Gui.c index 47b806263..88095c6bb 100644 --- a/src/Gui.c +++ b/src/Gui.c @@ -154,6 +154,10 @@ void Gui_RefreshAll(void) { OnContextRecreated(NULL); } +void Gui_RemoveAll(void) { + while (Gui_ScreensCount) Gui_Remove(Gui_Screens[0]); +} + void Gui_RefreshChat(void) { Gui_Refresh((struct Screen*)Gui_Chat); } void Gui_Refresh(struct Screen* s) { s->VTABLE->ContextLost(s); @@ -421,8 +425,7 @@ static void OnReset(void) { } static void OnFree(void) { - while (Gui_ScreensCount) Gui_Remove(Gui_Screens[0]); - + Gui_RemoveAll(); OnContextLost(NULL); OnReset(); } diff --git a/src/Gui.h b/src/Gui.h index 3895f5816..2e0792ecf 100644 --- a/src/Gui.h +++ b/src/Gui.h @@ -185,6 +185,7 @@ struct Screen* Gui_GetBlocksWorld(void); struct Screen* Gui_GetClosable(void); void Gui_RefreshAll(void); +void Gui_RemoveAll(void); void Gui_RefreshChat(void); void Gui_Refresh(struct Screen* s); diff --git a/src/Input.c b/src/Input.c index 9e71ff169..535c9503f 100644 --- a/src/Input.c +++ b/src/Input.c @@ -757,7 +757,7 @@ void InputHandler_PickBlocks(void) { static cc_bool InputHandler_IsShutdown(int key) { if (key == KEY_F4 && Key_IsAltPressed()) return true; - /* On OSX, Cmd+Q should also terminate the process */ + /* On macOS, Cmd+Q should also end the process */ #ifdef CC_BUILD_OSX return key == 'Q' && Key_IsWinPressed(); #else diff --git a/src/LWidgets.c b/src/LWidgets.c index 1706328b2..4047341e6 100644 --- a/src/LWidgets.c +++ b/src/LWidgets.c @@ -13,10 +13,18 @@ #ifndef CC_BUILD_WEB static int xBorder, xBorder2, xBorder3, xBorder4; static int yBorder, yBorder2, yBorder3, yBorder4; +static int xInputOffset, yInputOffset; +static int caretOffset, caretWidth, caretHeight; void LWidget_CalcOffsets(void) { xBorder = Display_ScaleX(1); xBorder2 = xBorder * 2; xBorder3 = xBorder * 3; xBorder4 = xBorder * 4; yBorder = Display_ScaleY(1); yBorder2 = yBorder * 2; yBorder3 = yBorder * 3; yBorder4 = yBorder * 4; + + xInputOffset = Display_ScaleX(5); + yInputOffset = Display_ScaleY(2); + caretOffset = Display_ScaleY(5); + caretWidth = Display_ScaleX(10); + caretHeight = Display_ScaleY(2); } void LWidget_SetLocation(void* widget, cc_uint8 horAnchor, cc_uint8 verAnchor, int xOffset, int yOffset) { @@ -244,14 +252,16 @@ static void LInput_DrawText(struct LInput* w, struct DrawTextArgs* args) { if (w->text.length || !w->hintText) { y = w->y + (w->height - w->_textHeight) / 2; - Drawer2D_DrawText(&Launcher_Framebuffer, args, w->x + 5, y + 2); + Drawer2D_DrawText(&Launcher_Framebuffer, args, + w->x + xInputOffset, y + yInputOffset); } else { args->text = String_FromReadonly(w->hintText); args->font = &Launcher_HintFont; hintHeight = Drawer2D_TextHeight(args); y = w->y + (w->height - hintHeight) / 2; - Drawer2D_DrawText(&Launcher_Framebuffer, args, w->x + 5, y); + Drawer2D_DrawText(&Launcher_Framebuffer, args, + w->x + xInputOffset, y); } } @@ -290,12 +300,12 @@ static Rect2D LInput_MeasureCaret(struct LInput* w) { LInput_GetText(w, &text); DrawTextArgs_Make(&args, &text, &Launcher_TextFont, true); - r.X = w->x + 5; - r.Y = w->y + w->height - 5; r.Height = 2; + r.X = w->x + xInputOffset; + r.Y = w->y + w->height - caretOffset; r.Height = caretHeight; if (w->caretPos == -1) { r.X += Drawer2D_TextWidth(&args); - r.Width = 10; + r.Width = caretWidth; } else { args.text = String_UNSAFE_Substring(&text, 0, w->caretPos); r.X += Drawer2D_TextWidth(&args); diff --git a/src/Launcher.c b/src/Launcher.c index aa8479440..1d808f332 100644 --- a/src/Launcher.c +++ b/src/Launcher.c @@ -168,7 +168,7 @@ static void OnResize(void* obj) { static cc_bool IsShutdown(int key) { if (key == KEY_F4 && Key_IsAltPressed()) return true; - /* On macOS, Cmd+Q should also terminate the process */ + /* On macOS, Cmd+Q should also end the process */ #ifdef CC_BUILD_OSX return key == 'Q' && Key_IsWinPressed(); #else diff --git a/src/Screens.c b/src/Screens.c index eb36e7e3b..a704608fa 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -1925,8 +1925,8 @@ void DisconnectScreen_Show(const String* title, const String* message) { s->canReconnect = !(String_CaselessStarts(&why, &kick) || String_CaselessStarts(&why, &ban)); s->VTABLE = &DisconnectScreen_VTABLE; - /* Get rid of all other menus instead of just hiding to reduce GPU usage */ - while (Gui_ScreensCount) Gui_Remove(Gui_Screens[0]); + /* Remove all screens instead of just drawing over them to reduce GPU usage */ + Gui_RemoveAll(); Gui_Add((struct Screen*)s, GUI_PRIORITY_DISCONNECT); } diff --git a/src/Window.c b/src/Window.c index bece27258..0021f80fb 100644 --- a/src/Window.c +++ b/src/Window.c @@ -1157,7 +1157,6 @@ static void ApplyIcon(void) { } void Window_Create(int width, int height) { XSetWindowAttributes attributes = { 0 }; - XSizeHints hints = { 0 }; Atom protocols[2]; struct GraphicsMode mode; cc_uintptr addr; @@ -1187,11 +1186,6 @@ void Window_Create(int width, int height) { CWColormap | CWEventMask | CWBackPixel | CWBorderPixel, &attributes); if (!win_handle) Logger_Abort("XCreateWindow failed"); - hints.base_width = width; - hints.base_height = height; - hints.flags = PSize | PPosition; - XSetWMNormalHints(win_display, win_handle, &hints); - /* Register for window destroy notification */ protocols[0] = wm_destroy; protocols[1] = net_wm_ping;