choice base

This commit is contained in:
KikooDX 2021-05-24 23:04:03 +02:00
parent 8a30df2b51
commit 6447cec8f2
6 changed files with 79 additions and 2 deletions

View File

@ -17,6 +17,8 @@ set(SOURCES
src/bar/update.c
src/bar/draw.c
src/bar/change.c
src/choice/init.c
src/choice/draw.c
)
set(ASSETS

27
include/choice.h Normal file
View File

@ -0,0 +1,27 @@
#pragma once
#include "locale.h"
#include <gint/display.h>
#ifdef LANG_FR
#define CHOICE_YES "OUI"
#define CHOICE_NO "NON"
#define CHOICE_OK "OK"
#endif
#ifdef LANG_EN
#define CHOICE_YES "YES"
#define CHOICE_NO "NO"
#define CHOICE_OK "OK"
#endif
#define BUTTON_WIDTH 52
#define BUTTON_HEIGHT 32
#define BUTTON_Y (DHEIGHT - BUTTON_HEIGHT * 1.7)
struct Choice {
int cursor;
};
struct Choice choice_init(void);
void choice_draw(struct Choice choice);

4
include/locale.h Normal file
View File

@ -0,0 +1,4 @@
#pragma once
/* #define LANG_FR */
#define LANG_EN

33
src/choice/draw.c Normal file
View File

@ -0,0 +1,33 @@
#include "choice.h"
#include <gint/display.h>
static char *yes = CHOICE_YES;
static char *no = CHOICE_NO;
/* static char *ok = CHOICE_OK; */
static void button_draw(int id, int highlight);
void
choice_draw(struct Choice choice)
{
int i;
i = 2;
while (i-- > 0)
button_draw(i, choice.cursor == i);
}
static void
button_draw(int id, int highlight)
{
const int x = id ? (DWIDTH / 2 - BUTTON_WIDTH * 1.5)
: (DWIDTH / 2 + BUTTON_WIDTH * 0.5);
const int y = BUTTON_Y;
const int text_x = x + BUTTON_WIDTH / 2;
const int text_y = y + BUTTON_HEIGHT / 2;
const color_t color = highlight ? C_LIGHT : C_DARK;
drect(x, y, x + BUTTON_WIDTH, y + BUTTON_HEIGHT, color);
dtext_opt(text_x, text_y, C_WHITE, C_NONE, DTEXT_CENTER, DTEXT_MIDDLE,
id ? no : yes);
}

7
src/choice/init.c Normal file
View File

@ -0,0 +1,7 @@
#include "choice.h"
struct Choice
choice_init(void)
{
return (struct Choice){.cursor = 0};
}

View File

@ -1,8 +1,10 @@
#include "bar.h"
#include "choice.h"
#include <gint/display.h>
#include <gint/keyboard.h>
static struct Bar bars[BAR_TOTAL];
static struct Choice choice;
static void main_draw(void);
@ -14,6 +16,7 @@ main(void)
/* init */
for (i = 0; i < BAR_TOTAL; i += 1)
bars[i] = bar_init(i);
choice = choice_init();
bar_change(&bars[BAR_CASH], 0.2);
bar_change(&bars[BAR_SMILE], 0.4);
@ -30,8 +33,6 @@ main_draw(void)
extern bopti_image_t bimg_background;
int i;
dclear(C_WHITE);
/* draw background */
dimage(0, 0, &bimg_background);
@ -39,5 +40,8 @@ main_draw(void)
for (i = 0; i < BAR_TOTAL; i += 1)
bar_draw(bars[i]);
/* draw choice */
choice_draw(choice);
dupdate();
}