OpenTTD: src/video/cocoa/cocoa_v.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

cocoa_v.h
Go to the documentation of this file.
1 /* $Id: cocoa_v.h 26108 2013-11-25 14:30:22Z rubidium $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef VIDEO_COCOA_H
13 #define VIDEO_COCOA_H
14
15 #include "../video_driver.hpp"
16
17 class VideoDriver_Cocoa : public VideoDriver {
18 public:
19 /* virtual */ const char *Start(const char * const *param);
20
22 /* virtual */ void Stop();
23
30 /* virtual */ void MakeDirty(int left, int top, int width, int height);
31
33 /* virtual */ void MainLoop();
34
40 /* virtual */ bool ChangeResolution(int w, int h);
41
46 /* virtual */ bool ToggleFullscreen(bool fullscreen);
47
51 /* virtual */ bool AfterBlitterChange();
52
56 /* virtual */ void EditBoxLostFocus();
57
61 /* virtual */ const char *GetName() const { return "cocoa"; }
62 };
63
64 class FVideoDriver_Cocoa : public DriverFactoryBase {
65 public:
66 FVideoDriver_Cocoa() : DriverFactoryBase(Driver::DT_VIDEO, 10, "cocoa", "Cocoa Video Driver") {}
67 /* virtual */ Driver *CreateInstance() const { return new VideoDriver_Cocoa(); }
68 };
69
70
76 class CocoaSubdriver {
77 public:
78 int device_width;
79 int device_height;
80 int device_depth;
81
82 int window_width;
83 int window_height;
84 int window_pitch;
85
86 int buffer_depth;
87 void *pixel_buffer;
88 void *window_buffer;
89 id window;
90
91 # define MAX_DIRTY_RECTS 100
92 Rect dirty_rects[MAX_DIRTY_RECTS];
93 int num_dirty_rects;
94 uint32 palette[256];
95
96 bool active;
97 bool setup;
98
99 id cocoaview;
100
101 /* Separate driver vars for Quarz
102 * Needed here in order to avoid much code duplication */
103 CGContextRef cgcontext;
104
105 /* Driver methods */
107 virtual ~CocoaSubdriver() {}
108
112 virtual void Draw(bool force_update = false) = 0;
113
120 virtual void MakeDirty(int left, int top, int width, int height) = 0;
121
123 virtual void UpdatePalette(uint first_color, uint num_colors) = 0;
124
125 virtual uint ListModes(OTTD_Point *modes, uint max_modes) = 0;
126
132 virtual bool ChangeResolution(int w, int h, int bpp) = 0;
133
137 virtual bool IsFullscreen() = 0;
138
142 virtual bool ToggleFullscreen() { return false; };
143
147 virtual int GetWidth() = 0;
148
152 virtual int GetHeight() = 0;
153
157 virtual void *GetPixelBuffer() = 0;
158
163 virtual CGPoint PrivateLocalToCG(NSPoint *p) = 0;
164
169 virtual NSPoint GetMouseLocation(NSEvent *event) = 0;
170
175 virtual bool MouseIsInsideView(NSPoint *pt) = 0;
176
180 virtual bool IsActive() = 0;
181
183 virtual void SetPortAlphaOpaque() { return; };
184
188 virtual bool WindowResized() { return false; };
189 };
190
191 extern CocoaSubdriver *_cocoa_subdriver;
192
193 CocoaSubdriver *QZ_CreateFullscreenSubdriver(int width, int height, int bpp);
194
195 #ifdef ENABLE_COCOA_QUICKDRAW
196 CocoaSubdriver *QZ_CreateWindowQuickdrawSubdriver(int width, int height, int bpp);
197 #endif
198
199 #ifdef ENABLE_COCOA_QUARTZ
200 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
201 CocoaSubdriver *QZ_CreateWindowQuartzSubdriver(int width, int height, int bpp);
202 #endif
203 #endif
204
205 void QZ_GameSizeChanged();
206
207 void QZ_GameLoop();
208
209 uint QZ_ListModes(OTTD_Point *modes, uint max_modes, CGDirectDisplayID display_id, int display_depth);
210
212 @interface NSCursor (OTTD_QuickdrawCursor)
213 + (NSCursor *) clearCocoaCursor;
214 @end
215
217 @interface OTTD_CocoaWindow : NSWindow {
218 CocoaSubdriver *driver;
219 }
220
221 - (void)setDriver:(CocoaSubdriver*)drv;
222
223 - (void)miniaturize:(id)sender;
224 - (void)display;
225 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
226 - (void)appDidHide:(NSNotification*)note;
227 - (void)appWillUnhide:(NSNotification*)note;
228 - (void)appDidUnhide:(NSNotification*)note;
229 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag;
230 @end
231
233 @interface OTTD_CocoaView : NSView
234 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
235 # if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
236 <NSTextInputClient, NSTextInput>
237 # else
238 <NSTextInputClient>
239 # endif /* MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 */
240 #else
241 <NSTextInput>
242 #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 */
243 {
244 CocoaSubdriver *driver;
245 NSTrackingRectTag trackingtag;
246 }
247 - (void)setDriver:(CocoaSubdriver*)drv;
248 - (void)drawRect:(NSRect)rect;
249 - (BOOL)isOpaque;
250 - (BOOL)acceptsFirstResponder;
251 - (BOOL)becomeFirstResponder;
252 - (void)setTrackingRect;
253 - (void)clearTrackingRect;
254 - (void)resetCursorRects;
255 - (void)viewWillMoveToWindow:(NSWindow *)win;
256 - (void)viewDidMoveToWindow;
257 - (void)mouseEntered:(NSEvent *)theEvent;
258 - (void)mouseExited:(NSEvent *)theEvent;
259 @end
260
262 @interface OTTD_CocoaWindowDelegate : NSObject {
263 CocoaSubdriver *driver;
264 }
265
266 - (void)setDriver:(CocoaSubdriver*)drv;
267
268 - (BOOL)windowShouldClose:(id)sender;
269 - (void)windowDidEnterFullScreen:(NSNotification *)aNotification;
270 @end
271
272
273 #endif /* VIDEO_COCOA_H */