src/video/cocoa/SDL_cocoawindow.h
author Sam Lantinga <slouken@libsdl.org>
Mon, 21 Feb 2011 10:50:53 -0800
changeset 5371 fc3d3d580777
parent 5305 75f5ff92ad08
child 5374 dacb4f5e0dd3
permissions -rw-r--r--
Fixed the responder chain for event handling, the listener fully handles mouse events - even in fullscreen mode.
The only reason we need a custom view is to handle right mouse down.

Implemented mouse grabbing, although it's kind of clunky right now. I'll be adding a relative mode that will be smoother soon.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2011 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 #ifndef _SDL_cocoawindow_h
    25 #define _SDL_cocoawindow_h
    26 
    27 #import <Cocoa/Cocoa.h>
    28 
    29 typedef struct SDL_WindowData SDL_WindowData;
    30 
    31 /* *INDENT-OFF* */
    32 @interface Cocoa_WindowListener : NSResponder {
    33     SDL_WindowData *_data;
    34 }
    35 
    36 -(void) listen:(SDL_WindowData *) data;
    37 -(void) close;
    38 
    39 /* Window delegate functionality */
    40 -(BOOL) windowShouldClose:(id) sender;
    41 -(void) windowDidExpose:(NSNotification *) aNotification;
    42 -(void) windowDidMove:(NSNotification *) aNotification;
    43 -(void) windowDidResize:(NSNotification *) aNotification;
    44 -(void) windowDidMiniaturize:(NSNotification *) aNotification;
    45 -(void) windowDidDeminiaturize:(NSNotification *) aNotification;
    46 -(void) windowDidBecomeKey:(NSNotification *) aNotification;
    47 -(void) windowDidResignKey:(NSNotification *) aNotification;
    48 -(void) windowDidHide:(NSNotification *) aNotification;
    49 -(void) windowDidUnhide:(NSNotification *) aNotification;
    50 
    51 /* Window event handling */
    52 -(void) mouseDown:(NSEvent *) theEvent;
    53 -(void) rightMouseDown:(NSEvent *) theEvent;
    54 -(void) otherMouseDown:(NSEvent *) theEvent;
    55 -(void) mouseUp:(NSEvent *) theEvent;
    56 -(void) rightMouseUp:(NSEvent *) theEvent;
    57 -(void) otherMouseUp:(NSEvent *) theEvent;
    58 -(void) mouseEntered:(NSEvent *)theEvent;
    59 -(void) mouseExited:(NSEvent *)theEvent;
    60 -(void) mouseMoved:(NSEvent *) theEvent;
    61 -(void) mouseDragged:(NSEvent *) theEvent;
    62 -(void) rightMouseDragged:(NSEvent *) theEvent;
    63 -(void) otherMouseDragged:(NSEvent *) theEvent;
    64 -(void) scrollWheel:(NSEvent *) theEvent;
    65 -(void) touchesBeganWithEvent:(NSEvent *) theEvent;
    66 -(void) touchesMovedWithEvent:(NSEvent *) theEvent;
    67 -(void) touchesEndedWithEvent:(NSEvent *) theEvent;
    68 -(void) touchesCancelledWithEvent:(NSEvent *) theEvent;
    69 
    70 /* Touch event handling */
    71 typedef enum {
    72     COCOA_TOUCH_DOWN,
    73     COCOA_TOUCH_UP,
    74     COCOA_TOUCH_MOVE,
    75     COCOA_TOUCH_CANCELLED
    76 } cocoaTouchType;
    77 -(void) handleTouches:(cocoaTouchType)type withEvent:(NSEvent*) event;
    78 
    79 @end
    80 /* *INDENT-ON* */
    81 
    82 struct SDL_WindowData
    83 {
    84     SDL_Window *window;
    85     NSWindow *nswindow;
    86     SDL_bool created;
    87     Cocoa_WindowListener *listener;
    88     struct SDL_VideoData *videodata;
    89 };
    90 
    91 extern int Cocoa_CreateWindow(_THIS, SDL_Window * window);
    92 extern int Cocoa_CreateWindowFrom(_THIS, SDL_Window * window,
    93                                   const void *data);
    94 extern void Cocoa_SetWindowTitle(_THIS, SDL_Window * window);
    95 extern void Cocoa_SetWindowPosition(_THIS, SDL_Window * window);
    96 extern void Cocoa_SetWindowSize(_THIS, SDL_Window * window);
    97 extern void Cocoa_ShowWindow(_THIS, SDL_Window * window);
    98 extern void Cocoa_HideWindow(_THIS, SDL_Window * window);
    99 extern void Cocoa_RaiseWindow(_THIS, SDL_Window * window);
   100 extern void Cocoa_MaximizeWindow(_THIS, SDL_Window * window);
   101 extern void Cocoa_MinimizeWindow(_THIS, SDL_Window * window);
   102 extern void Cocoa_RestoreWindow(_THIS, SDL_Window * window);
   103 extern void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
   104 extern void Cocoa_SetWindowGrab(_THIS, SDL_Window * window);
   105 extern void Cocoa_DestroyWindow(_THIS, SDL_Window * window);
   106 extern SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window,
   107                                       struct SDL_SysWMinfo *info);
   108 
   109 #endif /* _SDL_cocoawindow_h */
   110 
   111 /* vi: set ts=4 sw=4 expandtab: */