added GFX_blitABButtons() to api

This commit is contained in:
Shaun Inman 2023-01-14 08:47:16 -05:00
parent 8814fd2937
commit c1e7dbdfca
3 changed files with 60 additions and 45 deletions

View file

@ -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; i<h; i++) {
GFX_blitButton(hints[i].hint, hints[i].button, dst, &(SDL_Rect){ox,oy});
ox += hints[i].ow + SCALE1(BUTTON_MARGIN);
}
}
///////////////////////////////
// based on picoarch's audio

View file

@ -75,6 +75,7 @@ void GFX_blitPill(int asset, SDL_Surface* dst, SDL_Rect* dst_rect);
void GFX_blitBattery(SDL_Surface* dst, SDL_Rect* dst_rect);
int GFX_getButtonWidth(char* hint, char* button);
void GFX_blitButton(char* hint, char*button, SDL_Surface* dst, SDL_Rect* dst_rect);
void GFX_blitABButtons(char* a, char* b, SDL_Surface* dst);
///////////////////////////////

View file

@ -1582,51 +1582,7 @@ int main (int argc, char *argv[]) {
}
}
else {
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);
if (stack->count>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; i<h; i++) {
GFX_blitButton(hints[i].hint, hints[i].button, screen, &(SDL_Rect){ox,oy});
ox += hints[i].ow + SCALE1(BUTTON_MARGIN);
}
GFX_blitABButtons("OPEN", stack->count>1?"BACK":NULL, screen);
}
}