comparison EXCLUDE/GLTSF/src/Video_Mode.cpp @ 4730:6032ada8b9e5

Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
author dewyatt
date Tue, 25 May 2010 18:53:09 -0400
parents
children
comparison
equal deleted inserted replaced
4464:fa77a6429698 4730:6032ada8b9e5
1 #include "Video_Mode.hpp"
2 #include <vector>
3 #include <algorithm>
4 #define WIN32_LEAN_AND_MEAN
5 #include <Windows.h>
6
7 namespace
8 {
9
10 typedef std::vector<Video_Mode> Video_Mode_List;
11 Video_Mode_List Supported_Modes;
12
13 struct Compare_Modes
14 {
15 bool operator()(const Video_Mode &Mode_1, const Video_Mode &Mode_2) const
16 {
17 if (Mode_1.Bits_Per_Pixel > Mode_2.Bits_Per_Pixel)
18 return true;
19 else if (Mode_1.Bits_Per_Pixel < Mode_2.Bits_Per_Pixel)
20 return false;
21 else if (Mode_1.Width > Mode_2.Width)
22 return true;
23 else if (Mode_1.Width < Mode_2.Width)
24 return false;
25 else
26 return Mode_1.Height > Mode_2.Height;
27 }
28 };
29
30 }
31
32 Video_Mode::Video_Mode() : Width(0),
33 Height(0),
34 Bits_Per_Pixel(0)
35 {
36
37 }
38
39 Video_Mode::Video_Mode(unsigned int The_Width, unsigned int The_Height, unsigned int The_Bits_Per_Pixel)
40 : Width(The_Width),
41 Height(The_Height),
42 Bits_Per_Pixel(The_Bits_Per_Pixel)
43 {
44
45 }
46
47 Video_Mode Video_Mode::Get_Desktop_Mode()
48 {
49 DEVMODE Device_Mode = {0};
50 Device_Mode.dmSize = sizeof(Device_Mode);
51 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &Device_Mode);
52 return Video_Mode(Device_Mode.dmPelsWidth, Device_Mode.dmPelsHeight, Device_Mode.dmBitsPerPel);
53 }
54
55 std::size_t Video_Mode::Get_Mode_Count()
56 {
57 Initialize_Modes();
58 return Supported_Modes.size();
59 }
60
61 Video_Mode Video_Mode::Get_Mode(std::size_t Index)
62 {
63 Initialize_Modes();
64 return Supported_Modes[Index];
65 }
66
67 bool Video_Mode::Is_Valid() const
68 {
69 Initialize_Modes();
70 return Supported_Modes.end() != std::find(Supported_Modes.begin(), Supported_Modes.end(), *this);
71 }
72
73 bool Video_Mode::operator==(const Video_Mode &Mode) const
74 {
75 return (Width == Mode.Width
76 && Height == Mode.Height
77 && Bits_Per_Pixel == Mode.Bits_Per_Pixel);
78 }
79
80 bool Video_Mode::operator!=(const Video_Mode &Mode) const
81 {
82 return !(*this == Mode);
83 }
84
85 void Video_Mode::Initialize_Modes()
86 {
87 static bool Initialized = false;
88 if (!Initialized)
89 {
90 DEVMODE Device_Mode = {0};
91 Device_Mode.dmSize = sizeof(Device_Mode);
92 for (std::size_t i = 0; 0 != EnumDisplaySettings(NULL, i, &Device_Mode); ++i)
93 {
94 Video_Mode Mode(Device_Mode.dmPelsWidth, Device_Mode.dmPelsHeight, Device_Mode.dmBitsPerPel);
95 if (Supported_Modes.end() == std::find(Supported_Modes.begin(), Supported_Modes.end(), Mode))
96 Supported_Modes.push_back(Mode);
97 }
98 std::sort(Supported_Modes.begin(), Supported_Modes.end(), Compare_Modes());
99 }
100 }