mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-02-16 17:11:03 +00:00
Fixes for SDL2
* Fix input issues (mouse-wheel and mouse input) * SDL2 is not default anymore in the Makefile (use WITH_SDL2=yes) * If SDL2 is enabled, CD audio is disabled (SDL2 doesn't support that - use OGG/Vorbis instead) * Small fix to make it compile with SDL1.2 again
This commit is contained in:
parent
51b7607548
commit
997be0dcd1
3 changed files with 45 additions and 22 deletions
18
Makefile
18
Makefile
|
@ -20,16 +20,17 @@
|
|||
# User configurable options
|
||||
# -------------------------
|
||||
|
||||
# blabla
|
||||
# should be no by default in the future
|
||||
WITH_SDL2:=yes
|
||||
# Use SDL2 instead of SDL1.2
|
||||
# Disables CD audio support, because SDL2 has none.
|
||||
# Use OGG/Vorbis music instead :-)
|
||||
WITH_SDL2:=no
|
||||
|
||||
# Enables CD audio playback. CD audio playback is used
|
||||
# for the background music and doesn't add any further
|
||||
# dependencies. It should work on all platforms where
|
||||
# CD playback is supported by SDL.
|
||||
# was yes
|
||||
WITH_CDA:=no
|
||||
WITH_CDA:=yes
|
||||
|
||||
# Enables OGG/Vorbis support. OGG/Vorbis files can be
|
||||
# used as a substitute of CD audio playback. Adds
|
||||
|
@ -107,6 +108,15 @@ ifeq ($(findstring $(ARCH), i386 x86_64 sparc64 ia64),)
|
|||
$(error arch $(ARCH) is currently not supported)
|
||||
endif
|
||||
|
||||
# Disable CDA for SDL2
|
||||
# FIXME: printed too often
|
||||
ifeq ($(WITH_SDL2),yes)
|
||||
ifeq ($(WITH_CDA),yes)
|
||||
WITH_CDA:=no
|
||||
$(info WARNING: Disabled CD-Audio support, because SDL2 doesn't support it)
|
||||
endif
|
||||
endif
|
||||
|
||||
# ----------
|
||||
|
||||
# Base CFLAGS.
|
||||
|
|
|
@ -341,6 +341,19 @@ IN_TranslateSDLtoQ2Key(unsigned int keysym)
|
|||
return key;
|
||||
}
|
||||
|
||||
// add down and up event for mousewheel to simulate a "click"
|
||||
static void IN_AddMouseWheelEvents(int key)
|
||||
{
|
||||
assert(key == K_MWHEELUP || key == K_MWHEELDOWN);
|
||||
|
||||
keyq[keyq_head].key = key;
|
||||
keyq[keyq_head].down = true;
|
||||
keyq_head = (keyq_head + 1) & 127;
|
||||
keyq[keyq_head].key = key;
|
||||
keyq[keyq_head].down = false;
|
||||
keyq_head = (keyq_head + 1) & 127;
|
||||
}
|
||||
|
||||
/*
|
||||
* Input event processing
|
||||
*/
|
||||
|
@ -357,28 +370,25 @@ IN_GetEvent(SDL_Event *event)
|
|||
switch (event->type)
|
||||
{
|
||||
/* The mouse wheel */
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
case SDL_MOUSEWHEEL:
|
||||
IN_AddMouseWheelEvents(event->wheel.y > 0 ? K_MWHEELUP : K_MWHEELDOWN);
|
||||
break;
|
||||
|
||||
#else
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
|
||||
if (event->button.button == 4)
|
||||
{
|
||||
keyq[keyq_head].key = K_MWHEELUP;
|
||||
keyq[keyq_head].down = true;
|
||||
keyq_head = (keyq_head + 1) & 127;
|
||||
keyq[keyq_head].key = K_MWHEELUP;
|
||||
keyq[keyq_head].down = false;
|
||||
keyq_head = (keyq_head + 1) & 127;
|
||||
IN_AddMouseWheelEvents(K_MWHEELUP);
|
||||
}
|
||||
else if (event->button.button == 5)
|
||||
{
|
||||
keyq[keyq_head].key = K_MWHEELDOWN;
|
||||
keyq[keyq_head].down = true;
|
||||
keyq_head = (keyq_head + 1) & 127;
|
||||
keyq[keyq_head].key = K_MWHEELDOWN;
|
||||
keyq[keyq_head].down = false;
|
||||
keyq_head = (keyq_head + 1) & 127;
|
||||
IN_AddMouseWheelEvents(K_MWHEELDOWN);
|
||||
}
|
||||
|
||||
break;
|
||||
#endif
|
||||
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
break;
|
||||
|
|
|
@ -484,6 +484,9 @@ void GLimp_GrabInput(qboolean grab)
|
|||
{
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_SetWindowGrab(window, grab ? SDL_TRUE : SDL_FALSE);
|
||||
if(grab)
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
|
||||
#else
|
||||
SDL_WM_GrabInput(grab ? SDL_GRAB_ON : SDL_GRAB_OFF);
|
||||
#endif
|
||||
|
@ -525,6 +528,12 @@ GLimp_Shutdown(void)
|
|||
{
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
SDL_DestroyWindow(window);
|
||||
|
||||
if(context)
|
||||
{
|
||||
SDL_GL_DeleteContext(context);
|
||||
context = NULL;
|
||||
}
|
||||
#else
|
||||
SDL_FreeSurface(window);
|
||||
#endif
|
||||
|
@ -532,12 +541,6 @@ GLimp_Shutdown(void)
|
|||
|
||||
window = NULL;
|
||||
|
||||
if(context)
|
||||
{
|
||||
SDL_GL_DeleteContext(context);
|
||||
context = NULL;
|
||||
}
|
||||
|
||||
if (SDL_WasInit(SDL_INIT_EVERYTHING) == SDL_INIT_VIDEO)
|
||||
{
|
||||
SDL_Quit();
|
||||
|
|
Loading…
Reference in a new issue