mirror of https://github.com/OpenTTD/OpenTTD
Codechange: [OSX] There is only one subdriver left, remove virtual dispatch.
parent
63ed3f3575
commit
4db7837d06
|
@ -86,12 +86,22 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generic display driver for cocoa
|
class WindowQuartzSubdriver {
|
||||||
* On grounds to not duplicate some code, it contains a few variables
|
private:
|
||||||
* which are not used by all device drivers.
|
/**
|
||||||
*/
|
* This function copies 8bpp pixels from the screen buffer in 32bpp windowed mode.
|
||||||
class CocoaSubdriver {
|
*
|
||||||
|
* @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:
|
public:
|
||||||
int device_width; ///< Width of device in pixel
|
int device_width; ///< Width of device in pixel
|
||||||
int device_height; ///< Height 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
|
int buffer_depth; ///< Colour depth of used frame buffer
|
||||||
void *pixel_buffer; ///< used for direct pixel access
|
void *pixel_buffer; ///< used for direct pixel access
|
||||||
void *window_buffer; ///< Colour translation from palette to screen
|
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
|
# define MAX_DIRTY_RECTS 100
|
||||||
Rect dirty_rects[MAX_DIRTY_RECTS]; ///< dirty rectangles
|
Rect dirty_rects[MAX_DIRTY_RECTS]; ///< dirty rectangles
|
||||||
|
@ -115,20 +123,18 @@ public:
|
||||||
bool active; ///< Whether the window is visible
|
bool active; ///< Whether the window is visible
|
||||||
bool setup;
|
bool setup;
|
||||||
|
|
||||||
|
id window; ///< Pointer to window object
|
||||||
id cocoaview; ///< Pointer to view 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
|
WindowQuartzSubdriver();
|
||||||
* Needed here in order to avoid much code duplication */
|
~WindowQuartzSubdriver();
|
||||||
CGContextRef cgcontext; ///< Context reference for Quartz subdriver
|
|
||||||
|
|
||||||
/* Driver methods */
|
|
||||||
/** Initialize driver */
|
|
||||||
virtual ~CocoaSubdriver() {}
|
|
||||||
|
|
||||||
/** Draw window
|
/** Draw window
|
||||||
* @param force_update Whether to redraw unconditionally
|
* @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
|
/** Mark dirty a screen region
|
||||||
* @param left x-coordinate of left border
|
* @param left x-coordinate of left border
|
||||||
|
@ -136,77 +142,73 @@ public:
|
||||||
* @param width width or dirty rectangle
|
* @param width width or dirty rectangle
|
||||||
* @param height height of 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 */
|
/** 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
|
/** Change window resolution
|
||||||
* @param w New window width
|
* @param w New window width
|
||||||
* @param h New window height
|
* @param h New window height
|
||||||
* @return Whether change was successful
|
* @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
|
/** Are we in fullscreen mode
|
||||||
* @return whether fullscreen mode is currently used
|
* @return whether fullscreen mode is currently used
|
||||||
*/
|
*/
|
||||||
virtual bool IsFullscreen() = 0;
|
bool IsFullscreen();
|
||||||
|
|
||||||
/** Toggle between fullscreen and windowed mode
|
/** Toggle between fullscreen and windowed mode
|
||||||
* @return whether switch was successful
|
* @return whether switch was successful
|
||||||
*/
|
*/
|
||||||
virtual bool ToggleFullscreen(bool fullscreen) { return false; };
|
bool ToggleFullscreen(bool fullscreen);
|
||||||
|
|
||||||
/** Return the width of the current view
|
/** Return the width of the current view
|
||||||
* @return 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 the height of the current view
|
||||||
* @return 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 the current pixel buffer
|
||||||
* @return pixelbuffer
|
* @return pixelbuffer
|
||||||
*/
|
*/
|
||||||
virtual void *GetPixelBuffer() = 0;
|
void *GetPixelBuffer() { return buffer_depth == 8 ? pixel_buffer : window_buffer; }
|
||||||
|
|
||||||
/** Convert local coordinate to window server (CoreGraphics) coordinate
|
/** Convert local coordinate to window server (CoreGraphics) coordinate
|
||||||
* @param p local coordinates
|
* @param p local coordinates
|
||||||
* @return window driver coordinates
|
* @return window driver coordinates
|
||||||
*/
|
*/
|
||||||
virtual CGPoint PrivateLocalToCG(NSPoint *p) = 0;
|
CGPoint PrivateLocalToCG(NSPoint *p);
|
||||||
|
|
||||||
/** Return the mouse location
|
/** Return the mouse location
|
||||||
* @param event UI event
|
* @param event UI event
|
||||||
* @return mouse location as NSPoint
|
* @return mouse location as NSPoint
|
||||||
*/
|
*/
|
||||||
virtual NSPoint GetMouseLocation(NSEvent *event) = 0;
|
NSPoint GetMouseLocation(NSEvent *event);
|
||||||
|
|
||||||
/** Return whether the mouse is within our view
|
/** Return whether the mouse is within our view
|
||||||
* @param pt Mouse coordinates
|
* @param pt Mouse coordinates
|
||||||
* @return Whether mouse coordinates are within view
|
* @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 active (visible) */
|
||||||
* @return whether the window is visible or not
|
bool IsActive() { return active; }
|
||||||
*/
|
|
||||||
virtual bool IsActive() = 0;
|
|
||||||
|
|
||||||
/** Whether the window was successfully resized
|
/** Resize the window.
|
||||||
* @return whether the window was successfully resized
|
* @return whether the window was successfully resized
|
||||||
*/
|
*/
|
||||||
virtual bool WindowResized() { return false; };
|
bool WindowResized();
|
||||||
};
|
};
|
||||||
|
|
||||||
extern CocoaSubdriver *_cocoa_subdriver;
|
extern WindowQuartzSubdriver *_cocoa_subdriver;
|
||||||
|
|
||||||
CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp);
|
|
||||||
|
|
||||||
uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int display_depth);
|
uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int display_depth);
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool _cocoa_video_started = false;
|
bool _cocoa_video_started = false;
|
||||||
CocoaSubdriver *_cocoa_subdriver = NULL;
|
WindowQuartzSubdriver *_cocoa_subdriver = NULL;
|
||||||
|
|
||||||
|
|
||||||
static bool ModeSorter(const OTTD_Point &p1, const OTTD_Point &p2)
|
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;
|
static FVideoDriver_Cocoa iFVideoDriver_Cocoa;
|
||||||
|
|
||||||
|
@ -182,7 +156,7 @@ void VideoDriver_Cocoa::Stop()
|
||||||
CocoaExitApplication();
|
CocoaExitApplication();
|
||||||
|
|
||||||
delete _cocoa_subdriver;
|
delete _cocoa_subdriver;
|
||||||
_cocoa_subdriver = NULL;
|
_cocoa_subdriver = nullptr;
|
||||||
|
|
||||||
_cocoa_video_started = false;
|
_cocoa_video_started = false;
|
||||||
}
|
}
|
||||||
|
@ -198,7 +172,7 @@ const char *VideoDriver_Cocoa::Start(const StringList &parm)
|
||||||
_cocoa_video_started = true;
|
_cocoa_video_started = true;
|
||||||
|
|
||||||
/* Don't create a window or enter fullscreen if we're just going to show a dialog. */
|
/* 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();
|
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.";
|
return "The cocoa quartz subdriver only supports 8 and 32 bpp.";
|
||||||
}
|
}
|
||||||
|
|
||||||
_cocoa_subdriver = QZ_CreateSubdriver(width, height, bpp, _fullscreen, true);
|
_cocoa_subdriver = new WindowQuartzSubdriver();
|
||||||
if (_cocoa_subdriver == NULL) {
|
if (!_cocoa_subdriver->ChangeResolution(width, height, bpp)) {
|
||||||
Stop();
|
Stop();
|
||||||
return "Could not create subdriver";
|
return "Could not create subdriver";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_fullscreen) _cocoa_subdriver->ToggleFullscreen(_fullscreen);
|
||||||
|
|
||||||
this->GameSizeChanged();
|
this->GameSizeChanged();
|
||||||
QZ_UpdateVideoModes();
|
QZ_UpdateVideoModes();
|
||||||
|
|
||||||
|
@ -340,59 +316,14 @@ class WindowQuartzSubdriver;
|
||||||
|
|
||||||
/* Subclass of OTTD_CocoaView to fix Quartz rendering */
|
/* Subclass of OTTD_CocoaView to fix Quartz rendering */
|
||||||
@interface OTTD_QuartzView : OTTD_CocoaView
|
@interface OTTD_QuartzView : OTTD_CocoaView
|
||||||
- (void)setDriver:(WindowQuartzSubdriver*)drv;
|
- (void)setDriver:(WindowQuartzSubdriver *)drv;
|
||||||
- (void)drawRect:(NSRect)invalidRect;
|
- (void)drawRect:(NSRect)invalidRect;
|
||||||
@end
|
@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
|
@implementation OTTD_QuartzView
|
||||||
|
|
||||||
- (void)setDriver:(WindowQuartzSubdriver*)drv
|
- (void)setDriver:(WindowQuartzSubdriver *)drv
|
||||||
{
|
{
|
||||||
driver = drv;
|
driver = drv;
|
||||||
}
|
}
|
||||||
|
@ -850,17 +781,4 @@ bool WindowQuartzSubdriver::WindowResized()
|
||||||
return true;
|
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 */
|
#endif /* WITH_COCOA */
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
class CocoaSubdriver;
|
class WindowQuartzSubdriver;
|
||||||
|
|
||||||
extern NSString *OTTDMainLaunchGameEngine;
|
extern NSString *OTTDMainLaunchGameEngine;
|
||||||
|
|
||||||
|
@ -23,10 +23,10 @@ extern NSString *OTTDMainLaunchGameEngine;
|
||||||
|
|
||||||
/** Subclass of NSWindow to cater our special needs */
|
/** Subclass of NSWindow to cater our special needs */
|
||||||
@interface OTTD_CocoaWindow : NSWindow {
|
@interface OTTD_CocoaWindow : NSWindow {
|
||||||
CocoaSubdriver *driver;
|
WindowQuartzSubdriver *driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setDriver:(CocoaSubdriver*)drv;
|
- (void)setDriver:(WindowQuartzSubdriver *)drv;
|
||||||
|
|
||||||
- (void)miniaturize:(id)sender;
|
- (void)miniaturize:(id)sender;
|
||||||
- (void)display;
|
- (void)display;
|
||||||
|
@ -39,10 +39,10 @@ extern NSString *OTTDMainLaunchGameEngine;
|
||||||
/** Subclass of NSView to fix Quartz rendering and mouse awareness */
|
/** Subclass of NSView to fix Quartz rendering and mouse awareness */
|
||||||
@interface OTTD_CocoaView : NSView <NSTextInputClient>
|
@interface OTTD_CocoaView : NSView <NSTextInputClient>
|
||||||
{
|
{
|
||||||
CocoaSubdriver *driver;
|
WindowQuartzSubdriver *driver;
|
||||||
NSTrackingRectTag trackingtag;
|
NSTrackingRectTag trackingtag;
|
||||||
}
|
}
|
||||||
- (void)setDriver:(CocoaSubdriver*)drv;
|
- (void)setDriver:(WindowQuartzSubdriver *)drv;
|
||||||
- (void)drawRect:(NSRect)rect;
|
- (void)drawRect:(NSRect)rect;
|
||||||
- (BOOL)isOpaque;
|
- (BOOL)isOpaque;
|
||||||
- (BOOL)acceptsFirstResponder;
|
- (BOOL)acceptsFirstResponder;
|
||||||
|
@ -59,10 +59,10 @@ extern NSString *OTTDMainLaunchGameEngine;
|
||||||
/** Delegate for our NSWindow to send ask for quit on close */
|
/** Delegate for our NSWindow to send ask for quit on close */
|
||||||
@interface OTTD_CocoaWindowDelegate : NSObject <NSWindowDelegate>
|
@interface OTTD_CocoaWindowDelegate : NSObject <NSWindowDelegate>
|
||||||
{
|
{
|
||||||
CocoaSubdriver *driver;
|
WindowQuartzSubdriver *driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setDriver:(CocoaSubdriver*)drv;
|
- (void)setDriver:(WindowQuartzSubdriver *)drv;
|
||||||
|
|
||||||
- (BOOL)windowShouldClose:(id)sender;
|
- (BOOL)windowShouldClose:(id)sender;
|
||||||
- (void)windowDidEnterFullScreen:(NSNotification *)aNotification;
|
- (void)windowDidEnterFullScreen:(NSNotification *)aNotification;
|
||||||
|
|
|
@ -282,7 +282,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
|
||||||
|
|
||||||
@implementation OTTD_CocoaWindow
|
@implementation OTTD_CocoaWindow
|
||||||
|
|
||||||
- (void)setDriver:(CocoaSubdriver*)drv
|
- (void)setDriver:(WindowQuartzSubdriver *)drv
|
||||||
{
|
{
|
||||||
driver = drv;
|
driver = drv;
|
||||||
}
|
}
|
||||||
|
@ -404,7 +404,7 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count)
|
||||||
/**
|
/**
|
||||||
* Initialize the driver
|
* Initialize the driver
|
||||||
*/
|
*/
|
||||||
- (void)setDriver:(CocoaSubdriver*)drv
|
- (void)setDriver:(WindowQuartzSubdriver *)drv
|
||||||
{
|
{
|
||||||
driver = drv;
|
driver = drv;
|
||||||
}
|
}
|
||||||
|
@ -810,7 +810,7 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count)
|
||||||
|
|
||||||
@implementation OTTD_CocoaWindowDelegate
|
@implementation OTTD_CocoaWindowDelegate
|
||||||
/** Initialize the video driver */
|
/** Initialize the video driver */
|
||||||
- (void)setDriver:(CocoaSubdriver*)drv
|
- (void)setDriver:(WindowQuartzSubdriver *)drv
|
||||||
{
|
{
|
||||||
driver = drv;
|
driver = drv;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue