From 97ab1923a80a6fe59a2df6f455747a66e92fe301 Mon Sep 17 00:00:00 2001 From: KikooDX Date: Wed, 26 May 2021 10:42:24 +0200 Subject: [PATCH] bar image variable color palette MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thank you Lephé! --- CMakeLists.txt | 2 +- assets/bar3.png | Bin 125 -> 125 bytes assets/fxconv-metadata.txt | 1 + include/bar.h | 1 + src/bar/draw.c | 12 +++++----- src/bar/init.c | 45 +++++++++++++++++++++++++++++++++++++ src/main.c | 10 ++++++++- 7 files changed, 64 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f9c1024..36a086a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/assets/bar3.png b/assets/bar3.png index 0cf786fd9262d5b9fb2ef1982272218b7691c9f6..98ac0340fa0220a8b20399cb0864a5fdddded1a6 100644 GIT binary patch delta 86 zcmV-c0IC0deUL0sjav!;APB(n{)etf5B*EaK}Eu*H0Z#SMikz^0Pd0ba^G=Es|!Ts s&C)EOL?ccq2yk>@lLRcBEAgKL1LgQK_E0JkNB{r;07*qoM6N<$g0Ti9sQ>@~ delta 86 zcmV-c0IC0deUL0sk--T7APfT)Cv$Qq6TM=k-%31a^2&W$3oM|XsRpeH*v7a|BEe|H s;iDiszPKa=MpoiuLlrOQUCw| diff --git a/assets/fxconv-metadata.txt b/assets/fxconv-metadata.txt index 22fb8f1..8da7e0d 100644 --- a/assets/fxconv-metadata.txt +++ b/assets/fxconv-metadata.txt @@ -4,6 +4,7 @@ background.png: name: bimg_background bar3.png: type: bopti-image + profile: p4 name: bimg_bar3 icons.png: type: bopti-image diff --git a/include/bar.h b/include/bar.h index 01d5385..ddae9ba 100644 --- a/include/bar.h +++ b/include/bar.h @@ -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. diff --git a/src/bar/draw.c b/src/bar/draw.c index a80bef3..033da01 100644 --- a/src/bar/draw.c +++ b/src/bar/draw.c @@ -1,6 +1,8 @@ #include "bar.h" #include +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); diff --git a/src/bar/init.c b/src/bar/init.c index 020e93f..7827cde 100644 --- a/src/bar/init.c +++ b/src/bar/init.c @@ -1,10 +1,24 @@ #include "bar.h" #include +#include +#include + +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]; +} diff --git a/src/main.c b/src/main.c index 5a37af0..b1478f0 100644 --- a/src/main.c +++ b/src/main.c @@ -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);