src/video/quartz/SDL_QuartzWindow.m
changeset 501 74262d2647ca
parent 272 d1447a846d80
child 631 52864d66d168
equal deleted inserted replaced
500:c335456c421d 501:74262d2647ca
     1 /* Subclass of NSWindow to allow customization if we need it */
       
     2 
     1 
       
     2 /*
       
     3     This function makes the *SDL region* of the window 100% opaque. 
       
     4     The genie effect uses the alpha component. Otherwise,
       
     5     it doesn't seem to matter what value it has.
       
     6 */
       
     7 static void QZ_SetPortAlphaOpaque () {
       
     8     
       
     9     SDL_Surface *surface = current_video->screen;
       
    10     int bpp;
       
    11     
       
    12     bpp = surface->format->BitsPerPixel;
       
    13     
       
    14     if (bpp == 32) {
       
    15     
       
    16         Uint32    *pixels = (Uint32*) surface->pixels;
       
    17         Uint32    rowPixels = surface->pitch / 4;
       
    18         Uint32    i, j;
       
    19         
       
    20         for (i = 0; i < surface->h; i++)
       
    21             for (j = 0; j < surface->w; j++) {
       
    22         
       
    23                 pixels[ (i * rowPixels) + j ] |= 0xFF000000;
       
    24             }
       
    25     }
       
    26 }
       
    27 
       
    28 /* Subclass of NSWindow to fix genie effect and support resize events  */
     3 @interface SDL_QuartzWindow : NSWindow
    29 @interface SDL_QuartzWindow : NSWindow
     4 {}
    30 {}
     5 - (void)miniaturize:(id)sender;
    31 - (void)miniaturize:(id)sender;
     6 - (void)deminiaturize:(id)sender;
       
     7 - (void)display;
    32 - (void)display;
       
    33 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
     8 @end
    34 @end
     9 
       
    10 /**
       
    11  * Function to set the opacity of window's pixels to 100% 
       
    12  * The opacity is only used by the window server code that does the minimize effect
       
    13  **/
       
    14 static void QZ_SetPortAlphaOpaque (CGrafPtr port, Uint32 noTitleBar) {
       
    15     
       
    16     Uint32 *pixels;
       
    17     Uint32  rowPixels;
       
    18     Uint32  width, height;
       
    19     Uint32  bpp;
       
    20     PixMapHandle pixMap;
       
    21     Rect bounds;
       
    22     int i, j;
       
    23     
       
    24     pixMap = GetPortPixMap ( port );
       
    25     bpp = GetPixDepth ( pixMap );
       
    26     
       
    27     if (bpp == 32) {
       
    28     
       
    29         GetPortBounds ( port, &bounds );
       
    30         width = bounds.right - bounds.left;
       
    31         height = bounds.bottom - bounds.top;
       
    32         
       
    33         LockPortBits (port);
       
    34         
       
    35         pixels = (Uint32*) GetPixBaseAddr ( pixMap );
       
    36         rowPixels = GetPixRowBytes ( pixMap ) / 4;
       
    37         
       
    38         if (! noTitleBar) {
       
    39         
       
    40             /* offset for title bar */
       
    41             pixels += rowPixels * 22;
       
    42         }
       
    43             
       
    44         for (i = 0; i < height; i++)
       
    45             for (j = 0; j < width; j++) {
       
    46         
       
    47                 pixels[ (i * rowPixels) + j ] |= 0xFF000000;
       
    48             }
       
    49             
       
    50         UnlockPortBits (port);
       
    51     }
       
    52 }
       
    53 
    35 
    54 @implementation SDL_QuartzWindow
    36 @implementation SDL_QuartzWindow
    55 
    37 
    56 /* override these methods to fix the miniaturize animation/dock icon bug */
    38 /* we override these methods to fix the miniaturize animation/dock icon bug */
    57 - (void)miniaturize:(id)sender
    39 - (void)miniaturize:(id)sender
    58 {
    40 {
    59     
       
    60     if (SDL_VideoSurface->flags & SDL_OPENGL) {
    41     if (SDL_VideoSurface->flags & SDL_OPENGL) {
    61     
    42     
    62         /* Grab framebuffer and put into NSImage */
    43         /* 
    63         /* [ qz_window setMiniwindowImage:image ]; */
    44             Future: Grab framebuffer and put into NSImage
       
    45             [ qz_window setMiniwindowImage:image ];
       
    46         */
    64     }
    47     }
    65     else {
    48     else {
    66         
    49         
    67         QZ_SetPortAlphaOpaque ([ [ self contentView ] qdPort ], 
    50         /* make the alpha channel opaque so anim won't have holes in it */
    68                                [ self styleMask ] & NSBorderlessWindowMask);
    51         QZ_SetPortAlphaOpaque ();
    69     }
    52     }
    70     
    53     
    71     [ super miniaturize:sender ];
    54     [ super miniaturize:sender ];
    72 }
    55 }
    73 
    56 
    74 /* this routine fires *after* deminiaturizing, so it might be useless to us */
    57 - (void)display
    75 - (void)deminiaturize:(id)sender
    58 {    
    76 {
    59     /* 
    77    [ super deminiaturize:sender ];
    60         This method fires just before the window deminaturizes.
       
    61         So, it's just the right place to fixup the alpha channel - which
       
    62         makes the deminiaturize animation look right.
       
    63     */
       
    64     if ( (SDL_VideoSurface->flags & SDL_OPENGL) == 0)
       
    65         QZ_SetPortAlphaOpaque ();
    78 }
    66 }
    79 
    67 
    80 - (void)display
    68 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag
    81 {
    69 {
    82     /* Do nothing to keep pinstripe pattern from drawing */
    70 
       
    71     /*
       
    72         If the video surface is NULL, this originated from QZ_SetVideoMode,
       
    73         so don't send the resize event. 
       
    74     */
       
    75     if (SDL_VideoSurface == NULL) {
       
    76 
       
    77         [ super setFrame:frameRect display:flag ];
       
    78     }
       
    79     else {
       
    80 
       
    81         SDL_VideoDevice *this = (SDL_VideoDevice*)current_video;
       
    82         
       
    83         NSRect sdlRect = [ NSWindow contentRectForFrameRect:frameRect styleMask:[self styleMask] ];
       
    84 
       
    85         [ super setFrame:frameRect display:flag ];
       
    86         SDL_PrivateResize (sdlRect.size.width, sdlRect.size.height);
       
    87 
       
    88         /* If not OpenGL, we have to update the pixels and pitch */
       
    89         if ( ! this->screen->flags & SDL_OPENGL ) {
       
    90             
       
    91             LockPortBits ( [ window_view qdPort ] );
       
    92             
       
    93             SDL_VideoSurface->pixels = GetPixBaseAddr ( GetPortPixMap ( [ window_view qdPort ] ) );
       
    94             SDL_VideoSurface->pitch  = GetPixRowBytes ( GetPortPixMap ( [ window_view qdPort ] ) );
       
    95             
       
    96             SDL_VideoSurface->pixels += ((int)[ self frame ].size.height - (int)sdlRect.size.height) * SDL_VideoSurface->pitch;
       
    97     
       
    98             UnlockPortBits ( [ window_view qdPort ] );
       
    99         }
       
   100     }
    83 }
   101 }
       
   102 
    84 @end
   103 @end
    85 
   104 
    86 /* Delegate for our NSWindow to send SDLQuit() on close */
   105 /* Delegate for our NSWindow to send SDLQuit() on close */
    87 @interface SDL_QuartzWindowDelegate : NSObject
   106 @interface SDL_QuartzWindowDelegate : NSObject
    88 {}
   107 {}
    89 - (BOOL)windowShouldClose:(id)sender;
   108 - (BOOL)windowShouldClose:(id)sender;
    90 @end
   109 @end
    91 
   110 
    92 @implementation SDL_QuartzWindowDelegate
   111 @implementation SDL_QuartzWindowDelegate
    93 - (BOOL)windowShouldClose:(id)sender {
   112 - (BOOL)windowShouldClose:(id)sender
    94 
   113 {
    95     SDL_PrivateQuit();
   114     SDL_PrivateQuit();
    96     return NO;
   115     return NO;
    97 }
   116 }
    98 
       
    99 @end
   117 @end
   100 
   118 
   101 /* empty class; probably could be used to fix bugs in the future */
   119 /* Subclass of NSQuickDrawView for the window's subview */
   102 @interface SDL_QuartzWindowView : NSQuickDrawView
   120 @interface SDL_QuartzWindowView : NSQuickDrawView
   103 {}
   121 {}
   104 @end
   122 @end
   105 
   123 
   106 @implementation SDL_QuartzWindowView
   124 @implementation SDL_QuartzWindowView
   107 
       
   108 @end
   125 @end