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/
20 #include "VideoConfig.h"
22 #include "EmuWindow.h"
27 int OSDChoice
= 0 , OSDTime
= 0, OSDInternalW
= 0, OSDInternalH
= 0;
32 HWND m_hParent
= NULL
;
33 HINSTANCE m_hInstance
= NULL
;
35 const TCHAR m_szClassName
[] = _T("DolphinEmuWnd");
37 static volatile bool s_sizing
;
54 // ---------------------------------------------------------------------
57 void OnKeyDown(WPARAM wParam
)
59 switch (LOWORD( wParam
))
66 if (g_Config
.bOSDHotKey
)
71 // ---------------------------------------------------------------------
73 LRESULT CALLBACK
WndProc( HWND hWnd
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
81 hdc
= BeginPaint(hWnd
, &ps
);
86 case WM_ENTERSIZEMOVE
:
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()*/
98 case WM_LBUTTONDBLCLK
:
99 PostMessage(GetParentWnd(), iMsg
, wParam
, lParam
);
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);
110 if (wParam
== WM_USER_KEYDOWN
)
112 else if (wParam
== WIIMOTE_DISCONNECT
)
113 PostMessage(m_hParent
, WM_USER
, wParam
, lParam
);
120 case SC_MONITORPOWER
:
123 return DefWindowProc(hWnd
, iMsg
, wParam
, lParam
);
127 PostMessage(m_hParent
, WM_USER
, WM_USER_SETCURSOR
, 0);
131 return DefWindowProc(hWnd
, iMsg
, wParam
, lParam
);
136 // ---------------------------------------------------------------------
139 // Let's begin with 3 since 1 and 2 are default Wii keys
141 void OSDMenu(WPARAM wParam
)
143 switch( LOWORD( wParam
))
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();
161 // Toggle aspect ratio
162 g_Config
.iAspectRatio
= (g_Config
.iAspectRatio
+ 1) & 3;
167 if (g_Config
.bEFBCopyDisable
|| g_Config
.bCopyEFBToTexture
)
169 g_Config
.bEFBCopyDisable
= !g_Config
.bEFBCopyDisable
;
170 g_Config
.bCopyEFBToTexture
= false;
174 g_Config
.bCopyEFBToTexture
= !g_Config
.bCopyEFBToTexture
;
179 g_Config
.bDisableFog
= !g_Config
.bDisableFog
;
183 g_Config
.bDisableLighting
= !g_Config
.bDisableLighting
;
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
);
208 m_hWnd
= CreateWindow(m_szClassName
, title
, WS_CHILD
,
209 0, 0, width
, height
, m_hParent
, NULL
, hInstance
, NULL
);
216 ShowWindow(m_hWnd
, SW_SHOW
);
217 BringWindowToTop(m_hWnd
);
218 UpdateWindow(m_hWnd
);
222 HWND
Create(HWND hParent
, HINSTANCE hInstance
, const TCHAR
*title
)
225 // 1. Remove redundant window manipulation,
226 // 2. Make DX9 in fullscreen can be overlapped by other dialogs
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
);
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
);