dumb down and speed up bar drawing

This commit is contained in:
KikooDX 2021-05-27 23:08:08 +02:00
parent 971ce1d541
commit c907bc2b69
5 changed files with 7 additions and 62 deletions

View File

@ -23,7 +23,6 @@ set(SOURCES
set(ASSETS
assets/background.png
assets/bar3.png
assets/icons.png
)

View File

@ -1,7 +1,6 @@
#pragma once
#include <gint/display.h>
extern bopti_image_t bimg_bar3;
extern bopti_image_t bimg_icons;
#define BAR_WIDTH 16
@ -17,7 +16,6 @@ struct Bar {
int x;
int y;
int height;
int limit_height;
float fill;
};
@ -25,7 +23,6 @@ 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

@ -8,22 +8,15 @@ bar_draw(struct Bar bar)
{
const int height = bar.fill * (float)bar.height;
const int low_y = bar.y + bar.height;
const int high_y = bar.y - bar.limit_height + bar.height - height;
int i;
const int high_y = bar.y + bar.height - height;
/* draw borders */
drect_border(bar.x, bar.y - 1, bar.x + BAR_WIDTH - 1, low_y + 1,
C_WHITE, 1, C_BLACK);
/* borders */
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, vimg_bar3, 0, bar.limit_height + 1,
vimg_bar3->width, bar.limit_height, DIMAGE_NOCLIP);
/* draw higher limit */
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, vimg_bar3, 0, bar.limit_height,
vimg_bar3->width, 1, DIMAGE_NOCLIP);
drect(bar.x + 1, high_y, bar.x + BAR_WIDTH - 2, low_y, C_RGB(31, 8, 5));
/* draw icons */
dsubimage(bar.x + (BAR_WIDTH - BAR_ICON_WIDTH) / 2, BAR_ICON_Y,
&bimg_icons, BAR_ICON_WIDTH * bar.id, 0, BAR_ICON_WIDTH,

View File

@ -3,22 +3,11 @@
#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;
@ -41,38 +30,6 @@ bar_init(enum BarID bar_id)
.x = x,
.y = BAR_Y,
.height = BAR_HEIGHT,
.limit_height = bimg_bar3.height / 2,
.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

@ -35,7 +35,6 @@ main(void)
/* deinit */
usb_close();
bar_deinit();
return 1;
}