Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Implemented Cocoa mouse wheel events
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jul 29, 2006
1 parent 3fce07c commit 04ad26b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions include/SDL_events.h
Expand Up @@ -60,11 +60,11 @@ typedef enum
SDL_WINDOWEVENT, /**< Window state change */
SDL_KEYDOWN, /**< Keys pressed */
SDL_KEYUP, /**< Keys released */
SDL_TEXTINPUT, /**< Keyboard text input */
SDL_TEXTINPUT, /**< Keyboard text input */
SDL_MOUSEMOTION, /**< Mouse moved */
SDL_MOUSEBUTTONDOWN, /**< Mouse button pressed */
SDL_MOUSEBUTTONUP, /**< Mouse button released */
SDL_MOUSEWHEEL, /**< Mouse wheel motion */
SDL_MOUSEWHEEL, /**< Mouse wheel motion */
SDL_JOYAXISMOTION, /**< Joystick axis motion */
SDL_JOYBALLMOTION, /**< Joystick trackball motion */
SDL_JOYHATMOTION, /**< Joystick hat position change */
Expand Down
1 change: 1 addition & 0 deletions src/video/cocoa/SDL_cocoawindow.h
Expand Up @@ -54,6 +54,7 @@ typedef struct SDL_WindowData SDL_WindowData;
-(void) rightMouseUp:(NSEvent *) theEvent;
-(void) otherMouseUp:(NSEvent *) theEvent;
-(void) mouseMoved:(NSEvent *) theEvent;
-(void) mouseDragged:(NSEvent *) theEvent;
-(void) scrollWheel:(NSEvent *) theEvent;
-(void) keyDown:(NSEvent *) theEvent;
-(void) keyUp:(NSEvent *) theEvent;
Expand Down
22 changes: 9 additions & 13 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -208,26 +208,22 @@ - (void)mouseMoved:(NSEvent *)theEvent
}

point = [NSEvent mouseLocation];
if (point.x < rect.origin.x ||
point.x > (rect.origin.x + rect.size.width) ||
point.y < rect.origin.y ||
point.y > (rect.origin.y + rect.size.height)) {
if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_LEAVE, 0, 0);
}
} else {
if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
SDL_SendWindowEvent(_data->windowID, SDL_WINDOWEVENT_ENTER, 0, 0);
}
}
point.x = point.x - rect.origin.x;
point.y = rect.size.height - (point.y - rect.origin.y);
SDL_SendMouseMotion(index, 0, (int)point.x, (int)point.y);
}

- (void)mouseDragged:(NSEvent *)theEvent
{
[self mouseMoved:theEvent];
}

- (void)scrollWheel:(NSEvent *)theEvent
{
fprintf(stderr, "scrollWheel\n");
int index;

index = _data->videodata->mouse;
SDL_SendMouseWheel(index, (int)([theEvent deltaY]+0.9f));
}

- (void)keyDown:(NSEvent *)theEvent
Expand Down
2 changes: 1 addition & 1 deletion test/common.c
Expand Up @@ -827,7 +827,7 @@ PrintEvent(SDL_Event * event)
case SDL_MOUSEWHEEL:
fprintf(stderr, "Mouse %d: wheel scrolled %d in window %d",
event->wheel.which, event->wheel.motion,
event->button.windowID);
event->wheel.windowID);
break;
case SDL_JOYBALLMOTION:
fprintf(stderr, "Joystick %d: ball %d moved by %d,%d",
Expand Down

0 comments on commit 04ad26b

Please sign in to comment.