From e38f96d60910846cdfed516f80282789bdb685f5 Mon Sep 17 00:00:00 2001 From: planetmaker Date: Tue, 21 Dec 2010 16:00:42 +0000 Subject: [PATCH] (svn r21576) -Codechange: [OSX] Deduplicate code by moving the handling of the view for windowed screen drivers to a common class --- src/video/cocoa/cocoa_v.h | 9 +++++++++ src/video/cocoa/cocoa_v.mm | 30 ++++++++++++++++++++++++++++++ src/video/cocoa/wnd_quartz.mm | 18 +++--------------- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/video/cocoa/cocoa_v.h b/src/video/cocoa/cocoa_v.h index e81125b5bc..97fc23f26c 100644 --- a/src/video/cocoa/cocoa_v.h +++ b/src/video/cocoa/cocoa_v.h @@ -124,6 +124,15 @@ void QZ_HideMouse(); uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int display_depth); +/* Subclass of NSView to fix Quartz rendering */ +@interface OTTD_CocoaView : NSView { + CocoaSubdriver *driver; +} +- (void)setDriver:(CocoaSubdriver*)drv; +- (void)drawRect:(NSRect)rect; +- (BOOL)isOpaque; +@end + /** Delegate for our NSWindow to send ask for quit on close */ @interface OTTD_CocoaWindowDelegate : NSObject { CocoaSubdriver *driver; diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm index 756c86bfba..3abeaad9f4 100644 --- a/src/video/cocoa/cocoa_v.mm +++ b/src/video/cocoa/cocoa_v.mm @@ -407,6 +407,36 @@ void cocoaReleaseAutoreleasePool() [ _ottd_autorelease_pool release ]; } + + +@implementation OTTD_CocoaView +/** + * Initialize the driver + */ +- (void)setDriver:(CocoaSubdriver*)drv +{ + driver = drv; +} +/** + * Define the opaqueness of the window / screen + * @return opaqueness of window / screen + */ +- (BOOL)isOpaque +{ + return YES; +} +/** + * Draws a rectangle on the screen. + * It's overwritten by the individual drivers but must be defined + */ +- (void)drawRect:(NSRect)invalidRect +{ + return; +} +@end + + + @implementation OTTD_CocoaWindowDelegate /** Initialize the video driver */ - (void)setDriver:(CocoaSubdriver*)drv diff --git a/src/video/cocoa/wnd_quartz.mm b/src/video/cocoa/wnd_quartz.mm index 50712cf9d6..9e52e526f9 100644 --- a/src/video/cocoa/wnd_quartz.mm +++ b/src/video/cocoa/wnd_quartz.mm @@ -62,15 +62,10 @@ class WindowQuartzSubdriver; - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag; @end -/* Subclass of NSView to fix Quartz rendering */ -@interface OTTD_QuartzView : NSView { - WindowQuartzSubdriver *driver; -} - +/* Subclass of OTTD_CocoaView to fix Quartz rendering */ +@interface OTTD_QuartzView : OTTD_CocoaView - (void)setDriver:(WindowQuartzSubdriver*)drv; - -- (void)drawRect:(NSRect)rect; -- (BOOL)isOpaque; +- (void)drawRect:(NSRect)invalidRect; @end class WindowQuartzSubdriver: public CocoaSubdriver { @@ -239,13 +234,6 @@ static CGColorSpaceRef QZ_GetCorrectColorSpace() { driver = drv; } - - -- (BOOL)isOpaque -{ - return YES; -} - - (void)drawRect:(NSRect)invalidRect { if (driver->cgcontext == NULL) return;