From 05a5cb3ae48e00d82488d2d4056a5fd906cde571 Mon Sep 17 00:00:00 2001
From: scrawl <scrawl@baseoftrash.de>
Date: Wed, 3 Apr 2013 00:27:29 +0200
Subject: [PATCH] Improved responsiveness of the inventory window when
 resizing.

---
 apps/openmw/engine.cpp                 |  1 +
 apps/openmw/mwbase/windowmanager.hpp   |  2 ++
 apps/openmw/mwgui/inventorywindow.cpp  | 20 +++++++++++++++-----
 apps/openmw/mwgui/inventorywindow.hpp  |  4 ++++
 apps/openmw/mwgui/windowmanagerimp.cpp |  5 +++++
 apps/openmw/mwgui/windowmanagerimp.hpp |  2 ++
 6 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp
index dad024c98..948a06d47 100644
--- a/apps/openmw/engine.cpp
+++ b/apps/openmw/engine.cpp
@@ -66,6 +66,7 @@ bool OMW::Engine::frameStarted (const Ogre::FrameEvent& evt)
 {
     if (!MWBase::Environment::get().getWindowManager()->isGuiMode())
         MWBase::Environment::get().getWorld()->frameStarted(evt.timeSinceLastFrame);
+    MWBase::Environment::get().getWindowManager ()->frameStarted(evt.timeSinceLastFrame);
     return true;
 }
 
diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp
index 4d66a7742..b271aed18 100644
--- a/apps/openmw/mwbase/windowmanager.hpp
+++ b/apps/openmw/mwbase/windowmanager.hpp
@@ -246,6 +246,8 @@ namespace MWBase
 
             virtual void showSoulgemDialog (MWWorld::Ptr item) = 0;
 
+            virtual void frameStarted(float dt) = 0;
+
             virtual void changePointer (const std::string& name) = 0;
 
             virtual const Translation::Storage& getTranslationDataStorage() const = 0;
diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp
index 1943ff773..aeab5f94a 100644
--- a/apps/openmw/mwgui/inventorywindow.cpp
+++ b/apps/openmw/mwgui/inventorywindow.cpp
@@ -37,6 +37,7 @@ namespace MWGui
         , mLastXSize(0)
         , mLastYSize(0)
         , mPreview(MWBase::Environment::get().getWorld ()->getPlayer ().getPlayer ())
+        , mPreviewDirty(true)
     {
         static_cast<MyGUI::Window*>(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &InventoryWindow::onWindowResize);
 
@@ -268,6 +269,19 @@ namespace MWGui
         mTrading = true;
     }
 
+    void InventoryWindow::doRenderUpdate ()
+    {
+        if (mPreviewDirty)
+        {
+            mPreviewDirty = false;
+            MyGUI::IntSize size = mAvatar->getSize();
+
+            mPreview.update (size.width, size.height);
+            mAvatarImage->setSize(MyGUI::IntSize(std::max(mAvatar->getSize().width, 512), std::max(mAvatar->getSize().height, 1024)));
+            mAvatarImage->setImageTexture("CharacterPreview");
+        }
+    }
+
     void InventoryWindow::notifyContentChanged()
     {
         // update the spell window just in case new enchanted items were added to inventory
@@ -282,11 +296,7 @@ namespace MWGui
         else
             mWindowManager.setSelectedWeapon(*weaponSlot, 100); /// \todo track weapon durability
 
-        MyGUI::IntSize size = mAvatar->getSize();
-
-        mPreview.update (size.width, size.height);
-        mAvatarImage->setSize(MyGUI::IntSize(std::max(mAvatar->getSize().width, 512), std::max(mAvatar->getSize().height, 1024)));
-        mAvatarImage->setImageTexture("CharacterPreview");
+        mPreviewDirty = true;
 
         mArmorRating->setCaptionWithReplacing ("#{sArmor}: "
             + boost::lexical_cast<std::string>(static_cast<int>(MWWorld::Class::get(mPtr).getArmorRating(mPtr))));
diff --git a/apps/openmw/mwgui/inventorywindow.hpp b/apps/openmw/mwgui/inventorywindow.hpp
index 95657672d..fceb7ecef 100644
--- a/apps/openmw/mwgui/inventorywindow.hpp
+++ b/apps/openmw/mwgui/inventorywindow.hpp
@@ -16,6 +16,8 @@ namespace MWGui
 
             virtual void open();
 
+            void doRenderUpdate();
+
             /// start trading, disables item drag&drop
             void startTrade();
 
@@ -34,6 +36,8 @@ namespace MWGui
             }
 
         protected:
+            bool mPreviewDirty;
+
             MyGUI::Widget* mAvatar;
             MyGUI::ImageBox* mAvatarImage;
             MyGUI::TextBox* mArmorRating;
diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp
index cf14c1f51..c975b2cdb 100644
--- a/apps/openmw/mwgui/windowmanagerimp.cpp
+++ b/apps/openmw/mwgui/windowmanagerimp.cpp
@@ -1190,3 +1190,8 @@ void WindowManager::showSoulgemDialog(MWWorld::Ptr item)
 {
     mSoulgemDialog->show(item);
 }
+
+void WindowManager::frameStarted (float dt)
+{
+    mInventoryWindow->doRenderUpdate ();
+}
diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp
index 7a7adec27..c14c6b2fe 100644
--- a/apps/openmw/mwgui/windowmanagerimp.hpp
+++ b/apps/openmw/mwgui/windowmanagerimp.hpp
@@ -238,6 +238,8 @@ namespace MWGui
     virtual void startRepair(MWWorld::Ptr actor);
     virtual void startRepairItem(MWWorld::Ptr item);
 
+    virtual void frameStarted(float dt);
+
     virtual void showSoulgemDialog (MWWorld::Ptr item);
 
     virtual void changePointer (const std::string& name);