Exemplo n.º 1
0
// Finds any supported graphics mode that can fit requested game frame size;
// returns true if found acceptable mode, sets found_size.
bool try_find_nearest_supported_mode(const Size &base_size, const int scaling_factor, Size &found_size, const int color_depth,
                                     const bool windowed, const bool enable_sideborders, const bool force_letterbox)
{
    Size desktop_size;
    if (!get_desktop_size_for_mode(desktop_size, windowed))
    {
        Out::FPrint("Failed to find acceptable supported gfx mode (unable to obtain desktop resolution)");
        return false;
    }
    const Size wanted_size = base_size * scaling_factor;
    // Windowed mode
    if (windowed)
    {
        // Do not try to create windowed mode larger than current desktop resolution
        if (!wanted_size.ExceedsByAny(desktop_size))
        {
            found_size = wanted_size;
            return true;
        }
        return false;
    }

    // Fullscreen mode: always try strictly no borders first, unless they are
    // explicitly enabled, so that modes with borders could be tried later
    // anyway if "no borders" failed.
    bool found = false;
    if (!enable_sideborders)
    {
        // no sideborders
        if (!force_letterbox) 
            // no letterboxing, perfect match only
            found = find_nearest_supported_mode(base_size, scaling_factor, found_size, color_depth, NULL, true, true);

        if (!found)
        {
            // with letterboxing, letterbox only
            // try match desktop ratio
            found = find_nearest_supported_mode(base_size, scaling_factor, found_size, color_depth, &desktop_size, true, false);
            if (!found)
                // disregard desktop ratio
                found = find_nearest_supported_mode(base_size, scaling_factor, found_size, color_depth, NULL, true, false);
        }
    }

    if (!found)
    {
        // with sideborders
        if (!force_letterbox) 
        {
            // no letterbox, sideborders only
            // try match desktop ratio
            found = find_nearest_supported_mode(base_size, scaling_factor, found_size, color_depth, &desktop_size, false, true);
            if (!found)
                // disregard desktop ratio
                found = find_nearest_supported_mode(base_size, scaling_factor, found_size, color_depth, NULL, false, true);
        }

        if (!found)
        {
            // with letterboxing, letterbox + sideborders
            // try match desktop ratio
            found = find_nearest_supported_mode(base_size, scaling_factor, found_size, color_depth, &desktop_size);
            if (!found)
                // disregard desktop ratio
                found = find_nearest_supported_mode(base_size, scaling_factor, found_size, color_depth, NULL);
        }
    }

    if (!found)
        Out::FPrint("Couldn't find acceptable supported gfx mode for game frame %d x %d (%d bit)",
            wanted_size.Width, wanted_size.Height, color_depth);
    return found;
}