From: Holger Schemel Date: Thu, 21 Mar 2019 08:17:57 +0000 (+0100) Subject: added generic support for handling user events X-Git-Tag: 4.1.3.0~25 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=c38790fcee093efb156366bb4a02dbde55085ca4;p=rocksndiamonds.git added generic support for handling user events --- diff --git a/src/events.c b/src/events.c index 05c4f2a0..9966905b 100644 --- a/src/events.c +++ b/src/events.c @@ -218,6 +218,10 @@ static void HandleEvents(void) HandleKeyEvent((KeyEvent *) &event); break; + case EVENT_USER: + HandleUserEvent((UserEvent *) &event); + break; + default: HandleOtherEvents(&event); break; @@ -1599,6 +1603,15 @@ void HandleDropEvent(Event *event) SDL_free(event->drop.file); } +void HandleUserEvent(UserEvent *event) +{ + switch (event->code) + { + default: + break; + } +} + void HandleButton(int mx, int my, int button, int button_nr) { static int old_mx = 0, old_my = 0; diff --git a/src/events.h b/src/events.h index 1294689f..ef61b605 100644 --- a/src/events.h +++ b/src/events.h @@ -32,6 +32,7 @@ void HandlePauseResumeEvent(PauseResumeEvent *); boolean HandleKeysDebug(Key, int); void HandleKeyEvent(KeyEvent *); void HandleDropEvent(Event *); +void HandleUserEvent(UserEvent *); void HandleToonAnimations(void); diff --git a/src/libgame/sdl.h b/src/libgame/sdl.h index 627617d2..e4b2b684 100644 --- a/src/libgame/sdl.h +++ b/src/libgame/sdl.h @@ -88,6 +88,21 @@ struct MouseCursorInfo byte mask[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8]; }; +struct UserEventInfo +{ + // same as in "struct SDL_UserEvent" + Uint32 type; + Uint32 timestamp; + Uint32 windowID; + Sint32 code; + + // changed to use integer values instead of void pointers + Uint32 value1; + Uint32 value2; +}; + +typedef struct UserEventInfo UserEvent; + // SDL symbol definitions @@ -106,6 +121,7 @@ struct MouseCursorInfo #define EVENT_TEXTINPUT SDL_TEXTINPUT #define EVENT_KEYPRESS SDL_KEYDOWN #define EVENT_KEYRELEASE SDL_KEYUP +#define EVENT_USER SDL_USEREVENT #define EVENT_QUIT SDL_QUIT #define KSYM_UNDEFINED SDLK_UNKNOWN diff --git a/src/libgame/system.c b/src/libgame/system.c index fc1e0c69..15e86a4a 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -1733,6 +1733,20 @@ void StopTextInput(void) #endif } +void PushUserEvent(int code, int value1, int value2) +{ + UserEvent event; + + SDL_memset(&event, 0, sizeof(event)); + + event.type = EVENT_USER; + event.code = code; + event.value1 = value1; + event.value2 = value2; + + SDL_PushEvent((SDL_Event *)&event); +} + // ============================================================================ // joystick functions diff --git a/src/libgame/system.h b/src/libgame/system.h index 68e5a33e..cf49d86f 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -1854,6 +1854,7 @@ KeyMod GetKeyModState(void); KeyMod GetKeyModStateFromEvents(void); void StartTextInput(int, int, int, int); void StopTextInput(void); +void PushUserEvent(int, int, int); void InitJoysticks(void); boolean ReadJoystick(int, int *, int *, boolean *, boolean *);