Skip to content

Commit

Permalink
Add shortcut for twin_screen_t access
Browse files Browse the repository at this point in the history
  • Loading branch information
jserv committed Jul 25, 2024
1 parent 9a0a4dd commit 2ca0bdb
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions backend/sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ typedef struct {
int image_y;
} twin_sdl_t;

#define SCREEN(x) ((twin_context_t *) x)->screen
#define PRIV(x) ((twin_sdl_t *) ((twin_context_t *) x)->priv)

static void _twin_sdl_put_begin(twin_coord_t left,
Expand All @@ -40,7 +41,7 @@ static void _twin_sdl_put_span(twin_coord_t left,
twin_argb32_t *pixels,
void *closure)
{
twin_screen_t *screen = ((twin_context_t *) closure)->screen;
twin_screen_t *screen = SCREEN(closure);
twin_sdl_t *tx = PRIV(closure);

for (twin_coord_t ix = left, iy = top; ix < right; ix++) {
Expand All @@ -58,6 +59,8 @@ static void _twin_sdl_put_span(twin_coord_t left,
static void _twin_sdl_destroy(twin_screen_t *screen, twin_sdl_t *tx)
{
twin_screen_destroy(screen);

SDL_DestroyTexture(tx->texture);
SDL_DestroyRenderer(tx->render);
SDL_DestroyWindow(tx->win);
SDL_Quit();
Expand All @@ -74,7 +77,7 @@ static bool twin_sdl_read_events(int file maybe_unused,
twin_file_op_t ops maybe_unused,
void *closure)
{
twin_screen_t *screen = ((twin_context_t *) closure)->screen;
twin_screen_t *screen = SCREEN(closure);
twin_sdl_t *tx = PRIV(closure);

SDL_Event ev;
Expand Down Expand Up @@ -121,7 +124,7 @@ static bool twin_sdl_read_events(int file maybe_unused,

static bool twin_sdl_work(void *closure)
{
twin_screen_t *screen = ((twin_context_t *) closure)->screen;
twin_screen_t *screen = SCREEN(closure);

if (twin_screen_damaged(screen))
twin_screen_update(screen);
Expand Down

0 comments on commit 2ca0bdb

Please sign in to comment.