From: Mikko Rasa Date: Tue, 20 Oct 2015 16:31:41 +0000 (+0300) Subject: Use float rather than unsigned for refresh rate X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=9ffb9f22faf7c540083e6df828500d54aabcbb56;p=libs%2Fgui.git Use float rather than unsigned for refresh rate Display::set_mode now accepts a rate which is within +-0.5 Hz of requested and chooses the closest match if there are more than one. --- diff --git a/source/graphics/display.cpp b/source/graphics/display.cpp index de5a069..40112a3 100644 --- a/source/graphics/display.cpp +++ b/source/graphics/display.cpp @@ -1,3 +1,4 @@ +#include #include "display.h" #include "display_private.h" #include "window.h" @@ -31,19 +32,33 @@ void Display::restore_mode() 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::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->raterate>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(dwidth, info->height); mode.index = modes.size(); mode.monitor = &monitor; - mode.rate = info->dotClock/(info->hTotal*info->vTotal); + mode.rate = static_cast(info->dotClock)/(info->hTotal*info->vTotal); if(find_mode(mode)) continue;