Allow to scroll list box by touch gesture.
It can be restricted to Android-only, but tbh. I don't see any reason that it can't work in the same way on desktop computers (may be usable on laptops with touch screen, all-in-one computers etc...). I also made a minor fix with if(!event.MouseInput.isLeftPressed()) because the EGET_ELEMENT_FOCUS_LOST event seems to not work at all.
This commit is contained in:
parent
6a16f23132
commit
bcea2355fa
@ -25,9 +25,10 @@ CGUISTKListBox::CGUISTKListBox(IGUIEnvironment* environment, IGUIElement* parent
|
|||||||
bool drawBack, bool moveOverSelect)
|
bool drawBack, bool moveOverSelect)
|
||||||
: IGUIElement(EGUIET_LIST_BOX, environment, parent, id, rectangle), Selected(-1),
|
: IGUIElement(EGUIET_LIST_BOX, environment, parent, id, rectangle), Selected(-1),
|
||||||
ItemHeight(0),ItemHeightOverride(0),
|
ItemHeight(0),ItemHeightOverride(0),
|
||||||
TotalItemHeight(0), ItemsIconWidth(0), Font(0), IconBank(0),
|
TotalItemHeight(0), ItemsIconWidth(0), MousePosY(0), Font(0), IconBank(0),
|
||||||
ScrollBar(0), selectTime(0), Selecting(false), DrawBack(drawBack),
|
ScrollBar(0), selectTime(0), Selecting(false), Moving(false),
|
||||||
MoveOverSelect(moveOverSelect), AutoScroll(true), HighlightWhenNotFocused(true)
|
DrawBack(drawBack), MoveOverSelect(moveOverSelect), AutoScroll(true),
|
||||||
|
HighlightWhenNotFocused(true)
|
||||||
{
|
{
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
setDebugName("CGUISTKListBox");
|
setDebugName("CGUISTKListBox");
|
||||||
@ -334,10 +335,12 @@ bool CGUISTKListBox::OnEvent(const SEvent& event)
|
|||||||
case gui::EGET_ELEMENT_FOCUS_LOST:
|
case gui::EGET_ELEMENT_FOCUS_LOST:
|
||||||
{
|
{
|
||||||
if (event.GUIEvent.Caller == this)
|
if (event.GUIEvent.Caller == this)
|
||||||
|
{
|
||||||
|
Moving = false;
|
||||||
Selecting = false;
|
Selecting = false;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -356,21 +359,43 @@ bool CGUISTKListBox::OnEvent(const SEvent& event)
|
|||||||
case EMIE_LMOUSE_PRESSED_DOWN:
|
case EMIE_LMOUSE_PRESSED_DOWN:
|
||||||
{
|
{
|
||||||
Selecting = true;
|
Selecting = true;
|
||||||
|
Moving = false;
|
||||||
|
MousePosY = event.MouseInput.Y;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EMIE_LMOUSE_LEFT_UP:
|
case EMIE_LMOUSE_LEFT_UP:
|
||||||
{
|
{
|
||||||
Selecting = false;
|
if (isPointInside(p) && !Moving)
|
||||||
|
|
||||||
if (isPointInside(p))
|
|
||||||
selectNew(event.MouseInput.Y);
|
selectNew(event.MouseInput.Y);
|
||||||
|
|
||||||
|
Selecting = false;
|
||||||
|
Moving = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
case EMIE_MOUSE_MOVED:
|
case EMIE_MOUSE_MOVED:
|
||||||
if (Selecting || MoveOverSelect)
|
if (!event.MouseInput.isLeftPressed())
|
||||||
|
{
|
||||||
|
Selecting = false;
|
||||||
|
Moving = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Selecting &&
|
||||||
|
fabs(event.MouseInput.Y - MousePosY) > ItemHeight/3)
|
||||||
|
{
|
||||||
|
Moving = true;
|
||||||
|
Selecting = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Moving)
|
||||||
|
{
|
||||||
|
int pos = ScrollBar->getPos() - event.MouseInput.Y + MousePosY;
|
||||||
|
ScrollBar->setPos(pos);
|
||||||
|
MousePosY = event.MouseInput.Y;
|
||||||
|
}
|
||||||
|
else if (Selecting || MoveOverSelect)
|
||||||
{
|
{
|
||||||
if (isPointInside(p))
|
if (isPointInside(p))
|
||||||
{
|
{
|
||||||
|
@ -178,12 +178,14 @@ namespace irr
|
|||||||
s32 ItemHeightOverride;
|
s32 ItemHeightOverride;
|
||||||
s32 TotalItemHeight;
|
s32 TotalItemHeight;
|
||||||
s32 ItemsIconWidth;
|
s32 ItemsIconWidth;
|
||||||
|
s32 MousePosY;
|
||||||
gui::IGUIFont* Font;
|
gui::IGUIFont* Font;
|
||||||
gui::IGUISpriteBank* IconBank;
|
gui::IGUISpriteBank* IconBank;
|
||||||
gui::IGUIScrollBar* ScrollBar;
|
gui::IGUIScrollBar* ScrollBar;
|
||||||
u32 selectTime;
|
u32 selectTime;
|
||||||
core::stringw KeyBuffer;
|
core::stringw KeyBuffer;
|
||||||
bool Selecting;
|
bool Selecting;
|
||||||
|
bool Moving;
|
||||||
bool DrawBack;
|
bool DrawBack;
|
||||||
bool MoveOverSelect;
|
bool MoveOverSelect;
|
||||||
bool AutoScroll;
|
bool AutoScroll;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user