1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
#ifndef __C_GUI_ENUM_ATTRIBUTE_H_INCLUDED__
#define __C_GUI_ENUM_ATTRIBUTE_H_INCLUDED__
#include "CGUIAttribute.h"
#include "IGUIComboBox.h"
#include "IGUIEditBox.h"
#include "EGUIEditTypes.h"
namespace irr
{
namespace gui
{
class CGUIEnumAttribute : public CGUIAttribute
{
public:
//
CGUIEnumAttribute(IGUIEnvironment* environment, IGUIElement *parent, s32 myParentID) :
CGUIAttribute(environment, parent, myParentID),
AttribComboBox(0), AttribEditBox(0)
{
}
virtual ~CGUIEnumAttribute()
{
if (AttribComboBox)
AttribComboBox->drop();
if (AttribEditBox)
AttribEditBox->drop();
}
// save the attribute and possibly post the event to its parent
virtual void setAttrib(io::IAttributes *attribs, u32 attribIndex)
{
if (AttribComboBox)
{
AttribComboBox->remove();
AttribComboBox->drop();
AttribComboBox = 0;
}
if (AttribEditBox)
{
AttribEditBox->remove();
AttribEditBox->drop();
AttribEditBox = 0;
}
core::array<core::stringc> outLiterals;
attribs->getAttributeEnumerationLiteralsOfEnumeration(attribIndex, outLiterals);
core::rect<s32> r = getAbsolutePosition();
core::rect<s32> r2(0, Environment->getSkin()->getFont()->getDimension(L"A").Height + 10,
r.getWidth() - 5,
Environment->getSkin()->getFont()->getDimension(L"A").Height*2 + 20 );
if (outLiterals.size() > 0)
{
AttribComboBox = Environment->addComboBox(r2, this, -1);
for (u32 i=0; i<outLiterals.size(); ++i)
AttribComboBox->addItem( core::stringw(outLiterals[i].c_str()).c_str());
AttribComboBox->setSelected( attribs->getAttributeAsInt(attribIndex) );
AttribComboBox->grab();
AttribComboBox->setSubElement(true);
AttribComboBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
}
else
{
AttribEditBox = Environment->addEditBox(
attribs->getAttributeAsStringW(attribIndex).c_str(),
r2, true, this, -1);
AttribEditBox->grab();
AttribEditBox->setSubElement(true);
AttribEditBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
}
CGUIAttribute::setAttrib(attribs, attribIndex);
}
//! save the attribute and possibly post the event to its parent
virtual bool updateAttrib(bool sendEvent=true)
{
if (!Attribs)
return true;
if (AttribComboBox)
Attribs->setAttribute(Index, AttribComboBox->getText());
else if (AttribEditBox)
Attribs->setAttribute(Index, AttribEditBox->getText());
return CGUIAttribute::updateAttrib(sendEvent);
}
//! Returns the type name of the gui element.
virtual const c8* getTypeName() const
{
return GUIEditElementTypeNames[EGUIEDIT_ENUMATTRIBUTE];
}
private:
IGUIComboBox* AttribComboBox;
IGUIEditBox* AttribEditBox;
};
} // namespace gui
} // namespace irr
#endif
|