mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-14 16:14:38 +00:00
Update to SDL2.0.10
This commit is contained in:
parent
600859bd63
commit
c932bda8dd
915 changed files with 116675 additions and 21754 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
60
Engine/lib/sdl/src/events/SDL_displayevents.c
Normal file
60
Engine/lib/sdl/src/events/SDL_displayevents.c
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
/* Display event handling code for SDL */
|
||||
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_events_c.h"
|
||||
|
||||
|
||||
int
|
||||
SDL_SendDisplayEvent(SDL_VideoDisplay *display, Uint8 displayevent, int data1)
|
||||
{
|
||||
int posted;
|
||||
|
||||
if (!display) {
|
||||
return 0;
|
||||
}
|
||||
switch (displayevent) {
|
||||
case SDL_DISPLAYEVENT_ORIENTATION:
|
||||
if (data1 == SDL_ORIENTATION_UNKNOWN || data1 == display->orientation) {
|
||||
return 0;
|
||||
}
|
||||
display->orientation = (SDL_DisplayOrientation)data1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Post the event, if desired */
|
||||
posted = 0;
|
||||
if (SDL_GetEventState(SDL_DISPLAYEVENT) == SDL_ENABLE) {
|
||||
SDL_Event event;
|
||||
event.type = SDL_DISPLAYEVENT;
|
||||
event.display.event = displayevent;
|
||||
event.display.display = SDL_GetIndexOfDisplay(display);
|
||||
event.display.data1 = data1;
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
}
|
||||
|
||||
return (posted);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
30
Engine/lib/sdl/src/events/SDL_displayevents_c.h
Normal file
30
Engine/lib/sdl/src/events/SDL_displayevents_c.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
#ifndef SDL_displayevents_c_h_
|
||||
#define SDL_displayevents_c_h_
|
||||
|
||||
extern int SDL_SendDisplayEvent(SDL_VideoDisplay *display, Uint8 displayevent, int data1);
|
||||
|
||||
#endif /* SDL_displayevents_c_h_ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -33,8 +33,6 @@
|
|||
#include "../video/SDL_sysvideo.h"
|
||||
#include "SDL_syswm.h"
|
||||
|
||||
/*#define SDL_DEBUG_EVENTS 1*/
|
||||
|
||||
/* An arbitrary limit so we don't have unbounded growth */
|
||||
#define SDL_MAX_QUEUED_EVENTS 65535
|
||||
|
||||
|
|
@ -87,32 +85,53 @@ static struct
|
|||
} SDL_EventQ = { NULL, { 1 }, { 0 }, 0, NULL, NULL, NULL, NULL, NULL };
|
||||
|
||||
|
||||
#ifdef SDL_DEBUG_EVENTS
|
||||
/* 0 (default) means no logging, 1 means logging, 2 means logging with mouse and finger motion */
|
||||
static int SDL_DoEventLogging = 0;
|
||||
|
||||
/* this is to make printf() calls cleaner. */
|
||||
#define uint unsigned int
|
||||
static void SDLCALL
|
||||
SDL_EventLoggingChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
|
||||
{
|
||||
SDL_DoEventLogging = (hint && *hint) ? SDL_max(SDL_min(SDL_atoi(hint), 2), 0) : 0;
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_DebugPrintEvent(const SDL_Event *event)
|
||||
SDL_LogEvent(const SDL_Event *event)
|
||||
{
|
||||
/* !!! FIXME: This code is kinda ugly, sorry. */
|
||||
printf("SDL EVENT: ");
|
||||
char name[32];
|
||||
char details[128];
|
||||
|
||||
if ((event->type >= SDL_USEREVENT) && (event->type <= SDL_LASTEVENT)) {
|
||||
printf("SDL_USEREVENT");
|
||||
if (event->type > SDL_USEREVENT) {
|
||||
printf("+%u", ((uint) event->type) - SDL_USEREVENT);
|
||||
}
|
||||
printf(" (timestamp=%u windowid=%u code=%d data1=%p data2=%p)",
|
||||
(uint) event->user.timestamp, (uint) event->user.windowID,
|
||||
(int) event->user.code, event->user.data1, event->user.data2);
|
||||
/* mouse/finger motion are spammy, ignore these if they aren't demanded. */
|
||||
if ( (SDL_DoEventLogging < 2) &&
|
||||
( (event->type == SDL_MOUSEMOTION) ||
|
||||
(event->type == SDL_FINGERMOTION) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* this is to make SDL_snprintf() calls cleaner. */
|
||||
#define uint unsigned int
|
||||
|
||||
name[0] = '\0';
|
||||
details[0] = '\0';
|
||||
|
||||
/* !!! FIXME: This code is kinda ugly, sorry. */
|
||||
|
||||
if ((event->type >= SDL_USEREVENT) && (event->type <= SDL_LASTEVENT)) {
|
||||
char plusstr[16];
|
||||
SDL_strlcpy(name, "SDL_USEREVENT", sizeof (name));
|
||||
if (event->type > SDL_USEREVENT) {
|
||||
SDL_snprintf(plusstr, sizeof (plusstr), "+%u", ((uint) event->type) - SDL_USEREVENT);
|
||||
} else {
|
||||
plusstr[0] = '\0';
|
||||
}
|
||||
SDL_snprintf(details, sizeof (details), "%s (timestamp=%u windowid=%u code=%d data1=%p data2=%p)",
|
||||
plusstr, (uint) event->user.timestamp, (uint) event->user.windowID,
|
||||
(int) event->user.code, event->user.data1, event->user.data2);
|
||||
}
|
||||
|
||||
switch (event->type) {
|
||||
#define SDL_EVENT_CASE(x) case x: printf("%s", #x);
|
||||
SDL_EVENT_CASE(SDL_FIRSTEVENT) printf("(THIS IS PROBABLY A BUG!)"); break;
|
||||
SDL_EVENT_CASE(SDL_QUIT) printf("(timestamp=%u)", (uint) event->quit.timestamp); break;
|
||||
#define SDL_EVENT_CASE(x) case x: SDL_strlcpy(name, #x, sizeof (name));
|
||||
SDL_EVENT_CASE(SDL_FIRSTEVENT) SDL_strlcpy(details, " (THIS IS PROBABLY A BUG!)", sizeof (details)); break;
|
||||
SDL_EVENT_CASE(SDL_QUIT) SDL_snprintf(details, sizeof (details), " (timestamp=%u)", (uint) event->quit.timestamp); break;
|
||||
SDL_EVENT_CASE(SDL_APP_TERMINATING) break;
|
||||
SDL_EVENT_CASE(SDL_APP_LOWMEMORY) break;
|
||||
SDL_EVENT_CASE(SDL_APP_WILLENTERBACKGROUND) break;
|
||||
|
|
@ -123,15 +142,12 @@ SDL_DebugPrintEvent(const SDL_Event *event)
|
|||
SDL_EVENT_CASE(SDL_CLIPBOARDUPDATE) break;
|
||||
SDL_EVENT_CASE(SDL_RENDER_TARGETS_RESET) break;
|
||||
SDL_EVENT_CASE(SDL_RENDER_DEVICE_RESET) break;
|
||||
#undef SDL_EVENT_CASE
|
||||
|
||||
#define SDL_EVENT_CASE(x) case x: printf("%s ", #x);
|
||||
|
||||
SDL_EVENT_CASE(SDL_WINDOWEVENT)
|
||||
printf("(timestamp=%u windowid=%u event=", (uint) event->window.timestamp, (uint) event->window.windowID);
|
||||
SDL_EVENT_CASE(SDL_WINDOWEVENT) {
|
||||
char name2[64];
|
||||
switch(event->window.event) {
|
||||
case SDL_WINDOWEVENT_NONE: printf("none(THIS IS PROBABLY A BUG!)"); break;
|
||||
#define SDL_WINDOWEVENT_CASE(x) case x: printf("%s", #x); break
|
||||
case SDL_WINDOWEVENT_NONE: SDL_strlcpy(name2, "SDL_WINDOWEVENT_NONE (THIS IS PROBABLY A BUG!)", sizeof (name2)); break;
|
||||
#define SDL_WINDOWEVENT_CASE(x) case x: SDL_strlcpy(name2, #x, sizeof (name2)); break
|
||||
SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_SHOWN);
|
||||
SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_HIDDEN);
|
||||
SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_EXPOSED);
|
||||
|
|
@ -149,18 +165,20 @@ SDL_DebugPrintEvent(const SDL_Event *event)
|
|||
SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_TAKE_FOCUS);
|
||||
SDL_WINDOWEVENT_CASE(SDL_WINDOWEVENT_HIT_TEST);
|
||||
#undef SDL_WINDOWEVENT_CASE
|
||||
default: printf("UNKNOWN(bug? fixme?)"); break;
|
||||
default: SDL_strlcpy(name2, "UNKNOWN (bug? fixme?)", sizeof (name2)); break;
|
||||
}
|
||||
printf(" data1=%d data2=%d)", (int) event->window.data1, (int) event->window.data2);
|
||||
SDL_snprintf(details, sizeof (details), " (timestamp=%u windowid=%u event=%s data1=%d data2=%d)",
|
||||
(uint) event->window.timestamp, (uint) event->window.windowID, name2, (int) event->window.data1, (int) event->window.data2);
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_EVENT_CASE(SDL_SYSWMEVENT)
|
||||
printf("(timestamp=%u)", (uint) event->syswm.timestamp);
|
||||
/* !!! FIXME: we don't delve further at the moment. */
|
||||
SDL_snprintf(details, sizeof (details), " (timestamp=%u)", (uint) event->syswm.timestamp);
|
||||
break;
|
||||
|
||||
#define PRINT_KEY_EVENT(event) \
|
||||
printf("(timestamp=%u windowid=%u state=%s repeat=%s scancode=%u keycode=%u mod=%u)", \
|
||||
SDL_snprintf(details, sizeof (details), " (timestamp=%u windowid=%u state=%s repeat=%s scancode=%u keycode=%u mod=%u)", \
|
||||
(uint) event->key.timestamp, (uint) event->key.windowID, \
|
||||
event->key.state == SDL_PRESSED ? "pressed" : "released", \
|
||||
event->key.repeat ? "true" : "false", \
|
||||
|
|
@ -172,18 +190,18 @@ SDL_DebugPrintEvent(const SDL_Event *event)
|
|||
#undef PRINT_KEY_EVENT
|
||||
|
||||
SDL_EVENT_CASE(SDL_TEXTEDITING)
|
||||
printf("(timestamp=%u windowid=%u text='%s' start=%d length=%d)",
|
||||
SDL_snprintf(details, sizeof (details), " (timestamp=%u windowid=%u text='%s' start=%d length=%d)",
|
||||
(uint) event->edit.timestamp, (uint) event->edit.windowID,
|
||||
event->edit.text, (int) event->edit.start, (int) event->edit.length);
|
||||
break;
|
||||
|
||||
SDL_EVENT_CASE(SDL_TEXTINPUT)
|
||||
printf("(timestamp=%u windowid=%u text='%s')", (uint) event->text.timestamp, (uint) event->text.windowID, event->text.text);
|
||||
SDL_snprintf(details, sizeof (details), " (timestamp=%u windowid=%u text='%s')", (uint) event->text.timestamp, (uint) event->text.windowID, event->text.text);
|
||||
break;
|
||||
|
||||
|
||||
SDL_EVENT_CASE(SDL_MOUSEMOTION)
|
||||
printf("(timestamp=%u windowid=%u which=%u state=%u x=%d y=%d xrel=%d yrel=%d)",
|
||||
SDL_snprintf(details, sizeof (details), " (timestamp=%u windowid=%u which=%u state=%u x=%d y=%d xrel=%d yrel=%d)",
|
||||
(uint) event->motion.timestamp, (uint) event->motion.windowID,
|
||||
(uint) event->motion.which, (uint) event->motion.state,
|
||||
(int) event->motion.x, (int) event->motion.y,
|
||||
|
|
@ -191,7 +209,7 @@ SDL_DebugPrintEvent(const SDL_Event *event)
|
|||
break;
|
||||
|
||||
#define PRINT_MBUTTON_EVENT(event) \
|
||||
printf("(timestamp=%u windowid=%u which=%u button=%u state=%s clicks=%u x=%d y=%d)", \
|
||||
SDL_snprintf(details, sizeof (details), " (timestamp=%u windowid=%u which=%u button=%u state=%s clicks=%u x=%d y=%d)", \
|
||||
(uint) event->button.timestamp, (uint) event->button.windowID, \
|
||||
(uint) event->button.which, (uint) event->button.button, \
|
||||
event->button.state == SDL_PRESSED ? "pressed" : "released", \
|
||||
|
|
@ -202,67 +220,67 @@ SDL_DebugPrintEvent(const SDL_Event *event)
|
|||
|
||||
|
||||
SDL_EVENT_CASE(SDL_MOUSEWHEEL)
|
||||
printf("(timestamp=%u windowid=%u which=%u x=%d y=%d direction=%s)",
|
||||
SDL_snprintf(details, sizeof (details), " (timestamp=%u windowid=%u which=%u x=%d y=%d direction=%s)",
|
||||
(uint) event->wheel.timestamp, (uint) event->wheel.windowID,
|
||||
(uint) event->wheel.which, (int) event->wheel.x, (int) event->wheel.y,
|
||||
event->wheel.direction == SDL_MOUSEWHEEL_NORMAL ? "normal" : "flipped");
|
||||
break;
|
||||
|
||||
SDL_EVENT_CASE(SDL_JOYAXISMOTION)
|
||||
printf("(timestamp=%u which=%d axis=%u value=%d)",
|
||||
SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%d axis=%u value=%d)",
|
||||
(uint) event->jaxis.timestamp, (int) event->jaxis.which,
|
||||
(uint) event->jaxis.axis, (int) event->jaxis.value);
|
||||
break;
|
||||
|
||||
SDL_EVENT_CASE(SDL_JOYBALLMOTION)
|
||||
printf("(timestamp=%u which=%d ball=%u xrel=%d yrel=%d)",
|
||||
SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%d ball=%u xrel=%d yrel=%d)",
|
||||
(uint) event->jball.timestamp, (int) event->jball.which,
|
||||
(uint) event->jball.ball, (int) event->jball.xrel, (int) event->jball.yrel);
|
||||
break;
|
||||
|
||||
SDL_EVENT_CASE(SDL_JOYHATMOTION)
|
||||
printf("(timestamp=%u which=%d hat=%u value=%u)",
|
||||
SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%d hat=%u value=%u)",
|
||||
(uint) event->jhat.timestamp, (int) event->jhat.which,
|
||||
(uint) event->jhat.hat, (uint) event->jhat.value);
|
||||
break;
|
||||
|
||||
#define PRINT_JBUTTON_EVENT(event) \
|
||||
printf("(timestamp=%u which=%d button=%u state=%s)", \
|
||||
SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%d button=%u state=%s)", \
|
||||
(uint) event->jbutton.timestamp, (int) event->jbutton.which, \
|
||||
(uint) event->jbutton.button, event->jbutton.state == SDL_PRESSED ? "pressed" : "released")
|
||||
SDL_EVENT_CASE(SDL_JOYBUTTONDOWN) PRINT_JBUTTON_EVENT(event); break;
|
||||
SDL_EVENT_CASE(SDL_JOYBUTTONUP) PRINT_JBUTTON_EVENT(event); break;
|
||||
#undef PRINT_JBUTTON_EVENT
|
||||
|
||||
#define PRINT_JOYDEV_EVENT(event) printf("(timestamp=%u which=%d)", (uint) event->jdevice.timestamp, (int) event->jdevice.which)
|
||||
#define PRINT_JOYDEV_EVENT(event) SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%d)", (uint) event->jdevice.timestamp, (int) event->jdevice.which)
|
||||
SDL_EVENT_CASE(SDL_JOYDEVICEADDED) PRINT_JOYDEV_EVENT(event); break;
|
||||
SDL_EVENT_CASE(SDL_JOYDEVICEREMOVED) PRINT_JOYDEV_EVENT(event); break;
|
||||
#undef PRINT_JOYDEV_EVENT
|
||||
|
||||
SDL_EVENT_CASE(SDL_CONTROLLERAXISMOTION)
|
||||
printf("(timestamp=%u which=%d axis=%u value=%d)",
|
||||
SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%d axis=%u value=%d)",
|
||||
(uint) event->caxis.timestamp, (int) event->caxis.which,
|
||||
(uint) event->caxis.axis, (int) event->caxis.value);
|
||||
break;
|
||||
|
||||
#define PRINT_CBUTTON_EVENT(event) \
|
||||
printf("(timestamp=%u which=%d button=%u state=%s)", \
|
||||
SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%d button=%u state=%s)", \
|
||||
(uint) event->cbutton.timestamp, (int) event->cbutton.which, \
|
||||
(uint) event->cbutton.button, event->cbutton.state == SDL_PRESSED ? "pressed" : "released")
|
||||
SDL_EVENT_CASE(SDL_CONTROLLERBUTTONDOWN) PRINT_CBUTTON_EVENT(event); break;
|
||||
SDL_EVENT_CASE(SDL_CONTROLLERBUTTONUP) PRINT_CBUTTON_EVENT(event); break;
|
||||
#undef PRINT_CBUTTON_EVENT
|
||||
|
||||
#define PRINT_CONTROLLERDEV_EVENT(event) printf("(timestamp=%u which=%d)", (uint) event->cdevice.timestamp, (int) event->cdevice.which)
|
||||
#define PRINT_CONTROLLERDEV_EVENT(event) SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%d)", (uint) event->cdevice.timestamp, (int) event->cdevice.which)
|
||||
SDL_EVENT_CASE(SDL_CONTROLLERDEVICEADDED) PRINT_CONTROLLERDEV_EVENT(event); break;
|
||||
SDL_EVENT_CASE(SDL_CONTROLLERDEVICEREMOVED) PRINT_CONTROLLERDEV_EVENT(event); break;
|
||||
SDL_EVENT_CASE(SDL_CONTROLLERDEVICEREMAPPED) PRINT_CONTROLLERDEV_EVENT(event); break;
|
||||
#undef PRINT_CONTROLLERDEV_EVENT
|
||||
|
||||
#define PRINT_FINGER_EVENT(event) \
|
||||
printf("(timestamp=%u touchid=%lld fingerid=%lld x=%f y=%f dx=%f dy=%f pressure=%f)", \
|
||||
(uint) event->tfinger.timestamp, (long long) event->tfinger.touchId, \
|
||||
(long long) event->tfinger.fingerId, event->tfinger.x, event->tfinger.y, \
|
||||
SDL_snprintf(details, sizeof (details), " (timestamp=%u touchid=%"SDL_PRIs64" fingerid=%"SDL_PRIs64" x=%f y=%f dx=%f dy=%f pressure=%f)", \
|
||||
(uint) event->tfinger.timestamp, event->tfinger.touchId, \
|
||||
event->tfinger.fingerId, event->tfinger.x, event->tfinger.y, \
|
||||
event->tfinger.dx, event->tfinger.dy, event->tfinger.pressure)
|
||||
SDL_EVENT_CASE(SDL_FINGERDOWN) PRINT_FINGER_EVENT(event); break;
|
||||
SDL_EVENT_CASE(SDL_FINGERUP) PRINT_FINGER_EVENT(event); break;
|
||||
|
|
@ -270,29 +288,29 @@ SDL_DebugPrintEvent(const SDL_Event *event)
|
|||
#undef PRINT_FINGER_EVENT
|
||||
|
||||
#define PRINT_DOLLAR_EVENT(event) \
|
||||
printf("(timestamp=%u touchid=%lld gestureid=%lld numfingers=%u error=%f x=%f y=%f)", \
|
||||
(uint) event->dgesture.timestamp, (long long) event->dgesture.touchId, \
|
||||
(long long) event->dgesture.gestureId, (uint) event->dgesture.numFingers, \
|
||||
SDL_snprintf(details, sizeof (details), " (timestamp=%u touchid=%"SDL_PRIs64" gestureid=%"SDL_PRIs64" numfingers=%u error=%f x=%f y=%f)", \
|
||||
(uint) event->dgesture.timestamp, event->dgesture.touchId, \
|
||||
event->dgesture.gestureId, (uint) event->dgesture.numFingers, \
|
||||
event->dgesture.error, event->dgesture.x, event->dgesture.y);
|
||||
SDL_EVENT_CASE(SDL_DOLLARGESTURE) PRINT_DOLLAR_EVENT(event); break;
|
||||
SDL_EVENT_CASE(SDL_DOLLARRECORD) PRINT_DOLLAR_EVENT(event); break;
|
||||
#undef PRINT_DOLLAR_EVENT
|
||||
|
||||
SDL_EVENT_CASE(SDL_MULTIGESTURE)
|
||||
printf("(timestamp=%u touchid=%lld dtheta=%f ddist=%f x=%f y=%f numfingers=%u)",
|
||||
(uint) event->mgesture.timestamp, (long long) event->mgesture.touchId,
|
||||
SDL_snprintf(details, sizeof (details), " (timestamp=%u touchid=%"SDL_PRIs64" dtheta=%f ddist=%f x=%f y=%f numfingers=%u)",
|
||||
(uint) event->mgesture.timestamp, event->mgesture.touchId,
|
||||
event->mgesture.dTheta, event->mgesture.dDist,
|
||||
event->mgesture.x, event->mgesture.y, (uint) event->mgesture.numFingers);
|
||||
break;
|
||||
|
||||
#define PRINT_DROP_EVENT(event) printf("(file='%s' timestamp=%u windowid=%u)", event->drop.file, (uint) event->drop.timestamp, (uint) event->drop.windowID)
|
||||
#define PRINT_DROP_EVENT(event) SDL_snprintf(details, sizeof (details), " (file='%s' timestamp=%u windowid=%u)", event->drop.file, (uint) event->drop.timestamp, (uint) event->drop.windowID)
|
||||
SDL_EVENT_CASE(SDL_DROPFILE) PRINT_DROP_EVENT(event); break;
|
||||
SDL_EVENT_CASE(SDL_DROPTEXT) PRINT_DROP_EVENT(event); break;
|
||||
SDL_EVENT_CASE(SDL_DROPBEGIN) PRINT_DROP_EVENT(event); break;
|
||||
SDL_EVENT_CASE(SDL_DROPCOMPLETE) PRINT_DROP_EVENT(event); break;
|
||||
#undef PRINT_DROP_EVENT
|
||||
|
||||
#define PRINT_AUDIODEV_EVENT(event) printf("(timestamp=%u which=%u iscapture=%s)", (uint) event->adevice.timestamp, (uint) event->adevice.which, event->adevice.iscapture ? "true" : "false");
|
||||
#define PRINT_AUDIODEV_EVENT(event) SDL_snprintf(details, sizeof (details), " (timestamp=%u which=%u iscapture=%s)", (uint) event->adevice.timestamp, (uint) event->adevice.which, event->adevice.iscapture ? "true" : "false");
|
||||
SDL_EVENT_CASE(SDL_AUDIODEVICEADDED) PRINT_AUDIODEV_EVENT(event); break;
|
||||
SDL_EVENT_CASE(SDL_AUDIODEVICEREMOVED) PRINT_AUDIODEV_EVENT(event); break;
|
||||
#undef PRINT_AUDIODEV_EVENT
|
||||
|
|
@ -300,14 +318,19 @@ SDL_DebugPrintEvent(const SDL_Event *event)
|
|||
#undef SDL_EVENT_CASE
|
||||
|
||||
default:
|
||||
printf("UNKNOWN SDL EVENT #%u! (Bug? FIXME?)", (uint) event->type);
|
||||
if (!name[0]) {
|
||||
SDL_strlcpy(name, "UNKNOWN", sizeof (name));
|
||||
SDL_snprintf(details, sizeof (details), " #%u! (Bug? FIXME?)", (uint) event->type);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
if (name[0]) {
|
||||
SDL_Log("SDL EVENT: %s%s", name, details);
|
||||
}
|
||||
|
||||
#undef uint
|
||||
}
|
||||
#undef uint
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
@ -417,6 +440,10 @@ SDL_StartEventLoop(void)
|
|||
SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
|
||||
SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE);
|
||||
SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE);
|
||||
#if 0 /* Leave these events enabled so apps can respond to items being dragged onto them at startup */
|
||||
SDL_EventState(SDL_DROPFILE, SDL_DISABLE);
|
||||
SDL_EventState(SDL_DROPTEXT, SDL_DISABLE);
|
||||
#endif
|
||||
|
||||
SDL_AtomicSet(&SDL_EventQ.active, 1);
|
||||
|
||||
|
|
@ -447,9 +474,9 @@ SDL_AddEvent(SDL_Event * event)
|
|||
SDL_EventQ.free = entry->next;
|
||||
}
|
||||
|
||||
#ifdef SDL_DEBUG_EVENTS
|
||||
SDL_DebugPrintEvent(event);
|
||||
#endif
|
||||
if (SDL_DoEventLogging) {
|
||||
SDL_LogEvent(event);
|
||||
}
|
||||
|
||||
entry->event = *event;
|
||||
if (event->type == SDL_SYSWMEVENT) {
|
||||
|
|
@ -604,6 +631,10 @@ SDL_FlushEvent(Uint32 type)
|
|||
void
|
||||
SDL_FlushEvents(Uint32 minType, Uint32 maxType)
|
||||
{
|
||||
/* !!! FIXME: we need to manually SDL_free() the strings in TEXTINPUT and
|
||||
drag'n'drop events if we're flushing them without passing them to the
|
||||
app, but I don't know if this is the right place to do that. */
|
||||
|
||||
/* Don't look after we've quit */
|
||||
if (!SDL_AtomicGet(&SDL_EventQ.active)) {
|
||||
return;
|
||||
|
|
@ -651,7 +682,14 @@ SDL_PumpEvents(void)
|
|||
}
|
||||
#endif
|
||||
|
||||
SDL_SendPendingQuit(); /* in case we had a signal handler fire, etc. */
|
||||
#if !SDL_SENSOR_DISABLED
|
||||
/* Check for sensor state change */
|
||||
if (!SDL_disabled_events[SDL_SENSORUPDATE >> 8]) {
|
||||
SDL_SensorUpdate();
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_SendPendingSignalEvents(); /* in case we had a signal handler fire, etc. */
|
||||
}
|
||||
|
||||
/* Public functions */
|
||||
|
|
@ -863,6 +901,8 @@ SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
|
|||
Uint8
|
||||
SDL_EventState(Uint32 type, int state)
|
||||
{
|
||||
const SDL_bool isdnd = ((state == SDL_DISABLE) || (state == SDL_ENABLE)) &&
|
||||
((type == SDL_DROPFILE) || (type == SDL_DROPTEXT));
|
||||
Uint8 current_state;
|
||||
Uint8 hi = ((type >> 8) & 0xff);
|
||||
Uint8 lo = (type & 0xff);
|
||||
|
|
@ -898,6 +938,12 @@ SDL_EventState(Uint32 type, int state)
|
|||
}
|
||||
}
|
||||
|
||||
/* turn off drag'n'drop support if we've disabled the events.
|
||||
This might change some UI details at the OS level. */
|
||||
if (isdnd) {
|
||||
SDL_ToggleDragAndDropSupport();
|
||||
}
|
||||
|
||||
return current_state;
|
||||
}
|
||||
|
||||
|
|
@ -952,4 +998,26 @@ SDL_SendKeymapChangedEvent(void)
|
|||
return SDL_SendAppEvent(SDL_KEYMAPCHANGED);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_EventsInit(void)
|
||||
{
|
||||
SDL_AddHintCallback(SDL_HINT_EVENT_LOGGING, SDL_EventLoggingChanged, NULL);
|
||||
if (SDL_StartEventLoop() < 0) {
|
||||
SDL_DelHintCallback(SDL_HINT_EVENT_LOGGING, SDL_EventLoggingChanged, NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_QuitInit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_EventsQuit(void)
|
||||
{
|
||||
SDL_QuitQuit();
|
||||
SDL_StopEventLoop();
|
||||
SDL_DelHintCallback(SDL_HINT_EVENT_LOGGING, SDL_EventLoggingChanged, NULL);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -18,12 +18,19 @@
|
|||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef SDL_events_c_h_
|
||||
#define SDL_events_c_h_
|
||||
|
||||
#include "../SDL_internal.h"
|
||||
|
||||
/* Useful functions and variables from SDL_events.c */
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "../video/SDL_sysvideo.h"
|
||||
|
||||
#include "SDL_clipboardevents_c.h"
|
||||
#include "SDL_displayevents_c.h"
|
||||
#include "SDL_dropevents_c.h"
|
||||
#include "SDL_gesture_c.h"
|
||||
#include "SDL_keyboard_c.h"
|
||||
|
|
@ -40,10 +47,16 @@ extern int SDL_SendAppEvent(SDL_EventType eventType);
|
|||
extern int SDL_SendSysWMEvent(SDL_SysWMmsg * message);
|
||||
extern int SDL_SendKeymapChangedEvent(void);
|
||||
|
||||
extern int SDL_QuitInit(void);
|
||||
extern int SDL_SendQuit(void);
|
||||
|
||||
extern int SDL_EventsInit(void);
|
||||
extern void SDL_EventsQuit(void);
|
||||
|
||||
extern void SDL_SendPendingSignalEvents(void);
|
||||
|
||||
extern int SDL_QuitInit(void);
|
||||
extern void SDL_QuitQuit(void);
|
||||
|
||||
extern void SDL_SendPendingQuit(void);
|
||||
#endif /* SDL_events_c_h_ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -279,6 +279,7 @@ int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src)
|
|||
}
|
||||
|
||||
|
||||
#if defined(ENABLE_DOLLAR)
|
||||
static float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float ang)
|
||||
{
|
||||
/* SDL_FloatPoint p[DOLLARNPOINTS]; */
|
||||
|
|
@ -444,6 +445,7 @@ static float dollarRecognize(const SDL_DollarPath *path,int *bestTempl,SDL_Gestu
|
|||
}
|
||||
return bestDiff;
|
||||
}
|
||||
#endif
|
||||
|
||||
int SDL_GestureAddTouch(SDL_TouchID touchId)
|
||||
{
|
||||
|
|
@ -509,6 +511,7 @@ static int SDL_SendGestureMulti(SDL_GestureTouch* touch,float dTheta,float dDist
|
|||
return SDL_PushEvent(&event) > 0;
|
||||
}
|
||||
|
||||
#if defined(ENABLE_DOLLAR)
|
||||
static int SDL_SendGestureDollar(SDL_GestureTouch* touch,
|
||||
SDL_GestureID gestureId,float error)
|
||||
{
|
||||
|
|
@ -533,14 +536,17 @@ static int SDL_SendDollarRecord(SDL_GestureTouch* touch,SDL_GestureID gestureId)
|
|||
event.dgesture.gestureId = gestureId;
|
||||
return SDL_PushEvent(&event) > 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void SDL_GestureProcessEvent(SDL_Event* event)
|
||||
{
|
||||
float x,y;
|
||||
#if defined(ENABLE_DOLLAR)
|
||||
int index;
|
||||
int i;
|
||||
float pathDx, pathDy;
|
||||
#endif
|
||||
SDL_FloatPoint lastP;
|
||||
SDL_FloatPoint lastCentroid;
|
||||
float lDist;
|
||||
|
|
@ -561,11 +567,13 @@ void SDL_GestureProcessEvent(SDL_Event* event)
|
|||
|
||||
/* Finger Up */
|
||||
if (event->type == SDL_FINGERUP) {
|
||||
#if defined(ENABLE_DOLLAR)
|
||||
SDL_FloatPoint path[DOLLARNPOINTS];
|
||||
#endif
|
||||
|
||||
inTouch->numDownFingers--;
|
||||
|
||||
#ifdef ENABLE_DOLLAR
|
||||
#if defined(ENABLE_DOLLAR)
|
||||
if (inTouch->recording) {
|
||||
inTouch->recording = SDL_FALSE;
|
||||
dollarNormalize(&inTouch->dollarPath,path);
|
||||
|
|
@ -610,7 +618,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
|
|||
else if (event->type == SDL_FINGERMOTION) {
|
||||
float dx = event->tfinger.dx;
|
||||
float dy = event->tfinger.dy;
|
||||
#ifdef ENABLE_DOLLAR
|
||||
#if defined(ENABLE_DOLLAR)
|
||||
SDL_DollarPath* path = &inTouch->dollarPath;
|
||||
if (path->numPoints < MAXPATHSIZE) {
|
||||
path->p[path->numPoints].x = inTouch->centroid.x;
|
||||
|
|
@ -687,7 +695,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
|
|||
/* printf("Finger Down: (%f,%f). Centroid: (%f,%f\n",x,y,
|
||||
inTouch->centroid.x,inTouch->centroid.y); */
|
||||
|
||||
#ifdef ENABLE_DOLLAR
|
||||
#if defined(ENABLE_DOLLAR)
|
||||
inTouch->dollarPath.length = 0;
|
||||
inTouch->dollarPath.p[0].x = x;
|
||||
inTouch->dollarPath.p[0].y = y;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -28,17 +28,49 @@
|
|||
#include "SDL_events.h"
|
||||
#include "SDL_events_c.h"
|
||||
#include "../video/SDL_sysvideo.h"
|
||||
#ifdef __WIN32__
|
||||
#include "../core/windows/SDL_windows.h" // For GetDoubleClickTime()
|
||||
#endif
|
||||
|
||||
/* #define DEBUG_MOUSE */
|
||||
|
||||
/* The mouse state */
|
||||
static SDL_Mouse SDL_mouse;
|
||||
static Uint32 SDL_double_click_time = 500;
|
||||
static int SDL_double_click_radius = 1;
|
||||
|
||||
/* for mapping mouse events to touch */
|
||||
static SDL_bool track_mouse_down = SDL_FALSE;
|
||||
|
||||
static int
|
||||
SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y);
|
||||
|
||||
static void SDLCALL
|
||||
SDL_MouseDoubleClickTimeChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
|
||||
{
|
||||
SDL_Mouse *mouse = (SDL_Mouse *)userdata;
|
||||
|
||||
if (hint && *hint) {
|
||||
mouse->double_click_time = SDL_atoi(hint);
|
||||
} else {
|
||||
#ifdef __WIN32__
|
||||
mouse->double_click_time = GetDoubleClickTime();
|
||||
#else
|
||||
mouse->double_click_time = 500;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void SDLCALL
|
||||
SDL_MouseDoubleClickRadiusChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
|
||||
{
|
||||
SDL_Mouse *mouse = (SDL_Mouse *)userdata;
|
||||
|
||||
if (hint && *hint) {
|
||||
mouse->double_click_radius = SDL_atoi(hint);
|
||||
} else {
|
||||
mouse->double_click_radius = 32; /* 32 pixels seems about right for touch interfaces */
|
||||
}
|
||||
}
|
||||
|
||||
static void SDLCALL
|
||||
SDL_MouseNormalSpeedScaleChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
|
||||
{
|
||||
|
|
@ -75,6 +107,29 @@ SDL_TouchMouseEventsChanged(void *userdata, const char *name, const char *oldVal
|
|||
}
|
||||
}
|
||||
|
||||
static void SDLCALL
|
||||
SDL_MouseTouchEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
|
||||
{
|
||||
SDL_Mouse *mouse = (SDL_Mouse *)userdata;
|
||||
|
||||
if (hint == NULL || *hint == '\0') {
|
||||
/* Default */
|
||||
#if defined(__ANDROID__) || (defined(__IPHONEOS__) && !defined(__TVOS__))
|
||||
mouse->mouse_touch_events = SDL_TRUE;
|
||||
#else
|
||||
mouse->mouse_touch_events = SDL_FALSE;
|
||||
#endif
|
||||
} else if (*hint == '1' || SDL_strcasecmp(hint, "true") == 0) {
|
||||
mouse->mouse_touch_events = SDL_TRUE;
|
||||
} else {
|
||||
mouse->mouse_touch_events = SDL_FALSE;
|
||||
}
|
||||
|
||||
if (mouse->mouse_touch_events) {
|
||||
SDL_AddTouch(SDL_MOUSE_TOUCHID, SDL_TOUCH_DEVICE_DIRECT, "mouse_input");
|
||||
}
|
||||
}
|
||||
|
||||
/* Public functions */
|
||||
int
|
||||
SDL_MouseInit(void)
|
||||
|
|
@ -83,6 +138,12 @@ SDL_MouseInit(void)
|
|||
|
||||
SDL_zerop(mouse);
|
||||
|
||||
SDL_AddHintCallback(SDL_HINT_MOUSE_DOUBLE_CLICK_TIME,
|
||||
SDL_MouseDoubleClickTimeChanged, mouse);
|
||||
|
||||
SDL_AddHintCallback(SDL_HINT_MOUSE_DOUBLE_CLICK_RADIUS,
|
||||
SDL_MouseDoubleClickRadiusChanged, mouse);
|
||||
|
||||
SDL_AddHintCallback(SDL_HINT_MOUSE_NORMAL_SPEED_SCALE,
|
||||
SDL_MouseNormalSpeedScaleChanged, mouse);
|
||||
|
||||
|
|
@ -92,6 +153,11 @@ SDL_MouseInit(void)
|
|||
SDL_AddHintCallback(SDL_HINT_TOUCH_MOUSE_EVENTS,
|
||||
SDL_TouchMouseEventsChanged, mouse);
|
||||
|
||||
SDL_AddHintCallback(SDL_HINT_MOUSE_TOUCH_EVENTS,
|
||||
SDL_MouseTouchEventsChanged, mouse);
|
||||
|
||||
mouse->was_touch_mouse_events = SDL_FALSE; /* no touch to mouse movement event pending */
|
||||
|
||||
mouse->cursor_shown = SDL_TRUE;
|
||||
|
||||
return (0);
|
||||
|
|
@ -114,12 +180,6 @@ SDL_GetMouse(void)
|
|||
return &SDL_mouse;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SetDoubleClickTime(Uint32 interval)
|
||||
{
|
||||
SDL_double_click_time = interval;
|
||||
}
|
||||
|
||||
SDL_Window *
|
||||
SDL_GetMouseFocus(void)
|
||||
{
|
||||
|
|
@ -186,7 +246,7 @@ SDL_SetMouseFocus(SDL_Window * window)
|
|||
|
||||
/* Check to see if we need to synthesize focus events */
|
||||
static SDL_bool
|
||||
SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate)
|
||||
SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate, SDL_bool send_mouse_motion)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
SDL_bool inWindow = SDL_TRUE;
|
||||
|
|
@ -217,7 +277,9 @@ SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate)
|
|||
#ifdef DEBUG_MOUSE
|
||||
printf("Mouse left window, synthesizing move & focus lost event\n");
|
||||
#endif
|
||||
SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
|
||||
if (send_mouse_motion) {
|
||||
SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
|
||||
}
|
||||
SDL_SetMouseFocus(NULL);
|
||||
}
|
||||
return SDL_FALSE;
|
||||
|
|
@ -228,7 +290,9 @@ SDL_UpdateMouseFocus(SDL_Window * window, int x, int y, Uint32 buttonstate)
|
|||
printf("Mouse entered window, synthesizing focus gain & move event\n");
|
||||
#endif
|
||||
SDL_SetMouseFocus(window);
|
||||
SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
|
||||
if (send_mouse_motion) {
|
||||
SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
|
||||
}
|
||||
}
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
|
@ -238,7 +302,7 @@ SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int
|
|||
{
|
||||
if (window && !relative) {
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate)) {
|
||||
if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate, (mouseID == SDL_TOUCH_MOUSEID) ? SDL_FALSE : SDL_TRUE)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -269,8 +333,22 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
|
|||
int xrel;
|
||||
int yrel;
|
||||
|
||||
if (mouseID == SDL_TOUCH_MOUSEID && !mouse->touch_mouse_events) {
|
||||
return 0;
|
||||
/* SDL_HINT_MOUSE_TOUCH_EVENTS: controlling whether mouse events should generate synthetic touch events */
|
||||
if (mouse->mouse_touch_events) {
|
||||
if (mouseID != SDL_TOUCH_MOUSEID && !relative && track_mouse_down) {
|
||||
if (window) {
|
||||
float fx = (float)x / (float)window->w;
|
||||
float fy = (float)y / (float)window->h;
|
||||
SDL_SendTouchMotion(SDL_MOUSE_TOUCHID, 0, fx, fy, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* SDL_HINT_TOUCH_MOUSE_EVENTS: if not set, discard synthetic mouse events coming from platform layer */
|
||||
if (mouse->touch_mouse_events == 0) {
|
||||
if (mouseID == SDL_TOUCH_MOUSEID) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (mouseID != SDL_TOUCH_MOUSEID && mouse->relative_mode_warp) {
|
||||
|
|
@ -374,6 +452,8 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
|
|||
event.motion.type = SDL_MOUSEMOTION;
|
||||
event.motion.windowID = mouse->focus ? mouse->focus->id : 0;
|
||||
event.motion.which = mouseID;
|
||||
/* Set us pending (or clear during a normal mouse movement event) as having triggered */
|
||||
mouse->was_touch_mouse_events = (mouseID == SDL_TOUCH_MOUSEID)? SDL_TRUE : SDL_FALSE;
|
||||
event.motion.state = mouse->buttonstate;
|
||||
event.motion.x = mouse->x;
|
||||
event.motion.y = mouse->y;
|
||||
|
|
@ -418,8 +498,27 @@ SDL_PrivateSendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state
|
|||
Uint32 type;
|
||||
Uint32 buttonstate = mouse->buttonstate;
|
||||
|
||||
if (mouseID == SDL_TOUCH_MOUSEID && !mouse->touch_mouse_events) {
|
||||
return 0;
|
||||
/* SDL_HINT_MOUSE_TOUCH_EVENTS: controlling whether mouse events should generate synthetic touch events */
|
||||
if (mouse->mouse_touch_events) {
|
||||
if (mouseID != SDL_TOUCH_MOUSEID && button == SDL_BUTTON_LEFT) {
|
||||
if (state == SDL_PRESSED) {
|
||||
track_mouse_down = SDL_TRUE;
|
||||
} else {
|
||||
track_mouse_down = SDL_FALSE;
|
||||
}
|
||||
if (window) {
|
||||
float fx = (float)mouse->x / (float)window->w;
|
||||
float fy = (float)mouse->y / (float)window->h;
|
||||
SDL_SendTouch(SDL_MOUSE_TOUCHID, 0, track_mouse_down, fx, fy, 1.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* SDL_HINT_TOUCH_MOUSE_EVENTS: if not set, discard synthetic mouse events coming from platform layer */
|
||||
if (mouse->touch_mouse_events == 0) {
|
||||
if (mouseID == SDL_TOUCH_MOUSEID) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Figure out which event to perform */
|
||||
|
|
@ -439,7 +538,7 @@ SDL_PrivateSendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state
|
|||
|
||||
/* We do this after calculating buttonstate so button presses gain focus */
|
||||
if (window && state == SDL_PRESSED) {
|
||||
SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
|
||||
SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate, SDL_TRUE);
|
||||
}
|
||||
|
||||
if (buttonstate == mouse->buttonstate) {
|
||||
|
|
@ -454,9 +553,9 @@ SDL_PrivateSendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state
|
|||
if (state == SDL_PRESSED) {
|
||||
Uint32 now = SDL_GetTicks();
|
||||
|
||||
if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + SDL_double_click_time) ||
|
||||
SDL_abs(mouse->x - clickstate->last_x) > SDL_double_click_radius ||
|
||||
SDL_abs(mouse->y - clickstate->last_y) > SDL_double_click_radius) {
|
||||
if (SDL_TICKS_PASSED(now, clickstate->last_timestamp + mouse->double_click_time) ||
|
||||
SDL_abs(mouse->x - clickstate->last_x) > mouse->double_click_radius ||
|
||||
SDL_abs(mouse->y - clickstate->last_y) > mouse->double_click_radius) {
|
||||
clickstate->click_count = 0;
|
||||
}
|
||||
clickstate->last_timestamp = now;
|
||||
|
|
@ -489,9 +588,9 @@ SDL_PrivateSendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state
|
|||
|
||||
/* We do this after dispatching event so button releases can lose focus */
|
||||
if (window && state == SDL_RELEASED) {
|
||||
SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
|
||||
SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate, SDL_TRUE);
|
||||
}
|
||||
|
||||
|
||||
return posted;
|
||||
}
|
||||
|
||||
|
|
@ -519,7 +618,7 @@ SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, float x, float y, S
|
|||
SDL_SetMouseFocus(window);
|
||||
}
|
||||
|
||||
if (!x && !y) {
|
||||
if (x == 0.0f && y == 0.0f) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -581,6 +680,7 @@ SDL_MouseQuit(void)
|
|||
cursor = next;
|
||||
}
|
||||
mouse->cursors = NULL;
|
||||
mouse->cur_cursor = NULL;
|
||||
|
||||
if (mouse->def_cursor && mouse->FreeCursor) {
|
||||
mouse->FreeCursor(mouse->def_cursor);
|
||||
|
|
@ -687,8 +787,9 @@ SDL_WarpMouseGlobal(int x, int y)
|
|||
static SDL_bool
|
||||
ShouldUseRelativeModeWarp(SDL_Mouse *mouse)
|
||||
{
|
||||
if (!mouse->SetRelativeMouseMode) {
|
||||
return SDL_TRUE;
|
||||
if (!mouse->WarpMouse) {
|
||||
/* Need this functionality for relative mode warp implementation */
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
return SDL_GetHintBoolean(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, SDL_FALSE);
|
||||
|
|
@ -704,6 +805,24 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Set the relative mode */
|
||||
if (!enabled && mouse->relative_mode_warp) {
|
||||
mouse->relative_mode_warp = SDL_FALSE;
|
||||
} else if (enabled && ShouldUseRelativeModeWarp(mouse)) {
|
||||
mouse->relative_mode_warp = SDL_TRUE;
|
||||
} else if (!mouse->SetRelativeMouseMode || mouse->SetRelativeMouseMode(enabled) < 0) {
|
||||
if (enabled) {
|
||||
/* Fall back to warp mode if native relative mode failed */
|
||||
if (!mouse->WarpMouse) {
|
||||
return SDL_SetError("No relative mode implementation available");
|
||||
}
|
||||
mouse->relative_mode_warp = SDL_TRUE;
|
||||
}
|
||||
}
|
||||
mouse->relative_mode = enabled;
|
||||
mouse->scale_accum_x = 0.0f;
|
||||
mouse->scale_accum_y = 0.0f;
|
||||
|
||||
if (enabled && focusWindow) {
|
||||
/* Center it in the focused window to prevent clicks from going through
|
||||
* to background windows.
|
||||
|
|
@ -712,21 +831,6 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
|
|||
SDL_WarpMouseInWindow(focusWindow, focusWindow->w/2, focusWindow->h/2);
|
||||
}
|
||||
|
||||
/* Set the relative mode */
|
||||
if (!enabled && mouse->relative_mode_warp) {
|
||||
mouse->relative_mode_warp = SDL_FALSE;
|
||||
} else if (enabled && ShouldUseRelativeModeWarp(mouse)) {
|
||||
mouse->relative_mode_warp = SDL_TRUE;
|
||||
} else if (mouse->SetRelativeMouseMode(enabled) < 0) {
|
||||
if (enabled) {
|
||||
/* Fall back to warp mode if native relative mode failed */
|
||||
mouse->relative_mode_warp = SDL_TRUE;
|
||||
}
|
||||
}
|
||||
mouse->relative_mode = enabled;
|
||||
mouse->scale_accum_x = 0.0f;
|
||||
mouse->scale_accum_y = 0.0f;
|
||||
|
||||
if (mouse->focus) {
|
||||
SDL_UpdateWindowGrab(mouse->focus);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -90,7 +90,11 @@ typedef struct
|
|||
float relative_speed_scale;
|
||||
float scale_accum_x;
|
||||
float scale_accum_y;
|
||||
Uint32 double_click_time;
|
||||
int double_click_radius;
|
||||
SDL_bool touch_mouse_events;
|
||||
SDL_bool mouse_touch_events;
|
||||
SDL_bool was_touch_mouse_events; /* Was a touch-mouse event pending? */
|
||||
|
||||
/* Data for double-click tracking */
|
||||
int num_clickstates;
|
||||
|
|
@ -112,9 +116,6 @@ extern int SDL_MouseInit(void);
|
|||
/* Get the mouse state structure */
|
||||
SDL_Mouse *SDL_GetMouse(void);
|
||||
|
||||
/* Set the default double-click interval */
|
||||
extern void SDL_SetDoubleClickTime(Uint32 interval);
|
||||
|
||||
/* Set the default mouse cursor */
|
||||
extern void SDL_SetDefaultCursor(SDL_Cursor * cursor);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -31,10 +31,22 @@
|
|||
#include "SDL_events.h"
|
||||
#include "SDL_events_c.h"
|
||||
|
||||
#if defined(HAVE_SIGNAL_H) || defined(HAVE_SIGACTION)
|
||||
#define HAVE_SIGNAL_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SIGNAL_SUPPORT
|
||||
static SDL_bool disable_signals = SDL_FALSE;
|
||||
static SDL_bool send_quit_pending = SDL_FALSE;
|
||||
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
#ifdef SDL_BACKGROUNDING_SIGNAL
|
||||
static SDL_bool send_backgrounding_pending = SDL_FALSE;
|
||||
#endif
|
||||
|
||||
#ifdef SDL_FOREGROUNDING_SIGNAL
|
||||
static SDL_bool send_foregrounding_pending = SDL_FALSE;
|
||||
#endif
|
||||
|
||||
static void
|
||||
SDL_HandleSIG(int sig)
|
||||
{
|
||||
|
|
@ -43,110 +55,155 @@ SDL_HandleSIG(int sig)
|
|||
|
||||
/* Send a quit event next time the event loop pumps. */
|
||||
/* We can't send it in signal handler; malloc() might be interrupted! */
|
||||
send_quit_pending = SDL_TRUE;
|
||||
if ((sig == SIGINT) || (sig == SIGTERM)) {
|
||||
send_quit_pending = SDL_TRUE;
|
||||
}
|
||||
|
||||
#ifdef SDL_BACKGROUNDING_SIGNAL
|
||||
else if (sig == SDL_BACKGROUNDING_SIGNAL) {
|
||||
send_backgrounding_pending = SDL_TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SDL_FOREGROUNDING_SIGNAL
|
||||
else if (sig == SDL_FOREGROUNDING_SIGNAL) {
|
||||
send_foregrounding_pending = SDL_TRUE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_EventSignal_Init(const int sig)
|
||||
{
|
||||
#ifdef HAVE_SIGACTION
|
||||
struct sigaction action;
|
||||
|
||||
sigaction(sig, NULL, &action);
|
||||
#ifdef HAVE_SA_SIGACTION
|
||||
if ( action.sa_handler == SIG_DFL && (void (*)(int))action.sa_sigaction == SIG_DFL ) {
|
||||
#else
|
||||
if ( action.sa_handler == SIG_DFL ) {
|
||||
#endif
|
||||
action.sa_handler = SDL_HandleSIG;
|
||||
sigaction(sig, &action, NULL);
|
||||
}
|
||||
#elif HAVE_SIGNAL_H
|
||||
void (*ohandler) (int) = signal(sig, SDL_HandleSIG);
|
||||
if (ohandler != SIG_DFL) {
|
||||
signal(sig, ohandler);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_EventSignal_Quit(const int sig)
|
||||
{
|
||||
#ifdef HAVE_SIGACTION
|
||||
struct sigaction action;
|
||||
sigaction(sig, NULL, &action);
|
||||
if ( action.sa_handler == SDL_HandleSIG ) {
|
||||
action.sa_handler = SIG_DFL;
|
||||
sigaction(sig, &action, NULL);
|
||||
}
|
||||
#elif HAVE_SIGNAL_H
|
||||
void (*ohandler) (int) = signal(sig, SIG_DFL);
|
||||
if (ohandler != SDL_HandleSIG) {
|
||||
signal(sig, ohandler);
|
||||
}
|
||||
#endif /* HAVE_SIGNAL_H */
|
||||
}
|
||||
|
||||
/* Public functions */
|
||||
static int
|
||||
SDL_QuitInit_Internal(void)
|
||||
{
|
||||
#ifdef HAVE_SIGACTION
|
||||
struct sigaction action;
|
||||
sigaction(SIGINT, NULL, &action);
|
||||
#ifdef HAVE_SA_SIGACTION
|
||||
if ( action.sa_handler == SIG_DFL && (void (*)(int))action.sa_sigaction == SIG_DFL ) {
|
||||
#else
|
||||
if ( action.sa_handler == SIG_DFL ) {
|
||||
#endif
|
||||
action.sa_handler = SDL_HandleSIG;
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
}
|
||||
sigaction(SIGTERM, NULL, &action);
|
||||
|
||||
#ifdef HAVE_SA_SIGACTION
|
||||
if ( action.sa_handler == SIG_DFL && (void (*)(int))action.sa_sigaction == SIG_DFL ) {
|
||||
#else
|
||||
if ( action.sa_handler == SIG_DFL ) {
|
||||
#endif
|
||||
action.sa_handler = SDL_HandleSIG;
|
||||
sigaction(SIGTERM, &action, NULL);
|
||||
}
|
||||
#elif HAVE_SIGNAL_H
|
||||
void (*ohandler) (int);
|
||||
|
||||
/* Both SIGINT and SIGTERM are translated into quit interrupts */
|
||||
ohandler = signal(SIGINT, SDL_HandleSIG);
|
||||
if (ohandler != SIG_DFL)
|
||||
signal(SIGINT, ohandler);
|
||||
ohandler = signal(SIGTERM, SDL_HandleSIG);
|
||||
if (ohandler != SIG_DFL)
|
||||
signal(SIGTERM, ohandler);
|
||||
#endif /* HAVE_SIGNAL_H */
|
||||
/* and SDL can be built to simulate iOS/Android semantics with arbitrary signals. */
|
||||
SDL_EventSignal_Init(SIGINT);
|
||||
SDL_EventSignal_Init(SIGTERM);
|
||||
|
||||
#ifdef SDL_BACKGROUNDING_SIGNAL
|
||||
SDL_EventSignal_Init(SDL_BACKGROUNDING_SIGNAL);
|
||||
#endif
|
||||
|
||||
#ifdef SDL_FOREGROUNDING_SIGNAL
|
||||
SDL_EventSignal_Init(SDL_FOREGROUNDING_SIGNAL);
|
||||
#endif
|
||||
|
||||
/* That's it! */
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_QuitInit(void)
|
||||
{
|
||||
if (!SDL_GetHintBoolean(SDL_HINT_NO_SIGNAL_HANDLERS, SDL_FALSE)) {
|
||||
return SDL_QuitInit_Internal();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_QuitQuit_Internal(void)
|
||||
{
|
||||
#ifdef HAVE_SIGACTION
|
||||
struct sigaction action;
|
||||
sigaction(SIGINT, NULL, &action);
|
||||
if ( action.sa_handler == SDL_HandleSIG ) {
|
||||
action.sa_handler = SIG_DFL;
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
}
|
||||
sigaction(SIGTERM, NULL, &action);
|
||||
if ( action.sa_handler == SDL_HandleSIG ) {
|
||||
action.sa_handler = SIG_DFL;
|
||||
sigaction(SIGTERM, &action, NULL);
|
||||
}
|
||||
#elif HAVE_SIGNAL_H
|
||||
void (*ohandler) (int);
|
||||
SDL_EventSignal_Quit(SIGINT);
|
||||
SDL_EventSignal_Quit(SIGTERM);
|
||||
|
||||
ohandler = signal(SIGINT, SIG_DFL);
|
||||
if (ohandler != SDL_HandleSIG)
|
||||
signal(SIGINT, ohandler);
|
||||
ohandler = signal(SIGTERM, SIG_DFL);
|
||||
if (ohandler != SDL_HandleSIG)
|
||||
signal(SIGTERM, ohandler);
|
||||
#endif /* HAVE_SIGNAL_H */
|
||||
#ifdef SDL_BACKGROUNDING_SIGNAL
|
||||
SDL_EventSignal_Quit(SDL_BACKGROUNDING_SIGNAL);
|
||||
#endif
|
||||
|
||||
#ifdef SDL_FOREGROUNDING_SIGNAL
|
||||
SDL_EventSignal_Quit(SDL_FOREGROUNDING_SIGNAL);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
SDL_QuitInit(void)
|
||||
{
|
||||
#ifdef HAVE_SIGNAL_SUPPORT
|
||||
if (!SDL_GetHintBoolean(SDL_HINT_NO_SIGNAL_HANDLERS, SDL_FALSE)) {
|
||||
return SDL_QuitInit_Internal();
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_QuitQuit(void)
|
||||
{
|
||||
#ifdef HAVE_SIGNAL_SUPPORT
|
||||
if (!disable_signals) {
|
||||
SDL_QuitQuit_Internal();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SendPendingSignalEvents(void)
|
||||
{
|
||||
#ifdef HAVE_SIGNAL_SUPPORT
|
||||
if (send_quit_pending) {
|
||||
SDL_SendQuit();
|
||||
SDL_assert(!send_quit_pending);
|
||||
}
|
||||
|
||||
#ifdef SDL_BACKGROUNDING_SIGNAL
|
||||
if (send_backgrounding_pending) {
|
||||
send_backgrounding_pending = SDL_FALSE;
|
||||
SDL_OnApplicationWillResignActive();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SDL_FOREGROUNDING_SIGNAL
|
||||
if (send_foregrounding_pending) {
|
||||
send_foregrounding_pending = SDL_FALSE;
|
||||
SDL_OnApplicationDidBecomeActive();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/* This function returns 1 if it's okay to close the application window */
|
||||
int
|
||||
SDL_SendQuit(void)
|
||||
{
|
||||
#ifdef HAVE_SIGNAL_SUPPORT
|
||||
send_quit_pending = SDL_FALSE;
|
||||
#endif
|
||||
return SDL_SendAppEvent(SDL_QUIT);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SendPendingQuit(void)
|
||||
{
|
||||
if (send_quit_pending) {
|
||||
SDL_SendQuit();
|
||||
SDL_assert(!send_quit_pending);
|
||||
}
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -31,6 +31,15 @@
|
|||
static int SDL_num_touch = 0;
|
||||
static SDL_Touch **SDL_touchDevices = NULL;
|
||||
|
||||
/* for mapping touch events to mice */
|
||||
|
||||
#define SYNTHESIZE_TOUCH_TO_MOUSE 1
|
||||
|
||||
#if SYNTHESIZE_TOUCH_TO_MOUSE
|
||||
static SDL_bool finger_touching = SDL_FALSE;
|
||||
static SDL_FingerID track_fingerid;
|
||||
static SDL_TouchID track_touchid;
|
||||
#endif
|
||||
|
||||
/* Public functions */
|
||||
int
|
||||
|
|
@ -86,6 +95,16 @@ SDL_GetTouch(SDL_TouchID id)
|
|||
return SDL_touchDevices[index];
|
||||
}
|
||||
|
||||
SDL_TouchDeviceType
|
||||
SDL_GetTouchDeviceType(SDL_TouchID id)
|
||||
{
|
||||
SDL_Touch *touch = SDL_GetTouch(id);
|
||||
if (touch) {
|
||||
return touch->type;
|
||||
}
|
||||
return SDL_TOUCH_DEVICE_INVALID;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_GetFingerIndex(const SDL_Touch * touch, SDL_FingerID fingerid)
|
||||
{
|
||||
|
|
@ -133,7 +152,7 @@ SDL_GetTouchFinger(SDL_TouchID touchID, int index)
|
|||
}
|
||||
|
||||
int
|
||||
SDL_AddTouch(SDL_TouchID touchID, const char *name)
|
||||
SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char *name)
|
||||
{
|
||||
SDL_Touch **touchDevices;
|
||||
int index;
|
||||
|
|
@ -163,6 +182,7 @@ SDL_AddTouch(SDL_TouchID touchID, const char *name)
|
|||
|
||||
/* we're setting the touch properties */
|
||||
SDL_touchDevices[index]->id = touchID;
|
||||
SDL_touchDevices[index]->type = type;
|
||||
SDL_touchDevices[index]->num_fingers = 0;
|
||||
SDL_touchDevices[index]->max_fingers = 0;
|
||||
SDL_touchDevices[index]->fingers = NULL;
|
||||
|
|
@ -224,12 +244,72 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid,
|
|||
{
|
||||
int posted;
|
||||
SDL_Finger *finger;
|
||||
SDL_Mouse *mouse;
|
||||
|
||||
SDL_Touch* touch = SDL_GetTouch(id);
|
||||
if (!touch) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
mouse = SDL_GetMouse();
|
||||
|
||||
#if SYNTHESIZE_TOUCH_TO_MOUSE
|
||||
/* SDL_HINT_TOUCH_MOUSE_EVENTS: controlling whether touch events should generate synthetic mouse events */
|
||||
{
|
||||
if (mouse->touch_mouse_events) {
|
||||
/* FIXME: maybe we should only restrict to a few SDL_TouchDeviceType */
|
||||
if (id != SDL_MOUSE_TOUCHID) {
|
||||
SDL_Window *window = SDL_GetMouseFocus();
|
||||
if (window == NULL) {
|
||||
/* Mouse focus may have been lost by e.g. the window resizing
|
||||
* due to device orientation change while the mouse state is
|
||||
* pressed (because its position is now out of the window).
|
||||
* SendMouse* will update mouse focus again after that, but
|
||||
* if those are never called then SDL might think the
|
||||
* 'mouse' has no focus at all. */
|
||||
window = SDL_GetKeyboardFocus();
|
||||
}
|
||||
if (window) {
|
||||
if (down) {
|
||||
if (finger_touching == SDL_FALSE) {
|
||||
int pos_x = (int)(x * (float)window->w);
|
||||
int pos_y = (int)(y * (float)window->h);
|
||||
if (pos_x < 0) pos_x = 0;
|
||||
if (pos_x > window->w - 1) pos_x = window->w - 1;
|
||||
if (pos_y < 0) pos_y = 0;
|
||||
if (pos_y > window->h - 1) pos_y = window->h - 1;
|
||||
SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
|
||||
SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_PRESSED, SDL_BUTTON_LEFT);
|
||||
}
|
||||
} else {
|
||||
if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
|
||||
SDL_SendMouseButton(window, SDL_TOUCH_MOUSEID, SDL_RELEASED, SDL_BUTTON_LEFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (down) {
|
||||
if (finger_touching == SDL_FALSE) {
|
||||
finger_touching = SDL_TRUE;
|
||||
track_touchid = id;
|
||||
track_fingerid = fingerid;
|
||||
}
|
||||
} else {
|
||||
if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
|
||||
finger_touching = SDL_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* SDL_HINT_MOUSE_TOUCH_EVENTS: if not set, discard synthetic touch events coming from platform layer */
|
||||
if (mouse->mouse_touch_events == 0) {
|
||||
if (id == SDL_MOUSE_TOUCHID) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
finger = SDL_GetFinger(touch, fingerid);
|
||||
if (down) {
|
||||
if (finger) {
|
||||
|
|
@ -286,6 +366,7 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
|
|||
{
|
||||
SDL_Touch *touch;
|
||||
SDL_Finger *finger;
|
||||
SDL_Mouse *mouse;
|
||||
int posted;
|
||||
float xrel, yrel, prel;
|
||||
|
||||
|
|
@ -294,6 +375,37 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
|
|||
return -1;
|
||||
}
|
||||
|
||||
mouse = SDL_GetMouse();
|
||||
|
||||
#if SYNTHESIZE_TOUCH_TO_MOUSE
|
||||
/* SDL_HINT_TOUCH_MOUSE_EVENTS: controlling whether touch events should generate synthetic mouse events */
|
||||
{
|
||||
if (mouse->touch_mouse_events) {
|
||||
if (id != SDL_MOUSE_TOUCHID) {
|
||||
SDL_Window *window = SDL_GetMouseFocus();
|
||||
if (window) {
|
||||
if (finger_touching == SDL_TRUE && track_touchid == id && track_fingerid == fingerid) {
|
||||
int pos_x = (int)(x * (float)window->w);
|
||||
int pos_y = (int)(y * (float)window->h);
|
||||
if (pos_x < 0) pos_x = 0;
|
||||
if (pos_x > window->w - 1) pos_x = window->w - 1;
|
||||
if (pos_y < 0) pos_y = 0;
|
||||
if (pos_y > window->h - 1) pos_y = window->h - 1;
|
||||
SDL_SendMouseMotion(window, SDL_TOUCH_MOUSEID, 0, pos_x, pos_y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* SDL_HINT_MOUSE_TOUCH_EVENTS: if not set, discard synthetic touch events coming from platform layer */
|
||||
if (mouse->mouse_touch_events == 0) {
|
||||
if (id == SDL_MOUSE_TOUCHID) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
finger = SDL_GetFinger(touch,fingerid);
|
||||
if (!finger) {
|
||||
return SDL_SendTouch(id, fingerid, SDL_TRUE, x, y, pressure);
|
||||
|
|
@ -304,7 +416,7 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
|
|||
prel = pressure - finger->pressure;
|
||||
|
||||
/* Drop events that don't change state */
|
||||
if (!xrel && !yrel && !prel) {
|
||||
if (xrel == 0.0f && yrel == 0.0f && prel == 0.0f) {
|
||||
#if 0
|
||||
printf("Touch event didn't change state - dropped!\n");
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -27,6 +27,7 @@
|
|||
typedef struct SDL_Touch
|
||||
{
|
||||
SDL_TouchID id;
|
||||
SDL_TouchDeviceType type;
|
||||
int num_fingers;
|
||||
int max_fingers;
|
||||
SDL_Finger** fingers;
|
||||
|
|
@ -37,7 +38,7 @@ typedef struct SDL_Touch
|
|||
extern int SDL_TouchInit(void);
|
||||
|
||||
/* Add a touch, returning the index of the touch, or -1 if there was an error. */
|
||||
extern int SDL_AddTouch(SDL_TouchID id, const char *name);
|
||||
extern int SDL_AddTouch(SDL_TouchID id, SDL_TouchDeviceType type, const char *name);
|
||||
|
||||
/* Get the touch with a given id */
|
||||
extern SDL_Touch *SDL_GetTouch(SDL_TouchID id);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -25,30 +25,16 @@
|
|||
#include "SDL_events.h"
|
||||
#include "SDL_events_c.h"
|
||||
#include "SDL_mouse_c.h"
|
||||
#include "../video/SDL_sysvideo.h"
|
||||
|
||||
|
||||
static int SDLCALL
|
||||
RemovePendingResizedEvents(void * userdata, SDL_Event *event)
|
||||
RemovePendingSizeChangedAndResizedEvents(void * userdata, SDL_Event *event)
|
||||
{
|
||||
SDL_Event *new_event = (SDL_Event *)userdata;
|
||||
|
||||
if (event->type == SDL_WINDOWEVENT &&
|
||||
event->window.event == SDL_WINDOWEVENT_RESIZED &&
|
||||
event->window.windowID == new_event->window.windowID) {
|
||||
/* We're about to post a new size event, drop the old one */
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int SDLCALL
|
||||
RemovePendingSizeChangedEvents(void * userdata, SDL_Event *event)
|
||||
{
|
||||
SDL_Event *new_event = (SDL_Event *)userdata;
|
||||
|
||||
if (event->type == SDL_WINDOWEVENT &&
|
||||
event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED &&
|
||||
(event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED ||
|
||||
event->window.event == SDL_WINDOWEVENT_RESIZED) &&
|
||||
event->window.windowID == new_event->window.windowID) {
|
||||
/* We're about to post a new size event, drop the old one */
|
||||
return 0;
|
||||
|
|
@ -98,7 +84,7 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
|
|||
if (window->flags & SDL_WINDOW_SHOWN) {
|
||||
return 0;
|
||||
}
|
||||
window->flags &= ~SDL_WINDOW_HIDDEN;
|
||||
window->flags &= ~(SDL_WINDOW_HIDDEN | SDL_WINDOW_MINIMIZED);
|
||||
window->flags |= SDL_WINDOW_SHOWN;
|
||||
SDL_OnWindowShown(window);
|
||||
break;
|
||||
|
|
@ -200,11 +186,8 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
|
|||
event.window.windowID = window->id;
|
||||
|
||||
/* Fixes queue overflow with resize events that aren't processed */
|
||||
if (windowevent == SDL_WINDOWEVENT_RESIZED) {
|
||||
SDL_FilterEvents(RemovePendingResizedEvents, &event);
|
||||
}
|
||||
if (windowevent == SDL_WINDOWEVENT_SIZE_CHANGED) {
|
||||
SDL_FilterEvents(RemovePendingSizeChangedEvents, &event);
|
||||
SDL_FilterEvents(RemovePendingSizeChangedAndResizedEvents, &event);
|
||||
}
|
||||
if (windowevent == SDL_WINDOWEVENT_MOVED) {
|
||||
SDL_FilterEvents(RemovePendingMoveEvents, &event);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -18,6 +18,10 @@
|
|||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef scancodes_xfree86_h_
|
||||
#define scancodes_xfree86_h_
|
||||
|
||||
#include "../../include/SDL_scancode.h"
|
||||
|
||||
/* XFree86 key code to SDL scancode mapping table
|
||||
|
|
@ -503,4 +507,6 @@ static const SDL_Scancode xvnc_scancode_table[] = {
|
|||
/* 80 */ SDL_SCANCODE_F12,
|
||||
};
|
||||
|
||||
#endif /* scancodes_xfree86_h_ */
|
||||
|
||||
/* *INDENT-ON* */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue