summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/video/cocoa/cocoa_v.h128
-rw-r--r--src/video/cocoa/cocoa_v.mm229
-rw-r--r--src/video/cocoa/cocoa_wnd.h14
-rw-r--r--src/video/cocoa/cocoa_wnd.mm10
-rw-r--r--src/video/cocoa/event.mm102
5 files changed, 207 insertions, 276 deletions
diff --git a/src/video/cocoa/cocoa_v.h b/src/video/cocoa/cocoa_v.h
index a52cbb06e..adeadd3be 100644
--- a/src/video/cocoa/cocoa_v.h
+++ b/src/video/cocoa/cocoa_v.h
@@ -18,9 +18,37 @@ extern bool _cocoa_video_started;
class VideoDriver_Cocoa : public VideoDriver {
private:
- Dimension orig_res; ///< Saved window size for non-fullscreen mode.
+ Dimension orig_res; ///< Saved window size for non-fullscreen mode.
+
+ int device_width; ///< Width of device in pixel
+ int device_height; ///< Height of device in pixel
+ int device_depth; ///< Colour depth of device in bit
+
+ int window_width; ///< Current window width in pixel
+ int window_height; ///< Current window height in pixel
+ int window_pitch;
+
+ 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
+
+# define MAX_DIRTY_RECTS 100
+ Rect dirty_rects[MAX_DIRTY_RECTS]; ///< dirty rectangles
+ int num_dirty_rects = MAX_DIRTY_RECTS; ///< Number of dirty rectangles
+ uint32 palette[256]; ///< Colour Palette
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
+
+public:
+ VideoDriver_Cocoa();
+
const char *Start(const StringList &param) override;
/** Stop the video driver */
@@ -70,26 +98,28 @@ public:
/** Main game loop. */
void GameLoop(); // In event.mm.
+ /** Resize the window.
+ * @return whether the window was successfully resized
+ */
+ bool WindowResized();
+
+ /** Convert local coordinate to window server (CoreGraphics) coordinate
+ * @param p local coordinates
+ * @return window driver coordinates
+ */
+ CGPoint PrivateLocalToCG(NSPoint *p);
+
protected:
Dimension GetScreenSize() const override;
private:
- friend class WindowQuartzSubdriver;
+ bool PollEvent(); // In event.mm.
+ void MouseMovedEvent(int x, int y); // In event.mm.
+ void WarpCursor(int x, int y); // In event.mm.
void GameSizeChanged();
void UpdateVideoModes();
-};
-class FVideoDriver_Cocoa : public DriverFactoryBase {
-public:
- FVideoDriver_Cocoa() : DriverFactoryBase(Driver::DT_VIDEO, 10, "cocoa", "Cocoa Video Driver") {}
- Driver *CreateInstance() const override { return new VideoDriver_Cocoa(); }
-};
-
-
-
-class WindowQuartzSubdriver {
-private:
/**
* This function copies 8bpp pixels from the screen buffer in 32bpp windowed mode.
*
@@ -103,48 +133,11 @@ private:
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
- int device_depth; ///< Colour depth of device in bit
-
- int window_width; ///< Current window width in pixel
- int window_height; ///< Current window height in pixel
- int window_pitch;
-
- 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
-
-# define MAX_DIRTY_RECTS 100
- Rect dirty_rects[MAX_DIRTY_RECTS]; ///< dirty rectangles
- int num_dirty_rects; ///< Number of dirty rectangles
- uint32 palette[256]; ///< Colour Palette
-
- 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
-
- WindowQuartzSubdriver();
- ~WindowQuartzSubdriver();
-
/** Draw window
* @param force_update Whether to redraw unconditionally
*/
void Draw(bool force_update = false);
- /** Mark dirty a screen region
- * @param left x-coordinate of left border
- * @param top y-coordinate of top border
- * @param width width or dirty rectangle
- * @param height height of dirty rectangle
- */
- void MakeDirty(int left, int top, int width, int height);
-
/** Update the palette */
void UpdatePalette(uint first_color, uint num_colors);
@@ -162,32 +155,11 @@ public:
*/
bool IsFullscreen();
- /** Toggle between fullscreen and windowed mode
- * @return whether switch was successful
- */
- bool ToggleFullscreen(bool fullscreen);
-
- /** Return the width of the current view
- * @return width of the current view
- */
- int GetWidth() { return window_width; }
-
- /** Return the height of the current view
- * @return height of the current view
- */
- int GetHeight() { return window_height; }
-
/** Return the current pixel buffer
* @return pixelbuffer
*/
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
- */
- CGPoint PrivateLocalToCG(NSPoint *p);
-
/** Return the mouse location
* @param event UI event
* @return mouse location as NSPoint
@@ -200,15 +172,13 @@ public:
*/
bool MouseIsInsideView(NSPoint *pt);
- /** Return whether the window is active (visible) */
- bool IsActive() { return active; }
-
- /** Resize the window.
- * @return whether the window was successfully resized
- */
- bool WindowResized();
+ void CheckPaletteAnim();
};
-extern WindowQuartzSubdriver *_cocoa_subdriver;
+class FVideoDriver_Cocoa : public DriverFactoryBase {
+public:
+ FVideoDriver_Cocoa() : DriverFactoryBase(Driver::DT_VIDEO, 10, "cocoa", "Cocoa Video Driver") {}
+ Driver *CreateInstance() const override { return new VideoDriver_Cocoa(); }
+};
#endif /* VIDEO_COCOA_H */
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm
index 77dbbd21f..9d1fe3782 100644
--- a/src/video/cocoa/cocoa_v.mm
+++ b/src/video/cocoa/cocoa_v.mm
@@ -55,7 +55,6 @@
#endif
bool _cocoa_video_started = false;
-WindowQuartzSubdriver *_cocoa_subdriver = NULL;
/** List of common display/window sizes. */
@@ -74,30 +73,27 @@ static const Dimension _default_resolutions[] = {
{ 2560, 1440 }
};
-/**
- * Update the video modus.
- */
-void VideoDriver_Cocoa::UpdateVideoModes()
+static FVideoDriver_Cocoa iFVideoDriver_Cocoa;
+
+
+VideoDriver_Cocoa::VideoDriver_Cocoa()
{
- _resolutions.clear();
+ this->window_width = 0;
+ this->window_height = 0;
+ this->buffer_depth = 0;
+ this->window_buffer = nullptr;
+ this->pixel_buffer = nullptr;
+ this->active = false;
+ this->setup = false;
- if (_cocoa_subdriver != nullptr && _cocoa_subdriver->IsFullscreen()) {
- /* Full screen, there is only one possible resolution. */
- NSSize screen = [ [ _cocoa_subdriver->window screen ] frame ].size;
- _resolutions.emplace_back((uint)screen.width, (uint)screen.height);
- } else {
- /* Windowed; offer a selection of common window sizes up until the
- * maximum usable screen space. This excludes the menu and dock areas. */
- NSSize maxSize = [ [ NSScreen mainScreen] visibleFrame ].size;
- for (const auto &d : _default_resolutions) {
- if (d.width < maxSize.width && d.height < maxSize.height) _resolutions.push_back(d);
- }
- _resolutions.emplace_back((uint)maxSize.width, (uint)maxSize.height);
- }
-}
+ this->window = nil;
+ this->cocoaview = nil;
+ this->color_space = nullptr;
+ this->cgcontext = nullptr;
-static FVideoDriver_Cocoa iFVideoDriver_Cocoa;
+ this->num_dirty_rects = MAX_DIRTY_RECTS;
+}
/**
* Stop the cocoa video subdriver.
@@ -108,8 +104,14 @@ void VideoDriver_Cocoa::Stop()
CocoaExitApplication();
- delete _cocoa_subdriver;
- _cocoa_subdriver = nullptr;
+ /* Release window mode resources */
+ if (this->window != nil) [ this->window close ];
+
+ CGContextRelease(this->cgcontext);
+
+ CGColorSpaceRelease(this->color_space);
+ free(this->window_buffer);
+ free(this->pixel_buffer);
_cocoa_video_started = false;
}
@@ -139,18 +141,17 @@ const char *VideoDriver_Cocoa::Start(const StringList &parm)
return "The cocoa quartz subdriver only supports 8 and 32 bpp.";
}
- _cocoa_subdriver = new WindowQuartzSubdriver();
- if (!_cocoa_subdriver->ChangeResolution(width, height, bpp)) {
+ if (!this->ChangeResolution(width, height, bpp)) {
Stop();
return "Could not create subdriver";
}
- if (_fullscreen) _cocoa_subdriver->ToggleFullscreen(_fullscreen);
+ if (_fullscreen) this->ToggleFullscreen(_fullscreen);
this->GameSizeChanged();
this->UpdateVideoModes();
- return NULL;
+ return nullptr;
}
/**
@@ -163,9 +164,13 @@ const char *VideoDriver_Cocoa::Start(const StringList &parm)
*/
void VideoDriver_Cocoa::MakeDirty(int left, int top, int width, int height)
{
- assert(_cocoa_subdriver != NULL);
-
- _cocoa_subdriver->MakeDirty(left, top, width, height);
+ if (this->num_dirty_rects < MAX_DIRTY_RECTS) {
+ dirty_rects[this->num_dirty_rects].left = left;
+ dirty_rects[this->num_dirty_rects].top = top;
+ dirty_rects[this->num_dirty_rects].right = left + width;
+ dirty_rects[this->num_dirty_rects].bottom = top + height;
+ }
+ this->num_dirty_rects++;
}
/**
@@ -190,12 +195,8 @@ void VideoDriver_Cocoa::MainLoop()
*/
bool VideoDriver_Cocoa::ChangeResolution(int w, int h)
{
- assert(_cocoa_subdriver != NULL);
-
- bool ret = _cocoa_subdriver->ChangeResolution(w, h, BlitterFactory::GetCurrentBlitter()->GetScreenDepth());
-
+ bool ret = this->ChangeResolution(w, h, BlitterFactory::GetCurrentBlitter()->GetScreenDepth());
this->GameSizeChanged();
-
return ret;
}
@@ -207,11 +208,15 @@ bool VideoDriver_Cocoa::ChangeResolution(int w, int h)
*/
bool VideoDriver_Cocoa::ToggleFullscreen(bool full_screen)
{
- assert(_cocoa_subdriver != NULL);
+ if (this->IsFullscreen() == full_screen) return true;
- bool res = _cocoa_subdriver->ToggleFullscreen(full_screen);
- this->UpdateVideoModes();
- return res;
+ if ([ this->window respondsToSelector:@selector(toggleFullScreen:) ]) {
+ [ this->window performSelector:@selector(toggleFullScreen:) withObject:this->window ];
+ this->UpdateVideoModes();
+ return true;
+ }
+
+ return false;
}
/**
@@ -229,7 +234,7 @@ bool VideoDriver_Cocoa::AfterBlitterChange()
*/
void VideoDriver_Cocoa::EditBoxLostFocus()
{
- if (_cocoa_subdriver != NULL) [ [ _cocoa_subdriver->cocoaview inputContext ] discardMarkedText ];
+ [ [ this->cocoaview inputContext ] discardMarkedText ];
/* Clear any marked string from the current edit box. */
HandleTextInput(NULL, true);
}
@@ -248,16 +253,14 @@ Dimension VideoDriver_Cocoa::GetScreenSize() const
*/
void VideoDriver_Cocoa::GameSizeChanged()
{
- if (_cocoa_subdriver == nullptr) return;
-
/* Tell the game that the resolution has changed */
- _screen.width = _cocoa_subdriver->GetWidth();
- _screen.height = _cocoa_subdriver->GetHeight();
- _screen.pitch = _cocoa_subdriver->GetWidth();
- _screen.dst_ptr = _cocoa_subdriver->GetPixelBuffer();
+ _screen.width = this->window_width;
+ _screen.height = this->window_height;
+ _screen.pitch = this->window_width;
+ _screen.dst_ptr = this->GetPixelBuffer();
/* Store old window size if we entered fullscreen mode. */
- bool fullscreen = _cocoa_subdriver->IsFullscreen();
+ bool fullscreen = this->IsFullscreen();
if (fullscreen && !_fullscreen) this->orig_res = _cur_resolution;
_fullscreen = fullscreen;
@@ -266,18 +269,16 @@ void VideoDriver_Cocoa::GameSizeChanged()
::GameSizeChanged();
}
-class WindowQuartzSubdriver;
-
/* Subclass of OTTD_CocoaView to fix Quartz rendering */
@interface OTTD_QuartzView : OTTD_CocoaView
-- (void)setDriver:(WindowQuartzSubdriver *)drv;
+- (void)setDriver:(VideoDriver_Cocoa *)drv;
- (void)drawRect:(NSRect)invalidRect;
@end
@implementation OTTD_QuartzView
-- (void)setDriver:(WindowQuartzSubdriver *)drv
+- (void)setDriver:(VideoDriver_Cocoa *)drv
{
driver = drv;
}
@@ -360,7 +361,29 @@ class WindowQuartzSubdriver;
@end
-void WindowQuartzSubdriver::GetDeviceInfo()
+/**
+ * Update the video modus.
+ */
+void VideoDriver_Cocoa::UpdateVideoModes()
+{
+ _resolutions.clear();
+
+ if (this->IsFullscreen()) {
+ /* Full screen, there is only one possible resolution. */
+ NSSize screen = [ [ this->window screen ] frame ].size;
+ _resolutions.emplace_back((uint)screen.width, (uint)screen.height);
+ } else {
+ /* Windowed; offer a selection of common window sizes up until the
+ * maximum usable screen space. This excludes the menu and dock areas. */
+ NSSize maxSize = [ [ NSScreen mainScreen] visibleFrame ].size;
+ for (const auto &d : _default_resolutions) {
+ if (d.width < maxSize.width && d.height < maxSize.height) _resolutions.push_back(d);
+ }
+ _resolutions.emplace_back((uint)maxSize.width, (uint)maxSize.height);
+ }
+}
+
+void VideoDriver_Cocoa::GetDeviceInfo()
{
/* Initialize the video settings; this data persists between mode switches
* and gather some information that is useful to know about the display */
@@ -375,27 +398,12 @@ void WindowQuartzSubdriver::GetDeviceInfo()
CGDisplayModeRelease(cur_mode);
}
-bool WindowQuartzSubdriver::IsFullscreen()
+bool VideoDriver_Cocoa::IsFullscreen()
{
return this->window != nil && ([ this->window styleMask ] & NSWindowStyleMaskFullScreen) != 0;
}
-/** Switch to full screen mode on OSX 10.7
- * @return Whether we switched to full screen
- */
-bool WindowQuartzSubdriver::ToggleFullscreen(bool fullscreen)
-{
- if (this->IsFullscreen() == fullscreen) return true;
-
- if ([ this->window respondsToSelector:@selector(toggleFullScreen:) ]) {
- [ this->window performSelector:@selector(toggleFullScreen:) withObject:this->window ];
- return true;
- }
-
- return false;
-}
-
-bool WindowQuartzSubdriver::SetVideoMode(int width, int height, int bpp)
+bool VideoDriver_Cocoa::SetVideoMode(int width, int height, int bpp)
{
this->setup = true;
this->GetDeviceInfo();
@@ -508,7 +516,7 @@ bool WindowQuartzSubdriver::SetVideoMode(int width, int height, int bpp)
return ret;
}
-void WindowQuartzSubdriver::BlitIndexedToView32(int left, int top, int right, int bottom)
+void VideoDriver_Cocoa::BlitIndexedToView32(int left, int top, int right, int bottom)
{
const uint32 *pal = this->palette;
const uint8 *src = (uint8*)this->pixel_buffer;
@@ -524,37 +532,7 @@ void WindowQuartzSubdriver::BlitIndexedToView32(int left, int top, int right, in
}
-WindowQuartzSubdriver::WindowQuartzSubdriver()
-{
- this->window_width = 0;
- this->window_height = 0;
- this->buffer_depth = 0;
- this->window_buffer = NULL;
- this->pixel_buffer = NULL;
- this->active = false;
- this->setup = false;
-
- this->window = nil;
- this->cocoaview = nil;
-
- this->cgcontext = NULL;
-
- this->num_dirty_rects = MAX_DIRTY_RECTS;
-}
-
-WindowQuartzSubdriver::~WindowQuartzSubdriver()
-{
- /* Release window mode resources */
- if (this->window != nil) [ this->window close ];
-
- CGContextRelease(this->cgcontext);
-
- CGColorSpaceRelease(this->color_space);
- free(this->window_buffer);
- free(this->pixel_buffer);
-}
-
-void WindowQuartzSubdriver::Draw(bool force_update)
+void VideoDriver_Cocoa::Draw(bool force_update)
{
PerformanceMeasurer framerate(PFE_VIDEO);
@@ -596,18 +574,7 @@ void WindowQuartzSubdriver::Draw(bool force_update)
this->num_dirty_rects = 0;
}
-void WindowQuartzSubdriver::MakeDirty(int left, int top, int width, int height)
-{
- if (this->num_dirty_rects < MAX_DIRTY_RECTS) {
- dirty_rects[this->num_dirty_rects].left = left;
- dirty_rects[this->num_dirty_rects].top = top;
- dirty_rects[this->num_dirty_rects].right = left + width;
- dirty_rects[this->num_dirty_rects].bottom = top + height;
- }
- this->num_dirty_rects++;
-}
-
-void WindowQuartzSubdriver::UpdatePalette(uint first_color, uint num_colors)
+void VideoDriver_Cocoa::UpdatePalette(uint first_color, uint num_colors)
{
if (this->buffer_depth != 8) return;
@@ -622,7 +589,7 @@ void WindowQuartzSubdriver::UpdatePalette(uint first_color, uint num_colors)
this->num_dirty_rects = MAX_DIRTY_RECTS;
}
-bool WindowQuartzSubdriver::ChangeResolution(int w, int h, int bpp)
+bool VideoDriver_Cocoa::ChangeResolution(int w, int h, int bpp)
{
int old_width = this->window_width;
int old_height = this->window_height;
@@ -635,7 +602,7 @@ bool WindowQuartzSubdriver::ChangeResolution(int w, int h, int bpp)
}
/* Convert local coordinate to window server (CoreGraphics) coordinate */
-CGPoint WindowQuartzSubdriver::PrivateLocalToCG(NSPoint *p)
+CGPoint VideoDriver_Cocoa::PrivateLocalToCG(NSPoint *p)
{
p->y = this->window_height - p->y;
@@ -651,7 +618,7 @@ CGPoint WindowQuartzSubdriver::PrivateLocalToCG(NSPoint *p)
return cgp;
}
-NSPoint WindowQuartzSubdriver::GetMouseLocation(NSEvent *event)
+NSPoint VideoDriver_Cocoa::GetMouseLocation(NSEvent *event)
{
NSPoint pt;
@@ -666,7 +633,7 @@ NSPoint WindowQuartzSubdriver::GetMouseLocation(NSEvent *event)
return pt;
}
-bool WindowQuartzSubdriver::MouseIsInsideView(NSPoint *pt)
+bool VideoDriver_Cocoa::MouseIsInsideView(NSPoint *pt)
{
return [ cocoaview mouse:*pt inRect:[ this->cocoaview bounds ] ];
}
@@ -682,7 +649,7 @@ static void ClearWindowBuffer(uint32 *buffer, uint32 pitch, uint32 height)
}
}
-bool WindowQuartzSubdriver::WindowResized()
+bool VideoDriver_Cocoa::WindowResized()
{
if (this->window == nil || this->cocoaview == nil) return true;
@@ -722,7 +689,7 @@ bool WindowQuartzSubdriver::WindowResized()
}
}
- static_cast<VideoDriver_Cocoa *>(VideoDriver::GetInstance())->GameSizeChanged();
+ this->GameSizeChanged();
/* Redraw screen */
this->num_dirty_rects = MAX_DIRTY_RECTS;
@@ -730,4 +697,28 @@ bool WindowQuartzSubdriver::WindowResized()
return true;
}
+void VideoDriver_Cocoa::CheckPaletteAnim()
+{
+ if (_cur_palette.count_dirty != 0) {
+ Blitter *blitter = BlitterFactory::GetCurrentBlitter();
+
+ switch (blitter->UsePaletteAnimation()) {
+ case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
+ this->UpdatePalette(_cur_palette.first_dirty, _cur_palette.count_dirty);
+ break;
+
+ case Blitter::PALETTE_ANIMATION_BLITTER:
+ blitter->PaletteAnimate(_cur_palette);
+ break;
+
+ case Blitter::PALETTE_ANIMATION_NONE:
+ break;
+
+ default:
+ NOT_REACHED();
+ }
+ _cur_palette.count_dirty = 0;
+ }
+}
+
#endif /* WITH_COCOA */
diff --git a/src/video/cocoa/cocoa_wnd.h b/src/video/cocoa/cocoa_wnd.h
index 837532e9e..35dcaa7c0 100644
--- a/src/video/cocoa/cocoa_wnd.h
+++ b/src/video/cocoa/cocoa_wnd.h
@@ -12,7 +12,7 @@
#import <Cocoa/Cocoa.h>
-class WindowQuartzSubdriver;
+class VideoDriver_Cocoa;
extern NSString *OTTDMainLaunchGameEngine;
@@ -23,10 +23,10 @@ extern NSString *OTTDMainLaunchGameEngine;
/** Subclass of NSWindow to cater our special needs */
@interface OTTD_CocoaWindow : NSWindow {
- WindowQuartzSubdriver *driver;
+ VideoDriver_Cocoa *driver;
}
-- (void)setDriver:(WindowQuartzSubdriver *)drv;
+- (void)setDriver:(VideoDriver_Cocoa *)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>
{
- WindowQuartzSubdriver *driver;
+ VideoDriver_Cocoa *driver;
NSTrackingRectTag trackingtag;
}
-- (void)setDriver:(WindowQuartzSubdriver *)drv;
+- (void)setDriver:(VideoDriver_Cocoa *)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>
{
- WindowQuartzSubdriver *driver;
+ VideoDriver_Cocoa *driver;
}
-- (void)setDriver:(WindowQuartzSubdriver *)drv;
+- (void)setDriver:(VideoDriver_Cocoa *)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 256565b2b..ff222ea42 100644
--- a/src/video/cocoa/cocoa_wnd.mm
+++ b/src/video/cocoa/cocoa_wnd.mm
@@ -70,7 +70,7 @@ static OTTDMain *_ottd_main;
- (void)launchGameEngine: (NSNotification*) note
{
/* Setup cursor for the current _game_mode. */
- [ _cocoa_subdriver->cocoaview resetCursorRects ];
+ [ static_cast<VideoDriver_Cocoa *>(VideoDriver::GetInstance())->cocoaview resetCursorRects ];
/* Hand off to main application code. */
static_cast<VideoDriver_Cocoa *>(VideoDriver::GetInstance())->GameLoop();
@@ -282,7 +282,7 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel
@implementation OTTD_CocoaWindow
-- (void)setDriver:(WindowQuartzSubdriver *)drv
+- (void)setDriver:(VideoDriver_Cocoa *)drv
{
driver = drv;
}
@@ -404,7 +404,7 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count)
/**
* Initialize the driver
*/
-- (void)setDriver:(WindowQuartzSubdriver *)drv
+- (void)setDriver:(VideoDriver_Cocoa *)drv
{
driver = drv;
}
@@ -491,7 +491,7 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count)
*/
- (void)mouseExited:(NSEvent *)theEvent
{
- if (_cocoa_subdriver != NULL) UndrawMouseCursor();
+ if (driver->window != nil) UndrawMouseCursor();
_cursor.in_window = false;
}
@@ -810,7 +810,7 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count)
@implementation OTTD_CocoaWindowDelegate
/** Initialize the video driver */
-- (void)setDriver:(WindowQuartzSubdriver *)drv
+- (void)setDriver:(VideoDriver_Cocoa *)drv
{
driver = drv;
}
diff --git a/src/video/cocoa/event.mm b/src/video/cocoa/event.mm
index 8a43945f5..86ffd9145 100644
--- a/src/video/cocoa/event.mm
+++ b/src/video/cocoa/event.mm
@@ -73,15 +73,13 @@ static uint32 GetTick()
return tim.tv_usec / 1000 + tim.tv_sec * 1000;
}
-static void QZ_WarpCursor(int x, int y)
+void VideoDriver_Cocoa::WarpCursor(int x, int y)
{
- assert(_cocoa_subdriver != NULL);
-
/* Only allow warping when in foreground */
if (![ NSApp isActive ]) return;
NSPoint p = NSMakePoint(x, y);
- CGPoint cgp = _cocoa_subdriver->PrivateLocalToCG(&p);
+ CGPoint cgp = this->PrivateLocalToCG(&p);
/* Do the actual warp */
CGWarpMouseCursorPosition(cgp);
@@ -90,32 +88,6 @@ static void QZ_WarpCursor(int x, int y)
}
-static void QZ_CheckPaletteAnim()
-{
- if (_cur_palette.count_dirty != 0) {
- Blitter *blitter = BlitterFactory::GetCurrentBlitter();
-
- switch (blitter->UsePaletteAnimation()) {
- case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
- _cocoa_subdriver->UpdatePalette(_cur_palette.first_dirty, _cur_palette.count_dirty);
- break;
-
- case Blitter::PALETTE_ANIMATION_BLITTER:
- blitter->PaletteAnimate(_cur_palette);
- break;
-
- case Blitter::PALETTE_ANIMATION_NONE:
- break;
-
- default:
- NOT_REACHED();
- }
- _cur_palette.count_dirty = 0;
- }
-}
-
-
-
struct VkMapping {
unsigned short vk_from;
byte map_to;
@@ -343,10 +315,10 @@ static void QZ_DoUnsidedModifiers(unsigned int newMods)
_current_mods = newMods;
}
-static void QZ_MouseMovedEvent(int x, int y)
+void VideoDriver_Cocoa::MouseMovedEvent(int x, int y)
{
if (_cursor.UpdateCursorPosition(x, y, false)) {
- QZ_WarpCursor(_cursor.pos.x, _cursor.pos.y);
+ this->WarpCursor(_cursor.pos.x, _cursor.pos.y);
}
HandleMouseEvents();
}
@@ -380,10 +352,8 @@ static void QZ_MouseButtonEvent(int button, BOOL down)
-static bool QZ_PollEvent()
+bool VideoDriver_Cocoa::PollEvent()
{
- assert(_cocoa_subdriver != NULL);
-
#ifdef _DEBUG
uint32 et0 = GetTick();
#endif
@@ -395,7 +365,7 @@ static bool QZ_PollEvent()
#endif
if (event == nil) return false;
- if (!_cocoa_subdriver->IsActive()) {
+ if (!this->active) {
[ NSApp sendEvent:event ];
return true;
}
@@ -408,18 +378,18 @@ static bool QZ_PollEvent()
case NSMouseMoved:
case NSOtherMouseDragged:
case NSLeftMouseDragged:
- pt = _cocoa_subdriver->GetMouseLocation(event);
- if (!_cocoa_subdriver->MouseIsInsideView(&pt) && !_emulating_right_button) {
+ pt = this->GetMouseLocation(event);
+ if (!this->MouseIsInsideView(&pt) && !_emulating_right_button) {
[ NSApp sendEvent:event ];
break;
}
- QZ_MouseMovedEvent((int)pt.x, (int)pt.y);
+ this->MouseMovedEvent((int)pt.x, (int)pt.y);
break;
case NSRightMouseDragged:
- pt = _cocoa_subdriver->GetMouseLocation(event);
- QZ_MouseMovedEvent((int)pt.x, (int)pt.y);
+ pt = this->GetMouseLocation(event);
+ this->MouseMovedEvent((int)pt.x, (int)pt.y);
break;
case NSLeftMouseDown:
@@ -428,13 +398,13 @@ static bool QZ_PollEvent()
if (_settings_client.gui.right_mouse_btn_emulation == RMBE_COMMAND) keymask |= NSCommandKeyMask;
if (_settings_client.gui.right_mouse_btn_emulation == RMBE_CONTROL) keymask |= NSControlKeyMask;
- pt = _cocoa_subdriver->GetMouseLocation(event);
+ pt = this->GetMouseLocation(event);
- if (!([ event modifierFlags ] & keymask) || !_cocoa_subdriver->MouseIsInsideView(&pt)) {
+ if (!([ event modifierFlags ] & keymask) || !this->MouseIsInsideView(&pt)) {
[ NSApp sendEvent:event ];
}
- QZ_MouseMovedEvent((int)pt.x, (int)pt.y);
+ this->MouseMovedEvent((int)pt.x, (int)pt.y);
/* Right mouse button emulation */
if ([ event modifierFlags ] & keymask) {
@@ -448,9 +418,9 @@ static bool QZ_PollEvent()
case NSLeftMouseUp:
[ NSApp sendEvent:event ];
- pt = _cocoa_subdriver->GetMouseLocation(event);
+ pt = this->GetMouseLocation(event);
- QZ_MouseMovedEvent((int)pt.x, (int)pt.y);
+ this->MouseMovedEvent((int)pt.x, (int)pt.y);
/* Right mouse button emulation */
if (_emulating_right_button) {
@@ -462,24 +432,24 @@ static bool QZ_PollEvent()
break;
case NSRightMouseDown:
- pt = _cocoa_subdriver->GetMouseLocation(event);
- if (!_cocoa_subdriver->MouseIsInsideView(&pt)) {
+ pt = this->GetMouseLocation(event);
+ if (!this->MouseIsInsideView(&pt)) {
[ NSApp sendEvent:event ];
break;
}
- QZ_MouseMovedEvent((int)pt.x, (int)pt.y);
+ this->MouseMovedEvent((int)pt.x, (int)pt.y);
QZ_MouseButtonEvent(1, YES);
break;
case NSRightMouseUp:
- pt = _cocoa_subdriver->GetMouseLocation(event);
- if (!_cocoa_subdriver->MouseIsInsideView(&pt)) {
+ pt = this->GetMouseLocation(event);
+ if (!this->MouseIsInsideView(&pt)) {
[ NSApp sendEvent:event ];
break;
}
- QZ_MouseMovedEvent((int)pt.x, (int)pt.y);
+ this->MouseMovedEvent((int)pt.x, (int)pt.y);
QZ_MouseButtonEvent(1, NO);
break;
@@ -492,7 +462,7 @@ static bool QZ_PollEvent()
break;
}
- QZ_MouseMovedEvent((int)pt.x, (int)pt.y);
+ this->MouseMovedEvent((int)pt.x, (int)pt.y);
QZ_MouseButtonEvent([ event buttonNumber ], YES);
break;
@@ -503,7 +473,7 @@ static bool QZ_PollEvent()
break;
}
- QZ_MouseMovedEvent((int)pt.x, (int)pt.y);
+ this->MouseMovedEvent((int)pt.x, (int)pt.y);
QZ_MouseButtonEvent([ event buttonNumber ], NO);
break;
#endif
@@ -524,7 +494,7 @@ static bool QZ_PollEvent()
unsigned short unicode = [ chars length ] > 0 ? [ chars characterAtIndex:0 ] : 0;
if (EditBoxInGlobalFocus()) {
if (QZ_KeyEvent([ event keyCode ], unicode, YES)) {
- [ _cocoa_subdriver->cocoaview interpretKeyEvents:[ NSArray arrayWithObject:event ] ];
+ [ this->cocoaview interpretKeyEvents:[ NSArray arrayWithObject:event ] ];
}
} else {
QZ_KeyEvent([ event keyCode ], unicode, YES);
@@ -629,32 +599,32 @@ void VideoDriver_Cocoa::GameLoop()
#endif
DisplaySplashImage();
- QZ_CheckPaletteAnim();
- _cocoa_subdriver->Draw(true);
+ this->CheckPaletteAnim();
+ this->Draw(true);
CSleep(1);
for (int i = 0; i < 2; i++) ::GameLoop();
UpdateWindows();
- QZ_CheckPaletteAnim();
- _cocoa_subdriver->Draw();
+ this->CheckPaletteAnim();
+ this->Draw();
CSleep(1);
/* Set the proper OpenTTD palette which got spoilt by the splash
* image when using 8bpp blitter */
GfxInitPalettes();
- QZ_CheckPaletteAnim();
- _cocoa_subdriver->Draw(true);
+ this->CheckPaletteAnim();
+ this->Draw(true);
for (;;) {
uint32 prev_cur_ticks = cur_ticks; // to check for wrapping
InteractiveRandom(); // randomness
- while (QZ_PollEvent()) {}
+ while (this->PollEvent()) {}
if (_exit_game) {
/* Restore saved resolution if in fullscreen mode. */
- if (_cocoa_subdriver->IsFullscreen()) _cur_resolution = this->orig_res;
+ if (this->IsFullscreen()) _cur_resolution = this->orig_res;
break;
}
@@ -685,8 +655,8 @@ void VideoDriver_Cocoa::GameLoop()
::GameLoop();
UpdateWindows();
- QZ_CheckPaletteAnim();
- _cocoa_subdriver->Draw();
+ this->CheckPaletteAnim();
+ this->Draw();
} else {
#ifdef _DEBUG
uint32 st0 = GetTick();
@@ -697,7 +667,7 @@ void VideoDriver_Cocoa::GameLoop()
#endif
NetworkDrawChatMessage();
DrawMouseCursor();
- _cocoa_subdriver->Draw();
+ this->Draw();
}
}