annotate EXCLUDE/GLIMM/src/Window.cpp @ 4748:d1ce08e2697f

Added missing line to make things compile.
author dewyatt
date Tue, 06 Jul 2010 03:27:22 -0400
parents 0aaa54fbd2bc
children
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);
4745
0aaa54fbd2bc Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents: 4742
diff changeset
34 Show();
4741
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
35 my_IMM.Initialize(my_Handle);
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 void Window::Finalize()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
39 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
40 my_IMM.Finalize();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
41 Destroy_Window();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
42 Unregister_Class();
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 void Window::Set_Listener(Window_Listener *Listener)
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 my_Listener = Listener;
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
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
50 void Window::Show()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
51 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
52 if (my_Handle)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
53 ShowWindow(my_Handle, SW_SHOW);
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
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
56 void Window::Hide()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
57 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
58 if (my_Handle)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
59 ShowWindow(my_Handle, SW_HIDE);
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
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
62 void Window::Handle_Events()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
63 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
64 MSG Message = {0};
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
65 while (PeekMessageW(&Message, NULL, 0, 0, PM_REMOVE))
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 TranslateMessage(&Message);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
68 DispatchMessageW(&Message);
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
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
72 void Window::Display()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
73 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
74 if (my_Device_Context && my_GL_Context)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
75 SwapBuffers(my_Device_Context);
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
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
78 void Window::Show_Cursor()
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 ShowCursor(TRUE);
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
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
83 void Window::Hide_Cursor()
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 ShowCursor(FALSE);
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
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
88 HWND Window::Get_Handle()
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 return my_Handle;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
91 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
92
4742
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
93 IMM & Window::Get_IMM()
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
94 {
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
95 return my_IMM;
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
96 }
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
97
4741
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
98 void Window::Register_Class()
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 WNDCLASSEXW Window_Class = {0};
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
101 Window_Class.cbSize = sizeof(Window_Class);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
102 Window_Class.style = 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
103 Window_Class.lpfnWndProc = &Window::Window_Procedure;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
104 Window_Class.cbClsExtra = 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
105 Window_Class.cbWndExtra = 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
106 Window_Class.hInstance = GetModuleHandle(NULL);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
107 Window_Class.hIcon = NULL;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
108 Window_Class.hCursor = NULL;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
109 Window_Class.hbrBackground = NULL;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
110 Window_Class.lpszMenuName = NULL;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
111 Window_Class.lpszClassName = Window_Class_Name;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
112 Window_Class.hIconSm = NULL;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
113 if (0 == RegisterClassExW(&Window_Class))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
114 throw std::runtime_error("Failed to register window class");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
115
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
116 my_Class_Registered = true;
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
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
119 void Window::Unregister_Class()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
120 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
121 if (my_Class_Registered)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
122 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
123 if (0 == UnregisterClassW(Window_Class_Name, GetModuleHandle(NULL)))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
124 printf("Warning: Failed to unregister window class\n");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
125
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
126 my_Class_Registered = false;
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
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
130 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
131 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
132 HDC Screen_DC = GetDC(NULL);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
133 int Left = (GetDeviceCaps(Screen_DC, HORZRES) - my_Video_Mode.Width) / 2;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
134 int Top = (GetDeviceCaps(Screen_DC, VERTRES) - my_Video_Mode.Height) / 2;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
135 int Width = my_Video_Mode.Width;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
136 int Height = my_Video_Mode.Height;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
137 ReleaseDC(NULL, Screen_DC);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
138
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
139 DWORD Style = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
140 if (!my_Fullscreen)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
141 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
142 RECT Rect = {0, 0, Width, Height};
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
143 AdjustWindowRect(&Rect, Style, false);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
144 Width = Rect.right - Rect.left;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
145 Height = Rect.bottom - Rect.top;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
146 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
147 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
148 if (!my_Handle)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
149 throw std::runtime_error("Failed to create window");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
150
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
151 if (Fullscreen)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
152 Switch_To_Fullscreen(Mode);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
153
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
154 Create_Context(Mode);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
155
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
156 RECT Rect = {0};
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
157 GetClientRect(my_Handle, &Rect);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
158 //TODO: ...
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
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
161 void Window::Destroy_Window()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
162 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
163 Destroy_Context();
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
164 if (my_Handle)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
165 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
166 DestroyWindow(my_Handle);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
167 my_Handle = 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
168
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
169 if (my_Fullscreen)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
170 ChangeDisplaySettings(NULL, 0);
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
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
174 void Window::Create_Context(const Video_Mode &Mode)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
175 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
176 my_Device_Context = GetDC(my_Handle);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
177 if (!my_Device_Context)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
178 throw std::runtime_error("Failed to get device context");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
179
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
180 PIXELFORMATDESCRIPTOR Pixel_Descriptor = {0};
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
181 Pixel_Descriptor.nSize = sizeof(Pixel_Descriptor);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
182 Pixel_Descriptor.nVersion = 1;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
183 Pixel_Descriptor.iLayerType = PFD_MAIN_PLANE;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
184 Pixel_Descriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
185 Pixel_Descriptor.iPixelType = PFD_TYPE_RGBA;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
186 Pixel_Descriptor.cColorBits = static_cast<BYTE>(Mode.Bits_Per_Pixel);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
187 Pixel_Descriptor.cDepthBits = 24;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
188 Pixel_Descriptor.cStencilBits = 8;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
189 Pixel_Descriptor.cAlphaBits = Mode.Bits_Per_Pixel == 32 ? 8 : 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
190
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
191 int Best_Format = ChoosePixelFormat(my_Device_Context, &Pixel_Descriptor);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
192 if (0 == Best_Format)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
193 throw std::runtime_error("Failed to find suitable pixel format");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
194
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
195 PIXELFORMATDESCRIPTOR Actual_Format = {0};
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
196 Actual_Format.nSize = sizeof(Actual_Format);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
197 Actual_Format.nVersion = 1;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
198 DescribePixelFormat(my_Device_Context, Best_Format, sizeof(Actual_Format), &Actual_Format);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
199 if (!SetPixelFormat(my_Device_Context, Best_Format, &Actual_Format))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
200 throw std::runtime_error("Failed to set device pixel format");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
201
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
202 my_GL_Context = wglCreateContext(my_Device_Context);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
203 if (!my_GL_Context)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
204 throw std::runtime_error("Failed to create OpenGL context");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
205
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
206 wglMakeCurrent(my_Device_Context, my_GL_Context);
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
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
209 void Window::Destroy_Context()
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
210 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
211 if (my_GL_Context)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
212 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
213 wglDeleteContext(my_GL_Context);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
214 my_GL_Context = 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
215 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
216 if (my_Device_Context)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
217 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
218 ReleaseDC(my_Handle, my_Device_Context);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
219 my_Device_Context = 0;
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
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
223 void Window::Switch_To_Fullscreen(const Video_Mode &Mode)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
224 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
225 DEVMODE Device_Mode = {0};
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
226 Device_Mode.dmSize = sizeof(Device_Mode);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
227 Device_Mode.dmPelsWidth = Mode.Width;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
228 Device_Mode.dmPelsHeight = Mode.Height;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
229 Device_Mode.dmBitsPerPel = Mode.Bits_Per_Pixel;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
230 Device_Mode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
231
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
232 if (DISP_CHANGE_SUCCESSFUL != ChangeDisplaySettings(&Device_Mode, CDS_FULLSCREEN))
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
233 throw std::runtime_error("Failed to change to fullscreen mode");
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
234
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
235 SetWindowLong(my_Handle, GWL_STYLE, WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
236 SetWindowLong(my_Handle, GWL_EXSTYLE, WS_EX_APPWINDOW);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
237
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
238 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
239 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
240
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
241 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
242 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
243 switch (Message)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
244 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
245 case WM_CREATE:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
246 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
247 LONG This = reinterpret_cast<LONG>(reinterpret_cast<CREATESTRUCT *>(lParam)->lpCreateParams);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
248 SetWindowLongPtr(Handle, GWLP_USERDATA, This);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
249 return 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
250 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
251 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
252 case WM_DESTROY:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
253 PostQuitMessage(0);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
254 return 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
255 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
256 default:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
257 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
258 Window* Win = reinterpret_cast<Window *>(GetWindowLongPtr(Handle, GWLP_USERDATA));
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
259 if (Win)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
260 return Win->Handle_Message(Handle, Message, wParam, lParam);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
261 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
262 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
263 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
264 return DefWindowProcW(Handle, Message, wParam, lParam);
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
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
267 #define Call_Listener(x)\
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
268 if (my_Listener) my_Listener->x
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
269
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
270 LRESULT Window::Handle_Message(HWND Handle, UINT Message, WPARAM wParam, LPARAM lParam)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
271 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
272 bool IMM_Message = false;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
273 LRESULT Result = my_IMM.Handle_Message(Handle, Message, wParam, lParam, IMM_Message);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
274 if (IMM_Message)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
275 return Result;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
276
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
277 switch (Message)
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
278 {
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
279 case WM_SIZE:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
280 Call_Listener(On_Resized(LOWORD(lParam), HIWORD(lParam)));
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
281 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
282 case WM_CLOSE:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
283 Call_Listener(On_Close());
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
284 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
285 case WM_KEYDOWN:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
286 Call_Listener(On_Key_Down(wParam));
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
287 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
288 case WM_KEYUP:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
289 Call_Listener(On_Key_Up(wParam));
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
290 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
291 case WM_CHAR:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
292 Call_Listener(On_Char(wParam));
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
293 break;
4742
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
294 case WM_SETFOCUS:
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
295 my_IMM.Focus_Gained();
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
296 break;
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
297 case WM_KILLFOCUS:
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
298 my_IMM.Focus_Lost();
59b0750575b1 Added Get_IMM method to Window.
dewyatt
parents: 4741
diff changeset
299 break;
4745
0aaa54fbd2bc Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents: 4742
diff changeset
300 case WM_LBUTTONDOWN:
0aaa54fbd2bc Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents: 4742
diff changeset
301 Call_Listener(On_Mouse_Button_Down(Mouse_Button_Left));
0aaa54fbd2bc Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents: 4742
diff changeset
302 break;
0aaa54fbd2bc Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents: 4742
diff changeset
303 case WM_LBUTTONUP:
0aaa54fbd2bc Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents: 4742
diff changeset
304 Call_Listener(On_Mouse_Button_Up(Mouse_Button_Left));
0aaa54fbd2bc Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents: 4742
diff changeset
305 break;
0aaa54fbd2bc Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents: 4742
diff changeset
306 case WM_RBUTTONDOWN:
0aaa54fbd2bc Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents: 4742
diff changeset
307 Call_Listener(On_Mouse_Button_Down(Mouse_Button_Right));
0aaa54fbd2bc Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents: 4742
diff changeset
308 break;
0aaa54fbd2bc Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents: 4742
diff changeset
309 case WM_RBUTTONUP:
0aaa54fbd2bc Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents: 4742
diff changeset
310 Call_Listener(On_Mouse_Button_Up(Mouse_Button_Right));
0aaa54fbd2bc Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
dewyatt
parents: 4742
diff changeset
311 break;
4741
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
312 default:
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
313 return DefWindowProcW(Handle, Message, wParam, lParam);
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
314 break;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
315 }
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
316 return 0;
bb189d44af16 Added GLIMM (using IMM instead of TSF)
dewyatt
parents:
diff changeset
317 }