mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-23 09:34:35 -05:00
simplify launcher widgets code
This commit is contained in:
parent
aabfab54cf
commit
e3eee65df1
4 changed files with 73 additions and 93 deletions
|
@ -686,6 +686,7 @@ void Entities_DrawShadows(void) {
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
struct _TabListData TabList;
|
struct _TabListData TabList;
|
||||||
|
|
||||||
|
/* Removes the names from the names buffer for the given id. */
|
||||||
static void TabList_Delete(EntityID id) {
|
static void TabList_Delete(EntityID id) {
|
||||||
int i, index;
|
int i, index;
|
||||||
index = TabList.NameOffsets[id];
|
index = TabList.NameOffsets[id];
|
||||||
|
@ -695,16 +696,16 @@ static void TabList_Delete(EntityID id) {
|
||||||
StringsBuffer_Remove(&TabList._buffer, index - 2);
|
StringsBuffer_Remove(&TabList._buffer, index - 2);
|
||||||
StringsBuffer_Remove(&TabList._buffer, index - 3);
|
StringsBuffer_Remove(&TabList._buffer, index - 3);
|
||||||
|
|
||||||
|
/* Indices after this entry need to be shifted down */
|
||||||
for (i = 0; i < TABLIST_MAX_NAMES; i++) {
|
for (i = 0; i < TABLIST_MAX_NAMES; i++) {
|
||||||
if (TabList.NameOffsets[i] > index) TabList.NameOffsets[i] -= 3;
|
if (TabList.NameOffsets[i] > index) TabList.NameOffsets[i] -= 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
TabList.NameOffsets[id] = 0;
|
|
||||||
TabList.GroupRanks[id] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabList_Remove(EntityID id) {
|
void TabList_Remove(EntityID id) {
|
||||||
TabList_Delete(id);
|
TabList_Delete(id);
|
||||||
|
TabList.NameOffsets[id] = 0;
|
||||||
|
TabList.GroupRanks[id] = 0;
|
||||||
Event_RaiseInt(&TabListEvents.Removed, id);
|
Event_RaiseInt(&TabListEvents.Removed, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -194,23 +194,19 @@ CC_NOINLINE static void LScreen_Reset(struct LScreen* s) {
|
||||||
*--------------------------------------------------------Widget helpers---------------------------------------------------*
|
*--------------------------------------------------------Widget helpers---------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
CC_NOINLINE static void LScreen_Button(struct LScreen* s, struct LButton* w, int width, int height, const char* text) {
|
CC_NOINLINE static void LScreen_Button(struct LScreen* s, struct LButton* w, int width, int height, const char* text) {
|
||||||
String str = String_FromReadonly(text);
|
LButton_Init(w, width, height);
|
||||||
LButton_Init(w, &Launcher_TitleFont, width, height);
|
LButton_SetConst(w, text);
|
||||||
LButton_SetText(w, &str);
|
|
||||||
s->widgets[s->numWidgets++] = (struct LWidget*)w;
|
s->widgets[s->numWidgets++] = (struct LWidget*)w;
|
||||||
}
|
}
|
||||||
|
|
||||||
CC_NOINLINE static void LScreen_Label(struct LScreen* s, struct LLabel* w, const char* text) {
|
CC_NOINLINE static void LScreen_Label(struct LScreen* s, struct LLabel* w, const char* text) {
|
||||||
String str = String_FromReadonly(text);
|
LLabel_Init(w);
|
||||||
LLabel_Init(w, &Launcher_TextFont);
|
LLabel_SetConst(w, text);
|
||||||
LLabel_SetText(w, &str);
|
|
||||||
s->widgets[s->numWidgets++] = (struct LWidget*)w;
|
s->widgets[s->numWidgets++] = (struct LWidget*)w;
|
||||||
}
|
}
|
||||||
|
|
||||||
CC_NOINLINE static void LScreen_Input(struct LScreen* s, struct LInput* w, int width, bool password, const char* hintText) {
|
CC_NOINLINE static void LScreen_Input(struct LScreen* s, struct LInput* w, int width, const char* hintText) {
|
||||||
LInput_Init(w, &Launcher_TextFont, width, 30,
|
LInput_Init(w, width, 30, hintText);
|
||||||
hintText, &Launcher_HintFont);
|
|
||||||
w->Password = password;
|
|
||||||
s->widgets[s->numWidgets++] = (struct LWidget*)w;
|
s->widgets[s->numWidgets++] = (struct LWidget*)w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +277,6 @@ static void UseModeClassicHax(void* w, int x, int y) { ChooseMode_Click(true, t
|
||||||
static void UseModeClassic(void* w, int x, int y) { ChooseMode_Click(true, false); }
|
static void UseModeClassic(void* w, int x, int y) { ChooseMode_Click(true, false); }
|
||||||
|
|
||||||
static void ChooseModeScreen_Init(struct LScreen* s_) {
|
static void ChooseModeScreen_Init(struct LScreen* s_) {
|
||||||
static const String titleText = String_FromConst("Choose game mode");
|
|
||||||
struct ChooseModeScreen* s = (struct ChooseModeScreen*)s_;
|
struct ChooseModeScreen* s = (struct ChooseModeScreen*)s_;
|
||||||
|
|
||||||
s->lblHelp.Hidden = !s->firstTime;
|
s->lblHelp.Hidden = !s->firstTime;
|
||||||
|
@ -315,8 +310,8 @@ static void ChooseModeScreen_Init(struct LScreen* s_) {
|
||||||
s->btnClassic.OnClick = UseModeClassic;
|
s->btnClassic.OnClick = UseModeClassic;
|
||||||
s->btnBack.OnClick = SwitchToSettings;
|
s->btnBack.OnClick = SwitchToSettings;
|
||||||
|
|
||||||
s->lblTitle.Font = Launcher_TitleFont;
|
s->lblTitle.Font = &Launcher_TitleFont;
|
||||||
LLabel_SetText(&s->lblTitle, &titleText);
|
LLabel_SetConst(&s->lblTitle, "Choose game mode");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ChooseModeScreen_Reposition(struct LScreen* s_) {
|
static void ChooseModeScreen_Reposition(struct LScreen* s_) {
|
||||||
|
@ -468,7 +463,7 @@ static void ColoursScreen_Init(struct LScreen* s_) {
|
||||||
s->widgets = s->_widgets;
|
s->widgets = s->_widgets;
|
||||||
|
|
||||||
for (i = 0; i < 5 * 3; i++) {
|
for (i = 0; i < 5 * 3; i++) {
|
||||||
LScreen_Input(s_, &s->iptColours[i], 55, false, NULL);
|
LScreen_Input(s_, &s->iptColours[i], 55, NULL);
|
||||||
s->iptColours[i].TextChanged = ColoursScreen_TextChanged;
|
s->iptColours[i].TextChanged = ColoursScreen_TextChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,11 +531,9 @@ static struct DirectConnectScreen {
|
||||||
struct LWidget* _widgets[6];
|
struct LWidget* _widgets[6];
|
||||||
} DirectConnectScreen_Instance;
|
} DirectConnectScreen_Instance;
|
||||||
|
|
||||||
CC_NOINLINE static void DirectConnectScreen_SetStatus(const char* msg) {
|
CC_NOINLINE static void DirectConnectScreen_SetStatus(const char* text) {
|
||||||
String str = String_FromReadonly(msg);
|
|
||||||
struct LLabel* w = &DirectConnectScreen_Instance.lblStatus;
|
struct LLabel* w = &DirectConnectScreen_Instance.lblStatus;
|
||||||
|
LLabel_SetConst(w, text);
|
||||||
LLabel_SetText(w, &str);
|
|
||||||
LWidget_Redraw(w);
|
LWidget_Redraw(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -616,9 +609,9 @@ static void DirectConnectScreen_Init(struct LScreen* s_) {
|
||||||
if (s->numWidgets) return;
|
if (s->numWidgets) return;
|
||||||
s->widgets = s->_widgets;
|
s->widgets = s->_widgets;
|
||||||
|
|
||||||
LScreen_Input(s_, &s->iptUsername, 330, false, "&gUsername..");
|
LScreen_Input(s_, &s->iptUsername, 330, "&gUsername..");
|
||||||
LScreen_Input(s_, &s->iptAddress, 330, false, "&gIP address:Port number..");
|
LScreen_Input(s_, &s->iptAddress, 330, "&gIP address:Port number..");
|
||||||
LScreen_Input(s_, &s->iptMppass, 330, false, "&gMppass..");
|
LScreen_Input(s_, &s->iptMppass, 330, "&gMppass..");
|
||||||
|
|
||||||
LScreen_Button(s_, &s->btnConnect, 110, 35, "Connect");
|
LScreen_Button(s_, &s->btnConnect, 110, 35, "Connect");
|
||||||
LScreen_Button(s_, &s->btnBack, 80, 35, "Back");
|
LScreen_Button(s_, &s->btnBack, 80, 35, "Back");
|
||||||
|
@ -702,20 +695,16 @@ CC_NOINLINE static void MainScreen_Error(struct LWebTask* task, const char* acti
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MainScreen_Login(void* w, int x, int y) {
|
static void MainScreen_Login(void* w, int x, int y) {
|
||||||
static const String needUser = String_FromConst("&eUsername required");
|
|
||||||
static const String needPass = String_FromConst("&ePassword required");
|
|
||||||
static const String signIn = String_FromConst("&e&eSigning in..");
|
|
||||||
|
|
||||||
struct MainScreen* s = &MainScreen_Instance;
|
struct MainScreen* s = &MainScreen_Instance;
|
||||||
String* user = &s->iptUsername.Text;
|
String* user = &s->iptUsername.Text;
|
||||||
String* pass = &s->iptPassword.Text;
|
String* pass = &s->iptPassword.Text;
|
||||||
|
|
||||||
if (!user->length) {
|
if (!user->length) {
|
||||||
LLabel_SetText(&s->lblStatus, &needUser);
|
LLabel_SetConst(&s->lblStatus, "&eUsername required");
|
||||||
LWidget_Redraw(&s->lblStatus); return;
|
LWidget_Redraw(&s->lblStatus); return;
|
||||||
}
|
}
|
||||||
if (!pass->length) {
|
if (!pass->length) {
|
||||||
LLabel_SetText(&s->lblStatus, &needPass);
|
LLabel_SetConst(&s->lblStatus, "&ePassword required");
|
||||||
LWidget_Redraw(&s->lblStatus); return;
|
LWidget_Redraw(&s->lblStatus); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -724,7 +713,7 @@ static void MainScreen_Login(void* w, int x, int y) {
|
||||||
Options_SetSecure("launcher-cc-password", pass, user);
|
Options_SetSecure("launcher-cc-password", pass, user);
|
||||||
|
|
||||||
GetTokenTask_Run();
|
GetTokenTask_Run();
|
||||||
LLabel_SetText(&s->lblStatus, &signIn);
|
LLabel_SetConst(&s->lblStatus, "&eSigning in..");
|
||||||
LWidget_Redraw(&s->lblStatus);
|
LWidget_Redraw(&s->lblStatus);
|
||||||
s->signingIn = true;
|
s->signingIn = true;
|
||||||
}
|
}
|
||||||
|
@ -752,7 +741,6 @@ static void MainScreen_Singleplayer(void* w, int x, int y) {
|
||||||
|
|
||||||
static void MainScreen_Init(struct LScreen* s_) {
|
static void MainScreen_Init(struct LScreen* s_) {
|
||||||
String user, pass; char passBuffer[STRING_SIZE];
|
String user, pass; char passBuffer[STRING_SIZE];
|
||||||
static const String update = String_FromConst("&eChecking..");
|
|
||||||
struct MainScreen* s = (struct MainScreen*)s_;
|
struct MainScreen* s = (struct MainScreen*)s_;
|
||||||
|
|
||||||
/* status should reset after user has gone to another menu */
|
/* status should reset after user has gone to another menu */
|
||||||
|
@ -760,8 +748,8 @@ static void MainScreen_Init(struct LScreen* s_) {
|
||||||
if (s->numWidgets) return;
|
if (s->numWidgets) return;
|
||||||
s->widgets = s->_widgets;
|
s->widgets = s->_widgets;
|
||||||
|
|
||||||
LScreen_Input(s_, &s->iptUsername, 280, false, "&gUsername..");
|
LScreen_Input(s_, &s->iptUsername, 280, "&gUsername..");
|
||||||
LScreen_Input(s_, &s->iptPassword, 280, true, "&gPassword..");
|
LScreen_Input(s_, &s->iptPassword, 280, "&gPassword..");
|
||||||
|
|
||||||
LScreen_Button(s_, &s->btnLogin, 100, 35, "Sign in");
|
LScreen_Button(s_, &s->btnLogin, 100, 35, "Sign in");
|
||||||
LScreen_Label(s_, &s->lblStatus, "");
|
LScreen_Label(s_, &s->lblStatus, "");
|
||||||
|
@ -782,8 +770,9 @@ static void MainScreen_Init(struct LScreen* s_) {
|
||||||
s->btnRegister.OnClick = MainScreen_Register;
|
s->btnRegister.OnClick = MainScreen_Register;
|
||||||
|
|
||||||
/* need to set text here for right size */
|
/* need to set text here for right size */
|
||||||
s->lblUpdate.Font = Launcher_HintFont;
|
s->lblUpdate.Font = &Launcher_HintFont;
|
||||||
LLabel_SetText(&s->lblUpdate, &update);
|
LLabel_SetConst(&s->lblUpdate, "&eChecking..");
|
||||||
|
s->iptPassword.Password = true;
|
||||||
|
|
||||||
String_InitArray(pass, passBuffer);
|
String_InitArray(pass, passBuffer);
|
||||||
Options_UNSAFE_Get("launcher-cc-username", &user);
|
Options_UNSAFE_Get("launcher-cc-username", &user);
|
||||||
|
@ -836,7 +825,7 @@ static void MainScreen_UnhoverWidget(struct LScreen* s_, struct LWidget* w) {
|
||||||
struct MainScreen* s = (struct MainScreen*)s_;
|
struct MainScreen* s = (struct MainScreen*)s_;
|
||||||
if (s->signingIn || w != (struct LWidget*)&s->btnResume) return;
|
if (s->signingIn || w != (struct LWidget*)&s->btnResume) return;
|
||||||
|
|
||||||
LLabel_SetText(&s->lblStatus, &String_Empty);
|
LLabel_SetConst(&s->lblStatus, "");
|
||||||
LWidget_Redraw(&s->lblStatus);
|
LWidget_Redraw(&s->lblStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -854,9 +843,6 @@ CC_NOINLINE static uint32_t MainScreen_GetVersion(const String* version) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MainScreen_TickCheckUpdates(struct MainScreen* s) {
|
static void MainScreen_TickCheckUpdates(struct MainScreen* s) {
|
||||||
static const String needUpdate = String_FromConst("&aNew release");
|
|
||||||
static const String upToDate = String_FromConst("&eUp to date");
|
|
||||||
static const String failed = String_FromConst("&cCheck failed");
|
|
||||||
static const String currentStr = String_FromConst(GAME_APP_VER);
|
static const String currentStr = String_FromConst(GAME_APP_VER);
|
||||||
uint32_t latest, current;
|
uint32_t latest, current;
|
||||||
|
|
||||||
|
@ -867,9 +853,9 @@ static void MainScreen_TickCheckUpdates(struct MainScreen* s) {
|
||||||
if (CheckUpdateTask.Base.Success) {
|
if (CheckUpdateTask.Base.Success) {
|
||||||
latest = MainScreen_GetVersion(&CheckUpdateTask.LatestRelease);
|
latest = MainScreen_GetVersion(&CheckUpdateTask.LatestRelease);
|
||||||
current = MainScreen_GetVersion(¤tStr);
|
current = MainScreen_GetVersion(¤tStr);
|
||||||
LLabel_SetText(&s->lblUpdate, latest > current ? &needUpdate : &upToDate);
|
LLabel_SetConst(&s->lblUpdate, latest > current ? "&aNew release" : "&eUp to date");
|
||||||
} else {
|
} else {
|
||||||
LLabel_SetText(&s->lblUpdate, &failed);
|
LLabel_SetConst(&s->lblUpdate, "&cCheck failed");
|
||||||
}
|
}
|
||||||
LWidget_Redraw(&s->lblUpdate);
|
LWidget_Redraw(&s->lblUpdate);
|
||||||
}
|
}
|
||||||
|
@ -887,7 +873,6 @@ static void MainScreen_TickGetToken(struct MainScreen* s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MainScreen_TickSignIn(struct MainScreen* s) {
|
static void MainScreen_TickSignIn(struct MainScreen* s) {
|
||||||
static const String fetchMsg = String_FromConst("&eRetrieving servers list..");
|
|
||||||
if (!SignInTask.Base.Working) return;
|
if (!SignInTask.Base.Working) return;
|
||||||
LWebTask_Tick(&SignInTask.Base);
|
LWebTask_Tick(&SignInTask.Base);
|
||||||
if (!SignInTask.Base.Completed) return;
|
if (!SignInTask.Base.Completed) return;
|
||||||
|
@ -903,7 +888,7 @@ static void MainScreen_TickSignIn(struct MainScreen* s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
FetchServersTask_Run();
|
FetchServersTask_Run();
|
||||||
LLabel_SetText(&s->lblStatus, &fetchMsg);
|
LLabel_SetConst(&s->lblStatus, "&eRetrieving servers list..");
|
||||||
LWidget_Redraw(&s->lblStatus);
|
LWidget_Redraw(&s->lblStatus);
|
||||||
} else {
|
} else {
|
||||||
MainScreen_Error(&SignInTask.Base, "signing in");
|
MainScreen_Error(&SignInTask.Base, "signing in");
|
||||||
|
@ -1017,7 +1002,7 @@ static void ResourcesScreen_Init(struct LScreen* s_) {
|
||||||
String_InitArray(str, buffer);
|
String_InitArray(str, buffer);
|
||||||
size = Resources_Size / 1024.0f;
|
size = Resources_Size / 1024.0f;
|
||||||
|
|
||||||
s->lblStatus.Font = Launcher_HintFont;
|
s->lblStatus.Font = &Launcher_HintFont;
|
||||||
String_Format1(&str, "&eDownload size: %f2 megabytes", &size);
|
String_Format1(&str, "&eDownload size: %f2 megabytes", &size);
|
||||||
LLabel_SetText(&s->lblStatus, &str);
|
LLabel_SetText(&s->lblStatus, &str);
|
||||||
|
|
||||||
|
@ -1160,13 +1145,12 @@ static void ServersScreen_Connect(void* w, int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ServersScreen_Refresh(void* w, int x, int y) {
|
static void ServersScreen_Refresh(void* w, int x, int y) {
|
||||||
static const String working = String_FromConst("&eWorking..");
|
|
||||||
struct LButton* btn;
|
struct LButton* btn;
|
||||||
if (FetchServersTask.Base.Working) return;
|
if (FetchServersTask.Base.Working) return;
|
||||||
|
|
||||||
FetchServersTask_Run();
|
FetchServersTask_Run();
|
||||||
btn = &ServersScreen_Instance.btnRefresh;
|
btn = &ServersScreen_Instance.btnRefresh;
|
||||||
LButton_SetText(btn, &working);
|
LButton_SetConst(btn, "&eWorking..");
|
||||||
LWidget_Redraw(btn);
|
LWidget_Redraw(btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1215,8 +1199,8 @@ static void ServersScreen_InitWidgets(struct LScreen* s_) {
|
||||||
struct ServersScreen* s = (struct ServersScreen*)s_;
|
struct ServersScreen* s = (struct ServersScreen*)s_;
|
||||||
s->widgets = s->_widgets;
|
s->widgets = s->_widgets;
|
||||||
|
|
||||||
LScreen_Input(s_, &s->iptSearch, 370, false, "&gSearch servers..");
|
LScreen_Input(s_, &s->iptSearch, 370, "&gSearch servers..");
|
||||||
LScreen_Input(s_, &s->iptHash, 475, false, "&gclassicube.net/server/play/...");
|
LScreen_Input(s_, &s->iptHash, 475, "&gclassicube.net/server/play/...");
|
||||||
|
|
||||||
LScreen_Button(s_, &s->btnBack, 110, 30, "Back");
|
LScreen_Button(s_, &s->btnBack, 110, 30, "Back");
|
||||||
LScreen_Button(s_, &s->btnConnect, 130, 30, "Connect");
|
LScreen_Button(s_, &s->btnConnect, 130, 30, "Connect");
|
||||||
|
@ -1230,7 +1214,7 @@ static void ServersScreen_InitWidgets(struct LScreen* s_) {
|
||||||
s->iptHash.TextChanged = ServersScreen_HashChanged;
|
s->iptHash.TextChanged = ServersScreen_HashChanged;
|
||||||
s->iptHash.ClipboardFilter = ServersScreen_HashFilter;
|
s->iptHash.ClipboardFilter = ServersScreen_HashFilter;
|
||||||
|
|
||||||
LTable_Init(&s->table, &Launcher_TextFont, &s->rowFont);
|
LTable_Init(&s->table, &s->rowFont);
|
||||||
s->table.Filter = &s->iptSearch.Text;
|
s->table.Filter = &s->iptSearch.Text;
|
||||||
s->table.SelectedHash = &s->iptHash.Text;
|
s->table.SelectedHash = &s->iptHash.Text;
|
||||||
s->table.OnSelectedChanged = ServersScreen_OnSelectedChanged;
|
s->table.OnSelectedChanged = ServersScreen_OnSelectedChanged;
|
||||||
|
@ -1243,7 +1227,7 @@ static void ServersScreen_Init(struct LScreen* s_) {
|
||||||
Drawer2D_MakeFont(&s->rowFont, 11, FONT_STYLE_NORMAL);
|
Drawer2D_MakeFont(&s->rowFont, 11, FONT_STYLE_NORMAL);
|
||||||
|
|
||||||
if (!s->numWidgets) ServersScreen_InitWidgets(s_);
|
if (!s->numWidgets) ServersScreen_InitWidgets(s_);
|
||||||
s->table.RowFont = s->rowFont;
|
s->table.RowFont = &s->rowFont;
|
||||||
/* also resets hash and filter */
|
/* also resets hash and filter */
|
||||||
LTable_Reset(&s->table);
|
LTable_Reset(&s->table);
|
||||||
|
|
||||||
|
@ -1252,8 +1236,6 @@ static void ServersScreen_Init(struct LScreen* s_) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ServersScreen_Tick(struct LScreen* s_) {
|
static void ServersScreen_Tick(struct LScreen* s_) {
|
||||||
static const String refresh = String_FromConst("Refresh");
|
|
||||||
static const String failed = String_FromConst("&cFailed");
|
|
||||||
struct ServersScreen* s = (struct ServersScreen*)s_;
|
struct ServersScreen* s = (struct ServersScreen*)s_;
|
||||||
int count;
|
int count;
|
||||||
LScreen_Tick(s_);
|
LScreen_Tick(s_);
|
||||||
|
@ -1272,8 +1254,8 @@ static void ServersScreen_Tick(struct LScreen* s_) {
|
||||||
LWidget_Draw(&s->table);
|
LWidget_Draw(&s->table);
|
||||||
}
|
}
|
||||||
|
|
||||||
LButton_SetText(&s->btnRefresh,
|
LButton_SetConst(&s->btnRefresh,
|
||||||
FetchServersTask.Base.Success ? &refresh : &failed);
|
FetchServersTask.Base.Success ? "Refresh" : "&cFailed");
|
||||||
LWidget_Redraw(&s->btnRefresh);
|
LWidget_Redraw(&s->btnRefresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -116,7 +116,7 @@ static void LButton_Draw(void* widget) {
|
||||||
|
|
||||||
xOffset = w->Width - w->_TextSize.Width;
|
xOffset = w->Width - w->_TextSize.Width;
|
||||||
yOffset = w->Height - w->_TextSize.Height;
|
yOffset = w->Height - w->_TextSize.Height;
|
||||||
DrawTextArgs_Make(&args, &w->Text, &w->Font, true);
|
DrawTextArgs_Make(&args, &w->Text, &Launcher_TitleFont, true);
|
||||||
|
|
||||||
LButton_DrawBackground(w);
|
LButton_DrawBackground(w);
|
||||||
LButton_DrawBorder(w);
|
LButton_DrawBorder(w);
|
||||||
|
@ -141,19 +141,17 @@ static struct LWidgetVTABLE lbutton_VTABLE = {
|
||||||
LButton_Hover, LButton_Draw, /* Hover */
|
LButton_Hover, LButton_Draw, /* Hover */
|
||||||
NULL, NULL /* Select */
|
NULL, NULL /* Select */
|
||||||
};
|
};
|
||||||
void LButton_Init(struct LButton* w, const FontDesc* font, int width, int height) {
|
void LButton_Init(struct LButton* w, int width, int height) {
|
||||||
w->VTABLE = &lbutton_VTABLE;
|
w->VTABLE = &lbutton_VTABLE;
|
||||||
w->TabSelectable = true;
|
w->TabSelectable = true;
|
||||||
w->Font = *font;
|
|
||||||
w->Width = Display_ScaleX(width);
|
w->Width = Display_ScaleX(width);
|
||||||
w->Height = Display_ScaleY(height);
|
w->Height = Display_ScaleY(height);
|
||||||
String_InitArray(w->Text, w->_TextBuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LButton_SetText(struct LButton* w, const String* text) {
|
void LButton_SetConst(struct LButton* w, const char* text) {
|
||||||
struct DrawTextArgs args;
|
struct DrawTextArgs args;
|
||||||
String_Copy(&w->Text, text);
|
w->Text = String_FromReadonly(text);
|
||||||
DrawTextArgs_Make(&args, text, &w->Font, true);
|
DrawTextArgs_Make(&args, &w->Text, &Launcher_TitleFont, true);
|
||||||
w->_TextSize = Drawer2D_MeasureText(&args);
|
w->_TextSize = Drawer2D_MeasureText(&args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +235,7 @@ static void LInput_DrawText(struct LInput* w, struct DrawTextArgs* args) {
|
||||||
Drawer2D_DrawText(&Launcher_Framebuffer, args, w->X + 5, y + 2);
|
Drawer2D_DrawText(&Launcher_Framebuffer, args, w->X + 5, y + 2);
|
||||||
} else {
|
} else {
|
||||||
args->text = String_FromReadonly(w->HintText);
|
args->text = String_FromReadonly(w->HintText);
|
||||||
args->font = w->HintFont;
|
args->font = Launcher_HintFont;
|
||||||
|
|
||||||
hintHeight = Drawer2D_MeasureText(args).Height;
|
hintHeight = Drawer2D_MeasureText(args).Height;
|
||||||
y = w->Y + (w->Height - hintHeight) / 2;
|
y = w->Y + (w->Height - hintHeight) / 2;
|
||||||
|
@ -256,7 +254,7 @@ static void LInput_Draw(void* widget) {
|
||||||
|
|
||||||
String_InitArray(text, textBuffer);
|
String_InitArray(text, textBuffer);
|
||||||
LInput_GetText(w, &text);
|
LInput_GetText(w, &text);
|
||||||
DrawTextArgs_Make(&args, &text, &w->Font, false);
|
DrawTextArgs_Make(&args, &text, &Launcher_TextFont, false);
|
||||||
|
|
||||||
size = Drawer2D_MeasureText(&args);
|
size = Drawer2D_MeasureText(&args);
|
||||||
w->Width = max(w->MinWidth, size.Width + 20);
|
w->Width = max(w->MinWidth, size.Width + 20);
|
||||||
|
@ -282,7 +280,7 @@ static Rect2D LInput_MeasureCaret(struct LInput* w) {
|
||||||
|
|
||||||
String_InitArray(text, textBuffer);
|
String_InitArray(text, textBuffer);
|
||||||
LInput_GetText(w, &text);
|
LInput_GetText(w, &text);
|
||||||
DrawTextArgs_Make(&args, &text, &w->Font, true);
|
DrawTextArgs_Make(&args, &text, &Launcher_TextFont, true);
|
||||||
|
|
||||||
r.X = w->X + 5;
|
r.X = w->X + 5;
|
||||||
r.Y = w->Y + w->Height - 5; r.Height = 2;
|
r.Y = w->Y + w->Height - 5; r.Height = 2;
|
||||||
|
@ -361,7 +359,7 @@ static void LInput_MoveCaretToCursor(struct LInput* w) {
|
||||||
LInput_GetText(w, &text);
|
LInput_GetText(w, &text);
|
||||||
x -= w->X; y -= w->Y;
|
x -= w->X; y -= w->Y;
|
||||||
|
|
||||||
DrawTextArgs_Make(&args, &text, &w->Font, true);
|
DrawTextArgs_Make(&args, &text, &Launcher_TextFont, true);
|
||||||
if (x >= Drawer2D_TextWidth(&args)) {
|
if (x >= Drawer2D_TextWidth(&args)) {
|
||||||
w->CaretPos = -1; return;
|
w->CaretPos = -1; return;
|
||||||
}
|
}
|
||||||
|
@ -436,18 +434,16 @@ static struct LWidgetVTABLE linput_VTABLE = {
|
||||||
/* TODO: Don't redraw whole thing, just the outer border */
|
/* TODO: Don't redraw whole thing, just the outer border */
|
||||||
LInput_Select, LInput_Unselect /* Select */
|
LInput_Select, LInput_Unselect /* Select */
|
||||||
};
|
};
|
||||||
void LInput_Init(struct LInput* w, const FontDesc* font, int width, int height, const char* hintText, const FontDesc* hintFont) {
|
void LInput_Init(struct LInput* w, int width, int height, const char* hintText) {
|
||||||
w->VTABLE = &linput_VTABLE;
|
w->VTABLE = &linput_VTABLE;
|
||||||
w->TabSelectable = true;
|
w->TabSelectable = true;
|
||||||
String_InitArray(w->Text, w->_TextBuffer);
|
String_InitArray(w->Text, w->_TextBuffer);
|
||||||
w->Font = *font;
|
|
||||||
|
|
||||||
w->Width = Display_ScaleX(width);
|
w->Width = Display_ScaleX(width);
|
||||||
w->Height = Display_ScaleY(height);
|
w->Height = Display_ScaleY(height);
|
||||||
w->MinWidth = w->Width;
|
w->MinWidth = w->Width;
|
||||||
LWidget_CalcPosition(w);
|
LWidget_CalcPosition(w);
|
||||||
|
|
||||||
w->HintFont = *hintFont;
|
|
||||||
w->HintText = hintText;
|
w->HintText = hintText;
|
||||||
w->CaretPos = -1;
|
w->CaretPos = -1;
|
||||||
}
|
}
|
||||||
|
@ -460,7 +456,7 @@ void LInput_SetText(struct LInput* w, const String* text_) {
|
||||||
String_Copy(&w->Text, text_);
|
String_Copy(&w->Text, text_);
|
||||||
String_InitArray(text, textBuffer);
|
String_InitArray(text, textBuffer);
|
||||||
LInput_GetText(w, &text);
|
LInput_GetText(w, &text);
|
||||||
DrawTextArgs_Make(&args, &text, &w->Font, true);
|
DrawTextArgs_Make(&args, &text, &Launcher_TextFont, true);
|
||||||
|
|
||||||
size = Drawer2D_MeasureText(&args);
|
size = Drawer2D_MeasureText(&args);
|
||||||
w->Width = max(w->MinWidth, size.Width + 20);
|
w->Width = max(w->MinWidth, size.Width + 20);
|
||||||
|
@ -541,7 +537,7 @@ static void LLabel_Draw(void* widget) {
|
||||||
struct DrawTextArgs args;
|
struct DrawTextArgs args;
|
||||||
if (w->Hidden) return;
|
if (w->Hidden) return;
|
||||||
|
|
||||||
DrawTextArgs_Make(&args, &w->Text, &w->Font, true);
|
DrawTextArgs_Make(&args, &w->Text, w->Font, true);
|
||||||
Drawer2D_DrawText(&Launcher_Framebuffer, &args, w->X, w->Y);
|
Drawer2D_DrawText(&Launcher_Framebuffer, &args, w->X, w->Y);
|
||||||
Launcher_MarkDirty(w->X, w->Y, w->Width, w->Height);
|
Launcher_MarkDirty(w->X, w->Y, w->Width, w->Height);
|
||||||
}
|
}
|
||||||
|
@ -552,10 +548,10 @@ static struct LWidgetVTABLE llabel_VTABLE = {
|
||||||
NULL, NULL, /* Hover */
|
NULL, NULL, /* Hover */
|
||||||
NULL, NULL /* Select */
|
NULL, NULL /* Select */
|
||||||
};
|
};
|
||||||
void LLabel_Init(struct LLabel* w, const FontDesc* font) {
|
void LLabel_Init(struct LLabel* w) {
|
||||||
w->VTABLE = &llabel_VTABLE;
|
w->VTABLE = &llabel_VTABLE;
|
||||||
String_InitArray(w->Text, w->_TextBuffer);
|
String_InitArray(w->Text, w->_TextBuffer);
|
||||||
w->Font = *font;
|
w->Font = &Launcher_TextFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LLabel_SetText(struct LLabel* w, const String* text) {
|
void LLabel_SetText(struct LLabel* w, const String* text) {
|
||||||
|
@ -563,12 +559,17 @@ void LLabel_SetText(struct LLabel* w, const String* text) {
|
||||||
Size2D size;
|
Size2D size;
|
||||||
String_Copy(&w->Text, text);
|
String_Copy(&w->Text, text);
|
||||||
|
|
||||||
DrawTextArgs_Make(&args, &w->Text, &w->Font, true);
|
DrawTextArgs_Make(&args, &w->Text, w->Font, true);
|
||||||
size = Drawer2D_MeasureText(&args);
|
size = Drawer2D_MeasureText(&args);
|
||||||
w->Width = size.Width; w->Height = size.Height;
|
w->Width = size.Width; w->Height = size.Height;
|
||||||
LWidget_CalcPosition(w);
|
LWidget_CalcPosition(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LLabel_SetConst(struct LLabel* w, const char* text) {
|
||||||
|
String str = String_FromReadonly(text);
|
||||||
|
LLabel_SetText(w, &str);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*########################################################################################################################*
|
/*########################################################################################################################*
|
||||||
*-------------------------------------------------------BoxWidget---------------------------------------------------------*
|
*-------------------------------------------------------BoxWidget---------------------------------------------------------*
|
||||||
|
@ -849,7 +850,7 @@ static void LTable_DrawHeaders(struct LTable* w) {
|
||||||
struct DrawTextArgs args;
|
struct DrawTextArgs args;
|
||||||
int i, x, y;
|
int i, x, y;
|
||||||
|
|
||||||
DrawTextArgs_MakeEmpty(&args, &w->HdrFont, true);
|
DrawTextArgs_MakeEmpty(&args, &Launcher_TextFont, true);
|
||||||
x = w->X; y = w->Y;
|
x = w->X; y = w->Y;
|
||||||
|
|
||||||
for (i = 0; i < w->NumColumns; i++) {
|
for (i = 0; i < w->NumColumns; i++) {
|
||||||
|
@ -871,7 +872,7 @@ static void LTable_DrawRows(struct LTable* w) {
|
||||||
int i, x, y, row, end;
|
int i, x, y, row, end;
|
||||||
|
|
||||||
String_InitArray(str, strBuffer);
|
String_InitArray(str, strBuffer);
|
||||||
DrawTextArgs_Make(&args, &str, &w->RowFont, true);
|
DrawTextArgs_Make(&args, &str, w->RowFont, true);
|
||||||
y = w->RowsBegY;
|
y = w->RowsBegY;
|
||||||
end = w->TopRow + w->VisibleRows;
|
end = w->TopRow + w->VisibleRows;
|
||||||
|
|
||||||
|
@ -1055,8 +1056,8 @@ static void LTable_StopDragging(void* widget) {
|
||||||
|
|
||||||
void LTable_Reposition(struct LTable* w) {
|
void LTable_Reposition(struct LTable* w) {
|
||||||
int rowsHeight;
|
int rowsHeight;
|
||||||
w->HdrHeight = Drawer2D_FontHeight(&w->HdrFont, true) + HDR_YPADDING;
|
w->HdrHeight = Drawer2D_FontHeight(&Launcher_TextFont, true) + HDR_YPADDING;
|
||||||
w->RowHeight = Drawer2D_FontHeight(&w->RowFont, true) + ROW_YPADDING;
|
w->RowHeight = Drawer2D_FontHeight(w->RowFont, true) + ROW_YPADDING;
|
||||||
|
|
||||||
w->RowsBegY = w->Y + w->HdrHeight + w->GridlineHeight;
|
w->RowsBegY = w->Y + w->HdrHeight + w->GridlineHeight;
|
||||||
w->RowsEndY = w->Y + w->Height;
|
w->RowsEndY = w->Y + w->Height;
|
||||||
|
@ -1082,13 +1083,11 @@ static struct LWidgetVTABLE ltable_VTABLE = {
|
||||||
LTable_MouseDown, LTable_StopDragging, /* Select */
|
LTable_MouseDown, LTable_StopDragging, /* Select */
|
||||||
LTable_MouseWheel, /* Wheel */
|
LTable_MouseWheel, /* Wheel */
|
||||||
};
|
};
|
||||||
void LTable_Init(struct LTable* w, const FontDesc* hdrFont, const FontDesc* rowFont) {
|
void LTable_Init(struct LTable* w, FontDesc* rowFont) {
|
||||||
w->VTABLE = <able_VTABLE;
|
w->VTABLE = <able_VTABLE;
|
||||||
w->Columns = tableColumns;
|
w->Columns = tableColumns;
|
||||||
w->NumColumns = Array_Elems(tableColumns);
|
w->NumColumns = Array_Elems(tableColumns);
|
||||||
|
w->RowFont = rowFont;
|
||||||
w->HdrFont = *hdrFont;
|
|
||||||
w->RowFont = *rowFont;
|
|
||||||
|
|
||||||
w->ScrollbarWidth = Display_ScaleX(10);
|
w->ScrollbarWidth = Display_ScaleX(10);
|
||||||
w->GridlineWidth = Display_ScaleX(2);
|
w->GridlineWidth = Display_ScaleX(2);
|
||||||
|
|
|
@ -52,12 +52,10 @@ void LWidget_Redraw(void* widget);
|
||||||
struct LButton {
|
struct LButton {
|
||||||
LWidget_Layout
|
LWidget_Layout
|
||||||
String Text;
|
String Text;
|
||||||
FontDesc Font;
|
|
||||||
Size2D _TextSize;
|
Size2D _TextSize;
|
||||||
char _TextBuffer[STRING_SIZE];
|
|
||||||
};
|
};
|
||||||
CC_NOINLINE void LButton_Init(struct LButton* w, const FontDesc* font, int width, int height);
|
CC_NOINLINE void LButton_Init(struct LButton* w, int width, int height);
|
||||||
CC_NOINLINE void LButton_SetText(struct LButton* w, const String* text);
|
CC_NOINLINE void LButton_SetConst(struct LButton* w, const char* text);
|
||||||
|
|
||||||
struct LInput;
|
struct LInput;
|
||||||
struct LInput {
|
struct LInput {
|
||||||
|
@ -74,12 +72,11 @@ struct LInput {
|
||||||
/* Specifies the position that characters are inserted/deleted from. */
|
/* Specifies the position that characters are inserted/deleted from. */
|
||||||
/* NOTE: -1 to insert/delete characters at end of the text. */
|
/* NOTE: -1 to insert/delete characters at end of the text. */
|
||||||
int CaretPos;
|
int CaretPos;
|
||||||
FontDesc Font, HintFont;
|
|
||||||
String Text;
|
String Text;
|
||||||
int _TextHeight;
|
int _TextHeight;
|
||||||
char _TextBuffer[STRING_SIZE];
|
char _TextBuffer[STRING_SIZE];
|
||||||
};
|
};
|
||||||
CC_NOINLINE void LInput_Init(struct LInput* w, const FontDesc* font, int width, int height, const char* hintText, const FontDesc* hintFont);
|
CC_NOINLINE void LInput_Init(struct LInput* w, int width, int height, const char* hintText);
|
||||||
CC_NOINLINE void LInput_SetText(struct LInput* w, const String* text);
|
CC_NOINLINE void LInput_SetText(struct LInput* w, const String* text);
|
||||||
|
|
||||||
/* Appends a character to the currently entered text. */
|
/* Appends a character to the currently entered text. */
|
||||||
|
@ -96,13 +93,14 @@ CC_NOINLINE bool LInput_Clear(struct LInput* w);
|
||||||
/* Represents non-interactable text. */
|
/* Represents non-interactable text. */
|
||||||
struct LLabel {
|
struct LLabel {
|
||||||
LWidget_Layout
|
LWidget_Layout
|
||||||
FontDesc Font;
|
FontDesc* Font;
|
||||||
String Text;
|
String Text;
|
||||||
Size2D _TextSize;
|
Size2D _TextSize;
|
||||||
char _TextBuffer[STRING_SIZE];
|
char _TextBuffer[STRING_SIZE];
|
||||||
};
|
};
|
||||||
CC_NOINLINE void LLabel_Init(struct LLabel* w, const FontDesc* font);
|
CC_NOINLINE void LLabel_Init(struct LLabel* w);
|
||||||
CC_NOINLINE void LLabel_SetText(struct LLabel* w, const String* text);
|
CC_NOINLINE void LLabel_SetText(struct LLabel* w, const String* text);
|
||||||
|
CC_NOINLINE void LLabel_SetConst(struct LLabel* w, const char* text);
|
||||||
|
|
||||||
/* Represents a coloured rectangle. Usually used as a line separator. */
|
/* Represents a coloured rectangle. Usually used as a line separator. */
|
||||||
struct LBox {
|
struct LBox {
|
||||||
|
@ -149,8 +147,8 @@ struct LTable {
|
||||||
struct LTableColumn* Columns;
|
struct LTableColumn* Columns;
|
||||||
/* Number of columns in the table. */
|
/* Number of columns in the table. */
|
||||||
int NumColumns;
|
int NumColumns;
|
||||||
/* Fonts for text in header and rows. */
|
/* Fonts for text in rows. */
|
||||||
FontDesc RowFont, HdrFont;
|
FontDesc* RowFont;
|
||||||
/* Y start and end of rows and height of each row. */
|
/* Y start and end of rows and height of each row. */
|
||||||
int RowsBegY, RowsEndY, RowHeight;
|
int RowsBegY, RowsEndY, RowHeight;
|
||||||
/* Y height of headers. */
|
/* Y height of headers. */
|
||||||
|
@ -186,7 +184,7 @@ struct LTable {
|
||||||
|
|
||||||
/* Initialises a table. */
|
/* Initialises a table. */
|
||||||
/* NOTE: Must also call LTable_Reset to make a table actually useful. */
|
/* NOTE: Must also call LTable_Reset to make a table actually useful. */
|
||||||
void LTable_Init(struct LTable* table, const FontDesc* hdrFont, const FontDesc* rowFont);
|
void LTable_Init(struct LTable* table, FontDesc* rowFont);
|
||||||
/* Resets state of a table (reset sorter, filter, etc) */
|
/* Resets state of a table (reset sorter, filter, etc) */
|
||||||
void LTable_Reset(struct LTable* table);
|
void LTable_Reset(struct LTable* table);
|
||||||
/* Adjusts Y position of rows and number of visible rows. */
|
/* Adjusts Y position of rows and number of visible rows. */
|
||||||
|
|
Loading…
Add table
Reference in a new issue