summaryrefslogtreecommitdiff
path: root/src/video
diff options
context:
space:
mode:
authorplanetmaker <planetmaker@openttd.org>2010-12-21 16:02:55 +0000
committerplanetmaker <planetmaker@openttd.org>2010-12-21 16:02:55 +0000
commit30eef98ec0e5db58cb214624bd0eef8d8bf34c20 (patch)
tree793f0647438022e7ba33699dbd6bebbbb8207aad /src/video
parente38f96d60910846cdfed516f80282789bdb685f5 (diff)
downloadopenttd-30eef98ec0e5db58cb214624bd0eef8d8bf34c20.tar.xz
(svn r21577) -Codechange: [OSX] Deduplicate code by moving the handling of the window class for screen drivers to a common class
Diffstat (limited to 'src/video')
-rw-r--r--src/video/cocoa/cocoa_v.h19
-rw-r--r--src/video/cocoa/cocoa_v.mm107
-rw-r--r--src/video/cocoa/wnd_quartz.mm111
-rw-r--r--src/video/cocoa/wnd_quickdraw.mm114
4 files changed, 127 insertions, 224 deletions
diff --git a/src/video/cocoa/cocoa_v.h b/src/video/cocoa/cocoa_v.h
index 97fc23f26..e570c6a86 100644
--- a/src/video/cocoa/cocoa_v.h
+++ b/src/video/cocoa/cocoa_v.h
@@ -99,6 +99,9 @@ public:
virtual bool MouseIsInsideView(NSPoint *pt) = 0;
virtual bool IsActive() = 0;
+
+ virtual void SetPortAlphaOpaque() { return; };
+ virtual bool WindowResized() { return false; };
};
extern CocoaSubdriver *_cocoa_subdriver;
@@ -124,6 +127,22 @@ void QZ_HideMouse();
uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int display_depth);
+/* Subclass of NSWindow to cater our special needs */
+@interface OTTD_CocoaWindow : NSWindow {
+ CocoaSubdriver *driver;
+}
+
+- (void)setDriver:(CocoaSubdriver*)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 NSView to fix Quartz rendering */
@interface OTTD_CocoaView : NSView {
CocoaSubdriver *driver;
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm
index 3abeaad9f..7df4fab15 100644
--- a/src/video/cocoa/cocoa_v.mm
+++ b/src/video/cocoa/cocoa_v.mm
@@ -356,7 +356,6 @@ bool VideoDriver_Cocoa::ToggleFullscreen(bool full_screen)
return _cocoa_subdriver->IsFullscreen() == full_screen;
}
-
/* This is needed since sometimes assert is called before the videodriver is initialized */
void CocoaDialog(const char *title, const char *message, const char *buttonLabel)
{
@@ -409,6 +408,112 @@ void cocoaReleaseAutoreleasePool()
+@implementation OTTD_CocoaWindow
+
+- (void)setDriver:(CocoaSubdriver*)drv
+{
+ driver = drv;
+}
+/**
+ * Minimize the window
+ */
+- (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 ];
+}
+
+/**
+ * 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.
+ */
+- (void)display
+{
+ 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;
+}
+/**
+ * Define the rectangle we draw our window in
+ */
+- (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.");
+}
+/**
+ * Handle hiding of the application
+ */
+- (void)appDidHide:(NSNotification*)note
+{
+ driver->active = false;
+}
+/**
+ * Fade-in the application and restore display plane
+ */
+- (void)appWillUnhide:(NSNotification*)note
+{
+ driver->SetPortAlphaOpaque ();
+
+ /* save current visible surface */
+ [ self cacheImageInRect:[ driver->cocoaview frame ] ];
+}
+/**
+ * Unhide and restore display plane and re-activate driver
+ */
+- (void)appDidUnhide:(NSNotification*)note
+{
+ /* restore cached image, since it may not be current, post expose event too */
+ [ self restoreCachedImage ];
+
+ driver->active = true;
+}
+/**
+ * Initialize event system for the application rectangle
+ */
+- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)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_CocoaView
/**
* Initialize the driver
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
diff --git a/src/video/cocoa/wnd_quickdraw.mm b/src/video/cocoa/wnd_quickdraw.mm
index 0e5340a62..5ec3af6f5 100644
--- a/src/video/cocoa/wnd_quickdraw.mm
+++ b/src/video/cocoa/wnd_quickdraw.mm
@@ -46,22 +46,6 @@
class WindowQuickdrawSubdriver;
-/* Subclass of NSWindow to fix genie effect and support resize events */
-@interface OTTD_QuickdrawWindow : NSWindow {
- WindowQuickdrawSubdriver *driver;
-}
-
-- (void)setDriver:(WindowQuickdrawSubdriver*)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:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag;
-@end
-
class WindowQuickdrawSubdriver: public CocoaSubdriver {
private:
/**
@@ -130,102 +114,6 @@ public:
bool WindowResized();
};
-
-@implementation OTTD_QuickdrawWindow
-
-- (void)setDriver:(WindowQuickdrawSubdriver*)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:(unsigned int)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
-
static const int _resize_icon_width = 16;
static const int _resize_icon_height = 16;
@@ -291,7 +179,7 @@ bool WindowQuickdrawSubdriver::SetVideoMode(int width, int height)
style |= NSResizableWindowMask;
/* Manually create a window, avoids having a nib file resource */
- this->window = [ [ OTTD_QuickdrawWindow alloc ] initWithContentRect:contentRect
+ this->window = [ [ OTTD_CocoaWindow alloc ] initWithContentRect:contentRect
styleMask:style backing:NSBackingStoreBuffered defer:NO ];
if (this->window == nil) {