From 1fccbd5be3cc3c938a325d0f9401cc1a56e68e29 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 26 Jun 2017 01:35:24 +1000 Subject: [PATCH] DolphinWX: Add a progress dialog host command Allows feedback from backends to be communicated to the user when long-running operation are performed (e.g. shader compilation). --- Source/Android/jni/MainAndroid.cpp | 4 ++++ Source/Core/Core/Host.h | 1 + Source/Core/DolphinNoGUI/MainNoGUI.cpp | 4 ++++ Source/Core/DolphinQt2/Host.cpp | 3 +++ Source/Core/DolphinWX/Frame.cpp | 32 ++++++++++++++++++++++++++ Source/Core/DolphinWX/Frame.h | 2 ++ Source/Core/DolphinWX/Globals.h | 1 + Source/Core/DolphinWX/Main.cpp | 9 ++++++++ Source/UnitTests/StubHost.cpp | 3 +++ 9 files changed, 59 insertions(+) diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp index cda73a9fe5..fa92372f6a 100644 --- a/Source/Android/jni/MainAndroid.cpp +++ b/Source/Android/jni/MainAndroid.cpp @@ -148,6 +148,10 @@ void Host_YieldToUI() { } +void Host_UpdateProgressDialog(const char* caption, int position, int total) +{ +} + static bool MsgAlert(const char* caption, const char* text, bool yes_no, int /*Style*/) { __android_log_print(ANDROID_LOG_ERROR, DOLPHIN_TAG, "%s:%s", caption, text); diff --git a/Source/Core/Core/Host.h b/Source/Core/Core/Host.h index 0a8a8231ae..acbea49ef7 100644 --- a/Source/Core/Core/Host.h +++ b/Source/Core/Core/Host.h @@ -35,6 +35,7 @@ void Host_UpdateMainFrame(); void Host_UpdateTitle(const std::string& title); void Host_ShowVideoConfig(void* parent, const std::string& backend_name); void Host_YieldToUI(); +void Host_UpdateProgressDialog(const char* caption, int position, int total); // TODO (neobrain): Remove this from host! void* Host_GetRenderHandle(); diff --git a/Source/Core/DolphinNoGUI/MainNoGUI.cpp b/Source/Core/DolphinNoGUI/MainNoGUI.cpp index fc91ccac04..37860057aa 100644 --- a/Source/Core/DolphinNoGUI/MainNoGUI.cpp +++ b/Source/Core/DolphinNoGUI/MainNoGUI.cpp @@ -136,6 +136,10 @@ void Host_YieldToUI() { } +void Host_UpdateProgressDialog(const char* caption, int position, int total) +{ +} + #if HAVE_X11 #include #include diff --git a/Source/Core/DolphinQt2/Host.cpp b/Source/Core/DolphinQt2/Host.cpp index 2509d8c9b9..c39207b252 100644 --- a/Source/Core/DolphinQt2/Host.cpp +++ b/Source/Core/DolphinQt2/Host.cpp @@ -84,6 +84,9 @@ void Host_YieldToUI() { qApp->processEvents(QEventLoop::ExcludeUserInputEvents); } +void Host_UpdateProgressDialog(const char* caption, int position, int total) +{ +} // We ignore these, and their purpose should be questioned individually. // In particular, RequestRenderWindowSize, RequestFullscreen, and diff --git a/Source/Core/DolphinWX/Frame.cpp b/Source/Core/DolphinWX/Frame.cpp index 28e25b4806..08bbcc4a52 100644 --- a/Source/Core/DolphinWX/Frame.cpp +++ b/Source/Core/DolphinWX/Frame.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -817,6 +818,37 @@ void CFrame::OnHostMessage(wxCommandEvent& event) case IDM_STOPPED: OnStopped(); break; + + case IDM_UPDATE_PROGRESS_DIALOG: + { + int current = event.GetInt(); + int total = static_cast(event.GetExtraLong()); + if (total < 0 || current >= total) + { + if (m_progress_dialog) + { + delete m_progress_dialog; + m_progress_dialog = nullptr; + } + } + else if (total > 0 && current < total) + { + if (!m_progress_dialog) + { + m_progress_dialog = new wxProgressDialog( + _("Operation in progress..."), event.GetString(), total, m_render_frame, + wxPD_APP_MODAL | wxPD_ELAPSED_TIME | wxPD_SMOOTH | wxPD_REMAINING_TIME); + m_progress_dialog->Show(); + } + else + { + if (m_progress_dialog->GetRange() != total) + m_progress_dialog->SetRange(total); + m_progress_dialog->Update(current, event.GetString()); + } + } + } + break; } } diff --git a/Source/Core/DolphinWX/Frame.h b/Source/Core/DolphinWX/Frame.h index afc555af7a..918447e513 100644 --- a/Source/Core/DolphinWX/Frame.h +++ b/Source/Core/DolphinWX/Frame.h @@ -49,6 +49,7 @@ class wxAuiNotebook; class wxAuiNotebookEvent; class wxListEvent; class wxMenuItem; +class wxProgressDialog; class CRenderFrame : public wxFrame { @@ -154,6 +155,7 @@ private: FifoPlayerDlg* m_fifo_player_dialog = nullptr; std::array m_tas_input_dialogs{}; wxCheatsWindow* m_cheats_window = nullptr; + wxProgressDialog* m_progress_dialog = nullptr; bool m_use_debugger = false; bool m_batch_mode = false; bool m_editing_perspectives = false; diff --git a/Source/Core/DolphinWX/Globals.h b/Source/Core/DolphinWX/Globals.h index d11f42efae..0ade18f159 100644 --- a/Source/Core/DolphinWX/Globals.h +++ b/Source/Core/DolphinWX/Globals.h @@ -307,6 +307,7 @@ enum IDM_WINDOW_SIZE_REQUEST, IDM_STOPPED, IDM_HOST_MESSAGE, + IDM_UPDATE_PROGRESS_DIALOG, IDM_MPANEL, ID_STATUSBAR, diff --git a/Source/Core/DolphinWX/Main.cpp b/Source/Core/DolphinWX/Main.cpp index 2ef465531a..1a5fbad188 100644 --- a/Source/Core/DolphinWX/Main.cpp +++ b/Source/Core/DolphinWX/Main.cpp @@ -488,3 +488,12 @@ void Host_YieldToUI() { wxGetApp().GetMainLoop()->YieldFor(wxEVT_CATEGORY_UI); } + +void Host_UpdateProgressDialog(const char* caption, int position, int total) +{ + wxCommandEvent event(wxEVT_HOST_COMMAND, IDM_UPDATE_PROGRESS_DIALOG); + event.SetString(caption); + event.SetInt(position); + event.SetExtraLong(total); + main_frame->GetEventHandler()->AddPendingEvent(event); +} diff --git a/Source/UnitTests/StubHost.cpp b/Source/UnitTests/StubHost.cpp index 6348b1c776..860992bffd 100644 --- a/Source/UnitTests/StubHost.cpp +++ b/Source/UnitTests/StubHost.cpp @@ -57,6 +57,9 @@ void Host_ShowVideoConfig(void*, const std::string&) void Host_YieldToUI() { } +void Host_UpdateProgressDialog(const char* caption, int position, int total) +{ +} std::unique_ptr HostGL_CreateGLInterface() { return nullptr;