From 7442e24ded060ed67f6a75baec0be86fd3bdba6f Mon Sep 17 00:00:00 2001 From: cutealien Date: Sun, 17 Jun 2018 19:46:40 +0000 Subject: [PATCH] Simplify code (no need to keep scroll-bar width in extra variable here). git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5621 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CGUIListBox.cpp | 21 ++++++++++----------- source/Irrlicht/CGUIListBox.h | 1 - 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/source/Irrlicht/CGUIListBox.cpp b/source/Irrlicht/CGUIListBox.cpp index fde30e6a..7d484570 100644 --- a/source/Irrlicht/CGUIListBox.cpp +++ b/source/Irrlicht/CGUIListBox.cpp @@ -25,7 +25,7 @@ CGUIListBox::CGUIListBox(IGUIEnvironment* environment, IGUIElement* parent, bool drawBack, bool moveOverSelect) : IGUIListBox(environment, parent, id, rectangle), Selected(-1), ItemHeight(0),ItemHeightOverride(0), - TotalItemHeight(0), ItemsIconWidth(0), ScrollBarSize(0), Font(0), IconBank(0), + TotalItemHeight(0), ItemsIconWidth(0), Font(0), IconBank(0), ScrollBar(0), selectTime(0), LastKeyTime(0), Selecting(false), DrawBack(drawBack), MoveOverSelect(moveOverSelect), AutoScroll(true), HighlightWhenNotFocused(true) { @@ -34,10 +34,9 @@ CGUIListBox::CGUIListBox(IGUIEnvironment* environment, IGUIElement* parent, #endif IGUISkin* skin = Environment->getSkin(); - ScrollBarSize = skin->getSize(EGDS_SCROLLBAR_SIZE); - ScrollBar = new CGUIScrollBar(false, Environment, this, -1, - core::rect(RelativeRect.getWidth() - ScrollBarSize, 0, RelativeRect.getWidth(), RelativeRect.getHeight()), + ScrollBar = new CGUIScrollBar(false, Environment, this, -1, + core::recti(0, 0, 1, 1), !clip); ScrollBar->setSubElement(true); ScrollBar->setTabStop(false); @@ -45,6 +44,8 @@ CGUIListBox::CGUIListBox(IGUIEnvironment* environment, IGUIElement* parent, ScrollBar->setVisible(false); ScrollBar->setPos(0); + updateScrollBarSize(skin->getSize(EGDS_SCROLLBAR_SIZE)); + setNotClipped(!clip); // this element can be tabbed to @@ -149,8 +150,7 @@ void CGUIListBox::clear() ItemsIconWidth = 0; Selected = -1; - if (ScrollBar) - ScrollBar->setPos(0); + ScrollBar->setPos(0); recalculateItemHeight(); } @@ -510,7 +510,7 @@ void CGUIListBox::draw() clientClip.UpperLeftCorner.Y += 1; clientClip.UpperLeftCorner.X += 1; if (ScrollBar->isVisible()) - clientClip.LowerRightCorner.X -= ScrollBarSize; + clientClip.LowerRightCorner.X -= ScrollBar->getRelativePosition().getWidth(); clientClip.LowerRightCorner.Y -= 1; clientClip.clipAgainst(AbsoluteClippingRect); @@ -523,7 +523,7 @@ void CGUIListBox::draw() frameRect = AbsoluteRect; frameRect.UpperLeftCorner.X += 1; if (ScrollBar->isVisible()) - frameRect.LowerRightCorner.X -= ScrollBarSize; + frameRect.LowerRightCorner.X -= ScrollBar->getRelativePosition().getWidth(); frameRect.LowerRightCorner.Y = AbsoluteRect.UpperLeftCorner.Y + ItemHeight; @@ -642,10 +642,9 @@ void CGUIListBox::recalculateScrollPos() void CGUIListBox::updateScrollBarSize(s32 size) { - if ( size != ScrollBarSize ) + if ( size != ScrollBar->getRelativePosition().getWidth() ) { - ScrollBarSize = size; - core::recti r(RelativeRect.getWidth() - ScrollBarSize, 0, RelativeRect.getWidth(), RelativeRect.getHeight()); + core::recti r(RelativeRect.getWidth() - size, 0, RelativeRect.getWidth(), RelativeRect.getHeight()); ScrollBar->setRelativePosition(r); } } diff --git a/source/Irrlicht/CGUIListBox.h b/source/Irrlicht/CGUIListBox.h index 6219325a..4fc61220 100644 --- a/source/Irrlicht/CGUIListBox.h +++ b/source/Irrlicht/CGUIListBox.h @@ -171,7 +171,6 @@ namespace gui s32 ItemHeightOverride; s32 TotalItemHeight; s32 ItemsIconWidth; - s32 ScrollBarSize; gui::IGUIFont* Font; gui::IGUISpriteBank* IconBank; gui::IGUIScrollBar* ScrollBar;