Mercurial > sdl-ios-xcode
comparison src/video/quartz/SDL_QuartzWindow.m @ 683:5d2f027b3349
Date: Sat, 9 Aug 2003 20:14:06 -0400
From: Darrell Walisser
Subject: Re: Updated projects?
>> Did you get a chance to look at my "Custom Cocoa" demo? I have a few
>> minor patches that enable SDL/Cocoa integration, and a project
>> template.
>
> I didn't yet, but go ahead and send me the patches. :)
>
I updated the patch for current CVS. There are a lot of changes, but I
don't think I've broken anything. This patch also improves the behavior
of window minimize/deminimize.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 10 Aug 2003 07:21:43 +0000 |
parents | 52864d66d168 |
children | c5b2b6d2d1fe |
comparison
equal
deleted
inserted
replaced
682:8b2b97e466bc | 683:5d2f027b3349 |
---|---|
30 {} | 30 {} |
31 - (void)miniaturize:(id)sender; | 31 - (void)miniaturize:(id)sender; |
32 - (void)display; | 32 - (void)display; |
33 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag; | 33 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag; |
34 - (void)appDidHide:(NSNotification*)note; | 34 - (void)appDidHide:(NSNotification*)note; |
35 - (void)appWillUnhide:(NSNotification*)note; | |
35 - (void)appDidUnhide:(NSNotification*)note; | 36 - (void)appDidUnhide:(NSNotification*)note; |
36 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag; | 37 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag; |
37 @end | 38 @end |
38 | 39 |
39 @implementation SDL_QuartzWindow | 40 @implementation SDL_QuartzWindow |
61 } | 62 } |
62 | 63 |
63 - (void)display | 64 - (void)display |
64 { | 65 { |
65 /* | 66 /* |
66 This method fires just before the window deminaturizes. | 67 This method fires just before the window deminaturizes from the Dock. |
67 So, it's just the right place to fixup the alpha channel - which | 68 |
68 makes the deminiaturize animation look right. | 69 We'll save the current visible surface, let the window manager redraw any |
70 UI elements, and restore the SDL surface. This way, no expose event | |
71 is required, and the deminiaturize works perfectly. | |
69 */ | 72 */ |
70 if ( (SDL_VideoSurface->flags & SDL_OPENGL) == 0) | 73 SDL_VideoDevice *this = (SDL_VideoDevice*)current_video; |
74 | |
75 /* make sure pixels are fully opaque */ | |
76 if (! ( SDL_VideoSurface->flags & SDL_OPENGL ) ) | |
71 QZ_SetPortAlphaOpaque (); | 77 QZ_SetPortAlphaOpaque (); |
72 | 78 |
79 /* save current visible SDL surface */ | |
80 [ self cacheImageInRect:[ window_view frame ] ]; | |
81 | |
82 /* let the window manager redraw controls, border, etc */ | |
83 [ super display ]; | |
84 | |
85 /* restore visible SDL surface */ | |
86 [ self restoreCachedImage ]; | |
87 | |
73 /* window is visible again */ | 88 /* window is visible again */ |
74 SDL_PrivateAppActive (1, SDL_APPACTIVE); | 89 SDL_PrivateAppActive (1, SDL_APPACTIVE); |
75 } | 90 } |
76 | 91 |
77 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag | 92 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag |
79 | 94 |
80 /* | 95 /* |
81 If the video surface is NULL, this originated from QZ_SetVideoMode, | 96 If the video surface is NULL, this originated from QZ_SetVideoMode, |
82 so don't send the resize event. | 97 so don't send the resize event. |
83 */ | 98 */ |
84 if (SDL_VideoSurface == NULL) { | 99 SDL_VideoDevice *this = (SDL_VideoDevice*)current_video; |
100 | |
101 if (this && SDL_VideoSurface == NULL) { | |
85 | 102 |
86 [ super setFrame:frameRect display:flag ]; | 103 [ super setFrame:frameRect display:flag ]; |
87 } | 104 } |
88 else { | 105 else if (this && qz_window) { |
89 | 106 |
90 SDL_VideoDevice *this = (SDL_VideoDevice*)current_video; | 107 NSRect newViewFrame; |
91 | 108 |
92 NSRect sdlRect = [ NSWindow contentRectForFrameRect:frameRect styleMask:[self styleMask] ]; | |
93 | |
94 [ super setFrame:frameRect display:flag ]; | 109 [ super setFrame:frameRect display:flag ]; |
95 SDL_PrivateResize (sdlRect.size.width, sdlRect.size.height); | 110 |
111 newViewFrame = [ window_view frame ]; | |
112 | |
113 SDL_PrivateResize (newViewFrame.size.width, newViewFrame.size.height); | |
96 | 114 |
97 /* If not OpenGL, we have to update the pixels and pitch */ | 115 /* If not OpenGL, we have to update the pixels and pitch */ |
98 if ( ! this->screen->flags & SDL_OPENGL ) { | 116 if ( ! ( SDL_VideoSurface->flags & SDL_OPENGL ) ) { |
99 | 117 |
100 LockPortBits ( [ window_view qdPort ] ); | 118 CGrafPtr thePort = [ window_view qdPort ]; |
119 LockPortBits ( thePort ); | |
101 | 120 |
102 SDL_VideoSurface->pixels = GetPixBaseAddr ( GetPortPixMap ( [ window_view qdPort ] ) ); | 121 SDL_VideoSurface->pixels = GetPixBaseAddr ( GetPortPixMap ( thePort ) ); |
103 SDL_VideoSurface->pitch = GetPixRowBytes ( GetPortPixMap ( [ window_view qdPort ] ) ); | 122 SDL_VideoSurface->pitch = GetPixRowBytes ( GetPortPixMap ( thePort ) ); |
123 | |
124 /* | |
125 SDL_VideoSurface->pixels now points to the window's pixels | |
126 We want it to point to the *view's* pixels | |
127 */ | |
128 { | |
129 int vOffset = [ qz_window frame ].size.height - | |
130 newViewFrame.size.height - newViewFrame.origin.y; | |
131 | |
132 int hOffset = newViewFrame.origin.x; | |
133 | |
134 SDL_VideoSurface->pixels += (vOffset * SDL_VideoSurface->pitch) + hOffset * (device_bpp/8); | |
135 } | |
104 | 136 |
105 SDL_VideoSurface->pixels += ((int)[ self frame ].size.height - (int)sdlRect.size.height) * SDL_VideoSurface->pitch; | 137 UnlockPortBits ( thePort ); |
106 | |
107 UnlockPortBits ( [ window_view qdPort ] ); | |
108 } | 138 } |
109 } | 139 } |
110 } | 140 } |
111 | 141 |
112 - (void)appDidHide:(NSNotification*)note | 142 - (void)appDidHide:(NSNotification*)note |
113 { | 143 { |
114 SDL_PrivateAppActive (0, SDL_APPACTIVE); | 144 SDL_PrivateAppActive (0, SDL_APPACTIVE); |
115 } | 145 } |
116 | 146 |
147 - (void)appWillUnhide:(NSNotification*)note | |
148 { | |
149 SDL_VideoDevice *this = (SDL_VideoDevice*)current_video; | |
150 | |
151 if ( this ) { | |
152 | |
153 /* make sure pixels are fully opaque */ | |
154 if (! ( SDL_VideoSurface->flags & SDL_OPENGL ) ) | |
155 QZ_SetPortAlphaOpaque (); | |
156 | |
157 /* save current visible SDL surface */ | |
158 [ self cacheImageInRect:[ window_view frame ] ]; | |
159 } | |
160 } | |
161 | |
117 - (void)appDidUnhide:(NSNotification*)note | 162 - (void)appDidUnhide:(NSNotification*)note |
118 { | 163 { |
164 /* restore cached image, since it may not be current, post expose event too */ | |
165 [ self restoreCachedImage ]; | |
166 | |
167 //SDL_PrivateExpose (); | |
168 | |
119 SDL_PrivateAppActive (1, SDL_APPACTIVE); | 169 SDL_PrivateAppActive (1, SDL_APPACTIVE); |
120 } | 170 } |
121 | 171 |
122 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag | 172 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag |
123 { | 173 { |
125 [ [ NSNotificationCenter defaultCenter ] addObserver:self | 175 [ [ NSNotificationCenter defaultCenter ] addObserver:self |
126 selector:@selector(appDidHide:) name:NSApplicationDidHideNotification object:NSApp ]; | 176 selector:@selector(appDidHide:) name:NSApplicationDidHideNotification object:NSApp ]; |
127 | 177 |
128 [ [ NSNotificationCenter defaultCenter ] addObserver:self | 178 [ [ NSNotificationCenter defaultCenter ] addObserver:self |
129 selector:@selector(appDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp ]; | 179 selector:@selector(appDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp ]; |
180 | |
181 [ [ NSNotificationCenter defaultCenter ] addObserver:self | |
182 selector:@selector(appWillUnhide:) name:NSApplicationWillUnhideNotification object:NSApp ]; | |
130 | 183 |
131 return [ super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag ]; | 184 return [ super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag ]; |
132 } | 185 } |
133 | 186 |
134 @end | 187 @end |