cocoa_v.h

Go to the documentation of this file.
00001 /* $Id: cocoa_v.h 26108 2013-11-25 14:30:22Z 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 "../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 */ void EditBoxLostFocus();
00057 
00061   /* virtual */ const char *GetName() const { return "cocoa"; }
00062 };
00063 
00064 class FVideoDriver_Cocoa : public DriverFactoryBase {
00065 public:
00066   FVideoDriver_Cocoa() : DriverFactoryBase(Driver::DT_VIDEO, 10, "cocoa", "Cocoa Video Driver") {}
00067   /* virtual */ Driver *CreateInstance() const { return new VideoDriver_Cocoa(); }
00068 };
00069 
00070 
00076 class CocoaSubdriver {
00077 public:
00078   int device_width;     
00079   int device_height;    
00080   int device_depth;     
00081 
00082   int window_width;     
00083   int window_height;    
00084   int window_pitch;
00085 
00086   int buffer_depth;     
00087   void *pixel_buffer;   
00088   void *window_buffer;  
00089   id window;            
00090 
00091 # define MAX_DIRTY_RECTS 100
00092   Rect dirty_rects[MAX_DIRTY_RECTS]; 
00093   int num_dirty_rects;  
00094   uint32 palette[256];  
00095 
00096   bool active;          
00097   bool setup;
00098 
00099   id cocoaview;         
00100 
00101   /* Separate driver vars for Quarz
00102    * Needed here in order to avoid much code duplication */
00103   CGContextRef cgcontext;    
00104 
00105   /* Driver methods */
00107   virtual ~CocoaSubdriver() {}
00108 
00112   virtual void Draw(bool force_update = false) = 0;
00113 
00120   virtual void MakeDirty(int left, int top, int width, int height) = 0;
00121 
00123   virtual void UpdatePalette(uint first_color, uint num_colors) = 0;
00124 
00125   virtual uint ListModes(OTTD_Point *modes, uint max_modes) = 0;
00126 
00132   virtual bool ChangeResolution(int w, int h, int bpp) = 0;
00133 
00137   virtual bool IsFullscreen() = 0;
00138 
00142   virtual bool ToggleFullscreen() { return false; };
00143 
00147   virtual int GetWidth() = 0;
00148 
00152   virtual int GetHeight() = 0;
00153 
00157   virtual void *GetPixelBuffer() = 0;
00158 
00163   virtual CGPoint PrivateLocalToCG(NSPoint *p) = 0;
00164 
00169   virtual NSPoint GetMouseLocation(NSEvent *event) = 0;
00170 
00175   virtual bool MouseIsInsideView(NSPoint *pt) = 0;
00176 
00180   virtual bool IsActive() = 0;
00181 
00183   virtual void SetPortAlphaOpaque() { return; };
00184 
00188   virtual bool WindowResized() { return false; };
00189 };
00190 
00191 extern CocoaSubdriver *_cocoa_subdriver;
00192 
00193 CocoaSubdriver *QZ_CreateFullscreenSubdriver(int width, int height, int bpp);
00194 
00195 #ifdef ENABLE_COCOA_QUICKDRAW
00196 CocoaSubdriver *QZ_CreateWindowQuickdrawSubdriver(int width, int height, int bpp);
00197 #endif
00198 
00199 #ifdef ENABLE_COCOA_QUARTZ
00200 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
00201 CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp);
00202 #endif
00203 #endif
00204 
00205 void QZ_GameSizeChanged();
00206 
00207 void QZ_GameLoop();
00208 
00209 uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int display_depth);
00210 
00212 @interface NSCursor (OTTD_QuickdrawCursor)
00213 + (NSCursor *) clearCocoaCursor;
00214 @end
00215 
00217 @interface OTTD_CocoaWindow : NSWindow {
00218   CocoaSubdriver *driver;
00219 }
00220 
00221 - (void)setDriver:(CocoaSubdriver*)drv;
00222 
00223 - (void)miniaturize:(id)sender;
00224 - (void)display;
00225 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
00226 - (void)appDidHide:(NSNotification*)note;
00227 - (void)appWillUnhide:(NSNotification*)note;
00228 - (void)appDidUnhide:(NSNotification*)note;
00229 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag;
00230 @end
00231 
00233 @interface OTTD_CocoaView : NSView
00234 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
00235 # if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
00236     <NSTextInputClient, NSTextInput>
00237 # else
00238     <NSTextInputClient>
00239 # endif /* MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 */
00240 #else
00241   <NSTextInput>
00242 #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 */
00243 {
00244   CocoaSubdriver *driver;
00245   NSTrackingRectTag trackingtag;
00246 }
00247 - (void)setDriver:(CocoaSubdriver*)drv;
00248 - (void)drawRect:(NSRect)rect;
00249 - (BOOL)isOpaque;
00250 - (BOOL)acceptsFirstResponder;
00251 - (BOOL)becomeFirstResponder;
00252 - (void)setTrackingRect;
00253 - (void)clearTrackingRect;
00254 - (void)resetCursorRects;
00255 - (void)viewWillMoveToWindow:(NSWindow *)win;
00256 - (void)viewDidMoveToWindow;
00257 - (void)mouseEntered:(NSEvent *)theEvent;
00258 - (void)mouseExited:(NSEvent *)theEvent;
00259 @end
00260 
00262 @interface OTTD_CocoaWindowDelegate : NSObject {
00263   CocoaSubdriver *driver;
00264 }
00265 
00266 - (void)setDriver:(CocoaSubdriver*)drv;
00267 
00268 - (BOOL)windowShouldClose:(id)sender;
00269 - (void)windowDidEnterFullScreen:(NSNotification *)aNotification;
00270 @end
00271 
00272 
00273 #endif /* VIDEO_COCOA_H */