diff src/video/quartz/SDL_QuartzVideo.m @ 683:5d2f027b3349

Date: Sat, 9 Aug 2003 20:14:06 -0400 From: Darrell Walisser Subject: Re: Updated projects? >> Did you get a chance to look at my "Custom Cocoa" demo? I have a few >> minor patches that enable SDL/Cocoa integration, and a project >> template. > > I didn't yet, but go ahead and send me the patches. :) > I updated the patch for current CVS. There are a lot of changes, but I don't think I've broken anything. This patch also improves the behavior of window minimize/deminimize.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 10 Aug 2003 07:21:43 +0000
parents be597a247e20
children c5b2b6d2d1fe
line wrap: on
line diff
--- a/src/video/quartz/SDL_QuartzVideo.m	Sat Aug 09 22:49:28 2003 +0000
+++ b/src/video/quartz/SDL_QuartzVideo.m	Sun Aug 10 07:21:43 2003 +0000
@@ -396,7 +396,6 @@
         CGDisplaySwitchToMode (display_id, save_mode);
         CGReleaseAllDisplays ();
         ShowMenuBar ();
-
         /* 
             Reset the main screen's rectangle
             See comment in QZ_SetVideoFullscreen for why we do this
@@ -580,6 +579,7 @@
                                          int height, int bpp, Uint32 flags) {
     unsigned int style;
     NSRect contentRect;
+    BOOL isCustom = NO;
     int center_window = 1;
     int origin_x, origin_y;
 
@@ -602,7 +602,41 @@
              (mode_flags & SDL_OPENGL) || 
              (flags & SDL_OPENGL) )
             QZ_UnsetVideoMode (this);
-        
+    
+    /* Check for user-specified window and view */
+    {
+        char *windowPtrString = getenv ("SDL_NSWindowPointer");
+        char *viewPtrString = getenv ("SDL_NSQuickDrawViewPointer");
+    
+        if (windowPtrString && viewPtrString) {
+            
+            /* Release any previous window */
+            if ( qz_window ) {
+                [ qz_window release ];
+                qz_window = nil;
+            }
+            
+            qz_window = (NSWindow*)atoi(windowPtrString);
+            window_view = (NSQuickDrawView*)atoi(viewPtrString);
+            isCustom = YES;
+            
+            /* 
+                Retain reference to window because we
+                might release it in QZ_UnsetVideoMode
+            */
+            [ qz_window retain ];
+            
+            style = [ qz_window styleMask ];
+            /* Check resizability */
+            if ( style & NSResizableWindowMask )
+                current->flags |= SDL_RESIZABLE;
+            
+            /* Check frame */
+            if ( style & NSBorderlessWindowMask )
+                current->flags |= SDL_NOFRAME;
+        }
+    }
+    
     /* Check if we should recreate the window */
     if (qz_window == nil) {
     
@@ -650,8 +684,10 @@
     /* We already have a window, just change its size */
     else {
     
-        [ qz_window setContentSize:contentRect.size ];
-        current->flags |= (SDL_NOFRAME|SDL_RESIZABLE) & mode_flags;
+        if (!isCustom) {
+            [ qz_window setContentSize:contentRect.size ];
+            current->flags |= (SDL_NOFRAME|SDL_RESIZABLE) & mode_flags;
+        }
     }
 
     /* For OpenGL, we bind the context to a subview */
@@ -692,9 +728,18 @@
         current->flags |= SDL_PREALLOC;
         current->flags |= SDL_ASYNCBLIT;
         
-        /* Offset below the title bar to fill the full content region */
-        current->pixels += ((int)([ qz_window frame ].size.height) - height) * current->pitch;
-
+        /* 
+            current->pixels now points to the window's pixels
+            We want it to point to the *view's* pixels 
+        */
+        { 
+            int vOffset = [ qz_window frame ].size.height - 
+                [ window_view frame ].size.height - [ window_view frame ].origin.y;
+            
+            int hOffset = [ window_view frame ].origin.x;
+                    
+            current->pixels += (vOffset * current->pitch) + hOffset * (device_bpp/8);
+        }
         this->UpdateRects     = QZ_UpdateRects;
         this->LockHWSurface   = QZ_LockWindow;
         this->UnlockHWSurface = QZ_UnlockWindow;