From 0ae48c1f83a7e8179ea9b1e6c923c43084080f89 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sat, 9 Mar 2013 20:40:59 +0100 Subject: [PATCH] fix for Bug #509 --- apps/openmw/mwgui/list.cpp | 24 ++++++++++++++++++++++-- apps/openmw/mwgui/list.hpp | 20 ++++++++++++++------ apps/openmw/mwgui/windowmanagerimp.cpp | 1 + 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwgui/list.cpp b/apps/openmw/mwgui/list.cpp index d60e9b687..8343c302a 100644 --- a/apps/openmw/mwgui/list.cpp +++ b/apps/openmw/mwgui/list.cpp @@ -1,9 +1,9 @@ #include "list.hpp" -#include #include #include #include +#include using namespace MWGui; using namespace MWGui::Widgets; @@ -23,7 +23,7 @@ void MWList::initialiseOverride() if (mClient == 0) mClient = this; - mScrollView = mClient->createWidgetReal( + mScrollView = mClient->createWidgetReal( "MW_ScrollView", MyGUI::FloatCoord(0.0, 0.0, 1.0, 1.0), MyGUI::Align::Top | MyGUI::Align::Left | MyGUI::Align::Stretch, getName() + "_ScrollView"); } @@ -48,6 +48,7 @@ void MWList::redraw(bool scrollbarShown) const int _scrollBarWidth = 24; // fetch this from skin? const int scrollBarWidth = scrollbarShown ? _scrollBarWidth : 0; const int spacing = 3; + size_t scrollbarPosition = mScrollView->getScrollPosition(); while (mScrollView->getChildCount()) { @@ -88,6 +89,11 @@ void MWList::redraw(bool scrollbarShown) if (!scrollbarShown && mItemHeight > mClient->getSize().height) redraw(true); + + size_t scrollbarRange = mScrollView->getScrollRange(); + if(scrollbarPosition > scrollbarRange) + scrollbarPosition = scrollbarRange; + mScrollView->setScrollPosition(scrollbarPosition); } bool MWList::hasItem(const std::string& name) @@ -138,3 +144,17 @@ MyGUI::Widget* MWList::getItemWidget(const std::string& name) { return mScrollView->findWidget (getName() + "_item_" + name); } + +size_t MWScrollView::getScrollPosition() +{ + return getVScroll()->getScrollPosition(); +} + +void MWScrollView::setScrollPosition(size_t position) +{ + getVScroll()->setScrollPosition(position); +} +size_t MWScrollView::getScrollRange() +{ + return getVScroll()->getScrollRange(); +} diff --git a/apps/openmw/mwgui/list.hpp b/apps/openmw/mwgui/list.hpp index 38797e779..40e997459 100644 --- a/apps/openmw/mwgui/list.hpp +++ b/apps/openmw/mwgui/list.hpp @@ -2,16 +2,24 @@ #define MWGUI_LIST_HPP #include - -namespace MyGUI -{ - class ScrollView; -} +#include namespace MWGui { namespace Widgets { + /** + * \brief a custom ScrollView which has access to scrollbar properties + */ + class MWScrollView : public MyGUI::ScrollView + { + MYGUI_RTTI_DERIVED(MWScrollView) + public: + size_t getScrollPosition(); + void setScrollPosition(size_t); + size_t getScrollRange(); + }; + /** * \brief a very simple list widget that supports word-wrapping entries * \note if the width or height of the list changes, you must call adjustSize() method @@ -63,7 +71,7 @@ namespace MWGui void onItemSelected(MyGUI::Widget* _sender); private: - MyGUI::ScrollView* mScrollView; + MWGui::Widgets::MWScrollView* mScrollView; MyGUI::Widget* mClient; std::vector mItems; diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index d866ec755..0e4c3a608 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -132,6 +132,7 @@ WindowManager::WindowManager( MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Resource", "ResourceImageSetPointer"); MyGUI::ResourceManager::getInstance().load("core.xml");