Move fullscreen display resolution control to the GUI with the rest of the fullscreen...
[dolphin.git] / Source / Plugins / Plugin_VideoDX9 / Src / EmuWindow.cpp
bloba4390f892ea1b96b145c289378061c517b2b49c7
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 "VideoConfig.h"
21 #include "main.h"
22 #include "EmuWindow.h"
23 #include "D3DBase.h"
24 #include "Fifo.h"
27 int OSDChoice = 0 , OSDTime = 0, OSDInternalW = 0, OSDInternalH = 0;
29 namespace EmuWindow
31 HWND m_hWnd = NULL;
32 HWND m_hParent = NULL;
33 HINSTANCE m_hInstance = NULL;
34 WNDCLASSEX wndClass;
35 const TCHAR m_szClassName[] = _T("DolphinEmuWnd");
36 int g_winstyle;
37 static volatile bool s_sizing;
39 bool IsSizing()
41 return s_sizing;
44 HWND GetWnd()
46 return m_hWnd;
49 HWND GetParentWnd()
51 return m_hParent;
54 // ---------------------------------------------------------------------
55 // KeyDown events
56 // -------------
57 void OnKeyDown(WPARAM wParam)
59 switch (LOWORD( wParam ))
61 case '3': // OSD keys
62 case '4':
63 case '5':
64 case '6':
65 case '7':
66 if (g_Config.bOSDHotKey)
67 OSDMenu(wParam);
68 break;
71 // ---------------------------------------------------------------------
73 LRESULT CALLBACK WndProc( HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam )
75 switch( iMsg )
77 case WM_PAINT:
79 HDC hdc;
80 PAINTSTRUCT ps;
81 hdc = BeginPaint(hWnd, &ps);
82 EndPaint(hWnd, &ps);
84 break;
86 case WM_ENTERSIZEMOVE:
87 s_sizing = true;
88 break;
90 case WM_EXITSIZEMOVE:
91 s_sizing = false;
92 break;
94 /* Post thes mouse events to the main window, it's nessesary because in difference to the
95 keyboard inputs these events only appear here, not in the parent window or any other WndProc()*/
96 case WM_LBUTTONDOWN:
97 case WM_LBUTTONUP:
98 case WM_LBUTTONDBLCLK:
99 PostMessage(GetParentWnd(), iMsg, wParam, lParam);
100 break;
102 case WM_CLOSE:
103 // When the user closes the window, we post an event to the main window to call Stop()
104 // Which then handles all the necessary steps to Shutdown the core + the plugins
105 if (m_hParent == NULL)
106 PostMessage(m_hParent, WM_USER, WM_USER_STOP, 0);
107 break;
109 case WM_USER:
110 if (wParam == WM_USER_KEYDOWN)
111 OnKeyDown(lParam);
112 else if (wParam == WIIMOTE_DISCONNECT)
113 PostMessage(m_hParent, WM_USER, wParam, lParam);
114 break;
116 case WM_SYSCOMMAND:
117 switch (wParam)
119 case SC_SCREENSAVE:
120 case SC_MONITORPOWER:
121 break;
122 default:
123 return DefWindowProc(hWnd, iMsg, wParam, lParam);
125 break;
126 case WM_SETCURSOR:
127 PostMessage(m_hParent, WM_USER, WM_USER_SETCURSOR, 0);
128 return true;
129 break;
130 default:
131 return DefWindowProc(hWnd, iMsg, wParam, lParam);
133 return 0;
136 // ---------------------------------------------------------------------
137 // OSD Menu
138 // -------------
139 // Let's begin with 3 since 1 and 2 are default Wii keys
140 // -------------
141 void OSDMenu(WPARAM wParam)
143 switch( LOWORD( wParam ))
145 case '3':
146 OSDChoice = 1;
147 // Toggle native resolution
149 if (!(g_Config.bNativeResolution || g_Config.b2xResolution))
150 g_Config.bNativeResolution = true;
151 else if (g_Config.bNativeResolution && Renderer::AllowCustom())
152 { g_Config.bNativeResolution = false; if (Renderer::Allow2x()) {g_Config.b2xResolution = true;} }
153 else if (Renderer::AllowCustom())
154 g_Config.b2xResolution = false;
156 OSDInternalW = D3D::GetBackBufferWidth();
157 OSDInternalH = D3D::GetBackBufferHeight();
158 break;
159 case '4':
160 OSDChoice = 2;
161 // Toggle aspect ratio
162 g_Config.iAspectRatio = (g_Config.iAspectRatio + 1) & 3;
163 break;
164 case '5':
165 OSDChoice = 3;
166 // Toggle EFB copy
167 if (g_Config.bEFBCopyDisable || g_Config.bCopyEFBToTexture)
169 g_Config.bEFBCopyDisable = !g_Config.bEFBCopyDisable;
170 g_Config.bCopyEFBToTexture = false;
172 else
174 g_Config.bCopyEFBToTexture = !g_Config.bCopyEFBToTexture;
176 break;
177 case '6':
178 OSDChoice = 4;
179 g_Config.bDisableFog = !g_Config.bDisableFog;
180 break;
181 case '7':
182 OSDChoice = 5;
183 g_Config.bDisableLighting = !g_Config.bDisableLighting;
184 break;
188 HWND OpenWindow(HWND parent, HINSTANCE hInstance, int width, int height, const TCHAR *title)
190 wndClass.cbSize = sizeof( wndClass );
191 wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
192 wndClass.lpfnWndProc = WndProc;
193 wndClass.cbClsExtra = 0;
194 wndClass.cbWndExtra = 0;
195 wndClass.hInstance = hInstance;
196 wndClass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
197 wndClass.hCursor = NULL;
198 wndClass.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
199 wndClass.lpszMenuName = NULL;
200 wndClass.lpszClassName = m_szClassName;
201 wndClass.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
203 m_hInstance = hInstance;
204 RegisterClassEx( &wndClass );
206 m_hParent = parent;
208 m_hWnd = CreateWindow(m_szClassName, title, WS_CHILD,
209 0, 0, width, height, m_hParent, NULL, hInstance, NULL);
211 return m_hWnd;
214 void Show()
216 ShowWindow(m_hWnd, SW_SHOW);
217 BringWindowToTop(m_hWnd);
218 UpdateWindow(m_hWnd);
219 SetFocus(m_hParent);
222 HWND Create(HWND hParent, HINSTANCE hInstance, const TCHAR *title)
224 // TODO:
225 // 1. Remove redundant window manipulation,
226 // 2. Make DX9 in fullscreen can be overlapped by other dialogs
227 HWND Ret;
228 int x=0, y=0, width=640, height=480;
229 g_VideoInitialize.pRequestWindowSize(x, y, width, height);
231 Ret = OpenWindow(hParent, hInstance, width, height, title);
233 if (Ret)
235 Show();
237 return Ret;
240 void Close()
242 if (m_hParent == NULL)
243 DestroyWindow(m_hWnd);
244 UnregisterClass(m_szClassName, m_hInstance);
247 void SetSize(int width, int height)
249 RECT rc = {0, 0, width, height};
250 DWORD style = GetWindowLong(m_hWnd, GWL_STYLE);
251 AdjustWindowRect(&rc, style, false);
253 int w = rc.right - rc.left;
254 int h = rc.bottom - rc.top;
256 rc.left = (1280 - w)/2;
257 rc.right = rc.left + w;
258 rc.top = (1024 - h)/2;
259 rc.bottom = rc.top + h;
260 MoveWindow(m_hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, TRUE);