Files
2026-07-23 00:18:08 +02:00

67 lines
1.4 KiB
C

#ifndef PLATFORM
#define PLATFORM
#include <stdint.h>
#include <stdbool.h>
#include "utf.h"
typedef struct Color {
uint8_t r, g, b;
} Color;
#define WHITE ((Color){255,255,255})
#define BLACK ((Color){0,0,0})
typedef enum Key {
Key_backspace,
Key_ctrl,
Key_enter,
Key_h,
Key_n,
Key_p,
Key_y,
Count_Key
} Key;
bool KeyPressed(Key key);
bool InputGetNextPrintable(CodePoint const *out_key);
typedef struct Cell {
CodePoint character;
Color foreground;
Color background;
} Cell;
typedef struct Window {
int width;
int height;
Cell *cells;
} Window;
typedef struct PlatformState {
Window *prev;
Window *curr;
} PlatformState;
// Options for the backend. These options don't necessarily apply for all platforms.
typedef struct PlatformOpts {
float window_width_fraction; // decide the width of the window as a fraction of the total resolution. for gui backends
float window_height_fraction; // decide the height of the window as a fraction of the total resolution. for gui backends
} PlatformOpts;
PlatformOpts WindowCreateOptsDefault();
Window *WindowCreate(PlatformOpts opts);
void WindowClear(Window *window, Color color);
void WindowFlip(Window *window);
void PlatformInit(PlatformOpts opts);
int PlatformGetWidth();
int PlatformGetHeight();
// TODO: the platform layer would really update the keys being pressed, and
// receive a diff in the form of actions. print this line from here and change
// colors at these points.
#endif /* PLATFORM */