fancy bar

This might be extremely slow, but for now it's good enough.
This commit is contained in:
KikooDX 2021-05-26 00:07:55 +02:00
parent 6447cec8f2
commit b4caec6f04
7 changed files with 25 additions and 6 deletions

View File

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

BIN
assets/bar3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 B

View File

@ -2,3 +2,6 @@
background.png:
type: bopti-image
name: bimg_background
bar3.png:
type: bopti-image
name: bimg_bar3

View File

@ -1,6 +1,8 @@
#pragma once
#include <gint/display.h>
extern bopti_image_t bimg_bar3;
#define BAR_WIDTH 16
#define BAR_Y 48
#define BAR_HEIGHT (DHEIGHT - BAR_Y - 16)
@ -10,6 +12,7 @@ struct Bar {
int x;
int y;
int height;
int limit_height;
float fill;
};

View File

@ -5,11 +5,21 @@ void
bar_draw(struct Bar bar)
{
const int height = bar.fill * (float)bar.height;
const int y = bar.y + bar.height - height;
const int low_y = bar.y + bar.height;
const int high_y = bar.y - bar.limit_height + bar.height - height;
int i;
/* borders */
drect_border(bar.x - 1, bar.y - 1, bar.x + BAR_WIDTH + 1,
bar.y + bar.height + 1, C_WHITE, 2, C_BLACK);
/* fill */
drect(bar.x, y, bar.x + BAR_WIDTH, y + height, C_RGB(0, 32, 32));
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);
/* draw higher limit */
dsubimage(bar.x, high_y, &bimg_bar3, 0, 0, bimg_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);
}

View File

@ -26,6 +26,7 @@ bar_init(enum BarID bar_id)
.x = x,
.y = BAR_Y,
.height = BAR_HEIGHT,
.limit_height = bimg_bar3.height / 2,
.fill = BAR_BASE_FILL,
};
}

View File

@ -19,7 +19,8 @@ main(void)
choice = choice_init();
bar_change(&bars[BAR_CASH], 0.2);
bar_change(&bars[BAR_SMILE], 0.4);
bar_change(&bars[BAR_SMILE], -0.6);
bar_change(&bars[BAR_SUN], 69.42);
main_draw();
getkey();