From 8a9dcb1ff7d686ac58a067c3833276914b8f9444 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 20 Feb 2018 12:17:06 +0000 Subject: [PATCH] Further widget updates. --- src/structs.h | 1 - src/system/widgets.c | 26 ++++++++++++++++---------- src/system/widgets.h | 1 + 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/structs.h b/src/structs.h index 3cbb755..11b9f29 100644 --- a/src/structs.h +++ b/src/structs.h @@ -490,7 +490,6 @@ struct Widget { int minValue; int maxValue; int visible; - int enabled; int numOptions; char **options; void (*action)(void); diff --git a/src/system/widgets.c b/src/system/widgets.c index fbf74e4..75874be 100644 --- a/src/system/widgets.c +++ b/src/system/widgets.c @@ -106,7 +106,7 @@ static void updateWidgetValue(int dir) void drawWidgets(void) { - int i, j, x; + int i, j, x, tw, th, outline; Widget *w; for (i = 0 ; i < numWidgets ; i++) @@ -128,26 +128,32 @@ void drawWidgets(void) drawText(w->x + w->w / 2, w->y + 2, 24, TA_CENTER, colors.white, w->label); + outline = (w == selectedWidget) ? 255 : 192; + switch (w->type) { - case WT_BUTTON: - break; - case WT_SLIDER: drawRect(w->x + w->w + 25, w->y, 500 * (w->value * 1.0 / w->maxValue), 40, 0, 128, 0, 255); - drawOutlineRect(w->x + w->w + 25, w->y, 500, 40, 0, 255, 0, 255); + drawOutlineRect(w->x + w->w + 25, w->y, 500, 40, 0, outline, 0, 255); break; case WT_SPINNER: + x = w->x + w->w + 25; for (j = 0 ; j < w->numOptions ; j++) { - x = w->x + w->w + 25 + (125 * j); + textSize(w->options[j], 24, &tw, &th); + + tw += 25; + if (j == w->value) { - drawRect(x, w->y, 100, w->h, 0, 128, 0, 255); - drawOutlineRect(x, w->y, 100, w->h, 0, 255, 0, 255); + drawRect(x, w->y, tw, w->h, 0, 128, 0, 255); + drawOutlineRect(x, w->y, tw, w->h, 0, outline, 0, 255); } - drawText(x + 50, w->y + 2, 24, TA_CENTER, colors.white, w->options[j]); + + drawText(x + tw / 2, w->y + 2, 24, TA_CENTER, colors.white, w->options[j]); + + x += tw + 25; } break; @@ -178,7 +184,7 @@ static void selectWidget(int dir) selectedWidget = &widgets[widgetIndex]; - } while (!selectedWidget->enabled && !selectedWidget->visible); + } while (!selectedWidget->visible); if (oldWidgetIndex != widgetIndex) { diff --git a/src/system/widgets.h b/src/system/widgets.h index 6808dc5..34a8d1a 100644 --- a/src/system/widgets.h +++ b/src/system/widgets.h @@ -35,6 +35,7 @@ extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int extern Texture *getTexture(const char *filename); extern Atlas *getImageFromAtlas(char *filename); extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center); +extern void textSize(const char *text, int size, int *w, int *h); extern App app; extern Colors colors;