bar image variable color palette

Thank you Lephé!
This commit is contained in:
KikooDX 2021-05-26 10:42:24 +02:00
parent db24379558
commit 97ab1923a8
7 changed files with 64 additions and 7 deletions

View File

@ -7,7 +7,7 @@ project(PcAdmin C)
include(GenerateG1A)
include(GenerateG3A)
include(Fxconv)
find_package(Gint 2.4 REQUIRED)
find_package(Gint 2.5 REQUIRED)
include_directories(include)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 125 B

After

Width:  |  Height:  |  Size: 125 B

View File

@ -4,6 +4,7 @@ background.png:
name: bimg_background
bar3.png:
type: bopti-image
profile: p4
name: bimg_bar3
icons.png:
type: bopti-image

View File

@ -25,6 +25,7 @@ struct Bar {
enum BarID { BAR_CASH, BAR_HUMAN, BAR_SMILE, BAR_SUN };
struct Bar bar_init(enum BarID bar_id);
void bar_deinit(void);
void bar_update(struct Bar *bar);
void bar_draw(struct Bar bar);
/* Increase/decrease bar fill level.

View File

@ -1,6 +1,8 @@
#include "bar.h"
#include <gint/display.h>
extern bopti_image_t *vimg_bar3;
void
bar_draw(struct Bar bar)
{
@ -13,15 +15,15 @@ bar_draw(struct Bar bar)
drect(bar.x, bar.y - bar.limit_height, bar.x + BAR_WIDTH - 1,
low_y + bar.limit_height - 1, C_BLACK);
/* draw lower limit */
dsubimage(bar.x, low_y, &bimg_bar3, 0, bar.limit_height + 1,
bimg_bar3.width, bar.limit_height, DIMAGE_NOCLIP);
dsubimage(bar.x, low_y, vimg_bar3, 0, bar.limit_height + 1,
vimg_bar3->width, bar.limit_height, DIMAGE_NOCLIP);
/* draw higher limit */
dsubimage(bar.x, high_y, &bimg_bar3, 0, 0, bimg_bar3.width,
dsubimage(bar.x, high_y, vimg_bar3, 0, 0, vimg_bar3->width,
bar.limit_height, DIMAGE_NOCLIP);
/* draw fill */
for (i = high_y + bar.limit_height; i < low_y; i += 1)
dsubimage(bar.x, i, &bimg_bar3, 0, bar.limit_height,
bimg_bar3.width, 1, DIMAGE_NOCLIP);
dsubimage(bar.x, i, vimg_bar3, 0, bar.limit_height,
vimg_bar3->width, 1, DIMAGE_NOCLIP);
/* draw icons */
dsubimage(bar.x, BAR_ICON_Y, &bimg_icons, BAR_ICON_WIDTH * bar.id, 0,
BAR_ICON_WIDTH, BAR_ICON_HEIGHT, DIMAGE_NOCLIP);

View File

@ -1,10 +1,24 @@
#include "bar.h"
#include <gint/display.h>
#include <gint/std/stdlib.h>
#include <gint/std/string.h>
bopti_image_t *vimg_bar3;
color_t *vcol_bar3; /* was black */
static void init_vimg_bar3(void);
struct Bar
bar_init(enum BarID bar_id)
{
static int init_image = 1;
int x = 0;
if (init_image) {
init_image = 0;
init_vimg_bar3();
}
switch (bar_id) {
case BAR_CASH:
x = BAR_WIDTH;
@ -31,3 +45,34 @@ bar_init(enum BarID bar_id)
.fill = BAR_BASE_FILL,
};
}
void
bar_deinit(void)
{
free(vimg_bar3);
}
void
init_vimg_bar3(void)
{
int i;
color_t *palette;
const int sizeof_bimg_bar_3 =
sizeof(bimg_bar3) + 16 * sizeof(color_t) + /* palette */
(bimg_bar3.width + 1) / 2 * bimg_bar3.height; /* data */
/* allocate memory! */
vimg_bar3 = malloc(sizeof_bimg_bar_3);
/* copy original image to allocated area */
memcpy(vimg_bar3, &bimg_bar3, sizeof_bimg_bar_3);
/* find black color in palette */
palette = vimg_bar3->data;
i = -1;
while (++i < 16)
if (palette[i] == C_BLACK)
break;
vcol_bar3 = &palette[i];
}

View File

@ -8,6 +8,8 @@ static struct Choice choice;
static void main_draw(void);
extern color_t *vcol_bar3;
int
main(void)
{
@ -25,12 +27,16 @@ main(void)
main_draw();
getkey();
/* deinit */
bar_deinit();
return 1;
}
static void
main_draw(void)
{
static color_t colors[4] = { C_RED, C_GREEN, C_BLUE, C_WHITE };
extern bopti_image_t bimg_background;
int i;
@ -38,8 +44,10 @@ main_draw(void)
dimage(0, 0, &bimg_background);
/* draw bars */
for (i = 0; i < BAR_TOTAL; i += 1)
for (i = 0; i < BAR_TOTAL; i += 1) {
*vcol_bar3 = colors[i];
bar_draw(bars[i]);
}
/* draw choice */
choice_draw(choice);