testsAndMisc-archive/C/opening_learner/gui.h

39 lines
1.0 KiB
C
Raw Normal View History

2025-09-08 16:58:17 +02:00
#ifndef GUI_H
#define GUI_H
#include <SDL2/SDL.h>
2025-11-01 20:11:45 +01:00
#include <stdbool.h>
2025-09-08 16:58:17 +02:00
2025-11-01 20:11:45 +01:00
typedef struct
{
SDL_Window *window;
2025-09-08 16:58:17 +02:00
SDL_Renderer *renderer;
2025-11-01 20:11:45 +01:00
int win_w, win_h;
bool flipped; // true if black at bottom
2025-09-08 16:58:17 +02:00
} Gui;
2025-11-01 20:11:45 +01:00
typedef struct
{
int from_sq; // 0..63 or -1
int to_sq; // 0..63 or -1
char promo; // 'q','r','b','n' or 0
2025-09-08 16:58:17 +02:00
bool clicked;
} GuiSelection;
bool gui_init(Gui *g, int w, int h, const char *title);
void gui_destroy(Gui *g);
void gui_set_flipped(Gui *g, bool flipped);
void gui_draw(Gui *g, const char board[64], const GuiSelection *sel, const char *status_line);
// Returns true if something changed. If a key was pressed, key_out receives SDL_Keycode else 0.
bool gui_poll_move(Gui *g, GuiSelection *sel, bool *quit_requested, int *key_out);
2025-11-01 20:11:45 +01:00
int gui_coord_to_sq(Gui *g, int x, int y);
2025-09-08 16:58:17 +02:00
// colors
extern const SDL_Color COLOR_LIGHT;
extern const SDL_Color COLOR_DARK;
extern const SDL_Color COLOR_GRID;
extern const SDL_Color COLOR_SEL;
extern const SDL_Color COLOR_TEXT;
#endif