D:/Programmation/Cpp/SFML/src/SFML/Window/VideoMode.cpp

00001 
00002 //
00003 // SFML - Simple and Fast Multimedia Library
00004 // Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)
00005 //
00006 // This software is provided 'as-is', without any express or implied warranty.
00007 // In no event will the authors be held liable for any damages arising from the use of this software.
00008 //
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it freely,
00011 // subject to the following restrictions:
00012 //
00013 // 1. The origin of this software must not be misrepresented;
00014 //    you must not claim that you wrote the original software.
00015 //    If you use this software in a product, an acknowledgment
00016 //    in the product documentation would be appreciated but is not required.
00017 //
00018 // 2. Altered source versions must be plainly marked as such,
00019 //    and must not be misrepresented as being the original software.
00020 //
00021 // 3. This notice may not be removed or altered from any source distribution.
00022 //
00024 
00026 // Headers
00028 #include <SFML/Window/VideoMode.hpp>
00029 #include <SFML/Window/VideoModeSupport.hpp>
00030 #include <algorithm>
00031 #include <vector>
00032 
00033 
00037 namespace
00038 {
00039     // Global array of supported video modes
00040     std::vector<sfVideoMode> SupportedModes;
00041 
00042     // Functor for sorting modes from highest to lowest
00043     struct CompareModes
00044     {
00045         bool operator ()(const sfVideoMode& v1, const sfVideoMode& v2) const
00046         {
00047             if (v1.BitsPerPixel > v2.BitsPerPixel)
00048                 return true;
00049             else if (v1.BitsPerPixel < v2.BitsPerPixel)
00050                 return false;
00051             else if (v1.Width > v2.Width)
00052                 return true;
00053             else if (v1.Width < v2.Width)
00054                 return false;
00055             else
00056                 return (v1.Height > v2.Height);
00057         }
00058     };
00059 }
00060 
00061 
00065 sfVideoMode::sfVideoMode() :
00066 Width       (0),
00067 Height      (0),
00068 BitsPerPixel(0)
00069 {
00070 
00071 }
00072 
00073 
00077 sfVideoMode::sfVideoMode(unsigned int ModeWidth, unsigned int ModeHeight, unsigned int ModeBpp) :
00078 Width       (ModeWidth),
00079 Height      (ModeHeight),
00080 BitsPerPixel(ModeBpp)
00081 {
00082 
00083 }
00084 
00085 
00089 sfVideoMode sfVideoMode::GetDesktopMode()
00090 {
00091     // Directly forward to the video mode support
00092     return sf_private::sfVideoModeSupport::GetDesktopVideoMode();
00093 }
00094 
00095 
00100 sfVideoMode sfVideoMode::GetMode(unsigned int Index)
00101 {
00102     if (SupportedModes.empty())
00103         InitializeModes();
00104 
00105     if (Index < GetModesCount())
00106         return SupportedModes[Index];
00107     else
00108         return sfVideoMode();
00109 }
00110 
00111 
00115 unsigned int sfVideoMode::GetModesCount()
00116 {
00117     if (SupportedModes.empty())
00118         InitializeModes();
00119 
00120     return static_cast<int>(SupportedModes.size());
00121 }
00122 
00123 
00127 bool sfVideoMode::IsValid() const
00128 {
00129     if (SupportedModes.empty())
00130         InitializeModes();
00131 
00132     return std::find(SupportedModes.begin(), SupportedModes.end(), *this) != SupportedModes.end();
00133 }
00134 
00135 
00139 bool sfVideoMode::operator ==(const sfVideoMode& Other) const
00140 {
00141     return (Width        == Other.Width)        &&
00142            (Height       == Other.Height)       &&
00143            (BitsPerPixel == Other.BitsPerPixel);
00144 }
00145 
00146 
00150 bool sfVideoMode::operator !=(const sfVideoMode& Other) const
00151 {
00152     return !(*this == Other);
00153 }
00154 
00155 
00159 void sfVideoMode::InitializeModes()
00160 {
00161     // We request the array of valid modes
00162     sf_private::sfVideoModeSupport::GetSupportedVideoModes(SupportedModes);
00163 
00164     // And we sort them from highest to lowest (so that number 0 is the best)
00165     std::sort(SupportedModes.begin(), SupportedModes.end(), CompareModes());
00166 }

Generated for SFML by  doxygen 1.5.2