Hi,
I would like to have a combobox where the user can choose his country and I would like he could see a flag in the right side of each country name in the drop down list. Is it possible?
Thanks,
Dirso.
Multi Column ComboBox
Moderators: CEGUI MVP, CEGUI Team
Yes, it is possible by reating your own combobox items with their own drawing functions. Here is my source code of a iten you can use in listboxes/comboboxes, wich prepends one picture (directory or file) on the left and the sometext.
PS: sorry for the code formating
Header:
source:
PS: sorry for the code formating

Header:
Code: Select all
10 class CFileDlgListItem : public CEGUI::ListboxTextItem {
11 public:
12 CFileDlgListItem ( const String& in_text, PDBrowseInfo in_pDBI, CEGUI::uint in_uiItemID = 0, void* in_pItemData = 0, bool in_bDisabled = false, bool in_bAutoDelete = true );
13 CFileDlgListItem ( const String& in_text, bool in_bDir , CEGUI::uint in_uiItemID = 0, void* in_pItemData = 0, bool in_bDisabled = false, bool in_bAutoDelete = true );
14 virtual ~CFileDlgListItem( void );
15
16 Size getPixelSize( void ) const;
17 void draw( const Vector3& in_position, float in_fAlpha, const Rect& in_clipper ) const;
18 void draw( RenderCache& in_cache, const Rect& in_targetRect, float in_fZBase, float in_fAlpha, const Rect* in_pClipper ) const;
19
20 bool isDir( void ) { return m_bDir; };
21 private:
22 CEGUI::Image m_Img;
23 bool m_bDir;
24 };
source:
Code: Select all
33 /* Initialises an item of the file dialog listbox. */
34 CFileDlgListItem::CFileDlgListItem( const String& in_text, PDBrowseInfo in_pDBI, CEGUI::uint in_uiItemID, void* in_pItemData, bool in_bDisabled, bool in_bAutoDelete ) :
35 ListboxTextItem( in_text, in_uiItemID, in_pItemData, in_bDisabled, in_bAutoDelete )
36 {
37 try {
38 if( (dBrowse_GetType( in_pDBI ) == DB_DIR) ) {
39 m_Img = globals->pUI->m_pImageSet->getImage( "DirIcon" );
40 m_bDir = true;
41 } else {
42 m_Img = globals->pUI->m_pImageSet->getImage( "FileIcon" );
43 m_bDir = false;
44 }
45 } catch( CEGUI::Exception& e ) {
46 FTS18N( "CEGUI_Init", FTS_ERROR, e.getMessage( ).c_str( ) );
47 }
48 }
49
50 /* Initialises an item of the file dialog listbox. */
51 CFileDlgListItem::CFileDlgListItem( const String& in_text, bool in_bDir, CEGUI::uint in_uiItemID, void* in_pItemData, bool in_bDisabled, bool in_bAutoDelete ) :
52 ListboxTextItem( in_text, in_uiItemID, in_pItemData, in_bDisabled, in_bAutoDelete )
53 {
54 try {
55 if( in_bDir ) {
56 m_Img = globals->pUI->m_pImageSet->getImage( "DirIcon" );
57 m_bDir = true;
58 } else {
59 m_Img = globals->pUI->m_pImageSet->getImage( "FileIcon" );
60 m_bDir = false;
61 }
62 } catch( CEGUI::Exception& e ) {
63 FTS18N( "CEGUI_Init", FTS_ERROR, e.getMessage( ).c_str( ) );
64 }
65 }
66
67 CFileDlgListItem::~CFileDlgListItem( )
68 {
69 PList pLI = NULL;
70 if( isAutoDeleted( ) ) {
71 pLI = (PList)getUserData( );
72 SAFE_FREE( pLI );
73 }
74 }
75
76 /* Overloaded function to get the listbox item's size. */
77 Size CFileDlgListItem::getPixelSize( void ) const
78 {
79 Size s = ListboxTextItem::getPixelSize( );
80
81 s.d_height = s.d_height < m_Img.getHeight( ) ? m_Img.getHeight( ) : s.d_height;
82 s.d_width += m_Img.getWidth( );
83
84 return s;
85 }
86
87 /* Overloaded function to draw the listbox item. */
88 void CFileDlgListItem::draw( const Vector3& in_position, float in_fAlpha, const Rect& in_clipper ) const
89 {
90 Vector3 vTxt = in_position;
91
92 vTxt.d_x += m_Img.getWidth( );
93 m_Img.draw( in_position, in_clipper );
94
95 ListboxTextItem::draw( vTxt, in_fAlpha, in_clipper );
96 }
97
98 /* Overloaded function to draw the listbox item. */
99 void CFileDlgListItem::draw( RenderCache& in_cache, const Rect& in_targetRect, float in_fZBase, float in_fAlpha, const Rect* in_pClipper) const
100 {
101 Rect rImg = in_targetRect;
102 Rect rTxt = in_targetRect;
103 ColourRect cr( colour( 1.0f, 1.0f, 1.0f, in_fAlpha ) );
104
105 rTxt.d_left += m_Img.getWidth( );
106 rImg.d_right = rImg.d_left + m_Img.getWidth( );
107 in_cache.cacheImage( m_Img, rImg, in_fZBase, getModulateAlphaColourRect( cr, in_fAlpha ), in_pClipper );
108
109 ListboxTextItem::draw( in_cache, rTxt, in_fZBase, in_fAlpha, in_pClipper );
110 }
Return to “Modifications / Integrations / Customisations”
Who is online
Users browsing this forum: No registered users and 9 guests