1 // License: CC0 / Public Domain 2 #pragma once 3 4 #include <libplacebo/swapchain.h> 5 6 struct window { 7 const struct window_impl *impl; 8 pl_swapchain swapchain; 9 pl_gpu gpu; 10 bool window_lost; 11 }; 12 13 struct window_params { 14 const char *title; 15 int width; 16 int height; 17 18 // initial color space 19 struct pl_swapchain_colors colors; 20 bool alpha; 21 }; 22 23 struct window *window_create(pl_log log, const struct window_params *params); 24 void window_destroy(struct window **win); 25 26 // Poll/wait for window events 27 void window_poll(struct window *win, bool block); 28 29 // Input handling 30 enum button { 31 BTN_LEFT, 32 BTN_RIGHT, 33 BTN_MIDDLE, 34 }; 35 36 enum key { 37 KEY_ESC, 38 }; 39 40 void window_get_cursor(const struct window *win, int *x, int *y); 41 void window_get_scroll(const struct window *win, float *dx, float *dy); 42 bool window_get_button(const struct window *win, enum button); 43 bool window_get_key(const struct window *win, enum key); 44 char *window_get_file(const struct window *win); 45 46 // For implementations 47 struct window_impl { 48 const char *name; 49 __typeof__(window_create) *create; 50 __typeof__(window_destroy) *destroy; 51 __typeof__(window_poll) *poll; 52 __typeof__(window_get_cursor) *get_cursor; 53 __typeof__(window_get_scroll) *get_scroll; 54 __typeof__(window_get_button) *get_button; 55 __typeof__(window_get_key) *get_key; 56 __typeof__(window_get_file) *get_file; 57 }; 58