2006-07-23 09:11:10 +00:00
|
|
|
/*
|
|
|
|
SDL - Simple DirectMedia Layer
|
2010-07-08 00:03:39 -07:00
|
|
|
Copyright (C) 1997-2010 Sam Lantinga
|
2006-07-23 09:11:10 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
Sam Lantinga
|
|
|
|
slouken@libsdl.org
|
|
|
|
*/
|
|
|
|
#include "SDL_config.h"
|
|
|
|
|
2009-12-03 08:33:39 +00:00
|
|
|
#include "SDL_events.h"
|
2006-07-23 09:11:10 +00:00
|
|
|
#include "SDL_cocoavideo.h"
|
|
|
|
|
|
|
|
#include "../../events/SDL_mouse_c.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
Cocoa_InitMouse(_THIS)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-12-03 08:33:39 +00:00
|
|
|
static int
|
|
|
|
ConvertMouseButtonToSDL(int button)
|
|
|
|
{
|
|
|
|
switch (button)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return(SDL_BUTTON_LEFT); /* 1 */
|
|
|
|
case 1:
|
|
|
|
return(SDL_BUTTON_RIGHT); /* 3 */
|
|
|
|
case 2:
|
|
|
|
return(SDL_BUTTON_MIDDLE); /* 2 */
|
|
|
|
}
|
2011-01-20 17:29:13 -08:00
|
|
|
return button+1;
|
2009-12-03 08:33:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
|
|
|
{
|
|
|
|
int i;
|
2010-05-09 20:47:22 -07:00
|
|
|
NSPoint point = { 0, 0 };
|
2009-12-03 08:33:39 +00:00
|
|
|
SDL_Window *window;
|
2010-07-05 22:48:13 -07:00
|
|
|
SDL_Window *focus = SDL_GetMouseFocus();
|
2009-12-03 08:33:39 +00:00
|
|
|
|
|
|
|
/* See if there are any fullscreen windows that might handle this event */
|
|
|
|
window = NULL;
|
|
|
|
for (i = 0; i < _this->num_displays; ++i) {
|
|
|
|
SDL_VideoDisplay *display = &_this->displays[i];
|
|
|
|
SDL_Window *candidate = display->fullscreen_window;
|
|
|
|
|
|
|
|
if (candidate) {
|
2009-12-06 08:03:38 +00:00
|
|
|
SDL_Rect bounds;
|
2009-12-03 08:33:39 +00:00
|
|
|
|
2009-12-06 08:03:38 +00:00
|
|
|
Cocoa_GetDisplayBounds(_this, display, &bounds);
|
2009-12-03 08:33:39 +00:00
|
|
|
point = [NSEvent mouseLocation];
|
2009-12-06 08:03:38 +00:00
|
|
|
point.x = point.x - bounds.x;
|
|
|
|
point.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - point.y - bounds.y;
|
2010-07-05 22:48:13 -07:00
|
|
|
if ((point.x >= 0 && point.x < candidate->w) &&
|
2010-05-09 20:47:22 -07:00
|
|
|
(point.y >= 0 && point.y < candidate->h)) {
|
2009-12-03 08:33:39 +00:00
|
|
|
/* This is it! */
|
|
|
|
window = candidate;
|
|
|
|
break;
|
2010-07-05 22:48:13 -07:00
|
|
|
} else if (candidate == focus) {
|
|
|
|
SDL_SetMouseFocus(NULL);
|
2009-12-03 08:33:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-05 22:48:13 -07:00
|
|
|
if (!window) {
|
2010-05-09 20:47:22 -07:00
|
|
|
return;
|
2009-12-03 08:33:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch ([event type]) {
|
|
|
|
case NSLeftMouseDown:
|
|
|
|
case NSOtherMouseDown:
|
|
|
|
case NSRightMouseDown:
|
2010-07-05 22:48:13 -07:00
|
|
|
SDL_SendMouseButton(window, SDL_PRESSED, ConvertMouseButtonToSDL([event buttonNumber]));
|
2009-12-03 08:33:39 +00:00
|
|
|
break;
|
|
|
|
case NSLeftMouseUp:
|
|
|
|
case NSOtherMouseUp:
|
|
|
|
case NSRightMouseUp:
|
2010-07-05 22:48:13 -07:00
|
|
|
SDL_SendMouseButton(window, SDL_RELEASED, ConvertMouseButtonToSDL([event buttonNumber]));
|
2009-12-03 08:33:39 +00:00
|
|
|
break;
|
2011-01-21 00:15:18 +01:00
|
|
|
case NSScrollWheel:
|
|
|
|
Cocoa_HandleMouseWheel(window, event);
|
|
|
|
break;
|
2009-12-03 08:33:39 +00:00
|
|
|
case NSLeftMouseDragged:
|
|
|
|
case NSRightMouseDragged:
|
|
|
|
case NSOtherMouseDragged: /* usually middle mouse dragged */
|
|
|
|
case NSMouseMoved:
|
2010-07-05 22:48:13 -07:00
|
|
|
SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y);
|
2009-12-03 08:33:39 +00:00
|
|
|
break;
|
|
|
|
default: /* just to avoid compiler warnings */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-21 00:15:18 +01:00
|
|
|
void
|
|
|
|
Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
|
|
|
|
{
|
|
|
|
float x = [event deltaX];
|
|
|
|
float y = [event deltaY];
|
|
|
|
|
|
|
|
if (x > 0) {
|
|
|
|
x += 0.9f;
|
|
|
|
} else if (x < 0) {
|
|
|
|
x -= 0.9f;
|
|
|
|
}
|
|
|
|
if (y > 0) {
|
|
|
|
y += 0.9f;
|
|
|
|
} else if (y < 0) {
|
|
|
|
y -= 0.9f;
|
|
|
|
}
|
|
|
|
SDL_SendMouseWheel(window, (int)x, (int)y);
|
|
|
|
}
|
|
|
|
|
2011-01-20 17:11:22 -08:00
|
|
|
void
|
|
|
|
Cocoa_QuitMouse(_THIS)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-07-23 09:11:10 +00:00
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|