diff options
author | kdx <kdx@42l.fr> | 2023-02-18 01:32:22 +0100 |
---|---|---|
committer | kdx <kdx@42l.fr> | 2023-02-18 01:32:22 +0100 |
commit | 02f11f2c49378765d644edccd71ed6bb74e84cc2 (patch) | |
tree | f24711601b16fcad3b1e102c46bdeb826898f6a9 /commands.c | |
parent | 72a6892b5b18e450d82468e7bb830687a0215eb4 (diff) | |
download | bozojam-02f11f2c49378765d644edccd71ed6bb74e84cc2.tar.gz |
arter
Diffstat (limited to 'commands.c')
-rw-r--r-- | commands.c | 26 |
1 files changed, 24 insertions, 2 deletions
@@ -1,6 +1,9 @@ #include "commands.h" #include "lzr.h" #include "cfg.h" +#include <SDL2/SDL_log.h> + +int mouse_x, mouse_y, hovered = -1, editing = -1; static const unsigned int commands[COM_LEN] = { COM_RIGHT, @@ -13,12 +16,31 @@ static const unsigned int commands[COM_LEN] = { COM_UP }; +void commands_update(void) +{ + LZR_MousePosition(&mouse_x, &mouse_y); + hovered = -1; + if (mouse_x > CFG_TSIZE / 2 && mouse_x <= CFG_TSIZE * 2.5) { + int y = (mouse_y - CFG_TSIZE / 2) / (int)(CFG_TSIZE * 1.5); + if (y < 0 || y >= COM_LEN) + return; + hovered = y; + if (LZR_BUTTON(MOUSE_L)) + editing = commands[y]; + } +} + void commands_draw(void) { - LZR_DrawSetColor(1, 1, 1, 1); for (int i = 0; i < COM_LEN; i++) { const int dx = CFG_TSIZE / 2; const int dy = CFG_TSIZE / 2 + i * (int)(CFG_TSIZE * 1.5); - LZR_DrawImage(commands[i], dx, dy); + const int cmd = commands[i]; + const int blink = hovered != i || (LZR_GetTick() & 1); + if (cmd == editing) + LZR_DrawSetColor(rand() & 1, rand() & 1, rand() & 1, 1); + else + LZR_DrawSetColor(blink, blink, blink, 1); + LZR_DrawImage(cmd, dx, dy); } } |