summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/video/cocoa/cocoa_v.h76
-rw-r--r--src/video/cocoa/cocoa_v.mm100
-rw-r--r--src/video/cocoa/cocoa_wnd.h14
-rw-r--r--src/video/cocoa/cocoa_wnd.mm6
4 files changed, 58 insertions, 138 deletions
diff --git a/src/video/cocoa/cocoa_v.h b/src/video/cocoa/cocoa_v.h
index 54ff53d15..2aca2034e 100644
--- a/src/video/cocoa/cocoa_v.h
+++ b/src/video/cocoa/cocoa_v.h
@@ -86,12 +86,22 @@ public:
};
-/**
- * Generic display driver for cocoa
- * On grounds to not duplicate some code, it contains a few variables
- * which are not used by all device drivers.
- */
-class CocoaSubdriver {
+
+class WindowQuartzSubdriver {
+private:
+ /**
+ * This function copies 8bpp pixels from the screen buffer in 32bpp windowed mode.
+ *
+ * @param left The x coord for the left edge of the box to blit.
+ * @param top The y coord for the top edge of the box to blit.
+ * @param right The x coord for the right edge of the box to blit.
+ * @param bottom The y coord for the bottom edge of the box to blit.
+ */
+ void BlitIndexedToView32(int left, int top, int right, int bottom);
+
+ void GetDeviceInfo();
+ bool SetVideoMode(int width, int height, int bpp);
+
public:
int device_width; ///< Width of device in pixel
int device_height; ///< Height of device in pixel
@@ -104,8 +114,6 @@ public:
int buffer_depth; ///< Colour depth of used frame buffer
void *pixel_buffer; ///< used for direct pixel access
void *window_buffer; ///< Colour translation from palette to screen
- CGColorSpaceRef color_space; //< Window color space
- id window; ///< Pointer to window object
# define MAX_DIRTY_RECTS 100
Rect dirty_rects[MAX_DIRTY_RECTS]; ///< dirty rectangles
@@ -115,20 +123,18 @@ public:
bool active; ///< Whether the window is visible
bool setup;
+ id window; ///< Pointer to window object
id cocoaview; ///< Pointer to view object
+ CGColorSpaceRef color_space; ///< Window color space
+ CGContextRef cgcontext; ///< Context reference for Quartz subdriver
- /* Separate driver vars for Quarz
- * Needed here in order to avoid much code duplication */
- CGContextRef cgcontext; ///< Context reference for Quartz subdriver
-
- /* Driver methods */
- /** Initialize driver */
- virtual ~CocoaSubdriver() {}
+ WindowQuartzSubdriver();
+ ~WindowQuartzSubdriver();
/** Draw window
* @param force_update Whether to redraw unconditionally
*/
- virtual void Draw(bool force_update = false) = 0;
+ void Draw(bool force_update = false);
/** Mark dirty a screen region
* @param left x-coordinate of left border
@@ -136,77 +142,73 @@ public:
* @param width width or dirty rectangle
* @param height height of dirty rectangle
*/
- virtual void MakeDirty(int left, int top, int width, int height) = 0;
+ void MakeDirty(int left, int top, int width, int height);
/** Update the palette */
- virtual void UpdatePalette(uint first_color, uint num_colors) = 0;
+ void UpdatePalette(uint first_color, uint num_colors);
- virtual uint ListModes(OTTD_Point *modes, uint max_modes) = 0;
+ uint ListModes(OTTD_Point *modes, uint max_modes);
/** Change window resolution
* @param w New window width
* @param h New window height
* @return Whether change was successful
*/
- virtual bool ChangeResolution(int w, int h, int bpp) = 0;
+ bool ChangeResolution(int w, int h, int bpp);
/** Are we in fullscreen mode
* @return whether fullscreen mode is currently used
*/
- virtual bool IsFullscreen() = 0;
+ bool IsFullscreen();
/** Toggle between fullscreen and windowed mode
* @return whether switch was successful
*/
- virtual bool ToggleFullscreen(bool fullscreen) { return false; };
+ bool ToggleFullscreen(bool fullscreen);
/** Return the width of the current view
* @return width of the current view
*/
- virtual int GetWidth() = 0;
+ int GetWidth() { return window_width; }
/** Return the height of the current view
* @return height of the current view
*/
- virtual int GetHeight() = 0;
+ int GetHeight() { return window_height; }
/** Return the current pixel buffer
* @return pixelbuffer
*/
- virtual void *GetPixelBuffer() = 0;
+ void *GetPixelBuffer() { return buffer_depth == 8 ? pixel_buffer : window_buffer; }
/** Convert local coordinate to window server (CoreGraphics) coordinate
* @param p local coordinates
* @return window driver coordinates
*/
- virtual CGPoint PrivateLocalToCG(NSPoint *p) = 0;
+ CGPoint PrivateLocalToCG(NSPoint *p);
/** Return the mouse location
* @param event UI event
* @return mouse location as NSPoint
*/
- virtual NSPoint GetMouseLocation(NSEvent *event) = 0;
+ NSPoint GetMouseLocation(NSEvent *event);
/** Return whether the mouse is within our view
* @param pt Mouse coordinates
* @return Whether mouse coordinates are within view
*/
- virtual bool MouseIsInsideView(NSPoint *pt) = 0;
+ bool MouseIsInsideView(NSPoint *pt);
- /** Return whether the window is active (visible)
- * @return whether the window is visible or not
- */
- virtual bool IsActive() = 0;
+ /** Return whether the window is active (visible) */
+ bool IsActive() { return active; }
- /** Whether the window was successfully resized
+ /** Resize the window.
* @return whether the window was successfully resized
*/
- virtual bool WindowResized() { return false; };
+ bool WindowResized();
};
-extern CocoaSubdriver *_cocoa_subdriver;
-
-CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp);
+extern WindowQuartzSubdriver *_cocoa_subdriver;
uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int display_depth);
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm
index f09920fe2..5da0f55e3 100644
--- a/src/video/cocoa/cocoa_v.mm
+++ b/src/video/cocoa/cocoa_v.mm
@@ -56,7 +56,7 @@
#endif
bool _cocoa_video_started = false;
-CocoaSubdriver *_cocoa_subdriver = NULL;
+WindowQuartzSubdriver *_cocoa_subdriver = NULL;
static bool ModeSorter(const OTTD_Point &p1, const OTTD_Point &p2)
@@ -143,32 +143,6 @@ static void QZ_UpdateVideoModes()
}
}
-/**
- * Find a suitable cocoa subdriver.
- *
- * @param width Width of display area.
- * @param height Height of display area.
- * @param bpp Colour depth of display area.
- * @param fullscreen Whether a fullscreen mode is requested.
- * @param fallback Whether we look for a fallback driver.
- * @return Pointer to window subdriver.
- */
-static CocoaSubdriver *QZ_CreateSubdriver(int width, int height, int bpp, bool fullscreen, bool fallback)
-{
- CocoaSubdriver *ret = QZ_CreateWindowQuartzSubdriver(width, height, bpp);
- if (ret != nullptr && fullscreen) ret->ToggleFullscreen(fullscreen);
-
- if (ret != nullptr) return ret;
- if (!fallback) return nullptr;
-
- /* Try again in 640x480 windowed */
- DEBUG(driver, 0, "Setting video mode failed, falling back to 640x480 windowed mode.");
- ret = QZ_CreateWindowQuartzSubdriver(640, 480, bpp);
- if (ret != nullptr) return ret;
-
- return nullptr;
-}
-
static FVideoDriver_Cocoa iFVideoDriver_Cocoa;
@@ -182,7 +156,7 @@ void VideoDriver_Cocoa::Stop()
CocoaExitApplication();
delete _cocoa_subdriver;
- _cocoa_subdriver = NULL;
+ _cocoa_subdriver = nullptr;
_cocoa_video_started = false;
}
@@ -198,7 +172,7 @@ const char *VideoDriver_Cocoa::Start(const StringList &parm)
_cocoa_video_started = true;
/* Don't create a window or enter fullscreen if we're just going to show a dialog. */
- if (!CocoaSetupApplication()) return NULL;
+ if (!CocoaSetupApplication()) return nullptr;
this->UpdateAutoResolution();
@@ -212,12 +186,14 @@ const char *VideoDriver_Cocoa::Start(const StringList &parm)
return "The cocoa quartz subdriver only supports 8 and 32 bpp.";
}
- _cocoa_subdriver = QZ_CreateSubdriver(width, height, bpp, _fullscreen, true);
- if (_cocoa_subdriver == NULL) {
+ _cocoa_subdriver = new WindowQuartzSubdriver();
+ if (!_cocoa_subdriver->ChangeResolution(width, height, bpp)) {
Stop();
return "Could not create subdriver";
}
+ if (_fullscreen) _cocoa_subdriver->ToggleFullscreen(_fullscreen);
+
this->GameSizeChanged();
QZ_UpdateVideoModes();
@@ -340,59 +316,14 @@ class WindowQuartzSubdriver;
/* Subclass of OTTD_CocoaView to fix Quartz rendering */
@interface OTTD_QuartzView : OTTD_CocoaView
-- (void)setDriver:(WindowQuartzSubdriver*)drv;
+- (void)setDriver:(WindowQuartzSubdriver *)drv;
- (void)drawRect:(NSRect)invalidRect;
@end
-class WindowQuartzSubdriver : public CocoaSubdriver {
-private:
- /**
- * This function copies 8bpp pixels from the screen buffer in 32bpp windowed mode.
- *
- * @param left The x coord for the left edge of the box to blit.
- * @param top The y coord for the top edge of the box to blit.
- * @param right The x coord for the right edge of the box to blit.
- * @param bottom The y coord for the bottom edge of the box to blit.
- */
- void BlitIndexedToView32(int left, int top, int right, int bottom);
-
- virtual void GetDeviceInfo();
- virtual bool SetVideoMode(int width, int height, int bpp);
-
-public:
- WindowQuartzSubdriver();
- virtual ~WindowQuartzSubdriver();
-
- virtual void Draw(bool force_update);
- virtual void MakeDirty(int left, int top, int width, int height);
- virtual void UpdatePalette(uint first_color, uint num_colors);
-
- virtual uint ListModes(OTTD_Point *modes, uint max_modes);
-
- virtual bool ChangeResolution(int w, int h, int bpp);
-
- virtual bool IsFullscreen();
- virtual bool ToggleFullscreen(bool fullscreen); /* Full screen mode on OSX 10.7 */
-
- virtual int GetWidth() { return window_width; }
- virtual int GetHeight() { return window_height; }
- virtual void *GetPixelBuffer() { return buffer_depth == 8 ? pixel_buffer : window_buffer; }
-
- /* Convert local coordinate to window server (CoreGraphics) coordinate */
- virtual CGPoint PrivateLocalToCG(NSPoint *p);
-
- virtual NSPoint GetMouseLocation(NSEvent *event);
- virtual bool MouseIsInsideView(NSPoint *pt);
-
- virtual bool IsActive() { return active; }
-
- bool WindowResized();
-};
-
@implementation OTTD_QuartzView
-- (void)setDriver:(WindowQuartzSubdriver*)drv
+- (void)setDriver:(WindowQuartzSubdriver *)drv
{
driver = drv;
}
@@ -850,17 +781,4 @@ bool WindowQuartzSubdriver::WindowResized()
return true;
}
-
-CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp)
-{
- WindowQuartzSubdriver *ret = new WindowQuartzSubdriver();
-
- if (!ret->ChangeResolution(width, height, bpp)) {
- delete ret;
- return NULL;
- }
-
- return ret;
-}
-
#endif /* WITH_COCOA */
diff --git a/src/video/cocoa/cocoa_wnd.h b/src/video/cocoa/cocoa_wnd.h
index f2890ec0f..837532e9e 100644
--- a/src/video/cocoa/cocoa_wnd.h
+++ b/src/video/cocoa/cocoa_wnd.h
@@ -12,7 +12,7 @@
#import <Cocoa/Cocoa.h>
-class CocoaSubdriver;
+class WindowQuartzSubdriver;
extern NSString *OTTDMainLaunchGameEngine;
@@ -23,10 +23,10 @@ extern NSString *OTTDMainLaunchGameEngine;
/** Subclass of NSWindow to cater our special needs */
@interface OTTD_CocoaWindow : NSWindow {
- CocoaSubdriver *driver;
+ WindowQuartzSubdriver *driver;
}
-- (void)setDriver:(CocoaSubdriver*)drv;
+- (void)setDriver:(WindowQuartzSubdriver *)drv;
- (void)miniaturize:(id)sender;
- (void)display;
@@ -39,10 +39,10 @@ extern NSString *OTTDMainLaunchGameEngine;
/** Subclass of NSView to fix Quartz rendering and mouse awareness */
@interface OTTD_CocoaView : NSView <NSTextInputClient>
{
- CocoaSubdriver *driver;
+ WindowQuartzSubdriver *driver;
NSTrackingRectTag trackingtag;
}
-- (void)setDriver:(CocoaSubdriver*)drv;
+- (void)setDriver:(WindowQuartzSubdriver *)drv;
- (void)drawRect:(NSRect)rect;
- (BOOL)isOpaque;
- (BOOL)acceptsFirstResponder;
@@ -59,10 +59,10 @@ extern NSString *OTTDMainLaunchGameEngine;
/** Delegate for our NSWindow to send ask for quit on close */
@interface OTTD_CocoaWindowDelegate : NSObject <NSWindowDelegate>
{
- CocoaSubdriver *driver;
+ WindowQuartzSubdriver *driver;
}
-- (void)setDriver:(CocoaSubdriver*)drv;
+- (void)setDriver:(WindowQuartzSubdriver *)drv;
- (BOOL)windowShouldClose:(id)sender;
- (void)windowDidEnterFullScreen:(NSNotification *)aNotification;
diff --git a/src/video/cocoa/cocoa_wnd.mm b/src/video/cocoa/cocoa_wnd.mm
index 8c16dd1ef..256565b2b 100644
--- a/src/video/cocoa/cocoa_wnd.mm
+++ b/src/video/cocoa/cocoa_wnd.mm
@@ -282,7 +282,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
@implementation OTTD_CocoaWindow
-- (void)setDriver:(CocoaSubdriver*)drv
+- (void)setDriver:(WindowQuartzSubdriver *)drv
{
driver = drv;
}
@@ -404,7 +404,7 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count)
/**
* Initialize the driver
*/
-- (void)setDriver:(CocoaSubdriver*)drv
+- (void)setDriver:(WindowQuartzSubdriver *)drv
{
driver = drv;
}
@@ -810,7 +810,7 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count)
@implementation OTTD_CocoaWindowDelegate
/** Initialize the video driver */
-- (void)setDriver:(CocoaSubdriver*)drv
+- (void)setDriver:(WindowQuartzSubdriver *)drv
{
driver = drv;
}