mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 09:06:55 -04:00
Launcher: Tidy up widget/backend code a little bit
This commit is contained in:
parent
e02760dfb1
commit
a8d8fb9411
@ -135,6 +135,17 @@ void LBackend_DrawButton(struct LButton* w) {
|
||||
/*########################################################################################################################*
|
||||
*-----------------------------------------------------CheckboxWidget------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
#define CB_SIZE 24
|
||||
#define CB_OFFSET 8
|
||||
|
||||
void LBackend_InitCheckbox(struct LCheckbox* w) {
|
||||
struct DrawTextArgs args;
|
||||
DrawTextArgs_Make(&args, &w->text, &Launcher_TextFont, true);
|
||||
|
||||
w->width = Display_ScaleX(CB_SIZE + CB_OFFSET) + Drawer2D_TextWidth(&args);
|
||||
w->height = Display_ScaleY(CB_SIZE);
|
||||
}
|
||||
|
||||
/* 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,
|
||||
@ -210,7 +221,7 @@ void LBackend_DrawCheckbox(struct LCheckbox* w) {
|
||||
}
|
||||
DrawBoxBounds(black, w->x, w->y, width, height);
|
||||
|
||||
DrawTextArgs_Make(&args, &w->text, w->font, true);
|
||||
DrawTextArgs_Make(&args, &w->text, &Launcher_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);
|
||||
@ -306,6 +317,14 @@ void LBackend_DrawInput(struct LInput* w, const cc_string* text) {
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------LabelWidget--------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void LBackend_UpdateLabel(struct LLabel* w) {
|
||||
struct DrawTextArgs args;
|
||||
DrawTextArgs_Make(&args, &w->text, w->font, true);
|
||||
|
||||
w->width = Drawer2D_TextWidth(&args);
|
||||
w->height = Drawer2D_TextHeight(&args);
|
||||
}
|
||||
|
||||
void LBackend_DrawLabel(struct LLabel* w) {
|
||||
struct DrawTextArgs args;
|
||||
DrawTextArgs_Make(&args, &w->text, w->font, true);
|
||||
@ -359,12 +378,13 @@ static void LSlider_DrawBox(struct LSlider* w) {
|
||||
w->width - xBorder2, halfHeight);
|
||||
}
|
||||
|
||||
#define LSLIDER_MAXVALUE 100
|
||||
void LBackend_DrawSlider(struct LSlider* w) {
|
||||
int curWidth;
|
||||
LSlider_DrawBoxBounds(w);
|
||||
LSlider_DrawBox(w);
|
||||
|
||||
curWidth = (int)((w->width - xBorder2) * w->value / w->maxValue);
|
||||
curWidth = (int)((w->width - xBorder2) * w->value / LSLIDER_MAXVALUE);
|
||||
Drawer2D_Clear(&Launcher_Framebuffer, w->color,
|
||||
w->x + xBorder, w->y + yBorder,
|
||||
curWidth, w->height - yBorder2);
|
||||
|
@ -12,14 +12,19 @@ struct LLabel;
|
||||
struct LLine;
|
||||
struct LSlider;
|
||||
|
||||
#define CB_SIZE 24
|
||||
#define CB_OFFSET 8
|
||||
|
||||
void LBackend_CalcOffsets(void);
|
||||
|
||||
void LBackend_DrawButton(struct LButton* w);
|
||||
|
||||
void LBackend_InitCheckbox(struct LCheckbox* w);
|
||||
void LBackend_DrawCheckbox(struct LCheckbox* w);
|
||||
|
||||
void LBackend_DrawInput(struct LInput* w, const cc_string* text);
|
||||
|
||||
void LBackend_UpdateLabel(struct LLabel* w);
|
||||
void LBackend_DrawLabel(struct LLabel* w);
|
||||
|
||||
void LBackend_DrawLine(struct LLine* w);
|
||||
|
||||
void LBackend_DrawSlider(struct LSlider* w);
|
||||
#endif
|
||||
|
@ -129,17 +129,12 @@ static const struct LWidgetVTABLE lcheckbox_VTABLE = {
|
||||
NULL, NULL /* Select */
|
||||
};
|
||||
void LCheckbox_Init(struct LCheckbox* w, const char* text) {
|
||||
struct DrawTextArgs args;
|
||||
w->VTABLE = &lcheckbox_VTABLE;
|
||||
w->font = &Launcher_TextFont;
|
||||
w->tabSelectable = true;
|
||||
|
||||
String_InitArray(w->text, w->_textBuffer);
|
||||
String_AppendConst(&w->text, text);
|
||||
|
||||
DrawTextArgs_Make(&args, &w->text, w->font, true);
|
||||
w->width = Display_ScaleX(CB_SIZE + CB_OFFSET) + Drawer2D_TextWidth(&args);
|
||||
w->height = Display_ScaleY(CB_SIZE);
|
||||
LBackend_InitCheckbox(w);
|
||||
}
|
||||
|
||||
|
||||
@ -481,12 +476,8 @@ void LLabel_Init(struct LLabel* w, const char* text) {
|
||||
}
|
||||
|
||||
void LLabel_SetText(struct LLabel* w, const cc_string* text) {
|
||||
struct DrawTextArgs args;
|
||||
String_Copy(&w->text, text);
|
||||
|
||||
DrawTextArgs_Make(&args, &w->text, w->font, true);
|
||||
w->width = Drawer2D_TextWidth(&args);
|
||||
w->height = Drawer2D_TextHeight(&args);
|
||||
LBackend_UpdateLabel(w);
|
||||
LWidget_CalcPosition(w);
|
||||
}
|
||||
|
||||
@ -532,11 +523,10 @@ static const struct LWidgetVTABLE lslider_VTABLE = {
|
||||
NULL, NULL /* Select */
|
||||
};
|
||||
void LSlider_Init(struct LSlider* w, int width, int height, BitmapCol color) {
|
||||
w->VTABLE = &lslider_VTABLE;
|
||||
w->width = Display_ScaleX(width);
|
||||
w->height = Display_ScaleY(height);
|
||||
w->maxValue = 100;
|
||||
w->color = color;
|
||||
w->VTABLE = &lslider_VTABLE;
|
||||
w->width = Display_ScaleX(width);
|
||||
w->height = Display_ScaleY(height);
|
||||
w->color = color;
|
||||
}
|
||||
|
||||
|
||||
|
@ -61,7 +61,6 @@ CC_NOINLINE void LButton_SetConst(struct LButton* w, const char* text);
|
||||
|
||||
struct LCheckbox {
|
||||
LWidget_Layout
|
||||
struct FontDesc* font;
|
||||
cc_bool value;
|
||||
cc_string text;
|
||||
char _textBuffer[STRING_SIZE];
|
||||
@ -121,7 +120,7 @@ CC_NOINLINE void LLine_Init(struct LLine* w, int width);
|
||||
/* Represents a slider bar that may or may not be modifiable by the user. */
|
||||
struct LSlider {
|
||||
LWidget_Layout
|
||||
int value, maxValue;
|
||||
int value;
|
||||
BitmapCol color;
|
||||
};
|
||||
CC_NOINLINE void LSlider_Init(struct LSlider* w, int width, int height, BitmapCol color);
|
||||
|
Loading…
x
Reference in New Issue
Block a user