diff -r ac39d1dafd3c lib/irrlicht/include/IGUIListBox.h --- a/lib/irrlicht/include/IGUIListBox.h Wed Sep 23 15:31:57 2009 +0200 +++ b/lib/irrlicht/include/IGUIListBox.h Wed Sep 23 15:37:01 2009 +0200 @@ -63,6 +63,9 @@ namespace gui //! returns string of a list item. the may id be a value from 0 to itemCount-1 virtual const wchar_t* getListItem(u32 id) const = 0; + + //! get the the index of the item below the given absolute screen coordinates + virtual s32 getItemAt(s32 xpos, s32 ypos) const = 0; //! adds an list item, returns id of item virtual u32 addItem(const wchar_t* text) = 0; diff -r ac39d1dafd3c lib/irrlicht/source/Irrlicht/CGUIListBox.cpp --- a/lib/irrlicht/source/Irrlicht/CGUIListBox.cpp Wed Sep 23 15:31:57 2009 +0200 +++ b/lib/irrlicht/source/Irrlicht/CGUIListBox.cpp Wed Sep 23 15:37:01 2009 +0200 @@ -93,6 +93,35 @@ const wchar_t* CGUIListBox::getListItem( return Items[id].text.c_str(); } +//! get the the index of the item below the given absolute screen coordinates +s32 CGUIListBox::getItemAt(s32 xpos, s32 ypos) const +{ + if ( xpos < AbsoluteRect.UpperLeftCorner.X || xpos >= AbsoluteRect.LowerRightCorner.X ) + return -1; + + if ( ItemHeight == 0 ) + return -1; + + s32 item = ((ypos - AbsoluteRect.UpperLeftCorner.Y - 1) + ScrollBar->getPos()) / ItemHeight; + if ( item < 0 || item >= (s32)Items.size()) + return -1; + + if ( WordWrap ) + { + s32 lines = 0; + for ( u32 i=0; i < Items.size(); ++i) + { + lines += Items[i].WrappedText.size(); + if ( lines > item ) + { + item = i; + break; + } + } + } + + return item; +} //! Returns the icon of an item s32 CGUIListBox::getIcon(u32 id) const @@ -462,28 +491,11 @@ void CGUIListBox::selectNew(s32 ypos, bo s32 oldSelected = Selected; // find new selected item. - if (ItemHeight!=0) - { - s32 selectedLine = ((ypos - AbsoluteRect.UpperLeftCorner.Y - 1) + ScrollBar->getPos()) / ItemHeight; - - Selected = selectedLine; - if ( WordWrap ) - { - s32 lines = 0; - for ( u32 i=0; i < Items.size(); ++i) - { - lines += Items[i].WrappedText.size(); - if ( lines > selectedLine ) - { - Selected = i; - break; - } - } - } - } + Selected = getItemAt(AbsoluteRect.UpperLeftCorner.X, ypos); // set the multiselection flag. The other stuff like active selected can just be ignored. if ( EGUI_LBS_MULTI_SELECTION == SelectionMode + && Selected >= 0 && Selected < (s32)Items.size() ) { diff -r ac39d1dafd3c lib/irrlicht/source/Irrlicht/CGUIListBox.h --- a/lib/irrlicht/source/Irrlicht/CGUIListBox.h Wed Sep 23 15:31:57 2009 +0200 +++ b/lib/irrlicht/source/Irrlicht/CGUIListBox.h Wed Sep 23 15:37:01 2009 +0200 @@ -35,6 +35,9 @@ namespace gui //! returns string of a list item. the id may be a value from 0 to itemCount-1 virtual const wchar_t* getListItem(u32 id) const; + + //! get the the index of the item below the given absolute screen coordinates + virtual s32 getItemAt(s32 xpos, s32 ypos) const; //! adds an list item, returns id of item virtual u32 addItem(const wchar_t* text);