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 "../video_driver.hpp"
00016
00017 class VideoDriver_Cocoa: public VideoDriver {
00018 public:
00019 const char *Start(const char * const *param);
00020
00022 void Stop();
00023
00030 void MakeDirty(int left, int top, int width, int height);
00031
00033 void MainLoop();
00034
00040 bool ChangeResolution(int w, int h);
00041
00046 bool ToggleFullscreen(bool fullscreen);
00047
00051 bool AfterBlitterChange();
00052
00056 void EditBoxLostFocus();
00057
00061 const char *GetName() const { return "cocoa"; }
00062 };
00063
00064 class FVideoDriver_Cocoa: public VideoDriverFactory<FVideoDriver_Cocoa> {
00065 public:
00066 static const int priority = 10;
00067 const char *GetName() { return "cocoa"; }
00068 const char *GetDescription() { return "Cocoa Video Driver"; }
00069 Driver *CreateInstance() { return new VideoDriver_Cocoa(); }
00070 };
00071
00072
00078 class CocoaSubdriver {
00079 public:
00080 int device_width;
00081 int device_height;
00082 int device_depth;
00083
00084 int window_width;
00085 int window_height;
00086 int window_pitch;
00087
00088 int buffer_depth;
00089 void *pixel_buffer;
00090 void *window_buffer;
00091 id window;
00092
00093 # define MAX_DIRTY_RECTS 100
00094 Rect dirty_rects[MAX_DIRTY_RECTS];
00095 int num_dirty_rects;
00096 uint32 palette[256];
00097
00098 bool active;
00099 bool setup;
00100
00101 id cocoaview;
00102
00103
00104
00105 CGContextRef cgcontext;
00106
00107
00109 virtual ~CocoaSubdriver() {}
00110
00114 virtual void Draw(bool force_update = false) = 0;
00115
00122 virtual void MakeDirty(int left, int top, int width, int height) = 0;
00123
00125 virtual void UpdatePalette(uint first_color, uint num_colors) = 0;
00126
00127 virtual uint ListModes(OTTD_Point *modes, uint max_modes) = 0;
00128
00134 virtual bool ChangeResolution(int w, int h, int bpp) = 0;
00135
00139 virtual bool IsFullscreen() = 0;
00140
00144 virtual bool ToggleFullscreen() { return false; };
00145
00149 virtual int GetWidth() = 0;
00150
00154 virtual int GetHeight() = 0;
00155
00159 virtual void *GetPixelBuffer() = 0;
00160
00165 virtual CGPoint PrivateLocalToCG(NSPoint *p) = 0;
00166
00171 virtual NSPoint GetMouseLocation(NSEvent *event) = 0;
00172
00177 virtual bool MouseIsInsideView(NSPoint *pt) = 0;
00178
00182 virtual bool IsActive() = 0;
00183
00185 virtual void SetPortAlphaOpaque() { return; };
00186
00190 virtual bool WindowResized() { return false; };
00191 };
00192
00193 extern CocoaSubdriver *_cocoa_subdriver;
00194
00195 CocoaSubdriver *QZ_CreateFullscreenSubdriver(int width, int height, int bpp);
00196
00197 #ifdef ENABLE_COCOA_QUICKDRAW
00198 CocoaSubdriver *QZ_CreateWindowQuickdrawSubdriver(int width, int height, int bpp);
00199 #endif
00200
00201 #ifdef ENABLE_COCOA_QUARTZ
00202 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
00203 CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp);
00204 #endif
00205 #endif
00206
00207 void QZ_GameSizeChanged();
00208
00209 void QZ_GameLoop();
00210
00211 uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int display_depth);
00212
00214 @interface NSCursor (OTTD_QuickdrawCursor)
00215 + (NSCursor *) clearCocoaCursor;
00216 @end
00217
00219 @interface OTTD_CocoaWindow : NSWindow {
00220 CocoaSubdriver *driver;
00221 }
00222
00223 - (void)setDriver:(CocoaSubdriver*)drv;
00224
00225 - (void)miniaturize:(id)sender;
00226 - (void)display;
00227 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
00228 - (void)appDidHide:(NSNotification*)note;
00229 - (void)appWillUnhide:(NSNotification*)note;
00230 - (void)appDidUnhide:(NSNotification*)note;
00231 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag;
00232 @end
00233
00235 @interface OTTD_CocoaView : NSView
00236 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
00237 # if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
00238 <NSTextInputClient, NSTextInput>
00239 # else
00240 <NSTextInputClient>
00241 # endif
00242 #else
00243 <NSTextInput>
00244 #endif
00245 {
00246 CocoaSubdriver *driver;
00247 NSTrackingRectTag trackingtag;
00248 }
00249 - (void)setDriver:(CocoaSubdriver*)drv;
00250 - (void)drawRect:(NSRect)rect;
00251 - (BOOL)isOpaque;
00252 - (BOOL)acceptsFirstResponder;
00253 - (BOOL)becomeFirstResponder;
00254 - (void)setTrackingRect;
00255 - (void)clearTrackingRect;
00256 - (void)resetCursorRects;
00257 - (void)viewWillMoveToWindow:(NSWindow *)win;
00258 - (void)viewDidMoveToWindow;
00259 - (void)mouseEntered:(NSEvent *)theEvent;
00260 - (void)mouseExited:(NSEvent *)theEvent;
00261 @end
00262
00264 @interface OTTD_CocoaWindowDelegate : NSObject {
00265 CocoaSubdriver *driver;
00266 }
00267
00268 - (void)setDriver:(CocoaSubdriver*)drv;
00269
00270 - (BOOL)windowShouldClose:(id)sender;
00271 - (void)windowDidEnterFullScreen:(NSNotification *)aNotification;
00272 @end
00273
00274
00275 #endif