00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024
00026
00028 #include <SFML/Window/VideoMode.hpp>
00029 #include <SFML/Window/VideoModeSupport.hpp>
00030 #include <algorithm>
00031 #include <vector>
00032
00033
00037 namespace
00038 {
00039
00040 std::vector<sfVideoMode> SupportedModes;
00041
00042
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
00092 return sf_private::sfVideoModeSupport::GetDesktopVideoMode();
00093 }
00094
00095
00100 sfVideoMode sfVideoMode::GetMode(std::size_t 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 std::size_t sfVideoMode::GetModesCount()
00116 {
00117 if (SupportedModes.empty())
00118 InitializeModes();
00119
00120 return 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
00162 sf_private::sfVideoModeSupport::GetSupportedVideoModes(SupportedModes);
00163
00164
00165 std::sort(SupportedModes.begin(), SupportedModes.end(), CompareModes());
00166 }