src/video/cocoa/fullscreen.mm
changeset 8652 e06732646b8a
parent 8642 b4acd0ef9ed1
equal deleted inserted replaced
8651:0775567ebf8a 8652:e06732646b8a
    72 - (void) setFrame:(NSRect)frame;
    72 - (void) setFrame:(NSRect)frame;
    73 {
    73 {
    74 	_frame = frame;
    74 	_frame = frame;
    75 }
    75 }
    76 @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 }
    77 
   157 
    78 
   158 
    79 class FullscreenSubdriver: public CocoaSubdriver {
   159 class FullscreenSubdriver: public CocoaSubdriver {
    80 	int                display_width;
   160 	int                display_width;
    81 	int                display_height;
   161 	int                display_height;
   447 		CGDisplaySetPalette(display_id, palette);
   527 		CGDisplaySetPalette(display_id, palette);
   448 	}
   528 	}
   449 
   529 
   450 	virtual uint ListModes(OTTD_Point* modes, uint max_modes)
   530 	virtual uint ListModes(OTTD_Point* modes, uint max_modes)
   451 	{
   531 	{
   452 		CFArrayRef mode_list;
   532 		return QZ_ListModes(modes, max_modes, display_id, display_depth);
   453 		CFIndex num_modes;
       
   454 		CFIndex i;
       
   455 		uint count = 0;
       
   456 
       
   457 		mode_list  = CGDisplayAvailableModes(display_id);
       
   458 		num_modes = CFArrayGetCount(mode_list);
       
   459 
       
   460 		/* Build list of modes with the requested bpp */
       
   461 		for (i = 0; i < num_modes && count < max_modes; i++) {
       
   462 			CFDictionaryRef onemode;
       
   463 			CFNumberRef     number;
       
   464 			int bpp;
       
   465 			int intvalue;
       
   466 			bool hasMode;
       
   467 			uint16 width, height;
       
   468 
       
   469 			onemode = (const __CFDictionary*)CFArrayGetValueAtIndex(mode_list, i);
       
   470 			number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayBitsPerPixel);
       
   471 			CFNumberGetValue (number, kCFNumberSInt32Type, &bpp);
       
   472 
       
   473 			if (bpp != display_depth) continue;
       
   474 
       
   475 			number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayWidth);
       
   476 			CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue);
       
   477 			width = (uint16)intvalue;
       
   478 
       
   479 			number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayHeight);
       
   480 			CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue);
       
   481 			height = (uint16)intvalue;
       
   482 
       
   483 			/* Check if mode is already in the list */
       
   484 			{
       
   485 				uint i;
       
   486 				hasMode = false;
       
   487 				for (i = 0; i < count; i++) {
       
   488 					if (modes[i].x == width &&  modes[i].y == height) {
       
   489 						hasMode = true;
       
   490 						break;
       
   491 					}
       
   492 				}
       
   493 			}
       
   494 
       
   495 			if (hasMode) continue;
       
   496 
       
   497 			/* Add mode to the list */
       
   498 			modes[count].x = width;
       
   499 			modes[count].y = height;
       
   500 			count++;
       
   501 		}
       
   502 
       
   503 		/* Sort list smallest to largest */
       
   504 		{
       
   505 			uint i, j;
       
   506 			for (i = 0; i < count; i++) {
       
   507 				for (j = 0; j < count-1; j++) {
       
   508 					if (modes[j].x > modes[j + 1].x || (
       
   509 						modes[j].x == modes[j + 1].x &&
       
   510 						modes[j].y >  modes[j + 1].y
       
   511 						)) {
       
   512 						uint tmpw = modes[j].x;
       
   513 						uint tmph = modes[j].y;
       
   514 
       
   515 						modes[j].x = modes[j + 1].x;
       
   516 						modes[j].y = modes[j + 1].y;
       
   517 
       
   518 						modes[j + 1].x = tmpw;
       
   519 						modes[j + 1].y = tmph;
       
   520 					}
       
   521 				}
       
   522 			}
       
   523 		}
       
   524 
       
   525 		return count;
       
   526 	}
   533 	}
   527 
   534 
   528 	virtual bool ChangeResolution(int w, int h)
   535 	virtual bool ChangeResolution(int w, int h)
   529 	{
   536 	{
   530 		int old_width  = display_width;
   537 		int old_width  = display_width;