Back to shtanton's homepage
summaryrefslogtreecommitdiff
path: root/src/all.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/all.c')
-rw-r--r--src/all.c57
1 files changed, 54 insertions, 3 deletions
diff --git a/src/all.c b/src/all.c
index 3d192ba..372690f 100644
--- a/src/all.c
+++ b/src/all.c
@@ -89,18 +89,23 @@ static const Color colors[N_COLORS][4] = {
},
};
+static const Button buttons[N_BUTTONS] = {
+ [BUTTON_RETRY] = {.x = 16, .y = 16, .w = 128, .h = 32},
+ [BUTTON_BACK] = {.x = 16, .y = 48, .w = 128, .h = 32},
+};
+
static DrawList *render(State *state, UI *ui, Arena *a) {
(void) ui;
DrawList *drawList = new(a, 1, DrawList);
- int cellWidth = ui->width / GRIDWIDTH;
+ int cellWidth = (ui->width - GRID_OFFSET_X) / GRIDWIDTH;
int cellHeight = ui->height / GRIDHEIGHT;
for (int x = 0; x < GRIDWIDTH; x++) {
for (int y = 0; y < GRIDHEIGHT; y++) {
drawList->els[drawList->len++] = (DrawElement) {
- .x = cellWidth * x,
+ .x = cellWidth * x + GRID_OFFSET_X,
.y = cellHeight * y,
.w = cellWidth,
.h = cellHeight,
@@ -131,16 +136,59 @@ static DrawList *render(State *state, UI *ui, Arena *a) {
.border = {255, 0, 0, 255},
};
+ drawList->els[drawList->len++] = (DrawElement) {
+ .x = 0,
+ .y = 0,
+ .w = GRID_OFFSET_X,
+ .h = ui->height,
+ .fill = {255, 255, 0, 255},
+ .border = {0, 0, 0, 255},
+ };
+
+ for (int i = 0; i < N_BUTTONS; i++) {
+ Color colour = {0, 0, 0, 255};
+ switch (state->buttonStates[i]) {
+ case BUTTON_STATE_IDLE:
+ colour = (Color) {0, 0, 0, 255};
+ break;
+ case BUTTON_STATE_HOVERED:
+ colour = (Color) {255, 255, 0, 255};
+ break;
+ case BUTTON_STATE_PRESSED:
+ colour = (Color) {255, 0, 0, 255};
+ break;
+ }
+ drawList->els[drawList->len++] = (DrawElement) {
+ .x = buttons[i].x,
+ .y = buttons[i].y,
+ .w = buttons[i].w,
+ .h = buttons[i].h,
+ .fill = colour,
+ .border = {0, 0, 0, 255}
+ };
+ }
+
return drawList;
}
static void update(Game *game, uint64_t now, Arena a) {
+ const int offset_width = game->ui.width - GRID_OFFSET_X;
+
switch (game->input) {
int x, y;
case INPUT_CLICK:
- x = game->mousex * GRIDWIDTH / game->ui.width;
+ x = (game->mousex - GRID_OFFSET_X) * GRIDWIDTH / offset_width;
y = game->mousey * GRIDHEIGHT / game->ui.height;
game->state.grid[x + y * GRIDWIDTH] = (game->state.grid[x + y * GRIDWIDTH] + 1) % (sizeof(colors) / sizeof(colors[0]));
+ for (int i = 0; i < N_BUTTONS; i++) {
+ if (
+ game->mousex > buttons[i].x && game->mousex < buttons[i].x + buttons[i].w &&
+ game->mousey > buttons[i].y && game->mousey < buttons[i].y + buttons[i].h
+ ) {
+ // TODO - CLICK THINGS
+ //game->state.buttonStates[i] = BUTTON_STATE_PRESSED;
+ }
+ }
break;
case INPUT_RCLICK:
x = game->mousex * GRIDWIDTH / game->ui.width;
@@ -184,6 +232,9 @@ int main(int argc, char **argv) {
.width = 640,
.height = 480,
};
+ for (int i = 0; i < N_BUTTONS; i++) {
+ game->state.buttonStates[i] = BUTTON_STATE_IDLE;
+ }
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *w = SDL_CreateWindow(