Lots more work on making the frame aui stuff functional.
[dolphin.git] / Source / Core / DolphinWX / Src / FrameTools.cpp
blob24fe21797c59acde068fb57aa4a573bdf82463d8
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 "HW/GCPad.h"
60 #include "IPC_HLE/WII_IPC_HLE_Device_usb.h"
61 #include "State.h"
62 #include "VolumeHandler.h"
63 #include "NANDContentLoader.h"
64 #include "WXInputBase.h"
65 #include "../../InputUICommon/Src/ConfigDiag.h"
67 #include <wx/datetime.h> // wxWidgets
70 // Resources
71 extern "C" {
72 #include "../resources/Dolphin.c" // Dolphin icon
73 #include "../resources/toolbar_browse.c"
74 #include "../resources/toolbar_file_open.c"
75 #include "../resources/toolbar_fullscreen.c"
76 #include "../resources/toolbar_help.c"
77 #include "../resources/toolbar_pause.c"
78 #include "../resources/toolbar_play.c"
79 #include "../resources/toolbar_plugin_dsp.c"
80 #include "../resources/toolbar_plugin_gfx.c"
81 #include "../resources/toolbar_plugin_options.c"
82 #include "../resources/toolbar_plugin_pad.c"
83 #include "../resources/toolbar_plugin_wiimote.c"
84 #include "../resources/toolbar_refresh.c"
85 #include "../resources/toolbar_stop.c"
86 #include "../resources/Boomy.h" // Theme packages
87 #include "../resources/Vista.h"
88 #include "../resources/X-Plastik.h"
89 #include "../resources/KDE.h"
93 // Other Windows
94 wxCheatsWindow* CheatsWindow;
97 // Create menu items
98 // ---------------------
99 void CFrame::CreateMenu()
101 if (GetMenuBar()) GetMenuBar()->Destroy();
103 m_MenuBar = new wxMenuBar(wxMB_DOCKABLE);
105 // file menu
106 wxMenu* fileMenu = new wxMenu;
107 fileMenu->Append(wxID_OPEN, _T("&Open...\tCtrl+O"));
109 wxMenu *externalDrive = new wxMenu;
110 m_pSubMenuDrive = fileMenu->AppendSubMenu(externalDrive, _T("&Boot from DVD Drive..."));
112 drives = cdio_get_devices();
113 // Windows Limitation of 24 character drives
114 for (unsigned int i = 0; i < drives.size() && i < 24; i++) {
115 externalDrive->Append(IDM_DRIVE1 + i, wxString::FromAscii(drives[i].c_str()));
118 fileMenu->AppendSeparator();
119 fileMenu->Append(wxID_REFRESH, _T("&Refresh List"));
120 fileMenu->AppendSeparator();
121 fileMenu->Append(IDM_BROWSE, _T("&Browse for ISOs..."));
122 fileMenu->AppendSeparator();
123 fileMenu->Append(wxID_EXIT, _T("E&xit\tAlt+F4"));
124 m_MenuBar->Append(fileMenu, _T("&File"));
126 // Emulation menu
127 wxMenu* emulationMenu = new wxMenu;
128 emulationMenu->Append(IDM_PLAY, GetMenuLabel(HK_PLAY_PAUSE));
129 emulationMenu->Append(IDM_STOP, GetMenuLabel(HK_STOP));
130 emulationMenu->Append(IDM_RESET, _T("&Reset"));
131 emulationMenu->AppendSeparator();
132 emulationMenu->Append(IDM_TOGGLE_FULLSCREEN, GetMenuLabel(HK_FULLSCREEN));
133 emulationMenu->AppendSeparator();
134 emulationMenu->Append(IDM_RECORD, _T("Start Re&cording..."));
135 emulationMenu->Append(IDM_PLAYRECORD, _T("P&lay Recording..."));
136 emulationMenu->AppendSeparator();
137 emulationMenu->Append(IDM_CHANGEDISC, _T("Change &Disc"));
139 emulationMenu->Append(IDM_FRAMESTEP, _T("&Frame Stepping"), wxEmptyString, wxITEM_CHECK);
141 wxMenu *skippingMenu = new wxMenu;
142 m_pSubMenuFrameSkipping = emulationMenu->AppendSubMenu(skippingMenu, _T("Frame S&kipping"));
143 for(int i = 0; i < 10; i++)
144 skippingMenu->Append(IDM_FRAMESKIP0 + i, wxString::Format(_T("%i"), i), wxEmptyString, wxITEM_RADIO);
146 emulationMenu->AppendSeparator();
147 emulationMenu->Append(IDM_SCREENSHOT, _T("Take S&creenshot\tF9"));
148 emulationMenu->AppendSeparator();
149 wxMenu *saveMenu = new wxMenu;
150 wxMenu *loadMenu = new wxMenu;
151 m_pSubMenuLoad = emulationMenu->AppendSubMenu(loadMenu, _T("&Load State"));
152 m_pSubMenuSave = emulationMenu->AppendSubMenu(saveMenu, _T("Sa&ve State"));
154 saveMenu->Append(IDM_SAVESTATEFILE, _T("Save State..."));
155 loadMenu->Append(IDM_UNDOSAVESTATE, _T("Last Overwritten State\tShift+F12"));
156 saveMenu->AppendSeparator();
158 loadMenu->Append(IDM_LOADSTATEFILE, _T("Load State..."));
159 loadMenu->Append(IDM_LOADLASTSTATE, _T("Last Saved State\tF11"));
160 loadMenu->Append(IDM_UNDOLOADSTATE, _T("Undo Load State\tF12"));
161 loadMenu->AppendSeparator();
163 for (int i = 1; i <= 8; i++) {
164 loadMenu->Append(IDM_LOADSLOT1 + i - 1, wxString::Format(_T("Slot %i\tF%i"), i, i));
165 saveMenu->Append(IDM_SAVESLOT1 + i - 1, wxString::Format(_T("Slot %i\tShift+F%i"), i, i));
167 m_MenuBar->Append(emulationMenu, _T("&Emulation"));
169 // Options menu
170 wxMenu* pOptionsMenu = new wxMenu;
171 pOptionsMenu->Append(wxID_PREFERENCES, _T("Co&nfigure..."));
172 pOptionsMenu->AppendSeparator();
173 pOptionsMenu->Append(IDM_CONFIG_GFX_PLUGIN, _T("&Graphics Settings"));
174 pOptionsMenu->Append(IDM_CONFIG_DSP_PLUGIN, _T("&DSP Settings"));
175 pOptionsMenu->Append(IDM_CONFIG_PAD_PLUGIN, _T("&Gamecube Pad Settings"));
176 pOptionsMenu->Append(IDM_CONFIG_WIIMOTE_PLUGIN, _T("&Wiimote Settings"));
177 if (g_pCodeWindow)
179 pOptionsMenu->AppendSeparator();
180 g_pCodeWindow->CreateMenuOptions(NULL, pOptionsMenu);
182 m_MenuBar->Append(pOptionsMenu, _T("&Options"));
184 // Tools menu
185 wxMenu* toolsMenu = new wxMenu;
186 toolsMenu->Append(IDM_LUA, _T("New &Lua Console"));
187 toolsMenu->Append(IDM_MEMCARD, _T("&Memcard Manager (GC)"));
188 toolsMenu->Append(IDM_IMPORTSAVE, _T("Wii Save Import"));
189 toolsMenu->Append(IDM_CHEATS, _T("&Cheats Manager"));
191 toolsMenu->Append(IDM_NETPLAY, _T("Start &NetPlay"));
193 if (DiscIO::CNANDContentManager::Access().GetNANDLoader(std::string (File::GetUserPath(D_WIIMENU_IDX))).IsValid())
195 toolsMenu->Append(IDM_LOAD_WII_MENU, _T("Load Wii Menu"));
197 else
199 toolsMenu->Append(IDM_INSTALL_WII_MENU, _T("Install Wii Menu"));
201 toolsMenu->AppendSeparator();
202 toolsMenu->AppendCheckItem(IDM_CONNECT_WIIMOTE1, GetMenuLabel(HK_WIIMOTE1_CONNECT));
203 toolsMenu->AppendCheckItem(IDM_CONNECT_WIIMOTE2, GetMenuLabel(HK_WIIMOTE2_CONNECT));
204 toolsMenu->AppendCheckItem(IDM_CONNECT_WIIMOTE3, GetMenuLabel(HK_WIIMOTE3_CONNECT));
205 toolsMenu->AppendCheckItem(IDM_CONNECT_WIIMOTE4, GetMenuLabel(HK_WIIMOTE4_CONNECT));
207 m_MenuBar->Append(toolsMenu, _T("&Tools"));
209 wxMenu* viewMenu = new wxMenu;
210 viewMenu->AppendCheckItem(IDM_TOGGLE_TOOLBAR, _T("Show &Toolbar"));
211 viewMenu->Check(IDM_TOGGLE_TOOLBAR, SConfig::GetInstance().m_InterfaceToolbar);
212 viewMenu->AppendCheckItem(IDM_TOGGLE_STATUSBAR, _T("Show &Statusbar"));
213 viewMenu->Check(IDM_TOGGLE_STATUSBAR, SConfig::GetInstance().m_InterfaceStatusbar);
214 viewMenu->AppendSeparator();
215 viewMenu->AppendCheckItem(IDM_LOGWINDOW, _T("Show &Logwindow"));
216 viewMenu->Check(IDM_LOGWINDOW, SConfig::GetInstance().m_InterfaceLogWindow);
217 viewMenu->AppendCheckItem(IDM_CONSOLEWINDOW, _T("Show &Console"));
218 viewMenu->Check(IDM_CONSOLEWINDOW, SConfig::GetInstance().m_InterfaceConsole);
219 viewMenu->AppendSeparator();
221 if (g_pCodeWindow)
223 g_pCodeWindow->CreateMenuView(NULL, viewMenu);
224 viewMenu->AppendSeparator();
227 wxMenu *platformMenu = new wxMenu;
228 viewMenu->AppendSubMenu(platformMenu, _T("Show Platforms"));
229 platformMenu->AppendCheckItem(IDM_LISTWII, _T("Show Wii"));
230 platformMenu->Check(IDM_LISTWII, SConfig::GetInstance().m_ListWii);
231 platformMenu->AppendCheckItem(IDM_LISTGC, _T("Show GameCube"));
232 platformMenu->Check(IDM_LISTGC, SConfig::GetInstance().m_ListGC);
233 platformMenu->AppendCheckItem(IDM_LISTWAD, _T("Show Wad"));
234 platformMenu->Check(IDM_LISTWAD, SConfig::GetInstance().m_ListWad);
236 wxMenu *regionMenu = new wxMenu;
237 viewMenu->AppendSubMenu(regionMenu, _T("Show Regions"));
238 regionMenu->AppendCheckItem(IDM_LISTJAP, _T("Show JAP"));
239 regionMenu->Check(IDM_LISTJAP, SConfig::GetInstance().m_ListJap);
240 regionMenu->AppendCheckItem(IDM_LISTPAL, _T("Show PAL"));
241 regionMenu->Check(IDM_LISTPAL, SConfig::GetInstance().m_ListPal);
242 regionMenu->AppendCheckItem(IDM_LISTUSA, _T("Show USA"));
243 regionMenu->Check(IDM_LISTUSA, SConfig::GetInstance().m_ListUsa);
244 regionMenu->AppendSeparator();
245 regionMenu->AppendCheckItem(IDM_LISTFRANCE, _T("Show France"));
246 regionMenu->Check(IDM_LISTFRANCE, SConfig::GetInstance().m_ListFrance);
247 regionMenu->AppendCheckItem(IDM_LISTITALY, _T("Show Italy"));
248 regionMenu->Check(IDM_LISTITALY, SConfig::GetInstance().m_ListItaly);
249 regionMenu->AppendCheckItem(IDM_LISTKOREA, _T("Show Korea"));
250 regionMenu->Check(IDM_LISTKOREA, SConfig::GetInstance().m_ListKorea);
251 regionMenu->AppendCheckItem(IDM_LISTTAIWAN, _T("Show Taiwan"));
252 regionMenu->Check(IDM_LISTTAIWAN, SConfig::GetInstance().m_ListTaiwan);
253 regionMenu->AppendCheckItem(IDM_LIST_UNK, _T("Show unknown"));
254 regionMenu->Check(IDM_LIST_UNK, SConfig::GetInstance().m_ListUnknown);
255 viewMenu->AppendCheckItem(IDM_LISTDRIVES, _T("Show Drives"));
256 viewMenu->Check(IDM_LISTDRIVES, SConfig::GetInstance().m_ListDrives);
257 viewMenu->Append(IDM_PURGECACHE, _T("Purge Cache"));
258 m_MenuBar->Append(viewMenu, _T("&View"));
260 if (g_pCodeWindow) g_pCodeWindow->CreateMenu(SConfig::GetInstance().m_LocalCoreStartupParameter, m_MenuBar);
262 // Help menu
263 wxMenu* helpMenu = new wxMenu;
264 // Re-enable when there's something useful to display */
265 // helpMenu->Append(wxID_HELP, _T("&Help"));
266 helpMenu->Append(IDM_HELPWEBSITE, _T("Dolphin &Web Site"));
267 helpMenu->Append(IDM_HELPGOOGLECODE, _T("Dolphin at &Google Code"));
268 helpMenu->AppendSeparator();
269 helpMenu->Append(wxID_ABOUT, _T("&About..."));
270 m_MenuBar->Append(helpMenu, _T("&Help"));
272 // Associate the menu bar with the frame
273 SetMenuBar(m_MenuBar);
276 wxString CFrame::GetMenuLabel(int Id)
278 wxString Label;
279 switch (Id)
281 case HK_FULLSCREEN:
282 Label = _T("&Fullscreen\t");
283 break;
284 case HK_PLAY_PAUSE:
285 if (Core::GetState() == Core::CORE_RUN)
286 Label = _T("&Pause\t");
287 else
288 Label = _T("&Play\t");
289 break;
290 case HK_STOP:
291 Label = _T("&Stop\t");
292 break;
293 case HK_WIIMOTE1_CONNECT:
294 Label = _T("Connect Wiimote 1\t");
295 break;
296 case HK_WIIMOTE2_CONNECT:
297 Label = _T("Connect Wiimote 2\t");
298 break;
299 case HK_WIIMOTE3_CONNECT:
300 Label = _T("Connect Wiimote 3\t");
301 break;
302 case HK_WIIMOTE4_CONNECT:
303 Label = _T("Connect Wiimote 4\t");
304 break;
307 wxString Modifier = InputCommon::WXKeymodToString
308 (SConfig::GetInstance().m_LocalCoreStartupParameter.iHotkeyModifier[Id]);
309 wxString Hotkey = InputCommon::WXKeyToString
310 (SConfig::GetInstance().m_LocalCoreStartupParameter.iHotkey[Id]);
312 return Label + Modifier + (Modifier.Len() ? _T("+") : _T("")) + Hotkey;
316 // Create toolbar items
317 // ---------------------
318 void CFrame::PopulateToolbar(wxAuiToolBar* ToolBar)
320 int w = m_Bitmaps[Toolbar_FileOpen].GetWidth(),
321 h = m_Bitmaps[Toolbar_FileOpen].GetHeight();
322 ToolBar->SetToolBitmapSize(wxSize(w, h));
325 ToolBar->AddTool(wxID_OPEN, _T("Open"), m_Bitmaps[Toolbar_FileOpen], _T("Open file..."));
326 ToolBar->AddTool(wxID_REFRESH, _T("Refresh"), m_Bitmaps[Toolbar_Refresh], _T("Refresh game list"));
327 ToolBar->AddTool(IDM_BROWSE, _T("Browse"), m_Bitmaps[Toolbar_Browse], _T("Browse for an ISO directory..."));
328 ToolBar->AddSeparator();
329 ToolBar->AddTool(IDM_PLAY, wxT("Play"), m_Bitmaps[Toolbar_Play], _T("Play"));
330 ToolBar->AddTool(IDM_STOP, _T("Stop"), m_Bitmaps[Toolbar_Stop], _T("Stop"));
331 ToolBar->AddTool(IDM_TOGGLE_FULLSCREEN, _T("FullScr"), m_Bitmaps[Toolbar_FullScreen], _T("Toggle Fullscreen"));
332 ToolBar->AddTool(IDM_SCREENSHOT, _T("ScrShot"), m_Bitmaps[Toolbar_FullScreen], _T("Take Screenshot"));
333 ToolBar->AddSeparator();
334 ToolBar->AddTool(wxID_PREFERENCES, _T("Config"), m_Bitmaps[Toolbar_PluginOptions], _T("Configure..."));
335 ToolBar->AddTool(IDM_CONFIG_GFX_PLUGIN, _T("Graphics"), m_Bitmaps[Toolbar_PluginGFX], _T("Graphics settings"));
336 ToolBar->AddTool(IDM_CONFIG_DSP_PLUGIN, _T("DSP"), m_Bitmaps[Toolbar_PluginDSP], _T("DSP settings"));
337 ToolBar->AddTool(IDM_CONFIG_PAD_PLUGIN, _T("GCPad"), m_Bitmaps[Toolbar_PluginPAD], _T("Gamecube Pad settings"));
338 ToolBar->AddTool(IDM_CONFIG_WIIMOTE_PLUGIN, _T("Wiimote"), m_Bitmaps[Toolbar_Wiimote], _T("Wiimote settings"));
340 // after adding the buttons to the toolbar, must call Realize() to reflect
341 // the changes
342 ToolBar->Realize();
345 void CFrame::PopulateToolbarAui(wxAuiToolBar* ToolBar)
347 int w = m_Bitmaps[Toolbar_FileOpen].GetWidth(),
348 h = m_Bitmaps[Toolbar_FileOpen].GetHeight();
349 ToolBar->SetToolBitmapSize(wxSize(w, h));
351 ToolBar->AddTool(IDM_SAVE_PERSPECTIVE, wxT("Save"), g_pCodeWindow->m_Bitmaps[Toolbar_GotoPC], wxT("Save current perspective"));
352 ToolBar->AddTool(IDM_EDIT_PERSPECTIVES, wxT("Edit"), g_pCodeWindow->m_Bitmaps[Toolbar_GotoPC], wxT("Edit current perspective"));
354 ToolBar->SetToolDropDown(IDM_SAVE_PERSPECTIVE, true);
355 ToolBar->SetToolDropDown(IDM_EDIT_PERSPECTIVES, true);
357 ToolBar->Realize();
361 // Delete and recreate the toolbar
362 void CFrame::RecreateToolbar()
364 if (m_ToolBar)
366 m_Mgr->DetachPane(m_ToolBar);
367 m_ToolBar->Destroy();
370 m_ToolBar = new wxAuiToolBar(this, ID_TOOLBAR, wxDefaultPosition, wxDefaultSize, TOOLBAR_STYLE);
372 PopulateToolbar(m_ToolBar);
374 m_Mgr->AddPane(m_ToolBar, wxAuiPaneInfo().
375 Name(wxT("TBMain")).Caption(wxT("TBMain")).
376 ToolbarPane().Top().
377 LeftDockable(false).RightDockable(false).Floatable(false));
379 if (g_pCodeWindow && !m_ToolBarDebug)
381 m_ToolBarDebug = new wxAuiToolBar(this, ID_TOOLBAR_DEBUG, wxDefaultPosition, wxDefaultSize, TOOLBAR_STYLE);
382 g_pCodeWindow->PopulateToolbar(m_ToolBarDebug);
384 m_Mgr->AddPane(m_ToolBarDebug, wxAuiPaneInfo().
385 Name(wxT("TBDebug")).Caption(wxT("TBDebug")).
386 ToolbarPane().Top().
387 LeftDockable(false).RightDockable(false).Floatable(false));
389 m_ToolBarAui = new wxAuiToolBar(this, ID_TOOLBAR_AUI, wxDefaultPosition, wxDefaultSize, TOOLBAR_STYLE);
390 PopulateToolbarAui(m_ToolBarAui);
391 m_Mgr->AddPane(m_ToolBarAui, wxAuiPaneInfo().
392 Name(wxT("TBAui")).Caption(wxT("TBAui")).
393 ToolbarPane().Top().
394 LeftDockable(false).RightDockable(false).Floatable(false));
397 UpdateGUI();
400 void CFrame::InitBitmaps()
402 // Get selected theme
403 int Theme = SConfig::GetInstance().m_LocalCoreStartupParameter.iTheme;
405 // Save memory by only having one set of bitmaps loaded at any time. I mean, they are still
406 // in the exe, which is in memory, but at least we wont make another copy of all of them.
407 switch (Theme)
409 case BOOMY:
411 // These are stored as 48x48
412 m_Bitmaps[Toolbar_FileOpen] = wxGetBitmapFromMemory(toolbar_file_open_png);
413 m_Bitmaps[Toolbar_Refresh] = wxGetBitmapFromMemory(toolbar_refresh_png);
414 m_Bitmaps[Toolbar_Browse] = wxGetBitmapFromMemory(toolbar_browse_png);
415 m_Bitmaps[Toolbar_Play] = wxGetBitmapFromMemory(toolbar_play_png);
416 m_Bitmaps[Toolbar_Stop] = wxGetBitmapFromMemory(toolbar_stop_png);
417 m_Bitmaps[Toolbar_Pause] = wxGetBitmapFromMemory(toolbar_pause_png);
418 m_Bitmaps[Toolbar_PluginOptions]= wxGetBitmapFromMemory(toolbar_plugin_options_png);
419 m_Bitmaps[Toolbar_PluginGFX] = wxGetBitmapFromMemory(toolbar_plugin_gfx_png);
420 m_Bitmaps[Toolbar_PluginDSP] = wxGetBitmapFromMemory(toolbar_plugin_dsp_png);
421 m_Bitmaps[Toolbar_PluginPAD] = wxGetBitmapFromMemory(toolbar_plugin_pad_png);
422 m_Bitmaps[Toolbar_Wiimote] = wxGetBitmapFromMemory(toolbar_plugin_wiimote_png);
423 m_Bitmaps[Toolbar_Screenshot] = wxGetBitmapFromMemory(toolbar_fullscreen_png);
424 m_Bitmaps[Toolbar_FullScreen] = wxGetBitmapFromMemory(toolbar_fullscreen_png);
425 m_Bitmaps[Toolbar_Help] = wxGetBitmapFromMemory(toolbar_help_png);
427 // Scale the 48x48 bitmaps to 24x24
428 for (size_t n = Toolbar_FileOpen; n < EToolbar_Max; n++)
430 m_Bitmaps[n] = wxBitmap(m_Bitmaps[n].ConvertToImage().Scale(24, 24));
433 break;
435 case VISTA:
437 // These are stored as 24x24 and need no scaling
438 m_Bitmaps[Toolbar_FileOpen] = wxGetBitmapFromMemory(Toolbar_Open1_png);
439 m_Bitmaps[Toolbar_Refresh] = wxGetBitmapFromMemory(Toolbar_Refresh1_png);
440 m_Bitmaps[Toolbar_Browse] = wxGetBitmapFromMemory(Toolbar_Browse1_png);
441 m_Bitmaps[Toolbar_Play] = wxGetBitmapFromMemory(Toolbar_Play1_png);
442 m_Bitmaps[Toolbar_Stop] = wxGetBitmapFromMemory(Toolbar_Stop1_png);
443 m_Bitmaps[Toolbar_Pause] = wxGetBitmapFromMemory(Toolbar_Pause1_png);
444 m_Bitmaps[Toolbar_PluginOptions]= wxGetBitmapFromMemory(Toolbar_Options1_png);
445 m_Bitmaps[Toolbar_PluginGFX] = wxGetBitmapFromMemory(Toolbar_Gfx1_png);
446 m_Bitmaps[Toolbar_PluginDSP] = wxGetBitmapFromMemory(Toolbar_DSP1_png);
447 m_Bitmaps[Toolbar_PluginPAD] = wxGetBitmapFromMemory(Toolbar_Pad1_png);
448 m_Bitmaps[Toolbar_Wiimote] = wxGetBitmapFromMemory(Toolbar_Wiimote1_png);
449 m_Bitmaps[Toolbar_Screenshot] = wxGetBitmapFromMemory(Toolbar_Fullscreen1_png);
450 m_Bitmaps[Toolbar_FullScreen] = wxGetBitmapFromMemory(Toolbar_Fullscreen1_png);
451 m_Bitmaps[Toolbar_Help] = wxGetBitmapFromMemory(Toolbar_Help1_png);
453 break;
455 case XPLASTIK:
457 m_Bitmaps[Toolbar_FileOpen] = wxGetBitmapFromMemory(Toolbar_Open2_png);
458 m_Bitmaps[Toolbar_Refresh] = wxGetBitmapFromMemory(Toolbar_Refresh2_png);
459 m_Bitmaps[Toolbar_Browse] = wxGetBitmapFromMemory(Toolbar_Browse2_png);
460 m_Bitmaps[Toolbar_Play] = wxGetBitmapFromMemory(Toolbar_Play2_png);
461 m_Bitmaps[Toolbar_Stop] = wxGetBitmapFromMemory(Toolbar_Stop2_png);
462 m_Bitmaps[Toolbar_Pause] = wxGetBitmapFromMemory(Toolbar_Pause2_png);
463 m_Bitmaps[Toolbar_PluginOptions]= wxGetBitmapFromMemory(Toolbar_Options2_png);
464 m_Bitmaps[Toolbar_PluginGFX] = wxGetBitmapFromMemory(Toolbar_Gfx2_png);
465 m_Bitmaps[Toolbar_PluginDSP] = wxGetBitmapFromMemory(Toolbar_DSP2_png);
466 m_Bitmaps[Toolbar_PluginPAD] = wxGetBitmapFromMemory(Toolbar_Pad2_png);
467 m_Bitmaps[Toolbar_Wiimote] = wxGetBitmapFromMemory(Toolbar_Wiimote2_png);
468 m_Bitmaps[Toolbar_Screenshot] = wxGetBitmapFromMemory(Toolbar_Fullscreen2_png);
469 m_Bitmaps[Toolbar_FullScreen] = wxGetBitmapFromMemory(Toolbar_Fullscreen2_png);
470 m_Bitmaps[Toolbar_Help] = wxGetBitmapFromMemory(Toolbar_Help2_png);
472 break;
474 case KDE:
476 m_Bitmaps[Toolbar_FileOpen] = wxGetBitmapFromMemory(Toolbar_Open3_png);
477 m_Bitmaps[Toolbar_Refresh] = wxGetBitmapFromMemory(Toolbar_Refresh3_png);
478 m_Bitmaps[Toolbar_Browse] = wxGetBitmapFromMemory(Toolbar_Browse3_png);
479 m_Bitmaps[Toolbar_Play] = wxGetBitmapFromMemory(Toolbar_Play3_png);
480 m_Bitmaps[Toolbar_Stop] = wxGetBitmapFromMemory(Toolbar_Stop3_png);
481 m_Bitmaps[Toolbar_Pause] = wxGetBitmapFromMemory(Toolbar_Pause3_png);
482 m_Bitmaps[Toolbar_PluginOptions]= wxGetBitmapFromMemory(Toolbar_Options3_png);
483 m_Bitmaps[Toolbar_PluginGFX] = wxGetBitmapFromMemory(Toolbar_Gfx3_png);
484 m_Bitmaps[Toolbar_PluginDSP] = wxGetBitmapFromMemory(Toolbar_DSP3_png);
485 m_Bitmaps[Toolbar_PluginPAD] = wxGetBitmapFromMemory(Toolbar_Pad3_png);
486 m_Bitmaps[Toolbar_Wiimote] = wxGetBitmapFromMemory(Toolbar_Wiimote3_png);
487 m_Bitmaps[Toolbar_Screenshot] = wxGetBitmapFromMemory(Toolbar_Fullscreen3_png);
488 m_Bitmaps[Toolbar_FullScreen] = wxGetBitmapFromMemory(Toolbar_Fullscreen3_png);
489 m_Bitmaps[Toolbar_Help] = wxGetBitmapFromMemory(Toolbar_Help3_png);
491 break;
493 default: PanicAlert("Theme selection went wrong");
496 // Update in case the bitmap has been updated
497 if (m_ToolBar != NULL) RecreateToolbar();
499 aNormalFile = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
502 // Menu items
504 // Start the game or change the disc.
505 // Boot priority:
506 // 1. Show the game list and boot the selected game.
507 // 2. Default ISO
508 // 3. Boot last selected game
509 void CFrame::BootGame(const std::string& filename)
511 std::string bootfile = filename;
512 SCoreStartupParameter& StartUp = SConfig::GetInstance().m_LocalCoreStartupParameter;
514 if (Core::GetState() != Core::CORE_UNINITIALIZED)
515 return;
517 // Start filename if non empty.
518 // Start the selected ISO, or try one of the saved paths.
519 // If all that fails, ask to add a dir and don't boot
520 if (bootfile.empty())
522 if (m_GameListCtrl->GetSelectedISO() != NULL)
524 if (m_GameListCtrl->GetSelectedISO()->IsValid())
525 bootfile = m_GameListCtrl->GetSelectedISO()->GetFileName();
527 else if (!StartUp.m_strDefaultGCM.empty()
528 && wxFileExists(wxString(StartUp.m_strDefaultGCM.c_str(), wxConvUTF8)))
529 bootfile = StartUp.m_strDefaultGCM;
530 else
532 if (!SConfig::GetInstance().m_LastFilename.empty()
533 && wxFileExists(wxString(SConfig::GetInstance().m_LastFilename.c_str(), wxConvUTF8)))
534 bootfile = SConfig::GetInstance().m_LastFilename;
535 else
537 m_GameListCtrl->BrowseForDirectory();
538 return;
542 if (!bootfile.empty())
543 StartGame(bootfile);
546 // Open file to boot
547 void CFrame::OnOpen(wxCommandEvent& WXUNUSED (event))
549 DoOpen(true);
552 void CFrame::DoOpen(bool Boot)
554 std::string currentDir = File::GetCurrentDir();
556 wxString path = wxFileSelector(
557 _T("Select the file to load"),
558 wxEmptyString, wxEmptyString, wxEmptyString,
559 wxString::Format
561 _T("All GC/Wii files (elf, dol, gcm, iso, wad)|*.elf;*.dol;*.gcm;*.iso;*.gcz;*.wad|All files (%s)|%s"),
562 wxFileSelectorDefaultWildcardStr,
563 wxFileSelectorDefaultWildcardStr
565 wxFD_OPEN | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST,
566 this);
568 bool fileChosen = !path.IsEmpty();
570 std::string currentDir2 = File::GetCurrentDir();
572 if (currentDir != currentDir2)
574 PanicAlert("Current dir changed from %s to %s after wxFileSelector!",currentDir.c_str(),currentDir2.c_str());
575 File::SetCurrentDir(currentDir.c_str());
579 // Should we boot a new game or just change the disc?
580 if (Boot)
582 if (!fileChosen)
583 return;
584 BootGame(std::string(path.mb_str()));
586 else
588 strncpy(newDiscpath, path.mb_str(), strlen(path.mb_str())+1);
589 DVDInterface::ChangeDisc(newDiscpath);
593 void CFrame::OnFrameStep(wxCommandEvent& event)
595 Frame::SetFrameStepping(event.IsChecked());
598 void CFrame::OnChangeDisc(wxCommandEvent& WXUNUSED (event))
600 DoOpen(false);
603 void CFrame::OnRecord(wxCommandEvent& WXUNUSED (event))
605 wxString path = wxFileSelector(
606 _T("Select The Recording File"),
607 wxEmptyString, wxEmptyString, wxEmptyString,
608 wxString::Format
610 _T("Dolphin TAS Movies (*.dtm)|*.dtm|All files (%s)|%s"),
611 wxFileSelectorDefaultWildcardStr,
612 wxFileSelectorDefaultWildcardStr
614 wxFD_SAVE | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST,
615 this);
617 if(path.IsEmpty())
618 return;
620 // TODO: Take controller settings from Gamecube Configuration menu
621 if(Frame::BeginRecordingInput(path.mb_str(), 1))
622 BootGame(std::string(""));
625 void CFrame::OnPlayRecording(wxCommandEvent& WXUNUSED (event))
627 wxString path = wxFileSelector(
628 _T("Select The Recording File"),
629 wxEmptyString, wxEmptyString, wxEmptyString,
630 wxString::Format
632 _T("Dolphin TAS Movies (*.dtm)|*.dtm|All files (%s)|%s"),
633 wxFileSelectorDefaultWildcardStr,
634 wxFileSelectorDefaultWildcardStr
636 wxFD_OPEN | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST,
637 this);
639 if(path.IsEmpty())
640 return;
642 if(Frame::PlayInput(path.mb_str()))
643 BootGame(std::string(""));
646 void CFrame::OnPlay(wxCommandEvent& WXUNUSED (event))
648 if (Core::GetState() != Core::CORE_UNINITIALIZED)
650 // Core is initialized and emulator is running
651 if (UseDebugger)
653 if (CCPU::IsStepping())
654 CCPU::EnableStepping(false);
655 else
656 CCPU::EnableStepping(true); // Break
658 wxThread::Sleep(20);
659 g_pCodeWindow->JumpToAddress(PC);
660 g_pCodeWindow->Update();
661 // Update toolbar with Play/Pause status
662 UpdateGUI();
664 else
665 DoPause();
667 else
668 // Core is uninitialized, start the game
669 BootGame(std::string(""));
672 void CFrame::OnRenderParentClose(wxCloseEvent& event)
674 DoStop();
675 event.Skip();
678 void CFrame::OnRenderParentMove(wxMoveEvent& event)
680 if (Core::GetState() != Core::CORE_UNINITIALIZED &&
681 !RendererIsFullscreen() && !m_RenderFrame->IsMaximized())
683 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowXPos = m_RenderFrame->GetPosition().x;
684 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowYPos = m_RenderFrame->GetPosition().y;
686 event.Skip();
689 void CFrame::OnRenderParentResize(wxSizeEvent& event)
691 if (Core::GetState() != Core::CORE_UNINITIALIZED)
693 int width, height;
694 if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain &&
695 !RendererIsFullscreen() && !m_RenderFrame->IsMaximized())
697 m_RenderFrame->GetSize(&width, &height);
698 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth = width;
699 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight = height;
701 #if defined(HAVE_X11) && HAVE_X11
702 int x, y;
703 m_RenderParent->GetSize(&width, &height);
704 m_RenderParent->GetPosition(&x, &y);
705 X11Utils::SendClientEvent(X11Utils::XDisplayFromHandle(GetHandle()),
706 "RESIZE", x, y, width, height);
707 #endif
709 event.Skip();
712 void CFrame::ToggleDisplayMode (bool bFullscreen)
714 #ifdef _WIN32
715 if (bFullscreen)
717 DEVMODE dmScreenSettings;
718 memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
719 dmScreenSettings.dmSize = sizeof(dmScreenSettings);
720 sscanf(SConfig::GetInstance().m_LocalCoreStartupParameter.strFullscreenResolution.c_str(),
721 "%dx%d", &dmScreenSettings.dmPelsWidth, &dmScreenSettings.dmPelsHeight);
722 dmScreenSettings.dmBitsPerPel = 32;
723 dmScreenSettings.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
725 // Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
726 ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
728 else
730 // Change to default resolution
731 ChangeDisplaySettings(NULL, CDS_FULLSCREEN);
733 #elif defined(HAVE_XRANDR) && HAVE_XRANDR
734 m_XRRConfig->ToggleDisplayMode(bFullscreen);
735 #endif
738 // Prepare the GUI to start the game.
739 void CFrame::StartGame(const std::string& filename)
741 m_bGameLoading = true;
743 if (m_ToolBar)
744 m_ToolBar->EnableTool(IDM_PLAY, false);
745 GetMenuBar()->FindItem(IDM_PLAY)->Enable(false);
747 // Game has been started, hide the game list
748 if (m_GameListCtrl->IsShown())
750 m_GameListCtrl->Disable();
751 m_GameListCtrl->Hide();
754 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain)
756 m_RenderParent = m_Panel;
757 m_RenderFrame = this;
759 else
761 wxPoint position(SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowXPos,
762 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowYPos);
763 wxSize size(SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth,
764 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight);
765 m_RenderFrame = new CRenderFrame((wxFrame*)this, wxID_ANY, _("Dolphin"), position, size);
766 m_RenderFrame->Connect(wxID_ANY, wxEVT_CLOSE_WINDOW,
767 wxCloseEventHandler(CFrame::OnRenderParentClose),
768 (wxObject*)0, this);
769 m_RenderFrame->Connect(wxID_ANY, wxEVT_ACTIVATE,
770 wxActivateEventHandler(CFrame::OnActive),
771 (wxObject*)0, this);
772 m_RenderFrame->Connect(wxID_ANY, wxEVT_MOVE,
773 wxMoveEventHandler(CFrame::OnRenderParentMove),
774 (wxObject*)0, this);
775 m_RenderParent = new CPanel(m_RenderFrame, wxID_ANY);
776 m_RenderFrame->Show();
779 if (!BootManager::BootCore(filename))
781 // Destroy the renderer frame when not rendering to main
782 if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain)
783 m_RenderFrame->Destroy();
784 m_RenderParent = NULL;
785 m_bGameLoading = false;
786 UpdateGUI();
788 else
790 DoFullscreen(SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen);
792 #ifdef _WIN32
793 ::SetFocus((HWND)m_RenderParent->GetHandle());
794 #else
795 m_RenderParent->SetFocus();
796 #endif
798 wxTheApp->Connect(wxID_ANY, wxEVT_KEY_DOWN, // Keyboard
799 wxKeyEventHandler(CFrame::OnKeyDown),
800 (wxObject*)0, this);
801 wxTheApp->Connect(wxID_ANY, wxEVT_KEY_UP,
802 wxKeyEventHandler(CFrame::OnKeyUp),
803 (wxObject*)0, this);
804 m_RenderFrame->Connect(wxID_ANY, wxEVT_SIZE,
805 wxSizeEventHandler(CFrame::OnRenderParentResize),
806 (wxObject*)0, this);
810 void CFrame::OnBootDrive(wxCommandEvent& event)
812 BootGame(drives[event.GetId()-IDM_DRIVE1]);
816 // Refresh the file list and browse for a favorites directory
817 void CFrame::OnRefresh(wxCommandEvent& WXUNUSED (event))
819 if (m_GameListCtrl) m_GameListCtrl->Update();
823 void CFrame::OnBrowse(wxCommandEvent& WXUNUSED (event))
825 if (m_GameListCtrl) m_GameListCtrl->BrowseForDirectory();
828 // Create screenshot
829 void CFrame::OnScreenshot(wxCommandEvent& WXUNUSED (event))
831 Core::ScreenShot();
834 // Pause the emulation
835 void CFrame::DoPause()
837 if (Core::GetState() == Core::CORE_RUN)
839 Core::SetState(Core::CORE_PAUSE);
840 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
841 m_RenderParent->SetCursor(wxCURSOR_ARROW);
843 else
845 Core::SetState(Core::CORE_RUN);
846 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor &&
847 RendererHasFocus())
848 m_RenderParent->SetCursor(wxCURSOR_BLANK);
850 UpdateGUI();
853 // Stop the emulation
854 void CFrame::DoStop()
856 if (Core::GetState() != Core::CORE_UNINITIALIZED)
858 // Ask for confirmation in case the user accidentally clicked Stop / Escape
859 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bConfirmStop)
861 // Suppress duplicate dialog boxes
862 if (m_StopDlg)
863 return;
865 m_StopDlg = new wxMessageDialog(
866 this,
867 wxT("Do you want to stop the current emulation?"),
868 wxT("Please confirm..."),
869 wxYES_NO | wxSTAY_ON_TOP | wxICON_EXCLAMATION,
870 wxDefaultPosition);
872 int Ret = m_StopDlg->ShowModal();
873 m_StopDlg->Destroy();
874 m_StopDlg = NULL;
875 if (Ret == wxID_NO)
876 return;
879 // TODO: Show the author/description dialog here
880 if(Frame::IsRecordingInput())
881 Frame::EndRecordingInput();
882 if(Frame::IsPlayingInput())
883 Frame::EndPlayInput();
885 // These windows cause segmentation faults if they are open when the emulator
886 // stops. It has something to do with the the wxAuiManager update.
887 if (g_pCodeWindow)
889 g_pCodeWindow->ToggleDLLWindow(IDM_SOUNDWINDOW, false);
890 g_pCodeWindow->ToggleDLLWindow(IDM_VIDEOWINDOW, false);
893 Core::Stop();
895 // Destroy the renderer frame when not rendering to main
896 m_RenderFrame->Disconnect(wxID_ANY, wxEVT_SIZE,
897 wxSizeEventHandler(CFrame::OnRenderParentResize),
898 (wxObject*)0, this);
899 wxTheApp->Disconnect(wxID_ANY, wxEVT_KEY_DOWN, // Keyboard
900 wxKeyEventHandler(CFrame::OnKeyDown),
901 (wxObject*)0, this);
902 wxTheApp->Disconnect(wxID_ANY, wxEVT_KEY_UP,
903 wxKeyEventHandler(CFrame::OnKeyUp),
904 (wxObject*)0, this);
905 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
906 m_RenderParent->SetCursor(wxCURSOR_ARROW);
907 DoFullscreen(FALSE);
908 if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain)
909 m_RenderFrame->Destroy();
910 m_RenderParent = NULL;
912 UpdateGUI();
914 // Clean framerate indications from the status bar.
915 m_pStatusBar->SetStatusText(wxT(" "), 0);
917 // Clear wiimote connection status from the status bar.
918 m_pStatusBar->SetStatusText(wxT(" "), 1);
920 // If batch mode was specified on the command-line, exit now.
921 if (m_bBatchMode)
922 Close(true);
926 void CFrame::OnStop(wxCommandEvent& WXUNUSED (event))
928 m_bGameLoading = false;
929 DoStop();
932 void CFrame::OnReset(wxCommandEvent& WXUNUSED (event))
934 ProcessorInterface::ResetButton_Tap();
937 void CFrame::OnConfigMain(wxCommandEvent& WXUNUSED (event))
939 CConfigMain ConfigMain(this);
940 if (ConfigMain.ShowModal() == wxID_OK)
941 m_GameListCtrl->Update();
944 void CFrame::OnPluginGFX(wxCommandEvent& WXUNUSED (event))
946 CPluginManager::GetInstance().OpenConfig(
947 GetHandle(),
948 SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoPlugin.c_str(),
949 PLUGIN_TYPE_VIDEO
953 void CFrame::OnPluginDSP(wxCommandEvent& WXUNUSED (event))
955 CPluginManager::GetInstance().OpenConfig(
956 GetHandle(),
957 SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDSPPlugin.c_str(),
958 PLUGIN_TYPE_DSP
962 void CFrame::OnPluginPAD(wxCommandEvent& WXUNUSED (event))
964 InputPlugin *pad_plugin = PAD_GetPlugin();
965 bool was_init = false;
966 if ( pad_plugin->controller_interface.IsInit() ) // check if game is running
967 was_init = true;
968 else
970 #if defined(HAVE_X11) && HAVE_X11
971 Window win = X11Utils::XWindowFromHandle(GetHandle());
972 GCPad_Init((void *)win);
973 #else
974 GCPad_Init(GetHandle());
975 #endif
977 InputConfigDialog* m_ConfigFrame = new InputConfigDialog(this, *pad_plugin, "Dolphin GCPad Configuration");
978 m_ConfigFrame->ShowModal();
979 m_ConfigFrame->Destroy();
980 if (!was_init) // if game isn't running
982 GCPad_Deinit();
986 void CFrame::OnPluginWiimote(wxCommandEvent& WXUNUSED (event))
988 CPluginManager::GetInstance().OpenConfig(
989 GetHandle(),
990 SConfig::GetInstance().m_LocalCoreStartupParameter.m_strWiimotePlugin.c_str(),
991 PLUGIN_TYPE_WIIMOTE
995 void CFrame::OnHelp(wxCommandEvent& event)
997 switch (event.GetId())
999 case wxID_ABOUT:
1001 AboutDolphin frame(this);
1002 frame.ShowModal();
1004 break;
1005 case IDM_HELPWEBSITE:
1006 WxUtils::Launch("http://www.dolphin-emu.com/");
1007 break;
1008 case IDM_HELPGOOGLECODE:
1009 WxUtils::Launch("http://code.google.com/p/dolphin-emu/");
1010 break;
1014 void CFrame::ClearStatusBar()
1016 if (this->GetStatusBar()->IsEnabled()) this->GetStatusBar()->SetStatusText(wxT(""),0);
1019 void CFrame::StatusBarMessage(const char * Text, ...)
1021 const int MAX_BYTES = 1024*10;
1022 char Str[MAX_BYTES];
1023 va_list ArgPtr;
1024 int Cnt;
1025 va_start(ArgPtr, Text);
1026 Cnt = vsnprintf(Str, MAX_BYTES, Text, ArgPtr);
1027 va_end(ArgPtr);
1029 if (this->GetStatusBar()->IsEnabled()) this->GetStatusBar()->SetStatusText(wxString::FromAscii(Str),0);
1033 // Miscellaneous menus
1034 // ---------------------
1035 // NetPlay stuff
1036 void CFrame::OnNetPlay(wxCommandEvent& WXUNUSED (event))
1038 new NetPlaySetupDiag(this, m_GameListCtrl);
1041 void CFrame::OnMemcard(wxCommandEvent& WXUNUSED (event))
1043 CMemcardManager MemcardManager(this);
1044 MemcardManager.ShowModal();
1047 void CFrame::OnImportSave(wxCommandEvent& WXUNUSED (event))
1049 wxString path = wxFileSelector(_T("Select the save file"),
1050 wxEmptyString, wxEmptyString, wxEmptyString,
1051 wxString::Format
1053 _T("Wii save files|data.bin|All files (%s)|%s"),
1054 wxFileSelectorDefaultWildcardStr,
1055 wxFileSelectorDefaultWildcardStr
1057 wxFD_OPEN | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST,
1058 this);
1060 if (!path.IsEmpty())
1062 CWiiSaveCrypted* saveFile = new CWiiSaveCrypted(path.ToUTF8().data());
1063 delete saveFile;
1067 void CFrame::OnOpenLuaWindow(wxCommandEvent& WXUNUSED (event))
1069 new wxLuaWindow(this, wxDefaultPosition, wxSize(600, 390));
1072 void CFrame::OnShow_CheatsWindow(wxCommandEvent& WXUNUSED (event))
1074 CheatsWindow = new wxCheatsWindow(this);
1077 void CFrame::OnLoadWiiMenu(wxCommandEvent& event)
1079 if (event.GetId() == IDM_LOAD_WII_MENU)
1081 BootGame(std::string (File::GetUserPath(D_WIIMENU_IDX)));
1083 else
1086 wxString path = wxFileSelector(
1087 _T("Select the System Menu wad extracted from the update partition of a disc"),
1088 wxEmptyString, wxEmptyString, wxEmptyString,
1089 wxString::Format
1091 _T("System Menu wad|*.wad"),
1092 wxFileSelectorDefaultWildcardStr,
1093 wxFileSelectorDefaultWildcardStr
1095 wxFD_OPEN | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST,
1096 this);
1098 if (CBoot::Install_WiiWAD(path.mb_str()))
1100 GetMenuBar()->FindItem(IDM_INSTALL_WII_MENU)->Enable(false);
1105 void CFrame::OnConnectWiimote(wxCommandEvent& event)
1107 if (Core::isRunning() && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
1109 int Id = event.GetId() - IDM_CONNECT_WIIMOTE1;
1110 bNoWiimoteMsg = !event.IsChecked();
1111 GetUsbPointer()->AccessWiiMote(Id | 0x100)->Activate(event.IsChecked());
1112 wxString msg(wxString::Format(wxT("Wiimote %i %s"), Id + 1, (event.IsChecked()) ? wxT("Connected") : wxT("Disconnected")));
1113 Core::DisplayMessage(msg.ToAscii(), 3000);
1117 // Toogle fullscreen. In Windows the fullscreen mode is accomplished by expanding the m_Panel to cover
1118 // the entire screen (when we render to the main window).
1119 void CFrame::OnToggleFullscreen(wxCommandEvent& WXUNUSED (event))
1121 DoFullscreen(!RendererIsFullscreen());
1124 void CFrame::OnToggleDualCore(wxCommandEvent& WXUNUSED (event))
1126 SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread = !SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread;
1127 SConfig::GetInstance().SaveSettings();
1130 void CFrame::OnToggleSkipIdle(wxCommandEvent& WXUNUSED (event))
1132 SConfig::GetInstance().m_LocalCoreStartupParameter.bSkipIdle = !SConfig::GetInstance().m_LocalCoreStartupParameter.bSkipIdle;
1133 SConfig::GetInstance().SaveSettings();
1136 void CFrame::OnLoadStateFromFile(wxCommandEvent& WXUNUSED (event))
1138 wxString path = wxFileSelector(
1139 _T("Select the state to load"),
1140 wxEmptyString, wxEmptyString, wxEmptyString,
1141 wxString::Format
1143 _T("All Save States (sav, s##)|*.sav;*.s??|All files (%s)|%s"),
1144 wxFileSelectorDefaultWildcardStr,
1145 wxFileSelectorDefaultWildcardStr
1147 wxFD_OPEN | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST,
1148 this);
1150 if(!path.IsEmpty())
1151 State_LoadAs((const char*)path.mb_str());
1154 void CFrame::OnSaveStateToFile(wxCommandEvent& WXUNUSED (event))
1156 wxString path = wxFileSelector(
1157 _T("Select the state to save"),
1158 wxEmptyString, wxEmptyString, wxEmptyString,
1159 wxString::Format
1161 _T("All Save States (sav, s##)|*.sav;*.s??|All files (%s)|%s"),
1162 wxFileSelectorDefaultWildcardStr,
1163 wxFileSelectorDefaultWildcardStr
1165 wxFD_SAVE,
1166 this);
1168 if(! path.IsEmpty())
1169 State_SaveAs((const char*)path.mb_str());
1172 void CFrame::OnLoadLastState(wxCommandEvent& WXUNUSED (event))
1174 State_LoadLastSaved();
1177 void CFrame::OnUndoLoadState(wxCommandEvent& WXUNUSED (event))
1179 State_UndoLoadState();
1182 void CFrame::OnUndoSaveState(wxCommandEvent& WXUNUSED (event))
1184 State_UndoSaveState();
1188 void CFrame::OnLoadState(wxCommandEvent& event)
1190 int id = event.GetId();
1191 int slot = id - IDM_LOADSLOT1 + 1;
1192 State_Load(slot);
1195 void CFrame::OnSaveState(wxCommandEvent& event)
1197 int id = event.GetId();
1198 int slot = id - IDM_SAVESLOT1 + 1;
1199 State_Save(slot);
1202 void CFrame::OnFrameSkip(wxCommandEvent& event)
1204 int amount = event.GetId() - IDM_FRAMESKIP0;
1206 Frame::SetFrameSkipping((unsigned int)amount);
1212 // GUI
1213 // ---------------------
1215 // Update the enabled/disabled status
1216 void CFrame::UpdateGUI()
1218 if (!m_bControlsCreated)
1219 return;
1221 // Save status
1222 bool Initialized = Core::isRunning();
1223 bool Running = Core::GetState() == Core::CORE_RUN;
1224 bool Paused = Core::GetState() == Core::CORE_PAUSE;
1226 // Make sure that we have a toolbar
1227 if (m_ToolBar)
1229 // Enable/disable the Config and Stop buttons
1230 m_ToolBar->EnableTool(wxID_OPEN, !Initialized);
1231 m_ToolBar->EnableTool(wxID_REFRESH, !Initialized); // Don't allow refresh when we don't show the list
1232 m_ToolBar->EnableTool(IDM_STOP, Running || Paused);
1233 m_ToolBar->EnableTool(IDM_TOGGLE_FULLSCREEN, Running || Paused);
1234 m_ToolBar->EnableTool(IDM_SCREENSHOT, Running || Paused);
1237 // File
1238 GetMenuBar()->FindItem(wxID_OPEN)->Enable(!Initialized);
1239 m_pSubMenuDrive->Enable(!Initialized);
1240 GetMenuBar()->FindItem(wxID_REFRESH)->Enable(!Initialized);
1241 GetMenuBar()->FindItem(IDM_BROWSE)->Enable(!Initialized);
1243 // Emulation
1244 GetMenuBar()->FindItem(IDM_STOP)->Enable(Running || Paused);
1245 GetMenuBar()->FindItem(IDM_RESET)->Enable(Running || Paused);
1246 GetMenuBar()->FindItem(IDM_RECORD)->Enable(!Initialized);
1247 GetMenuBar()->FindItem(IDM_PLAYRECORD)->Enable(!Initialized);
1248 GetMenuBar()->FindItem(IDM_FRAMESTEP)->Enable(Running || Paused);
1249 GetMenuBar()->FindItem(IDM_SCREENSHOT)->Enable(Running || Paused);
1250 GetMenuBar()->FindItem(IDM_TOGGLE_FULLSCREEN)->Enable(Running || Paused);
1252 // Update Menu Accelerators
1253 GetMenuBar()->FindItem(IDM_TOGGLE_FULLSCREEN)->SetItemLabel(GetMenuLabel(HK_FULLSCREEN));
1254 GetMenuBar()->FindItem(IDM_PLAY)->SetItemLabel(GetMenuLabel(HK_PLAY_PAUSE));
1255 GetMenuBar()->FindItem(IDM_STOP)->SetItemLabel(GetMenuLabel(HK_STOP));
1256 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE1)->SetItemLabel(GetMenuLabel(HK_WIIMOTE1_CONNECT));
1257 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE2)->SetItemLabel(GetMenuLabel(HK_WIIMOTE2_CONNECT));
1258 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE3)->SetItemLabel(GetMenuLabel(HK_WIIMOTE3_CONNECT));
1259 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE4)->SetItemLabel(GetMenuLabel(HK_WIIMOTE4_CONNECT));
1261 m_pSubMenuLoad->Enable(Initialized);
1262 m_pSubMenuSave->Enable(Initialized);
1264 // Misc
1265 GetMenuBar()->FindItem(IDM_CHANGEDISC)->Enable(Initialized);
1266 if (DiscIO::CNANDContentManager::Access().GetNANDLoader(std::string(File::GetUserPath(D_WIIMENU_IDX))).IsValid())
1267 GetMenuBar()->FindItem(IDM_LOAD_WII_MENU)->Enable(!Initialized);
1269 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE1)->Enable(Initialized && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii);
1270 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE2)->Enable(Initialized && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii);
1271 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE3)->Enable(Initialized && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii);
1272 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE4)->Enable(Initialized && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii);
1273 if (Initialized && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
1275 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE1)->Check(GetUsbPointer()->AccessWiiMote(0x0100)->IsConnected() == 3);
1276 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE2)->Check(GetUsbPointer()->AccessWiiMote(0x0101)->IsConnected() == 3);
1277 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE3)->Check(GetUsbPointer()->AccessWiiMote(0x0102)->IsConnected() == 3);
1278 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE4)->Check(GetUsbPointer()->AccessWiiMote(0x0103)->IsConnected() == 3);
1281 if (Running)
1283 if (m_ToolBar)
1285 m_ToolBar->SetToolBitmap(IDM_PLAY, m_Bitmaps[Toolbar_Pause]);
1286 m_ToolBar->SetToolShortHelp(IDM_PLAY, _("Pause"));
1287 m_ToolBar->SetToolLabel(IDM_PLAY, _("Pause"));
1290 else
1292 if (m_ToolBar)
1294 m_ToolBar->SetToolBitmap(IDM_PLAY, m_Bitmaps[Toolbar_Play]);
1295 m_ToolBar->SetToolShortHelp(IDM_PLAY, _("Play"));
1296 m_ToolBar->SetToolLabel(IDM_PLAY, wxT(" Play "));
1300 if (!Initialized)
1302 if (m_GameListCtrl->IsEnabled())
1304 // Prepare to load Default ISO, enable play button
1305 if (!SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDefaultGCM.empty())
1307 if (m_ToolBar)
1308 m_ToolBar->EnableTool(IDM_PLAY, true);
1309 GetMenuBar()->FindItem(IDM_PLAY)->Enable(true);
1311 // Prepare to load last selected file, enable play button
1312 else if (!SConfig::GetInstance().m_LastFilename.empty()
1313 && wxFileExists(wxString(SConfig::GetInstance().m_LastFilename.c_str(), wxConvUTF8)))
1315 if (m_ToolBar)
1316 m_ToolBar->EnableTool(IDM_PLAY, true);
1317 GetMenuBar()->FindItem(IDM_PLAY)->Enable(true);
1319 else
1321 // No game has been selected yet, disable play button
1322 if (m_ToolBar)
1323 m_ToolBar->EnableTool(IDM_PLAY, false);
1324 GetMenuBar()->FindItem(IDM_PLAY)->Enable(false);
1328 if (m_GameListCtrl && !m_bGameLoading)
1330 // Game has not started, show game list
1331 if (!m_GameListCtrl->IsShown())
1333 m_GameListCtrl->Reparent(m_Panel);
1334 m_GameListCtrl->Enable();
1335 m_GameListCtrl->Show();
1336 sizerPanel->FitInside(m_Panel);
1338 // Game has been selected but not started, enable play button
1339 if (m_GameListCtrl->GetSelectedISO() != NULL && m_GameListCtrl->IsEnabled() && !m_bGameLoading)
1341 if (m_ToolBar)
1342 m_ToolBar->EnableTool(IDM_PLAY, true);
1343 GetMenuBar()->FindItem(IDM_PLAY)->Enable(true);
1347 else
1349 // Game has been loaded, enable the pause button
1350 if (m_ToolBar)
1351 m_ToolBar->EnableTool(IDM_PLAY, true);
1352 GetMenuBar()->FindItem(IDM_PLAY)->Enable(true);
1354 // Reset game loading flag
1355 m_bGameLoading = false;
1358 if (m_ToolBar) m_ToolBar->Refresh();
1359 if (g_pCodeWindow) g_pCodeWindow->Update();
1361 // Commit changes to manager
1362 m_Mgr->Update();
1365 void CFrame::UpdateGameList()
1367 m_GameListCtrl->Update();
1370 void CFrame::GameListChanged(wxCommandEvent& event)
1372 switch (event.GetId())
1374 case IDM_LISTWII:
1375 SConfig::GetInstance().m_ListWii = event.IsChecked();
1376 break;
1377 case IDM_LISTGC:
1378 SConfig::GetInstance().m_ListGC = event.IsChecked();
1379 break;
1380 case IDM_LISTWAD:
1381 SConfig::GetInstance().m_ListWad = event.IsChecked();
1382 break;
1383 case IDM_LISTJAP:
1384 SConfig::GetInstance().m_ListJap = event.IsChecked();
1385 break;
1386 case IDM_LISTPAL:
1387 SConfig::GetInstance().m_ListPal = event.IsChecked();
1388 break;
1389 case IDM_LISTUSA:
1390 SConfig::GetInstance().m_ListUsa = event.IsChecked();
1391 break;
1392 case IDM_LISTFRANCE:
1393 SConfig::GetInstance().m_ListFrance = event.IsChecked();
1394 break;
1395 case IDM_LISTITALY:
1396 SConfig::GetInstance().m_ListItaly = event.IsChecked();
1397 break;
1398 case IDM_LISTKOREA:
1399 SConfig::GetInstance().m_ListKorea = event.IsChecked();
1400 break;
1401 case IDM_LISTTAIWAN:
1402 SConfig::GetInstance().m_ListTaiwan = event.IsChecked();
1403 break;
1404 case IDM_LIST_UNK:
1405 SConfig::GetInstance().m_ListUnknown = event.IsChecked();
1406 break;
1407 case IDM_LISTDRIVES:
1408 SConfig::GetInstance().m_ListDrives = event.IsChecked();
1409 break;
1410 case IDM_PURGECACHE:
1411 CFileSearch::XStringVector Directories;
1412 Directories.push_back(File::GetUserPath(D_CACHE_IDX));
1413 CFileSearch::XStringVector Extensions;
1414 Extensions.push_back("*.cache");
1416 CFileSearch FileSearch(Extensions, Directories);
1417 const CFileSearch::XStringVector& rFilenames = FileSearch.GetFileNames();
1419 for (u32 i = 0; i < rFilenames.size(); i++)
1421 File::Delete(rFilenames[i].c_str());
1423 break;
1426 if (m_GameListCtrl) m_GameListCtrl->Update();
1429 // Enable and disable the toolbar
1430 void CFrame::OnToggleToolbar(wxCommandEvent& event)
1432 SConfig::GetInstance().m_InterfaceToolbar = event.IsChecked();
1433 DoToggleToolbar(event.IsChecked());
1435 void CFrame::DoToggleToolbar(bool _show)
1437 if (_show)
1439 m_Mgr->GetPane(wxT("TBMain")).Show();
1440 if (g_pCodeWindow) { m_Mgr->GetPane(wxT("TBDebug")).Show(); m_Mgr->GetPane(wxT("TBAui")).Show(); }
1441 m_Mgr->Update();
1443 else
1445 m_Mgr->GetPane(wxT("TBMain")).Hide();
1446 if (g_pCodeWindow) { m_Mgr->GetPane(wxT("TBDebug")).Hide(); m_Mgr->GetPane(wxT("TBAui")).Hide(); }
1447 m_Mgr->Update();
1451 // Enable and disable the status bar
1452 void CFrame::OnToggleStatusbar(wxCommandEvent& event)
1454 SConfig::GetInstance().m_InterfaceStatusbar = event.IsChecked();
1455 if (SConfig::GetInstance().m_InterfaceStatusbar == true)
1456 m_pStatusBar->Show();
1457 else
1458 m_pStatusBar->Hide();
1460 this->SendSizeEvent();