From 26575ab8f880a39dc9c07203d4f8b31eb667fdac Mon Sep 17 00:00:00 2001 From: planetmaker Date: Tue, 21 Dec 2010 15:57:55 +0000 Subject: (svn r21575) -Codechange: [OSX] Use the same class for the window delegate routines in windowed screen drivers --- src/video/cocoa/cocoa_v.h | 11 +++++++++ src/video/cocoa/cocoa_v.mm | 36 +++++++++++++++++++++++++++++ src/video/cocoa/wnd_quartz.mm | 50 ++-------------------------------------- src/video/cocoa/wnd_quickdraw.mm | 50 ++-------------------------------------- 4 files changed, 51 insertions(+), 96 deletions(-) (limited to 'src') diff --git a/src/video/cocoa/cocoa_v.h b/src/video/cocoa/cocoa_v.h index 2d789d89e..e81125b5b 100644 --- a/src/video/cocoa/cocoa_v.h +++ b/src/video/cocoa/cocoa_v.h @@ -124,4 +124,15 @@ void QZ_HideMouse(); uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int display_depth); +/** Delegate for our NSWindow to send ask for quit on close */ +@interface OTTD_CocoaWindowDelegate : NSObject { + CocoaSubdriver *driver; +} + +- (void)setDriver:(CocoaSubdriver*)drv; + +- (BOOL)windowShouldClose:(id)sender; +@end + + #endif /* VIDEO_COCOA_H */ diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm index 793e1b206..756c86bfb 100644 --- a/src/video/cocoa/cocoa_v.mm +++ b/src/video/cocoa/cocoa_v.mm @@ -407,4 +407,40 @@ void cocoaReleaseAutoreleasePool() [ _ottd_autorelease_pool release ]; } +@implementation OTTD_CocoaWindowDelegate +/** Initialize the video driver */ +- (void)setDriver:(CocoaSubdriver*)drv +{ + driver = drv; +} +/** Handle closure requests */ +- (BOOL)windowShouldClose:(id)sender +{ + HandleExitGameRequest(); + + return NO; +} +/** Handle key acceptance */ +- (void)windowDidBecomeKey:(NSNotification*)aNotification +{ + driver->active = true; +} +/** Resign key acceptance */ +- (void)windowDidResignKey:(NSNotification*)aNotification +{ + driver->active = false; +} +/** Handle becoming main window */ +- (void)windowDidBecomeMain:(NSNotification*)aNotification +{ + driver->active = true; +} +/** Resign being main window */ +- (void)windowDidResignMain:(NSNotification*)aNotification +{ + driver->active = false; +} + +@end + #endif /* WITH_COCOA */ diff --git a/src/video/cocoa/wnd_quartz.mm b/src/video/cocoa/wnd_quartz.mm index b9a84160f..50712cf9d 100644 --- a/src/video/cocoa/wnd_quartz.mm +++ b/src/video/cocoa/wnd_quartz.mm @@ -62,16 +62,6 @@ class WindowQuartzSubdriver; - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag; @end -/* Delegate for our NSWindow to send ask for quit on close */ -@interface OTTD_QuartzWindowDelegate : NSObject { - WindowQuartzSubdriver *driver; -} - -- (void)setDriver:(WindowQuartzSubdriver*)drv; - -- (BOOL)windowShouldClose:(id)sender; -@end - /* Subclass of NSView to fix Quartz rendering */ @interface OTTD_QuartzView : NSView { WindowQuartzSubdriver *driver; @@ -243,42 +233,6 @@ static CGColorSpaceRef QZ_GetCorrectColorSpace() @end -@implementation OTTD_QuartzWindowDelegate - -- (void)setDriver:(WindowQuartzSubdriver*)drv -{ - driver = drv; -} - -- (BOOL)windowShouldClose:(id)sender -{ - HandleExitGameRequest(); - - return NO; -} - -- (void)windowDidBecomeKey:(NSNotification*)aNotification -{ - driver->active = true; -} - -- (void)windowDidResignKey:(NSNotification*)aNotification -{ - driver->active = false; -} - -- (void)windowDidBecomeMain:(NSNotification*)aNotification -{ - driver->active = true; -} - -- (void)windowDidResignMain:(NSNotification*)aNotification -{ - driver->active = false; -} - -@end - @implementation OTTD_QuartzView - (void)setDriver:(WindowQuartzSubdriver*)drv @@ -400,7 +354,7 @@ bool WindowQuartzSubdriver::SetVideoMode(int width, int height) /* Check if we should recreate the window */ if (this->window == nil) { - OTTD_QuartzWindowDelegate *delegate; + OTTD_CocoaWindowDelegate *delegate; /* Set the window style */ unsigned int style = NSTitledWindowMask; @@ -436,7 +390,7 @@ bool WindowQuartzSubdriver::SetVideoMode(int width, int height) [ this->window useOptimizedDrawing:YES ]; - delegate = [ [ OTTD_QuartzWindowDelegate alloc ] init ]; + delegate = [ [ OTTD_CocoaWindowDelegate alloc ] init ]; [ delegate setDriver:this ]; [ this->window setDelegate:[ delegate autorelease ] ]; } else { diff --git a/src/video/cocoa/wnd_quickdraw.mm b/src/video/cocoa/wnd_quickdraw.mm index de38e26c0..0e5340a62 100644 --- a/src/video/cocoa/wnd_quickdraw.mm +++ b/src/video/cocoa/wnd_quickdraw.mm @@ -62,16 +62,6 @@ class WindowQuickdrawSubdriver; - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag; @end -/* Delegate for our NSWindow to send ask for quit on close */ -@interface OTTD_QuickdrawWindowDelegate : NSObject { - WindowQuickdrawSubdriver *driver; -} - -- (void)setDriver:(WindowQuickdrawSubdriver*)drv; - -- (BOOL)windowShouldClose:(id)sender; -@end - class WindowQuickdrawSubdriver: public CocoaSubdriver { private: /** @@ -236,42 +226,6 @@ public: @end -@implementation OTTD_QuickdrawWindowDelegate -- (void)setDriver:(WindowQuickdrawSubdriver*)drv -{ - driver = drv; -} - -- (BOOL)windowShouldClose:(id)sender -{ - HandleExitGameRequest(); - - return NO; -} - -- (void)windowDidBecomeKey:(NSNotification*)aNotification -{ - driver->active = true; -} - -- (void)windowDidResignKey:(NSNotification*)aNotification -{ - driver->active = false; -} - -- (void)windowDidBecomeMain:(NSNotification*)aNotification -{ - driver->active = true; -} - -- (void)windowDidResignMain:(NSNotification*)aNotification -{ - driver->active = false; -} - -@end - - static const int _resize_icon_width = 16; static const int _resize_icon_height = 16; @@ -329,7 +283,7 @@ bool WindowQuickdrawSubdriver::SetVideoMode(int width, int height) /* Check if we should recreate the window */ if (this->window == nil) { - OTTD_QuickdrawWindowDelegate *delegate; + OTTD_CocoaWindowDelegate *delegate; /* Set the window style */ unsigned int style = NSTitledWindowMask; @@ -360,7 +314,7 @@ bool WindowQuickdrawSubdriver::SetVideoMode(int width, int height) [ this->window setAcceptsMouseMovedEvents:YES ]; [ this->window setViewsNeedDisplay:NO ]; - delegate = [ [ OTTD_QuickdrawWindowDelegate alloc ] init ]; + delegate = [ [ OTTD_CocoaWindowDelegate alloc ] init ]; [ delegate setDriver:this ]; [ this->window setDelegate: [ delegate autorelease ] ]; } else { -- cgit v1.2.3-70-g09d2