mirror of
https://github.com/love2d/megasource.git
synced 2026-08-19 04:05:09 +02:00
Added SDL 1c0f6952e65e.
This commit is contained in:
@@ -83,19 +83,6 @@ static struct
|
||||
} SDL_EventQ = { NULL, SDL_TRUE };
|
||||
|
||||
|
||||
static SDL_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
|
||||
@@ -315,7 +302,6 @@ SDL_PeepEvents(SDL_Event * events, int numevents, SDL_eventaction action,
|
||||
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;
|
||||
@@ -403,7 +389,7 @@ SDL_PumpEvents(void)
|
||||
}
|
||||
#if !SDL_JOYSTICK_DISABLED
|
||||
/* Check for joystick state change */
|
||||
if (SDL_ShouldPollJoystick()) {
|
||||
if ((!SDL_disabled_events[SDL_JOYAXISMOTION >> 8] || SDL_JoystickEventState(SDL_QUERY))) {
|
||||
SDL_JoystickUpdate();
|
||||
}
|
||||
#endif
|
||||
@@ -550,7 +536,7 @@ SDL_DelEventWatch(SDL_EventFilter filter, void *userdata)
|
||||
void
|
||||
SDL_FilterEvents(SDL_EventFilter filter, void *userdata)
|
||||
{
|
||||
if (SDL_LockMutex(SDL_EventQ.lock) == 0) {
|
||||
if (SDL_EventQ.lock && SDL_LockMutex(SDL_EventQ.lock) == 0) {
|
||||
SDL_EventEntry *entry, *next;
|
||||
for (entry = SDL_EventQ.head; entry; entry = next) {
|
||||
next = entry->next;
|
||||
|
||||
@@ -27,13 +27,9 @@
|
||||
#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 */
|
||||
|
||||
@@ -137,7 +133,7 @@ int SDL_SaveAllDollarTemplates(SDL_RWops *dst)
|
||||
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], dst);
|
||||
rtrn += SaveTemplate(&touch->dollarTemplate[j], dst);
|
||||
}
|
||||
}
|
||||
return rtrn;
|
||||
@@ -149,8 +145,8 @@ int SDL_SaveDollarTemplate(SDL_GestureID gestureId, SDL_RWops *dst)
|
||||
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], dst);
|
||||
if (touch->dollarTemplate[j].hash == gestureId) {
|
||||
return SaveTemplate(&touch->dollarTemplate[j], dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -454,8 +450,8 @@ static int SDL_SendGestureDollar(SDL_GestureTouch* touch,
|
||||
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.x = touch->centroid.x;
|
||||
event.dgesture.y = touch->centroid.y;
|
||||
event.dgesture.gestureId = gestureId;
|
||||
event.dgesture.error = error;
|
||||
/* A finger came up to trigger this event. */
|
||||
@@ -477,7 +473,6 @@ static int SDL_SendDollarRecord(SDL_GestureTouch* touch,SDL_GestureID gestureId)
|
||||
void SDL_GestureProcessEvent(SDL_Event* event)
|
||||
{
|
||||
float x,y;
|
||||
SDL_FloatPoint path[DOLLARNPOINTS];
|
||||
int index;
|
||||
int i;
|
||||
float pathDx, pathDy;
|
||||
@@ -501,6 +496,8 @@ void SDL_GestureProcessEvent(SDL_Event* event)
|
||||
|
||||
/* Finger Up */
|
||||
if (event->type == SDL_FINGERUP) {
|
||||
SDL_FloatPoint path[DOLLARNPOINTS];
|
||||
|
||||
inTouch->numDownFingers--;
|
||||
|
||||
#ifdef ENABLE_DOLLAR
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "SDL_timer.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_events_c.h"
|
||||
#include "SDL_assert.h"
|
||||
#include "../video/SDL_sysvideo.h"
|
||||
|
||||
|
||||
@@ -619,6 +620,16 @@ SDL_SetKeyboardFocus(SDL_Window * window)
|
||||
|
||||
/* See if the current window has lost focus */
|
||||
if (keyboard->focus && keyboard->focus != window) {
|
||||
|
||||
/* new window shouldn't think it has mouse captured. */
|
||||
SDL_assert(!window || !(window->flags & SDL_WINDOW_MOUSE_CAPTURE));
|
||||
|
||||
/* old window must lose an existing mouse capture. */
|
||||
if (keyboard->focus->flags & SDL_WINDOW_MOUSE_CAPTURE) {
|
||||
SDL_CaptureMouse(SDL_FALSE); /* drop the capture. */
|
||||
SDL_assert(!(keyboard->focus->flags & SDL_WINDOW_MOUSE_CAPTURE));
|
||||
}
|
||||
|
||||
SDL_SendWindowEvent(keyboard->focus, SDL_WINDOWEVENT_FOCUS_LOST,
|
||||
0, 0);
|
||||
|
||||
|
||||
@@ -140,14 +140,14 @@ 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_bool inWindow = SDL_TRUE;
|
||||
|
||||
SDL_GetWindowSize(window, &w, &h);
|
||||
if (x < 0 || y < 0 || x >= w || y >= h) {
|
||||
inWindow = SDL_FALSE;
|
||||
} else {
|
||||
inWindow = SDL_TRUE;
|
||||
if (window && ((window->flags & SDL_WINDOW_MOUSE_CAPTURE) == 0)) {
|
||||
int w, h;
|
||||
SDL_GetWindowSize(window, &w, &h);
|
||||
if (x < 0 || y < 0 || x >= w || y >= h) {
|
||||
inWindow = SDL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Linux doesn't give you mouse events outside your window unless you grab
|
||||
@@ -204,7 +204,6 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
|
||||
int posted;
|
||||
int xrel;
|
||||
int yrel;
|
||||
int x_max = 0, y_max = 0;
|
||||
|
||||
if (mouse->relative_mode_warp) {
|
||||
int center_x = 0, center_y = 0;
|
||||
@@ -246,23 +245,29 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
|
||||
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,
|
||||
unless we have the mouse captured. */
|
||||
if (window && ((window->flags & SDL_WINDOW_MOUSE_CAPTURE) == 0)) {
|
||||
int x_max = 0, y_max = 0;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
// !!! FIXME: shouldn't this be (window) instead of (mouse->focus)?
|
||||
SDL_GetWindowSize(mouse->focus, &x_max, &y_max);
|
||||
--x_max;
|
||||
--y_max;
|
||||
|
||||
if (mouse->y > y_max) {
|
||||
mouse->y = y_max;
|
||||
}
|
||||
if (mouse->y < 0) {
|
||||
mouse->y = 0;
|
||||
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;
|
||||
@@ -298,10 +303,11 @@ static SDL_MouseClickState *GetMouseClickState(SDL_Mouse *mouse, Uint8 button)
|
||||
{
|
||||
if (button >= mouse->num_clickstates) {
|
||||
int i, count = button + 1;
|
||||
mouse->clickstate = (SDL_MouseClickState *)SDL_realloc(mouse->clickstate, count * sizeof(*mouse->clickstate));
|
||||
if (!mouse->clickstate) {
|
||||
SDL_MouseClickState *clickstate = (SDL_MouseClickState *)SDL_realloc(mouse->clickstate, count * sizeof(*mouse->clickstate));
|
||||
if (!clickstate) {
|
||||
return NULL;
|
||||
}
|
||||
mouse->clickstate = clickstate;
|
||||
|
||||
for (i = mouse->num_clickstates; i < count; ++i) {
|
||||
SDL_zero(mouse->clickstate[i]);
|
||||
@@ -392,7 +398,7 @@ SDL_SendMouseButton(SDL_Window * window, SDL_MouseID mouseID, Uint8 state, Uint8
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y)
|
||||
SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
int posted;
|
||||
@@ -414,6 +420,7 @@ SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y)
|
||||
event.wheel.which = mouseID;
|
||||
event.wheel.x = x;
|
||||
event.wheel.y = y;
|
||||
event.wheel.direction = (Uint32)direction;
|
||||
posted = (SDL_PushEvent(&event) > 0);
|
||||
}
|
||||
return posted;
|
||||
@@ -425,6 +432,9 @@ SDL_MouseQuit(void)
|
||||
SDL_Cursor *cursor, *next;
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
if (mouse->CaptureMouse) {
|
||||
SDL_CaptureMouse(SDL_FALSE);
|
||||
}
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
SDL_ShowCursor(1);
|
||||
|
||||
@@ -476,16 +486,42 @@ SDL_GetRelativeMouseState(int *x, int *y)
|
||||
return mouse->buttonstate;
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_GetGlobalMouseState(int *x, int *y)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
int tmpx, tmpy;
|
||||
|
||||
/* make sure these are never NULL for the backend implementations... */
|
||||
if (!x) {
|
||||
x = &tmpx;
|
||||
}
|
||||
if (!y) {
|
||||
y = &tmpy;
|
||||
}
|
||||
|
||||
*x = *y = 0;
|
||||
|
||||
if (!mouse->GetGlobalMouseState) {
|
||||
SDL_assert(0 && "This should really be implemented for every target.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return mouse->GetGlobalMouseState(x, y);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
if ( window == NULL )
|
||||
if (window == NULL) {
|
||||
window = mouse->focus;
|
||||
}
|
||||
|
||||
if ( window == NULL )
|
||||
if (window == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mouse->WarpMouse) {
|
||||
mouse->WarpMouse(window, x, y);
|
||||
@@ -494,6 +530,16 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_WarpMouseGlobal(int x, int y)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
|
||||
if (mouse->WarpMouseGlobal) {
|
||||
mouse->WarpMouseGlobal(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
ShouldUseRelativeModeWarp(SDL_Mouse *mouse)
|
||||
{
|
||||
@@ -539,7 +585,7 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
|
||||
mouse->relative_mode_warp = SDL_TRUE;
|
||||
} else if (mouse->SetRelativeMouseMode(enabled) < 0) {
|
||||
if (enabled) {
|
||||
// Fall back to warp mode if native relative mode failed
|
||||
/* Fall back to warp mode if native relative mode failed */
|
||||
mouse->relative_mode_warp = SDL_TRUE;
|
||||
}
|
||||
}
|
||||
@@ -571,6 +617,41 @@ SDL_GetRelativeMouseMode()
|
||||
return mouse->relative_mode;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_CaptureMouse(SDL_bool enabled)
|
||||
{
|
||||
SDL_Mouse *mouse = SDL_GetMouse();
|
||||
SDL_Window *focusWindow;
|
||||
SDL_bool isCaptured;
|
||||
|
||||
if (!mouse->CaptureMouse) {
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
focusWindow = SDL_GetKeyboardFocus();
|
||||
|
||||
isCaptured = focusWindow && (focusWindow->flags & SDL_WINDOW_MOUSE_CAPTURE);
|
||||
if (isCaptured == enabled) {
|
||||
return 0; /* already done! */
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
if (!focusWindow) {
|
||||
return SDL_SetError("No window has focus");
|
||||
} else if (mouse->CaptureMouse(focusWindow) == -1) {
|
||||
return -1; /* CaptureMouse() should call SetError */
|
||||
}
|
||||
focusWindow->flags |= SDL_WINDOW_MOUSE_CAPTURE;
|
||||
} else {
|
||||
if (mouse->CaptureMouse(NULL) == -1) {
|
||||
return -1; /* CaptureMouse() should call SetError */
|
||||
}
|
||||
focusWindow->flags &= ~SDL_WINDOW_MOUSE_CAPTURE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_Cursor *
|
||||
SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
|
||||
int w, int h, int hot_x, int hot_y)
|
||||
|
||||
@@ -57,12 +57,21 @@ typedef struct
|
||||
/* Free a window manager cursor */
|
||||
void (*FreeCursor) (SDL_Cursor * cursor);
|
||||
|
||||
/* Warp the mouse to (x,y) */
|
||||
/* Warp the mouse to (x,y) within a window */
|
||||
void (*WarpMouse) (SDL_Window * window, int x, int y);
|
||||
|
||||
/* Warp the mouse to (x,y) in screen space */
|
||||
void (*WarpMouseGlobal) (int x, int y);
|
||||
|
||||
/* Set relative mode */
|
||||
int (*SetRelativeMouseMode) (SDL_bool enabled);
|
||||
|
||||
/* Set mouse capture */
|
||||
int (*CaptureMouse) (SDL_Window * window);
|
||||
|
||||
/* Get absolute mouse coordinates. (x) and (y) are never NULL and set to zero before call. */
|
||||
Uint32 (*GetGlobalMouseState) (int *x, int *y);
|
||||
|
||||
/* Data common to all mice */
|
||||
SDL_MouseID mouseID;
|
||||
SDL_Window *focus;
|
||||
@@ -111,7 +120,7 @@ extern int SDL_SendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int rel
|
||||
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);
|
||||
extern int SDL_SendMouseWheel(SDL_Window * window, SDL_MouseID mouseID, int x, int y, SDL_MouseWheelDirection direction);
|
||||
|
||||
/* Shutdown the mouse subsystem */
|
||||
extern void SDL_MouseQuit(void);
|
||||
|
||||
Reference in New Issue
Block a user