DolphinWX: Move main menu creation into a wxMenuBar subclass

Keeps the actual GUI elements separate from the frame code.
This commit is contained in:
Lioncash
2016-10-20 09:54:29 -04:00
parent d2d4edf964
commit f871b2177e
9 changed files with 782 additions and 726 deletions
+1
View File
@@ -53,6 +53,7 @@ set(GUI_SRCS
LogConfigWindow.cpp
LogWindow.cpp
Main.cpp
MainMenuBar.cpp
MemcardManager.cpp
PatchAddEdit.cpp
PostProcessingConfigDiag.cpp
+2
View File
@@ -107,6 +107,7 @@
<ClCompile Include="LogConfigWindow.cpp" />
<ClCompile Include="LogWindow.cpp" />
<ClCompile Include="Main.cpp" />
<ClCompile Include="MainMenuBar.cpp" />
<ClCompile Include="MainNoGUI.cpp">
<ExcludedFromBuild>true</ExcludedFromBuild>
</ClCompile>
@@ -173,6 +174,7 @@
<ClInclude Include="LogConfigWindow.h" />
<ClInclude Include="LogWindow.h" />
<ClInclude Include="Main.h" />
<ClInclude Include="MainMenuBar.h" />
<ClInclude Include="MemcardManager.h" />
<ClInclude Include="PatchAddEdit.h" />
<ClInclude Include="SoftwareVideoConfigDialog.h" />
@@ -148,6 +148,9 @@
<ClCompile Include="LogWindow.cpp">
<Filter>GUI</Filter>
</ClCompile>
<ClCompile Include="MainMenuBar.cpp">
<Filter>GUI</Filter>
</ClCompile>
<ClCompile Include="MemcardManager.cpp">
<Filter>GUI</Filter>
</ClCompile>
@@ -324,6 +327,9 @@
<ClInclude Include="LogWindow.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="MainMenuBar.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="MemcardManager.h">
<Filter>GUI</Filter>
</ClInclude>
+6 -84
View File
@@ -220,96 +220,17 @@ bool CRenderFrame::ShowFullScreen(bool show, long style)
return result;
}
// event tables
// Notice that wxID_HELP will be processed for the 'About' menu and the toolbar
// help button.
wxDEFINE_EVENT(wxEVT_HOST_COMMAND, wxCommandEvent);
wxDEFINE_EVENT(DOLPHIN_EVT_LOCAL_INI_CHANGED, wxCommandEvent);
// Event tables
BEGIN_EVENT_TABLE(CFrame, CRenderFrame)
// Menu bar
EVT_MENU(wxID_OPEN, CFrame::OnOpen)
EVT_MENU(wxID_EXIT, CFrame::OnQuit)
EVT_MENU(IDM_HELP_WEBSITE, CFrame::OnHelp)
EVT_MENU(IDM_HELP_ONLINE_DOCS, CFrame::OnHelp)
EVT_MENU(IDM_HELP_GITHUB, CFrame::OnHelp)
EVT_MENU(wxID_ABOUT, CFrame::OnHelp)
EVT_MENU(wxID_REFRESH, CFrame::OnRefresh)
EVT_MENU(IDM_PLAY, CFrame::OnPlay)
EVT_MENU(IDM_STOP, CFrame::OnStop)
EVT_MENU(IDM_RESET, CFrame::OnReset)
EVT_MENU(IDM_RECORD, CFrame::OnRecord)
EVT_MENU(IDM_PLAY_RECORD, CFrame::OnPlayRecording)
EVT_MENU(IDM_RECORD_EXPORT, CFrame::OnRecordExport)
EVT_MENU(IDM_RECORD_READ_ONLY, CFrame::OnRecordReadOnly)
EVT_MENU(IDM_TAS_INPUT, CFrame::OnTASInput)
EVT_MENU(IDM_TOGGLE_PAUSE_MOVIE, CFrame::OnTogglePauseMovie)
EVT_MENU(IDM_SHOW_LAG, CFrame::OnShowLag)
EVT_MENU(IDM_SHOW_FRAME_COUNT, CFrame::OnShowFrameCount)
EVT_MENU(IDM_SHOW_INPUT_DISPLAY, CFrame::OnShowInputDisplay)
EVT_MENU(IDM_SHOW_RTC_DISPLAY, CFrame::OnShowRTCDisplay)
EVT_MENU(IDM_FRAMESTEP, CFrame::OnFrameStep)
EVT_MENU(IDM_SCREENSHOT, CFrame::OnScreenshot)
EVT_MENU(IDM_TOGGLE_DUMP_FRAMES, CFrame::OnToggleDumpFrames)
EVT_MENU(IDM_TOGGLE_DUMP_AUDIO, CFrame::OnToggleDumpAudio)
EVT_MENU(wxID_PREFERENCES, CFrame::OnConfigMain)
EVT_MENU(IDM_CONFIG_GFX_BACKEND, CFrame::OnConfigGFX)
EVT_MENU(IDM_CONFIG_AUDIO, CFrame::OnConfigAudio)
EVT_MENU(IDM_CONFIG_CONTROLLERS, CFrame::OnConfigControllers)
EVT_MENU(IDM_CONFIG_HOTKEYS, CFrame::OnConfigHotkey)
EVT_MENU(IDM_SAVE_PERSPECTIVE, CFrame::OnPerspectiveMenu)
EVT_MENU(IDM_EDIT_PERSPECTIVES, CFrame::OnPerspectiveMenu)
// Drop down
EVT_MENU(IDM_PERSPECTIVES_ADD_PANE_TOP, CFrame::OnPerspectiveMenu)
EVT_MENU(IDM_PERSPECTIVES_ADD_PANE_BOTTOM, CFrame::OnPerspectiveMenu)
EVT_MENU(IDM_PERSPECTIVES_ADD_PANE_LEFT, CFrame::OnPerspectiveMenu)
EVT_MENU(IDM_PERSPECTIVES_ADD_PANE_RIGHT, CFrame::OnPerspectiveMenu)
EVT_MENU(IDM_PERSPECTIVES_ADD_PANE_CENTER, CFrame::OnPerspectiveMenu)
EVT_MENU_RANGE(IDM_PERSPECTIVES_0, IDM_PERSPECTIVES_100, CFrame::OnSelectPerspective)
EVT_MENU(IDM_ADD_PERSPECTIVE, CFrame::OnPerspectiveMenu)
EVT_MENU(IDM_TAB_SPLIT, CFrame::OnPerspectiveMenu)
EVT_MENU(IDM_NO_DOCKING, CFrame::OnPerspectiveMenu)
// Drop down float
// Debugger pane context menu
EVT_MENU_RANGE(IDM_FLOAT_LOG_WINDOW, IDM_FLOAT_CODE_WINDOW, CFrame::OnFloatWindow)
EVT_MENU(IDM_NETPLAY, CFrame::OnNetPlay)
EVT_MENU(IDM_MEMCARD, CFrame::OnMemcard)
EVT_MENU(IDM_IMPORT_SAVE, CFrame::OnImportSave)
EVT_MENU(IDM_EXPORT_ALL_SAVE, CFrame::OnExportAllSaves)
EVT_MENU(IDM_CHEATS, CFrame::OnShowCheatsWindow)
EVT_MENU(IDM_CHANGE_DISC, CFrame::OnChangeDisc)
EVT_MENU(IDM_MENU_INSTALL_WAD, CFrame::OnInstallWAD)
// Game list context menu
EVT_MENU(IDM_LIST_INSTALL_WAD, CFrame::OnInstallWAD)
EVT_MENU(IDM_LOAD_WII_MENU, CFrame::OnLoadWiiMenu)
EVT_MENU(IDM_FIFOPLAYER, CFrame::OnFifoPlayer)
EVT_MENU(IDM_TOGGLE_FULLSCREEN, CFrame::OnToggleFullscreen)
EVT_MENU(IDM_TOGGLE_DUAL_CORE, CFrame::OnToggleDualCore)
EVT_MENU(IDM_TOGGLE_TOOLBAR, CFrame::OnToggleToolbar)
EVT_MENU(IDM_TOGGLE_STATUSBAR, CFrame::OnToggleStatusbar)
EVT_MENU_RANGE(IDM_LOG_WINDOW, IDM_VIDEO_WINDOW, CFrame::OnToggleWindow)
EVT_MENU_RANGE(IDM_SHOW_SYSTEM, IDM_SHOW_STATE, CFrame::OnChangeColumnsVisible)
EVT_MENU(IDM_PURGE_GAME_LIST_CACHE, CFrame::GameListChanged)
EVT_MENU(IDM_SAVE_FIRST_STATE, CFrame::OnSaveFirstState)
EVT_MENU(IDM_UNDO_LOAD_STATE, CFrame::OnUndoLoadState)
EVT_MENU(IDM_UNDO_SAVE_STATE, CFrame::OnUndoSaveState)
EVT_MENU(IDM_LOAD_STATE_FILE, CFrame::OnLoadStateFromFile)
EVT_MENU(IDM_SAVE_STATE_FILE, CFrame::OnSaveStateToFile)
EVT_MENU(IDM_SAVE_SELECTED_SLOT, CFrame::OnSaveCurrentSlot)
EVT_MENU(IDM_LOAD_SELECTED_SLOT, CFrame::OnLoadCurrentSlot)
EVT_MENU_RANGE(IDM_LOAD_SLOT_1, IDM_LOAD_SLOT_10, CFrame::OnLoadState)
EVT_MENU_RANGE(IDM_LOAD_LAST_1, IDM_LOAD_LAST_10, CFrame::OnLoadLastState)
EVT_MENU_RANGE(IDM_SAVE_SLOT_1, IDM_SAVE_SLOT_10, CFrame::OnSaveState)
EVT_MENU_RANGE(IDM_SELECT_SLOT_1, IDM_SELECT_SLOT_10, CFrame::OnSelectSlot)
EVT_MENU_RANGE(IDM_DRIVE1, IDM_DRIVE24, CFrame::OnBootDrive)
EVT_MENU_RANGE(IDM_CONNECT_WIIMOTE1, IDM_CONNECT_BALANCEBOARD, CFrame::OnConnectWiimote)
EVT_MENU_RANGE(IDM_LIST_WAD, IDM_LIST_DRIVES, CFrame::GameListChanged)
// Other
EVT_ACTIVATE(CFrame::OnActive)
@@ -378,6 +299,8 @@ CFrame::CFrame(wxFrame* parent, wxWindowID id, const wxString& title, wxRect geo
UseDebugger(use_debugger), m_bBatchMode(batch_mode),
m_toolbar_bitmap_size(FromDIP(wxSize(32, 32)))
{
BindMenuBarEvents();
for (int i = 0; i <= IDM_CODE_WINDOW - IDM_LOG_WINDOW; i++)
bFloatWindow[i] = false;
@@ -401,8 +324,7 @@ CFrame::CFrame(wxFrame* parent, wxWindowID id, const wxString& title, wxRect geo
GetStatusBar()->Hide();
// Give it a menu bar
wxMenuBar* menubar_active = CreateMenuBar();
SetMenuBar(menubar_active);
SetMenuBar(CreateMenuBar());
// Create a menubar to service requests while the real menubar is hidden from the screen
m_menubar_shadow = CreateMenuBar();
+5 -14
View File
@@ -106,7 +106,6 @@ public:
void DoFullscreen(bool bF);
void ToggleDisplayMode(bool bFullscreen);
void UpdateWiiMenuChoice(wxMenuItem* WiiMenuItem = nullptr);
void PopulateSavedPerspectives();
static void ConnectWiimote(int wm_idx, bool connect);
void UpdateTitle(const std::string& str);
void OpenGeneralConfiguration(int tab = -1);
@@ -199,21 +198,11 @@ private:
void PopulateToolbar(wxToolBar* toolBar);
void RecreateToolbar();
wxMenuBar* CreateMenuBar();
wxMenu* CreateFileMenu();
wxMenu* CreateEmulationMenu();
wxMenu* CreateMovieMenu();
wxMenu* CreateOptionsMenu();
wxMenu* CreateToolsMenu();
wxMenu* CreateViewMenu();
wxMenu* CreateJITMenu();
wxMenu* CreateDebugMenu();
wxMenu* CreateSymbolsMenu();
wxMenu* CreateProfilerMenu();
wxMenu* CreateHelpMenu();
wxMenuBar* CreateMenuBar() const;
void BindMenuBarEvents();
// Utility
wxString GetMenuLabel(int Id);
wxWindow* GetNotebookPageFromId(wxWindowID Id);
wxAuiNotebook* GetNotebookFromId(u32 NBId);
int GetNotebookCount();
@@ -236,6 +225,8 @@ private:
void SetPaneSize();
void TogglePaneStyle(bool On, int EventId);
void ToggleNotebookStyle(bool On, long Style);
void PopulateSavedPerspectives();
// Float window
void DoUnfloatPage(int Id);
void OnFloatingPageClosed(wxCloseEvent& event);
+9 -23
View File
@@ -2,6 +2,7 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include <algorithm>
#include <cstddef>
#include <string>
#include <vector>
@@ -36,6 +37,7 @@
#include "DolphinWX/Globals.h"
#include "DolphinWX/LogConfigWindow.h"
#include "DolphinWX/LogWindow.h"
#include "DolphinWX/MainMenuBar.h"
#include "DolphinWX/WxUtils.h"
#include "DolphinWX/Debugger/DebuggerUIUtil.h"
@@ -484,32 +486,16 @@ void CFrame::DoAddPage(wxWindow* Win, int i, bool Float)
void CFrame::PopulateSavedPerspectives()
{
// If the perspective submenu hasn't been created yet, return
if (!m_SavedPerspectives)
return;
std::vector<std::string> perspective_names(Perspectives.size());
// Delete all saved perspective menu items
while (m_SavedPerspectives->GetMenuItemCount() != 0)
{
// Delete the first menu item in the list (while there are menu items)
m_SavedPerspectives->Delete(m_SavedPerspectives->FindItemByPosition(0));
}
std::transform(Perspectives.begin(), Perspectives.end(), perspective_names.begin(),
[](const auto& perspective) { return perspective.Name; });
if (Perspectives.size() > 0)
{
for (u32 i = 0; i < Perspectives.size(); i++)
{
wxMenuItem* mItem = new wxMenuItem(m_SavedPerspectives, IDM_PERSPECTIVES_0 + i,
StrToWxStr(Perspectives[i].Name), "", wxITEM_CHECK);
MainMenuBar::PopulatePerspectivesEvent event{GetId(), EVT_POPULATE_PERSPECTIVES_MENU,
std::move(perspective_names),
static_cast<int>(ActivePerspective)};
m_SavedPerspectives->Append(mItem);
if (i == ActivePerspective)
{
mItem->Check(true);
}
}
}
wxPostEvent(GetMenuBar(), event);
}
void CFrame::OnPerspectiveMenu(wxCommandEvent& event)
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+77
View File
@@ -0,0 +1,77 @@
// Copyright 2016 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <string>
#include <vector>
#include <wx/event.h>
#include <wx/menu.h>
class MainMenuBar final : public wxMenuBar
{
public:
class PopulatePerspectivesEvent;
enum class MenuType
{
Regular,
Debug
};
explicit MainMenuBar(MenuType type, long style = 0);
void Refresh(bool erase_background, const wxRect* rect = nullptr) override;
private:
void AddMenus();
void BindEvents();
wxMenu* CreateFileMenu() const;
wxMenu* CreateEmulationMenu() const;
wxMenu* CreateMovieMenu() const;
wxMenu* CreateOptionsMenu() const;
wxMenu* CreateToolsMenu() const;
wxMenu* CreateViewMenu() const;
wxMenu* CreateJITMenu() const;
wxMenu* CreateDebugMenu();
wxMenu* CreateSymbolsMenu() const;
wxMenu* CreateProfilerMenu() const;
wxMenu* CreateHelpMenu() const;
void OnPopulatePerspectivesMenu(PopulatePerspectivesEvent&);
void RefreshMenuLabels() const;
void RefreshPlayMenuLabel() const;
void RefreshSaveStateMenuLabels() const;
void RefreshWiiSystemMenuLabel() const;
void ClearSavedPerspectivesMenu() const;
void PopulateSavedPerspectivesMenu(const std::vector<std::string>& label_names) const;
void CheckPerspectiveWithID(int perspective_id) const;
wxMenu* m_saved_perspectives_menu{};
MenuType m_type{};
};
class MainMenuBar::PopulatePerspectivesEvent final : public wxEvent
{
public:
PopulatePerspectivesEvent(int sender_id, wxEventType event_type,
std::vector<std::string> perspective_names, int active_perspective)
: wxEvent{sender_id, event_type}, m_perspective_names{std::move(perspective_names)},
m_active_perspective{active_perspective}
{
}
const std::vector<std::string>& PerspectiveNames() const { return m_perspective_names; }
int ActivePerspective() const { return m_active_perspective; }
wxEvent* Clone() const override { return new PopulatePerspectivesEvent(*this); }
private:
std::vector<std::string> m_perspective_names;
int m_active_perspective{};
};
wxDECLARE_EVENT(EVT_POPULATE_PERSPECTIVES_MENU, MainMenuBar::PopulatePerspectivesEvent);