2007-11-22 21:48:17 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file cocoa_v.h The Cocoa video driver. */
|
|
|
|
|
2007-11-22 21:48:17 +00:00
|
|
|
#ifndef VIDEO_COCOA_H
|
|
|
|
#define VIDEO_COCOA_H
|
|
|
|
|
2007-11-30 13:26:24 +00:00
|
|
|
#include <AvailabilityMacros.h>
|
|
|
|
|
2007-11-22 21:48:17 +00:00
|
|
|
#include "../video_driver.hpp"
|
|
|
|
|
|
|
|
class VideoDriver_Cocoa: public VideoDriver {
|
|
|
|
public:
|
|
|
|
/* virtual */ const char *Start(const char * const *param);
|
|
|
|
|
|
|
|
/* virtual */ void Stop();
|
|
|
|
|
|
|
|
/* virtual */ void MakeDirty(int left, int top, int width, int height);
|
|
|
|
|
|
|
|
/* virtual */ void MainLoop();
|
|
|
|
|
|
|
|
/* virtual */ bool ChangeResolution(int w, int h);
|
|
|
|
|
2008-01-01 14:20:48 +00:00
|
|
|
/* virtual */ bool ToggleFullscreen(bool fullscreen);
|
2009-09-06 23:12:25 +00:00
|
|
|
|
|
|
|
/* virtual */ const char *GetName() const { return "cocoa"; }
|
2007-11-22 21:48:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FVideoDriver_Cocoa: public VideoDriverFactory<FVideoDriver_Cocoa> {
|
|
|
|
public:
|
|
|
|
static const int priority = 10;
|
|
|
|
/* virtual */ const char *GetName() { return "cocoa"; }
|
|
|
|
/* virtual */ const char *GetDescription() { return "Cocoa Video Driver"; }
|
|
|
|
/* virtual */ Driver *CreateInstance() { return new VideoDriver_Cocoa(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-12-21 15:56:02 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2007-11-22 21:48:17 +00:00
|
|
|
class CocoaSubdriver {
|
|
|
|
public:
|
2010-12-21 15:56:02 +00:00
|
|
|
int device_width;
|
|
|
|
int device_height;
|
|
|
|
int device_depth;
|
|
|
|
|
|
|
|
int window_width;
|
|
|
|
int window_height;
|
|
|
|
int window_pitch;
|
|
|
|
|
|
|
|
int buffer_depth;
|
|
|
|
void *pixel_buffer; // used for direct pixel access
|
|
|
|
void *window_buffer; // has colour translation from palette to screen
|
|
|
|
id window; // pointer to window object
|
|
|
|
|
|
|
|
# define MAX_DIRTY_RECTS 100
|
|
|
|
Rect dirty_rects[MAX_DIRTY_RECTS];
|
|
|
|
int num_dirty_rects;
|
|
|
|
uint32 palette[256];
|
|
|
|
|
|
|
|
bool active;
|
|
|
|
bool setup;
|
|
|
|
|
|
|
|
id cocoaview; // pointer to view object
|
|
|
|
|
|
|
|
/* Separate driver vars for Quarz
|
|
|
|
* Needed here in order to avoid much code duplication */
|
|
|
|
CGContextRef cgcontext;
|
|
|
|
|
|
|
|
/* Driver methods */
|
2007-11-22 21:48:17 +00:00
|
|
|
virtual ~CocoaSubdriver() {}
|
|
|
|
|
2009-10-17 22:36:39 +00:00
|
|
|
virtual void Draw(bool force_update = false) = 0;
|
2007-11-22 21:48:17 +00:00
|
|
|
virtual void MakeDirty(int left, int top, int width, int height) = 0;
|
|
|
|
virtual void UpdatePalette(uint first_color, uint num_colors) = 0;
|
|
|
|
|
2009-01-10 00:31:47 +00:00
|
|
|
virtual uint ListModes(OTTD_Point *modes, uint max_modes) = 0;
|
2007-11-22 21:48:17 +00:00
|
|
|
|
|
|
|
virtual bool ChangeResolution(int w, int h) = 0;
|
|
|
|
|
|
|
|
virtual bool IsFullscreen() = 0;
|
|
|
|
virtual int GetWidth() = 0;
|
|
|
|
virtual int GetHeight() = 0;
|
|
|
|
virtual void *GetPixelBuffer() = 0;
|
|
|
|
|
|
|
|
/* Convert local coordinate to window server (CoreGraphics) coordinate */
|
2009-01-10 00:31:47 +00:00
|
|
|
virtual CGPoint PrivateLocalToCG(NSPoint *p) = 0;
|
2007-11-22 21:48:17 +00:00
|
|
|
|
|
|
|
virtual NSPoint GetMouseLocation(NSEvent *event) = 0;
|
|
|
|
virtual bool MouseIsInsideView(NSPoint *pt) = 0;
|
|
|
|
|
|
|
|
virtual bool IsActive() = 0;
|
|
|
|
};
|
|
|
|
|
2009-01-10 00:31:47 +00:00
|
|
|
extern CocoaSubdriver *_cocoa_subdriver;
|
2007-11-22 21:48:17 +00:00
|
|
|
|
|
|
|
CocoaSubdriver *QZ_CreateFullscreenSubdriver(int width, int height, int bpp);
|
2007-12-17 07:47:21 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_COCOA_QUICKDRAW
|
2007-11-22 21:48:17 +00:00
|
|
|
CocoaSubdriver *QZ_CreateWindowQuickdrawSubdriver(int width, int height, int bpp);
|
2007-12-17 07:47:21 +00:00
|
|
|
#endif
|
2007-11-22 21:48:17 +00:00
|
|
|
|
2007-12-17 07:47:21 +00:00
|
|
|
#ifdef ENABLE_COCOA_QUARTZ
|
2007-11-30 13:26:24 +00:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
|
|
|
|
CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp);
|
|
|
|
#endif
|
2007-12-17 07:47:21 +00:00
|
|
|
#endif
|
2007-11-30 13:26:24 +00:00
|
|
|
|
2007-11-22 21:48:17 +00:00
|
|
|
void QZ_GameSizeChanged();
|
|
|
|
|
|
|
|
void QZ_GameLoop();
|
|
|
|
|
|
|
|
void QZ_ShowMouse();
|
|
|
|
void QZ_HideMouse();
|
|
|
|
|
2009-01-10 00:31:47 +00:00
|
|
|
uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int display_depth);
|
2007-12-29 05:15:13 +00:00
|
|
|
|
2010-12-21 16:00:42 +00:00
|
|
|
/* Subclass of NSView to fix Quartz rendering */
|
|
|
|
@interface OTTD_CocoaView : NSView {
|
|
|
|
CocoaSubdriver *driver;
|
|
|
|
}
|
|
|
|
- (void)setDriver:(CocoaSubdriver*)drv;
|
|
|
|
- (void)drawRect:(NSRect)rect;
|
|
|
|
- (BOOL)isOpaque;
|
|
|
|
@end
|
|
|
|
|
2010-12-21 15:57:55 +00:00
|
|
|
/** Delegate for our NSWindow to send ask for quit on close */
|
|
|
|
@interface OTTD_CocoaWindowDelegate : NSObject {
|
|
|
|
CocoaSubdriver *driver;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDriver:(CocoaSubdriver*)drv;
|
|
|
|
|
|
|
|
- (BOOL)windowShouldClose:(id)sender;
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
2007-11-22 21:48:17 +00:00
|
|
|
#endif /* VIDEO_COCOA_H */
|