00001 00002 // 00003 // SFML - Simple and Fast Multimedia Library 00004 // Copyright (C) 2007-2009 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<sf::VideoMode> supportedModes; 00041 00042 // Functor for sorting modes from highest to lowest 00043 struct CompareModes 00044 { 00045 bool operator ()(const sf::VideoMode& left, const sf::VideoMode& right) const 00046 { 00047 if (left.BitsPerPixel > right.BitsPerPixel) 00048 return true; 00049 else if (left.BitsPerPixel < right.BitsPerPixel) 00050 return false; 00051 else if (left.Width > right.Width) 00052 return true; 00053 else if (left.Width < right.Width) 00054 return false; 00055 else 00056 return (left.Height > right.Height); 00057 } 00058 }; 00059 00060 // Get and sort valid video modes 00061 static void InitializeModes() 00062 { 00063 // We request the array of valid modes 00064 sf::priv::VideoModeSupport::GetSupportedVideoModes(supportedModes); 00065 00066 // And we sort them from highest to lowest (so that number 0 is the best) 00067 std::sort(supportedModes.begin(), supportedModes.end(), CompareModes()); 00068 } 00069 } 00070 00071 00072 namespace sf 00073 { 00075 VideoMode::VideoMode() : 00076 Width (0), 00077 Height (0), 00078 BitsPerPixel(0) 00079 { 00080 00081 } 00082 00083 00085 VideoMode::VideoMode(unsigned int width, unsigned int height, unsigned int bitsPerPixel) : 00086 Width (width), 00087 Height (height), 00088 BitsPerPixel(bitsPerPixel) 00089 { 00090 00091 } 00092 00093 00095 VideoMode VideoMode::GetDesktopMode() 00096 { 00097 // Directly forward to the video mode support 00098 return priv::VideoModeSupport::GetDesktopVideoMode(); 00099 } 00100 00101 00103 VideoMode VideoMode::GetMode(std::size_t index) 00104 { 00105 // Build and cache the list of valid modes on first call 00106 if (supportedModes.empty()) 00107 InitializeModes(); 00108 00109 if (index < GetModesCount()) 00110 return supportedModes[index]; 00111 else 00112 return VideoMode(); 00113 } 00114 00115 00117 std::size_t VideoMode::GetModesCount() 00118 { 00119 // Build and cache the list of valid modes on first call 00120 if (supportedModes.empty()) 00121 InitializeModes(); 00122 00123 return supportedModes.size(); 00124 } 00125 00126 00128 bool VideoMode::IsValid() const 00129 { 00130 // Build and cache the list of valid modes on first call 00131 if (supportedModes.empty()) 00132 InitializeModes(); 00133 00134 return std::find(supportedModes.begin(), supportedModes.end(), *this) != supportedModes.end(); 00135 } 00136 00137 00139 bool operator ==(const VideoMode& left, const VideoMode& right) 00140 { 00141 return (left.Width == right.Width) && 00142 (left.Height == right.Height) && 00143 (left.BitsPerPixel == right.BitsPerPixel); 00144 } 00145 00146 00148 bool operator !=(const VideoMode& left, const VideoMode& right) 00149 { 00150 return !(left == right); 00151 } 00152 00153 } // namespace sf
:: Copyright © 2007-2008 Laurent Gomila, all rights reserved :: Documentation generated by doxygen 1.5.2 ::