From c1e7dbdfca6832ed6c6f800890415d911369e045 Mon Sep 17 00:00:00 2001 From: Shaun Inman Date: Sat, 14 Jan 2023 08:47:16 -0500 Subject: [PATCH] added GFX_blitABButtons() to api --- src/common/api.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ src/common/api.h | 1 + src/minui/main.c | 46 +------------------------------------- 3 files changed, 60 insertions(+), 45 deletions(-) diff --git a/src/common/api.c b/src/common/api.c index 458a2ee..502516f 100644 --- a/src/common/api.c +++ b/src/common/api.c @@ -302,6 +302,8 @@ void GFX_blitPill(int asset, SDL_Surface* dst, SDL_Rect* dst_rect) { int y = dst_rect->y; int w = dst_rect->w; int h = dst_rect->h; + + if (h==0) h = asset_rects[asset].h; int r = h / 2; if (w < h) w = h; @@ -392,6 +394,62 @@ void GFX_blitButton(char* hint, char*button, SDL_Surface* dst, SDL_Rect* dst_rec SDL_FreeSurface(text); } +void GFX_blitABButtons(char* a, char* b, SDL_Surface* dst) { + int ox; + int oy; + int ow; + char* hint; + char* button; + + struct Hint { + char* hint; + char* button; + int ow; + } hints[3]; + int w = 0; // individual button dimension + int h = 0; // hints index + ow = 0; // full pill width + ox = SCREEN_WIDTH - SCALE1(PADDING); + oy = SCREEN_HEIGHT - SCALE1(PADDING + PILL_SIZE); + + if (b) { + hint = b; + button = "B"; + w = GFX_getButtonWidth(hint, button); + hints[h].hint = hint; + hints[h].button = button; + hints[h].ow = w; + h += 1; + ow += SCALE1(BUTTON_MARGIN) + w; + } + + + hint = a; + button = "A"; + w = GFX_getButtonWidth(hint, button); + hints[h].hint = hint; + hints[h].button = button; + hints[h].ow = w; + h += 1; + ow += SCALE1(BUTTON_MARGIN) + w; + + ow += SCALE1(BUTTON_MARGIN); + ox -= ow; + GFX_blitPill(ASSET_DARK_GRAY_PILL, dst, &(SDL_Rect){ + ox, + oy, + ow, + SCALE1(PILL_SIZE) + }); + + ox += SCALE1(BUTTON_MARGIN); + oy += SCALE1(BUTTON_MARGIN); + for (int i=0; icount>1) { - hint = "BACK"; - button = "B"; - w = GFX_getButtonWidth(hint, button); - hints[h].hint = hint; - hints[h].button = button; - hints[h].ow = w; - h += 1; - ow += SCALE1(BUTTON_MARGIN) + w; - } - - hint = "OPEN"; - button = "A"; - w = GFX_getButtonWidth(hint, button); - hints[h].hint = hint; - hints[h].button = button; - hints[h].ow = w; - h += 1; - ow += SCALE1(BUTTON_MARGIN) + w; - - ow += SCALE1(BUTTON_MARGIN); - ox -= ow; - GFX_blitPill(ASSET_DARK_GRAY_PILL, screen, &(SDL_Rect){ - ox, - oy, - ow, - SCALE1(PILL_SIZE) - }); - - ox += SCALE1(BUTTON_MARGIN); - oy += SCALE1(BUTTON_MARGIN); - for (int i=0; icount>1?"BACK":NULL, screen); } }