From cbbe0abec7e0e0f21f3315b455f3f795cedf2c9a Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 31 Oct 2021 17:20:07 -0700 Subject: play: add play_pointer_{own,disown}() api Abstract the sdl relative mouse things behind an ownership concept. In the future libplay will probably get more involved in projection transformation and pointer event coordinates mapping to the projection when owned. Though for now libplay doesn't get involved in such things. --- src/play.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src/play.c') diff --git a/src/play.c b/src/play.c index c15a26f..5c51cbf 100644 --- a/src/play.c +++ b/src/play.c @@ -39,6 +39,7 @@ typedef struct play_t { unsigned ticks_paused:1; unsigned update_needed:1; unsigned has_audio:1; + unsigned pointer_owned:1; const play_ops_t **ops; int n_ops; int context; @@ -196,7 +197,7 @@ void play_context_enter(play_t *play, int context) /* return context pointer of specified context, * a negative context requests the current context. */ -void * play_context(play_t *play, int context) +void * play_context(const play_t *play, int context) { assert(play); @@ -285,6 +286,40 @@ int play_ticks_elapsed(play_t *play, play_ticks_t timer, unsigned duration) } +void play_pointer_own(play_t *play) +{ + assert(play); + + if (play->pointer_owned) + return; + + SDL_SetRelativeMouseMode(SDL_TRUE); + + play->pointer_owned = 1; +} + + +void play_pointer_disown(play_t *play) +{ + assert(play); + + if (!play->pointer_owned) + return; + + SDL_SetRelativeMouseMode(SDL_FALSE); + + play->pointer_owned = 0; +} + + +int play_pointer_owned(const play_t *play) +{ + assert(play); + + return !!play->pointer_owned; +} + + void play_quit(play_t *play) { SDL_Event ev = { .type = SDL_QUIT }; -- cgit v1.2.3