diff --git a/src/LBackend.c b/src/LBackend.c index 75d22f0f5..5a8bd4e37 100644 --- a/src/LBackend.c +++ b/src/LBackend.c @@ -1,5 +1,10 @@ #include "LBackend.h" -#ifndef CC_BUILD_WEB +#if defined CC_BUILD_WEB +/* Web backend doesn't use the launcher */ +#elif defined CC_BUILD_WIN_TEST +/* Testing windows UI backend */ +#include "LBackend_Win.c" +#else #include "Launcher.h" #include "Drawer2D.h" #include "Window.h" @@ -48,10 +53,25 @@ static void DrawBoxBounds(BitmapCol col, int x, int y, int width, int height) { xBorder, height); } +void LBackend_WidgetRepositioned(struct LWidget* w) { } + /*########################################################################################################################* *------------------------------------------------------ButtonWidget-------------------------------------------------------* *#########################################################################################################################*/ +void LBackend_InitButton(struct LButton* w, int width, int height) { + w->width = Display_ScaleX(width); + w->height = Display_ScaleY(height); +} + +void LBackend_UpdateButton(struct LButton* w) { + struct DrawTextArgs args; + DrawTextArgs_Make(&args, &w->text, &Launcher_TitleFont, true); + + w->_textWidth = Drawer2D_TextWidth(&args); + w->_textHeight = Drawer2D_TextHeight(&args); +} + static BitmapCol LButton_Expand(BitmapCol a, int amount) { int r, g, b; r = BitmapCol_R(a) + amount; Math_Clamp(r, 0, 255); @@ -231,6 +251,11 @@ void LBackend_DrawCheckbox(struct LCheckbox* w) { /*########################################################################################################################* *------------------------------------------------------InputWidget--------------------------------------------------------* *#########################################################################################################################*/ +void LBackend_InitInput(struct LInput* w, int width) { + w->width = Display_ScaleX(width); + w->height = Display_ScaleY(30); +} + static void LInput_DrawOuterBorder(struct LInput* w) { BitmapCol color = BitmapCol_Make(97, 81, 110, 255); @@ -317,6 +342,8 @@ void LBackend_DrawInput(struct LInput* w, const cc_string* text) { /*########################################################################################################################* *------------------------------------------------------LabelWidget--------------------------------------------------------* *#########################################################################################################################*/ +void LBackend_InitLabel(struct LLabel* w) { } + void LBackend_UpdateLabel(struct LLabel* w) { struct DrawTextArgs args; DrawTextArgs_Make(&args, &w->text, w->font, true); @@ -335,6 +362,11 @@ void LBackend_DrawLabel(struct LLabel* w) { /*########################################################################################################################* *-------------------------------------------------------LineWidget--------------------------------------------------------* *#########################################################################################################################*/ +void LBackend_InitLine(struct LLine* w, int width) { + w->width = Display_ScaleX(width); + w->height = Display_ScaleY(2); +} + #define CLASSIC_LINE_COLOR BitmapCol_Make(128,128,128, 255) void LBackend_DrawLine(struct LLine* w) { BitmapCol color = Launcher_Theme.ClassicBackground ? CLASSIC_LINE_COLOR : Launcher_Theme.ButtonBorderColor; @@ -345,6 +377,11 @@ void LBackend_DrawLine(struct LLine* w) { /*########################################################################################################################* *------------------------------------------------------SliderWidget-------------------------------------------------------* *#########################################################################################################################*/ +void LBackend_InitSlider(struct LSlider* w, int width, int height) { + w->width = Display_ScaleX(width); + w->height = Display_ScaleY(height); +} + static void LSlider_DrawBoxBounds(struct LSlider* w) { BitmapCol boundsTop = BitmapCol_Make(119, 100, 132, 255); BitmapCol boundsBottom = BitmapCol_Make(150, 130, 165, 255); diff --git a/src/LBackend.h b/src/LBackend.h index b54378ce8..7fd7ab1dc 100644 --- a/src/LBackend.h +++ b/src/LBackend.h @@ -5,6 +5,7 @@ Copyright 2014-2021 ClassiCube | Licensed under BSD-3 */ struct Bitmap; +struct LWidget; struct LButton; struct LCheckbox; struct LInput; @@ -13,18 +14,25 @@ struct LLine; struct LSlider; void LBackend_CalcOffsets(void); +void LBackend_WidgetRepositioned(struct LWidget* w); +void LBackend_InitButton(struct LButton* w, int width, int height); +void LBackend_UpdateButton(struct LButton* w); void LBackend_DrawButton(struct LButton* w); void LBackend_InitCheckbox(struct LCheckbox* w); void LBackend_DrawCheckbox(struct LCheckbox* w); +void LBackend_InitInput(struct LInput* w, int width); void LBackend_DrawInput(struct LInput* w, const cc_string* text); +void LBackend_InitLabel(struct LLabel* w); void LBackend_UpdateLabel(struct LLabel* w); void LBackend_DrawLabel(struct LLabel* w); +void LBackend_InitLine(struct LLine* w, int width); void LBackend_DrawLine(struct LLine* w); +void LBackend_InitSlider(struct LSlider* w, int width, int height); void LBackend_DrawSlider(struct LSlider* w); #endif diff --git a/src/LWidgets.c b/src/LWidgets.c index fba5f6d1e..38673901e 100644 --- a/src/LWidgets.c +++ b/src/LWidgets.c @@ -57,6 +57,7 @@ void LWidget_CalcPosition(void* widget) { struct LWidget* w = (struct LWidget*)widget; w->x = Gui_CalcPos(w->horAnchor, Display_ScaleX(w->xOffset), w->width, WindowInfo.Width); w->y = Gui_CalcPos(w->verAnchor, Display_ScaleY(w->yOffset), w->height, WindowInfo.Height); + LBackend_WidgetRepositioned(w); } void LWidget_Draw(void* widget) { @@ -98,18 +99,13 @@ static const struct LWidgetVTABLE lbutton_VTABLE = { void LButton_Init(struct LButton* w, int width, int height, const char* text) { w->VTABLE = &lbutton_VTABLE; w->tabSelectable = true; - w->width = Display_ScaleX(width); - w->height = Display_ScaleY(height); - + LBackend_InitButton(w, width, height); LButton_SetConst(w, text); } void LButton_SetConst(struct LButton* w, const char* text) { - struct DrawTextArgs args; w->text = String_FromReadonly(text); - DrawTextArgs_Make(&args, &w->text, &Launcher_TitleFont, true); - w->_textWidth = Drawer2D_TextWidth(&args); - w->_textHeight = Drawer2D_TextHeight(&args); + LBackend_UpdateButton(w); } @@ -404,13 +400,10 @@ void LInput_Init(struct LInput* w, int width, const char* hintText) { w->TextFilter = LInput_DefaultInputFilter; String_InitArray(w->text, w->_textBuffer); - w->width = Display_ScaleX(width); - w->height = Display_ScaleY(30); - w->minWidth = w->width; - LWidget_CalcPosition(w); - w->hintText = hintText; w->caretPos = -1; + LBackend_InitInput(w, width); + w->minWidth = w->width; } void LInput_SetText(struct LInput* w, const cc_string* text_) { @@ -472,6 +465,7 @@ void LLabel_Init(struct LLabel* w, const char* text) { w->font = &Launcher_TextFont; String_InitArray(w->text, w->_textBuffer); + LBackend_InitLabel(w); LLabel_SetConst(w, text); } @@ -503,8 +497,7 @@ static const struct LWidgetVTABLE lline_VTABLE = { }; void LLine_Init(struct LLine* w, int width) { w->VTABLE = &lline_VTABLE; - w->width = Display_ScaleX(width); - w->height = Display_ScaleY(2); + LBackend_InitLine(w, width); } @@ -524,9 +517,8 @@ static const struct LWidgetVTABLE lslider_VTABLE = { }; 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->color = color; + LBackend_InitSlider(w, width, height); } diff --git a/src/LWidgets.h b/src/LWidgets.h index 04224d0ca..d2e0f622d 100644 --- a/src/LWidgets.h +++ b/src/LWidgets.h @@ -41,7 +41,8 @@ struct LWidgetVTABLE { cc_uint8 horAnchor, verAnchor; /* Specifies the reference point for when this widget is resized */ \ int xOffset, yOffset; /* Offset from the reference point */ \ void (*OnClick)(void* widget, int idx); /* Called when widget is clicked */ \ - Rect2D last; /* Widget's last drawn area */ + Rect2D last; /* Widget's last drawn area */ \ + void* meta; /* Backend specific data */ /* Represents an individual 2D gui component in the launcher. */ struct LWidget { LWidget_Layout };