diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/include/IGUIComboBox.h Irrlicht_starsonata/include/IGUIComboBox.h --- irrlicht-svn-ss/trunk/include/IGUIComboBox.h 2007-07-26 02:11:22.000000000 +0200 +++ Irrlicht_starsonata/include/IGUIComboBox.h 2007-12-28 05:45:50.000000000 +0100 @@ -45,6 +45,11 @@ namespace gui //! Sets the selected item. Set this to -1 if no item should be selected virtual void setSelected(s32 id) = 0; + //! set the custom data field for the item + virtual void setItemData(s32 idx, void *data) = 0; + + //! get the custom data field for the item + virtual void* getItemData(s32 idx) const = 0; }; diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CGUIComboBox.cpp Irrlicht_starsonata/source/Irrlicht/CGUIComboBox.cpp --- irrlicht-svn-ss/trunk/source/Irrlicht/CGUIComboBox.cpp 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CGUIComboBox.cpp 2008-06-13 19:45:42.000000000 +0200 @@ -44,8 +44,8 @@ CGUIComboBox::CGUIComboBox(IGUIEnvironme if (skin && skin->getSpriteBank()) { ListButton->setSpriteBank(skin->getSpriteBank()); - ListButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_CURSOR_DOWN), skin->getColor(EGDC_WINDOW_SYMBOL)); - ListButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_CURSOR_DOWN), skin->getColor(EGDC_WINDOW_SYMBOL)); + ListButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_DROP_DOWN), skin->getColor(EGDC_ICON)); + ListButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_DROP_DOWN_PRESSED), skin->getColor(EGDC_ICON)); } ListButton->setSubElement(true); ListButton->setTabStop(false); @@ -77,7 +77,7 @@ const wchar_t* CGUIComboBox::getItem(s32 if (idx < 0 || idx >= (s32)Items.size()) return 0; - return Items[idx].c_str(); + return Items[idx].Text.c_str(); } //! Removes an item from the combo box. @@ -102,7 +102,7 @@ const wchar_t* CGUIComboBox::getText() //! adds an item and returns the index of it s32 CGUIComboBox::addItem(const wchar_t* text) { - Items.push_back(core::stringw(text)); + Items.push_back( Item(core::stringw(text)) ); if (Selected == -1) Selected = 0; @@ -144,6 +144,7 @@ void CGUIComboBox::updateAbsolutePositio s32 width = Environment->getSkin()->getSize(EGDS_WINDOW_BUTTON_WIDTH); + if ( ListButton ) ListButton->setRelativePosition(core::rect(RelativeRect.getWidth() - width - 2, 2, RelativeRect.getWidth() - 2, RelativeRect.getHeight() - 2)); } @@ -152,6 +153,9 @@ void CGUIComboBox::updateAbsolutePositio //! called if an event happened. bool CGUIComboBox::OnEvent(SEvent event) { + if ( !IsEnabled ) + return IGUIElement::OnEvent(event); + switch(event.EventType) { @@ -300,7 +304,7 @@ bool CGUIComboBox::OnEvent(SEvent event) break; } - return Parent ? Parent->OnEvent(event) : false; + return IGUIElement::OnEvent(event); } @@ -356,10 +360,12 @@ void CGUIComboBox::draw() IGUIFont* font = skin->getFont(); if (font) - font->draw(Items[Selected].c_str(), frameRect, - skin->getColor(HasFocus ? EGDC_HIGH_LIGHT_TEXT : EGDC_BUTTON_TEXT), + { + font->draw(Items[Selected].Text.c_str(), frameRect, + skin->getColor(!IsEnabled ? EGDC_GRAY_TEXT : (HasFocus ? EGDC_HIGH_LIGHT_TEXT : EGDC_BUTTON_TEXT)), false, true, &AbsoluteClippingRect); } + } // draw buttons IGUIElement::draw(); @@ -399,9 +405,11 @@ void CGUIComboBox::openCloseMenu() ListBox = new CGUIListBox(Environment, this, -1, r, false, true, true); ListBox->setSubElement(true); ListBox->drop(); + video::SColor bkcolor = skin->getColor(EGDC_3D_FACE); + ListBox->setBackgroundOverrideColor( bkcolor ); for (s32 i=0; i<(s32)Items.size(); ++i) - ListBox->addItem(Items[i].c_str()); + ListBox->addItem(Items[i].Text.c_str()); ListBox->setSelected(Selected); @@ -410,22 +418,52 @@ void CGUIComboBox::openCloseMenu() } } + //! Writes attributes of the element. void CGUIComboBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) { IGUIComboBox::serializeAttributes(out,options); out->addInt ("Selected", Selected ); - out->addArray ("Items", Items); + + // done that way as it keeps downward compatibility + core::array< core::stringw > ItemTexts; + for ( u32 i=0; i < Items.size(); ++i ) + ItemTexts.push_back( Items[i].Text ); + out->addArray ("Items", ItemTexts); } //! Reads attributes of the element void CGUIComboBox::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) { - Items = in->getAttributeAsArray("Items"); IGUIComboBox::deserializeAttributes(in,options); setSelected(in->getAttributeAsInt("Selected")); + + Items.clear(); + core::array< core::stringw > ItemTexts; + ItemTexts = in->getAttributeAsArray("Items"); + for ( u32 i=0; i < ItemTexts.size(); ++i ) + Items.push_back( Item(ItemTexts[i]) ); +} + + +//! set the custom data field for the item +void CGUIComboBox::setItemData(s32 idx, void *data) +{ + if (idx < 0 || idx >= (s32)Items.size()) + return; + + Items[idx].UserData = data; +} + +//! get the custom data field for the item +void* CGUIComboBox::getItemData(s32 idx) const +{ + if (idx < 0 || idx >= (s32)Items.size()) + return 0; + + return Items[idx].UserData; } } // end namespace gui diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CGUIComboBox.h Irrlicht_starsonata/source/Irrlicht/CGUIComboBox.h --- irrlicht-svn-ss/trunk/source/Irrlicht/CGUIComboBox.h 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CGUIComboBox.h 2007-12-28 05:57:50.000000000 +0100 @@ -64,6 +64,12 @@ namespace gui //! Reads attributes of the element virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options); + //! set the custom data field for the item + virtual void setItemData(s32 idx, void *data); + + //! get the custom data field for the item + virtual void* getItemData(s32 idx) const; + private: void openCloseMenu(); @@ -71,10 +77,19 @@ namespace gui IGUIButton* ListButton; IGUIListBox* ListBox; - core::array< core::stringw > Items; s32 Selected; bool HasFocus; IGUIElement *LastFocus; + + struct Item + { + Item() : UserData(0) {} + Item(const core::stringw& text) : Text(text), UserData(0) {} + + core::stringw Text; + void * UserData; + }; + core::array< Item > Items; };