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
master
cutealien 2018-06-17 19:46:40 +00:00
parent 2246895ae1
commit 7442e24ded
2 changed files with 10 additions and 12 deletions

View File

@ -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<s32>(RelativeRect.getWidth() - ScrollBarSize, 0, RelativeRect.getWidth(), RelativeRect.getHeight()),
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,7 +150,6 @@ void CGUIListBox::clear()
ItemsIconWidth = 0;
Selected = -1;
if (ScrollBar)
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);
}
}

View File

@ -171,7 +171,6 @@ namespace gui
s32 ItemHeightOverride;
s32 TotalItemHeight;
s32 ItemsIconWidth;
s32 ScrollBarSize;
gui::IGUIFont* Font;
gui::IGUISpriteBank* IconBank;
gui::IGUIScrollBar* ScrollBar;