cocoa_v.h

Go to the documentation of this file.
00001 /* $Id: cocoa_v.h 24900 2013-01-08 22:46:42Z planetmaker $ */
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 "../video_driver.hpp"
00016 
00017 class VideoDriver_Cocoa: public VideoDriver {
00018 public:
00019   /* virtual */ const char *Start(const char * const *param);
00020 
00022   /* virtual */ void Stop();
00023 
00030   /* virtual */ void MakeDirty(int left, int top, int width, int height);
00031 
00033   /* virtual */ void MainLoop();
00034 
00040   /* virtual */ bool ChangeResolution(int w, int h);
00041 
00046   /* virtual */ bool ToggleFullscreen(bool fullscreen);
00047 
00051   /* virtual */ bool AfterBlitterChange();
00052 
00056   /* virtual */ const char *GetName() const { return "cocoa"; }
00057 };
00058 
00059 class FVideoDriver_Cocoa: public VideoDriverFactory<FVideoDriver_Cocoa> {
00060 public:
00061   static const int priority = 10;
00062   /* virtual */ const char *GetName() { return "cocoa"; }
00063   /* virtual */ const char *GetDescription() { return "Cocoa Video Driver"; }
00064   /* virtual */ Driver *CreateInstance() { return new VideoDriver_Cocoa(); }
00065 };
00066 
00067 
00073 class CocoaSubdriver {
00074 public:
00075   int device_width;     
00076   int device_height;    
00077   int device_depth;     
00078 
00079   int window_width;     
00080   int window_height;    
00081   int window_pitch;
00082 
00083   int buffer_depth;     
00084   void *pixel_buffer;   
00085   void *window_buffer;  
00086   id window;            
00087 
00088 # define MAX_DIRTY_RECTS 100
00089   Rect dirty_rects[MAX_DIRTY_RECTS]; 
00090   int num_dirty_rects;  
00091   uint32 palette[256];  
00092 
00093   bool active;          
00094   bool setup;
00095 
00096   id cocoaview;         
00097 
00098   /* Separate driver vars for Quarz
00099    * Needed here in order to avoid much code duplication */
00100   CGContextRef cgcontext;    
00101 
00102   /* Driver methods */
00104   virtual ~CocoaSubdriver() {}
00105 
00109   virtual void Draw(bool force_update = false) = 0;
00110 
00117   virtual void MakeDirty(int left, int top, int width, int height) = 0;
00118 
00120   virtual void UpdatePalette(uint first_color, uint num_colors) = 0;
00121 
00122   virtual uint ListModes(OTTD_Point *modes, uint max_modes) = 0;
00123 
00129   virtual bool ChangeResolution(int w, int h, int bpp) = 0;
00130 
00134   virtual bool IsFullscreen() = 0;
00135 
00139   virtual bool ToggleFullscreen() { return false; };
00140 
00144   virtual int GetWidth() = 0;
00145 
00149   virtual int GetHeight() = 0;
00150 
00154   virtual void *GetPixelBuffer() = 0;
00155 
00160   virtual CGPoint PrivateLocalToCG(NSPoint *p) = 0;
00161 
00166   virtual NSPoint GetMouseLocation(NSEvent *event) = 0;
00167 
00172   virtual bool MouseIsInsideView(NSPoint *pt) = 0;
00173 
00177   virtual bool IsActive() = 0;
00178 
00180   virtual void SetPortAlphaOpaque() { return; };
00181 
00185   virtual bool WindowResized() { return false; };
00186 };
00187 
00188 extern CocoaSubdriver *_cocoa_subdriver;
00189 
00190 CocoaSubdriver *QZ_CreateFullscreenSubdriver(int width, int height, int bpp);
00191 
00192 #ifdef ENABLE_COCOA_QUICKDRAW
00193 CocoaSubdriver *QZ_CreateWindowQuickdrawSubdriver(int width, int height, int bpp);
00194 #endif
00195 
00196 #ifdef ENABLE_COCOA_QUARTZ
00197 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
00198 CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp);
00199 #endif
00200 #endif
00201 
00202 void QZ_GameSizeChanged();
00203 
00204 void QZ_GameLoop();
00205 
00206 uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int display_depth);
00207 
00209 @interface NSCursor (OTTD_QuickdrawCursor)
00210 + (NSCursor *) clearCocoaCursor;
00211 @end
00212 
00214 @interface OTTD_CocoaWindow : NSWindow {
00215   CocoaSubdriver *driver;
00216 }
00217 
00218 - (void)setDriver:(CocoaSubdriver*)drv;
00219 
00220 - (void)miniaturize:(id)sender;
00221 - (void)display;
00222 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
00223 - (void)appDidHide:(NSNotification*)note;
00224 - (void)appWillUnhide:(NSNotification*)note;
00225 - (void)appDidUnhide:(NSNotification*)note;
00226 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag;
00227 @end
00228 
00230 @interface OTTD_CocoaView : NSView {
00231   CocoaSubdriver *driver;
00232   NSTrackingRectTag trackingtag;
00233 }
00234 - (void)setDriver:(CocoaSubdriver*)drv;
00235 - (void)drawRect:(NSRect)rect;
00236 - (BOOL)isOpaque;
00237 - (BOOL)acceptsFirstResponder;
00238 - (BOOL)becomeFirstResponder;
00239 - (void)setTrackingRect;
00240 - (void)clearTrackingRect;
00241 - (void)resetCursorRects;
00242 - (void)viewWillMoveToWindow:(NSWindow *)win;
00243 - (void)viewDidMoveToWindow;
00244 - (void)mouseEntered:(NSEvent *)theEvent;
00245 - (void)mouseExited:(NSEvent *)theEvent;
00246 @end
00247 
00249 @interface OTTD_CocoaWindowDelegate : NSObject {
00250   CocoaSubdriver *driver;
00251 }
00252 
00253 - (void)setDriver:(CocoaSubdriver*)drv;
00254 
00255 - (BOOL)windowShouldClose:(id)sender;
00256 @end
00257 
00258 
00259 #endif /* VIDEO_COCOA_H */