Move skin related variables into LauncherTheme struct

This commit is contained in:
UnknownShadow200 2021-08-06 17:32:21 +10:00
parent 579027fda2
commit 4ef86dfa13
5 changed files with 83 additions and 81 deletions

View File

@ -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 {
@ -106,13 +106,13 @@ static void LButton_DrawBackground(struct LButton* w) {
BitmapCol inactiveCol = BitmapCol_Make(111, 111, 111, 255);
BitmapCol col;
if (Launcher_ClassicBackground) {
if (Launcher_Theme.ClassicBackground) {
col = w->hovered ? activeCol : inactiveCol;
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;
col = w->hovered ? Launcher_Theme.ButtonForeActiveColor : Launcher_Theme.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);
@ -121,7 +121,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.ClassicBackground ? black : Launcher_Theme.ButtonBorderColor;
Drawer2D_Clear(&Launcher_Framebuffer, backCol,
w->x + xBorder, w->y,
@ -142,7 +142,7 @@ static void LButton_DrawHighlight(struct LButton* w) {
BitmapCol inactiveCol = BitmapCol_Make(168, 168, 168, 255);
BitmapCol highlightCol;
if (Launcher_ClassicBackground) {
if (Launcher_Theme.ClassicBackground) {
highlightCol = w->hovered ? activeCol : inactiveCol;
Drawer2D_Clear(&Launcher_Framebuffer, highlightCol,
w->x + xBorder2, w->y + yBorder,
@ -151,7 +151,7 @@ static void LButton_DrawHighlight(struct LButton* w) {
w->x + xBorder, w->y + yBorder2,
xBorder, w->height - yBorder4);
} else if (!w->hovered) {
Drawer2D_Clear(&Launcher_Framebuffer, Launcher_ButtonHighlightColor,
Drawer2D_Clear(&Launcher_Framebuffer, Launcher_Theme.ButtonHighlightColor,
w->x + xBorder2, w->y + yBorder,
w->width - xBorder4, yBorder);
}
@ -289,7 +289,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);
}

View File

@ -220,7 +220,7 @@ static struct ChooseModeScreen {
} ChooseModeScreen_Instance;
CC_NOINLINE static void ChooseMode_Click(cc_bool classic, cc_bool classicHacks) {
Launcher_ClassicBackground = classic;
Launcher_Theme.ClassicBackground = classic;
Options_SetBool(OPT_CLASSIC_MODE, classic);
if (classic) Options_SetBool(OPT_CLASSIC_HACKS, classicHacks);
@ -340,11 +340,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 +353,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 +366,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();
}
@ -412,8 +412,8 @@ static void ColoursScreen_KeyDown(struct LScreen* s, int key, cc_bool was) {
}
static void ColoursScreen_ResetAll(void* w, int idx) {
Launcher_ResetSkin();
Launcher_SaveSkin();
Launcher_ResetTheme();
Launcher_SaveTheme();
ColoursScreen_UpdateAll(&ColoursScreen_Instance);
Launcher_Redraw();
}
@ -1424,8 +1424,8 @@ static void SettingsScreen_Init(struct LScreen* s_) {
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 = Launcher_Theme.ClassicBackground;
s->lblColours.hidden = Launcher_Theme.ClassicBackground;
}
static void SettingsScreen_Layout(struct LScreen* s_) {

View File

@ -618,7 +618,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 +642,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 +673,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 +757,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;

View File

@ -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,24 +354,18 @@ 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), /* button foreground */
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;
void Launcher_ResetTheme(void) {
Launcher_Theme = Launcher_ModernTheme;
}
CC_NOINLINE static void Launcher_GetCol(const char* key, BitmapCol* col) {
@ -384,12 +377,13 @@ 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) {
Launcher_ResetTheme();
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 +396,12 @@ 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);
}
@ -474,9 +468,9 @@ void Launcher_TryLoadTexturePack(void) {
cc_string texPack;
if (Options_UNSAFE_Get("nostalgia-classicbg", &texPack)) {
Launcher_ClassicBackground = Options_GetBool("nostalgia-classicbg", false);
Launcher_Theme.ClassicBackground = Options_GetBool("nostalgia-classicbg", false);
} else {
Launcher_ClassicBackground = Options_GetBool(OPT_CLASSIC_MODE, false);
Launcher_Theme.ClassicBackground = Options_GetBool(OPT_CLASSIC_MODE, false);
}
if (Options_UNSAFE_Get(OPT_DEFAULT_TEX_PACK, &texPack)) {
@ -492,7 +486,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;
}

View File

@ -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,34 @@ 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);
void Launcher_ResetTheme(void);
/* Loads colours from options. */
void Launcher_LoadSkin(void);
void Launcher_LoadTheme(void);
/* Saves the colours to options. */
/* NOTE: Does not save options file itself. */
void Launcher_SaveSkin(void);
void Launcher_SaveTheme(void);
/* Updates logo font. */
void Launcher_UpdateLogoFont(void);