sdl2: Restore mouse motion support

This commit is contained in:
Ronald Kinard 2014-03-20 22:37:26 -05:00
parent 4c636123a4
commit d298aa8e0d
2 changed files with 90 additions and 40 deletions

View file

@ -95,11 +95,6 @@ endif
endif endif
endif endif
ifdef FILTERS
OBJS+=$(OBJDIR)/filters.o $(OBJDIR)/hq2x.o $(OBJDIR)/lq2x.o
OPTS+=-DHAVE_FILTER
endif
ifdef NOMIXER ifdef NOMIXER
i_sound_o=$(OBJDIR)/sdl_sound.o i_sound_o=$(OBJDIR)/sdl_sound.o
else else
@ -110,14 +105,14 @@ endif
ifdef SDL_TTF ifdef SDL_TTF
OPTS+=-DHAVE_TTF OPTS+=-DHAVE_TTF
SDL_LDFLAGS+=-lSDL_ttf -lfreetype -lz SDL_LDFLAGS+=-lSDL2_ttf -lfreetype -lz
OBJS+=$(OBJDIR)/i_ttf.o OBJS+=$(OBJDIR)/i_ttf.o
endif endif
#ifdef SDL_IMAGE ifdef SDL_IMAGE
# OPTS+=-DHAVE_IMAGE OPTS+=-DHAVE_IMAGE
# SDL_LDFLAGS+=-lSDL_image SDL_LDFLAGS+=-lSDL2_image
#endif endif
ifdef SDL_NET ifdef SDL_NET
OPTS+=-DHAVE_SDLNET OPTS+=-DHAVE_SDLNET

View file

@ -178,6 +178,7 @@ static void Impl_VideoSetupSDLBuffer(void);
static void Impl_VideoSetupBuffer(void); static void Impl_VideoSetupBuffer(void);
static SDL_bool Impl_CreateWindow(SDL_bool fullscreen); static SDL_bool Impl_CreateWindow(SDL_bool fullscreen);
static void Impl_SetWindowName(const char *title); static void Impl_SetWindowName(const char *title);
static void Impl_SetWindowIcon(void);
static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen)
{ {
@ -210,6 +211,7 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen)
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
window = NULL; window = NULL;
Impl_CreateWindow(SDL_TRUE); Impl_CreateWindow(SDL_TRUE);
Impl_SetWindowIcon();
wasfullscreen = SDL_TRUE; wasfullscreen = SDL_TRUE;
} }
else if (!fullscreen && wasfullscreen) else if (!fullscreen && wasfullscreen)
@ -220,6 +222,7 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen)
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
window = NULL; window = NULL;
Impl_CreateWindow(SDL_FALSE); Impl_CreateWindow(SDL_FALSE);
Impl_SetWindowIcon();
wasfullscreen = SDL_FALSE; wasfullscreen = SDL_FALSE;
} }
else if (!wasfullscreen) else if (!wasfullscreen)
@ -738,9 +741,30 @@ static INT32 SDLJoyAxis(const Sint16 axis, evtype_t which)
static void Impl_HandleWindowEvent(SDL_WindowEvent evt) static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
{ {
static SDL_bool firsttimeonmouse = SDL_TRUE; static SDL_bool firsttimeonmouse = SDL_TRUE;
switch (evt.type) static SDL_bool mousefocus = SDL_TRUE;
static SDL_bool kbfocus = SDL_TRUE;
switch (evt.event)
{ {
case SDL_WINDOWEVENT_ENTER:
mousefocus = SDL_TRUE;
break;
case SDL_WINDOWEVENT_LEAVE:
mousefocus = SDL_FALSE;
break;
case SDL_WINDOWEVENT_FOCUS_GAINED: case SDL_WINDOWEVENT_FOCUS_GAINED:
kbfocus = SDL_TRUE;
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
kbfocus = SDL_FALSE;
mousefocus = SDL_FALSE;
break;
case SDL_WINDOWEVENT_MAXIMIZED:
break;
}
if (mousefocus && kbfocus)
{
if (!firsttimeonmouse) if (!firsttimeonmouse)
{ {
if (cv_usemouse.value) I_StartupMouse(); if (cv_usemouse.value) I_StartupMouse();
@ -750,8 +774,9 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
{ {
if (!paused) I_ResumeSong(0); //resume it if (!paused) I_ResumeSong(0); //resume it
} }
break; }
case SDL_WINDOWEVENT_FOCUS_LOST: else if (!mousefocus && !kbfocus)
{
if (!disable_mouse) if (!disable_mouse)
{ {
SDLforceUngrabMouse(); SDLforceUngrabMouse();
@ -771,11 +796,8 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt)
SDLdoUngrabMouse(); SDLdoUngrabMouse();
return; return;
} }
break;
case SDL_WINDOWEVENT_MAXIMIZED:
break;
} }
} }
static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type) static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type)
@ -799,6 +821,39 @@ static void Impl_HandleKeyboardEvent(SDL_KeyboardEvent evt, Uint32 type)
static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt)
{ {
event_t event;
if (MOUSE_MENU)
{
SDLdoUngrabMouse();
return;
}
//if (USE_MOUSEINPUT) TODO SDL2 stub
{
// If the event is from warping the pointer back to middle
// of the screen then ignore it.
if ((evt.x == realwidth/2) &&
(evt.y == realheight/2))
{
return;
}
else
{
event.data2 = +evt.xrel;
event.data3 = -evt.yrel;
}
event.type = ev_mouse;
D_PostEvent(&event);
// Warp the pointer back to the middle of the window
// or we cannot move any further if it's at a border.
if ((evt.x < (realwidth/2 )-(realwidth/4 )) ||
(evt.y < (realheight/2)-(realheight/4)) ||
(evt.x > (realwidth/2 )+(realwidth/4 )) ||
(evt.y > (realheight/2)+(realheight/4) ) )
{
//if (SDL_GRAB_ON == SDL_WM_GrabInput(SDL_GRAB_QUERY) || !mousegrabok)
HalfWarpMouse(realwidth, realheight);
}
}
} }
static void Impl_HandleMouseButtonEvent(SDL_MouseButtonEvent evt, Uint32 type) static void Impl_HandleMouseButtonEvent(SDL_MouseButtonEvent evt, Uint32 type)