Index: src/video/cocoa/cocoa_v.mm =================================================================== --- src/video/cocoa/cocoa_v.mm (revision 11520) +++ src/video/cocoa/cocoa_v.mm (working copy) @@ -194,22 +194,78 @@ [NSApp setDelegate:_ottd_main]; } +/* List available modes */ +static uint QZ_ListModes(OTTDPoint* modes, uint max_modes) +{ + CFArrayRef mode_list; + CFIndex num_modes; + CFIndex i; + uint count = 0; + mode_list = CGDisplayAvailableModes(kCGDirectMainDisplay); + num_modes = CFArrayGetCount(mode_list); + + /* Build list of modes with the requested bpp */ + for (i = 0; i < num_modes && count < max_modes; i++) { + CFDictionaryRef onemode; + CFNumberRef number; + int bpp; + int intvalue; + bool hasMode; + uint16 width, height; + + onemode = (const __CFDictionary*)CFArrayGetValueAtIndex(mode_list, i); + number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayBitsPerPixel); + CFNumberGetValue (number, kCFNumberSInt32Type, &bpp); + + if (bpp != BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth()) continue; + + number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayWidth); + CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue); + width = (uint16)intvalue; + + number = (const __CFNumber*)CFDictionaryGetValue(onemode, kCGDisplayHeight); + CFNumberGetValue(number, kCFNumberSInt32Type, &intvalue); + height = (uint16)intvalue; + + /* Check if mode is already in the list */ + { + uint i; + hasMode = false; + for (i = 0; i < count; i++) { + if (modes[i].x == width && modes[i].y == height) { + hasMode = true; + break; + } + } + } + + if (hasMode) continue; + + /* Add mode to the list */ + modes[count].x = width; + modes[count].y = height; + count++; + } + + return count; +} + static void QZ_UpdateVideoModes() { uint i, count; OTTDPoint modes[32]; - assert(_cocoa_subdriver != NULL); + count = QZ_ListModes(modes, lengthof(modes)); - count = _cocoa_subdriver->ListModes(modes, lengthof(modes)); - for (i = 0; i < count; i++) { _resolutions[i][0] = modes[i].x; _resolutions[i][1] = modes[i].y; } _num_resolutions = count; + + SortResolutions(_num_resolutions); }