cocoa_v.h

Go to the documentation of this file.
00001 /* $Id: cocoa_v.h 22992 2011-10-04 20:12:02Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * 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.
00006  * 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.
00007  * 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/>.
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   /* virtual */ const char *Start(const char * const *param);
00022 
00023   /* virtual */ void Stop();
00024 
00025   /* virtual */ void MakeDirty(int left, int top, int width, int height);
00026 
00027   /* virtual */ void MainLoop();
00028 
00029   /* virtual */ bool ChangeResolution(int w, int h);
00030 
00031   /* virtual */ bool ToggleFullscreen(bool fullscreen);
00032 
00033   /* virtual */ 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   /* virtual */ const char *GetName() { return "cocoa"; }
00040   /* virtual */ const char *GetDescription() { return "Cocoa Video Driver"; }
00041   /* virtual */ 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;   // used for direct pixel access
00062   void *window_buffer;  // has colour translation from palette to screen
00063   id window;            // pointer to window object
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;         // pointer to view object
00074 
00075   /* Separate driver vars for Quarz
00076    * Needed here in order to avoid much code duplication */
00077   CGContextRef cgcontext;
00078 
00079   /* Driver methods */
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   /* Convert local coordinate to window server (CoreGraphics) coordinate */
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 /* VIDEO_COCOA_H */