cocoa_v.h
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 int GetWidth() = 0;
00092 virtual int GetHeight() = 0;
00093 virtual void *GetPixelBuffer() = 0;
00094
00095
00096 virtual CGPoint PrivateLocalToCG(NSPoint *p) = 0;
00097
00098 virtual NSPoint GetMouseLocation(NSEvent *event) = 0;
00099 virtual bool MouseIsInsideView(NSPoint *pt) = 0;
00100
00101 virtual bool IsActive() = 0;
00102
00103 virtual void SetPortAlphaOpaque() { return; };
00104 virtual bool WindowResized() { return false; };
00105 };
00106
00107 extern CocoaSubdriver *_cocoa_subdriver;
00108
00109 CocoaSubdriver *QZ_CreateFullscreenSubdriver(int width, int height, int bpp);
00110
00111 #ifdef ENABLE_COCOA_QUICKDRAW
00112 CocoaSubdriver *QZ_CreateWindowQuickdrawSubdriver(int width, int height, int bpp);
00113 #endif
00114
00115 #ifdef ENABLE_COCOA_QUARTZ
00116 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
00117 CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp);
00118 #endif
00119 #endif
00120
00121 void QZ_GameSizeChanged();
00122
00123 void QZ_GameLoop();
00124
00125 uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int display_depth);
00126
00128 @interface NSCursor (OTTD_QuickdrawCursor)
00129 + (NSCursor *) clearCocoaCursor;
00130 @end
00131
00133 @interface OTTD_CocoaWindow : NSWindow {
00134 CocoaSubdriver *driver;
00135 }
00136
00137 - (void)setDriver:(CocoaSubdriver*)drv;
00138
00139 - (void)miniaturize:(id)sender;
00140 - (void)display;
00141 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
00142 - (void)appDidHide:(NSNotification*)note;
00143 - (void)appWillUnhide:(NSNotification*)note;
00144 - (void)appDidUnhide:(NSNotification*)note;
00145 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag;
00146 @end
00147
00149 @interface OTTD_CocoaView : NSView {
00150 CocoaSubdriver *driver;
00151 NSTrackingRectTag trackingtag;
00152 }
00153 - (void)setDriver:(CocoaSubdriver*)drv;
00154 - (void)drawRect:(NSRect)rect;
00155 - (BOOL)isOpaque;
00156 - (BOOL)acceptsFirstResponder;
00157 - (BOOL)becomeFirstResponder;
00158 - (void)setTrackingRect;
00159 - (void)clearTrackingRect;
00160 - (void)resetCursorRects;
00161 - (void)viewWillMoveToWindow:(NSWindow *)win;
00162 - (void)viewDidMoveToWindow;
00163 - (void)mouseEntered:(NSEvent *)theEvent;
00164 - (void)mouseExited:(NSEvent *)theEvent;
00165 @end
00166
00168 @interface OTTD_CocoaWindowDelegate : NSObject {
00169 CocoaSubdriver *driver;
00170 }
00171
00172 - (void)setDriver:(CocoaSubdriver*)drv;
00173
00174 - (BOOL)windowShouldClose:(id)sender;
00175 @end
00176
00177
00178 #endif