Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef VIDEO_COCOA_H
00013 #define VIDEO_COCOA_H
00014
00015 #include <AvailabilityMacros.h>
00016
00017 #include "../video_driver.hpp"
00018
00019 class VideoDriver_Cocoa: public VideoDriver {
00020 public:
00021 const char *Start(const char * const *param);
00022
00023 void Stop();
00024
00025 void MakeDirty(int left, int top, int width, int height);
00026
00027 void MainLoop();
00028
00029 bool ChangeResolution(int w, int h);
00030
00031 bool ToggleFullscreen(bool fullscreen);
00032
00033 const char *GetName() const { return "cocoa"; }
00034 };
00035
00036 class FVideoDriver_Cocoa: public VideoDriverFactory<FVideoDriver_Cocoa> {
00037 public:
00038 static const int priority = 10;
00039 const char *GetName() { return "cocoa"; }
00040 const char *GetDescription() { return "Cocoa Video Driver"; }
00041 Driver *CreateInstance() { return new VideoDriver_Cocoa(); }
00042 };
00043
00044
00050 class CocoaSubdriver {
00051 public:
00052 int device_width;
00053 int device_height;
00054 int device_depth;
00055
00056 int window_width;
00057 int window_height;
00058 int window_pitch;
00059
00060 int buffer_depth;
00061 void *pixel_buffer;
00062 void *window_buffer;
00063 id window;
00064
00065 # define MAX_DIRTY_RECTS 100
00066 Rect dirty_rects[MAX_DIRTY_RECTS];
00067 int num_dirty_rects;
00068 uint32 palette[256];
00069
00070 bool active;
00071 bool setup;
00072
00073 id cocoaview;
00074
00075
00076
00077 CGContextRef cgcontext;
00078
00079
00080 virtual ~CocoaSubdriver() {}
00081
00082 virtual void Draw(bool force_update = false) = 0;
00083 virtual void MakeDirty(int left, int top, int width, int height) = 0;
00084 virtual void UpdatePalette(uint first_color, uint num_colors) = 0;
00085
00086 virtual uint ListModes(OTTD_Point *modes, uint max_modes) = 0;
00087
00088 virtual bool ChangeResolution(int w, int h) = 0;
00089
00090 virtual bool IsFullscreen() = 0;
00091 virtual bool ToggleFullscreen() { return false; };
00092 virtual int GetWidth() = 0;
00093 virtual int GetHeight() = 0;
00094 virtual void *GetPixelBuffer() = 0;
00095
00096
00097 virtual CGPoint PrivateLocalToCG(NSPoint *p) = 0;
00098
00099 virtual NSPoint GetMouseLocation(NSEvent *event) = 0;
00100 virtual bool MouseIsInsideView(NSPoint *pt) = 0;
00101
00102 virtual bool IsActive() = 0;
00103
00104 virtual void SetPortAlphaOpaque() { return; };
00105 virtual bool WindowResized() { return false; };
00106 };
00107
00108 extern CocoaSubdriver *_cocoa_subdriver;
00109
00110 CocoaSubdriver *QZ_CreateFullscreenSubdriver(int width, int height, int bpp);
00111
00112 #ifdef ENABLE_COCOA_QUICKDRAW
00113 CocoaSubdriver *QZ_CreateWindowQuickdrawSubdriver(int width, int height, int bpp);
00114 #endif
00115
00116 #ifdef ENABLE_COCOA_QUARTZ
00117 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
00118 CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp);
00119 #endif
00120 #endif
00121
00122 void QZ_GameSizeChanged();
00123
00124 void QZ_GameLoop();
00125
00126 uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int display_depth);
00127
00129 @interface NSCursor (OTTD_QuickdrawCursor)
00130 + (NSCursor *) clearCocoaCursor;
00131 @end
00132
00134 @interface OTTD_CocoaWindow : NSWindow {
00135 CocoaSubdriver *driver;
00136 }
00137
00138 - (void)setDriver:(CocoaSubdriver*)drv;
00139
00140 - (void)miniaturize:(id)sender;
00141 - (void)display;
00142 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
00143 - (void)appDidHide:(NSNotification*)note;
00144 - (void)appWillUnhide:(NSNotification*)note;
00145 - (void)appDidUnhide:(NSNotification*)note;
00146 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag;
00147 @end
00148
00150 @interface OTTD_CocoaView : NSView {
00151 CocoaSubdriver *driver;
00152 NSTrackingRectTag trackingtag;
00153 }
00154 - (void)setDriver:(CocoaSubdriver*)drv;
00155 - (void)drawRect:(NSRect)rect;
00156 - (BOOL)isOpaque;
00157 - (BOOL)acceptsFirstResponder;
00158 - (BOOL)becomeFirstResponder;
00159 - (void)setTrackingRect;
00160 - (void)clearTrackingRect;
00161 - (void)resetCursorRects;
00162 - (void)viewWillMoveToWindow:(NSWindow *)win;
00163 - (void)viewDidMoveToWindow;
00164 - (void)mouseEntered:(NSEvent *)theEvent;
00165 - (void)mouseExited:(NSEvent *)theEvent;
00166 @end
00167
00169 @interface OTTD_CocoaWindowDelegate : NSObject {
00170 CocoaSubdriver *driver;
00171 }
00172
00173 - (void)setDriver:(CocoaSubdriver*)drv;
00174
00175 - (BOOL)windowShouldClose:(id)sender;
00176 @end
00177
00178
00179 #endif