/
SDL_QuartzWindow.m
125 lines (95 loc) · 3.32 KB
/
SDL_QuartzWindow.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
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 () {
SDL_Surface *surface = current_video->screen;
int bpp;
bpp = surface->format->BitsPerPixel;
if (bpp == 32) {
Uint32 *pixels = (Uint32*) surface->pixels;
Uint32 rowPixels = surface->pitch / 4;
Uint32 i, j;
for (i = 0; i < surface->h; i++)
for (j = 0; j < surface->w; j++) {
pixels[ (i * rowPixels) + j ] |= 0xFF000000;
}
}
}
/* 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
/* we override these methods to fix the miniaturize animation/dock icon bug */
- (void)miniaturize:(id)sender
{
if (SDL_VideoSurface->flags & SDL_OPENGL) {
/*
Future: Grab framebuffer and put into NSImage
[ qz_window setMiniwindowImage:image ];
*/
}
else {
/* make the alpha channel opaque so anim won't have holes in it */
QZ_SetPortAlphaOpaque ();
}
[ super miniaturize: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)setFrame:(NSRect)frameRect display:(BOOL)flag
{
/*
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 */
@interface SDL_QuartzWindowDelegate : NSObject
{}
- (BOOL)windowShouldClose:(id)sender;
@end
@implementation SDL_QuartzWindowDelegate
- (BOOL)windowShouldClose:(id)sender
{
SDL_PrivateQuit();
return NO;
}
@end
/* Subclass of NSQuickDrawView for the window's subview */
@interface SDL_QuartzWindowView : NSQuickDrawView
{}
@end
@implementation SDL_QuartzWindowView
@end