From 30eef98ec0e5db58cb214624bd0eef8d8bf34c20 Mon Sep 17 00:00:00 2001 From: planetmaker Date: Tue, 21 Dec 2010 16:02:55 +0000 Subject: (svn r21577) -Codechange: [OSX] Deduplicate code by moving the handling of the window class for screen drivers to a common class --- src/video/cocoa/wnd_quartz.mm | 111 +----------------------------------------- 1 file changed, 1 insertion(+), 110 deletions(-) (limited to 'src/video/cocoa/wnd_quartz.mm') diff --git a/src/video/cocoa/wnd_quartz.mm b/src/video/cocoa/wnd_quartz.mm index 9e52e526f..211f5f11e 100644 --- a/src/video/cocoa/wnd_quartz.mm +++ b/src/video/cocoa/wnd_quartz.mm @@ -45,23 +45,6 @@ class WindowQuartzSubdriver; - -/* Subclass of NSWindow to fix genie effect and support resize events */ -@interface OTTD_QuartzWindow : NSWindow { - WindowQuartzSubdriver *driver; -} - -- (void)setDriver:(WindowQuartzSubdriver*)drv; - -- (void)miniaturize:(id)sender; -- (void)display; -- (void)setFrame:(NSRect)frameRect display:(BOOL)flag; -- (void)appDidHide:(NSNotification*)note; -- (void)appWillUnhide:(NSNotification*)note; -- (void)appDidUnhide:(NSNotification*)note; -- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag; -@end - /* Subclass of OTTD_CocoaView to fix Quartz rendering */ @interface OTTD_QuartzView : OTTD_CocoaView - (void)setDriver:(WindowQuartzSubdriver*)drv; @@ -136,98 +119,6 @@ static CGColorSpaceRef QZ_GetCorrectColorSpace() } -@implementation OTTD_QuartzWindow - -- (void)setDriver:(WindowQuartzSubdriver*)drv -{ - driver = drv; -} - - -/* we override these methods to fix the miniaturize animation/dock icon bug */ -- (void)miniaturize:(id)sender -{ - /* make the alpha channel opaque so anim won't have holes in it */ - driver->SetPortAlphaOpaque (); - - /* window is hidden now */ - driver->active = false; - - QZ_ShowMouse(); - - [ super miniaturize:sender ]; -} - -- (void)display -{ - /* 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 surface. This way, no expose event - * is required, and the deminiaturize works perfectly. - */ - - driver->SetPortAlphaOpaque(); - - /* save current visible surface */ - [ self cacheImageInRect:[ driver->cocoaview frame ] ]; - - /* let the window manager redraw controls, border, etc */ - [ super display ]; - - /* restore visible surface */ - [ self restoreCachedImage ]; - - /* window is visible again */ - driver->active = true; -} - -- (void)setFrame:(NSRect)frameRect display:(BOOL)flag -{ - [ super setFrame:frameRect display:flag ]; - - /* Don't do anything if the window is currently being created */ - if (driver->setup) return; - - if (!driver->WindowResized()) error("Cocoa: Failed to resize window."); -} - -- (void)appDidHide:(NSNotification*)note -{ - driver->active = false; -} - - -- (void)appWillUnhide:(NSNotification*)note -{ - driver->SetPortAlphaOpaque (); - - /* save current visible surface */ - [ self cacheImageInRect:[ driver->cocoaview frame ] ]; -} - -- (void)appDidUnhide:(NSNotification*)note -{ - /* restore cached image, since it may not be current, post expose event too */ - [ self restoreCachedImage ]; - - driver->active = true; -} - - -- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)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 ]; - - [ [ NSNotificationCenter defaultCenter ] addObserver:self selector:@selector(appWillUnhide:) name:NSApplicationWillUnhideNotification object:NSApp ]; - - return [ super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag ]; -} - -@end - @implementation OTTD_QuartzView - (void)setDriver:(WindowQuartzSubdriver*)drv @@ -350,7 +241,7 @@ bool WindowQuartzSubdriver::SetVideoMode(int width, int height) style |= NSResizableWindowMask; /* Manually create a window, avoids having a nib file resource */ - this->window = [ [ OTTD_QuartzWindow alloc ] + this->window = [ [ OTTD_CocoaWindow alloc ] initWithContentRect:contentRect styleMask:style backing:NSBackingStoreBuffered -- cgit v1.2.3-70-g09d2