cocoa_v.h

Go to the documentation of this file.
00001 /* $Id$ */
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 
00024   /* virtual */ void Stop();
00025 
00032   /* virtual */ void MakeDirty(int left, int top, int width, int height);
00033 
00035   /* virtual */ void MainLoop();
00036 
00042   /* virtual */ bool ChangeResolution(int w, int h);
00043 
00048   /* virtual */ bool ToggleFullscreen(bool fullscreen);
00049 
00053   /* virtual */ bool AfterBlitterChange();
00054 
00058   /* virtual */ const char *GetName() const { return "cocoa"; }
00059 };
00060 
00061 class FVideoDriver_Cocoa: public VideoDriverFactory<FVideoDriver_Cocoa> {
00062 public:
00063   static const int priority = 10;
00064   /* virtual */ const char *GetName() { return "cocoa"; }
00065   /* virtual */ const char *GetDescription() { return "Cocoa Video Driver"; }
00066   /* virtual */ Driver *CreateInstance() { return new VideoDriver_Cocoa(); }
00067 };
00068 
00069 
00075 class CocoaSubdriver {
00076 public:
00077   int device_width;     
00078   int device_height;    
00079   int device_depth;     
00080 
00081   int window_width;     
00082   int window_height;    
00083   int window_pitch;
00084 
00085   int buffer_depth;     
00086   void *pixel_buffer;   
00087   void *window_buffer;  
00088   id window;            
00089 
00090 # define MAX_DIRTY_RECTS 100
00091   Rect dirty_rects[MAX_DIRTY_RECTS]; 
00092   int num_dirty_rects;  
00093   uint32 palette[256];  
00094 
00095   bool active;          
00096   bool setup;
00097 
00098   id cocoaview;         
00099 
00100   /* Separate driver vars for Quarz
00101    * Needed here in order to avoid much code duplication */
00102   CGContextRef cgcontext;    
00103 
00104   /* Driver methods */
00106   virtual ~CocoaSubdriver() {}
00107 
00111   virtual void Draw(bool force_update = false) = 0;
00112 
00119   virtual void MakeDirty(int left, int top, int width, int height) = 0;
00120 
00122   virtual void UpdatePalette(uint first_color, uint num_colors) = 0;
00123 
00124   virtual uint ListModes(OTTD_Point *modes, uint max_modes) = 0;
00125 
00131   virtual bool ChangeResolution(int w, int h, int bpp) = 0;
00132 
00136   virtual bool IsFullscreen() = 0;
00137 
00141   virtual bool ToggleFullscreen() { return false; };
00142 
00146   virtual int GetWidth() = 0;
00147 
00151   virtual int GetHeight() = 0;
00152 
00156   virtual void *GetPixelBuffer() = 0;
00157 
00162   virtual CGPoint PrivateLocalToCG(NSPoint *p) = 0;
00163 
00168   virtual NSPoint GetMouseLocation(NSEvent *event) = 0;
00169 
00174   virtual bool MouseIsInsideView(NSPoint *pt) = 0;
00175 
00179   virtual bool IsActive() = 0;
00180 
00182   virtual void SetPortAlphaOpaque() { return; };
00183 
00187   virtual bool WindowResized() { return false; };
00188 };
00189 
00190 extern CocoaSubdriver *_cocoa_subdriver;
00191 
00192 CocoaSubdriver *QZ_CreateFullscreenSubdriver(int width, int height, int bpp);
00193 
00194 #ifdef ENABLE_COCOA_QUICKDRAW
00195 CocoaSubdriver *QZ_CreateWindowQuickdrawSubdriver(int width, int height, int bpp);
00196 #endif
00197 
00198 #ifdef ENABLE_COCOA_QUARTZ
00199 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
00200 CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp);
00201 #endif
00202 #endif
00203 
00204 void QZ_GameSizeChanged();
00205 
00206 void QZ_GameLoop();
00207 
00208 uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int display_depth);
00209 
00211 @interface NSCursor (OTTD_QuickdrawCursor)
00212 + (NSCursor *) clearCocoaCursor;
00213 @end
00214 
00216 @interface OTTD_CocoaWindow : NSWindow {
00217   CocoaSubdriver *driver;
00218 }
00219 
00220 - (void)setDriver:(CocoaSubdriver*)drv;
00221 
00222 - (void)miniaturize:(id)sender;
00223 - (void)display;
00224 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
00225 - (void)appDidHide:(NSNotification*)note;
00226 - (void)appWillUnhide:(NSNotification*)note;
00227 - (void)appDidUnhide:(NSNotification*)note;
00228 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag;
00229 @end
00230 
00232 @interface OTTD_CocoaView : NSView {
00233   CocoaSubdriver *driver;
00234   NSTrackingRectTag trackingtag;
00235 }
00236 - (void)setDriver:(CocoaSubdriver*)drv;
00237 - (void)drawRect:(NSRect)rect;
00238 - (BOOL)isOpaque;
00239 - (BOOL)acceptsFirstResponder;
00240 - (BOOL)becomeFirstResponder;
00241 - (void)setTrackingRect;
00242 - (void)clearTrackingRect;
00243 - (void)resetCursorRects;
00244 - (void)viewWillMoveToWindow:(NSWindow *)win;
00245 - (void)viewDidMoveToWindow;
00246 - (void)mouseEntered:(NSEvent *)theEvent;
00247 - (void)mouseExited:(NSEvent *)theEvent;
00248 @end
00249 
00251 @interface OTTD_CocoaWindowDelegate : NSObject {
00252   CocoaSubdriver *driver;
00253 }
00254 
00255 - (void)setDriver:(CocoaSubdriver*)drv;
00256 
00257 - (BOOL)windowShouldClose:(id)sender;
00258 @end
00259 
00260 
00261 #endif /* VIDEO_COCOA_H */