/
SDL_QuartzWindow.m
156 lines (119 loc) · 4.51 KB
1
2
3
4
5
6
7
/*
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 () {
8
9
10
SDL_Surface *surface = current_video->screen;
int bpp;
11
12
bpp = surface->format->BitsPerPixel;
13
14
15
if (bpp == 32) {
16
17
18
Uint32 *pixels = (Uint32*) surface->pixels;
Uint32 rowPixels = surface->pitch / 4;
Uint32 i, j;
19
20
21
for (i = 0; i < surface->h; i++)
for (j = 0; j < surface->w; j++) {
22
23
24
25
26
27
pixels[ (i * rowPixels) + j ] |= 0xFF000000;
}
}
}
28
29
30
31
32
33
/* 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;
34
35
36
- (void)appDidHide:(NSNotification*)note;
- (void)appDidUnhide:(NSNotification*)note;
- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag;
37
38
@end
39
40
@implementation SDL_QuartzWindow
41
/* we override these methods to fix the miniaturize animation/dock icon bug */
42
43
- (void)miniaturize:(id)sender
{
44
45
if (SDL_VideoSurface->flags & SDL_OPENGL) {
46
47
48
49
/*
Future: Grab framebuffer and put into NSImage
[ qz_window setMiniwindowImage:image ];
*/
50
51
52
}
else {
53
54
/* make the alpha channel opaque so anim won't have holes in it */
QZ_SetPortAlphaOpaque ();
55
56
}
57
58
59
/* window is hidden now */
SDL_PrivateAppActive (0, SDL_APPACTIVE);
60
61
62
[ super miniaturize:sender ];
}
63
64
65
66
67
68
69
70
71
- (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 ();
72
73
74
/* window is visible again */
SDL_PrivateAppActive (1, SDL_APPACTIVE);
75
76
}
77
- (void)setFrame:(NSRect)frameRect display:(BOOL)flag
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
/*
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 ] );
}
}
110
}
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
- (void)appDidHide:(NSNotification*)note
{
SDL_PrivateAppActive (0, SDL_APPACTIVE);
}
- (void)appDidUnhide:(NSNotification*)note
{
SDL_PrivateAppActive (1, SDL_APPACTIVE);
}
- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag
{
/* Make our window subclass receive these application notifications */
[ [ NSNotificationCenter defaultCenter ] addObserver:self
selector:@selector(appDidHide:) name:NSApplicationDidHideNotification object:NSApp ];
[ [ NSNotificationCenter defaultCenter ] addObserver:self
selector:@selector(appDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp ];
return [ super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag ];
}
134
135
136
137
138
139
@end
/* Delegate for our NSWindow to send SDLQuit() on close */
@interface SDL_QuartzWindowDelegate : NSObject
{}
- (BOOL)windowShouldClose:(id)sender;
140
@end
141
142
@implementation SDL_QuartzWindowDelegate
143
144
- (BOOL)windowShouldClose:(id)sender
{
145
SDL_PrivateQuit();
146
147
return NO;
}
148
149
@end
150
/* Subclass of NSQuickDrawView for the window's subview */
151
152
@interface SDL_QuartzWindowView : NSQuickDrawView
{}
153
@end
154
155
@implementation SDL_QuartzWindowView
156
@end