|
|
|
@ -28,6 +28,7 @@
|
|
|
|
|
#include "../thread.h"
|
|
|
|
|
#include "allegro_v.h"
|
|
|
|
|
#include <allegro.h>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
#include "../safeguards.h"
|
|
|
|
|
|
|
|
|
@ -139,34 +140,25 @@ static void GetVideoModes()
|
|
|
|
|
* cards ourselves... and we need a card to get the modes. */
|
|
|
|
|
set_gfx_mode(_fullscreen ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
|
|
|
|
|
|
|
|
|
|
_resolutions.clear();
|
|
|
|
|
|
|
|
|
|
GFX_MODE_LIST *mode_list = get_gfx_mode_list(gfx_driver->id);
|
|
|
|
|
if (mode_list == nullptr) {
|
|
|
|
|
memcpy(_resolutions, default_resolutions, sizeof(default_resolutions));
|
|
|
|
|
_num_resolutions = lengthof(default_resolutions);
|
|
|
|
|
_resolutions.assign(std::begin(default_resolutions), std::end(default_resolutions));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GFX_MODE *modes = mode_list->mode;
|
|
|
|
|
|
|
|
|
|
int n = 0;
|
|
|
|
|
for (int i = 0; modes[i].bpp != 0; i++) {
|
|
|
|
|
uint w = modes[i].width;
|
|
|
|
|
uint h = modes[i].height;
|
|
|
|
|
if (w >= 640 && h >= 480) {
|
|
|
|
|
int j;
|
|
|
|
|
for (j = 0; j < n; j++) {
|
|
|
|
|
if (_resolutions[j].width == w && _resolutions[j].height == h) break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (j == n) {
|
|
|
|
|
_resolutions[j].width = w;
|
|
|
|
|
_resolutions[j].height = h;
|
|
|
|
|
if (++n == lengthof(_resolutions)) break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (w < 640 || h < 480) continue;
|
|
|
|
|
if (std::find(_resolutions.begin(), _resolutions.end(), Dimension(w, h)) != _resolutions.end()) continue;
|
|
|
|
|
_resolutions.emplace_back(w, h);
|
|
|
|
|
}
|
|
|
|
|
_num_resolutions = n;
|
|
|
|
|
SortResolutions(_num_resolutions);
|
|
|
|
|
|
|
|
|
|
SortResolutions();
|
|
|
|
|
|
|
|
|
|
destroy_gfx_mode_list(mode_list);
|
|
|
|
|
}
|
|
|
|
@ -174,17 +166,15 @@ static void GetVideoModes()
|
|
|
|
|
static void GetAvailableVideoMode(uint *w, uint *h)
|
|
|
|
|
{
|
|
|
|
|
/* No video modes, so just try it and see where it ends */
|
|
|
|
|
if (_num_resolutions == 0) return;
|
|
|
|
|
if (_resolutions.empty()) return;
|
|
|
|
|
|
|
|
|
|
/* is the wanted mode among the available modes? */
|
|
|
|
|
for (int i = 0; i != _num_resolutions; i++) {
|
|
|
|
|
if (*w == _resolutions[i].width && *h == _resolutions[i].height) return;
|
|
|
|
|
}
|
|
|
|
|
if (std::find(_resolutions.begin(), _resolutions.end(), Dimension(*w, *h)) != _resolutions.end()) return;
|
|
|
|
|
|
|
|
|
|
/* use the closest possible resolution */
|
|
|
|
|
int best = 0;
|
|
|
|
|
uint best = 0;
|
|
|
|
|
uint delta = Delta(_resolutions[0].width, *w) * Delta(_resolutions[0].height, *h);
|
|
|
|
|
for (int i = 1; i != _num_resolutions; ++i) {
|
|
|
|
|
for (uint i = 1; i != _resolutions.size(); ++i) {
|
|
|
|
|
uint newdelta = Delta(_resolutions[i].width, *w) * Delta(_resolutions[i].height, *h);
|
|
|
|
|
if (newdelta < delta) {
|
|
|
|
|
best = i;
|
|
|
|
@ -545,7 +535,7 @@ bool VideoDriver_Allegro::ToggleFullscreen(bool fullscreen)
|
|
|
|
|
{
|
|
|
|
|
_fullscreen = fullscreen;
|
|
|
|
|
GetVideoModes(); // get the list of available video modes
|
|
|
|
|
if (_num_resolutions == 0 || !this->ChangeResolution(_cur_resolution.width, _cur_resolution.height)) {
|
|
|
|
|
if (_resolutions.empty() || !this->ChangeResolution(_cur_resolution.width, _cur_resolution.height)) {
|
|
|
|
|
/* switching resolution failed, put back full_screen to original status */
|
|
|
|
|
_fullscreen ^= true;
|
|
|
|
|
return false;
|
|
|
|
|