Fix some more resizing and saving of such.
[dolphin.git] / Source / Core / DolphinWX / Src / FrameTools.cpp
blob09ebe141f1bb9243179a3cb1b0a792485bbfd17d
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 wxMenuBar *m_MenuBar = new wxMenuBar();
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(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->AppendCheckItem(IDM_CONSOLEWINDOW, _T("Show &Console"));
217 viewMenu->AppendSeparator();
219 if (g_pCodeWindow)
221 viewMenu->Check(IDM_LOGWINDOW, g_pCodeWindow->bShowOnStart[0]);
222 viewMenu->Check(IDM_CONSOLEWINDOW, g_pCodeWindow->bShowOnStart[1]);
224 const wxString MenuText[] = {
225 wxT("&Registers"),
226 wxT("&Breakpoints"),
227 wxT("&Memory"),
228 wxT("&JIT"),
229 wxT("&Sound"),
230 wxT("&Video")
233 for (int i = IDM_REGISTERWINDOW; i <= IDM_VIDEOWINDOW; i++)
235 viewMenu->AppendCheckItem(i, MenuText[i - IDM_REGISTERWINDOW]);
236 viewMenu->Check(i, g_pCodeWindow->bShowOnStart[i - IDM_LOGWINDOW]);
239 viewMenu->AppendSeparator();
241 else
243 viewMenu->Check(IDM_LOGWINDOW, SConfig::GetInstance().m_InterfaceLogWindow);
244 viewMenu->Check(IDM_CONSOLEWINDOW, SConfig::GetInstance().m_InterfaceConsole);
247 wxMenu *platformMenu = new wxMenu;
248 viewMenu->AppendSubMenu(platformMenu, _T("Show Platforms"));
249 platformMenu->AppendCheckItem(IDM_LISTWII, _T("Show Wii"));
250 platformMenu->Check(IDM_LISTWII, SConfig::GetInstance().m_ListWii);
251 platformMenu->AppendCheckItem(IDM_LISTGC, _T("Show GameCube"));
252 platformMenu->Check(IDM_LISTGC, SConfig::GetInstance().m_ListGC);
253 platformMenu->AppendCheckItem(IDM_LISTWAD, _T("Show Wad"));
254 platformMenu->Check(IDM_LISTWAD, SConfig::GetInstance().m_ListWad);
256 wxMenu *regionMenu = new wxMenu;
257 viewMenu->AppendSubMenu(regionMenu, _T("Show Regions"));
258 regionMenu->AppendCheckItem(IDM_LISTJAP, _T("Show JAP"));
259 regionMenu->Check(IDM_LISTJAP, SConfig::GetInstance().m_ListJap);
260 regionMenu->AppendCheckItem(IDM_LISTPAL, _T("Show PAL"));
261 regionMenu->Check(IDM_LISTPAL, SConfig::GetInstance().m_ListPal);
262 regionMenu->AppendCheckItem(IDM_LISTUSA, _T("Show USA"));
263 regionMenu->Check(IDM_LISTUSA, SConfig::GetInstance().m_ListUsa);
264 regionMenu->AppendSeparator();
265 regionMenu->AppendCheckItem(IDM_LISTFRANCE, _T("Show France"));
266 regionMenu->Check(IDM_LISTFRANCE, SConfig::GetInstance().m_ListFrance);
267 regionMenu->AppendCheckItem(IDM_LISTITALY, _T("Show Italy"));
268 regionMenu->Check(IDM_LISTITALY, SConfig::GetInstance().m_ListItaly);
269 regionMenu->AppendCheckItem(IDM_LISTKOREA, _T("Show Korea"));
270 regionMenu->Check(IDM_LISTKOREA, SConfig::GetInstance().m_ListKorea);
271 regionMenu->AppendCheckItem(IDM_LISTTAIWAN, _T("Show Taiwan"));
272 regionMenu->Check(IDM_LISTTAIWAN, SConfig::GetInstance().m_ListTaiwan);
273 regionMenu->AppendCheckItem(IDM_LIST_UNK, _T("Show unknown"));
274 regionMenu->Check(IDM_LIST_UNK, SConfig::GetInstance().m_ListUnknown);
275 viewMenu->AppendCheckItem(IDM_LISTDRIVES, _T("Show Drives"));
276 viewMenu->Check(IDM_LISTDRIVES, SConfig::GetInstance().m_ListDrives);
277 viewMenu->Append(IDM_PURGECACHE, _T("Purge Cache"));
278 m_MenuBar->Append(viewMenu, _T("&View"));
280 if (g_pCodeWindow) g_pCodeWindow->CreateMenu(SConfig::GetInstance().m_LocalCoreStartupParameter, m_MenuBar);
282 // Help menu
283 wxMenu* helpMenu = new wxMenu;
284 // Re-enable when there's something useful to display */
285 // helpMenu->Append(wxID_HELP, _T("&Help"));
286 helpMenu->Append(IDM_HELPWEBSITE, _T("Dolphin &Web Site"));
287 helpMenu->Append(IDM_HELPGOOGLECODE, _T("Dolphin at &Google Code"));
288 helpMenu->AppendSeparator();
289 helpMenu->Append(wxID_ABOUT, _T("&About..."));
290 m_MenuBar->Append(helpMenu, _T("&Help"));
292 // Associate the menu bar with the frame
293 SetMenuBar(m_MenuBar);
296 wxString CFrame::GetMenuLabel(int Id)
298 wxString Label;
299 switch (Id)
301 case HK_FULLSCREEN:
302 Label = _T("&Fullscreen\t");
303 break;
304 case HK_PLAY_PAUSE:
305 if (Core::GetState() == Core::CORE_RUN)
306 Label = _T("&Pause\t");
307 else
308 Label = _T("&Play\t");
309 break;
310 case HK_STOP:
311 Label = _T("&Stop\t");
312 break;
313 case HK_WIIMOTE1_CONNECT:
314 Label = _T("Connect Wiimote 1\t");
315 break;
316 case HK_WIIMOTE2_CONNECT:
317 Label = _T("Connect Wiimote 2\t");
318 break;
319 case HK_WIIMOTE3_CONNECT:
320 Label = _T("Connect Wiimote 3\t");
321 break;
322 case HK_WIIMOTE4_CONNECT:
323 Label = _T("Connect Wiimote 4\t");
324 break;
327 wxString Modifier = InputCommon::WXKeymodToString
328 (SConfig::GetInstance().m_LocalCoreStartupParameter.iHotkeyModifier[Id]);
329 wxString Hotkey = InputCommon::WXKeyToString
330 (SConfig::GetInstance().m_LocalCoreStartupParameter.iHotkey[Id]);
332 return Label + Modifier + (Modifier.Len() ? _T("+") : _T("")) + Hotkey;
336 // Create toolbar items
337 // ---------------------
338 void CFrame::PopulateToolbar(wxAuiToolBar* ToolBar)
340 int w = m_Bitmaps[Toolbar_FileOpen].GetWidth(),
341 h = m_Bitmaps[Toolbar_FileOpen].GetHeight();
342 ToolBar->SetToolBitmapSize(wxSize(w, h));
345 ToolBar->AddTool(wxID_OPEN, _T("Open"), m_Bitmaps[Toolbar_FileOpen], _T("Open file..."));
346 ToolBar->AddTool(wxID_REFRESH, _T("Refresh"), m_Bitmaps[Toolbar_Refresh], _T("Refresh game list"));
347 ToolBar->AddTool(IDM_BROWSE, _T("Browse"), m_Bitmaps[Toolbar_Browse], _T("Browse for an ISO directory..."));
348 ToolBar->AddSeparator();
349 ToolBar->AddTool(IDM_PLAY, wxT("Play"), m_Bitmaps[Toolbar_Play], _T("Play"));
350 ToolBar->AddTool(IDM_STOP, _T("Stop"), m_Bitmaps[Toolbar_Stop], _T("Stop"));
351 ToolBar->AddTool(IDM_TOGGLE_FULLSCREEN, _T("FullScr"), m_Bitmaps[Toolbar_FullScreen], _T("Toggle Fullscreen"));
352 ToolBar->AddTool(IDM_SCREENSHOT, _T("ScrShot"), m_Bitmaps[Toolbar_FullScreen], _T("Take Screenshot"));
353 ToolBar->AddSeparator();
354 ToolBar->AddTool(wxID_PREFERENCES, _T("Config"), m_Bitmaps[Toolbar_PluginOptions], _T("Configure..."));
355 ToolBar->AddTool(IDM_CONFIG_GFX_PLUGIN, _T("Graphics"), m_Bitmaps[Toolbar_PluginGFX], _T("Graphics settings"));
356 ToolBar->AddTool(IDM_CONFIG_DSP_PLUGIN, _T("DSP"), m_Bitmaps[Toolbar_PluginDSP], _T("DSP settings"));
357 ToolBar->AddTool(IDM_CONFIG_PAD_PLUGIN, _T("GCPad"), m_Bitmaps[Toolbar_PluginPAD], _T("Gamecube Pad settings"));
358 ToolBar->AddTool(IDM_CONFIG_WIIMOTE_PLUGIN, _T("Wiimote"), m_Bitmaps[Toolbar_Wiimote], _T("Wiimote settings"));
360 // after adding the buttons to the toolbar, must call Realize() to reflect
361 // the changes
362 ToolBar->Realize();
365 void CFrame::PopulateToolbarAui(wxAuiToolBar* ToolBar)
367 int w = m_Bitmaps[Toolbar_FileOpen].GetWidth(),
368 h = m_Bitmaps[Toolbar_FileOpen].GetHeight();
369 ToolBar->SetToolBitmapSize(wxSize(w, h));
371 ToolBar->AddTool(IDM_SAVE_PERSPECTIVE, wxT("Save"), g_pCodeWindow->m_Bitmaps[Toolbar_GotoPC], wxT("Save current perspective"));
372 ToolBar->AddTool(IDM_EDIT_PERSPECTIVES, wxT("Edit"), g_pCodeWindow->m_Bitmaps[Toolbar_GotoPC], wxT("Edit current perspective"));
374 ToolBar->SetToolDropDown(IDM_SAVE_PERSPECTIVE, true);
375 ToolBar->SetToolDropDown(IDM_EDIT_PERSPECTIVES, true);
377 ToolBar->Realize();
381 // Delete and recreate the toolbar
382 void CFrame::RecreateToolbar()
384 if (m_ToolBar)
386 m_Mgr->DetachPane(m_ToolBar);
387 m_ToolBar->Destroy();
390 long TOOLBAR_STYLE = wxAUI_TB_DEFAULT_STYLE | wxAUI_TB_TEXT /*wxAUI_TB_OVERFLOW overflow visible*/;
391 m_ToolBar = new wxAuiToolBar(this, ID_TOOLBAR, wxDefaultPosition, wxDefaultSize, TOOLBAR_STYLE);
393 PopulateToolbar(m_ToolBar);
395 m_Mgr->AddPane(m_ToolBar, wxAuiPaneInfo().
396 Name(wxT("TBMain")).Caption(wxT("TBMain")).
397 ToolbarPane().Top().
398 LeftDockable(false).RightDockable(false).Floatable(false));
400 if (g_pCodeWindow && !m_ToolBarDebug)
402 m_ToolBarDebug = new wxAuiToolBar(this, ID_TOOLBAR_DEBUG, wxDefaultPosition, wxDefaultSize, TOOLBAR_STYLE);
403 g_pCodeWindow->PopulateToolbar(m_ToolBarDebug);
405 m_Mgr->AddPane(m_ToolBarDebug, wxAuiPaneInfo().
406 Name(wxT("TBDebug")).Caption(wxT("TBDebug")).
407 ToolbarPane().Top().
408 LeftDockable(false).RightDockable(false).Floatable(false));
410 m_ToolBarAui = new wxAuiToolBar(this, ID_TOOLBAR_AUI, wxDefaultPosition, wxDefaultSize, TOOLBAR_STYLE);
411 PopulateToolbarAui(m_ToolBarAui);
412 m_Mgr->AddPane(m_ToolBarAui, wxAuiPaneInfo().
413 Name(wxT("TBAui")).Caption(wxT("TBAui")).
414 ToolbarPane().Top().
415 LeftDockable(false).RightDockable(false).Floatable(false));
418 UpdateGUI();
421 void CFrame::InitBitmaps()
423 // Get selected theme
424 int Theme = SConfig::GetInstance().m_LocalCoreStartupParameter.iTheme;
426 // Save memory by only having one set of bitmaps loaded at any time. I mean, they are still
427 // in the exe, which is in memory, but at least we wont make another copy of all of them.
428 switch (Theme)
430 case BOOMY:
432 // These are stored as 48x48
433 m_Bitmaps[Toolbar_FileOpen] = wxGetBitmapFromMemory(toolbar_file_open_png);
434 m_Bitmaps[Toolbar_Refresh] = wxGetBitmapFromMemory(toolbar_refresh_png);
435 m_Bitmaps[Toolbar_Browse] = wxGetBitmapFromMemory(toolbar_browse_png);
436 m_Bitmaps[Toolbar_Play] = wxGetBitmapFromMemory(toolbar_play_png);
437 m_Bitmaps[Toolbar_Stop] = wxGetBitmapFromMemory(toolbar_stop_png);
438 m_Bitmaps[Toolbar_Pause] = wxGetBitmapFromMemory(toolbar_pause_png);
439 m_Bitmaps[Toolbar_PluginOptions]= wxGetBitmapFromMemory(toolbar_plugin_options_png);
440 m_Bitmaps[Toolbar_PluginGFX] = wxGetBitmapFromMemory(toolbar_plugin_gfx_png);
441 m_Bitmaps[Toolbar_PluginDSP] = wxGetBitmapFromMemory(toolbar_plugin_dsp_png);
442 m_Bitmaps[Toolbar_PluginPAD] = wxGetBitmapFromMemory(toolbar_plugin_pad_png);
443 m_Bitmaps[Toolbar_Wiimote] = wxGetBitmapFromMemory(toolbar_plugin_wiimote_png);
444 m_Bitmaps[Toolbar_Screenshot] = wxGetBitmapFromMemory(toolbar_fullscreen_png);
445 m_Bitmaps[Toolbar_FullScreen] = wxGetBitmapFromMemory(toolbar_fullscreen_png);
446 m_Bitmaps[Toolbar_Help] = wxGetBitmapFromMemory(toolbar_help_png);
448 // Scale the 48x48 bitmaps to 24x24
449 for (size_t n = Toolbar_FileOpen; n < EToolbar_Max; n++)
451 m_Bitmaps[n] = wxBitmap(m_Bitmaps[n].ConvertToImage().Scale(24, 24));
454 break;
456 case VISTA:
458 // These are stored as 24x24 and need no scaling
459 m_Bitmaps[Toolbar_FileOpen] = wxGetBitmapFromMemory(Toolbar_Open1_png);
460 m_Bitmaps[Toolbar_Refresh] = wxGetBitmapFromMemory(Toolbar_Refresh1_png);
461 m_Bitmaps[Toolbar_Browse] = wxGetBitmapFromMemory(Toolbar_Browse1_png);
462 m_Bitmaps[Toolbar_Play] = wxGetBitmapFromMemory(Toolbar_Play1_png);
463 m_Bitmaps[Toolbar_Stop] = wxGetBitmapFromMemory(Toolbar_Stop1_png);
464 m_Bitmaps[Toolbar_Pause] = wxGetBitmapFromMemory(Toolbar_Pause1_png);
465 m_Bitmaps[Toolbar_PluginOptions]= wxGetBitmapFromMemory(Toolbar_Options1_png);
466 m_Bitmaps[Toolbar_PluginGFX] = wxGetBitmapFromMemory(Toolbar_Gfx1_png);
467 m_Bitmaps[Toolbar_PluginDSP] = wxGetBitmapFromMemory(Toolbar_DSP1_png);
468 m_Bitmaps[Toolbar_PluginPAD] = wxGetBitmapFromMemory(Toolbar_Pad1_png);
469 m_Bitmaps[Toolbar_Wiimote] = wxGetBitmapFromMemory(Toolbar_Wiimote1_png);
470 m_Bitmaps[Toolbar_Screenshot] = wxGetBitmapFromMemory(Toolbar_Fullscreen1_png);
471 m_Bitmaps[Toolbar_FullScreen] = wxGetBitmapFromMemory(Toolbar_Fullscreen1_png);
472 m_Bitmaps[Toolbar_Help] = wxGetBitmapFromMemory(Toolbar_Help1_png);
474 break;
476 case XPLASTIK:
478 m_Bitmaps[Toolbar_FileOpen] = wxGetBitmapFromMemory(Toolbar_Open2_png);
479 m_Bitmaps[Toolbar_Refresh] = wxGetBitmapFromMemory(Toolbar_Refresh2_png);
480 m_Bitmaps[Toolbar_Browse] = wxGetBitmapFromMemory(Toolbar_Browse2_png);
481 m_Bitmaps[Toolbar_Play] = wxGetBitmapFromMemory(Toolbar_Play2_png);
482 m_Bitmaps[Toolbar_Stop] = wxGetBitmapFromMemory(Toolbar_Stop2_png);
483 m_Bitmaps[Toolbar_Pause] = wxGetBitmapFromMemory(Toolbar_Pause2_png);
484 m_Bitmaps[Toolbar_PluginOptions]= wxGetBitmapFromMemory(Toolbar_Options2_png);
485 m_Bitmaps[Toolbar_PluginGFX] = wxGetBitmapFromMemory(Toolbar_Gfx2_png);
486 m_Bitmaps[Toolbar_PluginDSP] = wxGetBitmapFromMemory(Toolbar_DSP2_png);
487 m_Bitmaps[Toolbar_PluginPAD] = wxGetBitmapFromMemory(Toolbar_Pad2_png);
488 m_Bitmaps[Toolbar_Wiimote] = wxGetBitmapFromMemory(Toolbar_Wiimote2_png);
489 m_Bitmaps[Toolbar_Screenshot] = wxGetBitmapFromMemory(Toolbar_Fullscreen2_png);
490 m_Bitmaps[Toolbar_FullScreen] = wxGetBitmapFromMemory(Toolbar_Fullscreen2_png);
491 m_Bitmaps[Toolbar_Help] = wxGetBitmapFromMemory(Toolbar_Help2_png);
493 break;
495 case KDE:
497 m_Bitmaps[Toolbar_FileOpen] = wxGetBitmapFromMemory(Toolbar_Open3_png);
498 m_Bitmaps[Toolbar_Refresh] = wxGetBitmapFromMemory(Toolbar_Refresh3_png);
499 m_Bitmaps[Toolbar_Browse] = wxGetBitmapFromMemory(Toolbar_Browse3_png);
500 m_Bitmaps[Toolbar_Play] = wxGetBitmapFromMemory(Toolbar_Play3_png);
501 m_Bitmaps[Toolbar_Stop] = wxGetBitmapFromMemory(Toolbar_Stop3_png);
502 m_Bitmaps[Toolbar_Pause] = wxGetBitmapFromMemory(Toolbar_Pause3_png);
503 m_Bitmaps[Toolbar_PluginOptions]= wxGetBitmapFromMemory(Toolbar_Options3_png);
504 m_Bitmaps[Toolbar_PluginGFX] = wxGetBitmapFromMemory(Toolbar_Gfx3_png);
505 m_Bitmaps[Toolbar_PluginDSP] = wxGetBitmapFromMemory(Toolbar_DSP3_png);
506 m_Bitmaps[Toolbar_PluginPAD] = wxGetBitmapFromMemory(Toolbar_Pad3_png);
507 m_Bitmaps[Toolbar_Wiimote] = wxGetBitmapFromMemory(Toolbar_Wiimote3_png);
508 m_Bitmaps[Toolbar_Screenshot] = wxGetBitmapFromMemory(Toolbar_Fullscreen3_png);
509 m_Bitmaps[Toolbar_FullScreen] = wxGetBitmapFromMemory(Toolbar_Fullscreen3_png);
510 m_Bitmaps[Toolbar_Help] = wxGetBitmapFromMemory(Toolbar_Help3_png);
512 break;
514 default: PanicAlert("Theme selection went wrong");
517 // Update in case the bitmap has been updated
518 if (m_ToolBar != NULL) RecreateToolbar();
521 // Menu items
523 // Start the game or change the disc.
524 // Boot priority:
525 // 1. Show the game list and boot the selected game.
526 // 2. Default ISO
527 // 3. Boot last selected game
528 void CFrame::BootGame(const std::string& filename)
530 std::string bootfile = filename;
531 SCoreStartupParameter& StartUp = SConfig::GetInstance().m_LocalCoreStartupParameter;
533 if (Core::GetState() != Core::CORE_UNINITIALIZED)
534 return;
536 // Start filename if non empty.
537 // Start the selected ISO, or try one of the saved paths.
538 // If all that fails, ask to add a dir and don't boot
539 if (bootfile.empty())
541 if (m_GameListCtrl->GetSelectedISO() != NULL)
543 if (m_GameListCtrl->GetSelectedISO()->IsValid())
544 bootfile = m_GameListCtrl->GetSelectedISO()->GetFileName();
546 else if (!StartUp.m_strDefaultGCM.empty()
547 && wxFileExists(wxString(StartUp.m_strDefaultGCM.c_str(), wxConvUTF8)))
548 bootfile = StartUp.m_strDefaultGCM;
549 else
551 if (!SConfig::GetInstance().m_LastFilename.empty()
552 && wxFileExists(wxString(SConfig::GetInstance().m_LastFilename.c_str(), wxConvUTF8)))
553 bootfile = SConfig::GetInstance().m_LastFilename;
554 else
556 m_GameListCtrl->BrowseForDirectory();
557 return;
561 if (!bootfile.empty())
562 StartGame(bootfile);
565 // Open file to boot
566 void CFrame::OnOpen(wxCommandEvent& WXUNUSED (event))
568 DoOpen(true);
571 void CFrame::DoOpen(bool Boot)
573 std::string currentDir = File::GetCurrentDir();
575 wxString path = wxFileSelector(
576 _T("Select the file to load"),
577 wxEmptyString, wxEmptyString, wxEmptyString,
578 wxString::Format
580 _T("All GC/Wii files (elf, dol, gcm, iso, wad)|*.elf;*.dol;*.gcm;*.iso;*.gcz;*.wad|All files (%s)|%s"),
581 wxFileSelectorDefaultWildcardStr,
582 wxFileSelectorDefaultWildcardStr
584 wxFD_OPEN | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST,
585 this);
587 bool fileChosen = !path.IsEmpty();
589 std::string currentDir2 = File::GetCurrentDir();
591 if (currentDir != currentDir2)
593 PanicAlert("Current dir changed from %s to %s after wxFileSelector!",currentDir.c_str(),currentDir2.c_str());
594 File::SetCurrentDir(currentDir.c_str());
598 // Should we boot a new game or just change the disc?
599 if (Boot)
601 if (!fileChosen)
602 return;
603 BootGame(std::string(path.mb_str()));
605 else
607 strncpy(newDiscpath, path.mb_str(), strlen(path.mb_str())+1);
608 DVDInterface::ChangeDisc(newDiscpath);
612 void CFrame::OnFrameStep(wxCommandEvent& event)
614 Frame::SetFrameStepping(event.IsChecked());
617 void CFrame::OnChangeDisc(wxCommandEvent& WXUNUSED (event))
619 DoOpen(false);
622 void CFrame::OnRecord(wxCommandEvent& WXUNUSED (event))
624 wxString path = wxFileSelector(
625 _T("Select The Recording File"),
626 wxEmptyString, wxEmptyString, wxEmptyString,
627 wxString::Format
629 _T("Dolphin TAS Movies (*.dtm)|*.dtm|All files (%s)|%s"),
630 wxFileSelectorDefaultWildcardStr,
631 wxFileSelectorDefaultWildcardStr
633 wxFD_SAVE | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST,
634 this);
636 if(path.IsEmpty())
637 return;
639 // TODO: Take controller settings from Gamecube Configuration menu
640 if(Frame::BeginRecordingInput(path.mb_str(), 1))
641 BootGame(std::string(""));
644 void CFrame::OnPlayRecording(wxCommandEvent& WXUNUSED (event))
646 wxString path = wxFileSelector(
647 _T("Select The Recording File"),
648 wxEmptyString, wxEmptyString, wxEmptyString,
649 wxString::Format
651 _T("Dolphin TAS Movies (*.dtm)|*.dtm|All files (%s)|%s"),
652 wxFileSelectorDefaultWildcardStr,
653 wxFileSelectorDefaultWildcardStr
655 wxFD_OPEN | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST,
656 this);
658 if(path.IsEmpty())
659 return;
661 if(Frame::PlayInput(path.mb_str()))
662 BootGame(std::string(""));
665 void CFrame::OnPlay(wxCommandEvent& WXUNUSED (event))
667 if (Core::GetState() != Core::CORE_UNINITIALIZED)
669 // Core is initialized and emulator is running
670 if (UseDebugger)
672 if (CCPU::IsStepping())
673 CCPU::EnableStepping(false);
674 else
675 CCPU::EnableStepping(true); // Break
677 wxThread::Sleep(20);
678 g_pCodeWindow->JumpToAddress(PC);
679 g_pCodeWindow->Update();
680 // Update toolbar with Play/Pause status
681 UpdateGUI();
683 else
684 DoPause();
686 else
687 // Core is uninitialized, start the game
688 BootGame(std::string(""));
691 void CFrame::OnRenderParentClose(wxCloseEvent& event)
693 DoStop();
694 event.Skip();
697 void CFrame::OnRenderParentMove(wxMoveEvent& event)
699 if (Core::GetState() != Core::CORE_UNINITIALIZED &&
700 !RendererIsFullscreen() && !m_RenderFrame->IsMaximized())
702 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowXPos = m_RenderFrame->GetPosition().x;
703 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowYPos = m_RenderFrame->GetPosition().y;
705 event.Skip();
708 void CFrame::OnRenderParentResize(wxSizeEvent& event)
710 if (Core::GetState() != Core::CORE_UNINITIALIZED)
712 int width, height;
713 if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain &&
714 !RendererIsFullscreen() && !m_RenderFrame->IsMaximized())
716 m_RenderFrame->GetSize(&width, &height);
717 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth = width;
718 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight = height;
720 #if defined(HAVE_X11) && HAVE_X11
721 int x, y;
722 m_RenderParent->GetSize(&width, &height);
723 m_RenderParent->GetPosition(&x, &y);
724 X11Utils::SendClientEvent(X11Utils::XDisplayFromHandle(GetHandle()),
725 "RESIZE", x, y, width, height);
726 #endif
727 m_LogWindow->Refresh();
728 m_LogWindow->Update();
730 event.Skip();
733 void CFrame::ToggleDisplayMode (bool bFullscreen)
735 #ifdef _WIN32
736 if (bFullscreen)
738 DEVMODE dmScreenSettings;
739 memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
740 dmScreenSettings.dmSize = sizeof(dmScreenSettings);
741 sscanf(SConfig::GetInstance().m_LocalCoreStartupParameter.strFullscreenResolution.c_str(),
742 "%dx%d", &dmScreenSettings.dmPelsWidth, &dmScreenSettings.dmPelsHeight);
743 dmScreenSettings.dmBitsPerPel = 32;
744 dmScreenSettings.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
746 // Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
747 ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN);
749 else
751 // Change to default resolution
752 ChangeDisplaySettings(NULL, CDS_FULLSCREEN);
754 #elif defined(HAVE_XRANDR) && HAVE_XRANDR
755 m_XRRConfig->ToggleDisplayMode(bFullscreen);
756 #endif
759 // Prepare the GUI to start the game.
760 void CFrame::StartGame(const std::string& filename)
762 m_bGameLoading = true;
764 if (m_ToolBar)
765 m_ToolBar->EnableTool(IDM_PLAY, false);
766 GetMenuBar()->FindItem(IDM_PLAY)->Enable(false);
768 // Game has been started, hide the game list
769 if (m_GameListCtrl->IsShown())
771 m_GameListCtrl->Disable();
772 m_GameListCtrl->Hide();
775 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain)
777 m_RenderParent = m_Panel;
778 m_RenderFrame = this;
780 else
782 wxPoint position(SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowXPos,
783 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowYPos);
784 wxSize size(SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowWidth,
785 SConfig::GetInstance().m_LocalCoreStartupParameter.iRenderWindowHeight);
786 m_RenderFrame = new CRenderFrame((wxFrame*)this, wxID_ANY, _("Dolphin"), position, size);
787 m_RenderFrame->Connect(wxID_ANY, wxEVT_CLOSE_WINDOW,
788 wxCloseEventHandler(CFrame::OnRenderParentClose),
789 (wxObject*)0, this);
790 m_RenderFrame->Connect(wxID_ANY, wxEVT_ACTIVATE,
791 wxActivateEventHandler(CFrame::OnActive),
792 (wxObject*)0, this);
793 m_RenderFrame->Connect(wxID_ANY, wxEVT_MOVE,
794 wxMoveEventHandler(CFrame::OnRenderParentMove),
795 (wxObject*)0, this);
796 m_RenderParent = new CPanel(m_RenderFrame, wxID_ANY);
797 m_RenderFrame->Show();
800 if (!BootManager::BootCore(filename))
802 // Destroy the renderer frame when not rendering to main
803 if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain)
804 m_RenderFrame->Destroy();
805 m_RenderParent = NULL;
806 m_bGameLoading = false;
807 UpdateGUI();
809 else
811 DoFullscreen(SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen);
813 #ifdef _WIN32
814 ::SetFocus((HWND)m_RenderParent->GetHandle());
815 #else
816 m_RenderParent->SetFocus();
817 #endif
819 wxTheApp->Connect(wxID_ANY, wxEVT_KEY_DOWN, // Keyboard
820 wxKeyEventHandler(CFrame::OnKeyDown),
821 (wxObject*)0, this);
822 wxTheApp->Connect(wxID_ANY, wxEVT_KEY_UP,
823 wxKeyEventHandler(CFrame::OnKeyUp),
824 (wxObject*)0, this);
825 m_RenderParent->Connect(wxID_ANY, wxEVT_SIZE,
826 wxSizeEventHandler(CFrame::OnRenderParentResize),
827 (wxObject*)0, this);
831 void CFrame::OnBootDrive(wxCommandEvent& event)
833 BootGame(drives[event.GetId()-IDM_DRIVE1]);
837 // Refresh the file list and browse for a favorites directory
838 void CFrame::OnRefresh(wxCommandEvent& WXUNUSED (event))
840 if (m_GameListCtrl) m_GameListCtrl->Update();
844 void CFrame::OnBrowse(wxCommandEvent& WXUNUSED (event))
846 if (m_GameListCtrl) m_GameListCtrl->BrowseForDirectory();
849 // Create screenshot
850 void CFrame::OnScreenshot(wxCommandEvent& WXUNUSED (event))
852 Core::ScreenShot();
855 // Pause the emulation
856 void CFrame::DoPause()
858 if (Core::GetState() == Core::CORE_RUN)
860 Core::SetState(Core::CORE_PAUSE);
861 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
862 m_RenderParent->SetCursor(wxCURSOR_ARROW);
864 else
866 Core::SetState(Core::CORE_RUN);
867 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor &&
868 RendererHasFocus())
869 m_RenderParent->SetCursor(wxCURSOR_BLANK);
871 UpdateGUI();
874 // Stop the emulation
875 void CFrame::DoStop()
877 if (Core::GetState() != Core::CORE_UNINITIALIZED)
879 // Ask for confirmation in case the user accidentally clicked Stop / Escape
880 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bConfirmStop)
882 // Suppress duplicate dialog boxes
883 if (m_StopDlg)
884 return;
886 m_StopDlg = new wxMessageDialog(
887 this,
888 wxT("Do you want to stop the current emulation?"),
889 wxT("Please confirm..."),
890 wxYES_NO | wxSTAY_ON_TOP | wxICON_EXCLAMATION,
891 wxDefaultPosition);
893 int Ret = m_StopDlg->ShowModal();
894 m_StopDlg->Destroy();
895 m_StopDlg = NULL;
896 if (Ret == wxID_NO)
897 return;
900 // TODO: Show the author/description dialog here
901 if(Frame::IsRecordingInput())
902 Frame::EndRecordingInput();
903 if(Frame::IsPlayingInput())
904 Frame::EndPlayInput();
906 // These windows cause segmentation faults if they are open when the emulator
907 // stops. It has something to do with the the wxAuiManager update.
908 if (g_pCodeWindow)
910 g_pCodeWindow->ToggleDLLWindow(IDM_SOUNDWINDOW, false);
911 g_pCodeWindow->ToggleDLLWindow(IDM_VIDEOWINDOW, false);
914 Core::Stop();
916 // Destroy the renderer frame when not rendering to main
917 m_RenderParent->Disconnect(wxID_ANY, wxEVT_SIZE,
918 wxSizeEventHandler(CFrame::OnRenderParentResize),
919 (wxObject*)0, this);
920 wxTheApp->Disconnect(wxID_ANY, wxEVT_KEY_DOWN, // Keyboard
921 wxKeyEventHandler(CFrame::OnKeyDown),
922 (wxObject*)0, this);
923 wxTheApp->Disconnect(wxID_ANY, wxEVT_KEY_UP,
924 wxKeyEventHandler(CFrame::OnKeyUp),
925 (wxObject*)0, this);
926 if (SConfig::GetInstance().m_LocalCoreStartupParameter.bHideCursor)
927 m_RenderParent->SetCursor(wxCURSOR_ARROW);
928 DoFullscreen(FALSE);
929 if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bRenderToMain)
930 m_RenderFrame->Destroy();
931 m_RenderParent = NULL;
933 UpdateGUI();
935 // Clean framerate indications from the status bar.
936 m_pStatusBar->SetStatusText(wxT(" "), 0);
938 // Clear wiimote connection status from the status bar.
939 m_pStatusBar->SetStatusText(wxT(" "), 1);
941 // If batch mode was specified on the command-line, exit now.
942 if (m_bBatchMode)
943 Close(true);
947 void CFrame::OnStop(wxCommandEvent& WXUNUSED (event))
949 m_bGameLoading = false;
950 DoStop();
953 void CFrame::OnReset(wxCommandEvent& WXUNUSED (event))
955 ProcessorInterface::ResetButton_Tap();
958 void CFrame::OnConfigMain(wxCommandEvent& WXUNUSED (event))
960 CConfigMain ConfigMain(this);
961 if (ConfigMain.ShowModal() == wxID_OK)
962 m_GameListCtrl->Update();
965 void CFrame::OnPluginGFX(wxCommandEvent& WXUNUSED (event))
967 CPluginManager::GetInstance().OpenConfig(
968 GetHandle(),
969 SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoPlugin.c_str(),
970 PLUGIN_TYPE_VIDEO
974 void CFrame::OnPluginDSP(wxCommandEvent& WXUNUSED (event))
976 CPluginManager::GetInstance().OpenConfig(
977 GetHandle(),
978 SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDSPPlugin.c_str(),
979 PLUGIN_TYPE_DSP
983 void CFrame::OnPluginPAD(wxCommandEvent& WXUNUSED (event))
985 InputPlugin *pad_plugin = PAD_GetPlugin();
986 bool was_init = false;
987 if ( pad_plugin->controller_interface.IsInit() ) // check if game is running
988 was_init = true;
989 else
991 #if defined(HAVE_X11) && HAVE_X11
992 Window win = X11Utils::XWindowFromHandle(GetHandle());
993 GCPad_Init((void *)win);
994 #else
995 GCPad_Init(GetHandle());
996 #endif
998 InputConfigDialog* m_ConfigFrame = new InputConfigDialog(this, *pad_plugin, "Dolphin GCPad Configuration");
999 m_ConfigFrame->ShowModal();
1000 m_ConfigFrame->Destroy();
1001 if (!was_init) // if game isn't running
1003 GCPad_Deinit();
1007 void CFrame::OnPluginWiimote(wxCommandEvent& WXUNUSED (event))
1009 CPluginManager::GetInstance().OpenConfig(
1010 GetHandle(),
1011 SConfig::GetInstance().m_LocalCoreStartupParameter.m_strWiimotePlugin.c_str(),
1012 PLUGIN_TYPE_WIIMOTE
1016 void CFrame::OnHelp(wxCommandEvent& event)
1018 switch (event.GetId())
1020 case wxID_ABOUT:
1022 AboutDolphin frame(this);
1023 frame.ShowModal();
1025 break;
1026 case IDM_HELPWEBSITE:
1027 WxUtils::Launch("http://www.dolphin-emu.com/");
1028 break;
1029 case IDM_HELPGOOGLECODE:
1030 WxUtils::Launch("http://code.google.com/p/dolphin-emu/");
1031 break;
1035 void CFrame::ClearStatusBar()
1037 if (this->GetStatusBar()->IsEnabled()) this->GetStatusBar()->SetStatusText(wxT(""),0);
1040 void CFrame::StatusBarMessage(const char * Text, ...)
1042 const int MAX_BYTES = 1024*10;
1043 char Str[MAX_BYTES];
1044 va_list ArgPtr;
1045 int Cnt;
1046 va_start(ArgPtr, Text);
1047 Cnt = vsnprintf(Str, MAX_BYTES, Text, ArgPtr);
1048 va_end(ArgPtr);
1050 if (this->GetStatusBar()->IsEnabled()) this->GetStatusBar()->SetStatusText(wxString::FromAscii(Str),0);
1054 // Miscellaneous menus
1055 // ---------------------
1056 // NetPlay stuff
1057 void CFrame::OnNetPlay(wxCommandEvent& WXUNUSED (event))
1059 new NetPlaySetupDiag(this, m_GameListCtrl);
1062 void CFrame::OnMemcard(wxCommandEvent& WXUNUSED (event))
1064 CMemcardManager MemcardManager(this);
1065 MemcardManager.ShowModal();
1068 void CFrame::OnImportSave(wxCommandEvent& WXUNUSED (event))
1070 wxString path = wxFileSelector(_T("Select the save file"),
1071 wxEmptyString, wxEmptyString, wxEmptyString,
1072 wxString::Format
1074 _T("Wii save files|data.bin|All files (%s)|%s"),
1075 wxFileSelectorDefaultWildcardStr,
1076 wxFileSelectorDefaultWildcardStr
1078 wxFD_OPEN | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST,
1079 this);
1081 if (!path.IsEmpty())
1083 CWiiSaveCrypted* saveFile = new CWiiSaveCrypted(path.ToUTF8().data());
1084 delete saveFile;
1088 void CFrame::OnOpenLuaWindow(wxCommandEvent& WXUNUSED (event))
1090 new wxLuaWindow(this, wxDefaultPosition, wxSize(600, 390));
1093 void CFrame::OnShow_CheatsWindow(wxCommandEvent& WXUNUSED (event))
1095 CheatsWindow = new wxCheatsWindow(this);
1098 void CFrame::OnLoadWiiMenu(wxCommandEvent& event)
1100 if (event.GetId() == IDM_LOAD_WII_MENU)
1102 BootGame(std::string (File::GetUserPath(D_WIIMENU_IDX)));
1104 else
1107 wxString path = wxFileSelector(
1108 _T("Select the System Menu wad extracted from the update partition of a disc"),
1109 wxEmptyString, wxEmptyString, wxEmptyString,
1110 _T("System Menu (*.wad)|*.wad"),
1111 wxFD_OPEN | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST,
1112 this);
1114 if (CBoot::Install_WiiWAD(path.mb_str()))
1116 GetMenuBar()->FindItem(IDM_INSTALL_WII_MENU)->Enable(false);
1121 void CFrame::OnConnectWiimote(wxCommandEvent& event)
1123 if (Core::isRunning() && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
1125 int Id = event.GetId() - IDM_CONNECT_WIIMOTE1;
1126 bNoWiimoteMsg = !event.IsChecked();
1127 GetUsbPointer()->AccessWiiMote(Id | 0x100)->Activate(event.IsChecked());
1128 wxString msg(wxString::Format(wxT("Wiimote %i %s"), Id + 1, (event.IsChecked()) ? wxT("Connected") : wxT("Disconnected")));
1129 Core::DisplayMessage(msg.ToAscii(), 3000);
1133 // Toogle fullscreen. In Windows the fullscreen mode is accomplished by expanding the m_Panel to cover
1134 // the entire screen (when we render to the main window).
1135 void CFrame::OnToggleFullscreen(wxCommandEvent& WXUNUSED (event))
1137 DoFullscreen(!RendererIsFullscreen());
1140 void CFrame::OnToggleDualCore(wxCommandEvent& WXUNUSED (event))
1142 SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread = !SConfig::GetInstance().m_LocalCoreStartupParameter.bCPUThread;
1143 SConfig::GetInstance().SaveSettings();
1146 void CFrame::OnToggleSkipIdle(wxCommandEvent& WXUNUSED (event))
1148 SConfig::GetInstance().m_LocalCoreStartupParameter.bSkipIdle = !SConfig::GetInstance().m_LocalCoreStartupParameter.bSkipIdle;
1149 SConfig::GetInstance().SaveSettings();
1152 void CFrame::OnLoadStateFromFile(wxCommandEvent& WXUNUSED (event))
1154 wxString path = wxFileSelector(
1155 _T("Select the state to load"),
1156 wxEmptyString, wxEmptyString, wxEmptyString,
1157 wxString::Format
1159 _T("All Save States (sav, s##)|*.sav;*.s??|All files (%s)|%s"),
1160 wxFileSelectorDefaultWildcardStr,
1161 wxFileSelectorDefaultWildcardStr
1163 wxFD_OPEN | wxFD_PREVIEW | wxFD_FILE_MUST_EXIST,
1164 this);
1166 if(!path.IsEmpty())
1167 State_LoadAs((const char*)path.mb_str());
1170 void CFrame::OnSaveStateToFile(wxCommandEvent& WXUNUSED (event))
1172 wxString path = wxFileSelector(
1173 _T("Select the state to save"),
1174 wxEmptyString, wxEmptyString, wxEmptyString,
1175 wxString::Format
1177 _T("All Save States (sav, s##)|*.sav;*.s??|All files (%s)|%s"),
1178 wxFileSelectorDefaultWildcardStr,
1179 wxFileSelectorDefaultWildcardStr
1181 wxFD_SAVE,
1182 this);
1184 if(! path.IsEmpty())
1185 State_SaveAs((const char*)path.mb_str());
1188 void CFrame::OnLoadLastState(wxCommandEvent& WXUNUSED (event))
1190 State_LoadLastSaved();
1193 void CFrame::OnUndoLoadState(wxCommandEvent& WXUNUSED (event))
1195 State_UndoLoadState();
1198 void CFrame::OnUndoSaveState(wxCommandEvent& WXUNUSED (event))
1200 State_UndoSaveState();
1204 void CFrame::OnLoadState(wxCommandEvent& event)
1206 int id = event.GetId();
1207 int slot = id - IDM_LOADSLOT1 + 1;
1208 State_Load(slot);
1211 void CFrame::OnSaveState(wxCommandEvent& event)
1213 int id = event.GetId();
1214 int slot = id - IDM_SAVESLOT1 + 1;
1215 State_Save(slot);
1218 void CFrame::OnFrameSkip(wxCommandEvent& event)
1220 int amount = event.GetId() - IDM_FRAMESKIP0;
1222 Frame::SetFrameSkipping((unsigned int)amount);
1228 // GUI
1229 // ---------------------
1231 // Update the enabled/disabled status
1232 void CFrame::UpdateGUI()
1234 if (!m_bControlsCreated)
1235 return;
1237 // Save status
1238 bool Initialized = Core::isRunning();
1239 bool Running = Core::GetState() == Core::CORE_RUN;
1240 bool Paused = Core::GetState() == Core::CORE_PAUSE;
1242 // Make sure that we have a toolbar
1243 if (m_ToolBar)
1245 // Enable/disable the Config and Stop buttons
1246 m_ToolBar->EnableTool(wxID_OPEN, !Initialized);
1247 m_ToolBar->EnableTool(wxID_REFRESH, !Initialized); // Don't allow refresh when we don't show the list
1248 m_ToolBar->EnableTool(IDM_STOP, Running || Paused);
1249 m_ToolBar->EnableTool(IDM_TOGGLE_FULLSCREEN, Running || Paused);
1250 m_ToolBar->EnableTool(IDM_SCREENSHOT, Running || Paused);
1253 // File
1254 GetMenuBar()->FindItem(wxID_OPEN)->Enable(!Initialized);
1255 m_pSubMenuDrive->Enable(!Initialized);
1256 GetMenuBar()->FindItem(wxID_REFRESH)->Enable(!Initialized);
1257 GetMenuBar()->FindItem(IDM_BROWSE)->Enable(!Initialized);
1259 // Emulation
1260 GetMenuBar()->FindItem(IDM_STOP)->Enable(Running || Paused);
1261 GetMenuBar()->FindItem(IDM_RESET)->Enable(Running || Paused);
1262 GetMenuBar()->FindItem(IDM_RECORD)->Enable(!Initialized);
1263 GetMenuBar()->FindItem(IDM_PLAYRECORD)->Enable(!Initialized);
1264 GetMenuBar()->FindItem(IDM_FRAMESTEP)->Enable(Running || Paused);
1265 GetMenuBar()->FindItem(IDM_SCREENSHOT)->Enable(Running || Paused);
1266 GetMenuBar()->FindItem(IDM_TOGGLE_FULLSCREEN)->Enable(Running || Paused);
1268 // Update Menu Accelerators
1269 GetMenuBar()->FindItem(IDM_TOGGLE_FULLSCREEN)->SetItemLabel(GetMenuLabel(HK_FULLSCREEN));
1270 GetMenuBar()->FindItem(IDM_PLAY)->SetItemLabel(GetMenuLabel(HK_PLAY_PAUSE));
1271 GetMenuBar()->FindItem(IDM_STOP)->SetItemLabel(GetMenuLabel(HK_STOP));
1272 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE1)->SetItemLabel(GetMenuLabel(HK_WIIMOTE1_CONNECT));
1273 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE2)->SetItemLabel(GetMenuLabel(HK_WIIMOTE2_CONNECT));
1274 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE3)->SetItemLabel(GetMenuLabel(HK_WIIMOTE3_CONNECT));
1275 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE4)->SetItemLabel(GetMenuLabel(HK_WIIMOTE4_CONNECT));
1277 m_pSubMenuLoad->Enable(Initialized);
1278 m_pSubMenuSave->Enable(Initialized);
1280 // Misc
1281 GetMenuBar()->FindItem(IDM_CHANGEDISC)->Enable(Initialized);
1282 if (DiscIO::CNANDContentManager::Access().GetNANDLoader(std::string(File::GetUserPath(D_WIIMENU_IDX))).IsValid())
1283 GetMenuBar()->FindItem(IDM_LOAD_WII_MENU)->Enable(!Initialized);
1285 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE1)->Enable(Initialized && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii);
1286 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE2)->Enable(Initialized && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii);
1287 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE3)->Enable(Initialized && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii);
1288 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE4)->Enable(Initialized && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii);
1289 if (Initialized && SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
1291 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE1)->Check(GetUsbPointer()->AccessWiiMote(0x0100)->IsConnected() == 3);
1292 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE2)->Check(GetUsbPointer()->AccessWiiMote(0x0101)->IsConnected() == 3);
1293 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE3)->Check(GetUsbPointer()->AccessWiiMote(0x0102)->IsConnected() == 3);
1294 GetMenuBar()->FindItem(IDM_CONNECT_WIIMOTE4)->Check(GetUsbPointer()->AccessWiiMote(0x0103)->IsConnected() == 3);
1297 if (Running)
1299 if (m_ToolBar)
1301 m_ToolBar->SetToolBitmap(IDM_PLAY, m_Bitmaps[Toolbar_Pause]);
1302 m_ToolBar->SetToolShortHelp(IDM_PLAY, _("Pause"));
1303 m_ToolBar->SetToolLabel(IDM_PLAY, _("Pause"));
1306 else
1308 if (m_ToolBar)
1310 m_ToolBar->SetToolBitmap(IDM_PLAY, m_Bitmaps[Toolbar_Play]);
1311 m_ToolBar->SetToolShortHelp(IDM_PLAY, _("Play"));
1312 m_ToolBar->SetToolLabel(IDM_PLAY, wxT(" Play "));
1316 if (!Initialized)
1318 if (m_GameListCtrl->IsEnabled())
1320 // Prepare to load Default ISO, enable play button
1321 if (!SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDefaultGCM.empty())
1323 if (m_ToolBar)
1324 m_ToolBar->EnableTool(IDM_PLAY, true);
1325 GetMenuBar()->FindItem(IDM_PLAY)->Enable(true);
1327 // Prepare to load last selected file, enable play button
1328 else if (!SConfig::GetInstance().m_LastFilename.empty()
1329 && wxFileExists(wxString(SConfig::GetInstance().m_LastFilename.c_str(), wxConvUTF8)))
1331 if (m_ToolBar)
1332 m_ToolBar->EnableTool(IDM_PLAY, true);
1333 GetMenuBar()->FindItem(IDM_PLAY)->Enable(true);
1335 else
1337 // No game has been selected yet, disable play button
1338 if (m_ToolBar)
1339 m_ToolBar->EnableTool(IDM_PLAY, false);
1340 GetMenuBar()->FindItem(IDM_PLAY)->Enable(false);
1344 if (m_GameListCtrl && !m_bGameLoading)
1346 // Game has not started, show game list
1347 if (!m_GameListCtrl->IsShown())
1349 m_GameListCtrl->Enable();
1350 m_GameListCtrl->Show();
1352 // Game has been selected but not started, enable play button
1353 if (m_GameListCtrl->GetSelectedISO() != NULL && m_GameListCtrl->IsEnabled() && !m_bGameLoading)
1355 if (m_ToolBar)
1356 m_ToolBar->EnableTool(IDM_PLAY, true);
1357 GetMenuBar()->FindItem(IDM_PLAY)->Enable(true);
1361 else
1363 // Game has been loaded, enable the pause button
1364 if (m_ToolBar)
1365 m_ToolBar->EnableTool(IDM_PLAY, true);
1366 GetMenuBar()->FindItem(IDM_PLAY)->Enable(true);
1368 // Reset game loading flag
1369 m_bGameLoading = false;
1372 if (m_ToolBar) m_ToolBar->Refresh();
1373 if (g_pCodeWindow) g_pCodeWindow->Update();
1375 // Commit changes to manager
1376 m_Mgr->Update();
1379 void CFrame::UpdateGameList()
1381 m_GameListCtrl->Update();
1384 void CFrame::GameListChanged(wxCommandEvent& event)
1386 switch (event.GetId())
1388 case IDM_LISTWII:
1389 SConfig::GetInstance().m_ListWii = event.IsChecked();
1390 break;
1391 case IDM_LISTGC:
1392 SConfig::GetInstance().m_ListGC = event.IsChecked();
1393 break;
1394 case IDM_LISTWAD:
1395 SConfig::GetInstance().m_ListWad = event.IsChecked();
1396 break;
1397 case IDM_LISTJAP:
1398 SConfig::GetInstance().m_ListJap = event.IsChecked();
1399 break;
1400 case IDM_LISTPAL:
1401 SConfig::GetInstance().m_ListPal = event.IsChecked();
1402 break;
1403 case IDM_LISTUSA:
1404 SConfig::GetInstance().m_ListUsa = event.IsChecked();
1405 break;
1406 case IDM_LISTFRANCE:
1407 SConfig::GetInstance().m_ListFrance = event.IsChecked();
1408 break;
1409 case IDM_LISTITALY:
1410 SConfig::GetInstance().m_ListItaly = event.IsChecked();
1411 break;
1412 case IDM_LISTKOREA:
1413 SConfig::GetInstance().m_ListKorea = event.IsChecked();
1414 break;
1415 case IDM_LISTTAIWAN:
1416 SConfig::GetInstance().m_ListTaiwan = event.IsChecked();
1417 break;
1418 case IDM_LIST_UNK:
1419 SConfig::GetInstance().m_ListUnknown = event.IsChecked();
1420 break;
1421 case IDM_LISTDRIVES:
1422 SConfig::GetInstance().m_ListDrives = event.IsChecked();
1423 break;
1424 case IDM_PURGECACHE:
1425 CFileSearch::XStringVector Directories;
1426 Directories.push_back(File::GetUserPath(D_CACHE_IDX));
1427 CFileSearch::XStringVector Extensions;
1428 Extensions.push_back("*.cache");
1430 CFileSearch FileSearch(Extensions, Directories);
1431 const CFileSearch::XStringVector& rFilenames = FileSearch.GetFileNames();
1433 for (u32 i = 0; i < rFilenames.size(); i++)
1435 File::Delete(rFilenames[i].c_str());
1437 break;
1440 if (m_GameListCtrl) m_GameListCtrl->Update();
1443 // Enable and disable the toolbar
1444 void CFrame::OnToggleToolbar(wxCommandEvent& event)
1446 SConfig::GetInstance().m_InterfaceToolbar = event.IsChecked();
1447 DoToggleToolbar(event.IsChecked());
1449 void CFrame::DoToggleToolbar(bool _show)
1451 if (_show)
1453 m_Mgr->GetPane(wxT("TBMain")).Show();
1454 if (g_pCodeWindow)
1456 m_Mgr->GetPane(wxT("TBDebug")).Show();
1457 m_Mgr->GetPane(wxT("TBAui")).Show();
1459 m_Mgr->Update();
1461 else
1463 m_Mgr->GetPane(wxT("TBMain")).Hide();
1464 if (g_pCodeWindow)
1466 m_Mgr->GetPane(wxT("TBDebug")).Hide();
1467 m_Mgr->GetPane(wxT("TBAui")).Hide();
1469 m_Mgr->Update();
1473 // Enable and disable the status bar
1474 void CFrame::OnToggleStatusbar(wxCommandEvent& event)
1476 SConfig::GetInstance().m_InterfaceStatusbar = event.IsChecked();
1477 if (SConfig::GetInstance().m_InterfaceStatusbar == true)
1478 m_pStatusBar->Show();
1479 else
1480 m_pStatusBar->Hide();
1482 this->SendSizeEvent();