comparison src/video/cocoa/wnd_quickdraw.mm @ 7943:d7120b427cf5 draft

(svn r11498) -Add [FS#1411]: [OSX] Added support for using Quartz instead of Quickdraw in windowed mode on OS X 10.4 and higher. Based on a patch by blackis.
author egladil <egladil@openttd.org>
date Fri, 23 Nov 2007 02:44:05 +0000
parents 025c23786172
children f68ccdd562d9
comparison
equal deleted inserted replaced
7942:ab77bf853d43 7943:d7120b427cf5
52 52
53 class WindowQuickdrawSubdriver; 53 class WindowQuickdrawSubdriver;
54 54
55 55
56 /* Subclass of NSWindow to fix genie effect and support resize events */ 56 /* Subclass of NSWindow to fix genie effect and support resize events */
57 @interface OTTD_QuartzWindow : NSWindow { 57 @interface OTTD_QuickdrawWindow : NSWindow {
58 WindowQuickdrawSubdriver *driver; 58 WindowQuickdrawSubdriver *driver;
59 } 59 }
60 60
61 - (void)setDriver:(WindowQuickdrawSubdriver*)drv; 61 - (void)setDriver:(WindowQuickdrawSubdriver*)drv;
62 62
68 - (void)appDidUnhide:(NSNotification*)note; 68 - (void)appDidUnhide:(NSNotification*)note;
69 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag; 69 - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag;
70 @end 70 @end
71 71
72 /* Delegate for our NSWindow to send ask for quit on close */ 72 /* Delegate for our NSWindow to send ask for quit on close */
73 @interface OTTD_QuartzWindowDelegate : NSObject{ 73 @interface OTTD_QuickdrawWindowDelegate : NSObject{
74 WindowQuickdrawSubdriver *driver; 74 WindowQuickdrawSubdriver *driver;
75 } 75 }
76 76
77 - (void)setDriver:(WindowQuickdrawSubdriver*)drv; 77 - (void)setDriver:(WindowQuickdrawSubdriver*)drv;
78 78
91 int buffer_depth; 91 int buffer_depth;
92 92
93 void *pixel_buffer; 93 void *pixel_buffer;
94 void *window_buffer; 94 void *window_buffer;
95 95
96 OTTD_QuartzWindow *window; 96 OTTD_QuickdrawWindow *window;
97 97
98 #define MAX_DIRTY_RECTS 100 98 #define MAX_DIRTY_RECTS 100
99 Rect dirty_rects[MAX_DIRTY_RECTS]; 99 Rect dirty_rects[MAX_DIRTY_RECTS];
100 int num_dirty_rects; 100 int num_dirty_rects;
101 101
177 void SetPortAlphaOpaque(); 177 void SetPortAlphaOpaque();
178 bool WindowResized(); 178 bool WindowResized();
179 }; 179 };
180 180
181 181
182 @implementation OTTD_QuartzWindow 182 @implementation OTTD_QuickdrawWindow
183 183
184 - (void)setDriver:(WindowQuickdrawSubdriver*)drv 184 - (void)setDriver:(WindowQuickdrawSubdriver*)drv
185 { 185 {
186 driver = drv; 186 driver = drv;
187 } 187 }
273 return [ super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag ]; 273 return [ super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag ];
274 } 274 }
275 275
276 @end 276 @end
277 277
278 @implementation OTTD_QuartzWindowDelegate 278 @implementation OTTD_QuickdrawWindowDelegate
279 - (void)setDriver:(WindowQuickdrawSubdriver*)drv 279 - (void)setDriver:(WindowQuickdrawSubdriver*)drv
280 { 280 {
281 driver = drv; 281 driver = drv;
282 } 282 }
283 283
388 388
389 contentRect = NSMakeRect(0, 0, width, height); 389 contentRect = NSMakeRect(0, 0, width, height);
390 390
391 /* Check if we should recreate the window */ 391 /* Check if we should recreate the window */
392 if (window == nil) { 392 if (window == nil) {
393 OTTD_QuartzWindowDelegate *delegate; 393 OTTD_QuickdrawWindowDelegate *delegate;
394 394
395 /* Set the window style */ 395 /* Set the window style */
396 style = NSTitledWindowMask; 396 style = NSTitledWindowMask;
397 style |= (NSMiniaturizableWindowMask | NSClosableWindowMask); 397 style |= (NSMiniaturizableWindowMask | NSClosableWindowMask);
398 style |= NSResizableWindowMask; 398 style |= NSResizableWindowMask;
399 399
400 /* Manually create a window, avoids having a nib file resource */ 400 /* Manually create a window, avoids having a nib file resource */
401 window = [ [ OTTD_QuartzWindow alloc ] 401 window = [ [ OTTD_QuickdrawWindow alloc ]
402 initWithContentRect:contentRect 402 initWithContentRect:contentRect
403 styleMask:style 403 styleMask:style
404 backing:NSBackingStoreBuffered 404 backing:NSBackingStoreBuffered
405 defer:NO ]; 405 defer:NO ];
406 406
419 [ nsscaption release ]; 419 [ nsscaption release ];
420 420
421 [ window setAcceptsMouseMovedEvents:YES ]; 421 [ window setAcceptsMouseMovedEvents:YES ];
422 [ window setViewsNeedDisplay:NO ]; 422 [ window setViewsNeedDisplay:NO ];
423 423
424 delegate = [ [ OTTD_QuartzWindowDelegate alloc ] init ]; 424 delegate = [ [ OTTD_QuickdrawWindowDelegate alloc ] init ];
425 [ delegate setDriver:this ]; 425 [ delegate setDriver:this ];
426 [ window setDelegate: [ delegate autorelease ] ]; 426 [ window setDelegate: [ delegate autorelease ] ];
427 } else { 427 } else {
428 /* We already have a window, just change its size */ 428 /* We already have a window, just change its size */
429 if (!isCustom) { 429 if (!isCustom) {
801 801
802 CocoaSubdriver *QZ_CreateWindowQuickdrawSubdriver(int width, int height, int bpp) 802 CocoaSubdriver *QZ_CreateWindowQuickdrawSubdriver(int width, int height, int bpp)
803 { 803 {
804 WindowQuickdrawSubdriver *ret; 804 WindowQuickdrawSubdriver *ret;
805 805
806 if (bpp != 8 && bpp != 32) {
807 DEBUG(driver, 0, "The cocoa quickdraw subdriver only supports 8 and 32 bpp.");
808 return NULL;
809 }
810
806 ret = new WindowQuickdrawSubdriver(bpp); 811 ret = new WindowQuickdrawSubdriver(bpp);
807 812
808 if (!ret->ChangeResolution(width, height)) { 813 if (!ret->ChangeResolution(width, height)) {
809 delete ret; 814 delete ret;
810 return NULL; 815 return NULL;