Upgrade bar visuals
This commit is contained in:
parent
f101e53706
commit
de8a218bcc
|
@ -1,9 +1,9 @@
|
|||
#pragma once
|
||||
#include <gint/display.h>
|
||||
|
||||
#define BAR_WIDTH 12
|
||||
#define BAR_Y 32
|
||||
#define BAR_HEIGHT (DHEIGHT - BAR_Y * 2)
|
||||
#define BAR_WIDTH 16
|
||||
#define BAR_Y 48
|
||||
#define BAR_HEIGHT (DHEIGHT - BAR_Y - 16)
|
||||
#define BAR_BASE_FILL 0.5
|
||||
|
||||
struct Bar {
|
||||
|
@ -13,6 +13,8 @@ struct Bar {
|
|||
float fill;
|
||||
};
|
||||
|
||||
struct Bar bar_init(int x);
|
||||
enum BarID { BAR_CASH, BAR_HUMAN, BAR_SMILE, BAR_SUN };
|
||||
|
||||
struct Bar bar_init(enum BarID bar_id);
|
||||
void bar_update(struct Bar *bar);
|
||||
void bar_draw(struct Bar bar);
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
#include "bar.h"
|
||||
#include <gint/display.h>
|
||||
|
||||
void
|
||||
bar_draw(struct Bar bar)
|
||||
{
|
||||
const int height = bar.fill * (float)bar.height;
|
||||
const int y = bar.y + bar.height - height;
|
||||
|
||||
/* fill */
|
||||
drect(bar.x, y, bar.x + BAR_WIDTH, y + height, C_GREEN);
|
||||
/* borders */
|
||||
drect_border(bar.x, bar.y, bar.x + BAR_WIDTH, bar.y + bar.height,
|
||||
C_NONE, 2, C_BLACK);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,27 @@
|
|||
#include "bar.h"
|
||||
#include <gint/display.h>
|
||||
|
||||
struct Bar
|
||||
bar_init(int x)
|
||||
bar_init(enum BarID bar_id)
|
||||
{
|
||||
int x = 0;
|
||||
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){
|
||||
.x = x,
|
||||
.y = BAR_Y,
|
||||
|
|
|
@ -5,10 +5,15 @@
|
|||
int
|
||||
main(void)
|
||||
{
|
||||
struct Bar my_bar = bar_init(22);
|
||||
int i;
|
||||
struct Bar bars[4];
|
||||
|
||||
for (i = 0; i < 4; i += 1)
|
||||
bars[i] = bar_init(i);
|
||||
|
||||
dclear(C_WHITE);
|
||||
bar_draw(my_bar);
|
||||
for (i = 0; i < 4; i += 1)
|
||||
bar_draw(bars[i]);
|
||||
dupdate();
|
||||
getkey();
|
||||
|
||||
|
|
Loading…
Reference in New Issue