mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 01:21:57 -05:00
Launcher: Move font loading into backend mostly, few other minor changes
This commit is contained in:
parent
8c6375b462
commit
d1ece08a58
8 changed files with 46 additions and 53 deletions
|
@ -23,10 +23,8 @@
|
|||
#include "LScreens.h"
|
||||
#include "Input.h"
|
||||
#include "Utils.h"
|
||||
struct FontDesc titleFont, textFont, hintFont;
|
||||
|
||||
/*########################################################################################################################*
|
||||
*---------------------------------------------------------LWidget---------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static int xBorder, xBorder2, xBorder3, xBorder4;
|
||||
static int yBorder, yBorder2, yBorder3, yBorder4;
|
||||
static int xInputOffset, yInputOffset, inputExpand;
|
||||
|
@ -63,6 +61,16 @@ void LBackend_Init(void) {
|
|||
cellMinWidth = Display_ScaleX(20);
|
||||
flagXOffset = Display_ScaleX(2);
|
||||
flagYOffset = Display_ScaleY(6);
|
||||
|
||||
Drawer2D_MakeFont(&titleFont, 16, FONT_FLAGS_BOLD);
|
||||
Drawer2D_MakeFont(&textFont, 14, FONT_FLAGS_NONE);
|
||||
Drawer2D_MakeFont(&hintFont, 12, FONT_FLAGS_NONE);
|
||||
}
|
||||
|
||||
void LBackend_Free(void) {
|
||||
Font_Free(&titleFont);
|
||||
Font_Free(&textFont);
|
||||
Font_Free(&hintFont);
|
||||
}
|
||||
|
||||
static void DrawBoxBounds(BitmapCol col, int x, int y, int width, int height) {
|
||||
|
@ -95,7 +103,7 @@ void LBackend_ButtonInit(struct LButton* w, int width, int height) {
|
|||
|
||||
void LBackend_ButtonUpdate(struct LButton* w) {
|
||||
struct DrawTextArgs args;
|
||||
DrawTextArgs_Make(&args, &w->text, &Launcher_TitleFont, true);
|
||||
DrawTextArgs_Make(&args, &w->text, &titleFont, true);
|
||||
|
||||
w->_textWidth = Drawer2D_TextWidth(&args);
|
||||
w->_textHeight = Drawer2D_TextHeight(&args);
|
||||
|
@ -108,7 +116,7 @@ void LBackend_ButtonDraw(struct LButton* w) {
|
|||
LButton_DrawBackground(w, &Launcher_Framebuffer, w->x, w->y);
|
||||
xOffset = w->width - w->_textWidth;
|
||||
yOffset = w->height - w->_textHeight;
|
||||
DrawTextArgs_Make(&args, &w->text, &Launcher_TitleFont, true);
|
||||
DrawTextArgs_Make(&args, &w->text, &titleFont, true);
|
||||
|
||||
if (!w->hovered) Drawer2D.Colors['f'] = Drawer2D.Colors['7'];
|
||||
Drawer2D_DrawText(&Launcher_Framebuffer, &args,
|
||||
|
@ -126,7 +134,7 @@ void LBackend_ButtonDraw(struct LButton* w) {
|
|||
|
||||
void LBackend_CheckboxInit(struct LCheckbox* w) {
|
||||
struct DrawTextArgs args;
|
||||
DrawTextArgs_Make(&args, &w->text, &Launcher_TextFont, true);
|
||||
DrawTextArgs_Make(&args, &w->text, &textFont, true);
|
||||
|
||||
w->width = Display_ScaleX(CB_SIZE + CB_OFFSET) + Drawer2D_TextWidth(&args);
|
||||
w->height = Display_ScaleY(CB_SIZE);
|
||||
|
@ -206,7 +214,7 @@ void LBackend_CheckboxDraw(struct LCheckbox* w) {
|
|||
}
|
||||
DrawBoxBounds(BITMAPCOL_BLACK, w->x, w->y, width, height);
|
||||
|
||||
DrawTextArgs_Make(&args, &w->text, &Launcher_TextFont, true);
|
||||
DrawTextArgs_Make(&args, &w->text, &textFont, true);
|
||||
x = w->x + Display_ScaleX(CB_SIZE + CB_OFFSET);
|
||||
y = w->y + (height - Drawer2D_TextHeight(&args)) / 2;
|
||||
Drawer2D_DrawText(&Launcher_Framebuffer, &args, x, y);
|
||||
|
@ -278,7 +286,7 @@ static void LInput_DrawText(struct LInput* w, struct DrawTextArgs* args) {
|
|||
w->x + xInputOffset, y + yInputOffset);
|
||||
} else {
|
||||
args->text = String_FromReadonly(w->hintText);
|
||||
args->font = &Launcher_HintFont;
|
||||
args->font = &hintFont;
|
||||
|
||||
hintHeight = Drawer2D_TextHeight(args);
|
||||
y = w->y + (w->height - hintHeight) / 2;
|
||||
|
@ -293,7 +301,7 @@ static void LInput_DrawText(struct LInput* w, struct DrawTextArgs* args) {
|
|||
static void LInput_UpdateDimensions(struct LInput* w, const cc_string* text) {
|
||||
struct DrawTextArgs args;
|
||||
int textWidth;
|
||||
DrawTextArgs_Make(&args, text, &Launcher_TextFont, false);
|
||||
DrawTextArgs_Make(&args, text, &textFont, false);
|
||||
|
||||
textWidth = Drawer2D_TextWidth(&args);
|
||||
w->width = max(w->minWidth, textWidth + inputExpand);
|
||||
|
@ -314,7 +322,7 @@ void LBackend_InputDraw(struct LInput* w) {
|
|||
|
||||
String_InitArray(text, textBuffer);
|
||||
LInput_UNSAFE_GetText(w, &text);
|
||||
DrawTextArgs_Make(&args, &text, &Launcher_TextFont, false);
|
||||
DrawTextArgs_Make(&args, &text, &textFont, false);
|
||||
|
||||
/* TODO shouldn't be recalcing size in draw.... */
|
||||
LInput_UpdateDimensions(w, &text);
|
||||
|
@ -343,7 +351,7 @@ static Rect2D LInput_MeasureCaret(struct LInput* w) {
|
|||
|
||||
String_InitArray(text, textBuffer);
|
||||
LInput_UNSAFE_GetText(w, &text);
|
||||
DrawTextArgs_Make(&args, &text, &Launcher_TextFont, true);
|
||||
DrawTextArgs_Make(&args, &text, &textFont, true);
|
||||
|
||||
r.X = w->x + xInputOffset;
|
||||
r.Y = w->y + w->height - caretOffset; r.Height = caretHeight;
|
||||
|
@ -376,7 +384,7 @@ static void LInput_MoveCaretToCursor(struct LInput* w, int idx) {
|
|||
LInput_UNSAFE_GetText(w, &text);
|
||||
x -= w->x; y -= w->y;
|
||||
|
||||
DrawTextArgs_Make(&args, &text, &Launcher_TextFont, true);
|
||||
DrawTextArgs_Make(&args, &text, &textFont, true);
|
||||
if (x >= Drawer2D_TextWidth(&args)) {
|
||||
w->caretPos = -1; return;
|
||||
}
|
||||
|
@ -430,7 +438,7 @@ void LBackend_InputSelect(struct LInput* w, int idx, cc_bool wasSelected) {
|
|||
if (wasSelected) return;
|
||||
|
||||
LWidget_Draw(w);
|
||||
OpenKeyboardArgs_Init(&args, &w->text, w->type);
|
||||
OpenKeyboardArgs_Init(&args, &w->text, w->inputType);
|
||||
Window_OpenKeyboard(&args);
|
||||
}
|
||||
|
||||
|
@ -446,10 +454,11 @@ void LBackend_InputUnselect(struct LInput* w) {
|
|||
*------------------------------------------------------LabelWidget--------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void LBackend_LabelInit(struct LLabel* w) { }
|
||||
#define LLabel_GetFont(w) (w->small ? &hintFont : &textFont)
|
||||
|
||||
void LBackend_LabelUpdate(struct LLabel* w) {
|
||||
struct DrawTextArgs args;
|
||||
DrawTextArgs_Make(&args, &w->text, w->font, true);
|
||||
DrawTextArgs_Make(&args, &w->text, LLabel_GetFont(w), true);
|
||||
|
||||
w->width = Drawer2D_TextWidth(&args);
|
||||
w->height = Drawer2D_TextHeight(&args);
|
||||
|
@ -457,7 +466,7 @@ void LBackend_LabelUpdate(struct LLabel* w) {
|
|||
|
||||
void LBackend_LabelDraw(struct LLabel* w) {
|
||||
struct DrawTextArgs args;
|
||||
DrawTextArgs_Make(&args, &w->text, w->font, true);
|
||||
DrawTextArgs_Make(&args, &w->text, LLabel_GetFont(w), true);
|
||||
Drawer2D_DrawText(&Launcher_Framebuffer, &args, w->x, w->y);
|
||||
}
|
||||
|
||||
|
@ -542,7 +551,7 @@ void LBackend_TableUpdate(struct LTable* w) { }
|
|||
|
||||
void LBackend_TableReposition(struct LTable* w) {
|
||||
int rowsHeight;
|
||||
w->hdrHeight = Drawer2D_FontHeight(&Launcher_TextFont, true) + hdrYPadding;
|
||||
w->hdrHeight = Drawer2D_FontHeight(&textFont, true) + hdrYPadding;
|
||||
w->rowHeight = Drawer2D_FontHeight(w->rowFont, true) + rowYPadding;
|
||||
|
||||
w->rowsBegY = w->y + w->hdrHeight + gridlineHeight;
|
||||
|
@ -649,7 +658,7 @@ static void LTable_DrawHeaders(struct LTable* w) {
|
|||
struct DrawTextArgs args;
|
||||
int i, x, y;
|
||||
|
||||
DrawTextArgs_MakeEmpty(&args, &Launcher_TextFont, true);
|
||||
DrawTextArgs_MakeEmpty(&args, &textFont, true);
|
||||
x = w->x; y = w->y;
|
||||
|
||||
for (i = 0; i < w->numColumns; i++) {
|
||||
|
|
|
@ -16,6 +16,7 @@ struct LSlider;
|
|||
struct LTable;
|
||||
|
||||
void LBackend_Init(void);
|
||||
void LBackend_Free(void);
|
||||
void LBackend_WidgetRepositioned(struct LWidget* w);
|
||||
void LBackend_SetScreen(struct LScreen* s);
|
||||
void LBackend_CloseScreen(struct LScreen* s);
|
||||
|
|
|
@ -461,7 +461,7 @@ static void ColoursScreen_Init(struct LScreen* s_) {
|
|||
s->numWidgets = Array_Elems(colours_widgets);
|
||||
|
||||
for (i = 0; i < 5 * 3; i++) {
|
||||
s->iptColours[i].type = KEYBOARD_TYPE_INTEGER;
|
||||
s->iptColours[i].inputType = KEYBOARD_TYPE_INTEGER;
|
||||
s->iptColours[i].TextChanged = ColoursScreen_TextChanged;
|
||||
LInput_Init(&s->iptColours[i], 55, NULL);
|
||||
}
|
||||
|
@ -714,7 +714,7 @@ static void MFAScreen_Init(struct LScreen* s_) {
|
|||
|
||||
s->btnSignIn.OnClick = MFAScreen_SignIn;
|
||||
s->btnCancel.OnClick = MFAScreen_Cancel;
|
||||
s->iptCode.type = KEYBOARD_TYPE_INTEGER;
|
||||
s->iptCode.inputType = KEYBOARD_TYPE_INTEGER;
|
||||
}
|
||||
|
||||
static void MFAScreen_Show(struct LScreen* s_) {
|
||||
|
@ -885,7 +885,9 @@ static void MainScreen_Init(struct LScreen* s_) {
|
|||
struct MainScreen* s = (struct MainScreen*)s_;
|
||||
s->widgets = main_widgets;
|
||||
s->numWidgets = Array_Elems(main_widgets);
|
||||
s->iptPassword.type = KEYBOARD_TYPE_PASSWORD;
|
||||
|
||||
s->iptPassword.inputType = KEYBOARD_TYPE_PASSWORD;
|
||||
s->lblUpdate.small = true;
|
||||
|
||||
LInput_Init( &s->iptUsername, 280, "Username..");
|
||||
LInput_Init( &s->iptPassword, 280, "Password..");
|
||||
|
@ -896,7 +898,7 @@ static void MainScreen_Init(struct LScreen* s_) {
|
|||
LButton_Init(&s->btnDirect, 200, 35, "Direct connect");
|
||||
LButton_Init(&s->btnSPlayer, 200, 35, "Singleplayer");
|
||||
|
||||
LLabel_Init( &s->lblUpdate, "");
|
||||
LLabel_Init( &s->lblUpdate, "&eChecking..");
|
||||
LButton_Init(&s->btnRegister, 100, 35, "Register");
|
||||
LButton_Init(&s->btnOptions, 100, 35, "Options");
|
||||
|
||||
|
@ -907,13 +909,8 @@ static void MainScreen_Init(struct LScreen* s_) {
|
|||
s->btnOptions.OnClick = SwitchToSettings;
|
||||
s->btnRegister.OnClick = MainScreen_Register;
|
||||
|
||||
|
||||
s->btnResume.OnHover = MainScreen_ResumeHover;
|
||||
s->btnResume.OnUnhover = MainScreen_ResumeUnhover;
|
||||
|
||||
/* need to set text here for right size */
|
||||
s->lblUpdate.font = &Launcher_HintFont;
|
||||
LLabel_SetConst(&s->lblUpdate, "&eChecking..");
|
||||
|
||||
String_InitArray(pass, passBuffer);
|
||||
Options_UNSAFE_Get(LOPT_USERNAME, &user);
|
||||
|
@ -1104,6 +1101,7 @@ static void CheckResourcesScreen_Init(struct LScreen* s_) {
|
|||
struct CheckResourcesScreen* s = (struct CheckResourcesScreen*)s_;
|
||||
s->widgets = checkResources_widgets;
|
||||
s->numWidgets = Array_Elems(checkResources_widgets);
|
||||
s->lblStatus.small = true;
|
||||
|
||||
LLabel_Init( &s->lblLine1, "Some required resources weren't found");
|
||||
LLabel_Init( &s->lblLine2, "Okay to download?");
|
||||
|
@ -1122,7 +1120,6 @@ static void CheckResourcesScreen_Show(struct LScreen* s_) {
|
|||
|
||||
String_InitArray(str, buffer);
|
||||
String_Format1(&str, "&eDownload size: %f2 megabytes", &size);
|
||||
s->lblStatus.font = &Launcher_HintFont;
|
||||
LLabel_SetText(&s->lblStatus, &str);
|
||||
}
|
||||
|
||||
|
@ -1187,12 +1184,12 @@ static void FetchResourcesScreen_Init(struct LScreen* s_) {
|
|||
struct FetchResourcesScreen* s = (struct FetchResourcesScreen*)s_;
|
||||
s->widgets = fetchResources_widgets;
|
||||
s->numWidgets = Array_Elems(fetchResources_widgets);
|
||||
s->lblStatus.small = true;
|
||||
|
||||
LLabel_Init( &s->lblStatus, "");
|
||||
LButton_Init(&s->btnCancel, 120, 35, "Cancel");
|
||||
LSlider_Init(&s->sdrProgress, 200, 12, BitmapCol_Make(0, 220, 0, 255));
|
||||
|
||||
s->lblStatus.font = &Launcher_HintFont;
|
||||
s->btnCancel.OnClick = CheckResourcesScreen_Next;
|
||||
}
|
||||
static void FetchResourcesScreen_Show(struct LScreen* s_) { Fetcher_Run(); }
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include "Utils.h"
|
||||
#include "LBackend.h"
|
||||
|
||||
static int xInputOffset;
|
||||
static int flagXOffset, flagYOffset;
|
||||
static int xBorder, xBorder2, xBorder4;
|
||||
static int yBorder, yBorder2, yBorder4;
|
||||
|
@ -23,7 +22,6 @@ void LWidget_CalcOffsets(void) {
|
|||
xBorder = Display_ScaleX(1); xBorder2 = xBorder * 2; xBorder4 = xBorder * 4;
|
||||
yBorder = Display_ScaleY(1); yBorder2 = yBorder * 2; yBorder4 = yBorder * 4;
|
||||
|
||||
xInputOffset = Display_ScaleX(5);
|
||||
flagXOffset = Display_ScaleX(2);
|
||||
flagYOffset = Display_ScaleY(6);
|
||||
}
|
||||
|
@ -187,7 +185,7 @@ void LCheckbox_Init(struct LCheckbox* w, const char* text) {
|
|||
*#########################################################################################################################*/
|
||||
void LInput_UNSAFE_GetText(struct LInput* w, cc_string* text) {
|
||||
int i;
|
||||
if (w->type != KEYBOARD_TYPE_PASSWORD) { *text = w->text; return; }
|
||||
if (w->inputType != KEYBOARD_TYPE_PASSWORD) { *text = w->text; return; }
|
||||
|
||||
for (i = 0; i < w->text.length; i++) {
|
||||
String_Append(text, '*');
|
||||
|
@ -291,7 +289,7 @@ static void LInput_KeyDown(void* widget, int key, cc_bool was) {
|
|||
}
|
||||
|
||||
static cc_bool LInput_CanAppend(struct LInput* w, char c) {
|
||||
switch (w->type) {
|
||||
switch (w->inputType) {
|
||||
case KEYBOARD_TYPE_PASSWORD:
|
||||
return true; /* keyboard accepts all characters */
|
||||
case KEYBOARD_TYPE_INTEGER:
|
||||
|
@ -392,7 +390,6 @@ static const struct LWidgetVTABLE llabel_VTABLE = {
|
|||
};
|
||||
void LLabel_Init(struct LLabel* w, const char* text) {
|
||||
w->VTABLE = &llabel_VTABLE;
|
||||
w->font = &Launcher_TextFont;
|
||||
|
||||
String_InitArray(w->text, w->_textBuffer);
|
||||
LBackend_LabelInit(w);
|
||||
|
|
|
@ -79,7 +79,7 @@ struct LInput {
|
|||
const char* hintText;
|
||||
/* The type of this input (see KEYBOARD_TYPE_ enum in Window.h) */
|
||||
/* If type is KEYBOARD_TYPE_PASSWORD, all characters are drawn as *. */
|
||||
cc_uint8 type;
|
||||
cc_uint8 inputType;
|
||||
/* Filter applied to text received from the clipboard. Can be NULL. */
|
||||
void (*ClipboardFilter)(cc_string* str);
|
||||
/* Callback invoked when the text is changed. Can be NULL. */
|
||||
|
@ -104,7 +104,7 @@ CC_NOINLINE void LInput_SetString(struct LInput* w, const cc_string* str);
|
|||
/* Represents non-interactable text. */
|
||||
struct LLabel {
|
||||
LWidget_Layout
|
||||
struct FontDesc* font;
|
||||
cc_bool small; /* whether to use 12pt instead of 14pt font size */
|
||||
cc_string text;
|
||||
char _textBuffer[STRING_SIZE];
|
||||
};
|
||||
|
|
|
@ -27,8 +27,7 @@ static Rect2D dirty_rect;
|
|||
|
||||
static struct LScreen* activeScreen;
|
||||
struct Bitmap Launcher_Framebuffer;
|
||||
struct FontDesc Launcher_TitleFont, Launcher_TextFont;
|
||||
struct FontDesc Launcher_HintFont, Launcher_LogoFont;
|
||||
struct FontDesc Launcher_LogoFont;
|
||||
static cc_bool pendingRedraw;
|
||||
|
||||
cc_bool Launcher_ShouldExit, Launcher_ShouldUpdate;
|
||||
|
@ -262,20 +261,14 @@ static void Launcher_Init(void) {
|
|||
Event_Register_(&PointerEvents.Up, NULL, OnPointerUp);
|
||||
Event_Register_(&PointerEvents.Moved, NULL, OnPointerMove);
|
||||
|
||||
Drawer2D_MakeFont(&Launcher_TitleFont, 16, FONT_FLAGS_BOLD);
|
||||
Drawer2D_MakeFont(&Launcher_TextFont, 14, FONT_FLAGS_NONE);
|
||||
Drawer2D_MakeFont(&Launcher_HintFont, 12, FONT_FLAGS_NONE);
|
||||
|
||||
Utils_EnsureDirectory("texpacks");
|
||||
Utils_EnsureDirectory("audio");
|
||||
}
|
||||
|
||||
static void Launcher_Free(void) {
|
||||
Event_UnregisterAll();
|
||||
LBackend_Free();
|
||||
Flags_Free();
|
||||
Font_Free(&Launcher_TitleFont);
|
||||
Font_Free(&Launcher_TextFont);
|
||||
Font_Free(&Launcher_HintFont);
|
||||
Font_Free(&Launcher_LogoFont);
|
||||
hasBitmappedFont = false;
|
||||
|
||||
|
@ -293,7 +286,6 @@ void Launcher_Run(void) {
|
|||
Window_SetTitle(&title);
|
||||
Window_Show();
|
||||
LWidget_CalcOffsets();
|
||||
LBackend_Init();
|
||||
|
||||
#ifdef CC_BUILD_WIN
|
||||
/* clean leftover exe from updating */
|
||||
|
@ -305,8 +297,9 @@ void Launcher_Run(void) {
|
|||
Drawer2D_Component.Init();
|
||||
Drawer2D.BitmappedText = false;
|
||||
Drawer2D.BlackTextShadows = true;
|
||||
InitFramebuffer();
|
||||
|
||||
LBackend_Init();
|
||||
InitFramebuffer();
|
||||
Launcher_ShowEmptyServers = Options_GetBool(LOPT_SHOW_EMPTY, true);
|
||||
Options_Get(LOPT_USERNAME, &Launcher_Username, "");
|
||||
|
||||
|
|
|
@ -9,10 +9,6 @@ struct FontDesc;
|
|||
|
||||
/* Contains the pixels that are drawn to the window */
|
||||
extern struct Bitmap Launcher_Framebuffer;
|
||||
/* Default font for buttons and labels */
|
||||
extern struct FontDesc Launcher_TitleFont, Launcher_TextFont;
|
||||
/* Default font for input widget hints */
|
||||
extern struct FontDesc Launcher_HintFont;
|
||||
/* Default font for screen/menu titles */
|
||||
extern struct FontDesc Launcher_LogoFont;
|
||||
|
||||
|
|
|
@ -655,7 +655,7 @@ static NSString* cellID = @"CC_Cell";
|
|||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
|
||||
}
|
||||
|
||||
struct ServerInfo* server = Servers_Get([indexPath row]);
|
||||
struct ServerInfo* server = LTable_Get([indexPath row]);
|
||||
struct Flag* flag = Flags_Get(server);
|
||||
|
||||
char descBuffer[128];
|
||||
|
@ -757,9 +757,9 @@ void LBackend_InputInit(struct LInput* w, int width) {
|
|||
fld.backgroundColor = [UIColor whiteColor];
|
||||
[fld addTarget:ui_controller action:@selector(handleTextChanged:) forControlEvents:UIControlEventEditingChanged];
|
||||
|
||||
if (w->type == KEYBOARD_TYPE_INTEGER) {
|
||||
if (w->inputType == KEYBOARD_TYPE_INTEGER) {
|
||||
[fld setKeyboardType:UIKeyboardTypeNumberPad];
|
||||
} else if (w->type == KEYBOARD_TYPE_PASSWORD) {
|
||||
} else if (w->inputType == KEYBOARD_TYPE_PASSWORD) {
|
||||
fld.secureTextEntry = YES;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue