Helper function for videomodelist.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1736 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2008-11-13 22:23:31 +00:00
parent ef33d9b051
commit 120e86226c
4 changed files with 51 additions and 0 deletions

View File

@ -33,6 +33,13 @@ namespace video
\return Size of screen in pixels of the specified video mode. */ \return Size of screen in pixels of the specified video mode. */
virtual core::dimension2d<s32> getVideoModeResolution(s32 modeNumber) const = 0; virtual core::dimension2d<s32> getVideoModeResolution(s32 modeNumber) const = 0;
//! Get a supported screen size with certain constraints.
/** \param minSize: Minimum dimensions required.
\param maxSize: Maximum dimensions allowed.
\return Size of screen in pixels which matches the requirements.
as good as possible. */
virtual core::dimension2d<s32> getVideoModeResolution(const core::dimension2d<s32>& minSize, const core::dimension2d<s32>& maxSize) const = 0;
//! Get the pixel depth of a video mode in bits. //! Get the pixel depth of a video mode in bits.
/** \param modeNumber: zero based index of the video mode. /** \param modeNumber: zero based index of the video mode.
\return Size of each pixel of the specified video mode in bits. */ \return Size of each pixel of the specified video mode in bits. */

View File

@ -8,6 +8,7 @@
#include "IrrCompileConfig.h" #include "IrrCompileConfig.h"
#include "irrTypes.h" #include "irrTypes.h"
#include <math.h> #include <math.h>
#include <stdlib.h> // for abs() etc.
#if defined(_IRR_SOLARIS_PLATFORM_) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) || defined (_WIN32_WCE) #if defined(_IRR_SOLARIS_PLATFORM_) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) || defined (_WIN32_WCE)
#define sqrtf(X) (f32)sqrt((f64)(X)) #define sqrtf(X) (f32)sqrt((f64)(X))

View File

@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in irrlicht.h // For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CVideoModeList.h" #include "CVideoModeList.h"
#include "irrMath.h"
namespace irr namespace irr
{ {
@ -45,6 +46,45 @@ core::dimension2d<s32> CVideoModeList::getVideoModeResolution(s32 modeNumber) co
} }
core::dimension2d<s32> CVideoModeList::getVideoModeResolution(
const core::dimension2d<s32>& minSize,
const core::dimension2d<s32>& maxSize) const
{
u32 best=VideoModes.size();
// if only one or no mode
if (best<2)
return getVideoModeResolution(0);
u32 i;
for (i=0; i<VideoModes.size(); ++i)
{
if (VideoModes[i].size.Width>=minSize.Width &&
VideoModes[i].size.Height>=minSize.Height &&
VideoModes[i].size.Width<=maxSize.Width &&
VideoModes[i].size.Height<=maxSize.Height)
best=i;
}
// we take the last one found, the largest one fitting
if (best<VideoModes.size())
return VideoModes[best].size;
const u32 minArea = minSize.getArea();
const u32 maxArea = maxSize.getArea();
u32 minDist = 0xffffffff;
best=0;
for (i=0; i<VideoModes.size(); ++i)
{
const u32 area = VideoModes[i].size.getArea();
const u32 dist = core::min_(abs(minArea-area), abs(maxArea-area));
if (dist<minDist)
{
minDist=dist;
best=i;
}
}
return VideoModes[best].size;
}
//! Returns the pixel depth of a video mode in bits. //! Returns the pixel depth of a video mode in bits.
s32 CVideoModeList::getVideoModeDepth(s32 modeNumber) const s32 CVideoModeList::getVideoModeDepth(s32 modeNumber) const
{ {

View File

@ -27,6 +27,9 @@ namespace video
//! Returns the screen size of a video mode in pixels. //! Returns the screen size of a video mode in pixels.
virtual core::dimension2d<s32> getVideoModeResolution(s32 modeNumber) const; virtual core::dimension2d<s32> getVideoModeResolution(s32 modeNumber) const;
//! Returns the screen size of an optimal video mode in pixels.
virtual core::dimension2d<s32> getVideoModeResolution(const core::dimension2d<s32>& minSize, const core::dimension2d<s32>& maxSize) const;
//! Returns the pixel depth of a video mode in bits. //! Returns the pixel depth of a video mode in bits.
virtual s32 getVideoModeDepth(s32 modeNumber) const; virtual s32 getVideoModeDepth(s32 modeNumber) const;