aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2023-04-11 14:36:44 +0200
committersfan5 <sfan5@live.de>2023-04-11 14:36:44 +0200
commit2d81374b3470aace9ccc42478e98c92aed479279 (patch)
treef52293d1e5d22313ee929f9cd653610408c9c942 /source
parentaa1696a7e6a275e613e7323e7f9553b7b7a0b7e0 (diff)
downloadirrlicht-2d81374b3470aace9ccc42478e98c92aed479279.tar.xz
Revert "Fix: Listbox was sometimes sending EGET_LISTBOX_SELECTED_AGAIN instead of EGET_LISTBOX_CHANGED."
This broke scrolling in listboxes, as they would always reset to top position. reverts commit 1967d71cfba23fb54ac88cea64673f73af13bfda
Diffstat (limited to 'source')
-rw-r--r--source/Irrlicht/CGUIListBox.cpp38
-rw-r--r--source/Irrlicht/CGUIListBox.h3
2 files changed, 16 insertions, 25 deletions
diff --git a/source/Irrlicht/CGUIListBox.cpp b/source/Irrlicht/CGUIListBox.cpp
index cbd3ae5..b00c7e3 100644
--- a/source/Irrlicht/CGUIListBox.cpp
+++ b/source/Irrlicht/CGUIListBox.cpp
@@ -22,10 +22,10 @@ namespace gui
CGUIListBox::CGUIListBox(IGUIEnvironment* environment, IGUIElement* parent,
s32 id, core::rect<s32> rectangle, bool clip,
bool drawBack, bool moveOverSelect)
-: IGUIListBox(environment, parent, id, rectangle), Selected(-1), HoverSelected(-1),
+: IGUIListBox(environment, parent, id, rectangle), Selected(-1),
ItemHeight(0),ItemHeightOverride(0),
TotalItemHeight(0), ItemsIconWidth(0), Font(0), IconBank(0),
- ScrollBar(0), SelectTime(0), LastKeyTime(0), Selecting(false), DrawBack(drawBack),
+ ScrollBar(0), selectTime(0), LastKeyTime(0), Selecting(false), DrawBack(drawBack),
MoveOverSelect(moveOverSelect), AutoScroll(true), HighlightWhenNotFocused(true)
{
#ifdef _DEBUG
@@ -116,7 +116,7 @@ void CGUIListBox::removeItem(u32 id)
else if ((u32)Selected > id)
{
Selected -= 1;
- SelectTime = os::Timer::getTime();
+ selectTime = os::Timer::getTime();
}
Items.erase(id);
@@ -148,7 +148,6 @@ void CGUIListBox::clear()
Items.clear();
ItemsIconWidth = 0;
Selected = -1;
- HoverSelected = -1;
ScrollBar->setPos(0);
@@ -193,7 +192,7 @@ void CGUIListBox::recalculateItemHeight()
//! returns id of selected item. returns -1 if no item is selected.
s32 CGUIListBox::getSelected() const
{
- return HoverSelected >= 0 ? HoverSelected : Selected;
+ return Selected;
}
@@ -205,8 +204,7 @@ void CGUIListBox::setSelected(s32 id)
else
Selected = id;
- HoverSelected = -1;
- SelectTime = os::Timer::getTime();
+ selectTime = os::Timer::getTime();
recalculateScrollPos();
}
@@ -456,19 +454,14 @@ void CGUIListBox::selectNew(s32 ypos, bool onlyHover)
u32 now = os::Timer::getTime();
s32 oldSelected = Selected;
- HoverSelected = getItemAt(AbsoluteRect.UpperLeftCorner.X, ypos);
- if (HoverSelected<0 && !Items.empty())
- HoverSelected = 0;
- if (!onlyHover)
- {
- Selected = HoverSelected;
- HoverSelected = -1;
- }
+ Selected = getItemAt(AbsoluteRect.UpperLeftCorner.X, ypos);
+ if (Selected<0 && !Items.empty())
+ Selected = 0;
recalculateScrollPos();
- gui::EGUI_EVENT_TYPE eventType = (Selected == oldSelected && now < SelectTime + 500) ? EGET_LISTBOX_SELECTED_AGAIN : EGET_LISTBOX_CHANGED;
- SelectTime = now;
+ gui::EGUI_EVENT_TYPE eventType = (Selected == oldSelected && now < selectTime + 500) ? EGET_LISTBOX_SELECTED_AGAIN : EGET_LISTBOX_CHANGED;
+ selectTime = now;
// post the news
if (Parent && !onlyHover)
{
@@ -534,14 +527,13 @@ void CGUIListBox::draw()
frameRect.LowerRightCorner.Y -= ScrollBar->getPos();
bool hl = (HighlightWhenNotFocused || Environment->hasFocus(this) || Environment->hasFocus(ScrollBar));
- const irr::s32 selected = getSelected();
for (s32 i=0; i<(s32)Items.size(); ++i)
{
if (frameRect.LowerRightCorner.Y >= AbsoluteRect.UpperLeftCorner.Y &&
frameRect.UpperLeftCorner.Y <= AbsoluteRect.LowerRightCorner.Y)
{
- if (i == selected && hl)
+ if (i == Selected && hl)
skin->draw2DRectangle(this, skin->getColor(EGDC_HIGH_LIGHT), frameRect, &clientClip);
core::rect<s32> textRect = frameRect;
@@ -555,24 +547,24 @@ void CGUIListBox::draw()
iconPos.Y += textRect.getHeight() / 2;
iconPos.X += ItemsIconWidth/2;
- if ( i==selected && hl )
+ if ( i==Selected && hl )
{
IconBank->draw2DSprite( (u32)Items[i].Icon, iconPos, &clientClip,
hasItemOverrideColor(i, EGUI_LBC_ICON_HIGHLIGHT) ?
getItemOverrideColor(i, EGUI_LBC_ICON_HIGHLIGHT) : getItemDefaultColor(EGUI_LBC_ICON_HIGHLIGHT),
- SelectTime, os::Timer::getTime(), false, true);
+ selectTime, os::Timer::getTime(), false, true);
}
else
{
IconBank->draw2DSprite( (u32)Items[i].Icon, iconPos, &clientClip,
hasItemOverrideColor(i, EGUI_LBC_ICON) ? getItemOverrideColor(i, EGUI_LBC_ICON) : getItemDefaultColor(EGUI_LBC_ICON),
- 0 , (i==selected) ? os::Timer::getTime() : 0, false, true);
+ 0 , (i==Selected) ? os::Timer::getTime() : 0, false, true);
}
}
textRect.UpperLeftCorner.X += ItemsIconWidth+3;
- if ( i==selected && hl )
+ if ( i==Selected && hl )
{
Font->draw(Items[i].Text.c_str(), textRect,
hasItemOverrideColor(i, EGUI_LBC_TEXT_HIGHLIGHT) ?
diff --git a/source/Irrlicht/CGUIListBox.h b/source/Irrlicht/CGUIListBox.h
index 37fffa8..a3e7255 100644
--- a/source/Irrlicht/CGUIListBox.h
+++ b/source/Irrlicht/CGUIListBox.h
@@ -154,7 +154,6 @@ namespace gui
core::array< ListItem > Items;
s32 Selected;
- s32 HoverSelected; // When >= 0 we're in the middle of changing selection while mouse is pressed. We need to know so selected again isn't called too often.
s32 ItemHeight;
s32 ItemHeightOverride;
s32 TotalItemHeight;
@@ -162,7 +161,7 @@ namespace gui
gui::IGUIFont* Font;
gui::IGUISpriteBank* IconBank;
gui::IGUIScrollBar* ScrollBar;
- u32 SelectTime;
+ u32 selectTime;
u32 LastKeyTime;
core::stringw KeyBuffer;
bool Selecting;