summaryrefslogtreecommitdiff
path: root/src/play.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2021-10-31 17:20:07 -0700
committerVito Caputo <vcaputo@pengaru.com>2021-10-31 17:20:07 -0700
commitcbbe0abec7e0e0f21f3315b455f3f795cedf2c9a (patch)
tree1aee2c1375e5bf2c0921f2bac1ab2d3f6540ef55 /src/play.c
parent30ea38a28f3abd05c32093c29c67b418c6904235 (diff)
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.
Diffstat (limited to 'src/play.c')
-rw-r--r--src/play.c37
1 files changed, 36 insertions, 1 deletions
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 };
© All Rights Reserved