Skip to content

Latest commit

 

History

History
156 lines (119 loc) · 4.51 KB

SDL_QuartzWindow.m

File metadata and controls

156 lines (119 loc) · 4.51 KB
 
Oct 5, 2002
Oct 5, 2002
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 () {
Jan 22, 2002
Jan 22, 2002
8
Oct 5, 2002
Oct 5, 2002
9
10
SDL_Surface *surface = current_video->screen;
int bpp;
Jan 22, 2002
Jan 22, 2002
11
Oct 5, 2002
Oct 5, 2002
12
bpp = surface->format->BitsPerPixel;
Jan 22, 2002
Jan 22, 2002
13
14
15
if (bpp == 32) {
Oct 5, 2002
Oct 5, 2002
16
17
18
Uint32 *pixels = (Uint32*) surface->pixels;
Uint32 rowPixels = surface->pitch / 4;
Uint32 i, j;
Jan 22, 2002
Jan 22, 2002
19
Oct 5, 2002
Oct 5, 2002
20
21
for (i = 0; i < surface->h; i++)
for (j = 0; j < surface->w; j++) {
Jan 22, 2002
Jan 22, 2002
22
23
24
25
26
27
pixels[ (i * rowPixels) + j ] |= 0xFF000000;
}
}
}
Oct 5, 2002
Oct 5, 2002
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;
May 29, 2003
May 29, 2003
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;
Oct 5, 2002
Oct 5, 2002
37
38
@end
39
40
@implementation SDL_QuartzWindow
Oct 5, 2002
Oct 5, 2002
41
/* we override these methods to fix the miniaturize animation/dock icon bug */
42
43
- (void)miniaturize:(id)sender
{
Jan 22, 2002
Jan 22, 2002
44
45
if (SDL_VideoSurface->flags & SDL_OPENGL) {
Oct 5, 2002
Oct 5, 2002
46
47
48
49
/*
Future: Grab framebuffer and put into NSImage
[ qz_window setMiniwindowImage:image ];
*/
Jan 22, 2002
Jan 22, 2002
50
51
52
}
else {
Oct 5, 2002
Oct 5, 2002
53
54
/* make the alpha channel opaque so anim won't have holes in it */
QZ_SetPortAlphaOpaque ();
Jan 22, 2002
Jan 22, 2002
55
56
}
May 29, 2003
May 29, 2003
57
58
59
/* window is hidden now */
SDL_PrivateAppActive (0, SDL_APPACTIVE);
60
61
62
[ super miniaturize:sender ];
}
Oct 5, 2002
Oct 5, 2002
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 ();
May 29, 2003
May 29, 2003
72
73
74
/* window is visible again */
SDL_PrivateAppActive (1, SDL_APPACTIVE);
Oct 5, 2002
Oct 5, 2002
77
- (void)setFrame:(NSRect)frameRect display:(BOOL)flag
Jun 11, 2001
Jun 11, 2001
78
{
Oct 5, 2002
Oct 5, 2002
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 ] );
}
}
Jun 11, 2001
Jun 11, 2001
110
}
Oct 5, 2002
Oct 5, 2002
111
May 29, 2003
May 29, 2003
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 ];
}
Jun 11, 2001
Jun 11, 2001
134
135
136
137
138
139
@end
/* Delegate for our NSWindow to send SDLQuit() on close */
@interface SDL_QuartzWindowDelegate : NSObject
{}
- (BOOL)windowShouldClose:(id)sender;
Jun 11, 2001
Jun 11, 2001
141
142
@implementation SDL_QuartzWindowDelegate
Oct 5, 2002
Oct 5, 2002
143
144
- (BOOL)windowShouldClose:(id)sender
{
Jun 11, 2001
Jun 11, 2001
145
SDL_PrivateQuit();
Jun 11, 2001
Jun 11, 2001
146
147
return NO;
}
Jan 22, 2002
Jan 22, 2002
148
149
@end
Oct 5, 2002
Oct 5, 2002
150
/* Subclass of NSQuickDrawView for the window's subview */
Jan 22, 2002
Jan 22, 2002
151
152
@interface SDL_QuartzWindowView : NSQuickDrawView
{}
Jun 11, 2001
Jun 11, 2001
153
@end
Jan 22, 2002
Jan 22, 2002
154
155
@implementation SDL_QuartzWindowView
Oct 5, 2002
Oct 5, 2002
156
@end