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/
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"
30 #include "OnScreenDisplay.h"
31 #include "VertexShaderManager.h"
34 #include "StringUtil.h"
37 HINSTANCE g_hInstance
;
39 #if defined(HAVE_WX) && HAVE_WX
40 class wxDLLApp
: public wxApp
47 IMPLEMENT_APP_NO_MAIN(wxDLLApp
)
48 WXDLLIMPEXP_BASE
void wxSetInstance(HINSTANCE hInst
);
52 BOOL APIENTRY
DllMain(HINSTANCE hinstDLL
, // DLL module handle
53 DWORD dwReason
, // reason called
54 LPVOID lpvReserved
) // reserved
58 case DLL_PROCESS_ATTACH
:
60 #if defined(HAVE_WX) && HAVE_WX
61 wxSetInstance((HINSTANCE
)hinstDLL
);
67 case DLL_PROCESS_DETACH
:
68 #if defined(HAVE_WX) && HAVE_WX
74 g_hInstance
= hinstDLL
;
78 extern bool gShowDebugger
;
79 int OSDChoice
= 0 , OSDTime
= 0, OSDInternalW
= 0, OSDInternalH
= 0;
82 // ---------------------------------------------------------------------
85 // Let's begin with 3 since 1 and 2 are default Wii keys
87 void OSDMenu(WPARAM wParam
)
89 switch( LOWORD( wParam
))
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;
103 // Toggle aspect ratio
104 g_Config
.iAspectRatio
= (g_Config
.iAspectRatio
+ 1) & 3;
109 if (g_Config
.bEFBCopyDisable
|| g_Config
.bCopyEFBToTexture
)
111 g_Config
.bEFBCopyDisable
= !g_Config
.bEFBCopyDisable
;
112 g_Config
.bCopyEFBToTexture
= false;
116 g_Config
.bCopyEFBToTexture
= !g_Config
.bCopyEFBToTexture
;
121 g_Config
.bDisableFog
= !g_Config
.bDisableFog
;
125 g_Config
.bDisableLighting
= !g_Config
.bDisableLighting
;
129 // ---------------------------------------------------------------------
132 // ---------------------------------------------------------------------
133 // The rendering window
134 // ----------------------
138 HWND m_hWnd
= NULL
; // The new window that is created here
139 HWND m_hParent
= NULL
;
141 HINSTANCE m_hInstance
= NULL
;
143 const TCHAR m_szClassName
[] = _T("DolphinEmuWnd");
155 void FreeLookInput( UINT iMsg
, WPARAM wParam
)
157 static float debugSpeed
= 1.0f
;
158 static bool mouseLookEnabled
= false;
159 static float lastMouse
[2];
163 case WM_USER_KEYDOWN
:
165 switch( LOWORD( wParam
))
174 VertexShaderManager::TranslateView(0.0f
, debugSpeed
);
177 VertexShaderManager::TranslateView(0.0f
, -debugSpeed
);
180 VertexShaderManager::TranslateView(debugSpeed
, 0.0f
);
183 VertexShaderManager::TranslateView(-debugSpeed
, 0.0f
);
186 VertexShaderManager::ResetView();
192 if (mouseLookEnabled
) {
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
;
203 GetCursorPos(&point
);
204 lastMouse
[0] = point
.x
;
205 lastMouse
[1] = point
.y
;
206 mouseLookEnabled
= true;
209 mouseLookEnabled
= false;
214 // ---------------------------------------------------------------------
217 void OnKeyDown(WPARAM wParam
)
219 switch (LOWORD( wParam
))
221 case '3': // OSD keys
226 if (g_Config
.bOSDHotKey
)
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
);
245 hdc
= BeginPaint(hWnd
, &ps
);
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()*/
257 case WM_LBUTTONDBLCLK
:
258 PostMessage(GetParentWnd(), iMsg
, wParam
, lParam
);
262 if (wParam
== WM_USER_KEYDOWN
)
265 FreeLookInput(wParam
, lParam
);
267 else if (wParam
== WIIMOTE_DISCONNECT
)
269 PostMessage(m_hParent
, WM_USER
, wParam
, lParam
);
273 // This is called when we close the window when we render to a separate window
275 if (m_hParent
== NULL
)
278 PostMessage(m_hParent
, WM_USER
, WM_USER_STOP
, 0);
286 // Called when a screensaver wants to show up while this window is active
291 case SC_MONITORPOWER
:
294 return DefWindowProc(hWnd
, iMsg
, wParam
, lParam
);
298 PostMessage(m_hParent
, WM_USER
, WM_USER_SETCURSOR
, 0);
302 return DefWindowProc(hWnd
, iMsg
, wParam
, lParam
);
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
331 m_hWnd
= CreateWindow(m_szClassName
, title
, WS_CHILD
,
332 0, 0, width
, height
, parent
, NULL
, hInstance
, NULL
);
339 ShowWindow(m_hWnd
, SW_SHOW
);
340 BringWindowToTop(m_hWnd
);
341 UpdateWindow(m_hWnd
);
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;
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
);
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
);