From 7ec12b458eb94d9f57d26edab1e4d2fd737db55a Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 20 Jul 2019 18:37:45 +1000 Subject: [PATCH] Make separators in updates/choose mode menu widgets, so they can be properly DPI scaled --- src/LScreens.c | 50 ++++++++++++++++++++++++-------------------------- src/LWidgets.c | 23 +++++++++++++++++++++++ src/LWidgets.h | 8 ++++++++ src/Window.c | 29 +++++++++++++++++++++++++++++ src/Window.h | 6 ++++++ 5 files changed, 90 insertions(+), 26 deletions(-) diff --git a/src/LScreens.c b/src/LScreens.c index f549e5622..743b7f5f5 100644 --- a/src/LScreens.c +++ b/src/LScreens.c @@ -214,6 +214,11 @@ CC_NOINLINE static void LScreen_Input(struct LScreen* s, struct LInput* w, int w s->widgets[s->numWidgets++] = (struct LWidget*)w; } +CC_NOINLINE static void LScreen_Box(struct LScreen* s, struct LBox* w, int width, int height) { + LBox_Init(w, width, height); + s->widgets[s->numWidgets++] = (struct LWidget*)w; +} + CC_NOINLINE static void LScreen_Slider(struct LScreen* s, struct LSlider* w, int width, int height, int initValue, int maxValue, BitmapCol progressCol) { LSlider_Init(w, width, height); @@ -247,10 +252,11 @@ static void SwitchToUpdates(void* w, int x, int y) { *#########################################################################################################################*/ static struct ChooseModeScreen { LScreen_Layout + struct LBox seps[2]; struct LButton btnEnhanced, btnClassicHax, btnClassic, btnBack; struct LLabel lblTitle, lblHelp, lblEnhanced[2], lblClassicHax[2], lblClassic[2]; bool firstTime; - struct LWidget* _widgets[12]; + struct LWidget* _widgets[14]; } ChooseModeScreen_Instance; CC_NOINLINE static void ChooseMode_Click(bool classic, bool classicHacks) { @@ -280,10 +286,14 @@ static void ChooseModeScreen_Init(struct LScreen* s_) { s->lblHelp.Hidden = !s->firstTime; s->btnBack.Hidden = s->firstTime; + s->seps[0].Col = Launcher_ButtonBorderCol; + s->seps[1].Col = Launcher_ButtonBorderCol; if (s->numWidgets) return; s->widgets = s->_widgets; - LScreen_Label(s_, &s->lblTitle, ""); + LScreen_Label(s_, &s->lblTitle, ""); + LScreen_Box(s_, &s->seps[0], 490, 1); + LScreen_Box(s_, &s->seps[1], 490, 1); LScreen_Button(s_, &s->btnEnhanced, 145, 35, "Enhanced"); LScreen_Label(s_, &s->lblEnhanced[0], "&eEnables custom blocks, changing env"); @@ -312,6 +322,8 @@ static void ChooseModeScreen_Init(struct LScreen* s_) { static void ChooseModeScreen_Reposition(struct LScreen* s_) { struct ChooseModeScreen* s = (struct ChooseModeScreen*)s_; LWidget_SetLocation(&s->lblTitle, ANCHOR_CENTRE, ANCHOR_CENTRE, 10, -135); + LWidget_SetLocation(&s->seps[0], ANCHOR_CENTRE, ANCHOR_CENTRE, -5, -35); + LWidget_SetLocation(&s->seps[1], ANCHOR_CENTRE, ANCHOR_CENTRE, -5, 35); LWidget_SetLocation(&s->btnEnhanced, ANCHOR_CENTRE_MIN, ANCHOR_CENTRE, -250, -72); LWidget_SetLocation(&s->lblEnhanced[0], ANCHOR_CENTRE_MIN, ANCHOR_CENTRE, -85, -72 - 12); @@ -329,22 +341,11 @@ static void ChooseModeScreen_Reposition(struct LScreen* s_) { LWidget_SetLocation(&s->btnBack, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 170); } -static void ChooseModeScreen_Draw(struct LScreen* s) { - int midX = Window_Width / 2, midY = Window_Height / 2; - LScreen_Draw(s); - - Drawer2D_Rect(&Launcher_Framebuffer, Launcher_ButtonBorderCol, - midX - 250, midY - 35, 490, 1); - Drawer2D_Rect(&Launcher_Framebuffer, Launcher_ButtonBorderCol, - midX - 250, midY + 35, 490, 1); -} - struct LScreen* ChooseModeScreen_MakeInstance(bool firstTime) { struct ChooseModeScreen* s = &ChooseModeScreen_Instance; LScreen_Reset((struct LScreen*)s); s->Init = ChooseModeScreen_Init; s->Reposition = ChooseModeScreen_Reposition; - s->Draw = ChooseModeScreen_Draw; s->firstTime = firstTime; s->onEnterWidget = (struct LWidget*)&s->btnEnhanced; return (struct LScreen*)s; @@ -1410,23 +1411,14 @@ struct LScreen* SettingsScreen_MakeInstance(void) { *#########################################################################################################################*/ static struct UpdatesScreen { LScreen_Layout + struct LBox seps[2]; struct LButton btnRel[2], btnDev[2], btnBack; struct LLabel lblYour, lblRel, lblDev, lblInfo, lblStatus; - struct LWidget* _widgets[10]; + struct LWidget* _widgets[12]; const char* buildName; int buildProgress; } UpdatesScreen_Instance; -static void UpdatesScreen_Draw(struct LScreen* s) { - int midX = Window_Width / 2, midY = Window_Height / 2; - LScreen_Draw(s); - - Drawer2D_Rect(&Launcher_Framebuffer, Launcher_ButtonBorderCol, - midX - 160, midY - 100, 320, 1); - Drawer2D_Rect(&Launcher_Framebuffer, Launcher_ButtonBorderCol, - midX - 160, midY - 5, 320, 1); -} - CC_NOINLINE static void UpdatesScreen_FormatTime(String* str, char* type, int delta, int unit) { delta /= unit; String_AppendInt(str, delta); @@ -1550,9 +1542,14 @@ static void UpdatesScreen_Init(struct LScreen* s_) { TimeMS buildTime; ReturnCode res; + s->seps[0].Col = Launcher_ButtonBorderCol; + s->seps[1].Col = Launcher_ButtonBorderCol; if (s->numWidgets) { CheckUpdateTask_Run(); return; } + s->widgets = s->_widgets; - LScreen_Label(s_, &s->lblYour, "Your build: (unknown)"); + LScreen_Label(s_, &s->lblYour, "Your build: (unknown)"); + LScreen_Box(s_, &s->seps[0], 320, 1); + LScreen_Box(s_, &s->seps[1], 320, 1); LScreen_Label(s_, &s->lblRel, "Latest release: Checking.."); LScreen_Button(s_, &s->btnRel[0], 130, 35, "Direct3D 9"); @@ -1591,6 +1588,8 @@ static void UpdatesScreen_Init(struct LScreen* s_) { static void UpdatesScreen_Reposition(struct LScreen* s_) { struct UpdatesScreen* s = (struct UpdatesScreen*)s_; LWidget_SetLocation(&s->lblYour, ANCHOR_CENTRE, ANCHOR_CENTRE, -5, -120); + LWidget_SetLocation(&s->seps[0], ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -100); + LWidget_SetLocation(&s->seps[1], ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -5); LWidget_SetLocation(&s->lblRel, ANCHOR_CENTRE, ANCHOR_CENTRE, -20, -75); LWidget_SetLocation(&s->btnRel[0], ANCHOR_CENTRE, ANCHOR_CENTRE, -80, -40); @@ -1627,7 +1626,6 @@ struct LScreen* UpdatesScreen_MakeInstance(void) { struct UpdatesScreen* s = &UpdatesScreen_Instance; LScreen_Reset((struct LScreen*)s); s->Init = UpdatesScreen_Init; - s->Draw = UpdatesScreen_Draw; s->Tick = UpdatesScreen_Tick; s->Free = UpdatesScreen_Free; s->Reposition = UpdatesScreen_Reposition; diff --git a/src/LWidgets.c b/src/LWidgets.c index 6f3be53b0..cfcc52840 100644 --- a/src/LWidgets.c +++ b/src/LWidgets.c @@ -384,12 +384,14 @@ static void LInput_Select(void* widget, bool wasSelected) { /* TODO: Only draw outer border */ if (wasSelected) return; LInput_Draw(widget); + Window_OpenKeyboard(); } static void LInput_Unselect(void* widget) { caretStart = 0; /* TODO: Only draw outer border */ LInput_Draw(widget); + Window_CloseKeyboard(); } static void LInput_CopyFromClipboard(String* text, void* widget) { @@ -568,6 +570,27 @@ void LLabel_SetText(struct LLabel* w, const String* text) { } +/*########################################################################################################################* +*-------------------------------------------------------BoxWidget---------------------------------------------------------* +*#########################################################################################################################*/ +static void LBox_Draw(void* widget) { + struct LBox* w = (struct LBox*)widget; + Drawer2D_Rect(&Launcher_Framebuffer, w->Col, w->X, w->Y, w->Width, w->Height); +} + +static struct LWidgetVTABLE lbox_VTABLE = { + LBox_Draw, NULL, + NULL, NULL, /* Key */ + NULL, NULL, /* Hover */ + NULL, NULL /* Select */ +}; +void LBox_Init(struct LBox* w, int width, int height) { + w->VTABLE = &lbox_VTABLE; + w->Width = Gui_ScaleX(width); + w->Height = Gui_ScaleY(height); +} + + /*########################################################################################################################* *------------------------------------------------------SliderWidget-------------------------------------------------------* *#########################################################################################################################*/ diff --git a/src/LWidgets.h b/src/LWidgets.h index 6e2f75f23..b730334d9 100644 --- a/src/LWidgets.h +++ b/src/LWidgets.h @@ -93,6 +93,7 @@ CC_NOINLINE bool LInput_Delete(struct LInput* w); /* Resets the currently entered text to an empty string. */ CC_NOINLINE bool LInput_Clear(struct LInput* w); +/* Represents non-interactable text. */ struct LLabel { LWidget_Layout FontDesc Font; @@ -103,6 +104,13 @@ struct LLabel { CC_NOINLINE void LLabel_Init(struct LLabel* w, const FontDesc* font); CC_NOINLINE void LLabel_SetText(struct LLabel* w, const String* text); +/* Represents a coloured rectangle. Usually used as a line separator. */ +struct LBox { + LWidget_Layout + BitmapCol Col; +}; +CC_NOINLINE void LBox_Init(struct LBox* w, int width, int height); + /* Represents a slider bar that may or may not be modifiable by the user. */ struct LSlider { LWidget_Layout diff --git a/src/Window.c b/src/Window.c index bb1d5ecf8..1fd7cbf7a 100644 --- a/src/Window.c +++ b/src/Window.c @@ -595,6 +595,9 @@ static void Window_InitRawMouse(void) { rawMouseSupported = false; } +void Window_OpenKeyboard(void) { } +void Window_CloseKeyboard(void) { } + void Window_EnableRawMouse(void) { rawMouseEnabled = true; Window_DefaultEnableRawMouse(); @@ -1434,6 +1437,8 @@ void Window_FreeFramebuffer(Bitmap* bmp) { Mem_Free(bmp->Scan0); } +void Window_OpenKeyboard(void) { } +void Window_CloseKeyboard(void) { } void Window_EnableRawMouse(void) { Window_DefaultEnableRawMouse(); } void Window_UpdateRawMouse(void) { Window_DefaultUpdateRawMouse(); } void Window_DisableRawMouse(void) { Window_DefaultDisableRawMouse(); } @@ -1991,6 +1996,8 @@ void Window_FreeFramebuffer(Bitmap* bmp) { CGColorSpaceRelease(colorSpace); } +void Window_OpenKeyboard(void) { } +void Window_CloseKeyboard(void) { } void Window_EnableRawMouse(void) { Window_DefaultEnableRawMouse(); } void Window_UpdateRawMouse(void) { Window_DefaultUpdateRawMouse(); } void Window_DisableRawMouse(void) { Window_DefaultDisableRawMouse(); } @@ -2302,6 +2309,13 @@ void Window_FreeFramebuffer(Bitmap* bmp) { /* TODO: Do we still need to unlock it though? */ } +void Window_OpenKeyboard(void) { + SDL_StartTextInput(); +} +void Window_CloseKeyboard(void) { + SDL_StopTextInput(); +} + void Window_EnableRawMouse(void) { Window_RegrabMouse(); SDL_SetRelativeMouseMode(true); @@ -2735,6 +2749,9 @@ void Window_AllocFramebuffer(Bitmap* bmp) { } void Window_DrawFramebuffer(Rect2D r) { } void Window_FreeFramebuffer(Bitmap* bmp) { } +void Window_OpenKeyboard(void) { } +void Window_CloseKeyboard(void) { } + void Window_EnableRawMouse(void) { Window_RegrabMouse(); emscripten_request_pointerlock(NULL, true); @@ -2983,6 +3000,18 @@ void Window_FreeFramebuffer(Bitmap* bmp) { Mem_Free(bmp->Scan0); } +void Window_OpenKeyboard(void) { + JNIEnv* env; + JavaGetCurrentEnv(env); + JavaCallVoid(env, "openKeyboard", "()V", NULL); +} + +void Window_CloseKeyboard(void) { + JNIEnv* env; + JavaGetCurrentEnv(env); + JavaCallVoid(env, "closeKeyboard", "()V", NULL); +} + void Window_EnableRawMouse(void) { Window_DefaultEnableRawMouse(); win_rawMouse = true; diff --git a/src/Window.h b/src/Window.h index 7bc8be0be..0c9052e5e 100644 --- a/src/Window.h +++ b/src/Window.h @@ -122,6 +122,12 @@ void Window_DrawFramebuffer(Rect2D r); /* Frees the previously allocated framebuffer. */ void Window_FreeFramebuffer(Bitmap* bmp); +/* Displays on-screen keyboard for platforms that lack physical keyboard input. */ +/* NOTE: On desktop platforms, this won't do anything. */ +void Window_OpenKeyboard(void); +/* Hides/Removes the previously displayed on-screen keyboard. */ +void Window_CloseKeyboard(void); + /* Begins listening for raw input and starts raising MouseEvents.RawMoved. */ /* NOTE: Some backends only raise it when Window_UpdateRawMouse is called. */ /* Cursor will also be hidden and moved to window centre. */