Skip to content

Commit

Permalink
Make separators in updates/choose mode menu widgets, so they can be p…
Browse files Browse the repository at this point in the history
…roperly DPI scaled
  • Loading branch information
UnknownShadow200 committed Jul 20, 2019
1 parent 8dc0006 commit 7ec12b4
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 26 deletions.
50 changes: 24 additions & 26 deletions src/LScreens.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions src/LWidgets.c
Expand Up @@ -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) {
Expand Down Expand Up @@ -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-------------------------------------------------------*
*#########################################################################################################################*/
Expand Down
8 changes: 8 additions & 0 deletions src/LWidgets.h
Expand Up @@ -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;
Expand All @@ -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
Expand Down
29 changes: 29 additions & 0 deletions src/Window.c
Expand Up @@ -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();
Expand Down Expand Up @@ -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(); }
Expand Down Expand Up @@ -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(); }
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/Window.h
Expand Up @@ -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. */
Expand Down

0 comments on commit 7ec12b4

Please sign in to comment.