From 5e8ccb15ff4c917c1934a162ce92208358908ac3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 21 Oct 2016 21:41:17 -0400 Subject: [PATCH 1/2] DolphinWX: Move toolbar creation to a wxToolBar subclass --- Source/Core/DolphinWX/CMakeLists.txt | 1 + Source/Core/DolphinWX/Config/ConfigMain.cpp | 2 + .../DolphinWX/Config/InterfaceConfigPane.cpp | 6 +- Source/Core/DolphinWX/Debugger/CodeWindow.cpp | 52 ---- Source/Core/DolphinWX/Debugger/CodeWindow.h | 6 - Source/Core/DolphinWX/DolphinWX.vcxproj | 2 + .../Core/DolphinWX/DolphinWX.vcxproj.filters | 6 + Source/Core/DolphinWX/Frame.cpp | 19 +- Source/Core/DolphinWX/Frame.h | 33 +-- Source/Core/DolphinWX/FrameTools.cpp | 144 ++-------- Source/Core/DolphinWX/Globals.h | 11 - Source/Core/DolphinWX/MainToolBar.cpp | 255 ++++++++++++++++++ Source/Core/DolphinWX/MainToolBar.h | 84 ++++++ 13 files changed, 395 insertions(+), 226 deletions(-) create mode 100644 Source/Core/DolphinWX/MainToolBar.cpp create mode 100644 Source/Core/DolphinWX/MainToolBar.h diff --git a/Source/Core/DolphinWX/CMakeLists.txt b/Source/Core/DolphinWX/CMakeLists.txt index 92b009d9ab..ba5b076938 100644 --- a/Source/Core/DolphinWX/CMakeLists.txt +++ b/Source/Core/DolphinWX/CMakeLists.txt @@ -54,6 +54,7 @@ set(GUI_SRCS LogWindow.cpp Main.cpp MainMenuBar.cpp + MainToolBar.cpp MemcardManager.cpp PatchAddEdit.cpp PostProcessingConfigDiag.cpp diff --git a/Source/Core/DolphinWX/Config/ConfigMain.cpp b/Source/Core/DolphinWX/Config/ConfigMain.cpp index 1836167ede..9e570e3e86 100644 --- a/Source/Core/DolphinWX/Config/ConfigMain.cpp +++ b/Source/Core/DolphinWX/Config/ConfigMain.cpp @@ -37,6 +37,8 @@ CConfigMain::CConfigMain(wxWindow* parent, wxWindowID id, const wxString& title, Bind(wxEVT_BUTTON, &CConfigMain::OnCloseButton, this, wxID_CLOSE); Bind(wxDOLPHIN_CFG_REFRESH_LIST, &CConfigMain::OnSetRefreshGameListOnClose, this); + wxDialog::SetExtraStyle(GetExtraStyle() & ~wxWS_EX_BLOCK_EVENTS); + CreateGUIControls(); } diff --git a/Source/Core/DolphinWX/Config/InterfaceConfigPane.cpp b/Source/Core/DolphinWX/Config/InterfaceConfigPane.cpp index eb3912f306..c1863e120e 100644 --- a/Source/Core/DolphinWX/Config/InterfaceConfigPane.cpp +++ b/Source/Core/DolphinWX/Config/InterfaceConfigPane.cpp @@ -25,7 +25,6 @@ #include "DolphinWX/Config/InterfaceConfigPane.h" #include "DolphinWX/Frame.h" #include "DolphinWX/InputConfigDiag.h" -#include "DolphinWX/Main.h" #include "DolphinWX/WxUtils.h" #if defined(HAVE_XRANDR) && HAVE_XRANDR @@ -241,6 +240,7 @@ void InterfaceConfigPane::OnThemeSelected(wxCommandEvent& event) { SConfig::GetInstance().theme_name = WxStrToStr(m_theme_choice->GetStringSelection()); - main_frame->InitBitmaps(); - main_frame->UpdateGameList(); + wxCommandEvent theme_event{DOLPHIN_EVT_RELOAD_THEME_BITMAPS}; + theme_event.SetEventObject(this); + ProcessEvent(theme_event); } diff --git a/Source/Core/DolphinWX/Debugger/CodeWindow.cpp b/Source/Core/DolphinWX/Debugger/CodeWindow.cpp index 388160f384..cddde0e7b2 100644 --- a/Source/Core/DolphinWX/Debugger/CodeWindow.cpp +++ b/Source/Core/DolphinWX/Debugger/CodeWindow.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include // clang-format on @@ -58,8 +57,6 @@ CCodeWindow::CCodeWindow(const SConfig& _LocalCoreStartupParameter, CFrame* pare : wxPanel(parent, id, position, size, style, name), m_sibling_panels(), Parent(parent), codeview(nullptr) { - InitBitmaps(); - DebugInterface* di = &PowerPC::debug_interface; codeview = new CCodeView(di, &g_symbolDB, this, wxID_ANY); @@ -140,11 +137,6 @@ wxMenuBar* CCodeWindow::GetMenuBar() return Parent->GetMenuBar(); } -wxToolBar* CCodeWindow::GetToolBar() -{ - return Parent->m_ToolBar; -} - // ---------- // Events @@ -574,36 +566,6 @@ bool CCodeWindow::JITNoBlockLinking() return GetMenuBar()->IsChecked(IDM_JIT_NO_BLOCK_LINKING); } -// Toolbar -void CCodeWindow::InitBitmaps() -{ - static constexpr std::array s_image_names{ - {"toolbar_debugger_step", "toolbar_debugger_step_over", "toolbar_debugger_step_out", - "toolbar_debugger_skip", "toolbar_debugger_goto_pc", "toolbar_debugger_set_pc"}}; - const wxSize tool_size = Parent->GetToolbarBitmapSize(); - for (std::size_t i = 0; i < s_image_names.size(); ++i) - m_Bitmaps[i] = - WxUtils::LoadScaledResourceBitmap(s_image_names[i], Parent, tool_size, wxDefaultSize, - WxUtils::LSI_SCALE_DOWN | WxUtils::LSI_ALIGN_CENTER); -} - -void CCodeWindow::PopulateToolbar(wxToolBar* toolBar) -{ - WxUtils::AddToolbarButton(toolBar, IDM_STEP, _("Step"), m_Bitmaps[Toolbar_Step], - _("Step into the next instruction")); - WxUtils::AddToolbarButton(toolBar, IDM_STEPOVER, _("Step Over"), m_Bitmaps[Toolbar_StepOver], - _("Step over the next instruction")); - WxUtils::AddToolbarButton(toolBar, IDM_STEPOUT, _("Step Out"), m_Bitmaps[Toolbar_StepOut], - _("Step out of the current function")); - WxUtils::AddToolbarButton(toolBar, IDM_SKIP, _("Skip"), m_Bitmaps[Toolbar_Skip], - _("Skips the next instruction completely")); - toolBar->AddSeparator(); - WxUtils::AddToolbarButton(toolBar, IDM_GOTOPC, _("Show PC"), m_Bitmaps[Toolbar_GotoPC], - _("Go to the current instruction")); - WxUtils::AddToolbarButton(toolBar, IDM_SETPC, _("Set PC"), m_Bitmaps[Toolbar_SetPC], - _("Set the current instruction")); -} - // Update GUI void CCodeWindow::Repopulate() { @@ -625,21 +587,7 @@ void CCodeWindow::UpdateButtonStates() bool Pause = (Core::GetState() == Core::CORE_PAUSE); bool Stepping = CPU::IsStepping(); bool can_step = Initialized && Stepping; - wxToolBar* ToolBar = GetToolBar(); - // Toolbar - if (!ToolBar) - return; - - ToolBar->EnableTool(IDM_STEP, can_step); - ToolBar->EnableTool(IDM_STEPOVER, can_step); - ToolBar->EnableTool(IDM_STEPOUT, can_step); - ToolBar->EnableTool(IDM_SKIP, can_step); - ToolBar->EnableTool(IDM_SETPC, Pause); - ToolBar->Realize(); - - // Menu bar - // ------------------ GetMenuBar()->Enable(IDM_INTERPRETER, Pause); // CPU Mode GetMenuBar()->Enable(IDM_STEP, can_step); diff --git a/Source/Core/DolphinWX/Debugger/CodeWindow.h b/Source/Core/DolphinWX/Debugger/CodeWindow.h index ccd7f4163e..255bd5fe5b 100644 --- a/Source/Core/DolphinWX/Debugger/CodeWindow.h +++ b/Source/Core/DolphinWX/Debugger/CodeWindow.h @@ -7,7 +7,6 @@ #include #include -#include #include #include "Common/CommonTypes.h" @@ -86,7 +85,6 @@ public: // Parent interaction wxMenuBar* GetMenuBar(); - wxToolBar* GetToolBar(); bool UseInterpreter(); bool BootToPause(); @@ -97,7 +95,6 @@ public: void Repopulate(); void NotifyMapLoaded(); - void PopulateToolbar(wxToolBar* toolBar); void UpdateButtonStates(); void OpenPages(); @@ -157,11 +154,8 @@ private: void UpdateLists(); void UpdateCallstack(); - void InitBitmaps(); wxPanel* CreateSiblingPanel(int id); - wxBitmap m_Bitmaps[Toolbar_Debug_Bitmap_Max]; - // Sibling debugger panels // FIXME: This obviously belongs in some manager class above this one. std::array m_sibling_panels; diff --git a/Source/Core/DolphinWX/DolphinWX.vcxproj b/Source/Core/DolphinWX/DolphinWX.vcxproj index cb8f409141..b3bf40f906 100644 --- a/Source/Core/DolphinWX/DolphinWX.vcxproj +++ b/Source/Core/DolphinWX/DolphinWX.vcxproj @@ -111,6 +111,7 @@ true + @@ -175,6 +176,7 @@ + diff --git a/Source/Core/DolphinWX/DolphinWX.vcxproj.filters b/Source/Core/DolphinWX/DolphinWX.vcxproj.filters index a24ec892d0..32cf32242e 100644 --- a/Source/Core/DolphinWX/DolphinWX.vcxproj.filters +++ b/Source/Core/DolphinWX/DolphinWX.vcxproj.filters @@ -151,6 +151,9 @@ GUI + + GUI + GUI @@ -330,6 +333,9 @@ GUI + + GUI + GUI diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index 5978dfc49d..9c39e5b754 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "AudioCommon/AudioCommon.h" @@ -222,6 +223,7 @@ bool CRenderFrame::ShowFullScreen(bool show, long style) wxDEFINE_EVENT(wxEVT_HOST_COMMAND, wxCommandEvent); wxDEFINE_EVENT(DOLPHIN_EVT_LOCAL_INI_CHANGED, wxCommandEvent); +wxDEFINE_EVENT(DOLPHIN_EVT_RELOAD_THEME_BITMAPS, wxCommandEvent); // Event tables BEGIN_EVENT_TABLE(CFrame, CRenderFrame) @@ -293,10 +295,9 @@ static BOOL WINAPI s_ctrl_handler(DWORD fdwCtrlType) CFrame::CFrame(wxFrame* parent, wxWindowID id, const wxString& title, wxRect geometry, bool use_debugger, bool batch_mode, bool show_log_window, long style) : CRenderFrame(parent, id, title, wxDefaultPosition, wxSize(800, 600), style), - UseDebugger(use_debugger), m_bBatchMode(batch_mode), - m_toolbar_bitmap_size(FromDIP(wxSize(32, 32))) + UseDebugger(use_debugger), m_bBatchMode(batch_mode) { - BindMenuBarEvents(); + BindEvents(); for (int i = 0; i <= IDM_CODE_WINDOW - IDM_LOG_WINDOW; i++) bFloatWindow[i] = false; @@ -312,8 +313,7 @@ CFrame::CFrame(wxFrame* parent, wxWindowID id, const wxString& title, wxRect geo g_pCodeWindow->Load(); } - // Create toolbar bitmaps - InitBitmaps(); + wxFrame::CreateToolBar(wxTB_DEFAULT_STYLE | wxTB_TEXT | wxTB_FLAT); // Give it a status bar SetStatusBar(CreateStatusBar(2, wxST_SIZEGRIP, ID_STATUSBAR)); @@ -361,8 +361,6 @@ CFrame::CFrame(wxFrame* parent, wxWindowID id, const wxString& title, wxRect geo .Hide()); AuiFullscreen = m_Mgr->SavePerspective(); - // Create toolbar - RecreateToolbar(); if (!SConfig::GetInstance().m_InterfaceToolbar) DoToggleToolbar(false); @@ -483,6 +481,13 @@ CFrame::~CFrame() m_menubar_shadow = nullptr; } +void CFrame::BindEvents() +{ + BindMenuBarEvents(); + + Bind(DOLPHIN_EVT_RELOAD_THEME_BITMAPS, &CFrame::OnReloadThemeBitmaps, this); +} + bool CFrame::RendererIsFullscreen() { bool fullscreen = false; diff --git a/Source/Core/DolphinWX/Frame.h b/Source/Core/DolphinWX/Frame.h index 883b2db9f4..33db6e7eb1 100644 --- a/Source/Core/DolphinWX/Frame.h +++ b/Source/Core/DolphinWX/Frame.h @@ -59,6 +59,8 @@ private: #endif }; +wxDECLARE_EVENT(DOLPHIN_EVT_RELOAD_THEME_BITMAPS, wxCommandEvent); + class CFrame : public CRenderFrame { public: @@ -84,7 +86,6 @@ public: wxCheatsWindow* g_CheatsWindow = nullptr; TASInputDlg* g_TASInputDlg[8]; - void InitBitmaps(); void DoPause(); void DoStop(); void OnStopped(); @@ -112,7 +113,6 @@ public: const CGameListCtrl* GetGameListCtrl() const; wxMenuBar* GetMenuBar() const override; - const wxSize& GetToolbarBitmapSize() const; // Needed before the toolbar exists #ifdef __WXGTK__ Common::Event panic_event; @@ -126,7 +126,6 @@ public: wxMenu* m_SavedPerspectives = nullptr; - wxToolBar* m_ToolBar = nullptr; // AUI wxAuiManager* m_Mgr = nullptr; bool bFloatWindow[IDM_DEBUG_WINDOW_LIST_END - IDM_DEBUG_WINDOW_LIST_START] = {}; @@ -164,21 +163,6 @@ private: std::vector drives; - enum EToolbar - { - Toolbar_FileOpen, - Toolbar_Refresh, - Toolbar_Play, - Toolbar_Stop, - Toolbar_Pause, - Toolbar_Screenshot, - Toolbar_FullScreen, - Toolbar_ConfigMain, - Toolbar_ConfigGFX, - Toolbar_Controller, - EToolbar_Max - }; - enum { ADD_PANE_TOP, @@ -191,17 +175,14 @@ private: wxTimer m_poll_hotkey_timer; wxTimer m_handle_signal_timer; - wxSize m_toolbar_bitmap_size; - wxBitmap m_Bitmaps[EToolbar_Max]; - wxMenuBar* m_menubar_shadow = nullptr; - void PopulateToolbar(wxToolBar* toolBar); - void RecreateToolbar(); - - wxMenuBar* CreateMenuBar() const; + void BindEvents(); void BindMenuBarEvents(); + wxToolBar* OnCreateToolBar(long style, wxWindowID id, const wxString& name) override; + wxMenuBar* CreateMenuBar() const; + // Utility wxWindow* GetNotebookPageFromId(wxWindowID Id); wxAuiNotebook* GetNotebookFromId(u32 NBId); @@ -252,6 +233,8 @@ private: void OnQuit(wxCommandEvent& event); void OnHelp(wxCommandEvent& event); + void OnReloadThemeBitmaps(wxCommandEvent& event); + void OnOpen(wxCommandEvent& event); // File menu void DoOpen(bool Boot); void OnRefresh(wxCommandEvent& event); diff --git a/Source/Core/DolphinWX/FrameTools.cpp b/Source/Core/DolphinWX/FrameTools.cpp index a4e3a0ae52..e6d9b41cb7 100644 --- a/Source/Core/DolphinWX/FrameTools.cpp +++ b/Source/Core/DolphinWX/FrameTools.cpp @@ -68,6 +68,7 @@ #include "DolphinWX/InputConfigDiag.h" #include "DolphinWX/LogWindow.h" #include "DolphinWX/MainMenuBar.h" +#include "DolphinWX/MainToolBar.h" #include "DolphinWX/MemcardManager.h" #include "DolphinWX/NetPlay/NetPlaySetupFrame.h" #include "DolphinWX/NetPlay/NetWindow.h" @@ -97,11 +98,6 @@ wxMenuBar* CFrame::GetMenuBar() const } } -const wxSize& CFrame::GetToolbarBitmapSize() const -{ - return m_toolbar_bitmap_size; -} - // Create menu items // --------------------- wxMenuBar* CFrame::CreateMenuBar() const @@ -200,69 +196,12 @@ void CFrame::BindMenuBarEvents() Bind(wxEVT_MENU, &CFrame::OnHelp, this, wxID_ABOUT); } -// Create toolbar items -// --------------------- -void CFrame::PopulateToolbar(wxToolBar* ToolBar) +wxToolBar* CFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name) { - WxUtils::AddToolbarButton(ToolBar, wxID_OPEN, _("Open"), m_Bitmaps[Toolbar_FileOpen], - _("Open file...")); - WxUtils::AddToolbarButton(ToolBar, wxID_REFRESH, _("Refresh"), m_Bitmaps[Toolbar_Refresh], - _("Refresh game list")); - ToolBar->AddSeparator(); - WxUtils::AddToolbarButton(ToolBar, IDM_PLAY, _("Play"), m_Bitmaps[Toolbar_Play], _("Play")); - WxUtils::AddToolbarButton(ToolBar, IDM_STOP, _("Stop"), m_Bitmaps[Toolbar_Stop], _("Stop")); - WxUtils::AddToolbarButton(ToolBar, IDM_TOGGLE_FULLSCREEN, _("FullScr"), - m_Bitmaps[Toolbar_FullScreen], _("Toggle fullscreen")); - WxUtils::AddToolbarButton(ToolBar, IDM_SCREENSHOT, _("ScrShot"), m_Bitmaps[Toolbar_Screenshot], - _("Take screenshot")); - ToolBar->AddSeparator(); - WxUtils::AddToolbarButton(ToolBar, wxID_PREFERENCES, _("Config"), m_Bitmaps[Toolbar_ConfigMain], - _("Configure...")); - WxUtils::AddToolbarButton(ToolBar, IDM_CONFIG_GFX_BACKEND, _("Graphics"), - m_Bitmaps[Toolbar_ConfigGFX], _("Graphics settings")); - WxUtils::AddToolbarButton(ToolBar, IDM_CONFIG_CONTROLLERS, _("Controllers"), - m_Bitmaps[Toolbar_Controller], _("Controller settings")); -} + const auto type = + UseDebugger ? MainToolBar::ToolBarType::Debug : MainToolBar::ToolBarType::Regular; -// Delete and recreate the toolbar -void CFrame::RecreateToolbar() -{ - static constexpr long TOOLBAR_STYLE = wxTB_DEFAULT_STYLE | wxTB_TEXT | wxTB_FLAT; - - if (m_ToolBar != nullptr) - { - m_ToolBar->Destroy(); - m_ToolBar = nullptr; - } - - m_ToolBar = CreateToolBar(TOOLBAR_STYLE, wxID_ANY); - m_ToolBar->SetToolBitmapSize(m_toolbar_bitmap_size); - - if (g_pCodeWindow) - { - g_pCodeWindow->PopulateToolbar(m_ToolBar); - m_ToolBar->AddSeparator(); - } - - PopulateToolbar(m_ToolBar); - // after adding the buttons to the toolbar, must call Realize() to reflect - // the changes - m_ToolBar->Realize(); - - UpdateGUI(); -} - -void CFrame::InitBitmaps() -{ - static constexpr std::array s_image_names{ - {"open", "refresh", "play", "stop", "pause", "screenshot", "fullscreen", "config", "graphics", - "classic"}}; - for (std::size_t i = 0; i < s_image_names.size(); ++i) - m_Bitmaps[i] = WxUtils::LoadScaledThemeBitmap(s_image_names[i], this, m_toolbar_bitmap_size); - - // Update in case the bitmap has been updated - if (m_ToolBar != nullptr) - RecreateToolbar(); + return new MainToolBar{type, this, id, wxDefaultPosition, wxDefaultSize, style}; } void CFrame::OpenGeneralConfiguration(int tab) @@ -629,8 +568,7 @@ void CFrame::StartGame(const std::string& filename) return; m_bGameLoading = true; - if (m_ToolBar) - m_ToolBar->EnableTool(IDM_PLAY, false); + GetToolBar()->EnableTool(IDM_PLAY, false); GetMenuBar()->FindItem(IDM_PLAY)->Enable(false); if (SConfig::GetInstance().bRenderToMain) @@ -1066,6 +1004,15 @@ void CFrame::OnHelp(wxCommandEvent& event) } } +void CFrame::OnReloadThemeBitmaps(wxCommandEvent& WXUNUSED(event)) +{ + wxCommandEvent reload_event{DOLPHIN_EVT_RELOAD_TOOLBAR_BITMAPS}; + reload_event.SetEventObject(this); + wxPostEvent(GetToolBar(), reload_event); + + UpdateGameList(); +} + void CFrame::ClearStatusBar() { if (this->GetStatusBar()->IsEnabled()) @@ -1368,18 +1315,7 @@ void CFrame::UpdateGUI() bool Paused = Core::GetState() == Core::CORE_PAUSE; bool Stopping = Core::GetState() == Core::CORE_STOPPING; - // Make sure that we have a toolbar - if (m_ToolBar) - { - // Enable/disable the Config and Stop buttons - m_ToolBar->EnableTool(wxID_OPEN, !Initialized); - // Don't allow refresh when we don't show the list - m_ToolBar->EnableTool(wxID_REFRESH, !Initialized); - m_ToolBar->EnableTool(IDM_STOP, Running || Paused); - m_ToolBar->EnableTool(IDM_TOGGLE_FULLSCREEN, Running || Paused); - m_ToolBar->EnableTool(IDM_SCREENSHOT, Running || Paused); - } - + GetToolBar()->Refresh(false); GetMenuBar()->Refresh(false); // File @@ -1436,33 +1372,6 @@ void CFrame::UpdateGUI() Core::PauseAndLock(false, was_unpaused); } - if (m_ToolBar) - { - // Get the tool that controls pausing/playing - wxToolBarToolBase* PlayTool = m_ToolBar->FindById(IDM_PLAY); - - if (PlayTool) - { - int position = m_ToolBar->GetToolPos(IDM_PLAY); - - if (Running) - { - m_ToolBar->DeleteTool(IDM_PLAY); - m_ToolBar->InsertTool(position, IDM_PLAY, _("Pause"), m_Bitmaps[Toolbar_Pause], - WxUtils::CreateDisabledButtonBitmap(m_Bitmaps[Toolbar_Pause]), - wxITEM_NORMAL, _("Pause")); - } - else - { - m_ToolBar->DeleteTool(IDM_PLAY); - m_ToolBar->InsertTool(position, IDM_PLAY, _("Play"), m_Bitmaps[Toolbar_Play], - WxUtils::CreateDisabledButtonBitmap(m_Bitmaps[Toolbar_Play]), - wxITEM_NORMAL, _("Play")); - } - m_ToolBar->Realize(); - } - } - GetMenuBar()->FindItem(IDM_RECORD_READ_ONLY)->Enable(Running || Paused); if (!Initialized && !m_bGameLoading) @@ -1472,8 +1381,7 @@ void CFrame::UpdateGUI() // Prepare to load Default ISO, enable play button if (!SConfig::GetInstance().m_strDefaultISO.empty()) { - if (m_ToolBar) - m_ToolBar->EnableTool(IDM_PLAY, true); + GetToolBar()->EnableTool(IDM_PLAY, true); GetMenuBar()->FindItem(IDM_PLAY)->Enable(); GetMenuBar()->FindItem(IDM_RECORD)->Enable(); GetMenuBar()->FindItem(IDM_PLAY_RECORD)->Enable(); @@ -1482,8 +1390,7 @@ void CFrame::UpdateGUI() else if (!SConfig::GetInstance().m_LastFilename.empty() && File::Exists(SConfig::GetInstance().m_LastFilename)) { - if (m_ToolBar) - m_ToolBar->EnableTool(IDM_PLAY, true); + GetToolBar()->EnableTool(IDM_PLAY, true); GetMenuBar()->FindItem(IDM_PLAY)->Enable(); GetMenuBar()->FindItem(IDM_RECORD)->Enable(); GetMenuBar()->FindItem(IDM_PLAY_RECORD)->Enable(); @@ -1491,8 +1398,7 @@ void CFrame::UpdateGUI() else { // No game has been selected yet, disable play button - if (m_ToolBar) - m_ToolBar->EnableTool(IDM_PLAY, false); + GetToolBar()->EnableTool(IDM_PLAY, false); GetMenuBar()->FindItem(IDM_PLAY)->Enable(false); GetMenuBar()->FindItem(IDM_RECORD)->Enable(false); GetMenuBar()->FindItem(IDM_PLAY_RECORD)->Enable(false); @@ -1508,8 +1414,7 @@ void CFrame::UpdateGUI() // Game has been selected but not started, enable play button if (m_GameListCtrl->GetSelectedISO() != nullptr && m_GameListCtrl->IsEnabled()) { - if (m_ToolBar) - m_ToolBar->EnableTool(IDM_PLAY, true); + GetToolBar()->EnableTool(IDM_PLAY, true); GetMenuBar()->FindItem(IDM_PLAY)->Enable(); GetMenuBar()->FindItem(IDM_RECORD)->Enable(); GetMenuBar()->FindItem(IDM_PLAY_RECORD)->Enable(); @@ -1518,19 +1423,14 @@ void CFrame::UpdateGUI() else if (Initialized) { // Game has been loaded, enable the pause button - if (m_ToolBar) - m_ToolBar->EnableTool(IDM_PLAY, !Stopping); + GetToolBar()->EnableTool(IDM_PLAY, !Stopping); GetMenuBar()->FindItem(IDM_PLAY)->Enable(!Stopping); // Reset game loading flag m_bGameLoading = false; } - // Refresh toolbar - if (m_ToolBar) - { - m_ToolBar->Refresh(); - } + GetToolBar()->Refresh(false); // Commit changes to manager m_Mgr->Update(); diff --git a/Source/Core/DolphinWX/Globals.h b/Source/Core/DolphinWX/Globals.h index 0f4db06b72..cd36f68c1a 100644 --- a/Source/Core/DolphinWX/Globals.h +++ b/Source/Core/DolphinWX/Globals.h @@ -9,17 +9,6 @@ #include #include -enum -{ - Toolbar_Step, - Toolbar_StepOver, - Toolbar_StepOut, - Toolbar_Skip, - Toolbar_GotoPC, - Toolbar_SetPC, - Toolbar_Debug_Bitmap_Max -}; - enum { // Emulation menu diff --git a/Source/Core/DolphinWX/MainToolBar.cpp b/Source/Core/DolphinWX/MainToolBar.cpp new file mode 100644 index 0000000000..371ed9def1 --- /dev/null +++ b/Source/Core/DolphinWX/MainToolBar.cpp @@ -0,0 +1,255 @@ +// Copyright 2016 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "DolphinWX/MainToolBar.h" + +#include +#include + +#include "Core/Core.h" +#include "Core/HW/CPU.h" +#include "DolphinWX/Globals.h" +#include "DolphinWX/WxUtils.h" + +wxDEFINE_EVENT(DOLPHIN_EVT_RELOAD_TOOLBAR_BITMAPS, wxCommandEvent); + +MainToolBar::MainToolBar(ToolBarType type, wxWindow* parent, wxWindowID id, const wxPoint& pos, + const wxSize& size, long style, const wxString& name) + : wxToolBar{parent, id, pos, size, style, name}, m_type{type} +{ + wxToolBar::SetToolBitmapSize(FromDIP(wxSize{32, 32})); + InitializeBitmaps(); + AddToolBarButtons(); + wxToolBar::Realize(); + + BindEvents(); +} + +void MainToolBar::BindEvents() +{ + Bind(DOLPHIN_EVT_RELOAD_TOOLBAR_BITMAPS, &MainToolBar::OnReloadBitmaps, this); + + BindMainButtonEvents(); + + if (m_type == ToolBarType::Debug) + BindDebuggerButtonEvents(); +} + +void MainToolBar::BindMainButtonEvents() +{ + Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCoreNotRunning, this, wxID_OPEN); + Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCoreNotRunning, this, wxID_REFRESH); + Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCoreRunningOrPaused, this, IDM_STOP); + Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCoreRunningOrPaused, this, IDM_TOGGLE_FULLSCREEN); + Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCoreRunningOrPaused, this, IDM_SCREENSHOT); +} + +void MainToolBar::BindDebuggerButtonEvents() +{ + Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCPUCanStep, this, IDM_STEP); + Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCPUCanStep, this, IDM_STEPOVER); + Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCPUCanStep, this, IDM_STEPOUT); + Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCPUCanStep, this, IDM_SKIP); + Bind(wxEVT_UPDATE_UI, &MainToolBar::OnUpdateIfCorePaused, this, IDM_SETPC); +} + +void MainToolBar::OnUpdateIfCoreNotRunning(wxUpdateUIEvent& event) +{ + event.Enable(!Core::IsRunning()); +} + +void MainToolBar::OnUpdateIfCorePaused(wxUpdateUIEvent& event) +{ + event.Enable(Core::GetState() == Core::CORE_PAUSE); +} + +void MainToolBar::OnUpdateIfCoreRunningOrPaused(wxUpdateUIEvent& event) +{ + const auto state = Core::GetState(); + + event.Enable(state == Core::CORE_RUN || state == Core::CORE_PAUSE); +} + +void MainToolBar::OnUpdateIfCPUCanStep(wxUpdateUIEvent& event) +{ + event.Enable(Core::IsRunning() && CPU::IsStepping()); +} + +void MainToolBar::OnReloadBitmaps(wxCommandEvent& WXUNUSED(event)) +{ + Freeze(); + + m_icon_bitmaps.clear(); + InitializeBitmaps(); + ApplyThemeBitmaps(); + + if (m_type == ToolBarType::Debug) + ApplyDebuggerBitmaps(); + + Thaw(); +} + +void MainToolBar::Refresh(bool erase_background, const wxRect* rect) +{ + wxToolBar::Refresh(erase_background, rect); + + RefreshPlayButton(); +} + +void MainToolBar::InitializeBitmaps() +{ + InitializeThemeBitmaps(); + + if (m_type == ToolBarType::Debug) + InitializeDebuggerBitmaps(); +} + +void MainToolBar::InitializeThemeBitmaps() +{ + m_icon_bitmaps.insert({{TOOLBAR_FILEOPEN, CreateBitmap("open")}, + {TOOLBAR_REFRESH, CreateBitmap("refresh")}, + {TOOLBAR_PLAY, CreateBitmap("play")}, + {TOOLBAR_STOP, CreateBitmap("stop")}, + {TOOLBAR_PAUSE, CreateBitmap("pause")}, + {TOOLBAR_SCREENSHOT, CreateBitmap("screenshot")}, + {TOOLBAR_FULLSCREEN, CreateBitmap("fullscreen")}, + {TOOLBAR_CONFIGMAIN, CreateBitmap("config")}, + {TOOLBAR_CONFIGGFX, CreateBitmap("graphics")}, + {TOOLBAR_CONTROLLER, CreateBitmap("classic")}}); +} + +void MainToolBar::InitializeDebuggerBitmaps() +{ + m_icon_bitmaps.insert( + {{TOOLBAR_DEBUG_STEP, CreateDebuggerBitmap("toolbar_debugger_step")}, + {TOOLBAR_DEBUG_STEPOVER, CreateDebuggerBitmap("toolbar_debugger_step_over")}, + {TOOLBAR_DEBUG_STEPOUT, CreateDebuggerBitmap("toolbar_debugger_step_out")}, + {TOOLBAR_DEBUG_SKIP, CreateDebuggerBitmap("toolbar_debugger_skip")}, + {TOOLBAR_DEBUG_GOTOPC, CreateDebuggerBitmap("toolbar_debugger_goto_pc")}, + {TOOLBAR_DEBUG_SETPC, CreateDebuggerBitmap("toolbar_debugger_set_pc")}}); +} + +wxBitmap MainToolBar::CreateBitmap(const std::string& name) const +{ + return WxUtils::LoadScaledThemeBitmap(name, this, GetToolBitmapSize()); +} + +wxBitmap MainToolBar::CreateDebuggerBitmap(const std::string& name) const +{ + constexpr auto scale_flags = WxUtils::LSI_SCALE_DOWN | WxUtils::LSI_ALIGN_CENTER; + + return WxUtils::LoadScaledResourceBitmap(name, this, GetToolBitmapSize(), wxDefaultSize, + scale_flags); +} + +void MainToolBar::ApplyThemeBitmaps() +{ + constexpr std::array, 8> bitmap_entries{ + {{wxID_OPEN, TOOLBAR_FILEOPEN}, + {wxID_REFRESH, TOOLBAR_REFRESH}, + {IDM_STOP, TOOLBAR_STOP}, + {IDM_TOGGLE_FULLSCREEN, TOOLBAR_FULLSCREEN}, + {IDM_SCREENSHOT, TOOLBAR_SCREENSHOT}, + {wxID_PREFERENCES, TOOLBAR_CONFIGMAIN}, + {IDM_CONFIG_GFX_BACKEND, TOOLBAR_CONFIGGFX}, + {IDM_CONFIG_CONTROLLERS, TOOLBAR_CONTROLLER}}}; + + for (const auto& entry : bitmap_entries) + ApplyBitmap(entry.first, entry.second); + + // Separate, as the play button is dual-state and doesn't have a fixed bitmap. + RefreshPlayButton(); +} + +void MainToolBar::ApplyDebuggerBitmaps() +{ + constexpr std::array, 6> bitmap_entries{ + {{IDM_STEP, TOOLBAR_DEBUG_STEP}, + {IDM_STEPOVER, TOOLBAR_DEBUG_STEPOVER}, + {IDM_STEPOUT, TOOLBAR_DEBUG_STEPOUT}, + {IDM_SKIP, TOOLBAR_DEBUG_SKIP}, + {IDM_GOTOPC, TOOLBAR_DEBUG_GOTOPC}, + {IDM_SETPC, TOOLBAR_DEBUG_SETPC}}}; + + for (const auto& entry : bitmap_entries) + ApplyBitmap(entry.first, entry.second); +} + +void MainToolBar::ApplyBitmap(int tool_id, ToolBarBitmapID bitmap_id) +{ + const auto& bitmap = m_icon_bitmaps[bitmap_id]; + + SetToolDisabledBitmap(tool_id, WxUtils::CreateDisabledButtonBitmap(bitmap)); + SetToolNormalBitmap(tool_id, bitmap); +} + +void MainToolBar::AddToolBarButtons() +{ + if (m_type == ToolBarType::Debug) + { + AddDebuggerToolBarButtons(); + AddSeparator(); + } + + AddMainToolBarButtons(); +} + +void MainToolBar::AddMainToolBarButtons() +{ + AddToolBarButton(wxID_OPEN, TOOLBAR_FILEOPEN, _("Open"), _("Open file...")); + AddToolBarButton(wxID_REFRESH, TOOLBAR_REFRESH, _("Refresh"), _("Refresh game list")); + AddSeparator(); + AddToolBarButton(IDM_PLAY, TOOLBAR_PLAY, _("Play"), _("Play")); + AddToolBarButton(IDM_STOP, TOOLBAR_STOP, _("Stop"), _("Stop")); + AddToolBarButton(IDM_TOGGLE_FULLSCREEN, TOOLBAR_FULLSCREEN, _("FullScr"), _("Toggle fullscreen")); + AddToolBarButton(IDM_SCREENSHOT, TOOLBAR_SCREENSHOT, _("ScrShot"), _("Take screenshot")); + AddSeparator(); + AddToolBarButton(wxID_PREFERENCES, TOOLBAR_CONFIGMAIN, _("Config"), _("Configure...")); + AddToolBarButton(IDM_CONFIG_GFX_BACKEND, TOOLBAR_CONFIGGFX, _("Graphics"), + _("Graphics settings")); + AddToolBarButton(IDM_CONFIG_CONTROLLERS, TOOLBAR_CONTROLLER, _("Controllers"), + _("Controller settings")); +} + +void MainToolBar::AddDebuggerToolBarButtons() +{ + AddToolBarButton(IDM_STEP, TOOLBAR_DEBUG_STEP, _("Step"), _("Step into the next instruction")); + AddToolBarButton(IDM_STEPOVER, TOOLBAR_DEBUG_STEPOVER, _("Step Over"), + _("Step over the next instruction")); + AddToolBarButton(IDM_STEPOUT, TOOLBAR_DEBUG_STEPOUT, _("Step Out"), + _("Step out of the current function")); + AddToolBarButton(IDM_SKIP, TOOLBAR_DEBUG_SKIP, _("Skip"), + _("Skips the next instruction completely")); + AddSeparator(); + AddToolBarButton(IDM_GOTOPC, TOOLBAR_DEBUG_GOTOPC, _("Show PC"), + _("Go to the current instruction")); + AddToolBarButton(IDM_SETPC, TOOLBAR_DEBUG_SETPC, _("Set PC"), _("Set the current instruction")); +} + +void MainToolBar::AddToolBarButton(int tool_id, ToolBarBitmapID bitmap_id, const wxString& label, + const wxString& short_help) +{ + WxUtils::AddToolbarButton(this, tool_id, label, m_icon_bitmaps[bitmap_id], short_help); +} + +void MainToolBar::RefreshPlayButton() +{ + ToolBarBitmapID bitmap_id; + wxString label; + + if (Core::GetState() == Core::CORE_RUN) + { + bitmap_id = TOOLBAR_PAUSE; + label = _("Pause"); + } + else + { + bitmap_id = TOOLBAR_PLAY; + label = _("Play"); + } + + FindById(IDM_PLAY)->SetLabel(label); + SetToolShortHelp(IDM_PLAY, label); + ApplyBitmap(IDM_PLAY, bitmap_id); +} diff --git a/Source/Core/DolphinWX/MainToolBar.h b/Source/Core/DolphinWX/MainToolBar.h new file mode 100644 index 0000000000..8b78fab344 --- /dev/null +++ b/Source/Core/DolphinWX/MainToolBar.h @@ -0,0 +1,84 @@ +// Copyright 2016 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include +#include +#include + +wxDECLARE_EVENT(DOLPHIN_EVT_RELOAD_TOOLBAR_BITMAPS, wxCommandEvent); + +class MainToolBar final : public wxToolBar +{ +public: + enum class ToolBarType + { + Regular, + Debug + }; + + MainToolBar(ToolBarType type, wxWindow* parent, wxWindowID id, + const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, + long style = wxTB_HORIZONTAL, const wxString& name = wxToolBarNameStr); + + void Refresh(bool erase_background, const wxRect* rect = nullptr) override; + +private: + enum ToolBarBitmapID : int + { + TOOLBAR_DEBUG_STEP, + TOOLBAR_DEBUG_STEPOVER, + TOOLBAR_DEBUG_STEPOUT, + TOOLBAR_DEBUG_SKIP, + TOOLBAR_DEBUG_GOTOPC, + TOOLBAR_DEBUG_SETPC, + + TOOLBAR_FILEOPEN, + TOOLBAR_REFRESH, + TOOLBAR_PLAY, + TOOLBAR_STOP, + TOOLBAR_PAUSE, + TOOLBAR_SCREENSHOT, + TOOLBAR_FULLSCREEN, + TOOLBAR_CONFIGMAIN, + TOOLBAR_CONFIGGFX, + TOOLBAR_CONTROLLER, + }; + + void BindEvents(); + void BindMainButtonEvents(); + void BindDebuggerButtonEvents(); + + void OnUpdateIfCoreNotRunning(wxUpdateUIEvent&); + void OnUpdateIfCorePaused(wxUpdateUIEvent&); + void OnUpdateIfCoreRunningOrPaused(wxUpdateUIEvent&); + void OnUpdateIfCPUCanStep(wxUpdateUIEvent&); + + void OnReloadBitmaps(wxCommandEvent&); + + void InitializeBitmaps(); + void InitializeThemeBitmaps(); + void InitializeDebuggerBitmaps(); + + wxBitmap CreateBitmap(const std::string& name) const; + wxBitmap CreateDebuggerBitmap(const std::string& name) const; + + void ApplyThemeBitmaps(); + void ApplyDebuggerBitmaps(); + void ApplyBitmap(int tool_id, ToolBarBitmapID bitmap_id); + + void AddToolBarButtons(); + void AddMainToolBarButtons(); + void AddDebuggerToolBarButtons(); + void AddToolBarButton(int tool_id, ToolBarBitmapID bitmap_id, const wxString& label, + const wxString& short_help = wxEmptyString); + + void RefreshPlayButton(); + + ToolBarType m_type{}; + std::unordered_map> m_icon_bitmaps; +}; From 65a8b999b4e6531ad43d83783cd10f425ce0e9f1 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 29 Oct 2016 02:44:48 -0400 Subject: [PATCH 2/2] wxWidgets (gtk): Patch that allows label switching to work for wxToolBar This applies a patch that was merged into the mainline wxWidgets tree to support label changing with wxToolBar. This originally only worked on Windows and macOS, which is kind of annoying. This is beneficial because it means that a tool doesn't have to be removed and then reinserted into a wxToolBar instance in order to change the label. For more details, see ticket #17567 on the wxWidgets issue tracker. --- Externals/wxWidgets3/src/gtk/toolbar.cpp | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Externals/wxWidgets3/src/gtk/toolbar.cpp b/Externals/wxWidgets3/src/gtk/toolbar.cpp index ff5bcdefa4..1ae765e9d0 100644 --- a/Externals/wxWidgets3/src/gtk/toolbar.cpp +++ b/Externals/wxWidgets3/src/gtk/toolbar.cpp @@ -56,6 +56,7 @@ public: void SetImage(); void CreateDropDown(); void ShowDropdown(GtkToggleButton* button); + virtual void SetLabel(const wxString& label) wxOVERRIDE; GtkToolItem* m_item; }; @@ -318,6 +319,36 @@ void wxToolBarTool::ShowDropdown(GtkToggleButton* button) } } +void wxToolBarTool::SetLabel(const wxString& label) +{ + wxASSERT_MSG( IsButton(), + wxS("Label can be set for button tool only") ); + + if ( label == m_label ) + return; + + wxToolBarToolBase::SetLabel(label); + if ( IsButton() ) + { + if ( !label.empty() ) + { + wxString newLabel = wxControl::RemoveMnemonics(label); + gtk_tool_button_set_label(GTK_TOOL_BUTTON(m_item), + wxGTK_CONV(newLabel)); + // To show the label for toolbar with wxTB_HORZ_LAYOUT. + gtk_tool_item_set_is_important(m_item, true); + } + else + { + gtk_tool_button_set_label(GTK_TOOL_BUTTON(m_item), NULL); + // To hide the label for toolbar with wxTB_HORZ_LAYOUT. + gtk_tool_item_set_is_important(m_item, false); + } + } + + // TODO: Set label for control tool, if it's possible. +} + wxToolBarToolBase *wxToolBar::CreateTool(int id, const wxString& text, const wxBitmap& bitmap1,