diff src/video/quartz/SDL_QuartzWindow.m @ 501:74262d2647ca

Lots of cleanups by Darrell, added the ability to resize Cocoa windows.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 05 Oct 2002 05:07:57 +0000
parents d1447a846d80
children 52864d66d168
line wrap: on
line diff
--- a/src/video/quartz/SDL_QuartzWindow.m	Sat Oct 05 04:56:32 2002 +0000
+++ b/src/video/quartz/SDL_QuartzWindow.m	Sat Oct 05 05:07:57 2002 +0000
@@ -1,86 +1,105 @@
-/* Subclass of NSWindow to allow customization if we need it */
 
-@interface SDL_QuartzWindow : NSWindow
-{}
-- (void)miniaturize:(id)sender;
-- (void)deminiaturize:(id)sender;
-- (void)display;
-@end
-
-/**
- * Function to set the opacity of window's pixels to 100% 
- * The opacity is only used by the window server code that does the minimize effect
- **/
-static void QZ_SetPortAlphaOpaque (CGrafPtr port, Uint32 noTitleBar) {
+/*
+    This function makes the *SDL region* of the window 100% opaque. 
+    The genie effect uses the alpha component. Otherwise,
+    it doesn't seem to matter what value it has.
+*/
+static void QZ_SetPortAlphaOpaque () {
     
-    Uint32 *pixels;
-    Uint32  rowPixels;
-    Uint32  width, height;
-    Uint32  bpp;
-    PixMapHandle pixMap;
-    Rect bounds;
-    int i, j;
+    SDL_Surface *surface = current_video->screen;
+    int bpp;
     
-    pixMap = GetPortPixMap ( port );
-    bpp = GetPixDepth ( pixMap );
+    bpp = surface->format->BitsPerPixel;
     
     if (bpp == 32) {
     
-        GetPortBounds ( port, &bounds );
-        width = bounds.right - bounds.left;
-        height = bounds.bottom - bounds.top;
-        
-        LockPortBits (port);
-        
-        pixels = (Uint32*) GetPixBaseAddr ( pixMap );
-        rowPixels = GetPixRowBytes ( pixMap ) / 4;
+        Uint32    *pixels = (Uint32*) surface->pixels;
+        Uint32    rowPixels = surface->pitch / 4;
+        Uint32    i, j;
         
-        if (! noTitleBar) {
-        
-            /* offset for title bar */
-            pixels += rowPixels * 22;
-        }
-            
-        for (i = 0; i < height; i++)
-            for (j = 0; j < width; j++) {
+        for (i = 0; i < surface->h; i++)
+            for (j = 0; j < surface->w; j++) {
         
                 pixels[ (i * rowPixels) + j ] |= 0xFF000000;
             }
-            
-        UnlockPortBits (port);
     }
 }
 
+/* Subclass of NSWindow to fix genie effect and support resize events  */
+@interface SDL_QuartzWindow : NSWindow
+{}
+- (void)miniaturize:(id)sender;
+- (void)display;
+- (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
+@end
+
 @implementation SDL_QuartzWindow
 
-/* override these methods to fix the miniaturize animation/dock icon bug */
+/* we override these methods to fix the miniaturize animation/dock icon bug */
 - (void)miniaturize:(id)sender
 {
-    
     if (SDL_VideoSurface->flags & SDL_OPENGL) {
     
-        /* Grab framebuffer and put into NSImage */
-        /* [ qz_window setMiniwindowImage:image ]; */
+        /* 
+            Future: Grab framebuffer and put into NSImage
+            [ qz_window setMiniwindowImage:image ];
+        */
     }
     else {
         
-        QZ_SetPortAlphaOpaque ([ [ self contentView ] qdPort ], 
-                               [ self styleMask ] & NSBorderlessWindowMask);
+        /* make the alpha channel opaque so anim won't have holes in it */
+        QZ_SetPortAlphaOpaque ();
     }
     
     [ super miniaturize:sender ];
 }
 
-/* this routine fires *after* deminiaturizing, so it might be useless to us */
-- (void)deminiaturize:(id)sender
-{
-   [ super deminiaturize:sender ];
+- (void)display
+{    
+    /* 
+        This method fires just before the window deminaturizes.
+        So, it's just the right place to fixup the alpha channel - which
+        makes the deminiaturize animation look right.
+    */
+    if ( (SDL_VideoSurface->flags & SDL_OPENGL) == 0)
+        QZ_SetPortAlphaOpaque ();
 }
 
-- (void)display
+- (void)setFrame:(NSRect)frameRect display:(BOOL)flag
 {
-    /* Do nothing to keep pinstripe pattern from drawing */
+
+    /*
+        If the video surface is NULL, this originated from QZ_SetVideoMode,
+        so don't send the resize event. 
+    */
+    if (SDL_VideoSurface == NULL) {
+
+        [ super setFrame:frameRect display:flag ];
+    }
+    else {
+
+        SDL_VideoDevice *this = (SDL_VideoDevice*)current_video;
+        
+        NSRect sdlRect = [ NSWindow contentRectForFrameRect:frameRect styleMask:[self styleMask] ];
+
+        [ super setFrame:frameRect display:flag ];
+        SDL_PrivateResize (sdlRect.size.width, sdlRect.size.height);
+
+        /* If not OpenGL, we have to update the pixels and pitch */
+        if ( ! this->screen->flags & SDL_OPENGL ) {
+            
+            LockPortBits ( [ window_view qdPort ] );
+            
+            SDL_VideoSurface->pixels = GetPixBaseAddr ( GetPortPixMap ( [ window_view qdPort ] ) );
+            SDL_VideoSurface->pitch  = GetPixRowBytes ( GetPortPixMap ( [ window_view qdPort ] ) );
+            
+            SDL_VideoSurface->pixels += ((int)[ self frame ].size.height - (int)sdlRect.size.height) * SDL_VideoSurface->pitch;
+    
+            UnlockPortBits ( [ window_view qdPort ] );
+        }
+    }
 }
+
 @end
 
 /* Delegate for our NSWindow to send SDLQuit() on close */
@@ -90,19 +109,17 @@
 @end
 
 @implementation SDL_QuartzWindowDelegate
-- (BOOL)windowShouldClose:(id)sender {
-
+- (BOOL)windowShouldClose:(id)sender
+{
     SDL_PrivateQuit();
     return NO;
 }
-
 @end
 
-/* empty class; probably could be used to fix bugs in the future */
+/* Subclass of NSQuickDrawView for the window's subview */
 @interface SDL_QuartzWindowView : NSQuickDrawView
 {}
 @end
 
 @implementation SDL_QuartzWindowView
-
-@end
\ No newline at end of file
+@end