+#include <cmath>
#include "display.h"
#include "display_private.h"
#include "window.h"
set_mode(*i->desktop_mode, false);
}
-const VideoMode *Display::find_mode(const VideoMode &mode) const
+const VideoMode *Display::find_mode(const VideoMode &mode, float rate_tolerance) const
{
+ const VideoMode *closest = 0;
+ float rate_diff = mode.rate;
for(list<VideoMode>::const_iterator i=modes.begin(); i!=modes.end(); ++i)
{
if(mode.monitor && i->monitor!=mode.monitor)
continue;
- if(mode.rate && i->rate!=mode.rate)
+ if(mode.rate && (i->rate<mode.rate-rate_tolerance || i->rate>mode.rate+rate_tolerance))
continue;
- if(i->width==mode.width && i->height==mode.height)
+ if(i->width!=mode.width || i->height!=mode.height)
+ continue;
+
+ if(mode.rate)
+ {
+ float d = abs(i->rate-mode.rate);
+ if(d<rate_diff)
+ {
+ closest = &*i;
+ rate_diff = d;
+ }
+ }
+ else
return &*i;
}
- return 0;
+ return closest;
}
const VideoMode *Display::find_mode(unsigned width, unsigned height) const
const VideoMode &get_desktop_mode() const;
void set_mode(const VideoMode &, bool = false);
void restore_mode();
- const VideoMode *find_mode(const VideoMode &) const;
+ const VideoMode *find_mode(const VideoMode &, float = 0.5f) const;
const VideoMode *find_mode(unsigned, unsigned) const;
void tick();
VideoMode mode(info->width, info->height);
mode.index = modes.size();
mode.monitor = &monitor;
- mode.rate = info->dotClock/(info->hTotal*info->vTotal);
+ mode.rate = static_cast<float>(info->dotClock)/(info->hTotal*info->vTotal);
if(find_mode(mode))
continue;