Fix launcher flags offset and input widget expand at high DPI

Also avoid double checking file existence when extracting launcher texture pack
This commit is contained in:
UnknownShadow200 2020-07-30 23:06:43 +10:00
parent 559ae5ceac
commit fbbe626a97
2 changed files with 18 additions and 13 deletions

View File

@ -13,11 +13,12 @@
#ifndef CC_BUILD_WEB #ifndef CC_BUILD_WEB
static int xBorder, xBorder2, xBorder3, xBorder4; static int xBorder, xBorder2, xBorder3, xBorder4;
static int yBorder, yBorder2, yBorder3, yBorder4; static int yBorder, yBorder2, yBorder3, yBorder4;
static int xInputOffset, yInputOffset; static int xInputOffset, yInputOffset, inputExpand;
static int caretOffset, caretWidth, caretHeight; static int caretOffset, caretWidth, caretHeight;
static int scrollbarWidth, dragPad, gridlineWidth, gridlineHeight; static int scrollbarWidth, dragPad, gridlineWidth, gridlineHeight;
static int hdrYOffset, hdrYPadding, rowYOffset, rowYPadding; static int hdrYOffset, hdrYPadding, rowYOffset, rowYPadding;
static int cellXOffset, cellXPadding, cellMinWidth; static int cellXOffset, cellXPadding, cellMinWidth;
static int flagXOffset, flagYOffset;
void LWidget_CalcOffsets(void) { void LWidget_CalcOffsets(void) {
xBorder = Display_ScaleX(1); xBorder2 = xBorder * 2; xBorder3 = xBorder * 3; xBorder4 = xBorder * 4; xBorder = Display_ScaleX(1); xBorder2 = xBorder * 2; xBorder3 = xBorder * 3; xBorder4 = xBorder * 4;
@ -25,6 +26,8 @@ void LWidget_CalcOffsets(void) {
xInputOffset = Display_ScaleX(5); xInputOffset = Display_ScaleX(5);
yInputOffset = Display_ScaleY(2); yInputOffset = Display_ScaleY(2);
inputExpand = Display_ScaleX(20);
caretOffset = Display_ScaleY(5); caretOffset = Display_ScaleY(5);
caretWidth = Display_ScaleX(10); caretWidth = Display_ScaleX(10);
caretHeight = Display_ScaleY(2); caretHeight = Display_ScaleY(2);
@ -42,6 +45,8 @@ void LWidget_CalcOffsets(void) {
cellXOffset = Display_ScaleX(6); cellXOffset = Display_ScaleX(6);
cellXPadding = Display_ScaleX(5); cellXPadding = Display_ScaleX(5);
cellMinWidth = Display_ScaleX(20); cellMinWidth = Display_ScaleX(20);
flagXOffset = Display_ScaleX(2);
flagYOffset = Display_ScaleY(6);
} }
void LWidget_SetLocation(void* widget, cc_uint8 horAnchor, cc_uint8 verAnchor, int xOffset, int yOffset) { void LWidget_SetLocation(void* widget, cc_uint8 horAnchor, cc_uint8 verAnchor, int xOffset, int yOffset) {
@ -293,7 +298,7 @@ static void LInput_Draw(void* widget) {
DrawTextArgs_Make(&args, &text, &Launcher_TextFont, false); DrawTextArgs_Make(&args, &text, &Launcher_TextFont, false);
textWidth = Drawer2D_TextWidth(&args); textWidth = Drawer2D_TextWidth(&args);
w->width = max(w->minWidth, textWidth + 20); w->width = max(w->minWidth, textWidth + inputExpand);
w->_textHeight = Drawer2D_TextHeight(&args); w->_textHeight = Drawer2D_TextHeight(&args);
LInput_DrawOuterBorder(w); LInput_DrawOuterBorder(w);
@ -498,7 +503,7 @@ void LInput_SetText(struct LInput* w, const String* text_) {
DrawTextArgs_Make(&args, &text, &Launcher_TextFont, true); DrawTextArgs_Make(&args, &text, &Launcher_TextFont, true);
textWidth = Drawer2D_TextWidth(&args); textWidth = Drawer2D_TextWidth(&args);
w->width = max(w->minWidth, textWidth + 20); w->width = max(w->minWidth, textWidth + inputExpand);
w->_textHeight = Drawer2D_TextHeight(&args); w->_textHeight = Drawer2D_TextHeight(&args);
} }
@ -702,7 +707,8 @@ void LSlider_Init(struct LScreen* s, struct LSlider* w, int width, int height, B
*#########################################################################################################################*/ *#########################################################################################################################*/
static void FlagColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, int x, int y) { static void FlagColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, int x, int y) {
Bitmap* bmp = Flags_Get(row); Bitmap* bmp = Flags_Get(row);
if (bmp) Drawer2D_BmpCopy(&Launcher_Framebuffer, x + 2, y + 6, bmp); if (!bmp) return;
Drawer2D_BmpCopy(&Launcher_Framebuffer, x + flagXOffset, y + flagYOffset, bmp);
} }
static void NameColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, int x, int y) { static void NameColumn_Draw(struct ServerInfo* row, struct DrawTextArgs* args, int x, int y) {

View File

@ -465,12 +465,13 @@ static cc_result Launcher_ProcessZipEntry(const String* path, struct Stream* dat
return 0; return 0;
} }
static void Launcher_ExtractTexturePack(const String* path) { static void ExtractTexturePack(const String* path) {
struct ZipState state; struct ZipState state;
struct Stream stream; struct Stream stream;
cc_result res; cc_result res;
res = Stream_OpenFile(&stream, path); res = Stream_OpenFile(&stream, path);
if (res == ReturnCode_FileNotFound) return;
if (res) { Logger_Warn(res, "opening texture pack"); return; } if (res) { Logger_Warn(res, "opening texture pack"); return; }
Zip_Init(&state, &stream); Zip_Init(&state, &stream);
@ -493,17 +494,15 @@ void Launcher_TryLoadTexturePack(void) {
Launcher_ClassicBackground = Options_GetBool(OPT_CLASSIC_MODE, false); Launcher_ClassicBackground = Options_GetBool(OPT_CLASSIC_MODE, false);
} }
Options_UNSAFE_Get(OPT_DEFAULT_TEX_PACK, &texPack); if (Options_UNSAFE_Get(OPT_DEFAULT_TEX_PACK, &texPack)) {
String_InitArray(path, pathBuffer); String_InitArray(path, pathBuffer);
String_Format1(&path, "texpacks/%s", &texPack); String_Format1(&path, "texpacks/%s", &texPack);
ExtractTexturePack(&path);
}
if (!texPack.length || !File_Exists(&path)) path = defZipPath;
if (!File_Exists(&path)) return;
Launcher_ExtractTexturePack(&path);
/* user selected texture pack is missing some required .png files */ /* user selected texture pack is missing some required .png files */
if (!fontBmp.scan0 || !dirtBmp.scan0) { if (!fontBmp.scan0 || !dirtBmp.scan0) {
Launcher_ExtractTexturePack(&defZipPath); ExtractTexturePack(&defZipPath);
} }
} }