diff src/video/quartz/SDL_QuartzWM.m @ 272:d1447a846d80

Date: Sat, 19 Jan 2002 17:24:32 -0500 (EST) From: Darrell Walisser <dwaliss1@purdue.edu> Subject: SDL Quartz video update -better mouse motion events -fixed minification bugs (except OpenGL) -fixed QZ_SetGamma for correct semantics -fade/unfade display before/after rez switch -experimental obscured-check/blind-copy code The obscured code, while it speeds up window drawing substantially, isn't ready yet. The reason is that there doesn't (yet) seem to be a way to know when the window is dragged or when the window suddenly comes to the foreground. Since Carbon windows seem to allow detection of such things, I suspect it is possible through some window server API. Cocoa(NSWindow) has no functions for such things, AFAIK.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 22 Jan 2002 18:46:28 +0000
parents 4125b9859c71
children 72acb06d3721
line wrap: on
line diff
--- a/src/video/quartz/SDL_QuartzWM.m	Tue Jan 22 18:28:35 2002 +0000
+++ b/src/video/quartz/SDL_QuartzWM.m	Tue Jan 22 18:46:28 2002 +0000
@@ -87,40 +87,112 @@
     return 1;
 }
 
-static void  QZ_PrivateWarpCursor (_THIS, int fullscreen, int h, int x, int y) {
+/**
+ * Coordinate conversion functions, for convenience
+ * Cocoa sets the origin at the lower left corner of the window/screen
+ * SDL, CoreGraphics/WindowServer, and QuickDraw use the origin at the upper left corner
+ * The routines were written so they could be called before SetVideoMode() has finished;
+ * this might have limited usefulness at the moment, but the extra cost is trivial.
+ **/
+
+/* Convert Cocoa screen coordinate to Cocoa window coordinate */
+static void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p) {
 
-    CGPoint p;
+    *p = [ qz_window convertScreenToBase:*p ];
+}
+
+
+/* Convert Cocoa window coordinate to Cocoa screen coordinate */
+static void QZ_PrivateLocalToGlobal (_THIS, NSPoint *p) {
+
+    *p = [ qz_window convertBaseToScreen:*p ];
+}
+
+/* Convert SDL coordinate to Cocoa coordinate */
+static void QZ_PrivateSDLToCocoa (_THIS, NSPoint *p) {
+
+    int height;
     
-    /* We require absolute screen coordiates for our warp */
-    p.x = x;
-    p.y = h - y;
+    if ( CGDisplayIsCaptured (display_id) ) { /* capture signals fullscreen */
+    
+        height = CGDisplayPixelsHigh (display_id);
+    }
+    else {
+        
+        height = NSHeight ( [ qz_window frame ] );
+        if ( [ qz_window styleMask ] & NSTitledWindowMask ) {
         
-    if ( fullscreen )
-        /* Already absolute coordinates */
-        CGDisplayMoveCursorToPoint(display_id, p);
-    else {
-        /* Convert to absolute screen coordinates */
-        NSPoint base, screen;
-        base = NSMakePoint (p.x, p.y);
-        screen = [ qz_window convertBaseToScreen:base ];
-        p.x = screen.x;
-        p.y = device_height - screen.y;
-        CGDisplayMoveCursorToPoint (display_id, p);
+            height -= 22;
+        }
+    }
+    
+    p->y = height - p->y;
+}
+
+/* Convert Cocoa coordinate to SDL coordinate */
+static void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p) {
+
+    QZ_PrivateSDLToCocoa (this, p);
+}
+
+/* Convert SDL coordinate to window server (CoreGraphics) coordinate */
+static CGPoint QZ_PrivateSDLToCG (_THIS, NSPoint *p) {
+    
+    CGPoint cgp;
+    
+    if ( ! CGDisplayIsCaptured (display_id) ) { /* not captured => not fullscreen => local coord */
+    
+        int height;
+        
+        QZ_PrivateSDLToCocoa (this, p);
+        QZ_PrivateLocalToGlobal (this, p);
+        
+        height = CGDisplayPixelsHigh (display_id);
+        p->y = height - p->y;
+    }
+    
+    cgp.x = p->x;
+    cgp.y = p->y;
+    
+    return cgp;
+}
+
+/* Convert window server (CoreGraphics) coordinate to SDL coordinate */
+static void QZ_PrivateCGToSDL (_THIS, NSPoint *p) {
+            
+    if ( ! CGDisplayIsCaptured (display_id) ) { /* not captured => not fullscreen => local coord */
+    
+        int height;
+
+        /* Convert CG Global to Cocoa Global */
+        height = CGDisplayPixelsHigh (display_id);
+        p->y = height - p->y;
+
+        QZ_PrivateGlobalToLocal (this, p);
+        QZ_PrivateCocoaToSDL (this, p);
     }
 }
 
-static void QZ_WarpWMCursor     (_THIS, Uint16 x, Uint16 y) {
+static void  QZ_PrivateWarpCursor (_THIS, int x, int y) {
+    
+    NSPoint p;
+    CGPoint cgp;
     
+    p = NSMakePoint (x, y);
+    cgp = QZ_PrivateSDLToCG (this, &p);   
+    CGDisplayMoveCursorToPoint (display_id, cgp);
+    warp_ticks = SDL_GetTicks();
+    warp_flag = 1;
+}
+
+static void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) {
+
     /* Only allow warping when in foreground */
     if ( ! inForeground )
         return;
             
     /* Do the actual warp */
-    QZ_PrivateWarpCursor (this, SDL_VideoSurface->flags & SDL_FULLSCREEN, 
-        SDL_VideoSurface->h, x, y);
-    
-    /* Generate mouse moved event */
-    SDL_PrivateMouseMotion (SDL_RELEASED, 0, x, y);
+    QZ_PrivateWarpCursor (this, x, y);
 }
 
 static void QZ_MoveWMCursor     (_THIS, int x, int y) { }
@@ -199,6 +271,17 @@
         return 0;
     }
 }
+static int  QZ_IconifyWindow (_THIS) { 
+
+    if ( ! [ qz_window isMiniaturized ] ) {
+        [ qz_window miniaturize:nil ];
+        return 1;
+    }
+    else {
+        SDL_SetError ("Quartz window already iconified");
+        return 0;
+    }
+}
 
 /*
 static int  QZ_GetWMInfo  (_THIS, SDL_SysWMinfo *info) { 
@@ -221,6 +304,7 @@
             currentGrabMode = SDL_GRAB_ON;
             break;
         case SDL_GRAB_FULLSCREEN:
+            
             break;
     }