Make sure screensaver does not start while a game is running in MS Windows
[dolphin.git] / Source / Core / DolphinWX / Src / FrameTools.cpp
blob973e25a1f0c78c4f6a32dee1aee968061c0e5a57
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 1.1 Windows
22 CFrame is the main parent window. Inside CFrame there is m_Panel which is the
23 parent for the rendering window (when we render to the main window). In Windows
24 the rendering window is created by giving CreateWindow() m_Panel->GetHandle()
25 as parent window and creating a new child window to m_Panel. The new child
26 window handle that is returned by CreateWindow() can be accessed from
27 Core::GetWindowHandle().
31 #include "Setup.h" // Common
33 #include "NetWindow.h"
34 #include "Common.h" // Common
35 #include "FileUtil.h"
36 #include "FileSearch.h"
37 #include "Timer.h"
39 #include "Globals.h" // Local
40 #include "Frame.h"
41 #include "ConfigMain.h"
42 #include "PluginManager.h"
43 #include "MemcardManager.h"
44 #include "CheatsWindow.h"
45 #include "LuaWindow.h"
46 #include "AboutDolphin.h"
47 #include "GameListCtrl.h"
48 #include "BootManager.h"
49 #include "LogWindow.h"
50 #include "WxUtils.h"
52 #include "ConfigManager.h" // Core
53 #include "Core.h"
54 #include "OnFrame.h"
55 #include "HW/CPU.h"
56 #include "PowerPC/PowerPC.h"
57 #include "HW/DVDInterface.h"
58 #include "HW/ProcessorInterface.h"
59 #include "IPC_HLE/WII_IPC_HLE_Device_usb.h"
60 #include "State.h"
61 #include "VolumeHandler.h"
62 #include "NANDContentLoader.h"
63 #include "WXInputBase.h"
65 #include <wx/datetime.h> // wxWidgets
68 // Resources
69 extern "C" {
70 #include "../resources/Dolphin.c" // Dolphin icon
71 #include "../resources/toolbar_browse.c"
72 #include "../resources/toolbar_file_open.c"
73 #include "../resources/toolbar_fullscreen.c"
74 #include "../resources/toolbar_help.c"
75 #include "../resources/toolbar_pause.c"
76 #include "../resources/toolbar_play.c"
77 #include "../resources/toolbar_plugin_dsp.c"
78 #include "../resources/toolbar_plugin_gfx.c"
79 #include "../resources/toolbar_plugin_options.c"
80 #include "../resources/toolbar_plugin_pad.c"
81 #include "../resources/toolbar_plugin_wiimote.c"
82 #include "../resources/toolbar_refresh.c"
83 #include "../resources/toolbar_stop.c"
84 #include "../resources/Boomy.h" // Theme packages
85 #include "../resources/Vista.h"
86 #include "../resources/X-Plastik.h"
87 #include "../resources/KDE.h"
91 // Other Windows
92 wxCheatsWindow* CheatsWindow;
95 // Create menu items
96 // ---------------------
97 void CFrame::CreateMenu()
99 if (GetMenuBar()) GetMenuBar()->Destroy();
101 m_MenuBar = new wxMenuBar(wxMB_DOCKABLE);
103 // file menu
104 wxMenu* fileMenu = new wxMenu;
105 fileMenu->Append(wxID_OPEN, _T("&Open...\tCtrl+O"));
107 wxMenu *externalDrive = new wxMenu;
108 m_pSubMenuDrive = fileMenu->AppendSubMenu(externalDrive, _T("&Boot from DVD Drive..."));
110 drives = cdio_get_devices();
111 // Windows Limitation of 24 character drives
112 for (unsigned int i = 0; i < drives.size() && i < 24; i++) {
113 externalDrive->Append(IDM_DRIVE1 + i, wxString::FromAscii(drives[i].c_str()));
116 fileMenu->AppendSeparator();
117 fileMenu->Append(wxID_REFRESH, _T("&Refresh List"));
118 fileMenu->AppendSeparator();
119 fileMenu->Append(IDM_BROWSE, _T("&Browse for ISOs..."));
120 fileMenu->AppendSeparator();
121 fileMenu->Append(wxID_EXIT, _T("E&xit\tAlt+F4"));
122 m_MenuBar->Append(fileMenu, _T("&File"));
124 // Emulation menu
125 wxMenu* emulationMenu = new wxMenu;
126 emulationMenu->Append(IDM_PLAY, GetMenuLabel(HK_PLAY_PAUSE));
127 emulationMenu->Append(IDM_STOP, GetMenuLabel(HK_STOP));
128 emulationMenu->Append(IDM_RESET, _T("&Reset"));
129 emulationMenu->AppendSeparator();
130 emulationMenu->Append(IDM_TOGGLE_FULLSCREEN, GetMenuLabel(HK_FULLSCREEN));
131 emulationMenu->AppendSeparator();
132 emulationMenu->Append(IDM_RECORD, _T("Start Re&cording..."));
133 emulationMenu->Append(IDM_PLAYRECORD, _T("P&lay Recording..."));
134 emulationMenu->AppendSeparator();
135 emulationMenu->Append(IDM_CHANGEDISC, _T("Change &Disc"));
137 emulationMenu->Append(IDM_FRAMESTEP, _T("&Frame Stepping"), wxEmptyString, wxITEM_CHECK);
139 wxMenu *skippingMenu = new wxMenu;
140 m_pSubMenuFrameSkipping = emulationMenu->AppendSubMenu(skippingMenu, _T("Frame S&kipping"));
141 for(int i = 0; i < 10; i++)
142 skippingMenu->Append(IDM_FRAMESKIP0 + i, wxString::Format(_T("%i"), i), wxEmptyString, wxITEM_RADIO);
144 emulationMenu->AppendSeparator();
145 emulationMenu->Append(IDM_SCREENSHOT, _T("Take S&creenshot\tF9"));
146 emulationMenu->AppendSeparator();
147 wxMenu *saveMenu = new wxMenu;
148 wxMenu *loadMenu = new wxMenu;
149 m_pSubMenuLoad = emulationMenu->AppendSubMenu(loadMenu, _T("&Load State"));
150 m_pSubMenuSave = emulationMenu->AppendSubMenu(saveMenu, _T("Sa&ve State"));
152 saveMenu->Append(IDM_SAVESTATEFILE, _T("Save State..."));
153 loadMenu->Append(IDM_UNDOSAVESTATE, _T("Last Overwritten State\tShift+F12"));
154 saveMenu->AppendSeparator();
156 loadMenu->Append(IDM_LOADSTATEFILE, _T("Load State..."));
157 loadMenu->Append(IDM_LOADLASTSTATE, _T("Last Saved State\tF11"));
158 loadMenu->Append(IDM_UNDOLOADSTATE, _T("Undo Load State\tF12"));
159 loadMenu->AppendSeparator();
161 for (int i = 1; i <= 8; i++) {
162 loadMenu->Append(IDM_LOADSLOT1 + i - 1, wxString::Format(_T("Slot %i\tF%i"), i, i));
163 saveMenu->Append(IDM_SAVESLOT1 + i - 1, wxString::Format(_T("Slot %i\tShift+F%i"), i, i));
165 m_MenuBar->Append(emulationMenu, _T("&Emulation"));
167 // Options menu
168 wxMenu* pOptionsMenu = new wxMenu;
169 pOptionsMenu->Append(IDM_CONFIG_MAIN, _T("Co&nfigure..."));
170 pOptionsMenu->AppendSeparator();
171 pOptionsMenu->Append(IDM_CONFIG_GFX_PLUGIN, _T("&Graphics Settings"));
172 pOptionsMenu->Append(IDM_CONFIG_DSP_PLUGIN, _T("&DSP Settings"));
173 pOptionsMenu->Append(IDM_CONFIG_PAD_PLUGIN, _T("&Gamecube Pad Settings"));
174 pOptionsMenu->Append(IDM_CONFIG_WIIMOTE_PLUGIN, _T("&Wiimote Settings"));
175 if (g_pCodeWindow)
177 pOptionsMenu->AppendSeparator();
178 g_pCodeWindow->CreateMenuOptions(NULL, pOptionsMenu);
180 m_MenuBar->Append(pOptionsMenu, _T("&Options"));
182 // Tools menu
183 wxMenu* toolsMenu = new wxMenu;
184 toolsMenu->Append(IDM_LUA, _T("New &Lua Console"));
185 toolsMenu->Append(IDM_MEMCARD, _T("&Memcard Manager (GC)"));
186 toolsMenu->Append(IDM_IMPORTSAVE, _T("Wii Save Import (experimental)"));
187 toolsMenu->Append(IDM_CHEATS, _T("Action &Replay Manager"));
189 #if defined(HAVE_SFML) && HAVE_SFML
190 // Disabled for now, netplay doesn't quite work currently
191 // toolsMenu->Append(IDM_NETPLAY, _T("Start &NetPlay"));
192 #endif
194 if (DiscIO::CNANDContentManager::Access().GetNANDLoader(std::string (File::GetUserPath(D_WIIMENU_IDX))).IsValid())
196 toolsMenu->Append(IDM_LOAD_WII_MENU, _T("Load Wii Menu"));
198 toolsMenu->AppendSeparator();
199 toolsMenu->AppendCheckItem(IDM_CONNECT_WIIMOTE1, _T("Connect Wiimote 1\tAlt+F5"));
200 toolsMenu->AppendCheckItem(IDM_CONNECT_WIIMOTE2, _T("Connect Wiimote 2\tAlt+F6"));
201 toolsMenu->AppendCheckItem(IDM_CONNECT_WIIMOTE3, _T("Connect Wiimote 3\tAlt+F7"));
202 toolsMenu->AppendCheckItem(IDM_CONNECT_WIIMOTE4, _T("Connect Wiimote 4\tAlt+F8"));
204 m_MenuBar->Append(toolsMenu, _T("&Tools"));
206 wxMenu* viewMenu = new wxMenu;
207 viewMenu->AppendCheckItem(IDM_TOGGLE_TOOLBAR, _T("Show &Toolbar"));
208 viewMenu->Check(IDM_TOGGLE_TOOLBAR, SConfig::GetInstance().m_InterfaceToolbar);
209 viewMenu->AppendCheckItem(IDM_TOGGLE_STATUSBAR, _T("Show &Statusbar"));
210 viewMenu->Check(IDM_TOGGLE_STATUSBAR, SConfig::GetInstance().m_InterfaceStatusbar);
211 viewMenu->AppendSeparator();
212 viewMenu->AppendCheckItem(IDM_LOGWINDOW, _T("Show &Logwindow"));
213 viewMenu->Check(IDM_LOGWINDOW, SConfig::GetInstance().m_InterfaceLogWindow);
214 viewMenu->AppendCheckItem(IDM_CONSOLEWINDOW, _T("Show &Console"));
215 viewMenu->Check(IDM_CONSOLEWINDOW, SConfig::GetInstance().m_InterfaceConsole);
216 viewMenu->AppendSeparator();
218 if (g_pCodeWindow)
220 g_pCodeWindow->CreateMenuView(NULL, viewMenu);
221 viewMenu->AppendSeparator();
224 wxMenu *platformMenu = new wxMenu;
225 viewMenu->AppendSubMenu(platformMenu, _T("Show Platforms"));
226 platformMenu->AppendCheckItem(IDM_LISTWII, _T("Show Wii"));
227 platformMenu->Check(IDM_LISTWII, SConfig::GetInstance().m_ListWii);
228 platformMenu->AppendCheckItem(IDM_LISTGC, _T("Show GameCube"));
229 platformMenu->Check(IDM_LISTGC, SConfig::GetInstance().m_ListGC);
230 platformMenu->AppendCheckItem(IDM_LISTWAD, _T("Show Wad"));
231 platformMenu->Check(IDM_LISTWAD, SConfig::GetInstance().m_ListWad);
233 wxMenu *regionMenu = new wxMenu;
234 viewMenu->AppendSubMenu(regionMenu, _T("Show Regions"));
235 regionMenu->AppendCheckItem(IDM_LISTJAP, _T("Show JAP"));
236 regionMenu->Check(IDM_LISTJAP, SConfig::GetInstance().m_ListJap);
237 regionMenu->AppendCheckItem(IDM_LISTPAL, _T("Show PAL"));
238 regionMenu->Check(IDM_LISTPAL, SConfig::GetInstance().m_ListPal);
239 regionMenu->AppendCheckItem(IDM_LISTUSA, _T("Show USA"));
240 regionMenu->Check(IDM_LISTUSA, SConfig::GetInstance().m_ListUsa);
241 regionMenu->AppendSeparator();
242 regionMenu->AppendCheckItem(IDM_LISTFRANCE, _T("Show France"));
243 regionMenu->Check(IDM_LISTFRANCE, SConfig::GetInstance().m_ListFrance);
244 regionMenu->AppendCheckItem(IDM_LISTITALY, _T("Show Italy"));
245 regionMenu->Check(IDM_LISTITALY, SConfig::GetInstance().m_ListItaly);
246 regionMenu->AppendCheckItem(IDM_LISTKOREA, _T("Show Korea"));
247 regionMenu->Check(IDM_LISTKOREA, SConfig::GetInstance().m_ListKorea);
248 regionMenu->AppendCheckItem(IDM_LISTTAIWAN, _T("Show Taiwan"));
249 regionMenu->Check(IDM_LISTTAIWAN, SConfig::GetInstance().m_ListTaiwan);
250 regionMenu->AppendCheckItem(IDM_LIST_UNK, _T("Show unknown"));
251 regionMenu->Check(IDM_LIST_UNK, SConfig::GetInstance().m_ListUnknown);
252 viewMenu->AppendCheckItem(IDM_LISTDRIVES, _T("Show Drives"));
253 viewMenu->Check(IDM_LISTDRIVES, SConfig::GetInstance().m_ListDrives);
254 viewMenu->Append(IDM_PURGECACHE, _T("Purge Cache"));
255 m_MenuBar->Append(viewMenu, _T("&View"));
257 if (g_pCodeWindow) g_pCodeWindow->CreateMenu(SConfig::GetInstance().m_LocalCoreStartupParameter, m_MenuBar);
259 // Help menu
260 wxMenu* helpMenu = new wxMenu;
261 /*helpMenu->Append(wxID_HELP, _T("&Help"));
262 re-enable when there's something useful to display*/
263 helpMenu->Append(IDM_HELPWEBSITE, _T("Dolphin &Web Site"));
264 helpMenu->Append(IDM_HELPGOOGLECODE, _T("Dolphin at &Google Code"));
265 helpMenu->AppendSeparator();
266 helpMenu->Append(IDM_HELPABOUT, _T("&About..."));
267 m_MenuBar->Append(helpMenu, _T("&Help"));
269 // Associate the menu bar with the frame
270 SetMenuBar(m_MenuBar);
273 wxString CFrame::GetMenuLabel(int Id)
275 wxString Label;
276 switch (Id)
278 case HK_FULLSCREEN:
279 Label = _T("&Fullscreen\t");
280 break;
281 case HK_PLAY_PAUSE:
282 if (Core::GetState() == Core::CORE_UNINITIALIZED)
283 Label = _T("&Play\t");
284 else
285 Label = _T("&Play\t");
286 break;
287 case HK_STOP:
288 Label = _T("&Stop\t");
291 wxString Modifier = InputCommon::WXKeymodToString
292 (SConfig::GetInstance().m_LocalCoreStartupParameter.iHotkeyModifier[Id]);
293 wxString Hotkey = InputCommon::WXKeyToString
294 (SConfig::GetInstance().m_LocalCoreStartupParameter.iHotkey[Id]);
296 return Label + Modifier + (Modifier.Len() ? _T("+") : _T("")) + Hotkey;
300 // Create toolbar items
301 // ---------------------
302 void CFrame::PopulateToolbar(wxAuiToolBar* ToolBar)
304 int w = m_Bitmaps[Toolbar_FileOpen].GetWidth(),
305 h = m_Bitmaps[Toolbar_FileOpen].GetHeight();
306 ToolBar->SetToolBitmapSize(wxSize(w, h));
309 ToolBar->AddTool(wxID_OPEN, _T("Open"), m_Bitmaps[Toolbar_FileOpen], _T("Open file..."));
310 ToolBar->AddTool(wxID_REFRESH, _T("Refresh"), m_Bitmaps[Toolbar_Refresh], _T("Refresh game list"));
311 ToolBar->AddTool(IDM_BROWSE, _T("Browse"), m_Bitmaps[Toolbar_Browse], _T("Browse for an ISO directory..."));
312 ToolBar->AddSeparator();
313 ToolBar->AddTool(IDM_PLAY, wxT("Play"), m_Bitmaps[Toolbar_Play], _T("Play"));
314 ToolBar->AddTool(IDM_STOP, _T("Stop"), m_Bitmaps[Toolbar_Stop], _T("Stop"));
315 ToolBar->AddTool(IDM_TOGGLE_FULLSCREEN, _T("FullScr"), m_Bitmaps[Toolbar_FullScreen], _T("Toggle Fullscreen"));
316 ToolBar->AddTool(IDM_SCREENSHOT, _T("ScrShot"), m_Bitmaps[Toolbar_FullScreen], _T("Take Screenshot"));
317 ToolBar->AddSeparator();
318 ToolBar->AddTool(IDM_CONFIG_MAIN, _T("Config"), m_Bitmaps[Toolbar_PluginOptions], _T("Configure..."));
319 ToolBar->AddTool(IDM_CONFIG_GFX_PLUGIN, _T("Graphics"), m_Bitmaps[Toolbar_PluginGFX], _T("Graphics settings"));
320 ToolBar->AddTool(IDM_CONFIG_DSP_PLUGIN, _T("DSP"), m_Bitmaps[Toolbar_PluginDSP], _T("DSP settings"));
321 ToolBar->AddTool(IDM_CONFIG_PAD_PLUGIN, _T("GC Pad"), m_Bitmaps[Toolbar_PluginPAD], _T("Gamecube Pad settings"));
322 ToolBar->AddTool(IDM_CONFIG_WIIMOTE_PLUGIN, _T("Wiimote"), m_Bitmaps[Toolbar_Wiimote], _T("Wiimote settings"));
324 // after adding the buttons to the toolbar, must call Realize() to reflect
325 // the changes
326 ToolBar->Realize();
329 void CFrame::PopulateToolbarAui(wxAuiToolBar* ToolBar)
331 int w = m_Bitmaps[Toolbar_FileOpen].GetWidth(),
332 h = m_Bitmaps[Toolbar_FileOpen].GetHeight();
333 ToolBar->SetToolBitmapSize(wxSize(w, h));
335 ToolBar->AddTool(IDM_SAVE_PERSPECTIVE, wxT("Save"), g_pCodeWindow->m_Bitmaps[Toolbar_GotoPC], wxT("Save current perspective"));
336 ToolBar->AddTool(IDM_EDIT_PERSPECTIVES, wxT("Edit"), g_pCodeWindow->m_Bitmaps[Toolbar_GotoPC], wxT("Edit current perspective"));
338 ToolBar->SetToolDropDown(IDM_SAVE_PERSPECTIVE, true);
339 ToolBar->SetToolDropDown(IDM_EDIT_PERSPECTIVES, true);
341 ToolBar->Realize();
345 // Delete and recreate the toolbar
346 void CFrame::RecreateToolbar()
348 if (m_ToolBar)
350 m_Mgr->DetachPane(m_ToolBar);
351 m_ToolBar->Destroy();
354 m_ToolBar = new wxAuiToolBar(this, ID_TOOLBAR, wxDefaultPosition, wxDefaultSize, TOOLBAR_STYLE);
356 PopulateToolbar(m_ToolBar);
358 m_Mgr->AddPane(m_ToolBar, wxAuiPaneInfo().
359 Name(wxT("TBMain")).Caption(wxT("TBMain")).
360 ToolbarPane().Top().
361 LeftDockable(false).RightDockable(false).Floatable(false));
363 if (g_pCodeWindow && !m_ToolBarDebug)
365 m_ToolBarDebug = new wxAuiToolBar(this, ID_TOOLBAR_DEBUG, wxDefaultPosition, wxDefaultSize, TOOLBAR_STYLE);
366 g_pCodeWindow->PopulateToolbar(m_ToolBarDebug);
368 m_Mgr->AddPane(m_ToolBarDebug, wxAuiPaneInfo().
369 Name(wxT("TBDebug")).Caption(wxT("TBDebug")).
370 ToolbarPane().Top().
371 LeftDockable(false).RightDockable(false).Floatable(false));
373 m_ToolBarAui = new wxAuiToolBar(this, ID_TOOLBAR_AUI, wxDefaultPosition, wxDefaultSize, TOOLBAR_STYLE);
374 PopulateToolbarAui(m_ToolBarAui);
375 m_Mgr->AddPane(m_ToolBarAui, wxAuiPaneInfo().
376 Name(wxT("TBAui")).Caption(wxT("TBAui")).
377 ToolbarPane().Top().
378 LeftDockable(false).RightDockable(false).Floatable(false));
381 UpdateGUI();
384 void CFrame::InitBitmaps()
386 // Get selected theme
387 int Theme = SConfig::GetInstance().m_LocalCoreStartupParameter.iTheme;
389 // Save memory by only having one set of bitmaps loaded at any time. I mean, they are still
390 // in the exe, which is in memory, but at least we wont make another copy of all of them.
391 switch (Theme)
393 case BOOMY:
395 // These are stored as 48x48
396 m_Bitmaps[Toolbar_FileOpen] = wxGetBitmapFromMemory(toolbar_file_open_png);
397 m_Bitmaps[Toolbar_Refresh] = wxGetBitmapFromMemory(toolbar_refresh_png);
398 m_Bitmaps[Toolbar_Browse] = wxGetBitmapFromMemory(toolbar_browse_png);
399 m_Bitmaps[Toolbar_Play] = wxGetBitmapFromMemory(toolbar_play_png);
400 m_Bitmaps[Toolbar_Stop] = wxGetBitmapFromMemory(toolbar_stop_png);
401 m_Bitmaps[Toolbar_Pause] = wxGetBitmapFromMemory(toolbar_pause_png);
402 m_Bitmaps[Toolbar_PluginOptions]= wxGetBitmapFromMemory(toolbar_plugin_options_png);
403 m_Bitmaps[Toolbar_PluginGFX] = wxGetBitmapFromMemory(toolbar_plugin_gfx_png);
404 m_Bitmaps[Toolbar_PluginDSP] = wxGetBitmapFromMemory(toolbar_plugin_dsp_png);
405 m_Bitmaps[Toolbar_PluginPAD] = wxGetBitmapFromMemory(toolbar_plugin_pad_png);
406 m_Bitmaps[Toolbar_Wiimote] = wxGetBitmapFromMemory(toolbar_plugin_wiimote_png);
407 m_Bitmaps[Toolbar_Screenshot] = wxGetBitmapFromMemory(toolbar_fullscreen_png);
408 m_Bitmaps[Toolbar_FullScreen] = wxGetBitmapFromMemory(toolbar_fullscreen_png);
409 m_Bitmaps[Toolbar_Help] = wxGetBitmapFromMemory(toolbar_help_png);
411 // Scale the 48x48 bitmaps to 24x24
412 for (size_t n = Toolbar_FileOpen; n <= Toolbar_Help; n++)
414 m_Bitmaps[n] = wxBitmap(m_Bitmaps[n].ConvertToImage().Scale(24, 24));
417 break;
419 case VISTA:
421 // These are stored as 24x24 and need no scaling
422 m_Bitmaps[Toolbar_FileOpen] = wxGetBitmapFromMemory(Toolbar_Open1_png);
423 m_Bitmaps[Toolbar_Refresh] = wxGetBitmapFromMemory(Toolbar_Refresh1_png);
424 m_Bitmaps[Toolbar_Browse] = wxGetBitmapFromMemory(Toolbar_Browse1_png);
425 m_Bitmaps[Toolbar_Play] = wxGetBitmapFromMemory(Toolbar_Play1_png);
426 m_Bitmaps[Toolbar_Stop] = wxGetBitmapFromMemory(Toolbar_Stop1_png);
427 m_Bitmaps[Toolbar_Pause] = wxGetBitmapFromMemory(Toolbar_Pause1_png);
428 m_Bitmaps[Toolbar_PluginOptions]= wxGetBitmapFromMemory(Toolbar_Options1_png);
429 m_Bitmaps[Toolbar_PluginGFX] = wxGetBitmapFromMemory(Toolbar_Gfx1_png);
430 m_Bitmaps[Toolbar_PluginDSP] = wxGetBitmapFromMemory(Toolbar_DSP1_png);
431 m_Bitmaps[Toolbar_PluginPAD] = wxGetBitmapFromMemory(Toolbar_Pad1_png);
432 m_Bitmaps[Toolbar_Wiimote] = wxGetBitmapFromMemory(Toolbar_Wiimote1_png);
433 m_Bitmaps[Toolbar_Screenshot] = wxGetBitmapFromMemory(Toolbar_Fullscreen1_png);
434 m_Bitmaps[Toolbar_FullScreen] = wxGetBitmapFromMemory(Toolbar_Fullscreen1_png);
435 m_Bitmaps[Toolbar_Help] = wxGetBitmapFromMemory(Toolbar_Help1_png);
437 break;
439 case XPLASTIK:
441 m_Bitmaps[Toolbar_FileOpen] = wxGetBitmapFromMemory(Toolbar_Open2_png);
442 m_Bitmaps[Toolbar_Refresh] = wxGetBitmapFromMemory(Toolbar_Refresh2_png);
443 m_Bitmaps[Toolbar_Browse] = wxGetBitmapFromMemory(Toolbar_Browse2_png);
444 m_Bitmaps[Toolbar_Play] = wxGetBitmapFromMemory(Toolbar_Play2_png);
445 m_Bitmaps[Toolbar_Stop] = wxGetBitmapFromMemory(Toolbar_Stop2_png);
446 m_Bitmaps[Toolbar_Pause] = wxGetBitmapFromMemory(Toolbar_Pause2_png);
447 m_Bitmaps[Toolbar_PluginOptions]= wxGetBitmapFromMemory(Toolbar_Options2_png);
448 m_Bitmaps[Toolbar_PluginGFX] = wxGetBitmapFromMemory(Toolbar_Gfx2_png);
449 m_Bitmaps[Toolbar_PluginDSP] = wxGetBitmapFromMemory(Toolbar_DSP2_png);
450 m_Bitmaps[Toolbar_PluginPAD] = wxGetBitmapFromMemory(Toolbar_Pad2_png);
451 m_Bitmaps[Toolbar_Wiimote] = wxGetBitmapFromMemory(Toolbar_Wiimote2_png);
452 m_Bitmaps[Toolbar_Screenshot] = wxGetBitmapFromMemory(Toolbar_Fullscreen2_png);
453 m_Bitmaps[Toolbar_FullScreen] = wxGetBitmapFromMemory(Toolbar_Fullscreen2_png);
454 m_Bitmaps[Toolbar_Help] = wxGetBitmapFromMemory(Toolbar_Help2_png);
456 break;
458 case KDE:
460 m_Bitmaps[Toolbar_FileOpen] = wxGetBitmapFromMemory(Toolbar_Open3_png);
461 m_Bitmaps[Toolbar_Refresh] = wxGetBitmapFromMemory(Toolbar_Refresh3_png);
462 m_Bitmaps[Toolbar_Browse] = wxGetBitmapFromMemory(Toolbar_Browse3_png);
463 m_Bitmaps[Toolbar_Play] = wxGetBitmapFromMemory(Toolbar_Play3_png);
464 m_Bitmaps[Toolbar_Stop] = wxGetBitmapFromMemory(Toolbar_Stop3_png);
465 m_Bitmaps[Toolbar_Pause] = wxGetBitmapFromMemory(Toolbar_Pause3_png);
466 m_Bitmaps[Toolbar_PluginOptions]= wxGetBitmapFromMemory(Toolbar_Options3_png);
467 m_Bitmaps[Toolbar_PluginGFX] = wxGetBitmapFromMemory(Toolbar_Gfx3_png);
468 m_Bitmaps[Toolbar_PluginDSP] = wxGetBitmapFromMemory(Toolbar_DSP3_png);
469 m_Bitmaps[Toolbar_PluginPAD] = wxGetBitmapFromMemory(Toolbar_Pad3_png);
470 m_Bitmaps[Toolbar_Wiimote] = wxGetBitmapFromMemory(Toolbar_Wiimote3_png);
471 m_Bitmaps[Toolbar_Screenshot] = wxGetBitmapFromMemory(Toolbar_Fullscreen3_png);
472 m_Bitmaps[Toolbar_FullScreen] = wxGetBitmapFromMemory(Toolbar_Fullscreen3_png);
473 m_Bitmaps[Toolbar_Help] = wxGetBitmapFromMemory(Toolbar_Help3_png);
475 break;
477 default: PanicAlert("Theme selection went wrong");
480 // Update in case the bitmap has been updated
481 if (m_ToolBar != NULL) RecreateToolbar();
483 aNormalFile = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
486 // Game loading state
487 bool game_loading = false;
489 // Menu items
491 // Start the game or change the disc.
492 // Boot priority:
493 // 1. Show the game list and boot the selected game.
494 // 2. Default ISO
495 // 3. Boot last selected game
496 void CFrame::BootGame(const std::string& filename)
498 bool success = false;
499 SCoreStartupParameter& StartUp = SConfig::GetInstance().m_LocalCoreStartupParameter;
501 if (Core::GetState() != Core::CORE_UNINITIALIZED)
502 return;
504 // Start filename if non empty.
505 // Start the selected ISO, or try one of the saved paths.
506 // If all that fails, ask to add a dir and don't boot
507 if (!filename.empty())
508 success = BootManager::BootCore(filename);
509 else if (m_GameListCtrl->GetSelectedISO() != NULL)
511 if (m_GameListCtrl->GetSelectedISO()->IsValid())
512 success = BootManager::BootCore(m_GameListCtrl->GetSelectedISO()->GetFileName());
514 else if (!StartUp.m_strDefaultGCM.empty()
515 && wxFileExists(wxString(StartUp.m_strDefaultGCM.c_str(), wxConvUTF8)))
517 success = BootManager::BootCore(StartUp.m_strDefaultGCM);
519 else
521 if (!SConfig::GetInstance().m_LastFilename.empty()
522 && wxFileExists(wxString(SConfig::GetInstance().m_LastFilename.c_str(), wxConvUTF8)))
524 success = BootManager::BootCore(SConfig::GetInstance().m_LastFilename);
526 else
528 if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain)
529 m_RenderFrame->Destroy();
530 m_GameListCtrl->BrowseForDirectory();
531 game_loading = false;
532 m_GameListCtrl->Enable();
533 m_GameListCtrl->Show();
534 return;
537 if (!success)
539 if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain)
540 m_RenderFrame->Destroy();
541 game_loading = false;
542 m_GameListCtrl->Enable();
543 m_GameListCtrl->Show();
547 // Open file to boot
548 void CFrame::OnOpen(wxCommandEvent& WXUNUSED (event))
550 DoOpen(true);
553 void CFrame::DoOpen(bool Boot)
555 std::string currentDir = File::GetCurrentDir();
557 wxString path = wxFileSelector(
558 _T("Select the file to load"),
559 wxEmptyString, wxEmptyString, wxEmptyString,
560 wxString::Format
562 _T("All GC/Wii files (elf, dol, gcm, iso, wad)|*.elf;*.dol;*.gcm;*.iso;*.gcz;*.wad|All files (%s)|%s"),
563 wxFileSelectorDefaultWildcardStr,
564 wxFileSelectorDefaultWildcardStr
566 wxFD_OPEN | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST,
567 this);
569 bool fileChosen = !path.IsEmpty();
571 std::string currentDir2 = File::GetCurrentDir();
573 if (currentDir != currentDir2)
575 PanicAlert("Current dir changed from %s to %s after wxFileSelector!",currentDir.c_str(),currentDir2.c_str());
576 File::SetCurrentDir(currentDir.c_str());
580 // Should we boot a new game or just change the disc?
581 if (Boot)
583 if (!fileChosen)
584 return;
585 StartGame(std::string(path.mb_str()));
587 else
589 strncpy(newDiscpath, path.mb_str(), strlen(path.mb_str())+1);
590 DVDInterface::ChangeDisc(newDiscpath);
594 void CFrame::OnFrameStep(wxCommandEvent& event)
596 Frame::SetFrameStepping(event.IsChecked());
599 void CFrame::OnChangeDisc(wxCommandEvent& WXUNUSED (event))
601 DoOpen(false);
604 void CFrame::OnRecord(wxCommandEvent& WXUNUSED (event))
606 wxString path = wxFileSelector(
607 _T("Select The Recording File"),
608 wxEmptyString, wxEmptyString, wxEmptyString,
609 wxString::Format
611 _T("Dolphin TAS Movies (*.dtm)|*.dtm|All files (%s)|%s"),
612 wxFileSelectorDefaultWildcardStr,
613 wxFileSelectorDefaultWildcardStr
615 wxFD_SAVE | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST,
616 this);
618 if(path.IsEmpty())
619 return;
621 // TODO: Take controller settings from Gamecube Configuration menu
622 if(Frame::BeginRecordingInput(path.mb_str(), 1))
623 BootGame(std::string(""));
626 void CFrame::OnPlayRecording(wxCommandEvent& WXUNUSED (event))
628 wxString path = wxFileSelector(
629 _T("Select The Recording File"),
630 wxEmptyString, wxEmptyString, wxEmptyString,
631 wxString::Format
633 _T("Dolphin TAS Movies (*.dtm)|*.dtm|All files (%s)|%s"),
634 wxFileSelectorDefaultWildcardStr,
635 wxFileSelectorDefaultWildcardStr
637 wxFD_OPEN | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST,
638 this);
640 if(path.IsEmpty())
641 return;
643 if(Frame::PlayInput(path.mb_str()))
644 BootGame(std::string(""));
647 void CFrame::OnPlay(wxCommandEvent& WXUNUSED (event))
649 if (Core::GetState() != Core::CORE_UNINITIALIZED)
651 // Core is initialized and emulator is running
652 if (UseDebugger)
654 if (CCPU::IsStepping())
655 CCPU::EnableStepping(false);
656 else
657 CCPU::EnableStepping(true); // Break
659 wxThread::Sleep(20);
660 g_pCodeWindow->JumpToAddress(PC);
661 g_pCodeWindow->Update();
662 // Update toolbar with Play/Pause status
663 UpdateGUI();
665 else
666 DoPause();
668 else
669 // Core is uninitialized, start the game
670 StartGame(std::string(""));
673 void CFrame::OnRenderParentClose(wxCloseEvent& event)
675 if ((Core::GetState() == Core::CORE_RUN) || (Core::GetState() == Core::CORE_PAUSE))
676 DoStop();
677 event.Skip();
680 void CFrame::OnRenderParentMove(wxMoveEvent& event)
682 if (!RendererIsFullscreen() && !m_RenderFrame->IsMaximized())
684 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowXPos = m_RenderFrame->GetPosition().x;
685 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowYPos = m_RenderFrame->GetPosition().y;
687 event.Skip();
690 void CFrame::OnRenderParentResize(wxSizeEvent& event)
692 event.Skip();
693 if (Core::GetState() == Core::CORE_RUN || Core::GetState() == Core::CORE_PAUSE)
695 int width, height;
696 if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain &&
697 !RendererIsFullscreen() && !m_RenderFrame->IsMaximized())
699 m_RenderFrame->GetSize(&width, &height);
700 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth = width;
701 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight = height;
703 #if defined(HAVE_X11) && HAVE_X11
704 int x, y;
705 m_RenderParent->GetSize(&width, &height);
706 m_RenderParent->GetPosition(&x, &y);
707 X11_SendClientEvent("RESIZE", x, y, width, height);
708 #endif
712 // Prepare the GUI to start the game.
713 void CFrame::StartGame(const std::string& filename)
715 game_loading = true;
717 if (m_ToolBar)
718 m_ToolBar->EnableTool(IDM_PLAY, false);
719 GetMenuBar()->FindItem(IDM_PLAY)->Enable(false);
721 // Game has been started, hide the game list
722 if (m_GameListCtrl->IsShown())
724 m_GameListCtrl->Disable();
725 m_GameListCtrl->Hide();
728 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain)
730 m_RenderParent = m_Panel;
731 m_RenderFrame = this;
733 else
735 wxPoint position(SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowXPos,
736 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowYPos);
737 wxSize size(SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth,
738 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight);
739 m_RenderFrame = new CRenderFrame((wxFrame*)this, wxID_ANY, _("Dolphin"), position, size);
740 m_RenderFrame->Connect(wxID_ANY, wxEVT_CLOSE_WINDOW,
741 wxCloseEventHandler(CFrame::OnRenderParentClose),
742 (wxObject*)0, this);
743 m_RenderFrame->Connect(wxID_ANY, wxEVT_ACTIVATE,
744 wxActivateEventHandler(CFrame::OnActive),
745 (wxObject*)0, this);
746 m_RenderFrame->Connect(wxID_ANY, wxEVT_MOVE,
747 wxMoveEventHandler(CFrame::OnRenderParentMove),
748 (wxObject*)0, this);
749 m_RenderFrame->Connect(wxID_ANY, wxEVT_KEY_DOWN, // Keyboard
750 wxKeyEventHandler(CFrame::OnKeyDown),
751 (wxObject*)0, this);
752 m_RenderParent = new CPanel(m_RenderFrame, wxID_ANY);
753 m_RenderFrame->Show();
755 m_RenderFrame->Connect(wxID_ANY, wxEVT_SIZE,
756 wxSizeEventHandler(CFrame::OnRenderParentResize),
757 (wxObject*)0, this);
758 #ifdef _WIN32
759 ::SetFocus((HWND)m_RenderParent->GetHandle());
760 #else
761 m_RenderParent->SetFocus();
762 #endif
764 BootGame(filename);
767 void CFrame::OnBootDrive(wxCommandEvent& event)
769 StartGame(drives[event.GetId()-IDM_DRIVE1]);
773 // Refresh the file list and browse for a favorites directory
774 void CFrame::OnRefresh(wxCommandEvent& WXUNUSED (event))
776 if (m_GameListCtrl) m_GameListCtrl->Update();
780 void CFrame::OnBrowse(wxCommandEvent& WXUNUSED (event))
782 if (m_GameListCtrl) m_GameListCtrl->BrowseForDirectory();
785 // Create screenshot
786 void CFrame::OnScreenshot(wxCommandEvent& WXUNUSED (event))
788 Core::ScreenShot();
791 // Pause the emulation
792 void CFrame::DoPause()
794 if (Core::GetState() == Core::CORE_RUN)
796 Core::SetState(Core::CORE_PAUSE);
797 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
798 m_RenderParent->SetCursor(wxCURSOR_ARROW);
800 else
802 Core::SetState(Core::CORE_RUN);
803 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor &&
804 RendererHasFocus())
805 m_RenderParent->SetCursor(wxCURSOR_BLANK);
807 UpdateGUI();
810 // Stop the emulation
811 void CFrame::DoStop()
813 if (Core::GetState() != Core::CORE_UNINITIALIZED)
815 // Ask for confirmation in case the user accidentally clicked Stop / Escape
816 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bConfirmStop)
818 // Suppress duplicate dialog boxes
819 if (m_StopDlg)
820 return;
822 m_StopDlg = new wxMessageDialog(
823 this,
824 wxT("Do you want to stop the current emulation?"),
825 wxT("Please confirm..."),
826 wxYES_NO | wxSTAY_ON_TOP | wxICON_EXCLAMATION,
827 wxDefaultPosition);
829 int Ret = m_StopDlg->ShowModal();
830 m_StopDlg->Destroy();
831 m_StopDlg = NULL;
832 if (Ret == wxID_NO)
833 return;
836 // TODO: Show the author/description dialog here
837 if(Frame::IsRecordingInput())
838 Frame::EndRecordingInput();
839 if(Frame::IsPlayingInput())
840 Frame::EndPlayInput();
842 Core::Stop();
843 UpdateGUI();
845 // Destroy the renderer frame when not rendering to main
846 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
847 m_RenderParent->SetCursor(wxCURSOR_ARROW);
848 if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain)
850 #ifdef _WIN32
851 if (!RendererIsFullscreen() && !m_RenderFrame->IsMaximized())
852 m_RenderFrame->GetSize(&SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth,
853 &SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight);
854 #endif
855 m_RenderFrame->Destroy();
857 m_RenderParent = NULL;
859 // Clean framerate indications from the status bar.
860 m_pStatusBar->SetStatusText(wxT(" "), 0);
864 void CFrame::OnStop(wxCommandEvent& WXUNUSED (event))
866 game_loading = false;
867 DoStop();
870 void CFrame::OnReset(wxCommandEvent& WXUNUSED (event))
872 ProcessorInterface::ResetButton_Tap();
875 void CFrame::OnConfigMain(wxCommandEvent& WXUNUSED (event))
877 CConfigMain ConfigMain(this);
878 if (ConfigMain.ShowModal() == wxID_OK)
879 m_GameListCtrl->Update();
882 void CFrame::OnPluginGFX(wxCommandEvent& WXUNUSED (event))
884 CPluginManager::GetInstance().OpenConfig(
885 GetHandle(),
886 SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoPlugin.c_str(),
887 PLUGIN_TYPE_VIDEO
891 void CFrame::OnPluginDSP(wxCommandEvent& WXUNUSED (event))
893 CPluginManager::GetInstance().OpenConfig(
894 GetHandle(),
895 SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDSPPlugin.c_str(),
896 PLUGIN_TYPE_DSP
900 void CFrame::OnPluginPAD(wxCommandEvent& WXUNUSED (event))
902 CPluginManager::GetInstance().OpenConfig(
903 GetHandle(),
904 SConfig::GetInstance().m_LocalCoreStartupParameter.m_strPadPlugin[0].c_str(),
905 PLUGIN_TYPE_PAD
908 void CFrame::OnPluginWiimote(wxCommandEvent& WXUNUSED (event))
910 CPluginManager::GetInstance().OpenConfig(
911 GetHandle(),
912 SConfig::GetInstance().m_LocalCoreStartupParameter.m_strWiimotePlugin[0].c_str(),
913 PLUGIN_TYPE_WIIMOTE
917 void CFrame::OnHelp(wxCommandEvent& event)
919 switch (event.GetId())
921 case IDM_HELPABOUT:
923 AboutDolphin frame(this);
924 frame.ShowModal();
926 break;
927 case IDM_HELPWEBSITE:
928 WxUtils::Launch("http://www.dolphin-emu.com/");
929 break;
930 case IDM_HELPGOOGLECODE:
931 WxUtils::Launch("http://code.google.com/p/dolphin-emu/");
932 break;
936 void CFrame::ClearStatusBar()
938 if (this->GetStatusBar()->IsEnabled()) this->GetStatusBar()->SetStatusText(wxT(""),0);
941 void CFrame::StatusBarMessage(const char * Text, ...)
943 const int MAX_BYTES = 1024*10;
944 char Str[MAX_BYTES];
945 va_list ArgPtr;
946 int Cnt;
947 va_start(ArgPtr, Text);
948 Cnt = vsnprintf(Str, MAX_BYTES, Text, ArgPtr);
949 va_end(ArgPtr);
951 if (this->GetStatusBar()->IsEnabled()) this->GetStatusBar()->SetStatusText(wxString::FromAscii(Str),0);
955 // Miscellaneous menus
956 // ---------------------
957 // NetPlay stuff
958 void CFrame::OnNetPlay(wxCommandEvent& WXUNUSED (event))
960 #if defined(HAVE_SFML) && HAVE_SFML
961 new NetPlay(this, m_GameListCtrl->GetGamePaths(), m_GameListCtrl->GetGameNames());
962 #endif
965 void CFrame::OnMemcard(wxCommandEvent& WXUNUSED (event))
967 CMemcardManager MemcardManager(this);
968 MemcardManager.ShowModal();
971 void CFrame::OnImportSave(wxCommandEvent& WXUNUSED (event))
973 wxString path = wxFileSelector(_T("Select the save file"),
974 wxEmptyString, wxEmptyString, wxEmptyString,
975 wxString::Format
977 _T("Wii save files|data.bin|All files (%s)|%s"),
978 wxFileSelectorDefaultWildcardStr,
979 wxFileSelectorDefaultWildcardStr
981 wxFD_OPEN | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST,
982 this);
984 if (!path.IsEmpty())
986 CWiiSaveCrypted* saveFile = new CWiiSaveCrypted(path.ToUTF8().data());
987 delete saveFile;
991 void CFrame::OnOpenLuaWindow(wxCommandEvent& WXUNUSED (event))
993 new wxLuaWindow(this, wxDefaultPosition, wxSize(600, 390));
996 void CFrame::OnShow_CheatsWindow(wxCommandEvent& WXUNUSED (event))
998 CheatsWindow = new wxCheatsWindow(this, wxDefaultPosition, wxSize(600, 390));
1001 void CFrame::OnLoadWiiMenu(wxCommandEvent& WXUNUSED (event))
1003 StartGame(std::string (File::GetUserPath(D_WIIMENU_IDX)));
1006 void CFrame::OnConnectWiimote(wxCommandEvent& event)
1008 if (Core::isRunning() && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
1010 int Id = event.GetId() - IDM_CONNECT_WIIMOTE1;
1011 bNoWiimoteMsg = !event.IsChecked();
1012 GetUsbPointer()->AccessWiiMote(Id | 0x100)->Activate(event.IsChecked());
1013 wxString msg(wxString::Format(wxT("Wiimote %i %s"), Id + 1, (event.IsChecked()) ? wxT("Connected") : wxT("Disconnected")));
1014 Core::DisplayMessage(msg.ToAscii(), 3000);
1018 // Toogle fullscreen. In Windows the fullscreen mode is accomplished by expanding the m_Panel to cover
1019 // the entire screen (when we render to the main window).
1020 void CFrame::OnToggleFullscreen(wxCommandEvent& WXUNUSED (event))
1022 DoFullscreen(!RendererIsFullscreen());
1025 void CFrame::OnToggleDualCore(wxCommandEvent& WXUNUSED (event))
1027 SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread = !SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread;
1028 SConfig::GetInstance().SaveSettings();
1031 void CFrame::OnToggleSkipIdle(wxCommandEvent& WXUNUSED (event))
1033 SConfig::GetInstance().m_LocalCoreStartupParameter.bSkipIdle = !SConfig::GetInstance().m_LocalCoreStartupParameter.bSkipIdle;
1034 SConfig::GetInstance().SaveSettings();
1037 void CFrame::OnLoadStateFromFile(wxCommandEvent& WXUNUSED (event))
1039 wxString path = wxFileSelector(
1040 _T("Select the state to load"),
1041 wxEmptyString, wxEmptyString, wxEmptyString,
1042 wxString::Format
1044 _T("All Save States (sav, s##)|*.sav;*.s??|All files (%s)|%s"),
1045 wxFileSelectorDefaultWildcardStr,
1046 wxFileSelectorDefaultWildcardStr
1048 wxFD_OPEN | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST,
1049 this);
1051 if(!path.IsEmpty())
1052 State_LoadAs((const char*)path.mb_str());
1055 void CFrame::OnSaveStateToFile(wxCommandEvent& WXUNUSED (event))
1057 wxString path = wxFileSelector(
1058 _T("Select the state to save"),
1059 wxEmptyString, wxEmptyString, wxEmptyString,
1060 wxString::Format
1062 _T("All Save States (sav, s##)|*.sav;*.s??|All files (%s)|%s"),
1063 wxFileSelectorDefaultWildcardStr,
1064 wxFileSelectorDefaultWildcardStr
1066 wxFD_SAVE,
1067 this);
1069 if(! path.IsEmpty())
1070 State_SaveAs((const char*)path.mb_str());
1073 void CFrame::OnLoadLastState(wxCommandEvent& WXUNUSED (event))
1075 State_LoadLastSaved();
1078 void CFrame::OnUndoLoadState(wxCommandEvent& WXUNUSED (event))
1080 State_UndoLoadState();
1083 void CFrame::OnUndoSaveState(wxCommandEvent& WXUNUSED (event))
1085 State_UndoSaveState();
1089 void CFrame::OnLoadState(wxCommandEvent& event)
1091 int id = event.GetId();
1092 int slot = id - IDM_LOADSLOT1 + 1;
1093 State_Load(slot);
1096 void CFrame::OnSaveState(wxCommandEvent& event)
1098 int id = event.GetId();
1099 int slot = id - IDM_SAVESLOT1 + 1;
1100 State_Save(slot);
1103 void CFrame::OnFrameSkip(wxCommandEvent& event)
1105 int amount = event.GetId() - IDM_FRAMESKIP0;
1107 Frame::SetFrameSkipping((unsigned int)amount);
1113 // GUI
1114 // ---------------------
1116 // Update the enabled/disabled status
1117 void CFrame::UpdateGUI()
1119 if (!m_bControlsCreated)
1120 return;
1122 // Save status
1123 bool Initialized = Core::isRunning();
1124 bool Running = Core::GetState() == Core::CORE_RUN;
1125 bool Paused = Core::GetState() == Core::CORE_PAUSE;
1127 // Make sure that we have a toolbar
1128 if (m_ToolBar)
1130 // Enable/disable the Config and Stop buttons
1131 m_ToolBar->EnableTool(wxID_OPEN, !Initialized);
1132 m_ToolBar->EnableTool(wxID_REFRESH, !Initialized); // Don't allow refresh when we don't show the list
1133 m_ToolBar->EnableTool(IDM_STOP, Running || Paused);
1134 m_ToolBar->EnableTool(IDM_TOGGLE_FULLSCREEN, Running || Paused);
1135 m_ToolBar->EnableTool(IDM_SCREENSHOT, Running || Paused);
1138 // File
1139 GetMenuBar()->FindItem(wxID_OPEN)->Enable(!Initialized);
1140 m_pSubMenuDrive->Enable(!Initialized);
1141 GetMenuBar()->FindItem(wxID_REFRESH)->Enable(!Initialized);
1142 GetMenuBar()->FindItem(IDM_BROWSE)->Enable(!Initialized);
1144 // Emulation
1145 GetMenuBar()->FindItem(IDM_STOP)->Enable(Running || Paused);
1146 GetMenuBar()->FindItem(IDM_RESET)->Enable(Running || Paused);
1147 GetMenuBar()->FindItem(IDM_RECORD)->Enable(!Initialized);
1148 GetMenuBar()->FindItem(IDM_PLAYRECORD)->Enable(!Initialized);
1149 GetMenuBar()->FindItem(IDM_FRAMESTEP)->Enable(Running || Paused);
1150 GetMenuBar()->FindItem(IDM_SCREENSHOT)->Enable(Running || Paused);
1151 GetMenuBar()->FindItem(IDM_TOGGLE_FULLSCREEN)->Enable(Running || Paused);
1153 // Update Menu Accelerators
1154 GetMenuBar()->FindItem(IDM_TOGGLE_FULLSCREEN)->SetItemLabel(GetMenuLabel(HK_FULLSCREEN));
1155 GetMenuBar()->FindItem(IDM_PLAY)->SetItemLabel(GetMenuLabel(HK_PLAY_PAUSE));
1156 GetMenuBar()->FindItem(IDM_STOP)->SetItemLabel(GetMenuLabel(HK_STOP));
1158 m_pSubMenuLoad->Enable(Initialized);
1159 m_pSubMenuSave->Enable(Initialized);
1161 // Misc
1162 GetMenuBar()->FindItem(IDM_CHANGEDISC)->Enable(Initialized);
1163 if (DiscIO::CNANDContentManager::Access().GetNANDLoader(std::string(File::GetUserPath(D_WIIMENU_IDX))).IsValid())
1164 GetMenuBar()->FindItem(IDM_LOAD_WII_MENU)->Enable(!Initialized);
1166 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE1)->Enable(Initialized && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii);
1167 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE2)->Enable(Initialized && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii);
1168 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE3)->Enable(Initialized && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii);
1169 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE4)->Enable(Initialized && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii);
1170 if (Initialized && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
1172 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE1)->Check(GetUsbPointer()->AccessWiiMote(0x0100)->IsConnected() == 3);
1173 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE2)->Check(GetUsbPointer()->AccessWiiMote(0x0101)->IsConnected() == 3);
1174 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE3)->Check(GetUsbPointer()->AccessWiiMote(0x0102)->IsConnected() == 3);
1175 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE4)->Check(GetUsbPointer()->AccessWiiMote(0x0103)->IsConnected() == 3);
1178 if (Running)
1180 if (m_ToolBar)
1182 m_ToolBar->SetToolBitmap(IDM_PLAY, m_Bitmaps[Toolbar_Pause]);
1183 m_ToolBar->SetToolShortHelp(IDM_PLAY, _("Pause"));
1184 m_ToolBar->SetToolLabel(IDM_PLAY, _("Pause"));
1187 else
1189 if (m_ToolBar)
1191 m_ToolBar->SetToolBitmap(IDM_PLAY, m_Bitmaps[Toolbar_Play]);
1192 m_ToolBar->SetToolShortHelp(IDM_PLAY, _("Play"));
1193 m_ToolBar->SetToolLabel(IDM_PLAY, wxT(" Play "));
1197 if (!Initialized)
1199 if (m_GameListCtrl->IsEnabled())
1201 // Prepare to load Default ISO, enable play button
1202 if (!SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDefaultGCM.empty())
1204 if (m_ToolBar)
1205 m_ToolBar->EnableTool(IDM_PLAY, true);
1206 GetMenuBar()->FindItem(IDM_PLAY)->Enable(true);
1208 // Prepare to load last selected file, enable play button
1209 else if (!SConfig::GetInstance().m_LastFilename.empty()
1210 && wxFileExists(wxString(SConfig::GetInstance().m_LastFilename.c_str(), wxConvUTF8)))
1212 if (m_ToolBar)
1213 m_ToolBar->EnableTool(IDM_PLAY, true);
1214 GetMenuBar()->FindItem(IDM_PLAY)->Enable(true);
1216 else
1218 // No game has been selected yet, disable play button
1219 if (m_ToolBar)
1220 m_ToolBar->EnableTool(IDM_PLAY, false);
1221 GetMenuBar()->FindItem(IDM_PLAY)->Enable(false);
1225 if (m_GameListCtrl && !game_loading)
1227 // Game has not started, show game list
1228 if (!m_GameListCtrl->IsShown())
1230 m_GameListCtrl->Reparent(m_Panel);
1231 m_GameListCtrl->Enable();
1232 m_GameListCtrl->Show();
1233 sizerPanel->FitInside(m_Panel);
1235 // Game has been selected but not started, enable play button
1236 if (m_GameListCtrl->GetSelectedISO() != NULL && m_GameListCtrl->IsEnabled() && !game_loading)
1238 if (m_ToolBar)
1239 m_ToolBar->EnableTool(IDM_PLAY, true);
1240 GetMenuBar()->FindItem(IDM_PLAY)->Enable(true);
1244 else
1246 // Game has been loaded, enable the play button
1247 if (m_ToolBar)
1248 m_ToolBar->EnableTool(IDM_PLAY, true);
1249 GetMenuBar()->FindItem(IDM_PLAY)->Enable(true);
1251 // Reset game loading flag
1252 game_loading = false;
1255 if (m_ToolBar) m_ToolBar->Refresh();
1256 if (g_pCodeWindow) g_pCodeWindow->Update();
1258 // Commit changes to manager
1259 m_Mgr->Update();
1262 void CFrame::GameListChanged(wxCommandEvent& event)
1264 switch (event.GetId())
1266 case IDM_LISTWII:
1267 SConfig::GetInstance().m_ListWii = event.IsChecked();
1268 break;
1269 case IDM_LISTGC:
1270 SConfig::GetInstance().m_ListGC = event.IsChecked();
1271 break;
1272 case IDM_LISTWAD:
1273 SConfig::GetInstance().m_ListWad = event.IsChecked();
1274 break;
1275 case IDM_LISTJAP:
1276 SConfig::GetInstance().m_ListJap = event.IsChecked();
1277 break;
1278 case IDM_LISTPAL:
1279 SConfig::GetInstance().m_ListPal = event.IsChecked();
1280 break;
1281 case IDM_LISTUSA:
1282 SConfig::GetInstance().m_ListUsa = event.IsChecked();
1283 break;
1284 case IDM_LISTFRANCE:
1285 SConfig::GetInstance().m_ListFrance = event.IsChecked();
1286 break;
1287 case IDM_LISTITALY:
1288 SConfig::GetInstance().m_ListItaly = event.IsChecked();
1289 break;
1290 case IDM_LISTKOREA:
1291 SConfig::GetInstance().m_ListKorea = event.IsChecked();
1292 break;
1293 case IDM_LISTTAIWAN:
1294 SConfig::GetInstance().m_ListTaiwan = event.IsChecked();
1295 break;
1296 case IDM_LIST_UNK:
1297 SConfig::GetInstance().m_ListUnknown = event.IsChecked();
1298 break;
1299 case IDM_LISTDRIVES:
1300 SConfig::GetInstance().m_ListDrives = event.IsChecked();
1301 break;
1302 case IDM_PURGECACHE:
1303 CFileSearch::XStringVector Directories;
1304 Directories.push_back(File::GetUserPath(D_CACHE_IDX));
1305 CFileSearch::XStringVector Extensions;
1306 Extensions.push_back("*.cache");
1308 CFileSearch FileSearch(Extensions, Directories);
1309 const CFileSearch::XStringVector& rFilenames = FileSearch.GetFileNames();
1311 for (u32 i = 0; i < rFilenames.size(); i++)
1313 File::Delete(rFilenames[i].c_str());
1315 break;
1318 if (m_GameListCtrl) m_GameListCtrl->Update();
1321 // Enable and disable the toolbar
1322 void CFrame::OnToggleToolbar(wxCommandEvent& event)
1324 SConfig::GetInstance().m_InterfaceToolbar = event.IsChecked();
1325 DoToggleToolbar(event.IsChecked());
1327 void CFrame::DoToggleToolbar(bool _show)
1329 if (_show)
1331 m_Mgr->GetPane(wxT("TBMain")).Show();
1332 if (g_pCodeWindow) { m_Mgr->GetPane(wxT("TBDebug")).Show(); m_Mgr->GetPane(wxT("TBAui")).Show(); }
1333 m_Mgr->Update();
1335 else
1337 m_Mgr->GetPane(wxT("TBMain")).Hide();
1338 if (g_pCodeWindow) { m_Mgr->GetPane(wxT("TBDebug")).Hide(); m_Mgr->GetPane(wxT("TBAui")).Hide(); }
1339 m_Mgr->Update();
1343 // Enable and disable the status bar
1344 void CFrame::OnToggleStatusbar(wxCommandEvent& event)
1346 SConfig::GetInstance().m_InterfaceStatusbar = event.IsChecked();
1347 if (SConfig::GetInstance().m_InterfaceStatusbar == true)
1348 m_pStatusBar->Show();
1349 else
1350 m_pStatusBar->Hide();
1352 this->SendSizeEvent();