Add btn_small

This commit is contained in:
Xavier Del Campo Romero 2024-01-27 17:09:39 +01:00
parent 27553f8ed1
commit cd2b58b561
Signed by: xavi
GPG Key ID: 84FF3612A9BF43F2
6 changed files with 43 additions and 6 deletions

View File

@ -56,6 +56,14 @@ sprite(NAME btn_right
CY 48
TRANSPARENT TRUE)
sprite(NAME btn_small
X 384
Y 0
BPP 4
CX 384
CY 48
TRANSPARENT TRUE)
level(NAME city1)
container(NAME jancity
@ -67,4 +75,5 @@ container(NAME jancity
btn_left
btn_mid
btn_right
btn_small
)

View File

@ -19,36 +19,48 @@ static const struct container c[] =
.type = CONTAINER_TYPE_SPRITE,
.data.sprite = &terrain_sprites[SIDEWALK]
},
{
.path = "roof1",
.type = CONTAINER_TYPE_SPRITE,
.data.sprite = &terrain_sprites[ROOF1]
},
{
.path = "roof2",
.type = CONTAINER_TYPE_SPRITE,
.data.sprite = &terrain_sprites[ROOF2]
},
{
.path = "cursor",
.type = CONTAINER_TYPE_SPRITE,
.data.sprite = &cursor_sprite
},
{
.path = "btn_left",
.type = CONTAINER_TYPE_SPRITE,
.data.sprite = &gui_button_sprites[GUI_BUTTON_LEFT]
},
{
.path = "btn_mid",
.type = CONTAINER_TYPE_SPRITE,
.data.sprite = &gui_button_sprites[GUI_BUTTON_MID]
},
{
.path = "btn_right",
.type = CONTAINER_TYPE_SPRITE,
.data.sprite = &gui_button_sprites[GUI_BUTTON_RIGHT]
},
{
.path = "btn_small",
.type = CONTAINER_TYPE_SPRITE,
.data.sprite = &gui_button_sprites[GUI_BUTTON_SMALL]
},
};
static bool init;

View File

@ -50,6 +50,7 @@ enum
GUI_BUTTON_LEFT,
GUI_BUTTON_MID,
GUI_BUTTON_RIGHT,
GUI_BUTTON_SMALL,
MAX_GUI_BUTTON_SPRITES
};

View File

@ -71,7 +71,7 @@ static int render_mid(const struct gui_button *const b,
}
else
{
fprintf(stderr, "%s: unexpected negative size for button %p\n",
fprintf(stderr, "%s: unexpected zero or negative size for button %p\n",
__func__, (void *)b);
return -1;
}

View File

@ -462,6 +462,7 @@ int human_player_render(const struct human_player *const h,
if (render_target(h)
|| render_own_units(h)
|| render_own_buildings(h)
|| human_player_gui_render(h)
|| input_render(&h->in, h->periph))
return -1;

View File

@ -5,6 +5,7 @@
#include <unit.h>
#include <gui.h>
#include <gui/bar.h>
#include <gui/button.h>
#include <gui/container.h>
#include <gui/label.h>
#include <gui/progress_bar.h>
@ -96,6 +97,19 @@ static int render_sel_multiple(const struct human_player *const h,
return gui_render(r);
}
static int render_top(const struct human_player *const h)
{
struct gui_button b;
gui_button_init(&b, GUI_BUTTON_TYPE_SPRITE);
b.on_pressed = NULL;
b.arg = NULL;
b.u.sprite.s = &gui_button_sprites[GUI_BUTTON_SMALL];
b.common.x = screen_w - b.u.sprite.s->w;
return gui_render(&b.common);
}
static int render_sel(const struct human_player *const h)
{
struct gui_rounded_rect r;
@ -106,15 +120,15 @@ static int render_sel(const struct human_player *const h)
r.h = screen_h / 4;
r.common.y = screen_h - r.h;
if (h->n_sel == 1)
return render_sel_single(h, &r.common);
return render_sel_multiple(h, &r.common);
return h->n_sel == 1 ? render_sel_single(h, &r.common)
: render_sel_multiple(h, &r.common);
}
int human_player_gui_render(const struct human_player *const h)
{
if (h->n_sel && render_sel(h))
if (render_top(h))
return -1;
else if (h->n_sel && render_sel(h))
return -1;
return 0;