Skip to content

Commit

Permalink
Use resolution detection function at startup
Browse files Browse the repository at this point in the history
It was previously used only for the resolution selection dialog.
  • Loading branch information
AI0867 committed Jun 16, 2014
1 parent 9e8ee00 commit b815ac9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
15 changes: 9 additions & 6 deletions src/preferences_display.cpp
Expand Up @@ -80,16 +80,19 @@ bool detect_video_settings(CVideo& video, std::pair<int,int>& resolution, int& b
<< resolution.second << 'x' << DefaultBPP << "...\n";

typedef std::pair<int, int> res_t;
std::vector<res_t> res_list;
res_list.push_back(res_t(1024, 768));
res_list.push_back(res_t(1024, 600));
res_list.push_back(res_t(800, 600));
res_list.push_back(res_t(800, 480));
std::vector<res_t> res_list = video.get_available_resolutions();
if (res_list.empty()) {
res_list.push_back(res_t(800, 480));
res_list.push_back(res_t(800, 600));
res_list.push_back(res_t(1024, 600));
res_list.push_back(res_t(1024, 768));
res_list.push_back(res_t(1920, 1080));
}

bpp = video.modePossible(resolution.first, resolution.second,
DefaultBPP, video_flags, true);

BOOST_FOREACH(const res_t &res, res_list)
BOOST_REVERSE_FOREACH(const res_t &res, res_list)
{
if (bpp != 0) break;
std::cerr << "Video mode " << resolution.first << 'x'
Expand Down
14 changes: 8 additions & 6 deletions src/video.cpp
Expand Up @@ -591,11 +591,13 @@ std::vector<std::pair<int, int> > CVideo::get_available_resolutions()
std::vector<std::pair<int, int> > CVideo::get_available_resolutions()
{
std::vector<std::pair<int, int> > result;

SDL_PixelFormat format = *getSurface()->format;
format.BitsPerPixel = getBpp();

const SDL_Rect* const * modes = SDL_ListModes(&format,FULL_SCREEN);
const SDL_Rect* const * modes;
if (const surface& surf = getSurface()) {
SDL_PixelFormat format = *surf->format;
format.BitsPerPixel = getBpp();
modes = SDL_ListModes(&format, FULL_SCREEN);
} else
modes = SDL_ListModes(NULL, FULL_SCREEN);

// The SDL documentation says that a return value of -1
// means that all dimensions are supported/possible.
Expand Down Expand Up @@ -626,7 +628,7 @@ std::vector<std::pair<int, int> > CVideo::get_available_resolutions()

const std::pair<int,int> min_res = std::make_pair(preferences::min_allowed_width(),preferences::min_allowed_height());

if (getSurface()->w >= min_res.first && getSurface()->h >= min_res.second)
if (getSurface() && getSurface()->w >= min_res.first && getSurface()->h >= min_res.second)
result.push_back(std::make_pair(getSurface()->w, getSurface()->h));

for(int i = 0; modes[i] != NULL; ++i) {
Expand Down

0 comments on commit b815ac9

Please sign in to comment.