- isCustomResolution = true;
- found = false;
- for (int i = 0; (!found) && (resolutions[i]); i++) {
- if ((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
- isCustomResolution = false;
-
- if ((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight)) {
- i++;
- if (resolutions[i] != NULL) {
- newscreenwidth = (int) resolutions[i]->w;
- newscreenheight = (int) resolutions[i]->h;
- } else if (isCustomResolution) {
- if ((screenwidth == newscreenwidth) && (screenheight == newscreenheight)) {
- newscreenwidth = (int) resolutions[0]->w;
- newscreenheight = (int) resolutions[0]->h;
- } else {
- newscreenwidth = screenwidth;
- newscreenheight = screenheight;
- }
- } else {
- newscreenwidth = (int) resolutions[0]->w;
- newscreenheight = (int) resolutions[0]->h;
- }
- found = true;
- }
- }
-
- if (!found) {
- newscreenwidth = (int) resolutions[0]->w;
- newscreenheight = (int) resolutions[0]->h;
+ newscreenresolution = resolutions.find(make_pair(newscreenwidth, newscreenheight));
+ /* Next one (end() + 1 is also end() so the ++ is safe even if it was not found) */
+ newscreenresolution++;
+ if (newscreenresolution == resolutions.end()) {
+ /* It was the last one (or not found), go back to the beginning */
+ newscreenresolution = resolutions.begin();