annotate EXCLUDE/GLIMM/src/Video_Mode.cpp @ 4745:0aaa54fbd2bc

Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
author dewyatt
date Tue, 06 Jul 2010 02:06:17 -0400
parents bb189d44af16
children
rev   line source
4741
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
1 #include "Video_Mode.hpp"
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
2 #include <vector>
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
3 #include <algorithm>
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
4 #define WIN32_LEAN_AND_MEAN
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
5 #include <Windows.h>
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
6
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
7 namespace
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
8 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
9
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
10 typedef std::vector<Video_Mode> Video_Mode_List;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
11 Video_Mode_List Supported_Modes;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
12
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
13 struct Compare_Modes
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
14 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
15 bool operator()(const Video_Mode &Mode_1, const Video_Mode &Mode_2) const
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
16 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
17 if (Mode_1.Bits_Per_Pixel > Mode_2.Bits_Per_Pixel)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
18 return true;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
19 else if (Mode_1.Bits_Per_Pixel < Mode_2.Bits_Per_Pixel)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
20 return false;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
21 else if (Mode_1.Width > Mode_2.Width)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
22 return true;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
23 else if (Mode_1.Width < Mode_2.Width)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
24 return false;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
25 else
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
26 return Mode_1.Height > Mode_2.Height;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
27 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
28 };
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
29
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
30 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
31
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
32 Video_Mode::Video_Mode() : Width(0),
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
33 Height(0),
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
34 Bits_Per_Pixel(0)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
35 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
36
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
37 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
38
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
39 Video_Mode::Video_Mode(unsigned int The_Width, unsigned int The_Height, unsigned int The_Bits_Per_Pixel)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
40 : Width(The_Width),
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
41 Height(The_Height),
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
42 Bits_Per_Pixel(The_Bits_Per_Pixel)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
43 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
44
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
45 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
46
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
47 Video_Mode Video_Mode::Get_Desktop_Mode()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
48 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
49 DEVMODE Device_Mode = {0};
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
50 Device_Mode.dmSize = sizeof(Device_Mode);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
51 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &Device_Mode);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
52 return Video_Mode(Device_Mode.dmPelsWidth, Device_Mode.dmPelsHeight, Device_Mode.dmBitsPerPel);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
53 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
54
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
55 std::size_t Video_Mode::Get_Mode_Count()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
56 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
57 Initialize_Modes();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
58 return Supported_Modes.size();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
59 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
60
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
61 Video_Mode Video_Mode::Get_Mode(std::size_t Index)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
62 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
63 Initialize_Modes();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
64 return Supported_Modes[Index];
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
65 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
66
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
67 bool Video_Mode::Is_Valid() const
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
68 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
69 Initialize_Modes();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
70 return Supported_Modes.end() != std::find(Supported_Modes.begin(), Supported_Modes.end(), *this);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
71 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
72
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
73 bool Video_Mode::operator==(const Video_Mode &Mode) const
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
74 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
75 return (Width == Mode.Width
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
76 && Height == Mode.Height
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
77 && Bits_Per_Pixel == Mode.Bits_Per_Pixel);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
78 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
79
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
80 bool Video_Mode::operator!=(const Video_Mode &Mode) const
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
81 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
82 return !(*this == Mode);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
83 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
84
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
85 void Video_Mode::Initialize_Modes()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
86 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
87 static bool Initialized = false;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
88 if (!Initialized)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
89 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
90 DEVMODE Device_Mode = {0};
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
91 Device_Mode.dmSize = sizeof(Device_Mode);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
92 for (std::size_t i = 0; 0 != EnumDisplaySettings(NULL, i, &Device_Mode); ++i)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
93 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
94 Video_Mode Mode(Device_Mode.dmPelsWidth, Device_Mode.dmPelsHeight, Device_Mode.dmBitsPerPel);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
95 if (Supported_Modes.end() == std::find(Supported_Modes.begin(), Supported_Modes.end(), Mode))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
96 Supported_Modes.push_back(Mode);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
97 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
98 std::sort(Supported_Modes.begin(), Supported_Modes.end(), Compare_Modes());
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
99 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
100 }