pcadmin/src/bar/init.c

79 lines
1.3 KiB
C

#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;
break;
case BAR_HUMAN:
x = BAR_WIDTH * 3;
break;
case BAR_SMILE:
x = DWIDTH - BAR_WIDTH * 4;
break;
case BAR_SUN:
x = DWIDTH - BAR_WIDTH * 2;
break;
default:
break;
}
return (struct Bar){
.id = 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];
}