comparison src/video/quartz/SDL_QuartzWindow.m @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents e49147870aac
children
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
27 /* 27 /*
28 This function makes the *SDL region* of the window 100% opaque. 28 This function makes the *SDL region* of the window 100% opaque.
29 The genie effect uses the alpha component. Otherwise, 29 The genie effect uses the alpha component. Otherwise,
30 it doesn't seem to matter what value it has. 30 it doesn't seem to matter what value it has.
31 */ 31 */
32 static void QZ_SetPortAlphaOpaque () { 32 static void
33 33 QZ_SetPortAlphaOpaque ()
34 {
35
34 SDL_Surface *surface = current_video->screen; 36 SDL_Surface *surface = current_video->screen;
35 int bpp; 37 int bpp;
36 38
37 bpp = surface->format->BitsPerPixel; 39 bpp = surface->format->BitsPerPixel;
38 40
39 if (bpp == 32) { 41 if (bpp == 32) {
40 42
41 Uint32 *pixels = (Uint32*) surface->pixels; 43 Uint32 *pixels = (Uint32 *) surface->pixels;
42 Uint32 rowPixels = surface->pitch / 4; 44 Uint32 rowPixels = surface->pitch / 4;
43 Uint32 i, j; 45 Uint32 i, j;
44 46
45 for (i = 0; i < surface->h; i++) 47 for (i = 0; i < surface->h; i++)
46 for (j = 0; j < surface->w; j++) { 48 for (j = 0; j < surface->w; j++) {
47 49
48 pixels[ (i * rowPixels) + j ] |= 0xFF000000; 50 pixels[(i * rowPixels) + j] |= 0xFF000000;
49 } 51 }
50 } 52 }
51 } 53 }
52 54
53 @implementation SDL_QuartzWindow 55 @implementation SDL_QuartzWindow
54
55 /* we override these methods to fix the miniaturize animation/dock icon bug */ 56 /* we override these methods to fix the miniaturize animation/dock icon bug */
56 - (void)miniaturize:(id)sender 57 - (void) miniaturize:(id) sender {
57 {
58 if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) { 58 if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) {
59 59
60 /* 60 /*
61 Future: Grab framebuffer and put into NSImage 61 Future: Grab framebuffer and put into NSImage
62 [ qz_window setMiniwindowImage:image ]; 62 [ qz_window setMiniwindowImage:image ];
63 */ 63 */
64 } 64 } else {
65 else { 65
66
67 /* make the alpha channel opaque so anim won't have holes in it */ 66 /* make the alpha channel opaque so anim won't have holes in it */
68 QZ_SetPortAlphaOpaque (); 67 QZ_SetPortAlphaOpaque ();
69 } 68 }
70 69
71 /* window is hidden now */ 70 /* window is hidden now */
72 SDL_PrivateAppActive (0, SDL_APPACTIVE); 71 SDL_PrivateAppActive (0, SDL_APPACTIVE);
73 72
74 [ super miniaturize:sender ]; 73 [super miniaturize:sender];
75 } 74 }
76 75
77 - (void)display 76 -(void) display {
78 {
79 /* 77 /*
80 This method fires just before the window deminaturizes from the Dock. 78 This method fires just before the window deminaturizes from the Dock.
81 79
82 We'll save the current visible surface, let the window manager redraw any 80 We'll save the current visible surface, let the window manager redraw any
83 UI elements, and restore the SDL surface. This way, no expose event 81 UI elements, and restore the SDL surface. This way, no expose event
84 is required, and the deminiaturize works perfectly. 82 is required, and the deminiaturize works perfectly.
85 */ 83 */
86 SDL_VideoDevice *this = (SDL_VideoDevice*)current_video; 84 SDL_VideoDevice *this = (SDL_VideoDevice *) current_video;
87 85
88 /* make sure pixels are fully opaque */ 86 /* make sure pixels are fully opaque */
89 if (! ( SDL_VideoSurface->flags & SDL_INTERNALOPENGL ) ) 87 if (!(SDL_VideoSurface->flags & SDL_INTERNALOPENGL))
90 QZ_SetPortAlphaOpaque (); 88 QZ_SetPortAlphaOpaque ();
91 89
92 /* save current visible SDL surface */ 90 /* save current visible SDL surface */
93 [ self cacheImageInRect:[ window_view frame ] ]; 91 [self cacheImageInRect:[window_view frame]];
94 92
95 /* let the window manager redraw controls, border, etc */ 93 /* let the window manager redraw controls, border, etc */
96 [ super display ]; 94 [super display];
97 95
98 /* restore visible SDL surface */ 96 /* restore visible SDL surface */
99 [ self restoreCachedImage ]; 97 [self restoreCachedImage];
100 98
101 /* window is visible again */ 99 /* window is visible again */
102 SDL_PrivateAppActive (1, SDL_APPACTIVE); 100 SDL_PrivateAppActive (1, SDL_APPACTIVE);
103 } 101 }
104 102
105 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag 103 -(void) setFrame:(NSRect)
104 frameRect display:(BOOL) flag
106 { 105 {
107 106
108 /* 107 /*
109 If the video surface is NULL, this originated from QZ_SetVideoMode, 108 If the video surface is NULL, this originated from QZ_SetVideoMode,
110 so don't send the resize event. 109 so don't send the resize event.
111 */ 110 */
112 SDL_VideoDevice *this = (SDL_VideoDevice*)current_video; 111 SDL_VideoDevice *this = (SDL_VideoDevice *) current_video;
113 112
114 if (this && SDL_VideoSurface == NULL) { 113 if (this && SDL_VideoSurface == NULL) {
115 114
116 [ super setFrame:frameRect display:flag ]; 115 [super setFrame: frameRect display:flag];
117 } 116 } else if (this && qz_window) {
118 else if (this && qz_window) {
119 117
120 NSRect newViewFrame; 118 NSRect newViewFrame;
121 119
122 [ super setFrame:frameRect display:flag ]; 120 [super setFrame: frameRect display:flag];
123 121
124 newViewFrame = [ window_view frame ]; 122 newViewFrame =[window_view frame];
125 123
126 SDL_PrivateResize (newViewFrame.size.width, newViewFrame.size.height); 124 SDL_PrivateResize (newViewFrame.size.width, newViewFrame.size.height);
127 125
128 /* If not OpenGL, we have to update the pixels and pitch */ 126 /* If not OpenGL, we have to update the pixels and pitch */
129 if ( ! ( SDL_VideoSurface->flags & SDL_INTERNALOPENGL ) ) { 127 if (!(SDL_VideoSurface->flags & SDL_INTERNALOPENGL)) {
130 128
131 CGrafPtr thePort = [ window_view qdPort ]; 129 CGrafPtr thePort =[window_view qdPort];
132 LockPortBits ( thePort ); 130 LockPortBits (thePort);
133 131
134 SDL_VideoSurface->pixels = GetPixBaseAddr ( GetPortPixMap ( thePort ) ); 132 SDL_VideoSurface->pixels =
135 SDL_VideoSurface->pitch = GetPixRowBytes ( GetPortPixMap ( thePort ) ); 133 GetPixBaseAddr (GetPortPixMap (thePort));
136 134 SDL_VideoSurface->pitch =
135 GetPixRowBytes (GetPortPixMap (thePort));
136
137 /* 137 /*
138 SDL_VideoSurface->pixels now points to the window's pixels 138 SDL_VideoSurface->pixels now points to the window's pixels
139 We want it to point to the *view's* pixels 139 We want it to point to the *view's* pixels
140 */ 140 */
141 { 141 {
142 int vOffset = [ qz_window frame ].size.height - 142 int vOffset =[qz_window frame].size.height -
143 newViewFrame.size.height - newViewFrame.origin.y; 143 newViewFrame.size.height - newViewFrame.origin.y;
144 144
145 int hOffset = newViewFrame.origin.x; 145 int hOffset = newViewFrame.origin.x;
146 146
147 SDL_VideoSurface->pixels = (Uint8 *)SDL_VideoSurface->pixels + (vOffset * SDL_VideoSurface->pitch) + hOffset * (device_bpp/8); 147 SDL_VideoSurface->pixels =
148 (Uint8 *) SDL_VideoSurface->pixels +
149 (vOffset * SDL_VideoSurface->pitch) +
150 hOffset * (device_bpp / 8);
148 } 151 }
149 152
150 UnlockPortBits ( thePort ); 153 UnlockPortBits (thePort);
151 } 154 }
152 } 155 }
153 } 156 }
154 157
155 - (void)appDidHide:(NSNotification*)note 158 -(void) appDidHide:(NSNotification *) note {
156 {
157 SDL_PrivateAppActive (0, SDL_APPACTIVE); 159 SDL_PrivateAppActive (0, SDL_APPACTIVE);
158 } 160 }
159 161
160 - (void)appWillUnhide:(NSNotification*)note 162 -(void) appWillUnhide:(NSNotification *) note {
161 { 163 SDL_VideoDevice *this = (SDL_VideoDevice *) current_video;
162 SDL_VideoDevice *this = (SDL_VideoDevice*)current_video; 164
163 165 if (this) {
164 if ( this ) { 166
165
166 /* make sure pixels are fully opaque */ 167 /* make sure pixels are fully opaque */
167 if (! ( SDL_VideoSurface->flags & SDL_INTERNALOPENGL ) ) 168 if (!(SDL_VideoSurface->flags & SDL_INTERNALOPENGL))
168 QZ_SetPortAlphaOpaque (); 169 QZ_SetPortAlphaOpaque ();
169 170
170 /* save current visible SDL surface */ 171 /* save current visible SDL surface */
171 [ self cacheImageInRect:[ window_view frame ] ]; 172 [self cacheImageInRect:[window_view frame]];
172 } 173 }
173 } 174 }
174 175
175 - (void)appDidUnhide:(NSNotification*)note 176 -(void) appDidUnhide:(NSNotification *) note {
176 {
177 /* restore cached image, since it may not be current, post expose event too */ 177 /* restore cached image, since it may not be current, post expose event too */
178 [ self restoreCachedImage ]; 178 [self restoreCachedImage];
179 179
180 /*SDL_PrivateExpose ();*/ 180 /*SDL_PrivateExpose (); */
181 181
182 SDL_PrivateAppActive (1, SDL_APPACTIVE); 182 SDL_PrivateAppActive (1, SDL_APPACTIVE);
183 } 183 }
184 184
185 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag 185 -(id) initWithContentRect:(NSRect)
186 contentRect styleMask:(unsigned int)
187 styleMask backing:(NSBackingStoreType)
188 backingType defer:(BOOL) flag
186 { 189 {
187 /* Make our window subclass receive these application notifications */ 190 /* Make our window subclass receive these application notifications */
188 [ [ NSNotificationCenter defaultCenter ] addObserver:self 191 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (appDidHide: )name: NSApplicationDidHideNotification object:NSApp];
189 selector:@selector(appDidHide:) name:NSApplicationDidHideNotification object:NSApp ]; 192
190 193 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (appDidUnhide: )name: NSApplicationDidUnhideNotification object:NSApp];
191 [ [ NSNotificationCenter defaultCenter ] addObserver:self 194
192 selector:@selector(appDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp ]; 195 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (appWillUnhide: )name: NSApplicationWillUnhideNotification object:NSApp];
193 196
194 [ [ NSNotificationCenter defaultCenter ] addObserver:self 197 return[super initWithContentRect: contentRect styleMask: styleMask backing: backingType defer:flag];
195 selector:@selector(appWillUnhide:) name:NSApplicationWillUnhideNotification object:NSApp ]; 198 }
196 199
197 return [ super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag ]; 200 @end @ implementation SDL_QuartzWindowDelegate - (BOOL) windowShouldClose:(id) sender
201 {
202 SDL_PrivateQuit ();
203 return NO;
204 }
205
206 -(void) windowDidBecomeKey:(NSNotification *) aNotification {
207 QZ_DoActivate (current_video);
208 }
209
210 -(void) windowDidResignKey:(NSNotification *) aNotification {
211 QZ_DoDeactivate (current_video);
198 } 212 }
199 213
200 @end 214 @end
201
202 @implementation SDL_QuartzWindowDelegate
203 - (BOOL)windowShouldClose:(id)sender
204 {
205 SDL_PrivateQuit();
206 return NO;
207 }
208
209 - (void)windowDidBecomeKey:(NSNotification *)aNotification
210 {
211 QZ_DoActivate (current_video);
212 }
213
214 - (void)windowDidResignKey:(NSNotification *)aNotification
215 {
216 QZ_DoDeactivate (current_video);
217 }
218
219 @end