MultiColumnList RowMultiple getNextSelectedItem

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

User avatar
Falagard
Just popping in
Just popping in
Posts: 12
Joined: Wed Jan 12, 2005 12:06

MultiColumnList RowMultiple getNextSelectedItem

Postby Falagard » Tue Feb 28, 2006 19:38

Hi guys. I was trying to use MultiColumnList with RowMultiple selection mode and then trying to retrieve the multiple rows that the user had selected and was having problems.

I was doing something like this:

Code: Select all

    CEGUI::ListboxItem* item = mSelectList->getFirstSelectedItem();
   
    if(!item)
      return true;

    for(;item != NULL; item = mSelectList->getNextSelected(item))
    {
      //do something here for selected item
    }


However it wasn't working as I expected. If a user had selected two rows, it was iterating through the first selected row, each item in each column in that row, but then not moving onto the next row. I looked at the source code for CEGUIMultiColumnList::getNextSelected and couldn't see what the problem might be. I'm actualling using the compiled SDK 0.4.1 but I additionally downloaded the source.

To get what I wanted I had to do this:

Code: Select all

    CEGUI::ListboxItem* item = mSelectList->getFirstSelectedItem();

    if(!item)
      return true;

    int colCount = mSelectList->getColumnCount();
    int rowCount = mSelectList->getRowCount();

    for(int row = 0; row < rowCount; ++row)
    {
      for(int col = 0; col < colCount; ++col)
      {
        CEGUI::MCLGridRef gridRef(row, col);
        //get item by grid reference
        item = mSelectList->getItemAtGridReference(gridRef);
        if(item->isSelected())
        {
          //do something here with the selected item
          break; //break out of the column loop
        }
      }
    }



Perhaps this will help others, or you could explain what I was doing wrong.

Clay

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Postby CrazyEddie » Thu Mar 02, 2006 09:19

Hi Falagard :)

I've not looked at the code yet, but this definitely sounds like some kind of bug.

Thanks for bringing it up, and for the work-around :D

CE.

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Postby Rackle » Tue Apr 25, 2006 06:21

The problem is with this bit of code within CEGUIMultiColumnList.cpp line 505:

if (start_item != NULL)
{
startRef = getItemGridReference(start_item);
++startRef.column;
}

Let's say the multi column list has three columns and the first two rows are selected. The cycle is started with a NULL, via the call to getFirstSelectedItem(). It will iterate through row 0, columns 0, 1, 2. The problem is that when trying to access the next row the code above will raise startRef.column to 3, which is beyond the capacity of getColumnCount(), which will prevent the code that follows from iterating through the second selected row.

The solution would be to increment the row and reset the column:

if (start_item != NULL)
{
startRef = getItemGridReference(start_item);
++startRef.column;
if( startRef.column == getColumnCount() )
{
startRef.column = 0;
++startRef.row;
}
}


[EDIT] Changed getRowCount() to getColumnCount(), silly mistake.

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Tue May 09, 2006 22:13

I have applied this fix to both 0.4 and 0.5


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 8 guests