[SOLVED] H: Can not getUserData() from the current Tab.

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
Van
Just can't stay away
Just can't stay away
Posts: 225
Joined: Fri Jan 21, 2005 20:29
Contact:

[SOLVED] H: Can not getUserData() from the current Tab.

Postby Van » Mon Mar 02, 2009 00:39

CEGUI: 0.6.2

How does one get their user data and ID from a tab they created?

This does NOT work:

Code: Select all


...

   mLastTabNumber++;
   mNewTabItem->TabNumber = mLastTabNumber;

...

   // Create the new TAB
   mNewTabItem->TabWindow = ( CEGUI::DefaultWindow *) CEGUI::WindowManager::getSingleton().createWindow( "DefaultWindow", mTemp );
   mTabControl->addTab( mNewTabItem->TabWindow );
   mNewTabItem->TabWindow->setFont( mNewTabItem->Font );
   mNewTabItem->TabWindow->setPosition( CEGUI::UVector2( CEGUI::UDim( 0.0f, 0.0f ), CEGUI::UDim( 0.0f, 0.0f ) ) );
   mNewTabItem->TabWindow->setSize( CEGUI::UVector2( CEGUI::UDim( 1.0f, 0.0f ), CEGUI::UDim( 1.0f, 0.0f ) ) );
   mNewTabItem->TabWindow->setText( mTabName );
   mNewTabItem->TabWindow->setUserData( mNewTabItem );
   mNewTabItem->TabWindow->setID( mNewTabItem->TabNumber );

...



and then when the CEGUI::TabControl fires off the EventSelectionChanged event...

Code: Select all


bool clsGUIChat::event_TabControl_TabChange(const CEGUI::EventArgs& e)
{
   // Get the current tab from the tab control.
   CEGUI::Window *mTabWindow = mTabControl->getActiveChild();
   if ( !mTabWindow || mTabWindow->getID() < 1 ) return true;

   // Can this tab be deleted?
   if ( mTabWindow->getID() == 1 )
      mPopupMenu[ PUM_MAIN ]->getChild( "Chat/PopupMenu/Tab/Delete" )->setEnabled( false );
   else
      mPopupMenu[ PUM_MAIN ]->getChild( "Chat/PopupMenu/Tab/Delete" )->setEnabled( true );   // Default

   // Update current Tab Item and Fonts.
   mCurrentTabItem = (tTabItem *) mTabWindow->getUserData();
   if ( mCurrentTabItem )
   {
      setTabFont( mCurrentTabItem, mCurrentTabItem->Font );
      refreshTabFonts();
   } // mCurrentTabItem?
   return true;
} // event_TabControl_TabChange



mTabWindow->getID() < 1 fails. Refer to this line when the tab is created: mNewTabItem->TabWindow->setID( mNewTabItem->TabNumber );

So, how can I do a getUserData() so I can get my data that I assigned way back up in mNewTabItem->TabWindow->setUserData( mNewTabItem );

It appears that the window being returned to me as the current tab is not really the window I created.
Last edited by Van on Mon Mar 02, 2009 10:48, edited 1 time in total.

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Mon Mar 02, 2009 09:17

Hi,

i have no compiled code at hands, but some questions/suggestions. Can you verify that the ActiveChild is equal to the window inside the event:

Code: Select all

Window* eventWindow = static_cast<const WindowEventArgs&>(e).window;

if (eventWindow->GetName() == mTabControl->getActiveChild()->GetName()
{
  // Equal ...
}


Also, but this might be a dull question. Did you initialize your mLastTabNumber item correctly? Maybe it has a bogus (negative) value?

HTH.
Check out my released snake game using Cegui!

User avatar
Van
Just can't stay away
Just can't stay away
Posts: 225
Joined: Fri Jan 21, 2005 20:29
Contact:

Postby Van » Mon Mar 02, 2009 10:29

Yes, mLastTabNumber is fine. When I step through the code the numbers are valid (we started with 1 - zero is invalid) .

I added the WindowEventArgs that you suggested and eventWindow does NOT equal getActiveChild.

As I stepped through the code I drilled down into the mTabControl and I did see my windows attached to the first child of mTabControl however, none of the children of mTabControl represent the window I created. So, CEGUI is definitely creating some auto windows.

User avatar
Van
Just can't stay away
Just can't stay away
Posts: 225
Joined: Fri Jan 21, 2005 20:29
Contact:

Postby Van » Mon Mar 02, 2009 10:47

OK, Solved it..

The proper way to get the active (or any) tab window from a tab control:

Code: Select all


   // Get the current tab from the tab control.
   CEGUI::Window *mTabWindow = mTabControl->getTabContentsAtIndex( mTabControl->getSelectedTabIndex() );



use CEGUI::TabControl::getTabContentsAtIndex()


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 14 guests