mirror of
https://github.com/encounter/SDL.git
synced 2025-12-11 06:27:44 +00:00
Fixes #2022, do not resume on Android when surfaceChanged
If the app is in landscape mode and the user presses the power button, a pause is followed immediately by a surfaceChanged event because the lock screen is shown in portrait mode. This triggers a "false" resume. So, we just pause and resume following the onWindowFocusChanged events. Also, wait for SDL_APP_WILLENTERBACKGROUND and SDL_APP_DIDENTERBACKGROUND before blocking the event pump.
This commit is contained in:
46
src/events/SDL_clipboardevents.c
Normal file
46
src/events/SDL_clipboardevents.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
/* Clipboard event handling code for SDL */
|
||||
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_events_c.h"
|
||||
#include "SDL_clipboardevents_c.h"
|
||||
|
||||
|
||||
int
|
||||
SDL_SendClipboardUpdate(void)
|
||||
{
|
||||
int posted;
|
||||
|
||||
/* Post the event, if desired */
|
||||
posted = 0;
|
||||
if (SDL_GetEventState(SDL_CLIPBOARDUPDATE) == SDL_ENABLE) {
|
||||
SDL_Event event;
|
||||
event.type = SDL_CLIPBOARDUPDATE;
|
||||
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
}
|
||||
return (posted);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
30
src/events/SDL_clipboardevents_c.h
Normal file
30
src/events/SDL_clipboardevents_c.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
#ifndef _SDL_clipboardevents_c_h
|
||||
#define _SDL_clipboardevents_c_h
|
||||
|
||||
extern int SDL_SendClipboardUpdate(void);
|
||||
|
||||
#endif /* _SDL_clipboardevents_c_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
46
src/events/SDL_dropevents.c
Normal file
46
src/events/SDL_dropevents.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
/* Drag and drop event handling code for SDL */
|
||||
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_events_c.h"
|
||||
#include "SDL_dropevents_c.h"
|
||||
|
||||
|
||||
int
|
||||
SDL_SendDropFile(const char *file)
|
||||
{
|
||||
int posted;
|
||||
|
||||
/* Post the event, if desired */
|
||||
posted = 0;
|
||||
if (SDL_GetEventState(SDL_DROPFILE) == SDL_ENABLE) {
|
||||
SDL_Event event;
|
||||
event.type = SDL_DROPFILE;
|
||||
event.drop.file = SDL_strdup(file);
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
}
|
||||
return (posted);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
30
src/events/SDL_dropevents_c.h
Normal file
30
src/events/SDL_dropevents_c.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
#ifndef _SDL_dropevents_c_h
|
||||
#define _SDL_dropevents_c_h
|
||||
|
||||
extern int SDL_SendDropFile(const char *file);
|
||||
|
||||
#endif /* _SDL_dropevents_c_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
642
src/events/SDL_events.c
Normal file
642
src/events/SDL_events.c
Normal file
@@ -0,0 +1,642 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
/* General event handling code for SDL */
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_syswm.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_events_c.h"
|
||||
#include "../timer/SDL_timer_c.h"
|
||||
#if !SDL_JOYSTICK_DISABLED
|
||||
#include "../joystick/SDL_joystick_c.h"
|
||||
#endif
|
||||
#include "../video/SDL_sysvideo.h"
|
||||
|
||||
/* An arbitrary limit so we don't have unbounded growth */
|
||||
#define SDL_MAX_QUEUED_EVENTS 65535
|
||||
|
||||
/* Public data -- the event filter */
|
||||
SDL_EventFilter SDL_EventOK = NULL;
|
||||
void *SDL_EventOKParam;
|
||||
|
||||
typedef struct SDL_EventWatcher {
|
||||
SDL_EventFilter callback;
|
||||
void *userdata;
|
||||
struct SDL_EventWatcher *next;
|
||||
} SDL_EventWatcher;
|
||||
|
||||
static SDL_EventWatcher *SDL_event_watchers = NULL;
|
||||
|
||||
typedef struct {
|
||||
Uint32 bits[8];
|
||||
} SDL_DisabledEventBlock;
|
||||
|
||||
static SDL_DisabledEventBlock *SDL_disabled_events[256];
|
||||
static Uint32 SDL_userevents = SDL_USEREVENT;
|
||||
|
||||
/* Private data -- event queue */
|
||||
typedef struct _SDL_EventEntry
|
||||
{
|
||||
SDL_Event event;
|
||||
SDL_SysWMmsg msg;
|
||||
struct _SDL_EventEntry *prev;
|
||||
struct _SDL_EventEntry *next;
|
||||
} SDL_EventEntry;
|
||||
|
||||
typedef struct _SDL_SysWMEntry
|
||||
{
|
||||
SDL_SysWMmsg msg;
|
||||
struct _SDL_SysWMEntry *next;
|
||||
} SDL_SysWMEntry;
|
||||
|
||||
static struct
|
||||
{
|
||||
SDL_mutex *lock;
|
||||
volatile SDL_bool active;
|
||||
volatile int count;
|
||||
SDL_EventEntry *head;
|
||||
SDL_EventEntry *tail;
|
||||
SDL_EventEntry *free;
|
||||
SDL_SysWMEntry *wmmsg_used;
|
||||
SDL_SysWMEntry *wmmsg_free;
|
||||
} SDL_EventQ = { NULL, SDL_TRUE };
|
||||
|
||||
|
||||
static __inline__ SDL_bool
|
||||
SDL_ShouldPollJoystick()
|
||||
{
|
||||
#if !SDL_JOYSTICK_DISABLED
|
||||
if ((!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] ||
|
||||
SDL_JoystickEventState(SDL_QUERY)) &&
|
||||
SDL_PrivateJoystickNeedsPolling()) {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
#endif
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
/* Public functions */
|
||||
|
||||
void
|
||||
SDL_StopEventLoop(void)
|
||||
{
|
||||
int i;
|
||||
SDL_EventEntry *entry;
|
||||
SDL_SysWMEntry *wmmsg;
|
||||
|
||||
if (SDL_EventQ.lock) {
|
||||
SDL_LockMutex(SDL_EventQ.lock);
|
||||
}
|
||||
|
||||
SDL_EventQ.active = SDL_FALSE;
|
||||
|
||||
/* Clean out EventQ */
|
||||
for (entry = SDL_EventQ.head; entry; ) {
|
||||
SDL_EventEntry *next = entry->next;
|
||||
SDL_free(entry);
|
||||
entry = next;
|
||||
}
|
||||
for (entry = SDL_EventQ.free; entry; ) {
|
||||
SDL_EventEntry *next = entry->next;
|
||||
SDL_free(entry);
|
||||
entry = next;
|
||||
}
|
||||
for (wmmsg = SDL_EventQ.wmmsg_used; wmmsg; ) {
|
||||
SDL_SysWMEntry *next = wmmsg->next;
|
||||
SDL_free(wmmsg);
|
||||
wmmsg = next;
|
||||
}
|
||||
for (wmmsg = SDL_EventQ.wmmsg_free; wmmsg; ) {
|
||||
SDL_SysWMEntry *next = wmmsg->next;
|
||||
SDL_free(wmmsg);
|
||||
wmmsg = next;
|
||||
}
|
||||
SDL_EventQ.count = 0;
|
||||
SDL_EventQ.head = NULL;
|
||||
SDL_EventQ.tail = NULL;
|
||||
SDL_EventQ.free = NULL;
|
||||
SDL_EventQ.wmmsg_used = NULL;
|
||||
SDL_EventQ.wmmsg_free = NULL;
|
||||
|
||||
/* Clear disabled event state */
|
||||
for (i = 0; i < SDL_arraysize(SDL_disabled_events); ++i) {
|
||||
if (SDL_disabled_events[i]) {
|
||||
SDL_free(SDL_disabled_events[i]);
|
||||
SDL_disabled_events[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
while (SDL_event_watchers) {
|
||||
SDL_EventWatcher *tmp = SDL_event_watchers;
|
||||
SDL_event_watchers = tmp->next;
|
||||
SDL_free(tmp);
|
||||
}
|
||||
SDL_EventOK = NULL;
|
||||
|
||||
if (SDL_EventQ.lock) {
|
||||
SDL_UnlockMutex(SDL_EventQ.lock);
|
||||
SDL_DestroyMutex(SDL_EventQ.lock);
|
||||
SDL_EventQ.lock = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* This function (and associated calls) may be called more than once */
|
||||
int
|
||||
SDL_StartEventLoop(void)
|
||||
{
|
||||
/* We'll leave the event queue alone, since we might have gotten
|
||||
some important events at launch (like SDL_DROPFILE)
|
||||
|
||||
FIXME: Does this introduce any other bugs with events at startup?
|
||||
*/
|
||||
|
||||
/* Create the lock and set ourselves active */
|
||||
#if !SDL_THREADS_DISABLED
|
||||
if (!SDL_EventQ.lock) {
|
||||
SDL_EventQ.lock = SDL_CreateMutex();
|
||||
}
|
||||
if (SDL_EventQ.lock == NULL) {
|
||||
return (-1);
|
||||
}
|
||||
#endif /* !SDL_THREADS_DISABLED */
|
||||
|
||||
/* Process most event types */
|
||||
SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE);
|
||||
SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE);
|
||||
SDL_EventState(SDL_SYSWMEVENT, SDL_DISABLE);
|
||||
|
||||
SDL_EventQ.active = SDL_TRUE;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/* Add an event to the event queue -- called with the queue locked */
|
||||
static int
|
||||
SDL_AddEvent(SDL_Event * event)
|
||||
{
|
||||
SDL_EventEntry *entry;
|
||||
|
||||
if (SDL_EventQ.count >= SDL_MAX_QUEUED_EVENTS) {
|
||||
SDL_SetError("Event queue is full (%d events)", SDL_EventQ.count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (SDL_EventQ.free == NULL) {
|
||||
entry = (SDL_EventEntry *)SDL_malloc(sizeof(*entry));
|
||||
if (!entry) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
entry = SDL_EventQ.free;
|
||||
SDL_EventQ.free = entry->next;
|
||||
}
|
||||
|
||||
entry->event = *event;
|
||||
if (event->type == SDL_SYSWMEVENT) {
|
||||
entry->msg = *event->syswm.msg;
|
||||
entry->event.syswm.msg = &entry->msg;
|
||||
}
|
||||
|
||||
if (SDL_EventQ.tail) {
|
||||
SDL_EventQ.tail->next = entry;
|
||||
entry->prev = SDL_EventQ.tail;
|
||||
SDL_EventQ.tail = entry;
|
||||
entry->next = NULL;
|
||||
} else {
|
||||
SDL_assert(!SDL_EventQ.head);
|
||||
SDL_EventQ.head = entry;
|
||||
SDL_EventQ.tail = entry;
|
||||
entry->prev = NULL;
|
||||
entry->next = NULL;
|
||||
}
|
||||
++SDL_EventQ.count;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Remove an event from the queue -- called with the queue locked */
|
||||
static void
|
||||
SDL_CutEvent(SDL_EventEntry *entry)
|
||||
{
|
||||
if (entry->prev) {
|
||||
entry->prev->next = entry->next;
|
||||
}
|
||||
if (entry->next) {
|
||||
entry->next->prev = entry->prev;
|
||||
}
|
||||
|
||||
if (entry == SDL_EventQ.head) {
|
||||
SDL_assert(entry->prev == NULL);
|
||||
SDL_EventQ.head = entry->next;
|
||||
}
|
||||
if (entry == SDL_EventQ.tail) {
|
||||
SDL_assert(entry->next == NULL);
|
||||
SDL_EventQ.tail = entry->prev;
|
||||
}
|
||||
|
||||
entry->next = SDL_EventQ.free;
|
||||
SDL_EventQ.free = entry;
|
||||
SDL_assert(SDL_EventQ.count > 0);
|
||||
--SDL_EventQ.count;
|
||||
}
|
||||
|
||||
/* Lock the event queue, take a peep at it, and unlock it */
|
||||
int
|
||||
SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
|
||||
Uint32 minType, Uint32 maxType)
|
||||
{
|
||||
int i, used;
|
||||
|
||||
/* Don't look after we've quit */
|
||||
if (!SDL_EventQ.active) {
|
||||
/* We get a few spurious events at shutdown, so don't warn then */
|
||||
if (action != SDL_ADDEVENT) {
|
||||
SDL_SetError("The event system has been shut down");
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
/* Lock the event queue */
|
||||
used = 0;
|
||||
if (!SDL_EventQ.lock || SDL_LockMutex(SDL_EventQ.lock) == 0) {
|
||||
if (action == SDL_ADDEVENT) {
|
||||
for (i = 0; i < numevents; ++i) {
|
||||
used += SDL_AddEvent(&events[i]);
|
||||
}
|
||||
} else {
|
||||
SDL_EventEntry *entry, *next;
|
||||
SDL_SysWMEntry *wmmsg, *wmmsg_next;
|
||||
SDL_Event tmpevent;
|
||||
Uint32 type;
|
||||
|
||||
/* If 'events' is NULL, just see if they exist */
|
||||
if (events == NULL) {
|
||||
action = SDL_PEEKEVENT;
|
||||
numevents = 1;
|
||||
events = &tmpevent;
|
||||
}
|
||||
|
||||
/* Clean out any used wmmsg data
|
||||
FIXME: Do we want to retain the data for some period of time?
|
||||
*/
|
||||
for (wmmsg = SDL_EventQ.wmmsg_used; wmmsg; wmmsg = wmmsg_next) {
|
||||
wmmsg_next = wmmsg->next;
|
||||
wmmsg->next = SDL_EventQ.wmmsg_free;
|
||||
SDL_EventQ.wmmsg_free = wmmsg;
|
||||
}
|
||||
SDL_EventQ.wmmsg_used = NULL;
|
||||
|
||||
for (entry = SDL_EventQ.head; entry && used < numevents; entry = next) {
|
||||
next = entry->next;
|
||||
type = entry->event.type;
|
||||
if (minType <= type && type <= maxType) {
|
||||
events[used] = entry->event;
|
||||
if (entry->event.type == SDL_SYSWMEVENT) {
|
||||
/* We need to copy the wmmsg somewhere safe.
|
||||
For now we'll guarantee it's valid at least until
|
||||
the next call to SDL_PeepEvents()
|
||||
*/
|
||||
SDL_SysWMEntry *wmmsg;
|
||||
if (SDL_EventQ.wmmsg_free) {
|
||||
wmmsg = SDL_EventQ.wmmsg_free;
|
||||
SDL_EventQ.wmmsg_free = wmmsg->next;
|
||||
} else {
|
||||
wmmsg = (SDL_SysWMEntry *)SDL_malloc(sizeof(*wmmsg));
|
||||
}
|
||||
wmmsg->msg = *entry->event.syswm.msg;
|
||||
wmmsg->next = SDL_EventQ.wmmsg_used;
|
||||
SDL_EventQ.wmmsg_used = wmmsg;
|
||||
events[used].syswm.msg = &wmmsg->msg;
|
||||
}
|
||||
++used;
|
||||
|
||||
if (action == SDL_GETEVENT) {
|
||||
SDL_CutEvent(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_UnlockMutex(SDL_EventQ.lock);
|
||||
} else {
|
||||
return SDL_SetError("Couldn't lock event queue");
|
||||
}
|
||||
return (used);
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
SDL_HasEvent(Uint32 type)
|
||||
{
|
||||
return (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, type, type) > 0);
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
SDL_HasEvents(Uint32 minType, Uint32 maxType)
|
||||
{
|
||||
return (SDL_PeepEvents(NULL, 0, SDL_PEEKEVENT, minType, maxType) > 0);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_FlushEvent(Uint32 type)
|
||||
{
|
||||
SDL_FlushEvents(type, type);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_FlushEvents(Uint32 minType, Uint32 maxType)
|
||||
{
|
||||
/* Don't look after we've quit */
|
||||
if (!SDL_EventQ.active) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Make sure the events are current */
|
||||
#if 0
|
||||
/* Actually, we can't do this since we might be flushing while processing
|
||||
a resize event, and calling this might trigger further resize events.
|
||||
*/
|
||||
SDL_PumpEvents();
|
||||
#endif
|
||||
|
||||
/* Lock the event queue */
|
||||
if (SDL_LockMutex(SDL_EventQ.lock) == 0) {
|
||||
SDL_EventEntry *entry, *next;
|
||||
Uint32 type;
|
||||
for (entry = SDL_EventQ.head; entry; entry = next) {
|
||||
next = entry->next;
|
||||
type = entry->event.type;
|
||||
if (minType <= type && type <= maxType) {
|
||||
SDL_CutEvent(entry);
|
||||
}
|
||||
}
|
||||
SDL_UnlockMutex(SDL_EventQ.lock);
|
||||
}
|
||||
}
|
||||
|
||||
/* Run the system dependent event loops */
|
||||
void
|
||||
SDL_PumpEvents(void)
|
||||
{
|
||||
SDL_VideoDevice *_this = SDL_GetVideoDevice();
|
||||
|
||||
/* Get events from the video subsystem */
|
||||
if (_this) {
|
||||
_this->PumpEvents(_this);
|
||||
}
|
||||
#if !SDL_JOYSTICK_DISABLED
|
||||
/* Check for joystick state change */
|
||||
if (SDL_ShouldPollJoystick()) {
|
||||
SDL_JoystickUpdate();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Public functions */
|
||||
|
||||
int
|
||||
SDL_PollEvent(SDL_Event * event)
|
||||
{
|
||||
return SDL_WaitEventTimeout(event, 0);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_WaitEvent(SDL_Event * event)
|
||||
{
|
||||
return SDL_WaitEventTimeout(event, -1);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_WaitEventTimeout(SDL_Event * event, int timeout)
|
||||
{
|
||||
Uint32 expiration = 0;
|
||||
|
||||
if (timeout > 0)
|
||||
expiration = SDL_GetTicks() + timeout;
|
||||
|
||||
for (;;) {
|
||||
SDL_PumpEvents();
|
||||
switch (SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT)) {
|
||||
case -1:
|
||||
return 0;
|
||||
case 1:
|
||||
return 1;
|
||||
case 0:
|
||||
if (timeout == 0) {
|
||||
/* Polling and no events, just return */
|
||||
return 0;
|
||||
}
|
||||
if (timeout > 0 && ((int) (SDL_GetTicks() - expiration) >= 0)) {
|
||||
/* Timeout expired and no events */
|
||||
return 0;
|
||||
}
|
||||
SDL_Delay(10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_PushEvent(SDL_Event * event)
|
||||
{
|
||||
SDL_EventWatcher *curr;
|
||||
|
||||
event->common.timestamp = SDL_GetTicks();
|
||||
|
||||
if (SDL_EventOK && !SDL_EventOK(SDL_EventOKParam, event)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (curr = SDL_event_watchers; curr; curr = curr->next) {
|
||||
curr->callback(curr->userdata, event);
|
||||
}
|
||||
|
||||
if (SDL_PeepEvents(event, 1, SDL_ADDEVENT, 0, 0) <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_GestureProcessEvent(event);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SetEventFilter(SDL_EventFilter filter, void *userdata)
|
||||
{
|
||||
/* Set filter and discard pending events */
|
||||
SDL_EventOK = NULL;
|
||||
SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
|
||||
SDL_EventOKParam = userdata;
|
||||
SDL_EventOK = filter;
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
SDL_GetEventFilter(SDL_EventFilter * filter, void **userdata)
|
||||
{
|
||||
if (filter) {
|
||||
*filter = SDL_EventOK;
|
||||
}
|
||||
if (userdata) {
|
||||
*userdata = SDL_EventOKParam;
|
||||
}
|
||||
return SDL_EventOK ? SDL_TRUE : SDL_FALSE;
|
||||
}
|
||||
|
||||
/* FIXME: This is not thread-safe yet */
|
||||
void
|
||||
SDL_AddEventWatch(SDL_EventFilter filter, void *userdata)
|
||||
{
|
||||
SDL_EventWatcher *watcher;
|
||||
|
||||
watcher = (SDL_EventWatcher *)SDL_malloc(sizeof(*watcher));
|
||||
if (!watcher) {
|
||||
/* Uh oh... */
|
||||
return;
|
||||
}
|
||||
watcher->callback = filter;
|
||||
watcher->userdata = userdata;
|
||||
watcher->next = SDL_event_watchers;
|
||||
SDL_event_watchers = watcher;
|
||||
}
|
||||
|
||||
/* FIXME: This is not thread-safe yet */
|
||||
void
|
||||
SDL_DelEventWatch(SDL_EventFilter filter, void *userdata)
|
||||
{
|
||||
SDL_EventWatcher *prev = NULL;
|
||||
SDL_EventWatcher *curr;
|
||||
|
||||
for (curr = SDL_event_watchers; curr; prev = curr, curr = curr->next) {
|
||||
if (curr->callback == filter && curr->userdata == userdata) {
|
||||
if (prev) {
|
||||
prev->next = curr->next;
|
||||
} else {
|
||||
SDL_event_watchers = curr->next;
|
||||
}
|
||||
SDL_free(curr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
|
||||
{
|
||||
if (SDL_LockMutex(SDL_EventQ.lock) == 0) {
|
||||
SDL_EventEntry *entry, *next;
|
||||
for (entry = SDL_EventQ.head; entry; entry = next) {
|
||||
next = entry->next;
|
||||
if (!filter(userdata, &entry->event)) {
|
||||
SDL_CutEvent(entry);
|
||||
}
|
||||
}
|
||||
SDL_UnlockMutex(SDL_EventQ.lock);
|
||||
}
|
||||
}
|
||||
|
||||
Uint8
|
||||
SDL_EventState(Uint32 type, int state)
|
||||
{
|
||||
Uint8 current_state;
|
||||
Uint8 hi = ((type >> 8) & 0xff);
|
||||
Uint8 lo = (type & 0xff);
|
||||
|
||||
if (SDL_disabled_events[hi] &&
|
||||
(SDL_disabled_events[hi]->bits[lo/32] & (1 << (lo&31)))) {
|
||||
current_state = SDL_DISABLE;
|
||||
} else {
|
||||
current_state = SDL_ENABLE;
|
||||
}
|
||||
|
||||
if (state != current_state)
|
||||
{
|
||||
switch (state) {
|
||||
case SDL_DISABLE:
|
||||
/* Disable this event type and discard pending events */
|
||||
if (!SDL_disabled_events[hi]) {
|
||||
SDL_disabled_events[hi] = (SDL_DisabledEventBlock*) SDL_calloc(1, sizeof(SDL_DisabledEventBlock));
|
||||
if (!SDL_disabled_events[hi]) {
|
||||
/* Out of memory, nothing we can do... */
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDL_disabled_events[hi]->bits[lo/32] |= (1 << (lo&31));
|
||||
SDL_FlushEvent(type);
|
||||
break;
|
||||
case SDL_ENABLE:
|
||||
SDL_disabled_events[hi]->bits[lo/32] &= ~(1 << (lo&31));
|
||||
break;
|
||||
default:
|
||||
/* Querying state... */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return current_state;
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_RegisterEvents(int numevents)
|
||||
{
|
||||
Uint32 event_base;
|
||||
|
||||
if ((numevents > 0) && (SDL_userevents+numevents <= SDL_LASTEVENT)) {
|
||||
event_base = SDL_userevents;
|
||||
SDL_userevents += numevents;
|
||||
} else {
|
||||
event_base = (Uint32)-1;
|
||||
}
|
||||
return event_base;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SendAppEvent(SDL_EventType eventType)
|
||||
{
|
||||
int posted;
|
||||
|
||||
posted = 0;
|
||||
if (SDL_GetEventState(eventType) == SDL_ENABLE) {
|
||||
SDL_Event event;
|
||||
event.type = eventType;
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
}
|
||||
return (posted);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SendSysWMEvent(SDL_SysWMmsg * message)
|
||||
{
|
||||
int posted;
|
||||
|
||||
posted = 0;
|
||||
if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
|
||||
SDL_Event event;
|
||||
SDL_memset(&event, 0, sizeof(event));
|
||||
event.type = SDL_SYSWMEVENT;
|
||||
event.syswm.msg = message;
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
}
|
||||
/* Update internal event state */
|
||||
return (posted);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
50
src/events/SDL_events_c.h
Normal file
50
src/events/SDL_events_c.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
/* Useful functions and variables from SDL_events.c */
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_clipboardevents_c.h"
|
||||
#include "SDL_dropevents_c.h"
|
||||
#include "SDL_gesture_c.h"
|
||||
#include "SDL_keyboard_c.h"
|
||||
#include "SDL_mouse_c.h"
|
||||
#include "SDL_touch_c.h"
|
||||
#include "SDL_windowevents_c.h"
|
||||
|
||||
/* Start and stop the event processing loop */
|
||||
extern int SDL_StartEventLoop(void);
|
||||
extern void SDL_StopEventLoop(void);
|
||||
extern void SDL_QuitInterrupt(void);
|
||||
|
||||
extern int SDL_SendAppEvent(SDL_EventType eventType);
|
||||
extern int SDL_SendSysWMEvent(SDL_SysWMmsg * message);
|
||||
|
||||
extern int SDL_QuitInit(void);
|
||||
extern int SDL_SendQuit(void);
|
||||
extern void SDL_QuitQuit(void);
|
||||
|
||||
/* The event filter function */
|
||||
extern SDL_EventFilter SDL_EventOK;
|
||||
extern void *SDL_EventOKParam;
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
646
src/events/SDL_gesture.c
Normal file
646
src/events/SDL_gesture.c
Normal file
@@ -0,0 +1,646 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
/* General mouse handling code for SDL */
|
||||
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_events_c.h"
|
||||
#include "SDL_gesture_c.h"
|
||||
|
||||
#if !defined(__PSP__)
|
||||
#include <memory.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
/* TODO: Replace with malloc */
|
||||
|
||||
#define MAXPATHSIZE 1024
|
||||
|
||||
#define DOLLARNPOINTS 64
|
||||
#define DOLLARSIZE 256
|
||||
|
||||
#define ENABLE_DOLLAR
|
||||
|
||||
#define PHI 0.618033989
|
||||
|
||||
typedef struct {
|
||||
float x,y;
|
||||
} SDL_FloatPoint;
|
||||
|
||||
typedef struct {
|
||||
float length;
|
||||
|
||||
int numPoints;
|
||||
SDL_FloatPoint p[MAXPATHSIZE];
|
||||
} SDL_DollarPath;
|
||||
|
||||
typedef struct {
|
||||
SDL_FloatPoint path[DOLLARNPOINTS];
|
||||
unsigned long hash;
|
||||
} SDL_DollarTemplate;
|
||||
|
||||
typedef struct {
|
||||
SDL_TouchID id;
|
||||
SDL_FloatPoint centroid;
|
||||
SDL_DollarPath dollarPath;
|
||||
Uint16 numDownFingers;
|
||||
|
||||
int numDollarTemplates;
|
||||
SDL_DollarTemplate *dollarTemplate;
|
||||
|
||||
SDL_bool recording;
|
||||
} SDL_GestureTouch;
|
||||
|
||||
SDL_GestureTouch *SDL_gestureTouch;
|
||||
int SDL_numGestureTouches = 0;
|
||||
SDL_bool recordAll;
|
||||
|
||||
#if 0
|
||||
static void PrintPath(SDL_FloatPoint *path)
|
||||
{
|
||||
int i;
|
||||
printf("Path:");
|
||||
for (i=0; i<DOLLARNPOINTS; i++) {
|
||||
printf(" (%f,%f)",path[i].x,path[i].y);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
int SDL_RecordGesture(SDL_TouchID touchId)
|
||||
{
|
||||
int i;
|
||||
if (touchId < 0) recordAll = SDL_TRUE;
|
||||
for (i = 0; i < SDL_numGestureTouches; i++) {
|
||||
if ((touchId < 0) || (SDL_gestureTouch[i].id == touchId)) {
|
||||
SDL_gestureTouch[i].recording = SDL_TRUE;
|
||||
if (touchId >= 0)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return (touchId < 0);
|
||||
}
|
||||
|
||||
static unsigned long SDL_HashDollar(SDL_FloatPoint* points)
|
||||
{
|
||||
unsigned long hash = 5381;
|
||||
int i;
|
||||
for (i = 0; i < DOLLARNPOINTS; i++) {
|
||||
hash = ((hash<<5) + hash) + (unsigned long)points[i].x;
|
||||
hash = ((hash<<5) + hash) + (unsigned long)points[i].y;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
static int SaveTemplate(SDL_DollarTemplate *templ, SDL_RWops * src)
|
||||
{
|
||||
if (src == NULL) return 0;
|
||||
|
||||
|
||||
//No Longer storing the Hash, rehash on load
|
||||
//if(SDL_RWops.write(src,&(templ->hash),sizeof(templ->hash),1) != 1) return 0;
|
||||
|
||||
if (SDL_RWwrite(src,templ->path,
|
||||
sizeof(templ->path[0]),DOLLARNPOINTS) != DOLLARNPOINTS)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int SDL_SaveAllDollarTemplates(SDL_RWops *src)
|
||||
{
|
||||
int i,j,rtrn = 0;
|
||||
for (i = 0; i < SDL_numGestureTouches; i++) {
|
||||
SDL_GestureTouch* touch = &SDL_gestureTouch[i];
|
||||
for (j = 0; j < touch->numDollarTemplates; j++) {
|
||||
rtrn += SaveTemplate(&touch->dollarTemplate[i],src);
|
||||
}
|
||||
}
|
||||
return rtrn;
|
||||
}
|
||||
|
||||
int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *src)
|
||||
{
|
||||
int i,j;
|
||||
for (i = 0; i < SDL_numGestureTouches; i++) {
|
||||
SDL_GestureTouch* touch = &SDL_gestureTouch[i];
|
||||
for (j = 0; j < touch->numDollarTemplates; j++) {
|
||||
if (touch->dollarTemplate[i].hash == gestureId) {
|
||||
return SaveTemplate(&touch->dollarTemplate[i],src);
|
||||
}
|
||||
}
|
||||
}
|
||||
return SDL_SetError("Unknown gestureId");
|
||||
}
|
||||
|
||||
//path is an already sampled set of points
|
||||
//Returns the index of the gesture on success, or -1
|
||||
static int SDL_AddDollarGesture_one(SDL_GestureTouch* inTouch, SDL_FloatPoint* path)
|
||||
{
|
||||
SDL_DollarTemplate* dollarTemplate;
|
||||
SDL_DollarTemplate *templ;
|
||||
int index;
|
||||
|
||||
index = inTouch->numDollarTemplates;
|
||||
dollarTemplate =
|
||||
(SDL_DollarTemplate *)SDL_realloc(inTouch->dollarTemplate,
|
||||
(index + 1) *
|
||||
sizeof(SDL_DollarTemplate));
|
||||
if (!dollarTemplate) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
inTouch->dollarTemplate = dollarTemplate;
|
||||
|
||||
templ = &inTouch->dollarTemplate[index];
|
||||
SDL_memcpy(templ->path, path, DOLLARNPOINTS*sizeof(SDL_FloatPoint));
|
||||
templ->hash = SDL_HashDollar(templ->path);
|
||||
inTouch->numDollarTemplates++;
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
static int SDL_AddDollarGesture(SDL_GestureTouch* inTouch, SDL_FloatPoint* path)
|
||||
{
|
||||
int index = -1;
|
||||
int i = 0;
|
||||
if (inTouch == NULL) {
|
||||
if (SDL_numGestureTouches == 0) return -1;
|
||||
for (i = 0; i < SDL_numGestureTouches; i++) {
|
||||
inTouch = &SDL_gestureTouch[i];
|
||||
index = SDL_AddDollarGesture_one(inTouch, path);
|
||||
if (index < 0)
|
||||
return -1;
|
||||
}
|
||||
// Use the index of the last one added.
|
||||
return index;
|
||||
} else {
|
||||
return SDL_AddDollarGesture_one(inTouch, path);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL_RWops *src)
|
||||
{
|
||||
int i,loaded = 0;
|
||||
SDL_GestureTouch *touch = NULL;
|
||||
if (src == NULL) return 0;
|
||||
if (touchId >= 0) {
|
||||
for (i = 0; i < SDL_numGestureTouches; i++)
|
||||
if (SDL_gestureTouch[i].id == touchId)
|
||||
touch = &SDL_gestureTouch[i];
|
||||
if (touch == NULL) return -1;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
SDL_DollarTemplate templ;
|
||||
|
||||
if (SDL_RWread(src,templ.path,sizeof(templ.path[0]),DOLLARNPOINTS) <
|
||||
DOLLARNPOINTS) break;
|
||||
|
||||
if (touchId >= 0) {
|
||||
//printf("Adding loaded gesture to 1 touch\n");
|
||||
if (SDL_AddDollarGesture(touch, templ.path) >= 0)
|
||||
loaded++;
|
||||
}
|
||||
else {
|
||||
//printf("Adding to: %i touches\n",SDL_numGestureTouches);
|
||||
for (i = 0; i < SDL_numGestureTouches; i++) {
|
||||
touch = &SDL_gestureTouch[i];
|
||||
//printf("Adding loaded gesture to + touches\n");
|
||||
//TODO: What if this fails?
|
||||
SDL_AddDollarGesture(touch,templ.path);
|
||||
}
|
||||
loaded++;
|
||||
}
|
||||
}
|
||||
|
||||
return loaded;
|
||||
}
|
||||
|
||||
|
||||
static float dollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ,float ang)
|
||||
{
|
||||
// SDL_FloatPoint p[DOLLARNPOINTS];
|
||||
float dist = 0;
|
||||
SDL_FloatPoint p;
|
||||
int i;
|
||||
for (i = 0; i < DOLLARNPOINTS; i++) {
|
||||
p.x = (float)(points[i].x * SDL_cos(ang) - points[i].y * SDL_sin(ang));
|
||||
p.y = (float)(points[i].x * SDL_sin(ang) + points[i].y * SDL_cos(ang));
|
||||
dist += (float)(SDL_sqrt((p.x-templ[i].x)*(p.x-templ[i].x)+
|
||||
(p.y-templ[i].y)*(p.y-templ[i].y)));
|
||||
}
|
||||
return dist/DOLLARNPOINTS;
|
||||
|
||||
}
|
||||
|
||||
static float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ)
|
||||
{
|
||||
//------------BEGIN DOLLAR BLACKBOX----------------//
|
||||
//-TRANSLATED DIRECTLY FROM PSUDEO-CODE AVAILABLE AT-//
|
||||
//-"http://depts.washington.edu/aimgroup/proj/dollar/"-//
|
||||
double ta = -M_PI/4;
|
||||
double tb = M_PI/4;
|
||||
double dt = M_PI/90;
|
||||
float x1 = (float)(PHI*ta + (1-PHI)*tb);
|
||||
float f1 = dollarDifference(points,templ,x1);
|
||||
float x2 = (float)((1-PHI)*ta + PHI*tb);
|
||||
float f2 = dollarDifference(points,templ,x2);
|
||||
while (SDL_fabs(ta-tb) > dt) {
|
||||
if (f1 < f2) {
|
||||
tb = x2;
|
||||
x2 = x1;
|
||||
f2 = f1;
|
||||
x1 = (float)(PHI*ta + (1-PHI)*tb);
|
||||
f1 = dollarDifference(points,templ,x1);
|
||||
}
|
||||
else {
|
||||
ta = x1;
|
||||
x1 = x2;
|
||||
f1 = f2;
|
||||
x2 = (float)((1-PHI)*ta + PHI*tb);
|
||||
f2 = dollarDifference(points,templ,x2);
|
||||
}
|
||||
}
|
||||
/*
|
||||
if (f1 <= f2)
|
||||
printf("Min angle (x1): %f\n",x1);
|
||||
else if (f1 > f2)
|
||||
printf("Min angle (x2): %f\n",x2);
|
||||
*/
|
||||
return SDL_min(f1,f2);
|
||||
}
|
||||
|
||||
//DollarPath contains raw points, plus (possibly) the calculated length
|
||||
static int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points)
|
||||
{
|
||||
int i;
|
||||
float interval;
|
||||
float dist;
|
||||
int numPoints = 0;
|
||||
SDL_FloatPoint centroid;
|
||||
float xmin,xmax,ymin,ymax;
|
||||
float ang;
|
||||
float w,h;
|
||||
float length = path->length;
|
||||
|
||||
//Calculate length if it hasn't already been done
|
||||
if (length <= 0) {
|
||||
for (i=1;i < path->numPoints; i++) {
|
||||
float dx = path->p[i ].x - path->p[i-1].x;
|
||||
float dy = path->p[i ].y - path->p[i-1].y;
|
||||
length += (float)(SDL_sqrt(dx*dx+dy*dy));
|
||||
}
|
||||
}
|
||||
|
||||
//Resample
|
||||
interval = length/(DOLLARNPOINTS - 1);
|
||||
dist = interval;
|
||||
|
||||
centroid.x = 0;centroid.y = 0;
|
||||
|
||||
//printf("(%f,%f)\n",path->p[path->numPoints-1].x,path->p[path->numPoints-1].y);
|
||||
for (i = 1; i < path->numPoints; i++) {
|
||||
float d = (float)(SDL_sqrt((path->p[i-1].x-path->p[i].x)*(path->p[i-1].x-path->p[i].x)+
|
||||
(path->p[i-1].y-path->p[i].y)*(path->p[i-1].y-path->p[i].y)));
|
||||
//printf("d = %f dist = %f/%f\n",d,dist,interval);
|
||||
while (dist + d > interval) {
|
||||
points[numPoints].x = path->p[i-1].x +
|
||||
((interval-dist)/d)*(path->p[i].x-path->p[i-1].x);
|
||||
points[numPoints].y = path->p[i-1].y +
|
||||
((interval-dist)/d)*(path->p[i].y-path->p[i-1].y);
|
||||
centroid.x += points[numPoints].x;
|
||||
centroid.y += points[numPoints].y;
|
||||
numPoints++;
|
||||
|
||||
dist -= interval;
|
||||
}
|
||||
dist += d;
|
||||
}
|
||||
if (numPoints < DOLLARNPOINTS-1) {
|
||||
SDL_SetError("ERROR: NumPoints = %i\n",numPoints);
|
||||
return 0;
|
||||
}
|
||||
//copy the last point
|
||||
points[DOLLARNPOINTS-1] = path->p[path->numPoints-1];
|
||||
numPoints = DOLLARNPOINTS;
|
||||
|
||||
centroid.x /= numPoints;
|
||||
centroid.y /= numPoints;
|
||||
|
||||
//printf("Centroid (%f,%f)",centroid.x,centroid.y);
|
||||
//Rotate Points so point 0 is left of centroid and solve for the bounding box
|
||||
xmin = centroid.x;
|
||||
xmax = centroid.x;
|
||||
ymin = centroid.y;
|
||||
ymax = centroid.y;
|
||||
|
||||
ang = (float)(SDL_atan2(centroid.y - points[0].y,
|
||||
centroid.x - points[0].x));
|
||||
|
||||
for (i = 0; i<numPoints; i++) {
|
||||
float px = points[i].x;
|
||||
float py = points[i].y;
|
||||
points[i].x = (float)((px - centroid.x)*SDL_cos(ang) -
|
||||
(py - centroid.y)*SDL_sin(ang) + centroid.x);
|
||||
points[i].y = (float)((px - centroid.x)*SDL_sin(ang) +
|
||||
(py - centroid.y)*SDL_cos(ang) + centroid.y);
|
||||
|
||||
|
||||
if (points[i].x < xmin) xmin = points[i].x;
|
||||
if (points[i].x > xmax) xmax = points[i].x;
|
||||
if (points[i].y < ymin) ymin = points[i].y;
|
||||
if (points[i].y > ymax) ymax = points[i].y;
|
||||
}
|
||||
|
||||
//Scale points to DOLLARSIZE, and translate to the origin
|
||||
w = xmax-xmin;
|
||||
h = ymax-ymin;
|
||||
|
||||
for (i=0; i<numPoints; i++) {
|
||||
points[i].x = (points[i].x - centroid.x)*DOLLARSIZE/w;
|
||||
points[i].y = (points[i].y - centroid.y)*DOLLARSIZE/h;
|
||||
}
|
||||
return numPoints;
|
||||
}
|
||||
|
||||
static float dollarRecognize(const SDL_DollarPath *path,int *bestTempl,SDL_GestureTouch* touch)
|
||||
{
|
||||
SDL_FloatPoint points[DOLLARNPOINTS];
|
||||
int i;
|
||||
float bestDiff = 10000;
|
||||
|
||||
SDL_memset(points, 0, sizeof(points));
|
||||
|
||||
dollarNormalize(path,points);
|
||||
|
||||
//PrintPath(points);
|
||||
*bestTempl = -1;
|
||||
for (i = 0; i < touch->numDollarTemplates; i++) {
|
||||
float diff = bestDollarDifference(points,touch->dollarTemplate[i].path);
|
||||
if (diff < bestDiff) {bestDiff = diff; *bestTempl = i;}
|
||||
}
|
||||
return bestDiff;
|
||||
}
|
||||
|
||||
int SDL_GestureAddTouch(SDL_TouchID touchId)
|
||||
{
|
||||
SDL_GestureTouch *gestureTouch = (SDL_GestureTouch *)SDL_realloc(SDL_gestureTouch,
|
||||
(SDL_numGestureTouches + 1) *
|
||||
sizeof(SDL_GestureTouch));
|
||||
|
||||
if (!gestureTouch) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
SDL_gestureTouch = gestureTouch;
|
||||
|
||||
SDL_gestureTouch[SDL_numGestureTouches].numDownFingers = 0;
|
||||
SDL_gestureTouch[SDL_numGestureTouches].id = touchId;
|
||||
|
||||
SDL_gestureTouch[SDL_numGestureTouches].numDollarTemplates = 0;
|
||||
|
||||
SDL_gestureTouch[SDL_numGestureTouches].recording = SDL_FALSE;
|
||||
|
||||
SDL_numGestureTouches++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SDL_GestureTouch * SDL_GetGestureTouch(SDL_TouchID id)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < SDL_numGestureTouches; i++) {
|
||||
//printf("%i ?= %i\n",SDL_gestureTouch[i].id,id);
|
||||
if (SDL_gestureTouch[i].id == id)
|
||||
return &SDL_gestureTouch[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int SDL_SendGestureMulti(SDL_GestureTouch* touch,float dTheta,float dDist)
|
||||
{
|
||||
SDL_Event event;
|
||||
event.mgesture.type = SDL_MULTIGESTURE;
|
||||
event.mgesture.touchId = touch->id;
|
||||
event.mgesture.x = touch->centroid.x;
|
||||
event.mgesture.y = touch->centroid.y;
|
||||
event.mgesture.dTheta = dTheta;
|
||||
event.mgesture.dDist = dDist;
|
||||
event.mgesture.numFingers = touch->numDownFingers;
|
||||
return SDL_PushEvent(&event) > 0;
|
||||
}
|
||||
|
||||
static int SDL_SendGestureDollar(SDL_GestureTouch* touch,
|
||||
SDL_GestureID gestureId,float error)
|
||||
{
|
||||
SDL_Event event;
|
||||
event.dgesture.type = SDL_DOLLARGESTURE;
|
||||
event.dgesture.touchId = touch->id;
|
||||
event.mgesture.x = touch->centroid.x;
|
||||
event.mgesture.y = touch->centroid.y;
|
||||
event.dgesture.gestureId = gestureId;
|
||||
event.dgesture.error = error;
|
||||
//A finger came up to trigger this event.
|
||||
event.dgesture.numFingers = touch->numDownFingers + 1;
|
||||
return SDL_PushEvent(&event) > 0;
|
||||
}
|
||||
|
||||
|
||||
static int SDL_SendDollarRecord(SDL_GestureTouch* touch,SDL_GestureID gestureId)
|
||||
{
|
||||
SDL_Event event;
|
||||
event.dgesture.type = SDL_DOLLARRECORD;
|
||||
event.dgesture.touchId = touch->id;
|
||||
event.dgesture.gestureId = gestureId;
|
||||
return SDL_PushEvent(&event) > 0;
|
||||
}
|
||||
|
||||
|
||||
void SDL_GestureProcessEvent(SDL_Event* event)
|
||||
{
|
||||
float x,y;
|
||||
SDL_FloatPoint path[DOLLARNPOINTS];
|
||||
int index;
|
||||
int i;
|
||||
float pathDx, pathDy;
|
||||
SDL_FloatPoint lastP;
|
||||
SDL_FloatPoint lastCentroid;
|
||||
float lDist;
|
||||
float Dist;
|
||||
float dtheta;
|
||||
float dDist;
|
||||
|
||||
if (event->type == SDL_FINGERMOTION ||
|
||||
event->type == SDL_FINGERDOWN ||
|
||||
event->type == SDL_FINGERUP) {
|
||||
SDL_GestureTouch* inTouch = SDL_GetGestureTouch(event->tfinger.touchId);
|
||||
|
||||
//Shouldn't be possible
|
||||
if (inTouch == NULL) return;
|
||||
|
||||
x = event->tfinger.x;
|
||||
y = event->tfinger.y;
|
||||
|
||||
//Finger Up
|
||||
if (event->type == SDL_FINGERUP) {
|
||||
inTouch->numDownFingers--;
|
||||
|
||||
#ifdef ENABLE_DOLLAR
|
||||
if (inTouch->recording) {
|
||||
inTouch->recording = SDL_FALSE;
|
||||
dollarNormalize(&inTouch->dollarPath,path);
|
||||
//PrintPath(path);
|
||||
if (recordAll) {
|
||||
index = SDL_AddDollarGesture(NULL,path);
|
||||
for (i = 0; i < SDL_numGestureTouches; i++)
|
||||
SDL_gestureTouch[i].recording = SDL_FALSE;
|
||||
}
|
||||
else {
|
||||
index = SDL_AddDollarGesture(inTouch,path);
|
||||
}
|
||||
|
||||
if (index >= 0) {
|
||||
SDL_SendDollarRecord(inTouch,inTouch->dollarTemplate[index].hash);
|
||||
}
|
||||
else {
|
||||
SDL_SendDollarRecord(inTouch,-1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
int bestTempl;
|
||||
float error;
|
||||
error = dollarRecognize(&inTouch->dollarPath,
|
||||
&bestTempl,inTouch);
|
||||
if (bestTempl >= 0){
|
||||
//Send Event
|
||||
unsigned long gestureId = inTouch->dollarTemplate[bestTempl].hash;
|
||||
SDL_SendGestureDollar(inTouch,gestureId,error);
|
||||
//printf ("%s\n",);("Dollar error: %f\n",error);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
//inTouch->gestureLast[j] = inTouch->gestureLast[inTouch->numDownFingers];
|
||||
if (inTouch->numDownFingers > 0) {
|
||||
inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers+1)-
|
||||
x)/inTouch->numDownFingers;
|
||||
inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers+1)-
|
||||
y)/inTouch->numDownFingers;
|
||||
}
|
||||
}
|
||||
else if (event->type == SDL_FINGERMOTION) {
|
||||
float dx = event->tfinger.dx;
|
||||
float dy = event->tfinger.dy;
|
||||
#ifdef ENABLE_DOLLAR
|
||||
SDL_DollarPath* path = &inTouch->dollarPath;
|
||||
if (path->numPoints < MAXPATHSIZE) {
|
||||
path->p[path->numPoints].x = inTouch->centroid.x;
|
||||
path->p[path->numPoints].y = inTouch->centroid.y;
|
||||
pathDx =
|
||||
(path->p[path->numPoints].x-path->p[path->numPoints-1].x);
|
||||
pathDy =
|
||||
(path->p[path->numPoints].y-path->p[path->numPoints-1].y);
|
||||
path->length += (float)SDL_sqrt(pathDx*pathDx + pathDy*pathDy);
|
||||
path->numPoints++;
|
||||
}
|
||||
#endif
|
||||
lastP.x = x - dx;
|
||||
lastP.y = y - dy;
|
||||
lastCentroid = inTouch->centroid;
|
||||
|
||||
inTouch->centroid.x += dx/inTouch->numDownFingers;
|
||||
inTouch->centroid.y += dy/inTouch->numDownFingers;
|
||||
//printf("Centrid : (%f,%f)\n",inTouch->centroid.x,inTouch->centroid.y);
|
||||
if (inTouch->numDownFingers > 1) {
|
||||
SDL_FloatPoint lv; //Vector from centroid to last x,y position
|
||||
SDL_FloatPoint v; //Vector from centroid to current x,y position
|
||||
//lv = inTouch->gestureLast[j].cv;
|
||||
lv.x = lastP.x - lastCentroid.x;
|
||||
lv.y = lastP.y - lastCentroid.y;
|
||||
lDist = (float)SDL_sqrt(lv.x*lv.x + lv.y*lv.y);
|
||||
//printf("lDist = %f\n",lDist);
|
||||
v.x = x - inTouch->centroid.x;
|
||||
v.y = y - inTouch->centroid.y;
|
||||
//inTouch->gestureLast[j].cv = v;
|
||||
Dist = (float)SDL_sqrt(v.x*v.x+v.y*v.y);
|
||||
// SDL_cos(dTheta) = (v . lv)/(|v| * |lv|)
|
||||
|
||||
//Normalize Vectors to simplify angle calculation
|
||||
lv.x/=lDist;
|
||||
lv.y/=lDist;
|
||||
v.x/=Dist;
|
||||
v.y/=Dist;
|
||||
dtheta = (float)SDL_atan2(lv.x*v.y - lv.y*v.x,lv.x*v.x + lv.y*v.y);
|
||||
|
||||
dDist = (Dist - lDist);
|
||||
if (lDist == 0) {dDist = 0;dtheta = 0;} //To avoid impossible values
|
||||
|
||||
//inTouch->gestureLast[j].dDist = dDist;
|
||||
//inTouch->gestureLast[j].dtheta = dtheta;
|
||||
|
||||
//printf("dDist = %f, dTheta = %f\n",dDist,dtheta);
|
||||
//gdtheta = gdtheta*.9 + dtheta*.1;
|
||||
//gdDist = gdDist*.9 + dDist*.1
|
||||
//knob.r += dDist/numDownFingers;
|
||||
//knob.ang += dtheta;
|
||||
//printf("thetaSum = %f, distSum = %f\n",gdtheta,gdDist);
|
||||
//printf("id: %i dTheta = %f, dDist = %f\n",j,dtheta,dDist);
|
||||
SDL_SendGestureMulti(inTouch,dtheta,dDist);
|
||||
}
|
||||
else {
|
||||
//inTouch->gestureLast[j].dDist = 0;
|
||||
//inTouch->gestureLast[j].dtheta = 0;
|
||||
//inTouch->gestureLast[j].cv.x = 0;
|
||||
//inTouch->gestureLast[j].cv.y = 0;
|
||||
}
|
||||
//inTouch->gestureLast[j].f.p.x = x;
|
||||
//inTouch->gestureLast[j].f.p.y = y;
|
||||
//break;
|
||||
//pressure?
|
||||
}
|
||||
|
||||
if (event->type == SDL_FINGERDOWN) {
|
||||
|
||||
inTouch->numDownFingers++;
|
||||
inTouch->centroid.x = (inTouch->centroid.x*(inTouch->numDownFingers - 1)+
|
||||
x)/inTouch->numDownFingers;
|
||||
inTouch->centroid.y = (inTouch->centroid.y*(inTouch->numDownFingers - 1)+
|
||||
y)/inTouch->numDownFingers;
|
||||
//printf("Finger Down: (%f,%f). Centroid: (%f,%f\n",x,y,
|
||||
// inTouch->centroid.x,inTouch->centroid.y);
|
||||
|
||||
#ifdef ENABLE_DOLLAR
|
||||
inTouch->dollarPath.length = 0;
|
||||
inTouch->dollarPath.p[0].x = x;
|
||||
inTouch->dollarPath.p[0].y = y;
|
||||
inTouch->dollarPath.numPoints = 1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
34
src/events/SDL_gesture_c.h
Normal file
34
src/events/SDL_gesture_c.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
#ifndef _SDL_gesture_c_h
|
||||
#define _SDL_gesture_c_h
|
||||
|
||||
extern int SDL_GestureAddTouch(SDL_TouchID touchId);
|
||||
|
||||
extern void SDL_GestureProcessEvent(SDL_Event* event);
|
||||
|
||||
extern int SDL_RecordGesture(SDL_TouchID touchId);
|
||||
|
||||
#endif /* _SDL_gesture_c_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
1013
src/events/SDL_keyboard.c
Normal file
1013
src/events/SDL_keyboard.c
Normal file
File diff suppressed because it is too large
Load Diff
64
src/events/SDL_keyboard_c.h
Normal file
64
src/events/SDL_keyboard_c.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
#ifndef _SDL_keyboard_c_h
|
||||
#define _SDL_keyboard_c_h
|
||||
|
||||
#include "SDL_keycode.h"
|
||||
#include "SDL_events.h"
|
||||
|
||||
/* Initialize the keyboard subsystem */
|
||||
extern int SDL_KeyboardInit(void);
|
||||
|
||||
/* Clear the state of the keyboard */
|
||||
extern void SDL_ResetKeyboard(void);
|
||||
|
||||
/* Get the default keymap */
|
||||
extern void SDL_GetDefaultKeymap(SDL_Keycode * keymap);
|
||||
|
||||
/* Set the mapping of scancode to key codes */
|
||||
extern void SDL_SetKeymap(int start, SDL_Keycode * keys, int length);
|
||||
|
||||
/* Set a platform-dependent key name, overriding the default platform-agnostic
|
||||
name. Encoded as UTF-8. The string is not copied, thus the pointer given to
|
||||
this function must stay valid forever (or at least until the call to
|
||||
VideoQuit()). */
|
||||
extern void SDL_SetScancodeName(SDL_Scancode scancode, const char *name);
|
||||
|
||||
/* Set the keyboard focus window */
|
||||
extern void SDL_SetKeyboardFocus(SDL_Window * window);
|
||||
|
||||
/* Send a keyboard key event */
|
||||
extern int SDL_SendKeyboardKey(Uint8 state, SDL_Scancode scancode);
|
||||
|
||||
/* Send keyboard text input */
|
||||
extern int SDL_SendKeyboardText(const char *text);
|
||||
|
||||
/* Send editing text for selected range from start to end */
|
||||
extern int SDL_SendEditingText(const char *text, int start, int end);
|
||||
|
||||
/* Shutdown the keyboard subsystem */
|
||||
extern void SDL_KeyboardQuit(void);
|
||||
|
||||
#endif /* _SDL_keyboard_c_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
725
src/events/SDL_mouse.c
Normal file
725
src/events/SDL_mouse.c
Normal file
@@ -0,0 +1,725 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
/* General mouse handling code for SDL */
|
||||
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_events_c.h"
|
||||
#include "default_cursor.h"
|
||||
#include "../video/SDL_sysvideo.h"
|
||||
|
||||
/*#define DEBUG_MOUSE*/
|
||||
|
||||
/* The mouse state */
|
||||
static SDL_Mouse SDL_mouse;
|
||||
|
||||
static int
|
||||
SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y);
|
||||
|
||||
/* Public functions */
|
||||
int
|
||||
SDL_MouseInit(void)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
mouse->cursor_shown = SDL_TRUE;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SetDefaultCursor(SDL_Cursor * cursor)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
mouse->def_cursor = cursor;
|
||||
if (!mouse->cur_cursor) {
|
||||
SDL_SetCursor(cursor);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Mouse *
|
||||
SDL_GetMouse(void)
|
||||
{
|
||||
return &SDL_mouse;
|
||||
}
|
||||
|
||||
SDL_Window *
|
||||
SDL_GetMouseFocus(void)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
return mouse->focus;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_ResetMouse(void)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
Uint8 i;
|
||||
|
||||
#ifdef DEBUG_MOUSE
|
||||
printf("Resetting mouse\n");
|
||||
#endif
|
||||
for (i = 1; i <= sizeof(mouse->buttonstate)*8; ++i) {
|
||||
if (mouse->buttonstate & SDL_BUTTON(i)) {
|
||||
SDL_SendMouseButton(mouse->focus, mouse->mouseID, SDL_RELEASED, i);
|
||||
}
|
||||
}
|
||||
SDL_assert(mouse->buttonstate == 0);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SetMouseFocus(SDL_Window * window)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
if (mouse->focus == window) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Actually, this ends up being a bad idea, because most operating
|
||||
systems have an implicit grab when you press the mouse button down
|
||||
so you can drag things out of the window and then get the mouse up
|
||||
when it happens. So, #if 0...
|
||||
*/
|
||||
#if 0
|
||||
if (mouse->focus && !window) {
|
||||
/* We won't get anymore mouse messages, so reset mouse state */
|
||||
SDL_ResetMouse();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* See if the current window has lost focus */
|
||||
if (mouse->focus) {
|
||||
SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_LEAVE, 0, 0);
|
||||
}
|
||||
|
||||
mouse->focus = window;
|
||||
|
||||
if (mouse->focus) {
|
||||
SDL_SendWindowEvent(mouse->focus, SDL_WINDOWEVENT_ENTER, 0, 0);
|
||||
}
|
||||
|
||||
/* Update cursor visibility */
|
||||
SDL_SetCursor(NULL);
|
||||
}
|
||||
|
||||
/* 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_Mouse *mouse = SDL_GetMouse();
|
||||
int w, h;
|
||||
SDL_bool inWindow;
|
||||
|
||||
SDL_GetWindowSize(window, &w, &h);
|
||||
if (x < 0 || y < 0 || x >= w || y >= h) {
|
||||
inWindow = SDL_FALSE;
|
||||
} else {
|
||||
inWindow = SDL_TRUE;
|
||||
}
|
||||
|
||||
/* Linux doesn't give you mouse events outside your window unless you grab
|
||||
the pointer.
|
||||
|
||||
Windows doesn't give you mouse events outside your window unless you call
|
||||
SetCapture().
|
||||
|
||||
Both of these are slightly scary changes, so for now we'll punt and if the
|
||||
mouse leaves the window you'll lose mouse focus and reset button state.
|
||||
*/
|
||||
#ifdef SUPPORT_DRAG_OUTSIDE_WINDOW
|
||||
if (!inWindow && !buttonstate) {
|
||||
#else
|
||||
if (!inWindow) {
|
||||
#endif
|
||||
if (window == mouse->focus) {
|
||||
#ifdef DEBUG_MOUSE
|
||||
printf("Mouse left window, synthesizing move & focus lost event\n");
|
||||
#endif
|
||||
SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
|
||||
SDL_SetMouseFocus(NULL);
|
||||
}
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
if (window != mouse->focus) {
|
||||
#ifdef DEBUG_MOUSE
|
||||
printf("Mouse entered window, synthesizing focus gain & move event\n");
|
||||
#endif
|
||||
SDL_SetMouseFocus(window);
|
||||
SDL_PrivateSendMouseMotion(window, mouse->mouseID, 0, x, y);
|
||||
}
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y)
|
||||
{
|
||||
if (window && !relative) {
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return SDL_PrivateSendMouseMotion(window, mouseID, relative, x, y);
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
int posted;
|
||||
int xrel;
|
||||
int yrel;
|
||||
int x_max = 0, y_max = 0;
|
||||
|
||||
/* relative motion is calculated regarding the system cursor last position */
|
||||
if (relative) {
|
||||
xrel = x;
|
||||
yrel = y;
|
||||
x = (mouse->last_x + x);
|
||||
y = (mouse->last_y + y);
|
||||
} else {
|
||||
xrel = x - mouse->last_x;
|
||||
yrel = y - mouse->last_y;
|
||||
}
|
||||
|
||||
/* Drop events that don't change state */
|
||||
if (!xrel && !yrel) {
|
||||
#ifdef DEBUG_MOUSE
|
||||
printf("Mouse event didn't change state - dropped!\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Update internal mouse coordinates */
|
||||
if (mouse->relative_mode == SDL_FALSE) {
|
||||
mouse->x = x;
|
||||
mouse->y = y;
|
||||
} else {
|
||||
mouse->x += xrel;
|
||||
mouse->y += yrel;
|
||||
}
|
||||
|
||||
SDL_GetWindowSize(mouse->focus, &x_max, &y_max);
|
||||
--x_max;
|
||||
--y_max;
|
||||
|
||||
/* make sure that the pointers find themselves inside the windows */
|
||||
if (mouse->x > x_max) {
|
||||
mouse->x = x_max;
|
||||
}
|
||||
if (mouse->x < 0) {
|
||||
mouse->x = 0;
|
||||
}
|
||||
|
||||
if (mouse->y > y_max) {
|
||||
mouse->y = y_max;
|
||||
}
|
||||
if (mouse->y < 0) {
|
||||
mouse->y = 0;
|
||||
}
|
||||
|
||||
mouse->xdelta += xrel;
|
||||
mouse->ydelta += yrel;
|
||||
|
||||
#if 0 /* FIXME */
|
||||
/* Move the mouse cursor, if needed */
|
||||
if (mouse->cursor_shown && !mouse->relative_mode &&
|
||||
mouse->MoveCursor && mouse->cur_cursor) {
|
||||
mouse->MoveCursor(mouse->cur_cursor);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Post the event, if desired */
|
||||
posted = 0;
|
||||
if (SDL_GetEventState(SDL_MOUSEMOTION) == SDL_ENABLE) {
|
||||
SDL_Event event;
|
||||
event.motion.type = SDL_MOUSEMOTION;
|
||||
event.motion.windowID = mouse->focus ? mouse->focus->id : 0;
|
||||
event.motion.which = mouseID;
|
||||
event.motion.state = mouse->buttonstate;
|
||||
event.motion.x = mouse->x;
|
||||
event.motion.y = mouse->y;
|
||||
event.motion.xrel = xrel;
|
||||
event.motion.yrel = yrel;
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
}
|
||||
/* Use unclamped values if we're getting events outside the window */
|
||||
mouse->last_x = x;
|
||||
mouse->last_y = y;
|
||||
return posted;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
int posted;
|
||||
Uint32 type;
|
||||
Uint32 buttonstate = mouse->buttonstate;
|
||||
|
||||
/* Figure out which event to perform */
|
||||
switch (state) {
|
||||
case SDL_PRESSED:
|
||||
type = SDL_MOUSEBUTTONDOWN;
|
||||
buttonstate |= SDL_BUTTON(button);
|
||||
break;
|
||||
case SDL_RELEASED:
|
||||
type = SDL_MOUSEBUTTONUP;
|
||||
buttonstate &= ~SDL_BUTTON(button);
|
||||
break;
|
||||
default:
|
||||
/* Invalid state -- bail */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* We do this after calculating buttonstate so button presses gain focus */
|
||||
if (window && state == SDL_PRESSED) {
|
||||
SDL_UpdateMouseFocus(window, mouse->x, mouse->y, buttonstate);
|
||||
}
|
||||
|
||||
if (buttonstate == mouse->buttonstate) {
|
||||
/* Ignore this event, no state change */
|
||||
return 0;
|
||||
}
|
||||
mouse->buttonstate = buttonstate;
|
||||
|
||||
/* Post the event, if desired */
|
||||
posted = 0;
|
||||
if (SDL_GetEventState(type) == SDL_ENABLE) {
|
||||
SDL_Event event;
|
||||
event.type = type;
|
||||
event.button.windowID = mouse->focus ? mouse->focus->id : 0;
|
||||
event.button.which = mouseID;
|
||||
event.button.state = state;
|
||||
event.button.button = button;
|
||||
event.button.x = mouse->x;
|
||||
event.button.y = mouse->y;
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
return posted;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
int posted;
|
||||
|
||||
if (window) {
|
||||
SDL_SetMouseFocus(window);
|
||||
}
|
||||
|
||||
if (!x && !y) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Post the event, if desired */
|
||||
posted = 0;
|
||||
if (SDL_GetEventState(SDL_MOUSEWHEEL) == SDL_ENABLE) {
|
||||
SDL_Event event;
|
||||
event.type = SDL_MOUSEWHEEL;
|
||||
event.wheel.windowID = mouse->focus ? mouse->focus->id : 0;
|
||||
event.wheel.which = mouseID;
|
||||
event.wheel.x = x;
|
||||
event.wheel.y = y;
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
}
|
||||
return posted;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_MouseQuit(void)
|
||||
{
|
||||
SDL_Cursor *cursor, *next;
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
SDL_ShowCursor(1);
|
||||
|
||||
cursor = mouse->cursors;
|
||||
while (cursor) {
|
||||
next = cursor->next;
|
||||
SDL_FreeCursor(cursor);
|
||||
cursor = next;
|
||||
}
|
||||
|
||||
if (mouse->def_cursor && mouse->FreeCursor) {
|
||||
mouse->FreeCursor(mouse->def_cursor);
|
||||
}
|
||||
|
||||
SDL_zerop(mouse);
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_GetMouseState(int *x, int *y)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
if (x) {
|
||||
*x = mouse->x;
|
||||
}
|
||||
if (y) {
|
||||
*y = mouse->y;
|
||||
}
|
||||
return mouse->buttonstate;
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_GetRelativeMouseState(int *x, int *y)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
if (x) {
|
||||
*x = mouse->xdelta;
|
||||
}
|
||||
if (y) {
|
||||
*y = mouse->ydelta;
|
||||
}
|
||||
mouse->xdelta = 0;
|
||||
mouse->ydelta = 0;
|
||||
return mouse->buttonstate;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
if ( window == NULL )
|
||||
window = mouse->focus;
|
||||
|
||||
if ( window == NULL )
|
||||
return;
|
||||
|
||||
if (mouse->WarpMouse) {
|
||||
mouse->WarpMouse(window, x, y);
|
||||
} else {
|
||||
SDL_SendMouseMotion(window, mouse->mouseID, 0, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SetRelativeMouseMode(SDL_bool enabled)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
SDL_Window *focusWindow = SDL_GetKeyboardFocus();
|
||||
int original_x = mouse->x, original_y = mouse->y;
|
||||
|
||||
if (enabled == mouse->relative_mode) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!mouse->SetRelativeMouseMode) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
if (enabled && focusWindow) {
|
||||
/* Center it in the focused window to prevent clicks from going through
|
||||
* to background windows.
|
||||
*/
|
||||
SDL_SetMouseFocus(focusWindow);
|
||||
SDL_WarpMouseInWindow(focusWindow, focusWindow->w/2, focusWindow->h/2);
|
||||
}
|
||||
|
||||
if (mouse->SetRelativeMouseMode(enabled) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Set the relative mode */
|
||||
mouse->relative_mode = enabled;
|
||||
|
||||
if (enabled) {
|
||||
/* Save the expected mouse position */
|
||||
mouse->original_x = original_x;
|
||||
mouse->original_y = original_y;
|
||||
} else if (mouse->focus) {
|
||||
/* Restore the expected mouse position */
|
||||
SDL_WarpMouseInWindow(mouse->focus, mouse->original_x, mouse->original_y);
|
||||
}
|
||||
|
||||
/* Flush pending mouse motion */
|
||||
SDL_FlushEvent(SDL_MOUSEMOTION);
|
||||
|
||||
/* Update cursor visibility */
|
||||
SDL_SetCursor(NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
SDL_GetRelativeMouseMode()
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
return mouse->relative_mode;
|
||||
}
|
||||
|
||||
SDL_Cursor *
|
||||
SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
|
||||
int w, int h, int hot_x, int hot_y)
|
||||
{
|
||||
SDL_Surface *surface;
|
||||
SDL_Cursor *cursor;
|
||||
int x, y;
|
||||
Uint32 *pixel;
|
||||
Uint8 datab = 0, maskb = 0;
|
||||
const Uint32 black = 0xFF000000;
|
||||
const Uint32 white = 0xFFFFFFFF;
|
||||
const Uint32 transparent = 0x00000000;
|
||||
|
||||
/* Make sure the width is a multiple of 8 */
|
||||
w = ((w + 7) & ~7);
|
||||
|
||||
/* Create the surface from a bitmap */
|
||||
surface = SDL_CreateRGBSurface(0, w, h, 32,
|
||||
0x00FF0000,
|
||||
0x0000FF00,
|
||||
0x000000FF,
|
||||
0xFF000000);
|
||||
if (!surface) {
|
||||
return NULL;
|
||||
}
|
||||
for (y = 0; y < h; ++y) {
|
||||
pixel = (Uint32 *) ((Uint8 *) surface->pixels + y * surface->pitch);
|
||||
for (x = 0; x < w; ++x) {
|
||||
if ((x % 8) == 0) {
|
||||
datab = *data++;
|
||||
maskb = *mask++;
|
||||
}
|
||||
if (maskb & 0x80) {
|
||||
*pixel++ = (datab & 0x80) ? black : white;
|
||||
} else {
|
||||
*pixel++ = (datab & 0x80) ? black : transparent;
|
||||
}
|
||||
datab <<= 1;
|
||||
maskb <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
cursor = SDL_CreateColorCursor(surface, hot_x, hot_y);
|
||||
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
SDL_Cursor *
|
||||
SDL_CreateColorCursor(SDL_Surface *surface, int hot_x, int hot_y)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
SDL_Surface *temp = NULL;
|
||||
SDL_Cursor *cursor;
|
||||
|
||||
if (!surface) {
|
||||
SDL_SetError("Passed NULL cursor surface");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!mouse->CreateCursor) {
|
||||
SDL_SetError("Cursors are not currently supported");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Sanity check the hot spot */
|
||||
if ((hot_x < 0) || (hot_y < 0) ||
|
||||
(hot_x >= surface->w) || (hot_y >= surface->h)) {
|
||||
SDL_SetError("Cursor hot spot doesn't lie within cursor");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (surface->format->format != SDL_PIXELFORMAT_ARGB8888) {
|
||||
temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ARGB8888, 0);
|
||||
if (!temp) {
|
||||
return NULL;
|
||||
}
|
||||
surface = temp;
|
||||
}
|
||||
|
||||
cursor = mouse->CreateCursor(surface, hot_x, hot_y);
|
||||
if (cursor) {
|
||||
cursor->next = mouse->cursors;
|
||||
mouse->cursors = cursor;
|
||||
}
|
||||
|
||||
if (temp) {
|
||||
SDL_FreeSurface(temp);
|
||||
}
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
SDL_Cursor *
|
||||
SDL_CreateSystemCursor(SDL_SystemCursor id)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
SDL_Cursor *cursor;
|
||||
|
||||
if (!mouse->CreateSystemCursor) {
|
||||
SDL_SetError("CreateSystemCursor is not currently supported");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cursor = mouse->CreateSystemCursor(id);
|
||||
if (cursor) {
|
||||
cursor->next = mouse->cursors;
|
||||
mouse->cursors = cursor;
|
||||
}
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
/* SDL_SetCursor(NULL) can be used to force the cursor redraw,
|
||||
if this is desired for any reason. This is used when setting
|
||||
the video mode and when the SDL window gains the mouse focus.
|
||||
*/
|
||||
void
|
||||
SDL_SetCursor(SDL_Cursor * cursor)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
/* Set the new cursor */
|
||||
if (cursor) {
|
||||
/* Make sure the cursor is still valid for this mouse */
|
||||
if (cursor != mouse->def_cursor) {
|
||||
SDL_Cursor *found;
|
||||
for (found = mouse->cursors; found; found = found->next) {
|
||||
if (found == cursor) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
SDL_SetError("Cursor not associated with the current mouse");
|
||||
return;
|
||||
}
|
||||
}
|
||||
mouse->cur_cursor = cursor;
|
||||
} else {
|
||||
if (mouse->focus) {
|
||||
cursor = mouse->cur_cursor;
|
||||
} else {
|
||||
cursor = mouse->def_cursor;
|
||||
}
|
||||
}
|
||||
|
||||
if (cursor && mouse->cursor_shown && !mouse->relative_mode) {
|
||||
if (mouse->ShowCursor) {
|
||||
mouse->ShowCursor(cursor);
|
||||
}
|
||||
} else {
|
||||
if (mouse->ShowCursor) {
|
||||
mouse->ShowCursor(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Cursor *
|
||||
SDL_GetCursor(void)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
if (!mouse) {
|
||||
return NULL;
|
||||
}
|
||||
return mouse->cur_cursor;
|
||||
}
|
||||
|
||||
SDL_Cursor *
|
||||
SDL_GetDefaultCursor(void)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
if (!mouse) {
|
||||
return NULL;
|
||||
}
|
||||
return mouse->def_cursor;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_FreeCursor(SDL_Cursor * cursor)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
SDL_Cursor *curr, *prev;
|
||||
|
||||
if (!cursor) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (cursor == mouse->def_cursor) {
|
||||
return;
|
||||
}
|
||||
if (cursor == mouse->cur_cursor) {
|
||||
SDL_SetCursor(mouse->def_cursor);
|
||||
}
|
||||
|
||||
for (prev = NULL, curr = mouse->cursors; curr;
|
||||
prev = curr, curr = curr->next) {
|
||||
if (curr == cursor) {
|
||||
if (prev) {
|
||||
prev->next = curr->next;
|
||||
} else {
|
||||
mouse->cursors = curr->next;
|
||||
}
|
||||
|
||||
if (mouse->FreeCursor) {
|
||||
mouse->FreeCursor(curr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_ShowCursor(int toggle)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
SDL_bool shown;
|
||||
|
||||
if (!mouse) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
shown = mouse->cursor_shown;
|
||||
if (toggle >= 0) {
|
||||
if (toggle) {
|
||||
mouse->cursor_shown = SDL_TRUE;
|
||||
} else {
|
||||
mouse->cursor_shown = SDL_FALSE;
|
||||
}
|
||||
if (mouse->cursor_shown != shown) {
|
||||
SDL_SetCursor(NULL);
|
||||
}
|
||||
}
|
||||
return shown;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
108
src/events/SDL_mouse_c.h
Normal file
108
src/events/SDL_mouse_c.h
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
#ifndef _SDL_mouse_c_h
|
||||
#define _SDL_mouse_c_h
|
||||
|
||||
#include "SDL_mouse.h"
|
||||
|
||||
typedef Uint32 SDL_MouseID;
|
||||
|
||||
struct SDL_Cursor
|
||||
{
|
||||
struct SDL_Cursor *next;
|
||||
void *driverdata;
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* Create a cursor from a surface */
|
||||
SDL_Cursor *(*CreateCursor) (SDL_Surface * surface, int hot_x, int hot_y);
|
||||
|
||||
/* Create a system cursor */
|
||||
SDL_Cursor *(*CreateSystemCursor) (SDL_SystemCursor id);
|
||||
|
||||
/* Show the specified cursor, or hide if cursor is NULL */
|
||||
int (*ShowCursor) (SDL_Cursor * cursor);
|
||||
|
||||
/* This is called when a mouse motion event occurs */
|
||||
void (*MoveCursor) (SDL_Cursor * cursor);
|
||||
|
||||
/* Free a window manager cursor */
|
||||
void (*FreeCursor) (SDL_Cursor * cursor);
|
||||
|
||||
/* Warp the mouse to (x,y) */
|
||||
void (*WarpMouse) (SDL_Window * window, int x, int y);
|
||||
|
||||
/* Set relative mode */
|
||||
int (*SetRelativeMouseMode) (SDL_bool enabled);
|
||||
|
||||
/* Data common to all mice */
|
||||
SDL_MouseID mouseID;
|
||||
SDL_Window *focus;
|
||||
int x;
|
||||
int y;
|
||||
int xdelta;
|
||||
int ydelta;
|
||||
int last_x, last_y; /* the last reported x and y coordinates */
|
||||
Uint32 buttonstate;
|
||||
SDL_bool relative_mode;
|
||||
/* the x and y coordinates when relative mode was activated */
|
||||
int original_x, original_y;
|
||||
|
||||
SDL_Cursor *cursors;
|
||||
SDL_Cursor *def_cursor;
|
||||
SDL_Cursor *cur_cursor;
|
||||
SDL_bool cursor_shown;
|
||||
|
||||
/* Driver-dependent data. */
|
||||
void *driverdata;
|
||||
} SDL_Mouse;
|
||||
|
||||
|
||||
/* Initialize the mouse subsystem */
|
||||
extern int SDL_MouseInit(void);
|
||||
|
||||
/* Get the mouse state structure */
|
||||
SDL_Mouse *SDL_GetMouse(void);
|
||||
|
||||
/* Set the default mouse cursor */
|
||||
extern void SDL_SetDefaultCursor(SDL_Cursor * cursor);
|
||||
|
||||
/* Set the mouse focus window */
|
||||
extern void SDL_SetMouseFocus(SDL_Window * window);
|
||||
|
||||
/* Send a mouse motion event */
|
||||
extern int SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relative, int x, int y);
|
||||
|
||||
/* Send a mouse button event */
|
||||
extern int SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8 button);
|
||||
|
||||
/* Send a mouse wheel event */
|
||||
extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y);
|
||||
|
||||
/* Shutdown the mouse subsystem */
|
||||
extern void SDL_MouseQuit(void);
|
||||
|
||||
#endif /* _SDL_mouse_c_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
120
src/events/SDL_quit.c
Normal file
120
src/events/SDL_quit.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
/* General quit handling code for SDL */
|
||||
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_events_c.h"
|
||||
|
||||
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
static void
|
||||
SDL_HandleSIG(int sig)
|
||||
{
|
||||
/* Reset the signal handler */
|
||||
signal(sig, SDL_HandleSIG);
|
||||
|
||||
/* Signal a quit interrupt */
|
||||
SDL_SendQuit();
|
||||
}
|
||||
#endif /* HAVE_SIGNAL_H */
|
||||
|
||||
/* Public functions */
|
||||
int
|
||||
SDL_QuitInit(void)
|
||||
{
|
||||
#ifdef HAVE_SIGACTION
|
||||
struct sigaction action;
|
||||
sigaction(SIGINT, NULL, &action);
|
||||
#ifdef HAVE_SA_SIGACTION
|
||||
if ( action.sa_handler == SIG_DFL && action.sa_sigaction == (void*)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 && action.sa_sigaction == (void*)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 */
|
||||
|
||||
/* That's it! */
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_QuitQuit(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);
|
||||
|
||||
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 */
|
||||
}
|
||||
|
||||
/* This function returns 1 if it's okay to close the application window */
|
||||
int
|
||||
SDL_SendQuit(void)
|
||||
{
|
||||
return SDL_SendAppEvent(SDL_QUIT);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
36
src/events/SDL_sysevents.h
Normal file
36
src/events/SDL_sysevents.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
#include "../video/SDL_sysvideo.h"
|
||||
|
||||
/* Useful functions and variables from SDL_sysevents.c */
|
||||
|
||||
#if defined(__BEOS__) || defined(__HAIKU__)
|
||||
/* The Be and Haiku event loops run in a separate thread */
|
||||
#define MUST_THREAD_EVENTS
|
||||
#endif
|
||||
|
||||
#ifdef __WIN32__ /* Windows doesn't allow a separate event thread */
|
||||
#define CANT_THREAD_EVENTS
|
||||
#endif
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
364
src/events/SDL_touch.c
Normal file
364
src/events/SDL_touch.c
Normal file
@@ -0,0 +1,364 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
/* General touch handling code for SDL */
|
||||
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_events_c.h"
|
||||
|
||||
|
||||
static int SDL_num_touch = 0;
|
||||
static SDL_Touch **SDL_touchDevices = NULL;
|
||||
|
||||
|
||||
/* Public functions */
|
||||
int
|
||||
SDL_TouchInit(void)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_GetNumTouchDevices(void)
|
||||
{
|
||||
return SDL_num_touch;
|
||||
}
|
||||
|
||||
SDL_TouchID
|
||||
SDL_GetTouchDevice(int index)
|
||||
{
|
||||
if (index < 0 || index >= SDL_num_touch) {
|
||||
SDL_SetError("Unknown touch device");
|
||||
return 0;
|
||||
}
|
||||
return SDL_touchDevices[index]->id;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_GetTouchIndex(SDL_TouchID id)
|
||||
{
|
||||
int index;
|
||||
SDL_Touch *touch;
|
||||
|
||||
for (index = 0; index < SDL_num_touch; ++index) {
|
||||
touch = SDL_touchDevices[index];
|
||||
if (touch->id == id) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_Touch *
|
||||
SDL_GetTouch(SDL_TouchID id)
|
||||
{
|
||||
int index = SDL_GetTouchIndex(id);
|
||||
if (index < 0 || index >= SDL_num_touch) {
|
||||
SDL_SetError("Unknown touch device");
|
||||
return NULL;
|
||||
}
|
||||
return SDL_touchDevices[index];
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_GetFingerIndex(const SDL_Touch * touch, SDL_FingerID fingerid)
|
||||
{
|
||||
int index;
|
||||
for (index = 0; index < touch->num_fingers; ++index) {
|
||||
if (touch->fingers[index]->id == fingerid) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_Finger *
|
||||
SDL_GetFinger(const SDL_Touch * touch, SDL_FingerID id)
|
||||
{
|
||||
int index = SDL_GetFingerIndex(touch, id);
|
||||
if (index < 0 || index >= touch->num_fingers) {
|
||||
return NULL;
|
||||
}
|
||||
return touch->fingers[index];
|
||||
}
|
||||
|
||||
int
|
||||
SDL_GetNumTouchFingers(SDL_TouchID touchID)
|
||||
{
|
||||
SDL_Touch *touch = SDL_GetTouch(touchID);
|
||||
if (touch) {
|
||||
return touch->num_fingers;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_Finger *
|
||||
SDL_GetTouchFinger(SDL_TouchID touchID, int index)
|
||||
{
|
||||
SDL_Touch *touch = SDL_GetTouch(touchID);
|
||||
if (!touch) {
|
||||
return NULL;
|
||||
}
|
||||
if (index < 0 || index >= touch->num_fingers) {
|
||||
SDL_SetError("Unknown touch finger");
|
||||
return NULL;
|
||||
}
|
||||
return touch->fingers[index];
|
||||
}
|
||||
|
||||
int
|
||||
SDL_AddTouch(SDL_TouchID touchID, const char *name)
|
||||
{
|
||||
SDL_Touch **touchDevices;
|
||||
int index;
|
||||
|
||||
index = SDL_GetTouchIndex(touchID);
|
||||
if (index >= 0) {
|
||||
return index;
|
||||
}
|
||||
|
||||
/* Add the touch to the list of touch */
|
||||
touchDevices = (SDL_Touch **) SDL_realloc(SDL_touchDevices,
|
||||
(SDL_num_touch + 1) * sizeof(*touchDevices));
|
||||
if (!touchDevices) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
SDL_touchDevices = touchDevices;
|
||||
index = SDL_num_touch++;
|
||||
|
||||
SDL_touchDevices[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchDevices[index]));
|
||||
if (!SDL_touchDevices[index]) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
/* we're setting the touch properties */
|
||||
SDL_touchDevices[index]->id = touchID;
|
||||
SDL_touchDevices[index]->num_fingers = 0;
|
||||
SDL_touchDevices[index]->max_fingers = 0;
|
||||
SDL_touchDevices[index]->fingers = NULL;
|
||||
|
||||
/* Record this touch device for gestures */
|
||||
/* We could do this on the fly in the gesture code if we wanted */
|
||||
SDL_GestureAddTouch(touchID);
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float y, float pressure)
|
||||
{
|
||||
SDL_Finger *finger;
|
||||
|
||||
if (touch->num_fingers == touch->max_fingers) {
|
||||
SDL_Finger **new_fingers;
|
||||
new_fingers = (SDL_Finger **)SDL_realloc(touch->fingers, (touch->max_fingers+1)*sizeof(*touch->fingers));
|
||||
if (!new_fingers) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
touch->fingers = new_fingers;
|
||||
touch->fingers[touch->max_fingers] = (SDL_Finger *)SDL_malloc(sizeof(*finger));
|
||||
if (!touch->fingers[touch->max_fingers]) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
touch->max_fingers++;
|
||||
}
|
||||
|
||||
finger = touch->fingers[touch->num_fingers++];
|
||||
finger->id = fingerid;
|
||||
finger->x = x;
|
||||
finger->y = y;
|
||||
finger->pressure = pressure;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_DelFinger(SDL_Touch* touch, SDL_FingerID fingerid)
|
||||
{
|
||||
SDL_Finger *temp;
|
||||
|
||||
int index = SDL_GetFingerIndex(touch, fingerid);
|
||||
if (index < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
touch->num_fingers--;
|
||||
temp = touch->fingers[index];
|
||||
touch->fingers[index] = touch->fingers[touch->num_fingers];
|
||||
touch->fingers[touch->num_fingers] = temp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid,
|
||||
SDL_bool down, float x, float y, float pressure)
|
||||
{
|
||||
int posted;
|
||||
SDL_Finger *finger;
|
||||
|
||||
SDL_Touch* touch = SDL_GetTouch(id);
|
||||
if (!touch) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
finger = SDL_GetFinger(touch, fingerid);
|
||||
if (down) {
|
||||
if (finger) {
|
||||
/* This finger is already down */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (SDL_AddFinger(touch, fingerid, x, y, pressure) < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
posted = 0;
|
||||
if (SDL_GetEventState(SDL_FINGERDOWN) == SDL_ENABLE) {
|
||||
SDL_Event event;
|
||||
event.tfinger.type = SDL_FINGERDOWN;
|
||||
event.tfinger.touchId = id;
|
||||
event.tfinger.fingerId = fingerid;
|
||||
event.tfinger.x = x;
|
||||
event.tfinger.y = y;
|
||||
event.tfinger.dx = 0;
|
||||
event.tfinger.dy = 0;
|
||||
event.tfinger.pressure = pressure;
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
}
|
||||
} else {
|
||||
if (!finger) {
|
||||
/* This finger is already up */
|
||||
return 0;
|
||||
}
|
||||
|
||||
posted = 0;
|
||||
if (SDL_GetEventState(SDL_FINGERUP) == SDL_ENABLE) {
|
||||
SDL_Event event;
|
||||
event.tfinger.type = SDL_FINGERUP;
|
||||
event.tfinger.touchId = id;
|
||||
event.tfinger.fingerId = fingerid;
|
||||
/* I don't trust the coordinates passed on fingerUp */
|
||||
event.tfinger.x = finger->x;
|
||||
event.tfinger.y = finger->y;
|
||||
event.tfinger.dx = 0;
|
||||
event.tfinger.dy = 0;
|
||||
event.tfinger.pressure = pressure;
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
}
|
||||
|
||||
SDL_DelFinger(touch, fingerid);
|
||||
}
|
||||
return posted;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
|
||||
float x, float y, float pressure)
|
||||
{
|
||||
SDL_Touch *touch;
|
||||
SDL_Finger *finger;
|
||||
int posted;
|
||||
float xrel, yrel, prel;
|
||||
|
||||
touch = SDL_GetTouch(id);
|
||||
if (!touch) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
finger = SDL_GetFinger(touch,fingerid);
|
||||
if (!finger) {
|
||||
return SDL_SendTouch(id, fingerid, SDL_TRUE, x, y, pressure);
|
||||
}
|
||||
|
||||
xrel = x - finger->x;
|
||||
yrel = y - finger->y;
|
||||
prel = pressure - finger->pressure;
|
||||
|
||||
/* Drop events that don't change state */
|
||||
if (!xrel && !yrel && !prel) {
|
||||
#if 0
|
||||
printf("Touch event didn't change state - dropped!\n");
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Update internal touch coordinates */
|
||||
finger->x = x;
|
||||
finger->y = y;
|
||||
finger->pressure = pressure;
|
||||
|
||||
/* Post the event, if desired */
|
||||
posted = 0;
|
||||
if (SDL_GetEventState(SDL_FINGERMOTION) == SDL_ENABLE) {
|
||||
SDL_Event event;
|
||||
event.tfinger.type = SDL_FINGERMOTION;
|
||||
event.tfinger.touchId = id;
|
||||
event.tfinger.fingerId = fingerid;
|
||||
event.tfinger.x = x;
|
||||
event.tfinger.y = y;
|
||||
event.tfinger.dx = xrel;
|
||||
event.tfinger.dy = yrel;
|
||||
event.tfinger.pressure = pressure;
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
}
|
||||
return posted;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_DelTouch(SDL_TouchID id)
|
||||
{
|
||||
int i;
|
||||
int index = SDL_GetTouchIndex(id);
|
||||
SDL_Touch *touch = SDL_GetTouch(id);
|
||||
|
||||
if (!touch) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < touch->max_fingers; ++i) {
|
||||
SDL_free(touch->fingers[i]);
|
||||
}
|
||||
SDL_free(touch->fingers);
|
||||
SDL_free(touch);
|
||||
|
||||
SDL_num_touch--;
|
||||
SDL_touchDevices[index] = SDL_touchDevices[SDL_num_touch];
|
||||
}
|
||||
|
||||
void
|
||||
SDL_TouchQuit(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = SDL_num_touch; i--; ) {
|
||||
SDL_DelTouch(SDL_touchDevices[i]->id);
|
||||
}
|
||||
SDL_assert(SDL_num_touch == 0);
|
||||
|
||||
if (SDL_touchDevices) {
|
||||
SDL_free(SDL_touchDevices);
|
||||
SDL_touchDevices = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
61
src/events/SDL_touch_c.h
Normal file
61
src/events/SDL_touch_c.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
#include "../../include/SDL_touch.h"
|
||||
|
||||
#ifndef _SDL_touch_c_h
|
||||
#define _SDL_touch_c_h
|
||||
|
||||
typedef struct SDL_Touch
|
||||
{
|
||||
SDL_TouchID id;
|
||||
int num_fingers;
|
||||
int max_fingers;
|
||||
SDL_Finger** fingers;
|
||||
} SDL_Touch;
|
||||
|
||||
|
||||
/* Initialize the touch subsystem */
|
||||
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);
|
||||
|
||||
/* Get the touch with a given id */
|
||||
extern SDL_Touch *SDL_GetTouch(SDL_TouchID id);
|
||||
|
||||
/* Send a touch down/up event for a touch */
|
||||
extern int SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid,
|
||||
SDL_bool down, float x, float y, float pressure);
|
||||
|
||||
/* Send a touch motion event for a touch */
|
||||
extern int SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
|
||||
float x, float y, float pressure);
|
||||
|
||||
/* Remove a touch */
|
||||
extern void SDL_DelTouch(SDL_TouchID id);
|
||||
|
||||
/* Shutdown the touch subsystem */
|
||||
extern void SDL_TouchQuit(void);
|
||||
|
||||
#endif /* _SDL_touch_c_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
210
src/events/SDL_windowevents.c
Normal file
210
src/events/SDL_windowevents.c
Normal file
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
/* Window event handling code for SDL */
|
||||
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_events_c.h"
|
||||
#include "SDL_mouse_c.h"
|
||||
#include "../video/SDL_sysvideo.h"
|
||||
|
||||
|
||||
static int
|
||||
RemovePendingResizedEvents(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
|
||||
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.windowID == new_event->window.windowID) {
|
||||
/* We're about to post a new size event, drop the old one */
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
RemovePendingMoveEvents(void * userdata, SDL_Event *event)
|
||||
{
|
||||
SDL_Event *new_event = (SDL_Event *)userdata;
|
||||
|
||||
if (event->type == SDL_WINDOWEVENT &&
|
||||
event->window.event == SDL_WINDOWEVENT_MOVED &&
|
||||
event->window.windowID == new_event->window.windowID) {
|
||||
/* We're about to post a new move event, drop the old one */
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
|
||||
int data2)
|
||||
{
|
||||
int posted;
|
||||
|
||||
if (!window) {
|
||||
return 0;
|
||||
}
|
||||
switch (windowevent) {
|
||||
case SDL_WINDOWEVENT_SHOWN:
|
||||
if (window->flags & SDL_WINDOW_SHOWN) {
|
||||
return 0;
|
||||
}
|
||||
window->flags &= ~SDL_WINDOW_HIDDEN;
|
||||
window->flags |= SDL_WINDOW_SHOWN;
|
||||
SDL_OnWindowShown(window);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_HIDDEN:
|
||||
if (!(window->flags & SDL_WINDOW_SHOWN)) {
|
||||
return 0;
|
||||
}
|
||||
window->flags &= ~SDL_WINDOW_SHOWN;
|
||||
window->flags |= SDL_WINDOW_HIDDEN;
|
||||
SDL_OnWindowHidden(window);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_MOVED:
|
||||
if (SDL_WINDOWPOS_ISUNDEFINED(data1) ||
|
||||
SDL_WINDOWPOS_ISUNDEFINED(data2)) {
|
||||
return 0;
|
||||
}
|
||||
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
|
||||
window->windowed.x = data1;
|
||||
window->windowed.y = data2;
|
||||
}
|
||||
if (data1 == window->x && data2 == window->y) {
|
||||
return 0;
|
||||
}
|
||||
window->x = data1;
|
||||
window->y = data2;
|
||||
break;
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
|
||||
window->windowed.w = data1;
|
||||
window->windowed.h = data2;
|
||||
}
|
||||
if (data1 == window->w && data2 == window->h) {
|
||||
return 0;
|
||||
}
|
||||
window->w = data1;
|
||||
window->h = data2;
|
||||
SDL_OnWindowResized(window);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_MINIMIZED:
|
||||
if (window->flags & SDL_WINDOW_MINIMIZED) {
|
||||
return 0;
|
||||
}
|
||||
window->flags |= SDL_WINDOW_MINIMIZED;
|
||||
SDL_OnWindowMinimized(window);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_MAXIMIZED:
|
||||
if (window->flags & SDL_WINDOW_MAXIMIZED) {
|
||||
return 0;
|
||||
}
|
||||
window->flags |= SDL_WINDOW_MAXIMIZED;
|
||||
break;
|
||||
case SDL_WINDOWEVENT_RESTORED:
|
||||
if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
|
||||
return 0;
|
||||
}
|
||||
window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
|
||||
SDL_OnWindowRestored(window);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_ENTER:
|
||||
if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
|
||||
return 0;
|
||||
}
|
||||
window->flags |= SDL_WINDOW_MOUSE_FOCUS;
|
||||
SDL_OnWindowEnter(window);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_LEAVE:
|
||||
if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
|
||||
return 0;
|
||||
}
|
||||
window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
|
||||
SDL_OnWindowLeave(window);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
|
||||
return 0;
|
||||
}
|
||||
window->flags |= SDL_WINDOW_INPUT_FOCUS;
|
||||
SDL_OnWindowFocusGained(window);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_LOST:
|
||||
if (!(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
|
||||
return 0;
|
||||
}
|
||||
window->flags &= ~SDL_WINDOW_INPUT_FOCUS;
|
||||
SDL_OnWindowFocusLost(window);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Post the event, if desired */
|
||||
posted = 0;
|
||||
if (SDL_GetEventState(SDL_WINDOWEVENT) == SDL_ENABLE) {
|
||||
SDL_Event event;
|
||||
event.type = SDL_WINDOWEVENT;
|
||||
event.window.event = windowevent;
|
||||
event.window.data1 = data1;
|
||||
event.window.data2 = data2;
|
||||
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);
|
||||
}
|
||||
if (windowevent == SDL_WINDOWEVENT_MOVED) {
|
||||
SDL_FilterEvents(RemovePendingMoveEvents, &event);
|
||||
}
|
||||
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
}
|
||||
|
||||
if (windowevent == SDL_WINDOWEVENT_CLOSE) {
|
||||
if ( !window->prev && !window->next ) {
|
||||
/* This is the last window in the list so send the SDL_QUIT event */
|
||||
SDL_SendQuit();
|
||||
}
|
||||
}
|
||||
|
||||
return (posted);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
31
src/events/SDL_windowevents_c.h
Normal file
31
src/events/SDL_windowevents_c.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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_config.h"
|
||||
|
||||
#ifndef _SDL_windowevents_c_h
|
||||
#define _SDL_windowevents_c_h
|
||||
|
||||
extern int SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent,
|
||||
int data1, int data2);
|
||||
|
||||
#endif /* _SDL_windowevents_c_h */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
33
src/events/blank_cursor.h
Normal file
33
src/events/blank_cursor.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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.
|
||||
*/
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* A default blank 8x8 cursor */
|
||||
|
||||
#define BLANK_CWIDTH 8
|
||||
#define BLANK_CHEIGHT 8
|
||||
#define BLANK_CHOTX 0
|
||||
#define BLANK_CHOTY 0
|
||||
|
||||
static const unsigned char blank_cdata[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
static const unsigned char blank_cmask[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
114
src/events/default_cursor.h
Normal file
114
src/events/default_cursor.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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.
|
||||
*/
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* Default cursor - it happens to be the Mac cursor, but could be anything */
|
||||
|
||||
#define DEFAULT_CWIDTH 16
|
||||
#define DEFAULT_CHEIGHT 16
|
||||
#define DEFAULT_CHOTX 0
|
||||
#define DEFAULT_CHOTY 0
|
||||
|
||||
/* Added a real MacOS cursor, at the request of Luc-Olivier de Charri<72>re */
|
||||
#define USE_MACOS_CURSOR
|
||||
|
||||
#ifdef USE_MACOS_CURSOR
|
||||
|
||||
static const unsigned char default_cdata[] = {
|
||||
0x00, 0x00,
|
||||
0x40, 0x00,
|
||||
0x60, 0x00,
|
||||
0x70, 0x00,
|
||||
0x78, 0x00,
|
||||
0x7C, 0x00,
|
||||
0x7E, 0x00,
|
||||
0x7F, 0x00,
|
||||
0x7F, 0x80,
|
||||
0x7C, 0x00,
|
||||
0x6C, 0x00,
|
||||
0x46, 0x00,
|
||||
0x06, 0x00,
|
||||
0x03, 0x00,
|
||||
0x03, 0x00,
|
||||
0x00, 0x00
|
||||
};
|
||||
|
||||
static const unsigned char default_cmask[] = {
|
||||
0xC0, 0x00,
|
||||
0xE0, 0x00,
|
||||
0xF0, 0x00,
|
||||
0xF8, 0x00,
|
||||
0xFC, 0x00,
|
||||
0xFE, 0x00,
|
||||
0xFF, 0x00,
|
||||
0xFF, 0x80,
|
||||
0xFF, 0xC0,
|
||||
0xFF, 0xE0,
|
||||
0xFE, 0x00,
|
||||
0xEF, 0x00,
|
||||
0xCF, 0x00,
|
||||
0x87, 0x80,
|
||||
0x07, 0x80,
|
||||
0x03, 0x00
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
static const unsigned char default_cdata[] = {
|
||||
0x00, 0x00,
|
||||
0x40, 0x00,
|
||||
0x60, 0x00,
|
||||
0x70, 0x00,
|
||||
0x78, 0x00,
|
||||
0x7C, 0x00,
|
||||
0x7E, 0x00,
|
||||
0x7F, 0x00,
|
||||
0x7F, 0x80,
|
||||
0x7C, 0x00,
|
||||
0x6C, 0x00,
|
||||
0x46, 0x00,
|
||||
0x06, 0x00,
|
||||
0x03, 0x00,
|
||||
0x03, 0x00,
|
||||
0x00, 0x00
|
||||
};
|
||||
|
||||
static const unsigned char default_cmask[] = {
|
||||
0x40, 0x00,
|
||||
0xE0, 0x00,
|
||||
0xF0, 0x00,
|
||||
0xF8, 0x00,
|
||||
0xFC, 0x00,
|
||||
0xFE, 0x00,
|
||||
0xFF, 0x00,
|
||||
0xFF, 0x80,
|
||||
0xFF, 0xC0,
|
||||
0xFF, 0x80,
|
||||
0xFE, 0x00,
|
||||
0xEF, 0x00,
|
||||
0x4F, 0x00,
|
||||
0x07, 0x80,
|
||||
0x07, 0x80,
|
||||
0x03, 0x00
|
||||
};
|
||||
|
||||
#endif /* TRUE_MACINTOSH_CURSOR */
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
159
src/events/scancodes_darwin.h
Normal file
159
src/events/scancodes_darwin.h
Normal file
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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.
|
||||
*/
|
||||
|
||||
/* Mac virtual key code to SDL scancode mapping table
|
||||
Sources:
|
||||
- Inside Macintosh: Text <http://developer.apple.com/documentation/mac/Text/Text-571.html>
|
||||
- Apple USB keyboard driver source <http://darwinsource.opendarwin.org/10.4.6.ppc/IOHIDFamily-172.8/IOHIDFamily/Cosmo_USB2ADB.c>
|
||||
- experimentation on various ADB and USB ISO keyboards and one ADB ANSI keyboard
|
||||
*/
|
||||
/* *INDENT-OFF* */
|
||||
static const SDL_Scancode darwin_scancode_table[] = {
|
||||
/* 0 */ SDL_SCANCODE_A,
|
||||
/* 1 */ SDL_SCANCODE_S,
|
||||
/* 2 */ SDL_SCANCODE_D,
|
||||
/* 3 */ SDL_SCANCODE_F,
|
||||
/* 4 */ SDL_SCANCODE_H,
|
||||
/* 5 */ SDL_SCANCODE_G,
|
||||
/* 6 */ SDL_SCANCODE_Z,
|
||||
/* 7 */ SDL_SCANCODE_X,
|
||||
/* 8 */ SDL_SCANCODE_C,
|
||||
/* 9 */ SDL_SCANCODE_V,
|
||||
/* 10 */ SDL_SCANCODE_NONUSBACKSLASH, /* SDL_SCANCODE_NONUSBACKSLASH on ANSI and JIS keyboards (if this key would exist there), SDL_SCANCODE_GRAVE on ISO. (The USB keyboard driver actually translates these usage codes to different virtual key codes depending on whether the keyboard is ISO/ANSI/JIS. That's why you have to help it identify the keyboard type when you plug in a PC USB keyboard. It's a historical thing - ADB keyboards are wired this way.) */
|
||||
/* 11 */ SDL_SCANCODE_B,
|
||||
/* 12 */ SDL_SCANCODE_Q,
|
||||
/* 13 */ SDL_SCANCODE_W,
|
||||
/* 14 */ SDL_SCANCODE_E,
|
||||
/* 15 */ SDL_SCANCODE_R,
|
||||
/* 16 */ SDL_SCANCODE_Y,
|
||||
/* 17 */ SDL_SCANCODE_T,
|
||||
/* 18 */ SDL_SCANCODE_1,
|
||||
/* 19 */ SDL_SCANCODE_2,
|
||||
/* 20 */ SDL_SCANCODE_3,
|
||||
/* 21 */ SDL_SCANCODE_4,
|
||||
/* 22 */ SDL_SCANCODE_6,
|
||||
/* 23 */ SDL_SCANCODE_5,
|
||||
/* 24 */ SDL_SCANCODE_EQUALS,
|
||||
/* 25 */ SDL_SCANCODE_9,
|
||||
/* 26 */ SDL_SCANCODE_7,
|
||||
/* 27 */ SDL_SCANCODE_MINUS,
|
||||
/* 28 */ SDL_SCANCODE_8,
|
||||
/* 29 */ SDL_SCANCODE_0,
|
||||
/* 30 */ SDL_SCANCODE_RIGHTBRACKET,
|
||||
/* 31 */ SDL_SCANCODE_O,
|
||||
/* 32 */ SDL_SCANCODE_U,
|
||||
/* 33 */ SDL_SCANCODE_LEFTBRACKET,
|
||||
/* 34 */ SDL_SCANCODE_I,
|
||||
/* 35 */ SDL_SCANCODE_P,
|
||||
/* 36 */ SDL_SCANCODE_RETURN,
|
||||
/* 37 */ SDL_SCANCODE_L,
|
||||
/* 38 */ SDL_SCANCODE_J,
|
||||
/* 39 */ SDL_SCANCODE_APOSTROPHE,
|
||||
/* 40 */ SDL_SCANCODE_K,
|
||||
/* 41 */ SDL_SCANCODE_SEMICOLON,
|
||||
/* 42 */ SDL_SCANCODE_BACKSLASH,
|
||||
/* 43 */ SDL_SCANCODE_COMMA,
|
||||
/* 44 */ SDL_SCANCODE_SLASH,
|
||||
/* 45 */ SDL_SCANCODE_N,
|
||||
/* 46 */ SDL_SCANCODE_M,
|
||||
/* 47 */ SDL_SCANCODE_PERIOD,
|
||||
/* 48 */ SDL_SCANCODE_TAB,
|
||||
/* 49 */ SDL_SCANCODE_SPACE,
|
||||
/* 50 */ SDL_SCANCODE_GRAVE, /* SDL_SCANCODE_GRAVE on ANSI and JIS keyboards, SDL_SCANCODE_NONUSBACKSLASH on ISO (see comment about virtual key code 10 above) */
|
||||
/* 51 */ SDL_SCANCODE_BACKSPACE,
|
||||
/* 52 */ SDL_SCANCODE_KP_ENTER, /* keyboard enter on portables */
|
||||
/* 53 */ SDL_SCANCODE_ESCAPE,
|
||||
/* 54 */ SDL_SCANCODE_RGUI,
|
||||
/* 55 */ SDL_SCANCODE_LGUI,
|
||||
/* 56 */ SDL_SCANCODE_LSHIFT,
|
||||
/* 57 */ SDL_SCANCODE_CAPSLOCK,
|
||||
/* 58 */ SDL_SCANCODE_LALT,
|
||||
/* 59 */ SDL_SCANCODE_LCTRL,
|
||||
/* 60 */ SDL_SCANCODE_RSHIFT,
|
||||
/* 61 */ SDL_SCANCODE_RALT,
|
||||
/* 62 */ SDL_SCANCODE_RCTRL,
|
||||
/* 63 */ SDL_SCANCODE_RGUI, /* fn on portables, acts as a hardware-level modifier already, so we don't generate events for it, also XK_Meta_R */
|
||||
/* 64 */ SDL_SCANCODE_F17,
|
||||
/* 65 */ SDL_SCANCODE_KP_PERIOD,
|
||||
/* 66 */ SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
|
||||
/* 67 */ SDL_SCANCODE_KP_MULTIPLY,
|
||||
/* 68 */ SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
|
||||
/* 69 */ SDL_SCANCODE_KP_PLUS,
|
||||
/* 70 */ SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
|
||||
/* 71 */ SDL_SCANCODE_NUMLOCKCLEAR,
|
||||
/* 72 */ SDL_SCANCODE_VOLUMEUP,
|
||||
/* 73 */ SDL_SCANCODE_VOLUMEDOWN,
|
||||
/* 74 */ SDL_SCANCODE_MUTE,
|
||||
/* 75 */ SDL_SCANCODE_KP_DIVIDE,
|
||||
/* 76 */ SDL_SCANCODE_KP_ENTER, /* keypad enter on external keyboards, fn-return on portables */
|
||||
/* 77 */ SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
|
||||
/* 78 */ SDL_SCANCODE_KP_MINUS,
|
||||
/* 79 */ SDL_SCANCODE_F18,
|
||||
/* 80 */ SDL_SCANCODE_F19,
|
||||
/* 81 */ SDL_SCANCODE_KP_EQUALS,
|
||||
/* 82 */ SDL_SCANCODE_KP_0,
|
||||
/* 83 */ SDL_SCANCODE_KP_1,
|
||||
/* 84 */ SDL_SCANCODE_KP_2,
|
||||
/* 85 */ SDL_SCANCODE_KP_3,
|
||||
/* 86 */ SDL_SCANCODE_KP_4,
|
||||
/* 87 */ SDL_SCANCODE_KP_5,
|
||||
/* 88 */ SDL_SCANCODE_KP_6,
|
||||
/* 89 */ SDL_SCANCODE_KP_7,
|
||||
/* 90 */ SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
|
||||
/* 91 */ SDL_SCANCODE_KP_8,
|
||||
/* 92 */ SDL_SCANCODE_KP_9,
|
||||
/* 93 */ SDL_SCANCODE_INTERNATIONAL3, /* Cosmo_USB2ADB.c says "Yen (JIS)" */
|
||||
/* 94 */ SDL_SCANCODE_INTERNATIONAL1, /* Cosmo_USB2ADB.c says "Ro (JIS)" */
|
||||
/* 95 */ SDL_SCANCODE_KP_COMMA, /* Cosmo_USB2ADB.c says ", JIS only" */
|
||||
/* 96 */ SDL_SCANCODE_F5,
|
||||
/* 97 */ SDL_SCANCODE_F6,
|
||||
/* 98 */ SDL_SCANCODE_F7,
|
||||
/* 99 */ SDL_SCANCODE_F3,
|
||||
/* 100 */ SDL_SCANCODE_F8,
|
||||
/* 101 */ SDL_SCANCODE_F9,
|
||||
/* 102 */ SDL_SCANCODE_LANG2, /* Cosmo_USB2ADB.c says "Eisu" */
|
||||
/* 103 */ SDL_SCANCODE_F11,
|
||||
/* 104 */ SDL_SCANCODE_LANG1, /* Cosmo_USB2ADB.c says "Kana" */
|
||||
/* 105 */ SDL_SCANCODE_PRINTSCREEN, /* On ADB keyboards, this key is labeled "F13/print screen". Problem: USB has different usage codes for these two functions. On Apple USB keyboards, the key is labeled "F13" and sends the F13 usage code (SDL_SCANCODE_F13). I decided to use SDL_SCANCODE_PRINTSCREEN here nevertheless since SDL applications are more likely to assume the presence of a print screen key than an F13 key. */
|
||||
/* 106 */ SDL_SCANCODE_F16,
|
||||
/* 107 */ SDL_SCANCODE_SCROLLLOCK, /* F14/scroll lock, see comment about F13/print screen above */
|
||||
/* 108 */ SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
|
||||
/* 109 */ SDL_SCANCODE_F10,
|
||||
/* 110 */ SDL_SCANCODE_APPLICATION, /* windows contextual menu key, fn-enter on portables */
|
||||
/* 111 */ SDL_SCANCODE_F12,
|
||||
/* 112 */ SDL_SCANCODE_UNKNOWN, /* unknown (unused?) */
|
||||
/* 113 */ SDL_SCANCODE_PAUSE, /* F15/pause, see comment about F13/print screen above */
|
||||
/* 114 */ SDL_SCANCODE_INSERT, /* the key is actually labeled "help" on Apple keyboards, and works as such in Mac OS, but it sends the "insert" usage code even on Apple USB keyboards */
|
||||
/* 115 */ SDL_SCANCODE_HOME,
|
||||
/* 116 */ SDL_SCANCODE_PAGEUP,
|
||||
/* 117 */ SDL_SCANCODE_DELETE,
|
||||
/* 118 */ SDL_SCANCODE_F4,
|
||||
/* 119 */ SDL_SCANCODE_END,
|
||||
/* 120 */ SDL_SCANCODE_F2,
|
||||
/* 121 */ SDL_SCANCODE_PAGEDOWN,
|
||||
/* 122 */ SDL_SCANCODE_F1,
|
||||
/* 123 */ SDL_SCANCODE_LEFT,
|
||||
/* 124 */ SDL_SCANCODE_RIGHT,
|
||||
/* 125 */ SDL_SCANCODE_DOWN,
|
||||
/* 126 */ SDL_SCANCODE_UP,
|
||||
/* 127 */ SDL_SCANCODE_POWER
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
263
src/events/scancodes_linux.h
Normal file
263
src/events/scancodes_linux.h
Normal file
@@ -0,0 +1,263 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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 "../../include/SDL_scancode.h"
|
||||
|
||||
/* Linux virtual key code to SDL_Keycode mapping table
|
||||
Sources:
|
||||
- Linux kernel source input.h
|
||||
*/
|
||||
/* *INDENT-OFF* */
|
||||
static SDL_Scancode const linux_scancode_table[] = {
|
||||
/* 0 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 1 */ SDL_SCANCODE_ESCAPE,
|
||||
/* 2 */ SDL_SCANCODE_1,
|
||||
/* 3 */ SDL_SCANCODE_2,
|
||||
/* 4 */ SDL_SCANCODE_3,
|
||||
/* 5 */ SDL_SCANCODE_4,
|
||||
/* 6 */ SDL_SCANCODE_5,
|
||||
/* 7 */ SDL_SCANCODE_6,
|
||||
/* 8 */ SDL_SCANCODE_7,
|
||||
/* 9 */ SDL_SCANCODE_8,
|
||||
/* 10 */ SDL_SCANCODE_9,
|
||||
/* 11 */ SDL_SCANCODE_0,
|
||||
/* 12 */ SDL_SCANCODE_MINUS,
|
||||
/* 13 */ SDL_SCANCODE_EQUALS,
|
||||
/* 14 */ SDL_SCANCODE_BACKSPACE,
|
||||
/* 15 */ SDL_SCANCODE_TAB,
|
||||
/* 16 */ SDL_SCANCODE_Q,
|
||||
/* 17 */ SDL_SCANCODE_W,
|
||||
/* 18 */ SDL_SCANCODE_E,
|
||||
/* 19 */ SDL_SCANCODE_R,
|
||||
/* 20 */ SDL_SCANCODE_T,
|
||||
/* 21 */ SDL_SCANCODE_Y,
|
||||
/* 22 */ SDL_SCANCODE_U,
|
||||
/* 23 */ SDL_SCANCODE_I,
|
||||
/* 24 */ SDL_SCANCODE_O,
|
||||
/* 25 */ SDL_SCANCODE_P,
|
||||
/* 26 */ SDL_SCANCODE_LEFTBRACKET,
|
||||
/* 27 */ SDL_SCANCODE_RIGHTBRACKET,
|
||||
/* 28 */ SDL_SCANCODE_RETURN,
|
||||
/* 29 */ SDL_SCANCODE_LCTRL,
|
||||
/* 30 */ SDL_SCANCODE_A,
|
||||
/* 31 */ SDL_SCANCODE_S,
|
||||
/* 32 */ SDL_SCANCODE_D,
|
||||
/* 33 */ SDL_SCANCODE_F,
|
||||
/* 34 */ SDL_SCANCODE_G,
|
||||
/* 35 */ SDL_SCANCODE_H,
|
||||
/* 36 */ SDL_SCANCODE_J,
|
||||
/* 37 */ SDL_SCANCODE_K,
|
||||
/* 38 */ SDL_SCANCODE_L,
|
||||
/* 39 */ SDL_SCANCODE_SEMICOLON,
|
||||
/* 40 */ SDL_SCANCODE_APOSTROPHE,
|
||||
/* 41 */ SDL_SCANCODE_GRAVE,
|
||||
/* 42 */ SDL_SCANCODE_LSHIFT,
|
||||
/* 43 */ SDL_SCANCODE_BACKSLASH,
|
||||
/* 44 */ SDL_SCANCODE_Z,
|
||||
/* 45 */ SDL_SCANCODE_X,
|
||||
/* 46 */ SDL_SCANCODE_C,
|
||||
/* 47 */ SDL_SCANCODE_V,
|
||||
/* 48 */ SDL_SCANCODE_B,
|
||||
/* 49 */ SDL_SCANCODE_N,
|
||||
/* 50 */ SDL_SCANCODE_M,
|
||||
/* 51 */ SDL_SCANCODE_COMMA,
|
||||
/* 52 */ SDL_SCANCODE_PERIOD,
|
||||
/* 53 */ SDL_SCANCODE_SLASH,
|
||||
/* 54 */ SDL_SCANCODE_RSHIFT,
|
||||
/* 55 */ SDL_SCANCODE_KP_MULTIPLY,
|
||||
/* 56 */ SDL_SCANCODE_LALT,
|
||||
/* 57 */ SDL_SCANCODE_SPACE,
|
||||
/* 58 */ SDL_SCANCODE_CAPSLOCK,
|
||||
/* 59 */ SDL_SCANCODE_F1,
|
||||
/* 60 */ SDL_SCANCODE_F2,
|
||||
/* 61 */ SDL_SCANCODE_F3,
|
||||
/* 62 */ SDL_SCANCODE_F4,
|
||||
/* 63 */ SDL_SCANCODE_F5,
|
||||
/* 64 */ SDL_SCANCODE_F6,
|
||||
/* 65 */ SDL_SCANCODE_F7,
|
||||
/* 66 */ SDL_SCANCODE_F8,
|
||||
/* 67 */ SDL_SCANCODE_F9,
|
||||
/* 68 */ SDL_SCANCODE_F10,
|
||||
/* 69 */ SDL_SCANCODE_NUMLOCKCLEAR,
|
||||
/* 70 */ SDL_SCANCODE_SCROLLLOCK,
|
||||
/* 71 */ SDL_SCANCODE_KP_7,
|
||||
/* 72 */ SDL_SCANCODE_KP_8,
|
||||
/* 73 */ SDL_SCANCODE_KP_9,
|
||||
/* 74 */ SDL_SCANCODE_KP_MINUS,
|
||||
/* 75 */ SDL_SCANCODE_KP_4,
|
||||
/* 76 */ SDL_SCANCODE_KP_5,
|
||||
/* 77 */ SDL_SCANCODE_KP_6,
|
||||
/* 78 */ SDL_SCANCODE_KP_PLUS,
|
||||
/* 79 */ SDL_SCANCODE_KP_1,
|
||||
/* 80 */ SDL_SCANCODE_KP_2,
|
||||
/* 81 */ SDL_SCANCODE_KP_3,
|
||||
/* 82 */ SDL_SCANCODE_KP_0,
|
||||
/* 83 */ SDL_SCANCODE_KP_PERIOD,
|
||||
0,
|
||||
/* 85 */ SDL_SCANCODE_UNKNOWN, /* KEY_ZENKAKUHANKAKU */
|
||||
/* 86 */ SDL_SCANCODE_NONUSBACKSLASH, /* KEY_102ND */
|
||||
/* 87 */ SDL_SCANCODE_F11,
|
||||
/* 88 */ SDL_SCANCODE_F12,
|
||||
/* 89 */ SDL_SCANCODE_INTERNATIONAL1, /* KEY_RO */
|
||||
/* 90 */ SDL_SCANCODE_LANG3, /* KEY_KATAKANA */
|
||||
/* 91 */ SDL_SCANCODE_LANG4, /* KEY_HIRAGANA */
|
||||
/* 92 */ SDL_SCANCODE_INTERNATIONAL4, /* KEY_HENKAN */
|
||||
/* 93 */ SDL_SCANCODE_INTERNATIONAL2, /* KEY_KATAKANAHIRAGANA */
|
||||
/* 94 */ SDL_SCANCODE_INTERNATIONAL5, /* KEY_MUHENKAN */
|
||||
/* 95 */ SDL_SCANCODE_INTERNATIONAL5, /* KEY_KPJPCOMMA */
|
||||
/* 96 */ SDL_SCANCODE_KP_ENTER,
|
||||
/* 97 */ SDL_SCANCODE_RCTRL,
|
||||
/* 98 */ SDL_SCANCODE_KP_DIVIDE,
|
||||
/* 99 */ SDL_SCANCODE_SYSREQ,
|
||||
/* 100 */ SDL_SCANCODE_RALT,
|
||||
/* 101 */ SDL_SCANCODE_UNKNOWN, /* KEY_LINEFEED */
|
||||
/* 102 */ SDL_SCANCODE_HOME,
|
||||
/* 103 */ SDL_SCANCODE_UP,
|
||||
/* 104 */ SDL_SCANCODE_PAGEUP,
|
||||
/* 105 */ SDL_SCANCODE_LEFT,
|
||||
/* 106 */ SDL_SCANCODE_RIGHT,
|
||||
/* 107 */ SDL_SCANCODE_END,
|
||||
/* 108 */ SDL_SCANCODE_DOWN,
|
||||
/* 109 */ SDL_SCANCODE_PAGEDOWN,
|
||||
/* 110 */ SDL_SCANCODE_INSERT,
|
||||
/* 111 */ SDL_SCANCODE_DELETE,
|
||||
/* 112 */ SDL_SCANCODE_UNKNOWN, /* KEY_MACRO */
|
||||
/* 113 */ SDL_SCANCODE_MUTE,
|
||||
/* 114 */ SDL_SCANCODE_VOLUMEDOWN,
|
||||
/* 115 */ SDL_SCANCODE_VOLUMEUP,
|
||||
/* 116 */ SDL_SCANCODE_POWER,
|
||||
/* 117 */ SDL_SCANCODE_KP_EQUALS,
|
||||
/* 118 */ SDL_SCANCODE_KP_PLUSMINUS,
|
||||
/* 119 */ SDL_SCANCODE_PAUSE,
|
||||
0,
|
||||
/* 121 */ SDL_SCANCODE_KP_COMMA,
|
||||
/* 122 */ SDL_SCANCODE_LANG1, /* KEY_HANGUEL */
|
||||
/* 123 */ SDL_SCANCODE_LANG2, /* KEY_HANJA */
|
||||
/* 124 */ SDL_SCANCODE_INTERNATIONAL3, /* KEY_YEN */
|
||||
/* 125 */ SDL_SCANCODE_LGUI,
|
||||
/* 126 */ SDL_SCANCODE_RGUI,
|
||||
/* 127 */ SDL_SCANCODE_UNKNOWN, /* KEY_COMPOSE */
|
||||
/* 128 */ SDL_SCANCODE_STOP,
|
||||
/* 129 */ SDL_SCANCODE_AGAIN,
|
||||
/* 130 */ SDL_SCANCODE_UNKNOWN, /* KEY_PROPS */
|
||||
/* 131 */ SDL_SCANCODE_UNDO,
|
||||
/* 132 */ SDL_SCANCODE_UNKNOWN, /* KEY_FRONT */
|
||||
/* 133 */ SDL_SCANCODE_COPY,
|
||||
/* 134 */ SDL_SCANCODE_UNKNOWN, /* KEY_OPEN */
|
||||
/* 135 */ SDL_SCANCODE_PASTE,
|
||||
/* 136 */ SDL_SCANCODE_FIND,
|
||||
/* 137 */ SDL_SCANCODE_CUT,
|
||||
/* 138 */ SDL_SCANCODE_HELP,
|
||||
/* 139 */ SDL_SCANCODE_MENU,
|
||||
/* 140 */ SDL_SCANCODE_CALCULATOR,
|
||||
/* 141 */ SDL_SCANCODE_UNKNOWN, /* KEY_SETUP */
|
||||
/* 142 */ SDL_SCANCODE_SLEEP,
|
||||
/* 143 */ SDL_SCANCODE_UNKNOWN, /* KEY_WAKEUP */
|
||||
/* 144 */ SDL_SCANCODE_UNKNOWN, /* KEY_FILE */
|
||||
/* 145 */ SDL_SCANCODE_UNKNOWN, /* KEY_SENDFILE */
|
||||
/* 146 */ SDL_SCANCODE_UNKNOWN, /* KEY_DELETEFILE */
|
||||
/* 147 */ SDL_SCANCODE_UNKNOWN, /* KEY_XFER */
|
||||
/* 148 */ SDL_SCANCODE_UNKNOWN, /* KEY_PROG1 */
|
||||
/* 149 */ SDL_SCANCODE_UNKNOWN, /* KEY_PROG2 */
|
||||
/* 150 */ SDL_SCANCODE_UNKNOWN, /* KEY_WWW */
|
||||
/* 151 */ SDL_SCANCODE_UNKNOWN, /* KEY_MSDOS */
|
||||
/* 152 */ SDL_SCANCODE_UNKNOWN, /* KEY_COFFEE */
|
||||
/* 153 */ SDL_SCANCODE_UNKNOWN, /* KEY_DIRECTION */
|
||||
/* 154 */ SDL_SCANCODE_UNKNOWN, /* KEY_CYCLEWINDOWS */
|
||||
/* 155 */ SDL_SCANCODE_MAIL,
|
||||
/* 156 */ SDL_SCANCODE_AC_BOOKMARKS,
|
||||
/* 157 */ SDL_SCANCODE_COMPUTER,
|
||||
/* 158 */ SDL_SCANCODE_AC_BACK,
|
||||
/* 159 */ SDL_SCANCODE_AC_FORWARD,
|
||||
/* 160 */ SDL_SCANCODE_UNKNOWN, /* KEY_CLOSECD */
|
||||
/* 161 */ SDL_SCANCODE_EJECT, /* KEY_EJECTCD */
|
||||
/* 162 */ SDL_SCANCODE_UNKNOWN, /* KEY_EJECTCLOSECD */
|
||||
/* 163 */ SDL_SCANCODE_AUDIONEXT, /* KEY_NEXTSONG */
|
||||
/* 164 */ SDL_SCANCODE_AUDIOPLAY, /* KEY_PLAYPAUSE */
|
||||
/* 165 */ SDL_SCANCODE_AUDIOPREV, /* KEY_PREVIOUSSONG */
|
||||
/* 166 */ SDL_SCANCODE_UNKNOWN, /* KEY_STOPCD */
|
||||
/* 167 */ SDL_SCANCODE_UNKNOWN, /* KEY_RECORD */
|
||||
/* 168 */ SDL_SCANCODE_UNKNOWN, /* KEY_REWIND */
|
||||
/* 169 */ SDL_SCANCODE_UNKNOWN, /* KEY_PHONE */
|
||||
/* 170 */ SDL_SCANCODE_UNKNOWN, /* KEY_ISO */
|
||||
/* 171 */ SDL_SCANCODE_UNKNOWN, /* KEY_CONFIG */
|
||||
/* 172 */ SDL_SCANCODE_AC_HOME,
|
||||
/* 173 */ SDL_SCANCODE_AC_REFRESH,
|
||||
/* 174 */ SDL_SCANCODE_UNKNOWN, /* KEY_EXIT */
|
||||
/* 175 */ SDL_SCANCODE_UNKNOWN, /* KEY_MOVE */
|
||||
/* 176 */ SDL_SCANCODE_UNKNOWN, /* KEY_EDIT */
|
||||
/* 177 */ SDL_SCANCODE_UNKNOWN, /* KEY_SCROLLUP */
|
||||
/* 178 */ SDL_SCANCODE_UNKNOWN, /* KEY_SCROLLDOWN */
|
||||
/* 179 */ SDL_SCANCODE_KP_LEFTPAREN,
|
||||
/* 180 */ SDL_SCANCODE_KP_RIGHTPAREN,
|
||||
/* 181 */ SDL_SCANCODE_UNKNOWN, /* KEY_NEW */
|
||||
/* 182 */ SDL_SCANCODE_UNKNOWN, /* KEY_REDO */
|
||||
/* 183 */ SDL_SCANCODE_F13,
|
||||
/* 184 */ SDL_SCANCODE_F14,
|
||||
/* 185 */ SDL_SCANCODE_F15,
|
||||
/* 186 */ SDL_SCANCODE_F16,
|
||||
/* 187 */ SDL_SCANCODE_F17,
|
||||
/* 188 */ SDL_SCANCODE_F18,
|
||||
/* 189 */ SDL_SCANCODE_F19,
|
||||
/* 190 */ SDL_SCANCODE_F20,
|
||||
/* 191 */ SDL_SCANCODE_F21,
|
||||
/* 192 */ SDL_SCANCODE_F22,
|
||||
/* 193 */ SDL_SCANCODE_F23,
|
||||
/* 194 */ SDL_SCANCODE_F24,
|
||||
0, 0, 0, 0,
|
||||
/* 200 */ SDL_SCANCODE_UNKNOWN, /* KEY_PLAYCD */
|
||||
/* 201 */ SDL_SCANCODE_UNKNOWN, /* KEY_PAUSECD */
|
||||
/* 202 */ SDL_SCANCODE_UNKNOWN, /* KEY_PROG3 */
|
||||
/* 203 */ SDL_SCANCODE_UNKNOWN, /* KEY_PROG4 */
|
||||
0,
|
||||
/* 205 */ SDL_SCANCODE_UNKNOWN, /* KEY_SUSPEND */
|
||||
/* 206 */ SDL_SCANCODE_UNKNOWN, /* KEY_CLOSE */
|
||||
/* 207 */ SDL_SCANCODE_UNKNOWN, /* KEY_PLAY */
|
||||
/* 208 */ SDL_SCANCODE_UNKNOWN, /* KEY_FASTFORWARD */
|
||||
/* 209 */ SDL_SCANCODE_UNKNOWN, /* KEY_BASSBOOST */
|
||||
/* 210 */ SDL_SCANCODE_UNKNOWN, /* KEY_PRINT */
|
||||
/* 211 */ SDL_SCANCODE_UNKNOWN, /* KEY_HP */
|
||||
/* 212 */ SDL_SCANCODE_UNKNOWN, /* KEY_CAMERA */
|
||||
/* 213 */ SDL_SCANCODE_UNKNOWN, /* KEY_SOUND */
|
||||
/* 214 */ SDL_SCANCODE_UNKNOWN, /* KEY_QUESTION */
|
||||
/* 215 */ SDL_SCANCODE_UNKNOWN, /* KEY_EMAIL */
|
||||
/* 216 */ SDL_SCANCODE_UNKNOWN, /* KEY_CHAT */
|
||||
/* 217 */ SDL_SCANCODE_AC_SEARCH,
|
||||
/* 218 */ SDL_SCANCODE_UNKNOWN, /* KEY_CONNECT */
|
||||
/* 219 */ SDL_SCANCODE_UNKNOWN, /* KEY_FINANCE */
|
||||
/* 220 */ SDL_SCANCODE_UNKNOWN, /* KEY_SPORT */
|
||||
/* 221 */ SDL_SCANCODE_UNKNOWN, /* KEY_SHOP */
|
||||
/* 222 */ SDL_SCANCODE_ALTERASE,
|
||||
/* 223 */ SDL_SCANCODE_CANCEL,
|
||||
/* 224 */ SDL_SCANCODE_BRIGHTNESSDOWN,
|
||||
/* 225 */ SDL_SCANCODE_BRIGHTNESSUP,
|
||||
/* 226 */ SDL_SCANCODE_UNKNOWN, /* KEY_MEDIA */
|
||||
/* 227 */ SDL_SCANCODE_DISPLAYSWITCH, /* KEY_SWITCHVIDEOMODE */
|
||||
/* 228 */ SDL_SCANCODE_KBDILLUMTOGGLE,
|
||||
/* 229 */ SDL_SCANCODE_KBDILLUMDOWN,
|
||||
/* 230 */ SDL_SCANCODE_KBDILLUMUP,
|
||||
/* 231 */ SDL_SCANCODE_UNKNOWN, /* KEY_SEND */
|
||||
/* 232 */ SDL_SCANCODE_UNKNOWN, /* KEY_REPLY */
|
||||
/* 233 */ SDL_SCANCODE_UNKNOWN, /* KEY_FORWARDMAIL */
|
||||
/* 234 */ SDL_SCANCODE_UNKNOWN, /* KEY_SAVE */
|
||||
/* 235 */ SDL_SCANCODE_UNKNOWN, /* KEY_DOCUMENTS */
|
||||
/* 236 */ SDL_SCANCODE_UNKNOWN, /* KEY_BATTERY */
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
55
src/events/scancodes_windows.h
Normal file
55
src/events/scancodes_windows.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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 "../../include/SDL_scancode.h"
|
||||
|
||||
/* Windows scancode to SDL scancode mapping table */
|
||||
/* derived from Microsoft scan code document, http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/scancode.doc */
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
static const SDL_Scancode windows_scancode_table[] =
|
||||
{
|
||||
// 0 1 2 3 4 5 6 7
|
||||
// 8 9 A B C D E F
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_ESCAPE, SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4, SDL_SCANCODE_5, SDL_SCANCODE_6, // 0
|
||||
SDL_SCANCODE_7, SDL_SCANCODE_8, SDL_SCANCODE_9, SDL_SCANCODE_0, SDL_SCANCODE_MINUS, SDL_SCANCODE_EQUALS, SDL_SCANCODE_BACKSPACE, SDL_SCANCODE_TAB, // 0
|
||||
|
||||
SDL_SCANCODE_Q, SDL_SCANCODE_W, SDL_SCANCODE_E, SDL_SCANCODE_R, SDL_SCANCODE_T, SDL_SCANCODE_Y, SDL_SCANCODE_U, SDL_SCANCODE_I, // 1
|
||||
SDL_SCANCODE_O, SDL_SCANCODE_P, SDL_SCANCODE_LEFTBRACKET, SDL_SCANCODE_RIGHTBRACKET, SDL_SCANCODE_RETURN, SDL_SCANCODE_LCTRL, SDL_SCANCODE_A, SDL_SCANCODE_S, // 1
|
||||
|
||||
SDL_SCANCODE_D, SDL_SCANCODE_F, SDL_SCANCODE_G, SDL_SCANCODE_H, SDL_SCANCODE_J, SDL_SCANCODE_K, SDL_SCANCODE_L, SDL_SCANCODE_SEMICOLON, // 2
|
||||
SDL_SCANCODE_APOSTROPHE, SDL_SCANCODE_GRAVE, SDL_SCANCODE_LSHIFT, SDL_SCANCODE_BACKSLASH, SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_C, SDL_SCANCODE_V, // 2
|
||||
|
||||
SDL_SCANCODE_B, SDL_SCANCODE_N, SDL_SCANCODE_M, SDL_SCANCODE_COMMA, SDL_SCANCODE_PERIOD, SDL_SCANCODE_SLASH, SDL_SCANCODE_RSHIFT, SDL_SCANCODE_PRINTSCREEN,// 3
|
||||
SDL_SCANCODE_LALT, SDL_SCANCODE_SPACE, SDL_SCANCODE_CAPSLOCK, SDL_SCANCODE_F1, SDL_SCANCODE_F2, SDL_SCANCODE_F3, SDL_SCANCODE_F4, SDL_SCANCODE_F5, // 3
|
||||
|
||||
SDL_SCANCODE_F6, SDL_SCANCODE_F7, SDL_SCANCODE_F8, SDL_SCANCODE_F9, SDL_SCANCODE_F10, SDL_SCANCODE_NUMLOCKCLEAR, SDL_SCANCODE_SCROLLLOCK, SDL_SCANCODE_HOME, // 4
|
||||
SDL_SCANCODE_UP, SDL_SCANCODE_PAGEUP, SDL_SCANCODE_KP_MINUS, SDL_SCANCODE_LEFT, SDL_SCANCODE_KP_5, SDL_SCANCODE_RIGHT, SDL_SCANCODE_KP_PLUS, SDL_SCANCODE_END, // 4
|
||||
|
||||
SDL_SCANCODE_DOWN, SDL_SCANCODE_PAGEDOWN, SDL_SCANCODE_INSERT, SDL_SCANCODE_DELETE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_NONUSBACKSLASH,SDL_SCANCODE_F11, // 5
|
||||
SDL_SCANCODE_F12, SDL_SCANCODE_PAUSE, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_LGUI, SDL_SCANCODE_RGUI, SDL_SCANCODE_APPLICATION, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 5
|
||||
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_F13, SDL_SCANCODE_F14, SDL_SCANCODE_F15, SDL_SCANCODE_F16, // 6
|
||||
SDL_SCANCODE_F17, SDL_SCANCODE_F18, SDL_SCANCODE_F19, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 6
|
||||
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, // 7
|
||||
SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN, SDL_SCANCODE_UNKNOWN // 7
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
421
src/events/scancodes_xfree86.h
Normal file
421
src/events/scancodes_xfree86.h
Normal file
@@ -0,0 +1,421 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2013 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 "../../include/SDL_scancode.h"
|
||||
|
||||
/* XFree86 key code to SDL scancode mapping table
|
||||
Sources:
|
||||
- atKeyNames.h from XFree86 source code
|
||||
*/
|
||||
/* *INDENT-OFF* */
|
||||
static const SDL_Scancode xfree86_scancode_table[] = {
|
||||
/* 0 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 1 */ SDL_SCANCODE_ESCAPE,
|
||||
/* 2 */ SDL_SCANCODE_1,
|
||||
/* 3 */ SDL_SCANCODE_2,
|
||||
/* 4 */ SDL_SCANCODE_3,
|
||||
/* 5 */ SDL_SCANCODE_4,
|
||||
/* 6 */ SDL_SCANCODE_5,
|
||||
/* 7 */ SDL_SCANCODE_6,
|
||||
/* 8 */ SDL_SCANCODE_7,
|
||||
/* 9 */ SDL_SCANCODE_8,
|
||||
/* 10 */ SDL_SCANCODE_9,
|
||||
/* 11 */ SDL_SCANCODE_0,
|
||||
/* 12 */ SDL_SCANCODE_MINUS,
|
||||
/* 13 */ SDL_SCANCODE_EQUALS,
|
||||
/* 14 */ SDL_SCANCODE_BACKSPACE,
|
||||
/* 15 */ SDL_SCANCODE_TAB,
|
||||
/* 16 */ SDL_SCANCODE_Q,
|
||||
/* 17 */ SDL_SCANCODE_W,
|
||||
/* 18 */ SDL_SCANCODE_E,
|
||||
/* 19 */ SDL_SCANCODE_R,
|
||||
/* 20 */ SDL_SCANCODE_T,
|
||||
/* 21 */ SDL_SCANCODE_Y,
|
||||
/* 22 */ SDL_SCANCODE_U,
|
||||
/* 23 */ SDL_SCANCODE_I,
|
||||
/* 24 */ SDL_SCANCODE_O,
|
||||
/* 25 */ SDL_SCANCODE_P,
|
||||
/* 26 */ SDL_SCANCODE_LEFTBRACKET,
|
||||
/* 27 */ SDL_SCANCODE_RIGHTBRACKET,
|
||||
/* 28 */ SDL_SCANCODE_RETURN,
|
||||
/* 29 */ SDL_SCANCODE_LCTRL,
|
||||
/* 30 */ SDL_SCANCODE_A,
|
||||
/* 31 */ SDL_SCANCODE_S,
|
||||
/* 32 */ SDL_SCANCODE_D,
|
||||
/* 33 */ SDL_SCANCODE_F,
|
||||
/* 34 */ SDL_SCANCODE_G,
|
||||
/* 35 */ SDL_SCANCODE_H,
|
||||
/* 36 */ SDL_SCANCODE_J,
|
||||
/* 37 */ SDL_SCANCODE_K,
|
||||
/* 38 */ SDL_SCANCODE_L,
|
||||
/* 39 */ SDL_SCANCODE_SEMICOLON,
|
||||
/* 40 */ SDL_SCANCODE_APOSTROPHE,
|
||||
/* 41 */ SDL_SCANCODE_GRAVE,
|
||||
/* 42 */ SDL_SCANCODE_LSHIFT,
|
||||
/* 43 */ SDL_SCANCODE_BACKSLASH,
|
||||
/* 44 */ SDL_SCANCODE_Z,
|
||||
/* 45 */ SDL_SCANCODE_X,
|
||||
/* 46 */ SDL_SCANCODE_C,
|
||||
/* 47 */ SDL_SCANCODE_V,
|
||||
/* 48 */ SDL_SCANCODE_B,
|
||||
/* 49 */ SDL_SCANCODE_N,
|
||||
/* 50 */ SDL_SCANCODE_M,
|
||||
/* 51 */ SDL_SCANCODE_COMMA,
|
||||
/* 52 */ SDL_SCANCODE_PERIOD,
|
||||
/* 53 */ SDL_SCANCODE_SLASH,
|
||||
/* 54 */ SDL_SCANCODE_RSHIFT,
|
||||
/* 55 */ SDL_SCANCODE_KP_MULTIPLY,
|
||||
/* 56 */ SDL_SCANCODE_LALT,
|
||||
/* 57 */ SDL_SCANCODE_SPACE,
|
||||
/* 58 */ SDL_SCANCODE_CAPSLOCK,
|
||||
/* 59 */ SDL_SCANCODE_F1,
|
||||
/* 60 */ SDL_SCANCODE_F2,
|
||||
/* 61 */ SDL_SCANCODE_F3,
|
||||
/* 62 */ SDL_SCANCODE_F4,
|
||||
/* 63 */ SDL_SCANCODE_F5,
|
||||
/* 64 */ SDL_SCANCODE_F6,
|
||||
/* 65 */ SDL_SCANCODE_F7,
|
||||
/* 66 */ SDL_SCANCODE_F8,
|
||||
/* 67 */ SDL_SCANCODE_F9,
|
||||
/* 68 */ SDL_SCANCODE_F10,
|
||||
/* 69 */ SDL_SCANCODE_NUMLOCKCLEAR,
|
||||
/* 70 */ SDL_SCANCODE_SCROLLLOCK,
|
||||
/* 71 */ SDL_SCANCODE_KP_7,
|
||||
/* 72 */ SDL_SCANCODE_KP_8,
|
||||
/* 73 */ SDL_SCANCODE_KP_9,
|
||||
/* 74 */ SDL_SCANCODE_KP_MINUS,
|
||||
/* 75 */ SDL_SCANCODE_KP_4,
|
||||
/* 76 */ SDL_SCANCODE_KP_5,
|
||||
/* 77 */ SDL_SCANCODE_KP_6,
|
||||
/* 78 */ SDL_SCANCODE_KP_PLUS,
|
||||
/* 79 */ SDL_SCANCODE_KP_1,
|
||||
/* 80 */ SDL_SCANCODE_KP_2,
|
||||
/* 81 */ SDL_SCANCODE_KP_3,
|
||||
/* 82 */ SDL_SCANCODE_KP_0,
|
||||
/* 83 */ SDL_SCANCODE_KP_PERIOD,
|
||||
/* 84 */ SDL_SCANCODE_SYSREQ,
|
||||
/* 85 */ SDL_SCANCODE_MODE,
|
||||
/* 86 */ SDL_SCANCODE_NONUSBACKSLASH,
|
||||
/* 87 */ SDL_SCANCODE_F11,
|
||||
/* 88 */ SDL_SCANCODE_F12,
|
||||
/* 89 */ SDL_SCANCODE_HOME,
|
||||
/* 90 */ SDL_SCANCODE_UP,
|
||||
/* 91 */ SDL_SCANCODE_PAGEUP,
|
||||
/* 92 */ SDL_SCANCODE_LEFT,
|
||||
/* 93 */ SDL_SCANCODE_BRIGHTNESSDOWN, /* on PowerBook G4 / KEY_Begin */
|
||||
/* 94 */ SDL_SCANCODE_RIGHT,
|
||||
/* 95 */ SDL_SCANCODE_END,
|
||||
/* 96 */ SDL_SCANCODE_DOWN,
|
||||
/* 97 */ SDL_SCANCODE_PAGEDOWN,
|
||||
/* 98 */ SDL_SCANCODE_INSERT,
|
||||
/* 99 */ SDL_SCANCODE_DELETE,
|
||||
/* 100 */ SDL_SCANCODE_KP_ENTER,
|
||||
/* 101 */ SDL_SCANCODE_RCTRL,
|
||||
/* 102 */ SDL_SCANCODE_PAUSE,
|
||||
/* 103 */ SDL_SCANCODE_PRINTSCREEN,
|
||||
/* 104 */ SDL_SCANCODE_KP_DIVIDE,
|
||||
/* 105 */ SDL_SCANCODE_RALT,
|
||||
/* 106 */ SDL_SCANCODE_UNKNOWN, /* BREAK */
|
||||
/* 107 */ SDL_SCANCODE_LGUI,
|
||||
/* 108 */ SDL_SCANCODE_RGUI,
|
||||
/* 109 */ SDL_SCANCODE_APPLICATION,
|
||||
/* 110 */ SDL_SCANCODE_F13,
|
||||
/* 111 */ SDL_SCANCODE_F14,
|
||||
/* 112 */ SDL_SCANCODE_F15,
|
||||
/* 113 */ SDL_SCANCODE_F16,
|
||||
/* 114 */ SDL_SCANCODE_F17,
|
||||
/* 115 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 116 */ SDL_SCANCODE_UNKNOWN, /* is translated to XK_ISO_Level3_Shift by my X server, but I have no keyboard that generates this code, so I don't know what the correct SDL_SCANCODE_* for it is */
|
||||
/* 117 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 118 */ SDL_SCANCODE_KP_EQUALS,
|
||||
/* 119 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 120 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 121 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 122 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 123 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 124 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 125 */ SDL_SCANCODE_INTERNATIONAL3, /* Yen */
|
||||
/* 126 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 127 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 128 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 129 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 130 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 131 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 132 */ SDL_SCANCODE_POWER,
|
||||
/* 133 */ SDL_SCANCODE_MUTE,
|
||||
/* 134 */ SDL_SCANCODE_VOLUMEDOWN,
|
||||
/* 135 */ SDL_SCANCODE_VOLUMEUP,
|
||||
/* 136 */ SDL_SCANCODE_HELP,
|
||||
/* 137 */ SDL_SCANCODE_STOP,
|
||||
/* 138 */ SDL_SCANCODE_AGAIN,
|
||||
/* 139 */ SDL_SCANCODE_UNKNOWN, /* PROPS */
|
||||
/* 140 */ SDL_SCANCODE_UNDO,
|
||||
/* 141 */ SDL_SCANCODE_UNKNOWN, /* FRONT */
|
||||
/* 142 */ SDL_SCANCODE_COPY,
|
||||
/* 143 */ SDL_SCANCODE_UNKNOWN, /* OPEN */
|
||||
/* 144 */ SDL_SCANCODE_PASTE,
|
||||
/* 145 */ SDL_SCANCODE_FIND,
|
||||
/* 146 */ SDL_SCANCODE_CUT,
|
||||
};
|
||||
|
||||
/* for wireless usb keyboard (manufacturer TRUST) without numpad. */
|
||||
static const SDL_Scancode xfree86_scancode_table2[] = {
|
||||
/* 0 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 1 */ SDL_SCANCODE_ESCAPE,
|
||||
/* 2 */ SDL_SCANCODE_1,
|
||||
/* 3 */ SDL_SCANCODE_2,
|
||||
/* 4 */ SDL_SCANCODE_3,
|
||||
/* 5 */ SDL_SCANCODE_4,
|
||||
/* 6 */ SDL_SCANCODE_5,
|
||||
/* 7 */ SDL_SCANCODE_6,
|
||||
/* 8 */ SDL_SCANCODE_7,
|
||||
/* 9 */ SDL_SCANCODE_8,
|
||||
/* 10 */ SDL_SCANCODE_9,
|
||||
/* 11 */ SDL_SCANCODE_0,
|
||||
/* 12 */ SDL_SCANCODE_MINUS,
|
||||
/* 13 */ SDL_SCANCODE_EQUALS,
|
||||
/* 14 */ SDL_SCANCODE_BACKSPACE,
|
||||
/* 15 */ SDL_SCANCODE_TAB,
|
||||
/* 16 */ SDL_SCANCODE_Q,
|
||||
/* 17 */ SDL_SCANCODE_W,
|
||||
/* 18 */ SDL_SCANCODE_E,
|
||||
/* 19 */ SDL_SCANCODE_R,
|
||||
/* 20 */ SDL_SCANCODE_T,
|
||||
/* 21 */ SDL_SCANCODE_Y,
|
||||
/* 22 */ SDL_SCANCODE_U,
|
||||
/* 23 */ SDL_SCANCODE_I,
|
||||
/* 24 */ SDL_SCANCODE_O,
|
||||
/* 25 */ SDL_SCANCODE_P,
|
||||
/* 26 */ SDL_SCANCODE_LEFTBRACKET,
|
||||
/* 27 */ SDL_SCANCODE_RIGHTBRACKET,
|
||||
/* 28 */ SDL_SCANCODE_RETURN,
|
||||
/* 29 */ SDL_SCANCODE_LCTRL,
|
||||
/* 30 */ SDL_SCANCODE_A,
|
||||
/* 31 */ SDL_SCANCODE_S,
|
||||
/* 32 */ SDL_SCANCODE_D,
|
||||
/* 33 */ SDL_SCANCODE_F,
|
||||
/* 34 */ SDL_SCANCODE_G,
|
||||
/* 35 */ SDL_SCANCODE_H,
|
||||
/* 36 */ SDL_SCANCODE_J,
|
||||
/* 37 */ SDL_SCANCODE_K,
|
||||
/* 38 */ SDL_SCANCODE_L,
|
||||
/* 39 */ SDL_SCANCODE_SEMICOLON,
|
||||
/* 40 */ SDL_SCANCODE_APOSTROPHE,
|
||||
/* 41 */ SDL_SCANCODE_GRAVE,
|
||||
/* 42 */ SDL_SCANCODE_LSHIFT,
|
||||
/* 43 */ SDL_SCANCODE_BACKSLASH,
|
||||
/* 44 */ SDL_SCANCODE_Z,
|
||||
/* 45 */ SDL_SCANCODE_X,
|
||||
/* 46 */ SDL_SCANCODE_C,
|
||||
/* 47 */ SDL_SCANCODE_V,
|
||||
/* 48 */ SDL_SCANCODE_B,
|
||||
/* 49 */ SDL_SCANCODE_N,
|
||||
/* 50 */ SDL_SCANCODE_M,
|
||||
/* 51 */ SDL_SCANCODE_COMMA,
|
||||
/* 52 */ SDL_SCANCODE_PERIOD,
|
||||
/* 53 */ SDL_SCANCODE_SLASH,
|
||||
/* 54 */ SDL_SCANCODE_RSHIFT,
|
||||
/* 55 */ SDL_SCANCODE_KP_MULTIPLY,
|
||||
/* 56 */ SDL_SCANCODE_LALT,
|
||||
/* 57 */ SDL_SCANCODE_SPACE,
|
||||
/* 58 */ SDL_SCANCODE_CAPSLOCK,
|
||||
/* 59 */ SDL_SCANCODE_F1,
|
||||
/* 60 */ SDL_SCANCODE_F2,
|
||||
/* 61 */ SDL_SCANCODE_F3,
|
||||
/* 62 */ SDL_SCANCODE_F4,
|
||||
/* 63 */ SDL_SCANCODE_F5,
|
||||
/* 64 */ SDL_SCANCODE_F6,
|
||||
/* 65 */ SDL_SCANCODE_F7,
|
||||
/* 66 */ SDL_SCANCODE_F8,
|
||||
/* 67 */ SDL_SCANCODE_F9,
|
||||
/* 68 */ SDL_SCANCODE_F10,
|
||||
/* 69 */ SDL_SCANCODE_NUMLOCKCLEAR,
|
||||
/* 70 */ SDL_SCANCODE_SCROLLLOCK,
|
||||
/* 71 */ SDL_SCANCODE_KP_7,
|
||||
/* 72 */ SDL_SCANCODE_KP_8,
|
||||
/* 73 */ SDL_SCANCODE_KP_9,
|
||||
/* 74 */ SDL_SCANCODE_KP_MINUS,
|
||||
/* 75 */ SDL_SCANCODE_KP_4,
|
||||
/* 76 */ SDL_SCANCODE_KP_5,
|
||||
/* 77 */ SDL_SCANCODE_KP_6,
|
||||
/* 78 */ SDL_SCANCODE_KP_PLUS,
|
||||
/* 79 */ SDL_SCANCODE_KP_1,
|
||||
/* 80 */ SDL_SCANCODE_KP_2,
|
||||
/* 81 */ SDL_SCANCODE_KP_3,
|
||||
/* 82 */ SDL_SCANCODE_KP_0,
|
||||
/* 83 */ SDL_SCANCODE_KP_PERIOD,
|
||||
/* 84 */ SDL_SCANCODE_SYSREQ, /* ???? */
|
||||
/* 85 */ SDL_SCANCODE_MODE, /* ???? */
|
||||
/* 86 */ SDL_SCANCODE_NONUSBACKSLASH,
|
||||
/* 87 */ SDL_SCANCODE_F11,
|
||||
/* 88 */ SDL_SCANCODE_F12,
|
||||
/* 89 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 90 */ SDL_SCANCODE_UNKNOWN, /* Katakana */
|
||||
/* 91 */ SDL_SCANCODE_UNKNOWN, /* Hiragana */
|
||||
/* 92 */ SDL_SCANCODE_UNKNOWN, /* Henkan_Mode */
|
||||
/* 93 */ SDL_SCANCODE_UNKNOWN, /* Hiragana_Katakana */
|
||||
/* 94 */ SDL_SCANCODE_UNKNOWN, /* Muhenkan */
|
||||
/* 95 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 96 */ SDL_SCANCODE_KP_ENTER,
|
||||
/* 97 */ SDL_SCANCODE_RCTRL,
|
||||
/* 98 */ SDL_SCANCODE_KP_DIVIDE,
|
||||
/* 99 */ SDL_SCANCODE_PRINTSCREEN,
|
||||
/* 100 */ SDL_SCANCODE_RALT, /* ISO_Level3_Shift, ALTGR, RALT */
|
||||
/* 101 */ SDL_SCANCODE_UNKNOWN, /* Linefeed */
|
||||
/* 102 */ SDL_SCANCODE_HOME,
|
||||
/* 103 */ SDL_SCANCODE_UP,
|
||||
/* 104 */ SDL_SCANCODE_PAGEUP,
|
||||
/* 105 */ SDL_SCANCODE_LEFT,
|
||||
/* 106 */ SDL_SCANCODE_RIGHT,
|
||||
/* 107 */ SDL_SCANCODE_END,
|
||||
/* 108 */ SDL_SCANCODE_DOWN,
|
||||
/* 109 */ SDL_SCANCODE_PAGEDOWN,
|
||||
/* 110 */ SDL_SCANCODE_INSERT,
|
||||
/* 111 */ SDL_SCANCODE_DELETE,
|
||||
/* 112 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 113 */ SDL_SCANCODE_MUTE,
|
||||
/* 114 */ SDL_SCANCODE_VOLUMEDOWN,
|
||||
/* 115 */ SDL_SCANCODE_VOLUMEUP,
|
||||
/* 116 */ SDL_SCANCODE_POWER,
|
||||
/* 117 */ SDL_SCANCODE_KP_EQUALS,
|
||||
/* 118 */ SDL_SCANCODE_UNKNOWN, /* plusminus */
|
||||
/* 119 */ SDL_SCANCODE_PAUSE,
|
||||
/* 120 */ SDL_SCANCODE_UNKNOWN, /* XF86LaunchA */
|
||||
/* 121 */ SDL_SCANCODE_UNKNOWN, /* KP_Decimal */
|
||||
/* 122 */ SDL_SCANCODE_UNKNOWN, /* Hangul */
|
||||
/* 123 */ SDL_SCANCODE_UNKNOWN, /* Hangul_Hanja */
|
||||
/* 124 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 125 */ SDL_SCANCODE_LGUI,
|
||||
/* 126 */ SDL_SCANCODE_RGUI,
|
||||
/* 127 */ SDL_SCANCODE_APPLICATION,
|
||||
/* 128 */ SDL_SCANCODE_CANCEL,
|
||||
/* 129 */ SDL_SCANCODE_AGAIN,
|
||||
/* 130 */ SDL_SCANCODE_UNKNOWN, /* SunProps */
|
||||
/* 131 */ SDL_SCANCODE_UNDO,
|
||||
/* 132 */ SDL_SCANCODE_UNKNOWN, /* SunFront */
|
||||
/* 133 */ SDL_SCANCODE_COPY,
|
||||
/* 134 */ SDL_SCANCODE_UNKNOWN, /* SunOpen */
|
||||
/* 135 */ SDL_SCANCODE_PASTE,
|
||||
/* 136 */ SDL_SCANCODE_FIND,
|
||||
/* 137 */ SDL_SCANCODE_CUT,
|
||||
/* 138 */ SDL_SCANCODE_HELP,
|
||||
/* 139 */ SDL_SCANCODE_UNKNOWN, /* XF86MenuKB */
|
||||
/* 140 */ SDL_SCANCODE_CALCULATOR,
|
||||
/* 141 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 142 */ SDL_SCANCODE_SLEEP,
|
||||
/* 143 */ SDL_SCANCODE_UNKNOWN, /* XF86WakeUp */
|
||||
/* 144 */ SDL_SCANCODE_UNKNOWN, /* XF86Explorer */
|
||||
/* 145 */ SDL_SCANCODE_UNKNOWN, /* XF86Send */
|
||||
/* 146 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 147 */ SDL_SCANCODE_UNKNOWN, /* XF86Xfer */
|
||||
/* 148 */ SDL_SCANCODE_APP1, /* XF86Launch1 */
|
||||
/* 149 */ SDL_SCANCODE_APP2, /* XF86Launch2 */
|
||||
/* 150 */ SDL_SCANCODE_WWW,
|
||||
/* 151 */ SDL_SCANCODE_UNKNOWN, /* XF86DOS */
|
||||
/* 152 */ SDL_SCANCODE_UNKNOWN, /* XF86ScreenSaver */
|
||||
/* 153 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 154 */ SDL_SCANCODE_UNKNOWN, /* XF86RotateWindows */
|
||||
/* 155 */ SDL_SCANCODE_MAIL,
|
||||
/* 156 */ SDL_SCANCODE_AC_BOOKMARKS, /* XF86Favorites */
|
||||
/* 157 */ SDL_SCANCODE_COMPUTER,
|
||||
/* 158 */ SDL_SCANCODE_AC_BACK,
|
||||
/* 159 */ SDL_SCANCODE_AC_FORWARD,
|
||||
/* 160 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 161 */ SDL_SCANCODE_EJECT,
|
||||
/* 162 */ SDL_SCANCODE_EJECT,
|
||||
/* 163 */ SDL_SCANCODE_AUDIONEXT,
|
||||
/* 164 */ SDL_SCANCODE_AUDIOPLAY,
|
||||
/* 165 */ SDL_SCANCODE_AUDIOPREV,
|
||||
/* 166 */ SDL_SCANCODE_AUDIOSTOP,
|
||||
/* 167 */ SDL_SCANCODE_UNKNOWN, /* XF86AudioRecord */
|
||||
/* 168 */ SDL_SCANCODE_UNKNOWN, /* XF86AudioRewind */
|
||||
/* 169 */ SDL_SCANCODE_UNKNOWN, /* XF86Phone */
|
||||
/* 170 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 171 */ SDL_SCANCODE_F13, /* XF86Tools */
|
||||
/* 172 */ SDL_SCANCODE_AC_HOME,
|
||||
/* 173 */ SDL_SCANCODE_AC_REFRESH,
|
||||
/* 174 */ SDL_SCANCODE_UNKNOWN, /* XF86Close */
|
||||
/* 175 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 176 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 177 */ SDL_SCANCODE_UNKNOWN, /* XF86ScrollUp */
|
||||
/* 178 */ SDL_SCANCODE_UNKNOWN, /* XF86ScrollDown */
|
||||
/* 179 */ SDL_SCANCODE_UNKNOWN, /* parenleft */
|
||||
/* 180 */ SDL_SCANCODE_UNKNOWN, /* parenright */
|
||||
/* 181 */ SDL_SCANCODE_UNKNOWN, /* XF86New */
|
||||
/* 182 */ SDL_SCANCODE_AGAIN,
|
||||
/* 183 */ SDL_SCANCODE_F13, /* XF86Tools */
|
||||
/* 184 */ SDL_SCANCODE_F14, /* XF86Launch5 */
|
||||
/* 185 */ SDL_SCANCODE_F15, /* XF86Launch6 */
|
||||
/* 186 */ SDL_SCANCODE_F16, /* XF86Launch7 */
|
||||
/* 187 */ SDL_SCANCODE_F17, /* XF86Launch8 */
|
||||
/* 188 */ SDL_SCANCODE_F18, /* XF86Launch9 */
|
||||
/* 189 */ SDL_SCANCODE_F19, /* null keysym */
|
||||
/* 190 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 191 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 192 */ SDL_SCANCODE_UNKNOWN, /* XF86TouchpadToggle */
|
||||
/* 193 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 194 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 195 */ SDL_SCANCODE_MODE,
|
||||
/* 196 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 197 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 198 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 199 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 200 */ SDL_SCANCODE_AUDIOPLAY,
|
||||
/* 201 */ SDL_SCANCODE_UNKNOWN, /* XF86AudioPause */
|
||||
/* 202 */ SDL_SCANCODE_UNKNOWN, /* XF86Launch3 */
|
||||
/* 203 */ SDL_SCANCODE_UNKNOWN, /* XF86Launch4 */
|
||||
/* 204 */ SDL_SCANCODE_UNKNOWN, /* XF86LaunchB */
|
||||
/* 205 */ SDL_SCANCODE_UNKNOWN, /* XF86Suspend */
|
||||
/* 206 */ SDL_SCANCODE_UNKNOWN, /* XF86Close */
|
||||
/* 207 */ SDL_SCANCODE_AUDIOPLAY,
|
||||
/* 208 */ SDL_SCANCODE_AUDIONEXT,
|
||||
/* 209 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 210 */ SDL_SCANCODE_PRINTSCREEN,
|
||||
/* 211 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 212 */ SDL_SCANCODE_UNKNOWN, /* XF86WebCam */
|
||||
/* 213 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 214 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 215 */ SDL_SCANCODE_MAIL,
|
||||
/* 216 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 217 */ SDL_SCANCODE_AC_SEARCH,
|
||||
/* 218 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 219 */ SDL_SCANCODE_UNKNOWN, /* XF86Finance */
|
||||
/* 220 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 221 */ SDL_SCANCODE_UNKNOWN, /* XF86Shop */
|
||||
/* 222 */ SDL_SCANCODE_UNKNOWN,
|
||||
/* 223 */ SDL_SCANCODE_STOP,
|
||||
/* 224 */ SDL_SCANCODE_BRIGHTNESSDOWN,
|
||||
/* 225 */ SDL_SCANCODE_BRIGHTNESSUP,
|
||||
/* 226 */ SDL_SCANCODE_MEDIASELECT,
|
||||
/* 227 */ SDL_SCANCODE_DISPLAYSWITCH,
|
||||
/* 228 */ SDL_SCANCODE_KBDILLUMTOGGLE,
|
||||
/* 229 */ SDL_SCANCODE_KBDILLUMDOWN,
|
||||
/* 230 */ SDL_SCANCODE_KBDILLUMUP,
|
||||
/* 231 */ SDL_SCANCODE_UNKNOWN, /* XF86Send */
|
||||
/* 232 */ SDL_SCANCODE_UNKNOWN, /* XF86Reply */
|
||||
/* 233 */ SDL_SCANCODE_UNKNOWN, /* XF86MailForward */
|
||||
/* 234 */ SDL_SCANCODE_UNKNOWN, /* XF86Save */
|
||||
/* 235 */ SDL_SCANCODE_UNKNOWN, /* XF86Documents */
|
||||
/* 236 */ SDL_SCANCODE_UNKNOWN, /* XF86Battery */
|
||||
/* 237 */ SDL_SCANCODE_UNKNOWN, /* XF86Bluetooth */
|
||||
/* 238 */ SDL_SCANCODE_UNKNOWN, /* XF86WLAN */
|
||||
};
|
||||
|
||||
/* *INDENT-ON* */
|
||||
Reference in New Issue
Block a user