diff --git a/src/LBackend.c b/src/LBackend.c index 32d976f81..ed81aca5f 100644 --- a/src/LBackend.c +++ b/src/LBackend.c @@ -57,15 +57,15 @@ CC_NOINLINE static void ClearTile(int x, int y, int width, int height, struct Bi } void LBackend_ResetArea(int x, int y, int width, int height) { - if (Launcher_ClassicBackground && dirtBmp.scan0) { + if (Launcher_Theme.ClassicBackground && dirtBmp.scan0) { ClearTile(x, y, width, height, &stoneBmp); } else { - Gradient_Noise(&Launcher_Framebuffer, Launcher_BackgroundColor, 6, x, y, width, height); + Gradient_Noise(&Launcher_Framebuffer, Launcher_Theme.BackgroundColor, 6, x, y, width, height); } } void LBackend_ResetPixels(void) { - if (Launcher_ClassicBackground && dirtBmp.scan0) { + if (Launcher_Theme.ClassicBackground && dirtBmp.scan0) { ClearTile(0, 0, WindowInfo.Width, TILESIZE, &dirtBmp); ClearTile(0, TILESIZE, WindowInfo.Width, WindowInfo.Height - TILESIZE, &stoneBmp); } else { @@ -89,6 +89,21 @@ void LBackend_CalcOffsets(void) { yInputOffset = Display_ScaleY(2); } +static void DrawBoxBounds(BitmapCol col, int x, int y, int width, int height) { + Drawer2D_Clear(&Launcher_Framebuffer, col, + x, y, + width, yBorder); + Drawer2D_Clear(&Launcher_Framebuffer, col, + x, y + height - yBorder, + width, yBorder); + Drawer2D_Clear(&Launcher_Framebuffer, col, + x, y, + xBorder, height); + Drawer2D_Clear(&Launcher_Framebuffer, col, + x + width - xBorder, y, + xBorder, height); +} + /*########################################################################################################################* *------------------------------------------------------ButtonWidget-------------------------------------------------------* @@ -102,17 +117,15 @@ static BitmapCol LButton_Expand(BitmapCol a, int amount) { } static void LButton_DrawBackground(struct LButton* w) { - BitmapCol activeCol = BitmapCol_Make(126, 136, 191, 255); - BitmapCol inactiveCol = BitmapCol_Make(111, 111, 111, 255); - BitmapCol col; + BitmapCol col = w->hovered ? Launcher_Theme.ButtonForeActiveColor + : Launcher_Theme.ButtonForeColor; - if (Launcher_ClassicBackground) { - col = w->hovered ? activeCol : inactiveCol; + if (Launcher_Theme.ClassicBackground) { Gradient_Noise(&Launcher_Framebuffer, col, 8, w->x + xBorder, w->y + yBorder, w->width - xBorder2, w->height - yBorder2); } else { - col = w->hovered ? Launcher_ButtonForeActiveColor : Launcher_ButtonForeColor; + Gradient_Vertical(&Launcher_Framebuffer, LButton_Expand(col, 8), LButton_Expand(col, -8), w->x + xBorder, w->y + yBorder, w->width - xBorder2, w->height - yBorder2); @@ -120,9 +133,7 @@ static void LButton_DrawBackground(struct LButton* w) { } static void LButton_DrawBorder(struct LButton* w) { - BitmapCol black = BitmapCol_Make(0, 0, 0, 255); - BitmapCol backCol = Launcher_ClassicBackground ? black : Launcher_ButtonBorderColor; - + BitmapCol backCol = Launcher_Theme.ButtonBorderColor; Drawer2D_Clear(&Launcher_Framebuffer, backCol, w->x + xBorder, w->y, w->width - xBorder2, yBorder); @@ -138,20 +149,20 @@ static void LButton_DrawBorder(struct LButton* w) { } static void LButton_DrawHighlight(struct LButton* w) { - BitmapCol activeCol = BitmapCol_Make(189, 198, 255, 255); - BitmapCol inactiveCol = BitmapCol_Make(168, 168, 168, 255); - BitmapCol highlightCol; + BitmapCol activeCol = BitmapCol_Make(189, 198, 255, 255); + BitmapCol col = Launcher_Theme.ButtonHighlightColor; - if (Launcher_ClassicBackground) { - highlightCol = w->hovered ? activeCol : inactiveCol; - Drawer2D_Clear(&Launcher_Framebuffer, highlightCol, + if (Launcher_Theme.ClassicBackground) { + if (w->hovered) col = activeCol; + + Drawer2D_Clear(&Launcher_Framebuffer, col, w->x + xBorder2, w->y + yBorder, w->width - xBorder4, yBorder); - Drawer2D_Clear(&Launcher_Framebuffer, highlightCol, + Drawer2D_Clear(&Launcher_Framebuffer, col, w->x + xBorder, w->y + yBorder2, xBorder, w->height - yBorder4); } else if (!w->hovered) { - Drawer2D_Clear(&Launcher_Framebuffer, Launcher_ButtonHighlightColor, + Drawer2D_Clear(&Launcher_Framebuffer, col, w->x + xBorder2, w->y + yBorder, w->width - xBorder4, yBorder); } @@ -177,6 +188,81 @@ void LBackend_DrawButton(struct LButton* w) { } +/*########################################################################################################################* +*-----------------------------------------------------CheckboxWidget------------------------------------------------------* +*#########################################################################################################################*/ +/* Based off checkbox from original ClassiCube Launcher */ +static const cc_uint8 checkbox_indices[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x06, 0x07, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x06, 0x09, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x06, 0x0B, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0D, 0x0E, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0F, 0x06, 0x10, 0x00, 0x11, 0x06, 0x12, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x13, 0x14, 0x15, 0x00, 0x16, 0x17, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x18, 0x06, 0x19, 0x06, 0x1A, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1B, 0x06, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x1D, 0x06, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; +static PackedCol checkbox_palette[] = { + PackedCol_Make( 0, 0, 0, 0), PackedCol_Make(144, 144, 144, 255), + PackedCol_Make( 61, 61, 61, 255), PackedCol_Make( 94, 94, 94, 255), + PackedCol_Make(197, 196, 197, 255), PackedCol_Make( 57, 57, 57, 255), + PackedCol_Make( 33, 33, 33, 255), PackedCol_Make(177, 177, 177, 255), + PackedCol_Make(189, 189, 189, 255), PackedCol_Make( 67, 67, 67, 255), + PackedCol_Make(108, 108, 108, 255), PackedCol_Make(171, 171, 171, 255), + PackedCol_Make(220, 220, 220, 255), PackedCol_Make( 43, 43, 43, 255), + PackedCol_Make( 63, 63, 63, 255), PackedCol_Make(100, 100, 100, 255), + PackedCol_Make(192, 192, 192, 255), PackedCol_Make(132, 132, 132, 255), + PackedCol_Make(175, 175, 175, 255), PackedCol_Make(217, 217, 217, 255), + PackedCol_Make( 42, 42, 42, 255), PackedCol_Make( 86, 86, 86, 255), + PackedCol_Make( 56, 56, 56, 255), PackedCol_Make( 76, 76, 76, 255), + PackedCol_Make(139, 139, 139, 255), PackedCol_Make(130, 130, 130, 255), + PackedCol_Make(181, 181, 181, 255), PackedCol_Make( 62, 62, 62, 255), + PackedCol_Make( 75, 75, 75, 255), PackedCol_Make(184, 184, 184, 255), +}; + +static void DrawIndexed(int size, int x, int y, struct Bitmap* bmp) { + BitmapCol* row; + int i, xx, yy; + + for (i = 0, yy = 0; yy < size; yy++) { + if ((y + yy) < 0) { i += size; continue; } + if ((y + yy) >= bmp->height) break; + int* row = Bitmap_GetRow(bmp, y + yy); + + for (xx = 0; xx < size; xx++) { + int col = checkbox_palette[checkbox_indices[i++]]; + if (col == 0) continue; /* transparent pixel */ + if ((x + xx) < 0 || (x + xx) >= bmp->width) continue; + row[x + xx] = col; + } + } +} + +void LBackend_DrawCheckbox(struct LCheckbox* w) { + PackedCol boxTop = PackedCol_Make(255, 255, 255, 255); + PackedCol boxBottom = PackedCol_Make(240, 240, 240, 255); + PackedCol black = PackedCol_Make(0, 0, 0, 255); + int height = w->height / 2; + + Gradient_Vertical(&Launcher_Framebuffer, boxTop, boxBottom, + w->x, w->y, w->width, height); + Gradient_Vertical(&Launcher_Framebuffer, boxBottom, boxTop, + w->x, w->y + height, w->width, height); + + if (w->value) { + const int size = 12; + int x = w->x + w->width / 2 - size / 2; + int y = w->y + w->height / 2 - size / 2; + DrawIndexed(size, x, y, &Launcher_Framebuffer); + } + DrawBoxBounds(black, w->x, w->y, w->width, w->height); +} + + /*########################################################################################################################* *------------------------------------------------------InputWidget--------------------------------------------------------* *#########################################################################################################################*/ @@ -184,18 +270,7 @@ static void LInput_DrawOuterBorder(struct LInput* w) { BitmapCol col = BitmapCol_Make(97, 81, 110, 255); if (w->selected) { - Drawer2D_Clear(&Launcher_Framebuffer, col, - w->x, w->y, - w->width, yBorder); - Drawer2D_Clear(&Launcher_Framebuffer, col, - w->x, w->y + w->height - yBorder, - w->width, yBorder); - Drawer2D_Clear(&Launcher_Framebuffer, col, - w->x, w->y, - xBorder, w->height); - Drawer2D_Clear(&Launcher_Framebuffer, col, - w->x + w->width - xBorder, w->y, - xBorder, w->height); + DrawBoxBounds(col, w->x, w->y, w->width, w->height); } else { Launcher_ResetArea(w->x, w->y, w->width, yBorder); @@ -289,7 +364,7 @@ void LBackend_DrawLabel(struct LLabel* w) { *#########################################################################################################################*/ #define CLASSIC_LINE_COL BitmapCol_Make(128,128,128, 255) void LBackend_DrawLine(struct LLine* w) { - BitmapCol col = Launcher_ClassicBackground ? CLASSIC_LINE_COL : Launcher_ButtonBorderColor; + BitmapCol col = Launcher_Theme.ClassicBackground ? CLASSIC_LINE_COL : Launcher_Theme.ButtonBorderColor; Gradient_Blend(&Launcher_Framebuffer, col, 128, w->x, w->y, w->width, w->height); } diff --git a/src/LBackend.h b/src/LBackend.h index c930159f1..2139b3751 100644 --- a/src/LBackend.h +++ b/src/LBackend.h @@ -22,6 +22,7 @@ void LBackend_ResetPixels(void); void LBackend_CalcOffsets(void); void LBackend_DrawButton(struct LButton* w); +void LBackend_DrawCheckbox(struct LCheckbox* w); void LBackend_DrawInput(struct LInput* w, const cc_string* text); void LBackend_DrawLabel(struct LLabel* w); void LBackend_DrawLine(struct LLine* w); diff --git a/src/LScreens.c b/src/LScreens.c index eb76eabe5..e2e26629e 100644 --- a/src/LScreens.c +++ b/src/LScreens.c @@ -204,7 +204,8 @@ static void SwitchToColours(void* w, int idx) { ColoursScreen_SetActive(); } static void SwitchToDirectConnect(void* w, int idx) { DirectConnectScreen_SetActive(); } static void SwitchToMain(void* w, int idx) { MainScreen_SetActive(); } static void SwitchToSettings(void* w, int idx) { SettingsScreen_SetActive(); } -static void SwitchToUpdates(void* w, int idx) { UpdatesScreen_SetActive(); } +static void SwitchToThemes(void* w, int idx) { ThemesScreen_SetActive(); } +static void SwitchToUpdates(void* w, int idx) { UpdatesScreen_SetActive(); } /*########################################################################################################################* @@ -220,11 +221,9 @@ static struct ChooseModeScreen { } ChooseModeScreen_Instance; CC_NOINLINE static void ChooseMode_Click(cc_bool classic, cc_bool classicHacks) { - Launcher_ClassicBackground = classic; Options_SetBool(OPT_CLASSIC_MODE, classic); if (classic) Options_SetBool(OPT_CLASSIC_HACKS, classicHacks); - Options_SetBool("nostalgia-classicbg", classic); Options_SetBool(OPT_CUSTOM_BLOCKS, !classic); Options_SetBool(OPT_CPE, !classic); Options_SetBool(OPT_SERVER_TEXTURES, !classic); @@ -232,6 +231,7 @@ CC_NOINLINE static void ChooseMode_Click(cc_bool classic, cc_bool classicHacks) Options_SetBool(OPT_CLASSIC_OPTIONS, classic); Options_SaveIfChanged(); + Launcher_LoadTheme(); Launcher_UpdateLogoFont(); MainScreen_SetActive(); } @@ -316,10 +316,11 @@ void ChooseModeScreen_SetActive(cc_bool firstTime) { *#########################################################################################################################*/ static struct ColoursScreen { LScreen_Layout - struct LButton btnDefault, btnBack; - struct LLabel lblNames[5], lblRGB[3]; + struct LButton btnBack; + struct LLabel lblNames[5], lblRGB[3], lblClassic; struct LInput iptColours[5 * 3]; - struct LWidget* _widgets[25]; + struct LCheckbox cbClassic; + struct LWidget* _widgets[26]; float colourAcc; } ColoursScreen_Instance; @@ -340,11 +341,11 @@ CC_NOINLINE static void ColoursScreen_Update(struct ColoursScreen* s, int i, Bit } CC_NOINLINE static void ColoursScreen_UpdateAll(struct ColoursScreen* s) { - ColoursScreen_Update(s, 0, Launcher_BackgroundColor); - ColoursScreen_Update(s, 3, Launcher_ButtonBorderColor); - ColoursScreen_Update(s, 6, Launcher_ButtonHighlightColor); - ColoursScreen_Update(s, 9, Launcher_ButtonForeColor); - ColoursScreen_Update(s, 12, Launcher_ButtonForeActiveColor); + ColoursScreen_Update(s, 0, Launcher_Theme.BackgroundColor); + ColoursScreen_Update(s, 3, Launcher_Theme.ButtonBorderColor); + ColoursScreen_Update(s, 6, Launcher_Theme.ButtonHighlightColor); + ColoursScreen_Update(s, 9, Launcher_Theme.ButtonForeColor); + ColoursScreen_Update(s, 12, Launcher_Theme.ButtonForeActiveColor); } static void ColoursScreen_TextChanged(struct LInput* w) { @@ -353,11 +354,11 @@ static void ColoursScreen_TextChanged(struct LInput* w) { BitmapCol* col; cc_uint8 r, g, b; - if (index < 3) col = &Launcher_BackgroundColor; - else if (index < 6) col = &Launcher_ButtonBorderColor; - else if (index < 9) col = &Launcher_ButtonHighlightColor; - else if (index < 12) col = &Launcher_ButtonForeColor; - else col = &Launcher_ButtonForeActiveColor; + if (index < 3) col = &Launcher_Theme.BackgroundColor; + else if (index < 6) col = &Launcher_Theme.ButtonBorderColor; + else if (index < 9) col = &Launcher_Theme.ButtonHighlightColor; + else if (index < 12) col = &Launcher_Theme.ButtonForeColor; + else col = &Launcher_Theme.ButtonForeActiveColor; /* if index of G input, changes to index of R input */ index = (index / 3) * 3; @@ -366,7 +367,7 @@ static void ColoursScreen_TextChanged(struct LInput* w) { if (!Convert_ParseUInt8(&s->iptColours[index + 2].text, &b)) return; *col = BitmapCol_Make(r, g, b, 255); - Launcher_SaveSkin(); + Launcher_SaveTheme(); Launcher_Redraw(); } @@ -411,10 +412,12 @@ static void ColoursScreen_KeyDown(struct LScreen* s, int key, cc_bool was) { } } -static void ColoursScreen_ResetAll(void* w, int idx) { - Launcher_ResetSkin(); - Launcher_SaveSkin(); - ColoursScreen_UpdateAll(&ColoursScreen_Instance); +static void ColoursScreen_ToggleBG(void* w, int idx) { + struct LCheckbox* cb = (struct LCheckbox*)w; + Launcher_Theme.ClassicBackground = !Launcher_Theme.ClassicBackground; + cb->value = Launcher_Theme.ClassicBackground; + + Launcher_SaveTheme(); Launcher_Redraw(); } @@ -443,17 +446,18 @@ static void ColoursScreen_Init(struct LScreen* s_) { LLabel_Init(s_, &s->lblRGB[0], "Red"); LLabel_Init(s_, &s->lblRGB[1], "Green"); LLabel_Init(s_, &s->lblRGB[2], "Blue"); + LButton_Init(s_, &s->btnBack, 80, 35, "Back"); - LButton_Init(s_, &s->btnDefault, 160, 35, "Default colours"); - LButton_Init(s_, &s->btnBack, 80, 35, "Back"); - - s->btnDefault.OnClick = ColoursScreen_ResetAll; - s->btnBack.OnClick = SwitchToSettings; + LLabel_Init(s_, &s->lblClassic, "Classic style"); + LCheckbox_Init(s_, &s->cbClassic); + s->cbClassic.OnClick = ColoursScreen_ToggleBG; + s->btnBack.OnClick = SwitchToThemes; } static void ColoursScreen_Show(struct LScreen* s_) { struct ColoursScreen* s = (struct ColoursScreen*)s_; - s->colourAcc = 0; + s->colourAcc = 0; + s->cbClassic.value = Launcher_Theme.ClassicBackground; ColoursScreen_UpdateAll(s); } @@ -477,8 +481,9 @@ static void ColoursScreen_Layout(struct LScreen* s_) { LWidget_SetLocation(&s->lblRGB[1], ANCHOR_CENTRE, ANCHOR_CENTRE, 95, -130); LWidget_SetLocation(&s->lblRGB[2], ANCHOR_CENTRE, ANCHOR_CENTRE, 160, -130); - LWidget_SetLocation(&s->btnDefault, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 120); - LWidget_SetLocation(&s->btnBack, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 170); + LWidget_SetLocation(&s->cbClassic, ANCHOR_CENTRE, ANCHOR_CENTRE, -75, 130); + LWidget_SetLocation(&s->lblClassic, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 130); + LWidget_SetLocation(&s->btnBack, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 170); } void ColoursScreen_SetActive(void) { @@ -1411,21 +1416,21 @@ static void SettingsScreen_Init(struct LScreen* s_) { LButton_Init(s_, &s->btnMode, 110, 35, "Mode"); LLabel_Init(s_, &s->lblMode, "&eChange the enabled features"); - LButton_Init(s_, &s->btnColours, 110, 35, "Colours"); + LButton_Init(s_, &s->btnColours, 110, 35, "Theme"); LLabel_Init(s_, &s->lblColours, "&eChange how the launcher looks"); LButton_Init(s_, &s->btnBack, 80, 35, "Back"); s->btnMode.OnClick = SwitchToChooseMode; s->btnUpdates.OnClick = SwitchToUpdates; - s->btnColours.OnClick = SwitchToColours; + s->btnColours.OnClick = SwitchToThemes; s->btnBack.OnClick = SwitchToMain; } static void SettingsScreen_Show(struct LScreen* s_) { struct SettingsScreen* s = (struct SettingsScreen*)s_; - s->btnColours.hidden = Launcher_ClassicBackground; - s->lblColours.hidden = Launcher_ClassicBackground; + s->btnColours.hidden = Options_GetBool(OPT_CLASSIC_MODE, false); + s->lblColours.hidden = s->btnColours.hidden; } static void SettingsScreen_Layout(struct LScreen* s_) { @@ -1452,6 +1457,60 @@ void SettingsScreen_SetActive(void) { } +/*########################################################################################################################* +*----------------------------------------------------------ThemesScreen----------------------------------------------------* +*#########################################################################################################################*/ +static struct ThemesScreen { + LScreen_Layout + struct LButton btnModern, btnClassic, btnCustom, btnBack; + struct LWidget* _widgets[4]; +} ThemesScreen_Instance; + +static void ThemesScreen_Set(const struct LauncherTheme* theme) { + Launcher_Theme = *theme; + Launcher_SaveTheme(); + Launcher_Redraw(); +} + +static void ThemesScreen_Modern(void* w, int idx) { + ThemesScreen_Set(&Launcher_ModernTheme); +} +static void ThemesScreen_Classic(void* w, int idx) { + ThemesScreen_Set(&Launcher_ClassicTheme); +} + +static void ThemesScreen_Init(struct LScreen* s_) { + struct ThemesScreen* s = (struct ThemesScreen*)s_; + s->widgets = s->_widgets; + + LButton_Init(s_, &s->btnModern, 200, 35, "Modern"); + LButton_Init(s_, &s->btnClassic, 200, 35, "Classic"); + LButton_Init(s_, &s->btnCustom, 200, 35, "Custom"); + LButton_Init(s_, &s->btnBack, 80, 35, "Back"); + + s->btnModern.OnClick = ThemesScreen_Modern; + s->btnClassic.OnClick = ThemesScreen_Classic; + s->btnCustom.OnClick = SwitchToColours; + s->btnBack.OnClick = SwitchToSettings; +} + +static void ThemesScreen_Layout(struct LScreen* s_) { + struct ThemesScreen* s = (struct ThemesScreen*)s_; + LWidget_SetLocation(&s->btnModern, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -120); + LWidget_SetLocation(&s->btnClassic, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -70); + LWidget_SetLocation(&s->btnCustom, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 120); + LWidget_SetLocation(&s->btnBack, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 170); +} + +void ThemesScreen_SetActive(void) { + struct ThemesScreen* s = &ThemesScreen_Instance; + LScreen_Reset((struct LScreen*)s); + s->Init = ThemesScreen_Init; + s->Layout = ThemesScreen_Layout; + Launcher_SetScreen((struct LScreen*)s); +} + + /*########################################################################################################################* *--------------------------------------------------------UpdatesScreen----------------------------------------------------* *#########################################################################################################################*/ diff --git a/src/LScreens.h b/src/LScreens.h index 7c21d84fe..4d9264af4 100644 --- a/src/LScreens.h +++ b/src/LScreens.h @@ -44,5 +44,6 @@ void CheckResourcesScreen_SetActive(void); void FetchResourcesScreen_SetActive(void); void ServersScreen_SetActive(void); void SettingsScreen_SetActive(void); +void ThemesScreen_SetActive(void); void UpdatesScreen_SetActive(void); #endif diff --git a/src/LWidgets.c b/src/LWidgets.c index 4b9efb4b4..2127ee044 100644 --- a/src/LWidgets.c +++ b/src/LWidgets.c @@ -117,6 +117,30 @@ void LButton_SetConst(struct LButton* w, const char* text) { } +/*########################################################################################################################* +*-----------------------------------------------------CheckboxWidget------------------------------------------------------* +*#########################################################################################################################*/ +static void LCheckbox_Draw(void* widget) { + struct LCheckbox* w = (struct LCheckbox*)widget; + LBackend_DrawCheckbox(w); + Launcher_MarkDirty(w->x, w->y, w->width, w->height); +} + +static const struct LWidgetVTABLE lcheckbox_VTABLE = { + LCheckbox_Draw, NULL, + NULL, NULL, /* Key */ + NULL, NULL, /* Hover */ + NULL, NULL /* Select */ +}; +void LCheckbox_Init(struct LScreen* s, struct LCheckbox* w) { + w->VTABLE = &lcheckbox_VTABLE; + w->tabSelectable = true; + w->width = Display_ScaleX(24); + w->height = Display_ScaleY(24); + s->widgets[s->numWidgets++] = (struct LWidget*)w; +} + + /*########################################################################################################################* *------------------------------------------------------InputWidget--------------------------------------------------------* *#########################################################################################################################*/ @@ -618,7 +642,7 @@ static void LTable_SetSelectedTo(struct LTable* w, int index) { static void LTable_DrawHeaderBackground(struct LTable* w) { BitmapCol gridCol = BitmapCol_Make(20, 20, 10, 255); - if (!Launcher_ClassicBackground) { + if (!Launcher_Theme.ClassicBackground) { Drawer2D_Clear(&Launcher_Framebuffer, gridCol, w->x, w->y, w->width, w->hdrHeight); } else { @@ -642,7 +666,7 @@ static BitmapCol LTable_RowCol(struct LTable* w, struct ServerInfo* row) { return selectedCol; } } - return Launcher_ClassicBackground ? 0 : gridCol; + return Launcher_Theme.ClassicBackground ? 0 : gridCol; } /* Draws background behind each row in the table */ @@ -673,17 +697,17 @@ static void LTable_DrawRowsBackground(struct LTable* w) { /* Draws a gridline below column headers and gridlines after each column */ static void LTable_DrawGridlines(struct LTable* w) { int i, x; - if (Launcher_ClassicBackground) return; + if (Launcher_Theme.ClassicBackground) return; x = w->x; - Drawer2D_Clear(&Launcher_Framebuffer, Launcher_BackgroundColor, + Drawer2D_Clear(&Launcher_Framebuffer, Launcher_Theme.BackgroundColor, x, w->y + w->hdrHeight, w->width, gridlineHeight); for (i = 0; i < w->numColumns; i++) { x += w->columns[i].width; if (!w->columns[i].hasGridline) continue; - Drawer2D_Clear(&Launcher_Framebuffer, Launcher_BackgroundColor, + Drawer2D_Clear(&Launcher_Framebuffer, Launcher_Theme.BackgroundColor, x, w->y, gridlineWidth, w->height); x += gridlineWidth; } @@ -757,8 +781,8 @@ static void LTable_DrawRows(struct LTable* w) { static void LTable_DrawScrollbar(struct LTable* w) { BitmapCol classicBack = BitmapCol_Make( 80, 80, 80, 255); BitmapCol classicScroll = BitmapCol_Make(160, 160, 160, 255); - BitmapCol backCol = Launcher_ClassicBackground ? classicBack : Launcher_ButtonBorderColor; - BitmapCol scrollCol = Launcher_ClassicBackground ? classicScroll : Launcher_ButtonForeActiveColor; + BitmapCol backCol = Launcher_Theme.ClassicBackground ? classicBack : Launcher_Theme.ButtonBorderColor; + BitmapCol scrollCol = Launcher_Theme.ClassicBackground ? classicScroll : Launcher_Theme.ButtonForeActiveColor; int x, y, height; x = w->x + w->width - scrollbarWidth; diff --git a/src/LWidgets.h b/src/LWidgets.h index 28cb4afb7..38cf1e4b1 100644 --- a/src/LWidgets.h +++ b/src/LWidgets.h @@ -61,6 +61,12 @@ struct LButton { CC_NOINLINE void LButton_Init(struct LScreen* s, struct LButton* w, int width, int height, const char* text); CC_NOINLINE void LButton_SetConst(struct LButton* w, const char* text); +struct LCheckbox { + LWidget_Layout + cc_bool value; +}; +CC_NOINLINE void LCheckbox_Init(struct LScreen* s, struct LCheckbox* w); + struct LInput; struct LInput { LWidget_Layout diff --git a/src/Launcher.c b/src/Launcher.c index 64cbc4d70..2d4f6f37d 100644 --- a/src/Launcher.c +++ b/src/Launcher.c @@ -26,7 +26,6 @@ static Rect2D dirty_rect; static struct LScreen* activeScreen; struct Bitmap Launcher_Framebuffer; -cc_bool Launcher_ClassicBackground; struct FontDesc Launcher_TitleFont, Launcher_TextFont, Launcher_HintFont; static cc_bool pendingRedraw; @@ -302,7 +301,7 @@ void Launcher_Run(void) { Options_Get(LOPT_USERNAME, &Launcher_Username, ""); LWebTasks_Init(); Session_Load(); - Launcher_LoadSkin(); + Launcher_LoadTheme(); Launcher_Init(); Launcher_TryLoadTexturePack(); @@ -355,25 +354,24 @@ void Launcher_Run(void) { /*########################################################################################################################* *---------------------------------------------------------Colours/Skin----------------------------------------------------* *#########################################################################################################################*/ -#define DEFAULT_BACKGROUND_COLOR BitmapCol_Make(153, 127, 172, 255) -#define DEFAULT_BUTTON_BORDER_COLOR BitmapCol_Make( 97, 81, 110, 255) -#define DEFAULT_BUTTON_FORE_ACTIVE_COLOR BitmapCol_Make(189, 168, 206, 255) -#define DEFAULT_BUTTON_FORE_COLOR BitmapCol_Make(141, 114, 165, 255) -#define DEFAULT_BUTTON_HIGHLIGHT_COLOR BitmapCol_Make(162, 131, 186, 255) +struct LauncherTheme Launcher_Theme; +const struct LauncherTheme Launcher_ModernTheme = { + false, + BitmapCol_Make(153, 127, 172, 255), /* background */ + BitmapCol_Make( 97, 81, 110, 255), /* button border */ + BitmapCol_Make(189, 168, 206, 255), /* active button */ + BitmapCol_Make(141, 114, 165, 255), /* button foreground */ + BitmapCol_Make(162, 131, 186, 255), /* button highlight */ +}; -BitmapCol Launcher_BackgroundColor = DEFAULT_BACKGROUND_COLOR; -BitmapCol Launcher_ButtonBorderColor = DEFAULT_BUTTON_BORDER_COLOR; -BitmapCol Launcher_ButtonForeActiveColor = DEFAULT_BUTTON_FORE_ACTIVE_COLOR; -BitmapCol Launcher_ButtonForeColor = DEFAULT_BUTTON_FORE_COLOR; -BitmapCol Launcher_ButtonHighlightColor = DEFAULT_BUTTON_HIGHLIGHT_COLOR; - -void Launcher_ResetSkin(void) { - Launcher_BackgroundColor = DEFAULT_BACKGROUND_COLOR; - Launcher_ButtonBorderColor = DEFAULT_BUTTON_BORDER_COLOR; - Launcher_ButtonForeActiveColor = DEFAULT_BUTTON_FORE_ACTIVE_COLOR; - Launcher_ButtonForeColor = DEFAULT_BUTTON_FORE_COLOR; - Launcher_ButtonHighlightColor = DEFAULT_BUTTON_HIGHLIGHT_COLOR; -} +const struct LauncherTheme Launcher_ClassicTheme = { + true, + BitmapCol_Make( 50, 50, 50, 255), /* background */ + BitmapCol_Make( 0, 0, 0, 255), /* button border */ + BitmapCol_Make(126, 136, 191, 255), /* active button */ + BitmapCol_Make(111, 111, 111, 255), /* button foreground */ + BitmapCol_Make(168, 168, 168, 255), /* button highlight */ +}; CC_NOINLINE static void Launcher_GetCol(const char* key, BitmapCol* col) { cc_uint8 rgb[3]; @@ -384,12 +382,19 @@ CC_NOINLINE static void Launcher_GetCol(const char* key, BitmapCol* col) { *col = BitmapCol_Make(rgb[0], rgb[1], rgb[2], 255); } -void Launcher_LoadSkin(void) { - Launcher_GetCol("launcher-back-col", &Launcher_BackgroundColor); - Launcher_GetCol("launcher-btn-border-col", &Launcher_ButtonBorderColor); - Launcher_GetCol("launcher-btn-fore-active-col", &Launcher_ButtonForeActiveColor); - Launcher_GetCol("launcher-btn-fore-inactive-col", &Launcher_ButtonForeColor); - Launcher_GetCol("launcher-btn-highlight-inactive-col", &Launcher_ButtonHighlightColor); +void Launcher_LoadTheme(void) { + if (Options_GetBool(OPT_CLASSIC_MODE, false)) { + Launcher_Theme = Launcher_ClassicTheme; + return; + } + Launcher_Theme = Launcher_ModernTheme; + Launcher_Theme.ClassicBackground = Options_GetBool("nostalgia-classicbg", false); + + Launcher_GetCol("launcher-back-col", &Launcher_Theme.BackgroundColor); + Launcher_GetCol("launcher-btn-border-col", &Launcher_Theme.ButtonBorderColor); + Launcher_GetCol("launcher-btn-fore-active-col", &Launcher_Theme.ButtonForeActiveColor); + Launcher_GetCol("launcher-btn-fore-inactive-col", &Launcher_Theme.ButtonForeColor); + Launcher_GetCol("launcher-btn-highlight-inactive-col", &Launcher_Theme.ButtonHighlightColor); } CC_NOINLINE static void Launcher_SetCol(const char* key, BitmapCol col) { @@ -402,12 +407,13 @@ CC_NOINLINE static void Launcher_SetCol(const char* key, BitmapCol col) { Options_Set(key, &value); } -void Launcher_SaveSkin(void) { - Launcher_SetCol("launcher-back-col", Launcher_BackgroundColor); - Launcher_SetCol("launcher-btn-border-col", Launcher_ButtonBorderColor); - Launcher_SetCol("launcher-btn-fore-active-col", Launcher_ButtonForeActiveColor); - Launcher_SetCol("launcher-btn-fore-inactive-col", Launcher_ButtonForeColor); - Launcher_SetCol("launcher-btn-highlight-inactive-col", Launcher_ButtonHighlightColor); +void Launcher_SaveTheme(void) { + Launcher_SetCol("launcher-back-col", Launcher_Theme.BackgroundColor); + Launcher_SetCol("launcher-btn-border-col", Launcher_Theme.ButtonBorderColor); + Launcher_SetCol("launcher-btn-fore-active-col", Launcher_Theme.ButtonForeActiveColor); + Launcher_SetCol("launcher-btn-fore-inactive-col", Launcher_Theme.ButtonForeColor); + Launcher_SetCol("launcher-btn-highlight-inactive-col", Launcher_Theme.ButtonHighlightColor); + Options_SetBool("nostalgia-classicbg", Launcher_Theme.ClassicBackground); } @@ -473,12 +479,6 @@ void Launcher_TryLoadTexturePack(void) { cc_string path; char pathBuffer[FILENAME_SIZE]; cc_string texPack; - if (Options_UNSAFE_Get("nostalgia-classicbg", &texPack)) { - Launcher_ClassicBackground = Options_GetBool("nostalgia-classicbg", false); - } else { - Launcher_ClassicBackground = Options_GetBool(OPT_CLASSIC_MODE, false); - } - if (Options_UNSAFE_Get(OPT_DEFAULT_TEX_PACK, &texPack)) { String_InitArray(path, pathBuffer); String_Format1(&path, "texpacks/%s", &texPack); @@ -492,7 +492,7 @@ void Launcher_TryLoadTexturePack(void) { void Launcher_UpdateLogoFont(void) { Font_Free(&logoFont); - Drawer2D.BitmappedText = (useBitmappedFont || Launcher_ClassicBackground) && hasBitmappedFont; + Drawer2D.BitmappedText = (useBitmappedFont || Launcher_Theme.ClassicBackground) && hasBitmappedFont; Drawer2D_MakeFont(&logoFont, 32, FONT_FLAGS_NONE); Drawer2D.BitmappedText = false; } diff --git a/src/Launcher.h b/src/Launcher.h index d0d6211ee..c4d2fe907 100644 --- a/src/Launcher.h +++ b/src/Launcher.h @@ -9,8 +9,6 @@ struct FontDesc; /* Contains the pixels that are drawn to the window. */ extern struct Bitmap Launcher_Framebuffer; -/* Whether to use stone tile background like minecraft.net. */ -extern cc_bool Launcher_ClassicBackground; /* Default font for buttons and labels. */ extern struct FontDesc Launcher_TitleFont, Launcher_TextFont; /* Default font for input widget hints. */ @@ -25,24 +23,32 @@ extern cc_string Launcher_AutoHash; /* The username of currently active user */ extern cc_string Launcher_Username; -/* Base colour of pixels before any widgets are drawn. */ -extern BitmapCol Launcher_BackgroundColor; -/* Colour of pixels on the 4 line borders around buttons. */ -extern BitmapCol Launcher_ButtonBorderColor; -/* Colour of button when user has mouse over it. */ -extern BitmapCol Launcher_ButtonForeActiveColor; -/* Colour of button when user does not have mouse over it. */ -extern BitmapCol Launcher_ButtonForeColor; -/* Colour of line at top of buttons to give them a less flat look.*/ -extern BitmapCol Launcher_ButtonHighlightColor; +struct LauncherTheme { + /* Whether to use stone tile background like minecraft.net. */ + cc_bool ClassicBackground; + /* Base colour of pixels before any widgets are drawn. */ + BitmapCol BackgroundColor; + /* Colour of pixels on the 4 line borders around buttons. */ + BitmapCol ButtonBorderColor; + /* Colour of button when user has mouse over it. */ + BitmapCol ButtonForeActiveColor; + /* Colour of button when user does not have mouse over it. */ + BitmapCol ButtonForeColor; + /* Colour of line at top of buttons to give them a less flat look.*/ + BitmapCol ButtonHighlightColor; +}; +/* Currently active theme */ +extern struct LauncherTheme Launcher_Theme; +/* Modern / enhanced theme */ +extern const struct LauncherTheme Launcher_ModernTheme; +/* Minecraft Classic theme */ +extern const struct LauncherTheme Launcher_ClassicTheme; -/* Resets colours to default. */ -void Launcher_ResetSkin(void); -/* Loads colours from options. */ -void Launcher_LoadSkin(void); -/* Saves the colours to options. */ +/* Loads theme from options. */ +void Launcher_LoadTheme(void); +/* Saves the theme to options. */ /* NOTE: Does not save options file itself. */ -void Launcher_SaveSkin(void); +void Launcher_SaveTheme(void); /* Updates logo font. */ void Launcher_UpdateLogoFont(void);