From 506f61d254c1a2f0c1fe220e5edf388097171086 Mon Sep 17 00:00:00 2001 From: Jan Borsodi Date: Fri, 22 Oct 2010 23:14:21 +0200 Subject: [PATCH] Added a method to remove a dialog safely, first hides the dialog then schedules for deletion in the garbage list. --- apps/openmw/mwgui/window_manager.cpp | 9 +++++++++ apps/openmw/mwgui/window_manager.hpp | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index ca8d2e140d..563545f5b0 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -459,6 +459,15 @@ void WindowManager::updateSkillArea() stats->updateSkillArea(); } +void WindowManager::removeDialog(OEngine::GUI::Layout*dialog) +{ + assert(dialog); + if (!dialog) + return; + dialog->setVisible(false); + garbageDialogs.push_back(dialog); +} + void WindowManager::messageBox (const std::string& message, const std::vector& buttons) { std::cout << "message box: " << message << std::endl; diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index c646a841b1..f2f58f26eb 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -228,6 +228,13 @@ namespace MWGui void updateSkillArea(); ///< update display of skills, factions, birth sign, reputation and bounty + template + void removeDialog(T*& dialog); + ///< Casts to OEngine::GUI::Layout and calls removeDialog, then resets pointer to nullptr. + + void removeDialog(OEngine::GUI::Layout* dialog); + ///< Hides dialog and schedules dialog to be deleted. + void messageBox (const std::string& message, const std::vector& buttons); /** @@ -275,5 +282,14 @@ namespace MWGui void onReviewDialogDone(); void onReviewDialogBack(); }; + + template + void WindowManager::removeDialog(T*& dialog) + { + OEngine::GUI::Layout *d = static_cast(dialog); + removeDialog(d); + dialog = nullptr; + } } + #endif