annotate EXCLUDE/GLIMM/src/Window.cpp @ 4742:59b0750575b1

Added Get_IMM method to Window. Added focus gain/loss events for IMM.
author dewyatt
date Sun, 04 Jul 2010 06:07:38 -0400
parents bb189d44af16
children 0aaa54fbd2bc
rev   line source
4741
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
1 #include "Window.hpp"
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
2 #include <gl/GL.h>
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
3
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
4 #pragma comment(lib, "opengl32.lib")
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
5
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
6 const wchar_t *Window::Window_Class_Name = L"GLTSF";
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
7
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
8 Window::Window() : my_Handle(0),
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
9 my_Device_Context(0),
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
10 my_GL_Context(0),
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
11 my_Class_Registered(false),
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
12 my_Listener(0)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
13 {
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 }
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 Window::~Window()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
18 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
19 Finalize();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
20 Show_Cursor();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
21 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
22
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
23 void Window::Initialize(const std::wstring &Title, const Video_Mode &Mode, bool Fullscreen)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
24 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
25 Finalize();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
26
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
27 my_Video_Mode = Mode;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
28 if (!my_Video_Mode.Is_Valid())
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
29 throw std::runtime_error("Invalid video mode");
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 my_Fullscreen = Fullscreen;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
32 Register_Class();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
33 Create_Window(Title, Mode, Fullscreen);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
34 my_IMM.Initialize(my_Handle);
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 void Window::Finalize()
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 my_IMM.Finalize();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
40 Destroy_Window();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
41 Unregister_Class();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
42 }
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 void Window::Set_Listener(Window_Listener *Listener)
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 my_Listener = Listener;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
47 }
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 void Window::Show()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
50 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
51 if (my_Handle)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
52 ShowWindow(my_Handle, SW_SHOW);
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 void Window::Hide()
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 if (my_Handle)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
58 ShowWindow(my_Handle, SW_HIDE);
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 void Window::Handle_Events()
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 MSG Message = {0};
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
64 while (PeekMessageW(&Message, NULL, 0, 0, PM_REMOVE))
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 TranslateMessage(&Message);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
67 DispatchMessageW(&Message);
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 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
70
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
71 void Window::Display()
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 if (my_Device_Context && my_GL_Context)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
74 SwapBuffers(my_Device_Context);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
75 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
76
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
77 void Window::Show_Cursor()
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 ShowCursor(TRUE);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
80 }
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 void Window::Hide_Cursor()
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 ShowCursor(FALSE);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
85 }
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 HWND Window::Get_Handle()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
88 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
89 return my_Handle;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
90 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
91
4742
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
92 IMM & Window::Get_IMM()
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
93 {
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
94 return my_IMM;
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
95 }
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
96
4741
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
97 void Window::Register_Class()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
98 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
99 WNDCLASSEXW Window_Class = {0};
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
100 Window_Class.cbSize = sizeof(Window_Class);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
101 Window_Class.style = 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
102 Window_Class.lpfnWndProc = &Window::Window_Procedure;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
103 Window_Class.cbClsExtra = 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
104 Window_Class.cbWndExtra = 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
105 Window_Class.hInstance = GetModuleHandle(NULL);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
106 Window_Class.hIcon = NULL;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
107 Window_Class.hCursor = NULL;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
108 Window_Class.hbrBackground = NULL;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
109 Window_Class.lpszMenuName = NULL;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
110 Window_Class.lpszClassName = Window_Class_Name;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
111 Window_Class.hIconSm = NULL;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
112 if (0 == RegisterClassExW(&Window_Class))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
113 throw std::runtime_error("Failed to register window class");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
114
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
115 my_Class_Registered = true;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
116 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
117
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
118 void Window::Unregister_Class()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
119 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
120 if (my_Class_Registered)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
121 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
122 if (0 == UnregisterClassW(Window_Class_Name, GetModuleHandle(NULL)))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
123 printf("Warning: Failed to unregister window class\n");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
124
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
125 my_Class_Registered = false;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
126 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
127 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
128
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
129 void Window::Create_Window(const std::wstring &Title, const Video_Mode &Mode, bool Fullscreen)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
130 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
131 HDC Screen_DC = GetDC(NULL);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
132 int Left = (GetDeviceCaps(Screen_DC, HORZRES) - my_Video_Mode.Width) / 2;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
133 int Top = (GetDeviceCaps(Screen_DC, VERTRES) - my_Video_Mode.Height) / 2;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
134 int Width = my_Video_Mode.Width;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
135 int Height = my_Video_Mode.Height;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
136 ReleaseDC(NULL, Screen_DC);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
137
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
138 DWORD Style = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
139 if (!my_Fullscreen)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
140 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
141 RECT Rect = {0, 0, Width, Height};
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
142 AdjustWindowRect(&Rect, Style, false);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
143 Width = Rect.right - Rect.left;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
144 Height = Rect.bottom - Rect.top;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
145 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
146 my_Handle = CreateWindowW(Window_Class_Name, Title.c_str(), Style, Left, Top, Width, Height, NULL, NULL, GetModuleHandle(NULL), this);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
147 if (!my_Handle)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
148 throw std::runtime_error("Failed to create window");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
149
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
150 if (Fullscreen)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
151 Switch_To_Fullscreen(Mode);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
152
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
153 Create_Context(Mode);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
154
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
155 RECT Rect = {0};
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
156 GetClientRect(my_Handle, &Rect);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
157 //TODO: ...
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
158 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
159
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
160 void Window::Destroy_Window()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
161 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
162 Destroy_Context();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
163 if (my_Handle)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
164 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
165 DestroyWindow(my_Handle);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
166 my_Handle = 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
167
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
168 if (my_Fullscreen)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
169 ChangeDisplaySettings(NULL, 0);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
170 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
171 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
172
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
173 void Window::Create_Context(const Video_Mode &Mode)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
174 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
175 my_Device_Context = GetDC(my_Handle);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
176 if (!my_Device_Context)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
177 throw std::runtime_error("Failed to get device context");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
178
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
179 PIXELFORMATDESCRIPTOR Pixel_Descriptor = {0};
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
180 Pixel_Descriptor.nSize = sizeof(Pixel_Descriptor);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
181 Pixel_Descriptor.nVersion = 1;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
182 Pixel_Descriptor.iLayerType = PFD_MAIN_PLANE;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
183 Pixel_Descriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
184 Pixel_Descriptor.iPixelType = PFD_TYPE_RGBA;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
185 Pixel_Descriptor.cColorBits = static_cast<BYTE>(Mode.Bits_Per_Pixel);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
186 Pixel_Descriptor.cDepthBits = 24;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
187 Pixel_Descriptor.cStencilBits = 8;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
188 Pixel_Descriptor.cAlphaBits = Mode.Bits_Per_Pixel == 32 ? 8 : 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
189
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
190 int Best_Format = ChoosePixelFormat(my_Device_Context, &Pixel_Descriptor);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
191 if (0 == Best_Format)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
192 throw std::runtime_error("Failed to find suitable pixel format");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
193
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
194 PIXELFORMATDESCRIPTOR Actual_Format = {0};
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
195 Actual_Format.nSize = sizeof(Actual_Format);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
196 Actual_Format.nVersion = 1;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
197 DescribePixelFormat(my_Device_Context, Best_Format, sizeof(Actual_Format), &Actual_Format);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
198 if (!SetPixelFormat(my_Device_Context, Best_Format, &Actual_Format))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
199 throw std::runtime_error("Failed to set device pixel format");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
200
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
201 my_GL_Context = wglCreateContext(my_Device_Context);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
202 if (!my_GL_Context)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
203 throw std::runtime_error("Failed to create OpenGL context");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
204
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
205 wglMakeCurrent(my_Device_Context, my_GL_Context);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
206 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
207
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
208 void Window::Destroy_Context()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
209 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
210 if (my_GL_Context)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
211 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
212 wglDeleteContext(my_GL_Context);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
213 my_GL_Context = 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
214 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
215 if (my_Device_Context)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
216 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
217 ReleaseDC(my_Handle, my_Device_Context);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
218 my_Device_Context = 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
219 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
220 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
221
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
222 void Window::Switch_To_Fullscreen(const Video_Mode &Mode)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
223 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
224 DEVMODE Device_Mode = {0};
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
225 Device_Mode.dmSize = sizeof(Device_Mode);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
226 Device_Mode.dmPelsWidth = Mode.Width;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
227 Device_Mode.dmPelsHeight = Mode.Height;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
228 Device_Mode.dmBitsPerPel = Mode.Bits_Per_Pixel;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
229 Device_Mode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
230
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
231 if (DISP_CHANGE_SUCCESSFUL != ChangeDisplaySettings(&Device_Mode, CDS_FULLSCREEN))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
232 throw std::runtime_error("Failed to change to fullscreen mode");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
233
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
234 SetWindowLong(my_Handle, GWL_STYLE, WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
235 SetWindowLong(my_Handle, GWL_EXSTYLE, WS_EX_APPWINDOW);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
236
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
237 SetWindowPos(my_Handle, HWND_TOP, 0, 0, Mode.Width, Mode.Height, SWP_FRAMECHANGED);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
238 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
239
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
240 LRESULT CALLBACK Window::Window_Procedure(HWND Handle, UINT Message, WPARAM wParam, LPARAM lParam)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
241 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
242 switch (Message)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
243 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
244 case WM_CREATE:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
245 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
246 LONG This = reinterpret_cast<LONG>(reinterpret_cast<CREATESTRUCT *>(lParam)->lpCreateParams);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
247 SetWindowLongPtr(Handle, GWLP_USERDATA, This);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
248 return 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
249 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
250 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
251 case WM_DESTROY:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
252 PostQuitMessage(0);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
253 return 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
254 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
255 default:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
256 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
257 Window* Win = reinterpret_cast<Window *>(GetWindowLongPtr(Handle, GWLP_USERDATA));
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
258 if (Win)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
259 return Win->Handle_Message(Handle, Message, wParam, lParam);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
260 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
261 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
262 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
263 return DefWindowProcW(Handle, Message, wParam, lParam);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
264 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
265
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
266 #define Call_Listener(x)\
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
267 if (my_Listener) my_Listener->x
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
268
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
269 LRESULT Window::Handle_Message(HWND Handle, UINT Message, WPARAM wParam, LPARAM lParam)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
270 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
271 bool IMM_Message = false;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
272 LRESULT Result = my_IMM.Handle_Message(Handle, Message, wParam, lParam, IMM_Message);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
273 if (IMM_Message)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
274 return Result;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
275
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
276 switch (Message)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
277 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
278 case WM_SIZE:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
279 Call_Listener(On_Resized(LOWORD(lParam), HIWORD(lParam)));
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
280 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
281 case WM_CLOSE:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
282 Call_Listener(On_Close());
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
283 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
284 case WM_KEYDOWN:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
285 Call_Listener(On_Key_Down(wParam));
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
286 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
287 case WM_KEYUP:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
288 Call_Listener(On_Key_Up(wParam));
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
289 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
290 case WM_CHAR:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
291 Call_Listener(On_Char(wParam));
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
292 break;
4742
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
293 case WM_SETFOCUS:
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
294 my_IMM.Focus_Gained();
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
295 break;
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
296 case WM_KILLFOCUS:
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
297 my_IMM.Focus_Lost();
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
298 break;
4741
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
299 default:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
300 return DefWindowProcW(Handle, Message, wParam, lParam);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
301 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
302 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
303 return 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
304 }