Move fullscreen display resolution control to the GUI with the rest of the fullscreen...
[dolphin.git] / Source / Plugins / Plugin_VideoOGL / Src / OS / Win32.cpp
blobc40e5bfb8862fdb5773b889b31900c1a02909e04
1 // Copyright (C) 2003 Dolphin Project.
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0.
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU General Public License 2.0 for more details.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official SVN repository and contact information can be found at
16 // http://code.google.com/p/dolphin-emu/
18 #include <windows.h>
20 #include <wx/wx.h>
21 #include <wx/filepicker.h>
22 #include <wx/notebook.h>
23 #include <wx/dialog.h>
24 #include <wx/aboutdlg.h>
26 #include "../Globals.h"
27 #include "VideoConfig.h"
28 #include "main.h"
29 #include "Win32.h"
30 #include "OnScreenDisplay.h"
31 #include "VertexShaderManager.h"
32 #include "Render.h"
34 #include "StringUtil.h"
37 HINSTANCE g_hInstance;
39 #if defined(HAVE_WX) && HAVE_WX
40 class wxDLLApp : public wxApp
42 bool OnInit()
44 return true;
47 IMPLEMENT_APP_NO_MAIN(wxDLLApp)
48 WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
49 #endif
50 // ------------------
52 BOOL APIENTRY DllMain(HINSTANCE hinstDLL, // DLL module handle
53 DWORD dwReason, // reason called
54 LPVOID lpvReserved) // reserved
56 switch (dwReason)
58 case DLL_PROCESS_ATTACH:
60 #if defined(HAVE_WX) && HAVE_WX
61 wxSetInstance((HINSTANCE)hinstDLL);
62 wxInitialize();
63 #endif
65 break;
67 case DLL_PROCESS_DETACH:
68 #if defined(HAVE_WX) && HAVE_WX
69 wxUninitialize();
70 #endif
71 break;
74 g_hInstance = hinstDLL;
75 return TRUE;
78 extern bool gShowDebugger;
79 int OSDChoice = 0 , OSDTime = 0, OSDInternalW = 0, OSDInternalH = 0;
82 // ---------------------------------------------------------------------
83 // OSD Menu
84 // -------------
85 // Let's begin with 3 since 1 and 2 are default Wii keys
86 // -------------
87 void OSDMenu(WPARAM wParam)
89 switch( LOWORD( wParam ))
91 case '3':
92 OSDChoice = 1;
93 // Toggle native resolution
94 if (!(g_Config.bNativeResolution || g_Config.b2xResolution))
95 g_Config.bNativeResolution = true;
96 else if (g_Config.bNativeResolution && Renderer::AllowCustom())
97 { g_Config.bNativeResolution = false; if (Renderer::Allow2x()) {g_Config.b2xResolution = true;} }
98 else if (Renderer::AllowCustom())
99 g_Config.b2xResolution = false;
100 break;
101 case '4':
102 OSDChoice = 2;
103 // Toggle aspect ratio
104 g_Config.iAspectRatio = (g_Config.iAspectRatio + 1) & 3;
105 break;
106 case '5':
107 OSDChoice = 3;
108 // Toggle EFB copy
109 if (g_Config.bEFBCopyDisable || g_Config.bCopyEFBToTexture)
111 g_Config.bEFBCopyDisable = !g_Config.bEFBCopyDisable;
112 g_Config.bCopyEFBToTexture = false;
114 else
116 g_Config.bCopyEFBToTexture = !g_Config.bCopyEFBToTexture;
118 break;
119 case '6':
120 OSDChoice = 4;
121 g_Config.bDisableFog = !g_Config.bDisableFog;
122 break;
123 case '7':
124 OSDChoice = 5;
125 g_Config.bDisableLighting = !g_Config.bDisableLighting;
126 break;
129 // ---------------------------------------------------------------------
132 // ---------------------------------------------------------------------
133 // The rendering window
134 // ----------------------
135 namespace EmuWindow
138 HWND m_hWnd = NULL; // The new window that is created here
139 HWND m_hParent = NULL;
141 HINSTANCE m_hInstance = NULL;
142 WNDCLASSEX wndClass;
143 const TCHAR m_szClassName[] = _T("DolphinEmuWnd");
144 int g_winstyle;
146 HWND GetWnd()
148 return m_hWnd;
150 HWND GetParentWnd()
152 return m_hParent;
155 void FreeLookInput( UINT iMsg, WPARAM wParam )
157 static float debugSpeed = 1.0f;
158 static bool mouseLookEnabled = false;
159 static float lastMouse[2];
161 switch( iMsg )
163 case WM_USER_KEYDOWN:
164 case WM_KEYDOWN:
165 switch( LOWORD( wParam ))
167 case '9':
168 debugSpeed /= 2.0f;
169 break;
170 case '0':
171 debugSpeed *= 2.0f;
172 break;
173 case 'W':
174 VertexShaderManager::TranslateView(0.0f, debugSpeed);
175 break;
176 case 'S':
177 VertexShaderManager::TranslateView(0.0f, -debugSpeed);
178 break;
179 case 'A':
180 VertexShaderManager::TranslateView(debugSpeed, 0.0f);
181 break;
182 case 'D':
183 VertexShaderManager::TranslateView(-debugSpeed, 0.0f);
184 break;
185 case 'R':
186 VertexShaderManager::ResetView();
187 break;
189 break;
191 case WM_MOUSEMOVE:
192 if (mouseLookEnabled) {
193 POINT point;
194 GetCursorPos(&point);
195 VertexShaderManager::RotateView((point.x - lastMouse[0]) / 200.0f, (point.y - lastMouse[1]) / 200.0f);
196 lastMouse[0] = point.x;
197 lastMouse[1] = point.y;
199 break;
201 case WM_RBUTTONDOWN:
202 POINT point;
203 GetCursorPos(&point);
204 lastMouse[0] = point.x;
205 lastMouse[1] = point.y;
206 mouseLookEnabled= true;
207 break;
208 case WM_RBUTTONUP:
209 mouseLookEnabled = false;
210 break;
214 // ---------------------------------------------------------------------
215 // KeyDown events
216 // -------------
217 void OnKeyDown(WPARAM wParam)
219 switch (LOWORD( wParam ))
221 case '3': // OSD keys
222 case '4':
223 case '5':
224 case '6':
225 case '7':
226 if (g_Config.bOSDHotKey)
227 OSDMenu(wParam);
228 break;
231 // ---------------------------------------------------------------------
233 // Should really take a look at the mouse stuff in here - some of it is weird.
234 LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
236 if (g_Config.bFreeLook)
237 FreeLookInput( iMsg, wParam );
239 switch (iMsg)
241 case WM_PAINT:
243 HDC hdc;
244 PAINTSTRUCT ps;
245 hdc = BeginPaint(hWnd, &ps);
246 EndPaint(hWnd, &ps);
248 break;
250 case WM_KEYDOWN:
251 break;
253 /* Post these mouse events to the main window, it's nessesary becase in difference to the
254 keyboard inputs these events only appear here, not in the parent window or any other WndProc()*/
255 case WM_LBUTTONDOWN:
256 case WM_LBUTTONUP:
257 case WM_LBUTTONDBLCLK:
258 PostMessage(GetParentWnd(), iMsg, wParam, lParam);
259 break;
261 case WM_USER:
262 if (wParam == WM_USER_KEYDOWN)
264 OnKeyDown(lParam);
265 FreeLookInput(wParam, lParam);
267 else if (wParam == WIIMOTE_DISCONNECT)
269 PostMessage(m_hParent, WM_USER, wParam, lParam);
271 break;
273 // This is called when we close the window when we render to a separate window
274 case WM_CLOSE:
275 if (m_hParent == NULL)
277 // Stop the game
278 PostMessage(m_hParent, WM_USER, WM_USER_STOP, 0);
280 break;
282 case WM_DESTROY:
283 Shutdown();
284 break;
286 // Called when a screensaver wants to show up while this window is active
287 case WM_SYSCOMMAND:
288 switch (wParam)
290 case SC_SCREENSAVE:
291 case SC_MONITORPOWER:
292 break;
293 default:
294 return DefWindowProc(hWnd, iMsg, wParam, lParam);
296 break;
297 case WM_SETCURSOR:
298 PostMessage(m_hParent, WM_USER, WM_USER_SETCURSOR, 0);
299 return true;
300 break;
301 default:
302 return DefWindowProc(hWnd, iMsg, wParam, lParam);
304 return 0;
309 // This is called from Create()
310 HWND OpenWindow(HWND parent, HINSTANCE hInstance, int width, int height, const TCHAR *title)
312 wndClass.cbSize = sizeof( wndClass );
313 wndClass.style = CS_HREDRAW | CS_VREDRAW;
314 wndClass.lpfnWndProc = WndProc;
315 wndClass.cbClsExtra = 0;
316 wndClass.cbWndExtra = 0;
317 wndClass.hInstance = hInstance;
318 wndClass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
319 wndClass.hCursor = NULL;
320 wndClass.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
321 wndClass.lpszMenuName = NULL;
322 wndClass.lpszClassName = m_szClassName;
323 wndClass.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
325 m_hInstance = hInstance;
326 RegisterClassEx( &wndClass );
328 // Create child window
329 m_hParent = parent;
331 m_hWnd = CreateWindow(m_szClassName, title, WS_CHILD,
332 0, 0, width, height, parent, NULL, hInstance, NULL);
334 return m_hWnd;
337 void Show()
339 ShowWindow(m_hWnd, SW_SHOW);
340 BringWindowToTop(m_hWnd);
341 UpdateWindow(m_hWnd);
342 SetFocus(m_hParent);
344 // gShowDebugger from main.cpp is forgotten between the Dolphin-Debugger is opened and a game is
345 // started so we have to use an ini file setting here
347 bool bVideoWindow = false;
348 IniFile ini;
349 ini.Load(File::GetUserPath(F_DEBUGGERCONFIG_IDX));
350 ini.Get("ShowOnStart", "VideoWindow", &bVideoWindow, false);
351 if(bVideoWindow) DoDllDebugger();
355 HWND Create(HWND hParent, HINSTANCE hInstance, const TCHAR *title)
357 int x=0, y=0, width=640, height=480;
358 g_VideoInitialize.pRequestWindowSize(x, y, width, height);
359 return OpenWindow(hParent, hInstance, width, height, title);
362 void Close()
364 if (m_hParent == NULL)
365 DestroyWindow(m_hWnd);
366 UnregisterClass(m_szClassName, m_hInstance);
369 // ------------------------------------------
370 // Set the size of the child or main window
371 // ------------------------------------------
372 void SetSize(int width, int height)
374 RECT rc = {0, 0, width, height};
375 DWORD dwStyle = GetWindowLong(m_hWnd, GWL_STYLE);
376 AdjustWindowRect(&rc, dwStyle, false);
378 int w = rc.right - rc.left;
379 int h = rc.bottom - rc.top;
381 // Move and resize the window
382 rc.left = (1280 - w)/2;
383 rc.right = rc.left + w;
384 rc.top = (1024 - h)/2;
385 rc.bottom = rc.top + h;
386 MoveWindow(m_hWnd, rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top, TRUE);
389 } // EmuWindow