mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 10:05:44 -04:00
Launcher: Simplify input widget, more splitting up into Backend
This commit is contained in:
parent
3e9bce269e
commit
62d8649900
@ -4,6 +4,8 @@
|
||||
#elif defined CC_BUILD_WIN_TEST
|
||||
/* Testing windows UI backend */
|
||||
#include "LBackend_Win.c"
|
||||
#elif defined CC_BUILD_IOS
|
||||
/* iOS uses custom UI backend */
|
||||
#else
|
||||
#include "Launcher.h"
|
||||
#include "Drawer2D.h"
|
||||
@ -27,7 +29,7 @@
|
||||
*#########################################################################################################################*/
|
||||
static int xBorder, xBorder2, xBorder3, xBorder4;
|
||||
static int yBorder, yBorder2, yBorder3, yBorder4;
|
||||
static int xInputOffset, yInputOffset;
|
||||
static int xInputOffset, yInputOffset, inputExpand;
|
||||
|
||||
void LBackend_Init(void) {
|
||||
xBorder = Display_ScaleX(1); xBorder2 = xBorder * 2; xBorder3 = xBorder * 3; xBorder4 = xBorder * 4;
|
||||
@ -35,6 +37,7 @@ void LBackend_Init(void) {
|
||||
|
||||
xInputOffset = Display_ScaleX(5);
|
||||
yInputOffset = Display_ScaleY(2);
|
||||
inputExpand = Display_ScaleX(20);
|
||||
}
|
||||
|
||||
static void DrawBoxBounds(BitmapCol col, int x, int y, int width, int height) {
|
||||
@ -73,78 +76,15 @@ void LBackend_UpdateButton(struct LButton* w) {
|
||||
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);
|
||||
g = BitmapCol_G(a) + amount; Math_Clamp(g, 0, 255);
|
||||
b = BitmapCol_B(a) + amount; Math_Clamp(b, 0, 255);
|
||||
return BitmapCol_Make(r, g, b, 255);
|
||||
}
|
||||
|
||||
static void LButton_DrawBackground(struct LButton* w) {
|
||||
BitmapCol color = w->hovered ? Launcher_Theme.ButtonForeActiveColor
|
||||
: Launcher_Theme.ButtonForeColor;
|
||||
|
||||
if (Launcher_Theme.ClassicBackground) {
|
||||
Gradient_Noise(&Launcher_Framebuffer, color, 8,
|
||||
w->x + xBorder, w->y + yBorder,
|
||||
w->width - xBorder2, w->height - yBorder2);
|
||||
} else {
|
||||
|
||||
Gradient_Vertical(&Launcher_Framebuffer, LButton_Expand(color, 8), LButton_Expand(color, -8),
|
||||
w->x + xBorder, w->y + yBorder,
|
||||
w->width - xBorder2, w->height - yBorder2);
|
||||
}
|
||||
}
|
||||
|
||||
static void LButton_DrawBorder(struct LButton* w) {
|
||||
BitmapCol backColor = Launcher_Theme.ButtonBorderColor;
|
||||
Drawer2D_Clear(&Launcher_Framebuffer, backColor,
|
||||
w->x + xBorder, w->y,
|
||||
w->width - xBorder2, yBorder);
|
||||
Drawer2D_Clear(&Launcher_Framebuffer, backColor,
|
||||
w->x + xBorder, w->y + w->height - yBorder,
|
||||
w->width - xBorder2, yBorder);
|
||||
Drawer2D_Clear(&Launcher_Framebuffer, backColor,
|
||||
w->x, w->y + yBorder,
|
||||
xBorder, w->height - yBorder2);
|
||||
Drawer2D_Clear(&Launcher_Framebuffer, backColor,
|
||||
w->x + w->width - xBorder, w->y + yBorder,
|
||||
xBorder, w->height - yBorder2);
|
||||
}
|
||||
|
||||
static void LButton_DrawHighlight(struct LButton* w) {
|
||||
BitmapCol activeColor = BitmapCol_Make(189, 198, 255, 255);
|
||||
BitmapCol color = Launcher_Theme.ButtonHighlightColor;
|
||||
|
||||
if (Launcher_Theme.ClassicBackground) {
|
||||
if (w->hovered) color = activeColor;
|
||||
|
||||
Drawer2D_Clear(&Launcher_Framebuffer, color,
|
||||
w->x + xBorder2, w->y + yBorder,
|
||||
w->width - xBorder4, yBorder);
|
||||
Drawer2D_Clear(&Launcher_Framebuffer, color,
|
||||
w->x + xBorder, w->y + yBorder2,
|
||||
xBorder, w->height - yBorder4);
|
||||
} else if (!w->hovered) {
|
||||
Drawer2D_Clear(&Launcher_Framebuffer, color,
|
||||
w->x + xBorder2, w->y + yBorder,
|
||||
w->width - xBorder4, yBorder);
|
||||
}
|
||||
}
|
||||
|
||||
void LBackend_DrawButton(struct LButton* w) {
|
||||
struct DrawTextArgs args;
|
||||
int xOffset, yOffset;
|
||||
|
||||
LButton_DrawBackground(w, &Launcher_Framebuffer, w->x, w->y);
|
||||
xOffset = w->width - w->_textWidth;
|
||||
yOffset = w->height - w->_textHeight;
|
||||
DrawTextArgs_Make(&args, &w->text, &Launcher_TitleFont, true);
|
||||
|
||||
LButton_DrawBackground(w);
|
||||
LButton_DrawBorder(w);
|
||||
LButton_DrawHighlight(w);
|
||||
|
||||
if (!w->hovered) Drawer2D.Colors['f'] = Drawer2D.Colors['7'];
|
||||
Drawer2D_DrawText(&Launcher_Framebuffer, &args,
|
||||
w->x + xOffset / 2, w->y + yOffset / 2);
|
||||
@ -322,10 +262,26 @@ static void LInput_DrawText(struct LInput* w, struct DrawTextArgs* args) {
|
||||
}
|
||||
}
|
||||
|
||||
CC_NOINLINE static void LInput_UpdateDimensions(struct LInput* w, const cc_string* text) {
|
||||
struct DrawTextArgs args;
|
||||
int textWidth;
|
||||
DrawTextArgs_Make(&args, text, &Launcher_TextFont, false);
|
||||
|
||||
textWidth = Drawer2D_TextWidth(&args);
|
||||
w->width = max(w->minWidth, textWidth + inputExpand);
|
||||
w->_textHeight = Drawer2D_TextHeight(&args);
|
||||
}
|
||||
|
||||
void LBackend_UpdateInput(struct LInput* w, const cc_string* text) {
|
||||
LInput_UpdateDimensions(w, text);
|
||||
}
|
||||
|
||||
void LBackend_DrawInput(struct LInput* w, const cc_string* text) {
|
||||
struct DrawTextArgs args;
|
||||
DrawTextArgs_Make(&args, text, &Launcher_TextFont, false);
|
||||
|
||||
/* TODO shouldn't be recalcing size in draw.... */
|
||||
LInput_UpdateDimensions(w, text);
|
||||
LInput_DrawOuterBorder(w);
|
||||
LInput_DrawInnerBorder(w);
|
||||
Drawer2D_Clear(&Launcher_Framebuffer, BITMAPCOL_WHITE,
|
||||
@ -368,7 +324,7 @@ void LBackend_InitLine(struct LLine* w, int width) {
|
||||
}
|
||||
|
||||
void LBackend_DrawLine(struct LLine* w) {
|
||||
BitmapCol color = Launcher_Theme.ClassicBackground ? CLASSIC_LINE_COLOR : Launcher_Theme.ButtonBorderColor;
|
||||
BitmapCol color = LLine_GetColor();
|
||||
Gradient_Blend(&Launcher_Framebuffer, color, 128, w->x, w->y, w->width, w->height);
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,6 @@ struct LLabel;
|
||||
struct LLine;
|
||||
struct LSlider;
|
||||
|
||||
#define CLASSIC_LINE_COLOR BitmapCol_Make(128,128,128, 255)
|
||||
|
||||
void LBackend_Init(void);
|
||||
void LBackend_WidgetRepositioned(struct LWidget* w);
|
||||
void LBackend_SetScreen(struct LScreen* s);
|
||||
@ -29,6 +27,7 @@ void LBackend_InitCheckbox(struct LCheckbox* w);
|
||||
void LBackend_DrawCheckbox(struct LCheckbox* w);
|
||||
|
||||
void LBackend_InitInput(struct LInput* w, int width);
|
||||
void LBackend_UpdateInput(struct LInput* w, const cc_string* text);
|
||||
void LBackend_DrawInput(struct LInput* w, const cc_string* text);
|
||||
|
||||
void LBackend_InitLabel(struct LLabel* w);
|
||||
|
@ -464,10 +464,6 @@ static void ColoursScreen_ToggleBG(void* w, int idx) {
|
||||
Launcher_Redraw();
|
||||
}
|
||||
|
||||
static cc_bool ColoursScreen_InputFilter(char c) {
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
|
||||
static void ColoursScreen_Init(struct LScreen* s_) {
|
||||
struct ColoursScreen* s = (struct ColoursScreen*)s_;
|
||||
int i;
|
||||
@ -475,10 +471,9 @@ static void ColoursScreen_Init(struct LScreen* s_) {
|
||||
s->numWidgets = Array_Elems(colours_widgets);
|
||||
|
||||
for (i = 0; i < 5 * 3; i++) {
|
||||
LInput_Init(&s->iptColours[i], 55, NULL);
|
||||
s->iptColours[i].type = KEYBOARD_TYPE_INTEGER;
|
||||
s->iptColours[i].TextFilter = ColoursScreen_InputFilter;
|
||||
s->iptColours[i].TextChanged = ColoursScreen_TextChanged;
|
||||
LInput_Init(&s->iptColours[i], 55, NULL);
|
||||
}
|
||||
|
||||
LLabel_Init( &s->lblNames[0], "Background");
|
||||
@ -865,13 +860,12 @@ static void MainScreen_Singleplayer(void* w, int idx) {
|
||||
Launcher_StartGame(user, &String_Empty, &String_Empty, &String_Empty, &String_Empty);
|
||||
}
|
||||
|
||||
static cc_bool MainScreen_PasswordFilter(char c) { return true; }
|
||||
|
||||
static void MainScreen_Init(struct LScreen* s_) {
|
||||
cc_string user, pass; char passBuffer[STRING_SIZE];
|
||||
struct MainScreen* s = (struct MainScreen*)s_;
|
||||
s->widgets = main_widgets;
|
||||
s->numWidgets = Array_Elems(main_widgets);
|
||||
s->widgets = main_widgets;
|
||||
s->numWidgets = Array_Elems(main_widgets);
|
||||
s->iptPassword.type = KEYBOARD_TYPE_PASSWORD;
|
||||
|
||||
LInput_Init( &s->iptUsername, 280, "&gUsername..");
|
||||
LInput_Init( &s->iptPassword, 280, "&gPassword..");
|
||||
@ -896,8 +890,6 @@ static void MainScreen_Init(struct LScreen* s_) {
|
||||
/* need to set text here for right size */
|
||||
s->lblUpdate.font = &Launcher_HintFont;
|
||||
LLabel_SetConst(&s->lblUpdate, "&eChecking..");
|
||||
s->iptPassword.type = KEYBOARD_TYPE_PASSWORD;
|
||||
s->iptPassword.TextFilter = MainScreen_PasswordFilter;
|
||||
|
||||
String_InitArray(pass, passBuffer);
|
||||
Options_UNSAFE_Get(LOPT_USERNAME, &user);
|
||||
|
121
src/LWidgets.c
121
src/LWidgets.c
@ -14,16 +14,20 @@
|
||||
#include "Utils.h"
|
||||
#include "LBackend.h"
|
||||
|
||||
static int xInputOffset, inputExpand;
|
||||
static int xInputOffset;
|
||||
static int caretOffset, caretWidth, caretHeight;
|
||||
static int scrollbarWidth, dragPad, gridlineWidth, gridlineHeight;
|
||||
static int hdrYOffset, hdrYPadding, rowYOffset, rowYPadding;
|
||||
static int cellXOffset, cellXPadding, cellMinWidth;
|
||||
static int flagXOffset, flagYOffset;
|
||||
static int xBorder, xBorder2, xBorder4;
|
||||
static int yBorder, yBorder2, yBorder4;
|
||||
|
||||
void LWidget_CalcOffsets(void) {
|
||||
xBorder = Display_ScaleX(1); xBorder2 = xBorder * 2; xBorder4 = xBorder * 4;
|
||||
yBorder = Display_ScaleY(1); yBorder2 = yBorder * 2; yBorder4 = yBorder * 4;
|
||||
|
||||
xInputOffset = Display_ScaleX(5);
|
||||
inputExpand = Display_ScaleX(20);
|
||||
|
||||
caretOffset = Display_ScaleY(5);
|
||||
caretWidth = Display_ScaleX(10);
|
||||
@ -79,6 +83,72 @@ void LWidget_Redraw(void* widget) {
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------ButtonWidget-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static BitmapCol LButton_Expand(BitmapCol a, int amount) {
|
||||
int r, g, b;
|
||||
r = BitmapCol_R(a) + amount; Math_Clamp(r, 0, 255);
|
||||
g = BitmapCol_G(a) + amount; Math_Clamp(g, 0, 255);
|
||||
b = BitmapCol_B(a) + amount; Math_Clamp(b, 0, 255);
|
||||
return BitmapCol_Make(r, g, b, 255);
|
||||
}
|
||||
|
||||
static void LButton_DrawBase(struct LButton* w, struct Bitmap* bmp, int x, int y) {
|
||||
BitmapCol color = w->hovered ? Launcher_Theme.ButtonForeActiveColor
|
||||
: Launcher_Theme.ButtonForeColor;
|
||||
|
||||
if (Launcher_Theme.ClassicBackground) {
|
||||
Gradient_Noise(bmp, color, 8,
|
||||
x + xBorder, y + yBorder,
|
||||
w->width - xBorder2, w->height - yBorder2);
|
||||
} else {
|
||||
|
||||
Gradient_Vertical(bmp, LButton_Expand(color, 8), LButton_Expand(color, -8),
|
||||
x + xBorder, y + yBorder,
|
||||
w->width - xBorder2, w->height - yBorder2);
|
||||
}
|
||||
}
|
||||
|
||||
static void LButton_DrawBorder(struct LButton* w, struct Bitmap* bmp, int x, int y) {
|
||||
BitmapCol backColor = Launcher_Theme.ButtonBorderColor;
|
||||
Drawer2D_Clear(bmp, backColor,
|
||||
x + xBorder, y,
|
||||
w->width - xBorder2, yBorder);
|
||||
Drawer2D_Clear(bmp, backColor,
|
||||
x + xBorder, y + w->height - yBorder,
|
||||
w->width - xBorder2, yBorder);
|
||||
Drawer2D_Clear(bmp, backColor,
|
||||
x, y + yBorder,
|
||||
xBorder, w->height - yBorder2);
|
||||
Drawer2D_Clear(bmp, backColor,
|
||||
x + w->width - xBorder, y + yBorder,
|
||||
xBorder, w->height - yBorder2);
|
||||
}
|
||||
|
||||
static void LButton_DrawHighlight(struct LButton* w, struct Bitmap* bmp, int x, int y) {
|
||||
BitmapCol activeColor = BitmapCol_Make(189, 198, 255, 255);
|
||||
BitmapCol color = Launcher_Theme.ButtonHighlightColor;
|
||||
|
||||
if (Launcher_Theme.ClassicBackground) {
|
||||
if (w->hovered) color = activeColor;
|
||||
|
||||
Drawer2D_Clear(&Launcher_Framebuffer, color,
|
||||
x + xBorder2, y + yBorder,
|
||||
w->width - xBorder4, yBorder);
|
||||
Drawer2D_Clear(&Launcher_Framebuffer, color,
|
||||
x + xBorder, y + yBorder2,
|
||||
xBorder, w->height - yBorder4);
|
||||
} else if (!w->hovered) {
|
||||
Drawer2D_Clear(&Launcher_Framebuffer, color,
|
||||
x + xBorder2, y + yBorder,
|
||||
w->width - xBorder4, yBorder);
|
||||
}
|
||||
}
|
||||
|
||||
void LButton_DrawBackground(struct LButton* w, struct Bitmap* bmp, int x, int y) {
|
||||
LButton_DrawBase(w, bmp, x, y);
|
||||
LButton_DrawBorder(w, bmp, x, y);
|
||||
LButton_DrawHighlight(w, bmp, x, y);
|
||||
}
|
||||
|
||||
static void LButton_Draw(void* widget) {
|
||||
struct LButton* w = (struct LButton*)widget;
|
||||
LBackend_DrawButton(w);
|
||||
@ -146,23 +216,12 @@ CC_NOINLINE static void LInput_GetText(struct LInput* w, cc_string* text) {
|
||||
}
|
||||
}
|
||||
|
||||
CC_NOINLINE static void LInput_UpdateDimensions(struct LInput* w, const cc_string* text) {
|
||||
struct DrawTextArgs args;
|
||||
int textWidth;
|
||||
DrawTextArgs_Make(&args, text, &Launcher_TextFont, false);
|
||||
|
||||
textWidth = Drawer2D_TextWidth(&args);
|
||||
w->width = max(w->minWidth, textWidth + inputExpand);
|
||||
w->_textHeight = Drawer2D_TextHeight(&args);
|
||||
}
|
||||
|
||||
static void LInput_Draw(void* widget) {
|
||||
struct LInput* w = (struct LInput*)widget;
|
||||
cc_string text; char textBuffer[STRING_SIZE];
|
||||
|
||||
String_InitArray(text, textBuffer);
|
||||
LInput_GetText(w, &text);
|
||||
LInput_UpdateDimensions(w, &text);
|
||||
LBackend_DrawInput(w, &text);
|
||||
}
|
||||
|
||||
@ -346,7 +405,7 @@ static void LInput_KeyDown(void* widget, int key, cc_bool was) {
|
||||
} else if (key == INPUT_CLIPBOARD_PASTE) {
|
||||
LInput_CopyFromClipboard(w);
|
||||
} else if (key == KEY_ESCAPE) {
|
||||
LInput_Clear(w);
|
||||
if (w->text.length) LInput_SetString(w, &String_Empty);
|
||||
} else if (key == KEY_LEFT) {
|
||||
LInput_AdvanceCaretPos(w, false);
|
||||
} else if (key == KEY_RIGHT) {
|
||||
@ -354,9 +413,19 @@ static void LInput_KeyDown(void* widget, int key, cc_bool was) {
|
||||
}
|
||||
}
|
||||
|
||||
static cc_bool LInput_CanAppend(struct LInput* w, char c) {
|
||||
switch (w->type) {
|
||||
case KEYBOARD_TYPE_PASSWORD:
|
||||
return true; /* keyboard accepts all characters */
|
||||
case KEYBOARD_TYPE_INTEGER:
|
||||
return c >= '0' && c <= '9';
|
||||
}
|
||||
return c >= ' ' && c <= '~' && c != '&';
|
||||
}
|
||||
|
||||
/* Appends a character to the currently entered text */
|
||||
static CC_NOINLINE cc_bool LInput_Append(struct LInput* w, char c) {
|
||||
if (w->TextFilter(c) && w->text.length < w->text.capacity) {
|
||||
if (LInput_CanAppend(w, c) && w->text.length < w->text.capacity) {
|
||||
if (w->caretPos == -1) {
|
||||
String_Append(&w->text, c);
|
||||
} else {
|
||||
@ -382,10 +451,6 @@ static void LInput_TextChanged(void* widget, const cc_string* str) {
|
||||
if (w->TextChanged) w->TextChanged(w);
|
||||
}
|
||||
|
||||
static cc_bool LInput_DefaultInputFilter(char c) {
|
||||
return c >= ' ' && c <= '~' && c != '&';
|
||||
}
|
||||
|
||||
static const struct LWidgetVTABLE linput_VTABLE = {
|
||||
LInput_Draw, LInput_TickCaret,
|
||||
LInput_KeyDown, LInput_KeyChar, /* Key */
|
||||
@ -397,7 +462,6 @@ static const struct LWidgetVTABLE linput_VTABLE = {
|
||||
void LInput_Init(struct LInput* w, int width, const char* hintText) {
|
||||
w->VTABLE = &linput_VTABLE;
|
||||
w->tabSelectable = true;
|
||||
w->TextFilter = LInput_DefaultInputFilter;
|
||||
String_InitArray(w->text, w->_textBuffer);
|
||||
|
||||
w->hintText = hintText;
|
||||
@ -411,9 +475,9 @@ void LInput_SetText(struct LInput* w, const cc_string* text_) {
|
||||
String_Copy(&w->text, text_);
|
||||
String_InitArray(text, textBuffer);
|
||||
|
||||
LInput_GetText(w, &text);
|
||||
LInput_UpdateDimensions(w, &text);
|
||||
LInput_ClampCaret(w);
|
||||
LInput_GetText(w, &text);
|
||||
LBackend_UpdateInput(w, &text);
|
||||
}
|
||||
|
||||
void LInput_ClearText(struct LInput* w) {
|
||||
@ -431,14 +495,6 @@ void LInput_AppendString(struct LInput* w, const cc_string* str) {
|
||||
if (appended) LWidget_Redraw(w);
|
||||
}
|
||||
|
||||
void LInput_Clear(struct LInput* w) {
|
||||
if (!w->text.length) return;
|
||||
LInput_ClearText(w);
|
||||
|
||||
if (w->TextChanged) w->TextChanged(w);
|
||||
LWidget_Redraw(w);
|
||||
}
|
||||
|
||||
void LInput_SetString(struct LInput* w, const cc_string* str) {
|
||||
LInput_SetText(w, str);
|
||||
if (w->TextChanged) w->TextChanged(w);
|
||||
@ -500,6 +556,11 @@ void LLine_Init(struct LLine* w, int width) {
|
||||
LBackend_InitLine(w, width);
|
||||
}
|
||||
|
||||
#define CLASSIC_LINE_COLOR BitmapCol_Make(128,128,128, 255)
|
||||
BitmapCol LLine_GetColor(void) {
|
||||
return Launcher_Theme.ClassicBackground ? CLASSIC_LINE_COLOR : Launcher_Theme.ButtonBorderColor;
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------SliderWidget-------------------------------------------------------*
|
||||
|
@ -59,6 +59,7 @@ struct LButton {
|
||||
};
|
||||
CC_NOINLINE void LButton_Init(struct LButton* w, int width, int height, const char* text);
|
||||
CC_NOINLINE void LButton_SetConst(struct LButton* w, const char* text);
|
||||
CC_NOINLINE void LButton_DrawBackground(struct LButton* w, struct Bitmap* bmp, int x, int y);
|
||||
|
||||
struct LCheckbox {
|
||||
LWidget_Layout
|
||||
@ -81,8 +82,6 @@ struct LInput {
|
||||
void (*ClipboardFilter)(cc_string* str);
|
||||
/* Callback invoked when the text is changed. Can be NULL. */
|
||||
void (*TextChanged)(struct LInput* w);
|
||||
/* Callback invoked whenever user attempts to append a character to the text. */
|
||||
cc_bool (*TextFilter)(char c);
|
||||
/* Specifies the position that characters are inserted/deleted from. */
|
||||
/* NOTE: -1 to insert/delete characters at end of the text. */
|
||||
int caretPos;
|
||||
@ -96,8 +95,6 @@ CC_NOINLINE void LInput_ClearText(struct LInput* w);
|
||||
|
||||
/* Appends a string to the currently entered text */
|
||||
CC_NOINLINE void LInput_AppendString(struct LInput* w, const cc_string* str);
|
||||
/* Resets the currently entered text to an empty string */
|
||||
CC_NOINLINE void LInput_Clear(struct LInput* w);
|
||||
/* Sets the currently entered text to the given string */
|
||||
CC_NOINLINE void LInput_SetString(struct LInput* w, const cc_string* str);
|
||||
|
||||
@ -117,6 +114,7 @@ struct LLine {
|
||||
LWidget_Layout
|
||||
};
|
||||
CC_NOINLINE void LLine_Init(struct LLine* w, int width);
|
||||
CC_NOINLINE BitmapCol LLine_GetColor(void);
|
||||
|
||||
/* Represents a slider bar that may or may not be modifiable by the user. */
|
||||
struct LSlider {
|
||||
|
@ -76,11 +76,16 @@ static void RemoveTouch(UITouch* t) {
|
||||
|
||||
// helpers for LBackend
|
||||
static void LBackend_HandleButton(id btn);
|
||||
static void LBackend_HandleInput(id ipt);
|
||||
|
||||
- (void)handleButtonPress:(id)sender {
|
||||
LBackend_HandleButton(sender);
|
||||
}
|
||||
|
||||
- (void)handleTextChanged:(id)sender {
|
||||
LBackend_HandleInput(sender);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
static cc_bool landscape_locked;
|
||||
@ -494,6 +499,7 @@ void Platform_ShareScreenshot(const cc_string* filename) {
|
||||
String_Format1(&path, "screenshots/%s", filename);
|
||||
Platform_EncodeUtf8(tmp, &path);
|
||||
|
||||
// TODO unify with ToNSString
|
||||
NSString* pathStr = [NSString stringWithUTF8String:tmp];
|
||||
UIImage* img = [UIImage imageWithContentsOfFile:pathStr];
|
||||
|
||||
@ -505,7 +511,21 @@ void Platform_ShareScreenshot(const cc_string* filename) {
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------UI Backend--------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static UIColor* ToUIColor(BitmapCol color, float A) {
|
||||
float R = BitmapCol_R(color) / 255.0f;
|
||||
float G = BitmapCol_G(color) / 255.0f;
|
||||
float B = BitmapCol_B(color) / 255.0f;
|
||||
return [UIColor colorWithRed:R green:G blue:B alpha:A];
|
||||
}
|
||||
|
||||
static NSString* ToNSString(const cc_string* text) {
|
||||
char raw[NATIVE_STR_LEN];
|
||||
Platform_EncodeUtf8(raw, text);
|
||||
return [NSString stringWithUTF8String:raw];
|
||||
}
|
||||
|
||||
void LBackend_Init(void) {
|
||||
}
|
||||
@ -572,8 +592,8 @@ static struct LWidget* FindWidgetForView(id obj) {
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------ButtonWidget-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static void LBackend_HandleButton(id btn_id) {
|
||||
struct LWidget* w = FindWidgetForView(btn_id);
|
||||
static void LBackend_HandleButton(id btn_obj) {
|
||||
struct LWidget* w = FindWidgetForView(btn_obj);
|
||||
if (w == NULL) return;
|
||||
|
||||
struct LButton* btn = (struct LButton*)w;
|
||||
@ -588,14 +608,19 @@ void LBackend_InitButton(struct LButton* w, int width, int height) {
|
||||
|
||||
AssignView(w, btn);
|
||||
UpdateWidgetDimensions(w);
|
||||
|
||||
struct Bitmap bmp;//
|
||||
//Bitmap_Allocate(&bmp, w->width, w->height);
|
||||
//LButton_DrawBackground(w, &bmp, 0, 0);
|
||||
|
||||
//UIImage* img = [UIImage i]
|
||||
//[btn setBackgroundImage:img forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
void LBackend_UpdateButton(struct LButton* w) {
|
||||
UIButton* btn = (__bridge UIButton*)w->meta;
|
||||
char raw[NATIVE_STR_LEN];
|
||||
Platform_EncodeUtf8(raw, &w->text);
|
||||
NSString* str = ToNSString(&w->text);
|
||||
|
||||
NSString* str = [NSString stringWithUTF8String:raw];
|
||||
[btn setTitle:str forState:UIControlStateNormal];
|
||||
UpdateWidgetDimensions(w);
|
||||
}
|
||||
@ -622,15 +647,42 @@ void LBackend_DrawCheckbox(struct LCheckbox* w) {
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------InputWidget--------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static void LBackend_HandleInput(id ipt_obj) {
|
||||
struct LWidget* w = FindWidgetForView(ipt_obj);
|
||||
if (w == NULL) return;
|
||||
|
||||
UITextField* src = (UITextField*)ipt_obj;
|
||||
const char* str = [[src text] UTF8String];
|
||||
|
||||
struct LInput* ipt = (struct LInput*)w;
|
||||
ipt->text.length = 0;
|
||||
String_AppendUtf8(&ipt->text, str, String_Length(str));
|
||||
}
|
||||
|
||||
void LBackend_InitInput(struct LInput* w, int width) {
|
||||
UITextField* fld = [[UITextField alloc] init];
|
||||
fld.frame = CGRectMake(0, 0, width, 30);
|
||||
fld.borderStyle = UITextBorderStyleBezel;
|
||||
fld.frame = CGRectMake(0, 0, width, 30);
|
||||
fld.borderStyle = UITextBorderStyleBezel;
|
||||
fld.backgroundColor = [UIColor whiteColor];
|
||||
// TODO should be app_handle, because win_handle can change
|
||||
[fld addTarget:win_handle action:@selector(handleTextChanged:) forControlEvents:UIControlEventEditingChanged];
|
||||
|
||||
if (w->type == KEYBOARD_TYPE_INTEGER) {
|
||||
[fld setKeyboardType:UIKeyboardTypeNumberPad];
|
||||
} else if (w->type == KEYBOARD_TYPE_PASSWORD) {
|
||||
fld.secureTextEntry = YES;
|
||||
}
|
||||
|
||||
AssignView(w, fld);
|
||||
UpdateWidgetDimensions(w);
|
||||
}
|
||||
|
||||
void LBackend_UpdateInput(struct LInput* w, const cc_string* text) {
|
||||
UITextField* fld = (__bridge UITextField*)w->meta;
|
||||
fld.text = ToNSString(&w->text);
|
||||
UpdateWidgetDimensions(w);
|
||||
}
|
||||
|
||||
void LBackend_DrawInput(struct LInput* w, const cc_string* text) {
|
||||
}
|
||||
|
||||
@ -639,7 +691,8 @@ void LBackend_DrawInput(struct LInput* w, const cc_string* text) {
|
||||
*------------------------------------------------------LabelWidget--------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
void LBackend_InitLabel(struct LLabel* w) {
|
||||
UILabel* lbl = [[UILabel alloc] init];
|
||||
UILabel* lbl = [[UILabel alloc] init];
|
||||
lbl.textColor = [UIColor whiteColor];
|
||||
|
||||
AssignView(w, lbl);
|
||||
UpdateWidgetDimensions(w);
|
||||
@ -668,11 +721,8 @@ void LBackend_InitLine(struct LLine* w, int width) {
|
||||
UIView* view = [[UIView alloc] init];
|
||||
view.frame = CGRectMake(0, 0, width, 2);
|
||||
|
||||
BitmapCol color = Launcher_Theme.ClassicBackground ? CLASSIC_LINE_COLOR : Launcher_Theme.ButtonBorderColor;
|
||||
float R = BitmapCol_R(color) / 255.0f;
|
||||
float G = BitmapCol_G(color) / 255.0f;
|
||||
float B = BitmapCol_B(color) / 255.0f;
|
||||
view.backgroundColor = [UIColor colorWithRed:R green:G blue:B alpha:0.5f];
|
||||
BitmapCol color = LLine_GetColor();
|
||||
view.backgroundColor = ToUIColor(color, 0.5f);
|
||||
|
||||
AssignView(w, view);
|
||||
UpdateWidgetDimensions(w);
|
||||
|
Loading…
x
Reference in New Issue
Block a user