Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
219 lines (162 loc) · 6.59 KB

SDL_QuartzWindow.m

File metadata and controls

219 lines (162 loc) · 6.59 KB
 
Jan 4, 2004
Jan 4, 2004
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2003 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Jan 4, 2004
Jan 4, 2004
23
24
25
#include "SDL_QuartzVideo.h"
#include "SDL_QuartzWindow.h"
Oct 5, 2002
Oct 5, 2002
27
28
29
30
31
32
/*
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
33
Oct 5, 2002
Oct 5, 2002
34
35
SDL_Surface *surface = current_video->screen;
int bpp;
Jan 22, 2002
Jan 22, 2002
36
Oct 5, 2002
Oct 5, 2002
37
bpp = surface->format->BitsPerPixel;
Jan 22, 2002
Jan 22, 2002
38
39
40
if (bpp == 32) {
Oct 5, 2002
Oct 5, 2002
41
42
43
Uint32 *pixels = (Uint32*) surface->pixels;
Uint32 rowPixels = surface->pitch / 4;
Uint32 i, j;
Jan 22, 2002
Jan 22, 2002
44
Oct 5, 2002
Oct 5, 2002
45
46
for (i = 0; i < surface->h; i++)
for (j = 0; j < surface->w; j++) {
Jan 22, 2002
Jan 22, 2002
47
48
49
50
51
52
pixels[ (i * rowPixels) + j ] |= 0xFF000000;
}
}
}
53
54
@implementation SDL_QuartzWindow
Oct 5, 2002
Oct 5, 2002
55
/* we override these methods to fix the miniaturize animation/dock icon bug */
56
57
- (void)miniaturize:(id)sender
{
May 1, 2006
May 1, 2006
58
if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) {
Jan 22, 2002
Jan 22, 2002
59
Oct 5, 2002
Oct 5, 2002
60
61
62
63
/*
Future: Grab framebuffer and put into NSImage
[ qz_window setMiniwindowImage:image ];
*/
Jan 22, 2002
Jan 22, 2002
64
65
66
}
else {
Oct 5, 2002
Oct 5, 2002
67
68
/* make the alpha channel opaque so anim won't have holes in it */
QZ_SetPortAlphaOpaque ();
Jan 22, 2002
Jan 22, 2002
69
70
}
May 29, 2003
May 29, 2003
71
72
73
/* window is hidden now */
SDL_PrivateAppActive (0, SDL_APPACTIVE);
74
75
76
[ super miniaturize:sender ];
}
Oct 5, 2002
Oct 5, 2002
77
78
79
- (void)display
{
/*
Aug 10, 2003
Aug 10, 2003
80
81
82
83
84
This method fires just before the window deminaturizes from the Dock.
We'll save the current visible surface, let the window manager redraw any
UI elements, and restore the SDL surface. This way, no expose event
is required, and the deminiaturize works perfectly.
Oct 5, 2002
Oct 5, 2002
85
*/
Aug 10, 2003
Aug 10, 2003
86
87
88
SDL_VideoDevice *this = (SDL_VideoDevice*)current_video;
/* make sure pixels are fully opaque */
May 1, 2006
May 1, 2006
89
if (! ( SDL_VideoSurface->flags & SDL_INTERNALOPENGL ) )
Oct 5, 2002
Oct 5, 2002
90
QZ_SetPortAlphaOpaque ();
Aug 10, 2003
Aug 10, 2003
91
92
93
94
95
96
97
98
99
100
/* save current visible SDL surface */
[ self cacheImageInRect:[ window_view frame ] ];
/* let the window manager redraw controls, border, etc */
[ super display ];
/* restore visible SDL surface */
[ self restoreCachedImage ];
May 29, 2003
May 29, 2003
101
102
/* window is visible again */
SDL_PrivateAppActive (1, SDL_APPACTIVE);
Oct 5, 2002
Oct 5, 2002
105
- (void)setFrame:(NSRect)frameRect display:(BOOL)flag
Jun 11, 2001
Jun 11, 2001
106
{
Oct 5, 2002
Oct 5, 2002
107
108
109
110
111
/*
If the video surface is NULL, this originated from QZ_SetVideoMode,
so don't send the resize event.
*/
Aug 10, 2003
Aug 10, 2003
112
113
114
SDL_VideoDevice *this = (SDL_VideoDevice*)current_video;
if (this && SDL_VideoSurface == NULL) {
Oct 5, 2002
Oct 5, 2002
115
116
117
[ super setFrame:frameRect display:flag ];
}
Aug 10, 2003
Aug 10, 2003
118
else if (this && qz_window) {
Oct 5, 2002
Oct 5, 2002
119
Aug 10, 2003
Aug 10, 2003
120
NSRect newViewFrame;
Oct 5, 2002
Oct 5, 2002
121
122
[ super setFrame:frameRect display:flag ];
Aug 10, 2003
Aug 10, 2003
123
124
125
126
newViewFrame = [ window_view frame ];
SDL_PrivateResize (newViewFrame.size.width, newViewFrame.size.height);
Oct 5, 2002
Oct 5, 2002
127
128
/* If not OpenGL, we have to update the pixels and pitch */
May 1, 2006
May 1, 2006
129
if ( ! ( SDL_VideoSurface->flags & SDL_INTERNALOPENGL ) ) {
Oct 5, 2002
Oct 5, 2002
130
Aug 10, 2003
Aug 10, 2003
131
132
CGrafPtr thePort = [ window_view qdPort ];
LockPortBits ( thePort );
Oct 5, 2002
Oct 5, 2002
133
Aug 10, 2003
Aug 10, 2003
134
135
136
137
138
139
140
141
142
143
144
145
146
SDL_VideoSurface->pixels = GetPixBaseAddr ( GetPortPixMap ( thePort ) );
SDL_VideoSurface->pitch = GetPixRowBytes ( GetPortPixMap ( thePort ) );
/*
SDL_VideoSurface->pixels now points to the window's pixels
We want it to point to the *view's* pixels
*/
{
int vOffset = [ qz_window frame ].size.height -
newViewFrame.size.height - newViewFrame.origin.y;
int hOffset = newViewFrame.origin.x;
Mar 9, 2006
Mar 9, 2006
147
SDL_VideoSurface->pixels = (Uint8 *)SDL_VideoSurface->pixels + (vOffset * SDL_VideoSurface->pitch) + hOffset * (device_bpp/8);
Aug 10, 2003
Aug 10, 2003
148
}
Oct 5, 2002
Oct 5, 2002
149
Aug 10, 2003
Aug 10, 2003
150
UnlockPortBits ( thePort );
Oct 5, 2002
Oct 5, 2002
151
152
}
}
Jun 11, 2001
Jun 11, 2001
153
}
Oct 5, 2002
Oct 5, 2002
154
May 29, 2003
May 29, 2003
155
156
157
158
159
- (void)appDidHide:(NSNotification*)note
{
SDL_PrivateAppActive (0, SDL_APPACTIVE);
}
Aug 10, 2003
Aug 10, 2003
160
161
162
163
164
165
166
- (void)appWillUnhide:(NSNotification*)note
{
SDL_VideoDevice *this = (SDL_VideoDevice*)current_video;
if ( this ) {
/* make sure pixels are fully opaque */
May 1, 2006
May 1, 2006
167
if (! ( SDL_VideoSurface->flags & SDL_INTERNALOPENGL ) )
Aug 10, 2003
Aug 10, 2003
168
169
170
171
172
173
174
QZ_SetPortAlphaOpaque ();
/* save current visible SDL surface */
[ self cacheImageInRect:[ window_view frame ] ];
}
}
May 29, 2003
May 29, 2003
175
176
- (void)appDidUnhide:(NSNotification*)note
{
Aug 10, 2003
Aug 10, 2003
177
178
179
/* restore cached image, since it may not be current, post expose event too */
[ self restoreCachedImage ];
Mar 9, 2006
Mar 9, 2006
180
/*SDL_PrivateExpose ();*/
Aug 10, 2003
Aug 10, 2003
181
May 29, 2003
May 29, 2003
182
183
184
185
186
187
188
189
190
191
192
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 ];
Aug 10, 2003
Aug 10, 2003
193
194
195
[ [ NSNotificationCenter defaultCenter ] addObserver:self
selector:@selector(appWillUnhide:) name:NSApplicationWillUnhideNotification object:NSApp ];
May 29, 2003
May 29, 2003
196
197
198
199
return [ super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag ];
}
Jun 11, 2001
Jun 11, 2001
200
201
202
@end
@implementation SDL_QuartzWindowDelegate
Oct 5, 2002
Oct 5, 2002
203
204
- (BOOL)windowShouldClose:(id)sender
{
Jun 11, 2001
Jun 11, 2001
205
SDL_PrivateQuit();
Jun 11, 2001
Jun 11, 2001
206
207
return NO;
}
Jan 7, 2004
Jan 7, 2004
208
209
210
- (void)windowDidBecomeKey:(NSNotification *)aNotification
{
Apr 13, 2006
Apr 13, 2006
211
QZ_DoActivate (current_video);
Jan 7, 2004
Jan 7, 2004
212
213
214
215
}
- (void)windowDidResignKey:(NSNotification *)aNotification
{
Apr 13, 2006
Apr 13, 2006
216
QZ_DoDeactivate (current_video);
Jan 7, 2004
Jan 7, 2004
217
218
}
Jan 22, 2002
Jan 22, 2002
219
@end