From d09f0610eaaf5128b9d849e3bc99868fcf17f43e Mon Sep 17 00:00:00 2001 From: Roman Melnik Date: Sun, 1 Apr 2012 20:36:57 +0300 Subject: [PATCH] Add basic windows pinning Create WindowPinnableBase class for windows which should be allowed to be pinned. Add skin for pinnable windows - currently just a copy of normal window with 1 extra button (hopefully this can be improved later). Handle clicking on PinToggle button (pinning/unpinning a window). --- apps/openmw/mwgui/stats_window.cpp | 2 +- apps/openmw/mwgui/stats_window.hpp | 4 +- apps/openmw/mwgui/window_pinnable_base.cpp | 31 +++++++++ apps/openmw/mwgui/window_pinnable_base.hpp | 24 +++++++ files/mygui/openmw_stats_window_layout.xml | 2 +- files/mygui/openmw_windows.skin.xml | 81 ++++++++++++++++++++++ libs/openengine/gui/layout.hpp | 2 +- 7 files changed, 141 insertions(+), 5 deletions(-) create mode 100644 apps/openmw/mwgui/window_pinnable_base.cpp create mode 100644 apps/openmw/mwgui/window_pinnable_base.hpp diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index 12b0dcc79..3ded9713a 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -12,7 +12,7 @@ using namespace MWGui; const int StatsWindow::lineHeight = 18; StatsWindow::StatsWindow (WindowManager& parWindowManager) - : WindowBase("openmw_stats_window_layout.xml", parWindowManager) + : WindowPinnableBase("openmw_stats_window_layout.xml", parWindowManager) , skillAreaWidget(NULL) , skillClientWidget(NULL) , skillScrollerWidget(NULL) diff --git a/apps/openmw/mwgui/stats_window.hpp b/apps/openmw/mwgui/stats_window.hpp index 2ff170f57..081a75d56 100644 --- a/apps/openmw/mwgui/stats_window.hpp +++ b/apps/openmw/mwgui/stats_window.hpp @@ -9,13 +9,13 @@ #include #include "../mwmechanics/stat.hpp" -#include "window_base.hpp" +#include "window_pinnable_base.hpp" namespace MWGui { class WindowManager; - class StatsWindow : public WindowBase + class StatsWindow : public WindowPinnableBase { public: typedef std::pair Faction; diff --git a/apps/openmw/mwgui/window_pinnable_base.cpp b/apps/openmw/mwgui/window_pinnable_base.cpp new file mode 100644 index 000000000..cca593c9c --- /dev/null +++ b/apps/openmw/mwgui/window_pinnable_base.cpp @@ -0,0 +1,31 @@ +#include "window_pinnable_base.hpp" +#include "window_manager.hpp" + +using namespace MWGui; + +WindowPinnableBase::WindowPinnableBase(const std::string& parLayout, WindowManager& parWindowManager) + : WindowBase(parLayout, parWindowManager), mIsPinned(false) +{ + MyGUI::WindowPtr t = static_cast(mMainWidget); + t->eventWindowButtonPressed += MyGUI::newDelegate(this, &WindowPinnableBase::onWindowButtonPressed); +} + +void WindowPinnableBase::setVisible(bool b) +{ + // Pinned windows can not be hidden + if (mIsPinned && !b) + return; + + WindowBase::setVisible(b); +} + +void WindowPinnableBase::onWindowButtonPressed(MyGUI::Window* sender, const std::string& eventName) +{ + if ("PinToggle" == eventName) + { + mIsPinned = !mIsPinned; + } + + eventDone(this); +} + diff --git a/apps/openmw/mwgui/window_pinnable_base.hpp b/apps/openmw/mwgui/window_pinnable_base.hpp new file mode 100644 index 000000000..0e3c27c86 --- /dev/null +++ b/apps/openmw/mwgui/window_pinnable_base.hpp @@ -0,0 +1,24 @@ +#ifndef MWGUI_WINDOW_PINNABLE_BASE_H +#define MWGUI_WINDOW_PINNABLE_BASE_H + +#include "window_base.hpp" + +namespace MWGui +{ + class WindowManager; + + class WindowPinnableBase: public WindowBase + { + public: + WindowPinnableBase(const std::string& parLayout, WindowManager& parWindowManager); + void setVisible(bool b); + + private: + void onWindowButtonPressed(MyGUI::Window* sender, const std::string& eventName); + + bool mIsPinned; + }; +} + +#endif + diff --git a/files/mygui/openmw_stats_window_layout.xml b/files/mygui/openmw_stats_window_layout.xml index 1380d474c..fd99f863e 100644 --- a/files/mygui/openmw_stats_window_layout.xml +++ b/files/mygui/openmw_stats_window_layout.xml @@ -1,7 +1,7 @@ - + diff --git a/files/mygui/openmw_windows.skin.xml b/files/mygui/openmw_windows.skin.xml index 3ee33124c..7c194ea5d 100644 --- a/files/mygui/openmw_windows.skin.xml +++ b/files/mygui/openmw_windows.skin.xml @@ -289,6 +289,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/openengine/gui/layout.hpp b/libs/openengine/gui/layout.hpp index e73b2d1ce..05a23e8ae 100644 --- a/libs/openengine/gui/layout.hpp +++ b/libs/openengine/gui/layout.hpp @@ -103,7 +103,7 @@ namespace GUI )); } - void setVisible(bool b) + virtual void setVisible(bool b) { mMainWidget->setVisible(b); }