Mercurial > sdl-ios-xcode
annotate EXCLUDE/GLTSF/src/Video_Mode.cpp @ 4734:0c7c67d4e6ee
Added On_Char method to Window_Listener for WM_CHAR messages.
Removed a lot of TSF code because part of it was wrong and part was too complicated.
Added Clear method to clear the window.
IME input should work in both windowed mode and fullscreen mode with these changes.
I have tested on Windows XP SP3 and Windows 7 Ultimate in VirtualBox.
When you type a character (with an IME or not), the console will show the code point as U+XXXX.
You use Left Alt+Shift (or whatever you have it set to) to switch input languages as usual.
Hit ESC to exit (or close the window in windowed mode).
The program will pause before exiting so you can review the console output (press a key to exit).
author | dewyatt |
---|---|
date | Wed, 09 Jun 2010 00:03:54 -0400 |
parents | 6032ada8b9e5 |
children |
rev | line source |
---|---|
4730
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
1 #include "Video_Mode.hpp" |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
2 #include <vector> |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
3 #include <algorithm> |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
4 #define WIN32_LEAN_AND_MEAN |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
5 #include <Windows.h> |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
6 |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
7 namespace |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
8 { |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
9 |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
10 typedef std::vector<Video_Mode> Video_Mode_List; |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
11 Video_Mode_List Supported_Modes; |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
12 |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
13 struct Compare_Modes |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
14 { |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
15 bool operator()(const Video_Mode &Mode_1, const Video_Mode &Mode_2) const |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
16 { |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
17 if (Mode_1.Bits_Per_Pixel > Mode_2.Bits_Per_Pixel) |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
18 return true; |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
19 else if (Mode_1.Bits_Per_Pixel < Mode_2.Bits_Per_Pixel) |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
20 return false; |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
21 else if (Mode_1.Width > Mode_2.Width) |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
22 return true; |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
23 else if (Mode_1.Width < Mode_2.Width) |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
24 return false; |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
25 else |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
26 return Mode_1.Height > Mode_2.Height; |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
27 } |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
28 }; |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
29 |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
30 } |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
31 |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
32 Video_Mode::Video_Mode() : Width(0), |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
33 Height(0), |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
34 Bits_Per_Pixel(0) |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
35 { |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
36 |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
37 } |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
38 |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
39 Video_Mode::Video_Mode(unsigned int The_Width, unsigned int The_Height, unsigned int The_Bits_Per_Pixel) |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
40 : Width(The_Width), |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
41 Height(The_Height), |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
42 Bits_Per_Pixel(The_Bits_Per_Pixel) |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
43 { |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
44 |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
45 } |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
46 |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
47 Video_Mode Video_Mode::Get_Desktop_Mode() |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
48 { |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
49 DEVMODE Device_Mode = {0}; |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
50 Device_Mode.dmSize = sizeof(Device_Mode); |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
51 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &Device_Mode); |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
52 return Video_Mode(Device_Mode.dmPelsWidth, Device_Mode.dmPelsHeight, Device_Mode.dmBitsPerPel); |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
53 } |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
54 |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
55 std::size_t Video_Mode::Get_Mode_Count() |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
56 { |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
57 Initialize_Modes(); |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
58 return Supported_Modes.size(); |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
59 } |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
60 |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
61 Video_Mode Video_Mode::Get_Mode(std::size_t Index) |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
62 { |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
63 Initialize_Modes(); |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
64 return Supported_Modes[Index]; |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
65 } |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
66 |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
67 bool Video_Mode::Is_Valid() const |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
68 { |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
69 Initialize_Modes(); |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
70 return Supported_Modes.end() != std::find(Supported_Modes.begin(), Supported_Modes.end(), *this); |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
71 } |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
72 |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
73 bool Video_Mode::operator==(const Video_Mode &Mode) const |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
74 { |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
75 return (Width == Mode.Width |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
76 && Height == Mode.Height |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
77 && Bits_Per_Pixel == Mode.Bits_Per_Pixel); |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
78 } |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
79 |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
80 bool Video_Mode::operator!=(const Video_Mode &Mode) const |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
81 { |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
82 return !(*this == Mode); |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
83 } |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
84 |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
85 void Video_Mode::Initialize_Modes() |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
86 { |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
87 static bool Initialized = false; |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
88 if (!Initialized) |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
89 { |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
90 DEVMODE Device_Mode = {0}; |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
91 Device_Mode.dmSize = sizeof(Device_Mode); |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
92 for (std::size_t i = 0; 0 != EnumDisplaySettings(NULL, i, &Device_Mode); ++i) |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
93 { |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
94 Video_Mode Mode(Device_Mode.dmPelsWidth, Device_Mode.dmPelsHeight, Device_Mode.dmBitsPerPel); |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
95 if (Supported_Modes.end() == std::find(Supported_Modes.begin(), Supported_Modes.end(), Mode)) |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
96 Supported_Modes.push_back(Mode); |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
97 } |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
98 std::sort(Supported_Modes.begin(), Supported_Modes.end(), Compare_Modes()); |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
99 } |
6032ada8b9e5
Adding GLTSF (somewhat based on SFML, no actual TSF code yet)
dewyatt
parents:
diff
changeset
|
100 } |