diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index 32dac71de..3bd74ba8f 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -25,9 +25,7 @@ const int StatsWindow::sLineHeight = 18; StatsWindow::StatsWindow (MWBase::WindowManager& parWindowManager) : WindowPinnableBase("openmw_stats_window.layout", parWindowManager) , mSkillAreaWidget(NULL) - , mSkillClientWidget(NULL) - , mSkillScrollerWidget(NULL) - , mLastPos(0) + , mSkillView(NULL) , mClientHeight(0) , mMajorSkills() , mMinorSkills() @@ -64,16 +62,10 @@ StatsWindow::StatsWindow (MWBase::WindowManager& parWindowManager) } getWidget(mSkillAreaWidget, "Skills"); - getWidget(mSkillClientWidget, "SkillClient"); - getWidget(mSkillScrollerWidget, "SkillScroller"); + getWidget(mSkillView, "SkillView"); getWidget(mLeftPane, "LeftPane"); getWidget(mRightPane, "RightPane"); - mSkillClientWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); - - mSkillScrollerWidget->eventScrollChangePosition += MyGUI::newDelegate(this, &StatsWindow::onScrollChangePosition); - updateScroller(); - for (int i = 0; i < ESM::Skill::Length; ++i) { mSkillValues.insert(std::pair >(i, MWMechanics::Stat())); @@ -84,38 +76,18 @@ StatsWindow::StatsWindow (MWBase::WindowManager& parWindowManager) t->eventWindowChangeCoord += MyGUI::newDelegate(this, &StatsWindow::onWindowResize); } -void StatsWindow::onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos) -{ - int diff = mLastPos - pos; - // Adjust position of all widget according to difference - if (diff == 0) - return; - mLastPos = pos; - - std::vector::const_iterator end = mSkillWidgets.end(); - for (std::vector::const_iterator it = mSkillWidgets.begin(); it != end; ++it) - { - (*it)->setCoord((*it)->getCoord() + MyGUI::IntPoint(0, diff)); - } -} - void StatsWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel) { - if (mSkillScrollerWidget->getScrollPosition() - _rel*0.3 < 0) - mSkillScrollerWidget->setScrollPosition(0); - else if (mSkillScrollerWidget->getScrollPosition() - _rel*0.3 > mSkillScrollerWidget->getScrollRange()-1) - mSkillScrollerWidget->setScrollPosition(mSkillScrollerWidget->getScrollRange()-1); + if (mSkillView->getViewOffset().top + _rel*0.3 > 0) + mSkillView->setViewOffset(MyGUI::IntPoint(0, 0)); else - mSkillScrollerWidget->setScrollPosition(mSkillScrollerWidget->getScrollPosition() - _rel*0.3); - - onScrollChangePosition(mSkillScrollerWidget, mSkillScrollerWidget->getScrollPosition()); + mSkillView->setViewOffset(MyGUI::IntPoint(0, mSkillView->getViewOffset().top + _rel*0.3)); } void StatsWindow::onWindowResize(MyGUI::Window* window) { mLeftPane->setCoord( MyGUI::IntCoord(0, 0, 0.44*window->getSize().width, window->getSize().height) ); mRightPane->setCoord( MyGUI::IntCoord(0.44*window->getSize().width, 0, 0.56*window->getSize().width, window->getSize().height) ); - updateScroller(); } void StatsWindow::setBar(const std::string& name, const std::string& tname, int val, int max) @@ -299,7 +271,7 @@ void StatsWindow::setBirthSign (const std::string& signId) void StatsWindow::addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) { - MyGUI::ImageBox* separator = mSkillClientWidget->createWidget("MW_HLine", + MyGUI::ImageBox* separator = mSkillView->createWidget("MW_HLine", MyGUI::IntCoord(10, coord1.top, coord1.width + coord2.width - 4, 18), MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch); separator->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); @@ -311,7 +283,7 @@ void StatsWindow::addSeparator(MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) void StatsWindow::addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2) { - MyGUI::TextBox* groupWidget = mSkillClientWidget->createWidget("SandBrightText", + MyGUI::TextBox* groupWidget = mSkillView->createWidget("SandBrightText", MyGUI::IntCoord(0, coord1.top, coord1.width + coord2.width, coord1.height), MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch); groupWidget->setCaption(label); @@ -326,11 +298,11 @@ MyGUI::TextBox* StatsWindow::addValueItem(const std::string& text, const std::st { MyGUI::TextBox *skillNameWidget, *skillValueWidget; - skillNameWidget = mSkillClientWidget->createWidget("SandText", coord1, MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch); + skillNameWidget = mSkillView->createWidget("SandText", coord1, MyGUI::Align::Left | MyGUI::Align::Top | MyGUI::Align::HStretch); skillNameWidget->setCaption(text); skillNameWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); - skillValueWidget = mSkillClientWidget->createWidget("SandTextRight", coord2, MyGUI::Align::Right | MyGUI::Align::Top); + skillValueWidget = mSkillView->createWidget("SandTextRight", coord2, MyGUI::Align::Right | MyGUI::Align::Top); skillValueWidget->setCaption(value); skillValueWidget->_setWidgetState(state); skillValueWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); @@ -348,7 +320,7 @@ MyGUI::Widget* StatsWindow::addItem(const std::string& text, MyGUI::IntCoord &co { MyGUI::TextBox* skillNameWidget; - skillNameWidget = mSkillClientWidget->createWidget("SandText", coord1 + MyGUI::IntSize(coord2.width, 0), MyGUI::Align::Default); + skillNameWidget = mSkillView->createWidget("SandText", coord1 + MyGUI::IntSize(coord2.width, 0), MyGUI::Align::Default); skillNameWidget->setCaption(text); skillNameWidget->eventMouseWheel += MyGUI::newDelegate(this, &StatsWindow::onMouseWheel); @@ -426,12 +398,11 @@ void StatsWindow::updateSkillArea() } mSkillWidgets.clear(); - mSkillScrollerWidget->setScrollPosition(0); - onScrollChangePosition(mSkillScrollerWidget, 0); + mSkillView->setViewOffset (MyGUI::IntPoint(0,0)); mClientHeight = 0; const int valueSize = 40; - MyGUI::IntCoord coord1(10, 0, mSkillClientWidget->getWidth() - (10 + valueSize), 18); + MyGUI::IntCoord coord1(10, 0, mSkillView->getWidth() - (10 + valueSize) - 24, 18); MyGUI::IntCoord coord2(coord1.left + coord1.width, coord1.top, valueSize, coord1.height); if (!mMajorSkills.empty()) @@ -555,15 +526,8 @@ void StatsWindow::updateSkillArea() } mClientHeight = coord1.top; - updateScroller(); -} -void StatsWindow::updateScroller() -{ - mSkillScrollerWidget->setScrollRange(std::max(mClientHeight - mSkillClientWidget->getHeight(), 0)); - mSkillScrollerWidget->setScrollPage(std::max(mSkillClientWidget->getHeight() - sLineHeight, 0)); - if (mClientHeight != 0) - mSkillScrollerWidget->setTrackSize( (mSkillAreaWidget->getHeight() / float(mClientHeight)) * mSkillScrollerWidget->getLineSize() ); + mSkillView->setCanvasSize (mSkillView->getWidth(), std::max(mSkillView->getHeight(), mClientHeight)); } void StatsWindow::onPinToggled() diff --git a/apps/openmw/mwgui/stats_window.hpp b/apps/openmw/mwgui/stats_window.hpp index a46ab7531..fea89ba2d 100644 --- a/apps/openmw/mwgui/stats_window.hpp +++ b/apps/openmw/mwgui/stats_window.hpp @@ -48,12 +48,10 @@ namespace MWGui void addGroup(const std::string &label, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); MyGUI::TextBox* addValueItem(const std::string& text, const std::string &value, const std::string& state, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); MyGUI::Widget* addItem(const std::string& text, MyGUI::IntCoord &coord1, MyGUI::IntCoord &coord2); - void updateScroller(); void setFactions (const FactionList& factions); void setBirthSign (const std::string &signId); - void onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos); void onWindowResize(MyGUI::Window* window); void onMouseWheel(MyGUI::Widget* _sender, int _rel); @@ -62,8 +60,8 @@ namespace MWGui MyGUI::Widget* mLeftPane; MyGUI::Widget* mRightPane; - MyGUI::WidgetPtr mSkillAreaWidget, mSkillClientWidget; - MyGUI::ScrollBar* mSkillScrollerWidget; + MyGUI::WidgetPtr mSkillAreaWidget; + MyGUI::ScrollView* mSkillView; int mLastPos, mClientHeight; SkillList mMajorSkills, mMinorSkills, mMiscSkills; diff --git a/files/mygui/openmw_stats_window.layout b/files/mygui/openmw_stats_window.layout index 81d70f704..c2c8a5dae 100644 --- a/files/mygui/openmw_stats_window.layout +++ b/files/mygui/openmw_stats_window.layout @@ -218,8 +218,7 @@ - - +