6 * Scale© the old pixel buffer to the new one when switching resolution. * |
6 * Scale© the old pixel buffer to the new one when switching resolution. * |
7 ******************************************************************************/ |
7 ******************************************************************************/ |
8 |
8 |
9 #ifdef WITH_COCOA |
9 #ifdef WITH_COCOA |
10 |
10 |
|
11 #define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_3 |
11 #include <AvailabilityMacros.h> |
12 #include <AvailabilityMacros.h> |
12 |
13 |
13 #import <Cocoa/Cocoa.h> |
14 #import <Cocoa/Cocoa.h> |
14 #import <sys/time.h> /* gettimeofday */ |
15 #import <sys/time.h> /* gettimeofday */ |
15 #import <sys/param.h> /* for MAXPATHLEN */ |
16 #import <sys/param.h> /* for MAXPATHLEN */ |
37 # endif |
38 # endif |
38 #endif |
39 #endif |
39 |
40 |
40 |
41 |
41 #include "../../stdafx.h" |
42 #include "../../stdafx.h" |
42 #include "../../openttd.h" |
|
43 #include "../../debug.h" |
43 #include "../../debug.h" |
44 #include "../../macros.h" |
44 #include "../../core/geometry_type.hpp" |
45 #include "../../os/macosx/splash.h" |
|
46 #include "../../variables.h" |
|
47 #include "../../gfx.h" |
|
48 #include "cocoa_v.h" |
45 #include "cocoa_v.h" |
49 #include "cocoa_keys.h" |
46 #include "../../gfx_func.h" |
50 #include "../../blitter/factory.hpp" |
47 |
51 #include "../../fileio.h" |
|
52 |
|
53 #undef Point |
|
54 #undef Rect |
48 #undef Rect |
55 |
49 |
56 |
50 |
57 /* Structure for rez switch gamma fades |
51 /* Structure for rez switch gamma fades |
58 * We can hide the monitor flicker by setting the gamma tables to 0 |
52 * We can hide the monitor flicker by setting the gamma tables to 0 |
78 - (void) setFrame:(NSRect)frame; |
72 - (void) setFrame:(NSRect)frame; |
79 { |
73 { |
80 _frame = frame; |
74 _frame = frame; |
81 } |
75 } |
82 @end |
76 @end |
|
77 |
|
78 |
|
79 |
|
80 uint QZ_ListModes(OTTD_Point* modes, uint max_modes, CGDirectDisplayID display_id, int display_depth) |
|
81 { |
|
82 CFArrayRef mode_list; |
|
83 CFIndex num_modes; |
|
84 CFIndex i; |
|
85 uint count = 0; |
|
86 |
|
87 mode_list = CGDisplayAvailableModes(display_id); |
|
88 num_modes = CFArrayGetCount(mode_list); |
|
89 |
|
90 /* Build list of modes with the requested bpp */ |
|
91 for (i = 0; i < num_modes && count < max_modes; i++) { |
|
92 CFDictionaryRef onemode; |
|
93 CFNumberRef number; |
|
94 int bpp; |
|
95 int intvalue; |
|
96 bool hasMode; |
|
97 uint16 width, height; |
|
98 |
|
99 onemode = (const __CFDictionary*)CFArrayGetValueAtIndex(mode_list, i); |
|
100 number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayBitsPerPixel); |
|
101 CFNumberGetValue (number, kCFNumberSInt32Type, &bpp); |
|
102 |
|
103 if (bpp != display_depth) continue; |
|
104 |
|
105 number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayWidth); |
|
106 CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue); |
|
107 width = (uint16)intvalue; |
|
108 |
|
109 number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayHeight); |
|
110 CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue); |
|
111 height = (uint16)intvalue; |
|
112 |
|
113 /* Check if mode is already in the list */ |
|
114 { |
|
115 uint i; |
|
116 hasMode = false; |
|
117 for (i = 0; i < count; i++) { |
|
118 if (modes[i].x == width && modes[i].y == height) { |
|
119 hasMode = true; |
|
120 break; |
|
121 } |
|
122 } |
|
123 } |
|
124 |
|
125 if (hasMode) continue; |
|
126 |
|
127 /* Add mode to the list */ |
|
128 modes[count].x = width; |
|
129 modes[count].y = height; |
|
130 count++; |
|
131 } |
|
132 |
|
133 /* Sort list smallest to largest */ |
|
134 { |
|
135 uint i, j; |
|
136 for (i = 0; i < count; i++) { |
|
137 for (j = 0; j < count-1; j++) { |
|
138 if (modes[j].x > modes[j + 1].x || ( |
|
139 modes[j].x == modes[j + 1].x && |
|
140 modes[j].y > modes[j + 1].y |
|
141 )) { |
|
142 uint tmpw = modes[j].x; |
|
143 uint tmph = modes[j].y; |
|
144 |
|
145 modes[j].x = modes[j + 1].x; |
|
146 modes[j].y = modes[j + 1].y; |
|
147 |
|
148 modes[j + 1].x = tmpw; |
|
149 modes[j + 1].y = tmph; |
|
150 } |
|
151 } |
|
152 } |
|
153 } |
|
154 |
|
155 return count; |
|
156 } |
83 |
157 |
84 |
158 |
85 class FullscreenSubdriver: public CocoaSubdriver { |
159 class FullscreenSubdriver: public CocoaSubdriver { |
86 int display_width; |
160 int display_width; |
87 int display_height; |
161 int display_height; |
451 } |
525 } |
452 |
526 |
453 CGDisplaySetPalette(display_id, palette); |
527 CGDisplaySetPalette(display_id, palette); |
454 } |
528 } |
455 |
529 |
456 virtual uint ListModes(OTTDPoint* modes, uint max_modes) |
530 virtual uint ListModes(OTTD_Point* modes, uint max_modes) |
457 { |
531 { |
458 CFArrayRef mode_list; |
532 return QZ_ListModes(modes, max_modes, display_id, display_depth); |
459 CFIndex num_modes; |
|
460 CFIndex i; |
|
461 uint count = 0; |
|
462 |
|
463 mode_list = CGDisplayAvailableModes(display_id); |
|
464 num_modes = CFArrayGetCount(mode_list); |
|
465 |
|
466 /* Build list of modes with the requested bpp */ |
|
467 for (i = 0; i < num_modes && count < max_modes; i++) { |
|
468 CFDictionaryRef onemode; |
|
469 CFNumberRef number; |
|
470 int bpp; |
|
471 int intvalue; |
|
472 bool hasMode; |
|
473 uint16 width, height; |
|
474 |
|
475 onemode = (const __CFDictionary*)CFArrayGetValueAtIndex(mode_list, i); |
|
476 number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayBitsPerPixel); |
|
477 CFNumberGetValue (number, kCFNumberSInt32Type, &bpp); |
|
478 |
|
479 if (bpp != display_depth) continue; |
|
480 |
|
481 number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayWidth); |
|
482 CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue); |
|
483 width = (uint16)intvalue; |
|
484 |
|
485 number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayHeight); |
|
486 CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue); |
|
487 height = (uint16)intvalue; |
|
488 |
|
489 /* Check if mode is already in the list */ |
|
490 { |
|
491 uint i; |
|
492 hasMode = false; |
|
493 for (i = 0; i < count; i++) { |
|
494 if (modes[i].x == width && modes[i].y == height) { |
|
495 hasMode = true; |
|
496 break; |
|
497 } |
|
498 } |
|
499 } |
|
500 |
|
501 if (hasMode) continue; |
|
502 |
|
503 /* Add mode to the list */ |
|
504 modes[count].x = width; |
|
505 modes[count].y = height; |
|
506 count++; |
|
507 } |
|
508 |
|
509 /* Sort list smallest to largest */ |
|
510 { |
|
511 uint i, j; |
|
512 for (i = 0; i < count; i++) { |
|
513 for (j = 0; j < count-1; j++) { |
|
514 if (modes[j].x > modes[j + 1].x || ( |
|
515 modes[j].x == modes[j + 1].x && |
|
516 modes[j].y > modes[j + 1].y |
|
517 )) { |
|
518 uint tmpw = modes[j].x; |
|
519 uint tmph = modes[j].y; |
|
520 |
|
521 modes[j].x = modes[j + 1].x; |
|
522 modes[j].y = modes[j + 1].y; |
|
523 |
|
524 modes[j + 1].x = tmpw; |
|
525 modes[j + 1].y = tmph; |
|
526 } |
|
527 } |
|
528 } |
|
529 } |
|
530 |
|
531 return count; |
|
532 } |
533 } |
533 |
534 |
534 virtual bool ChangeResolution(int w, int h) |
535 virtual bool ChangeResolution(int w, int h) |
535 { |
536 { |
536 int old_width = display_width; |
537 int old_width = display_width; |