2 This base class is used by the Attribute editor for making your own attribute types.
\r
4 The attribute editor will try and create an attribute called "AttribType_attribute",
\r
5 and if it fails, it will create a "string_attribute".
\r
9 #ifndef __C_GUI_ATTRIBUTE_H_INCLUDED__
\r
10 #define __C_GUI_ATTRIBUTE_H_INCLUDED__
\r
12 #include "IGUIElement.h"
\r
13 #include "IGUIEnvironment.h"
\r
14 #include "IGUIFont.h"
\r
15 #include "IGUIStaticText.h"
\r
16 #include "IAttributes.h"
\r
17 #include "CGUIEditWorkspace.h"
\r
25 const u32 ATTRIBEDIT_ATTRIB_CHANGED=MAKE_IRR_ID('A','T','T','R');
\r
27 class CGUIAttribute : public IGUIElement
\r
31 CGUIAttribute(IGUIEnvironment* environment, IGUIElement *parent, s32 myParentID) :
\r
32 IGUIElement(EGUIET_ELEMENT, environment, parent, -1, core::rect<s32>(0, 0, 100, 100) ),
\r
33 AttribName(0), Attribs(0), Index(0), MyParentID(myParentID)
\r
37 setDebugName("CGUIAttribute");
\r
40 AttribName = environment->addStaticText(0,
\r
41 core::rect<s32>(0, 0,
\r
42 100, Environment->getSkin()->getFont()->getDimension(L"A").Height),
\r
43 false, false, this, -1, false);
\r
45 AttribName->setSubElement(true);
\r
46 AttribName->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
\r
49 virtual ~CGUIAttribute()
\r
57 virtual bool OnEvent(const SEvent &e)
\r
61 switch (e.EventType)
\r
64 switch (e.GUIEvent.EventType)
\r
66 case EGET_ELEMENT_FOCUSED:
\r
67 if (Parent && isMyChild(e.GUIEvent.Caller))
\r
68 Parent->bringToFront(this);
\r
70 case EGET_ELEMENT_HOVERED:
\r
71 case EGET_ELEMENT_LEFT:
\r
72 return IGUIElement::OnEvent(e);
\r
73 case EGET_ELEMENT_FOCUS_LOST:
\r
75 return IGUIElement::OnEvent(e);
\r
77 return updateAttrib();
\r
80 case EET_KEY_INPUT_EVENT:
\r
87 return IGUIElement::OnEvent(e);
\r
90 //! sets the attribute to use
\r
91 virtual void setAttrib(io::IAttributes *attribs, u32 attribIndex)
\r
98 Index = attribIndex;
\r
100 core::stringw name(attribs->getAttributeName(attribIndex));
\r
102 name += attribs->getAttributeTypeString(attribIndex);
\r
104 AttribName->setText(name.c_str());
\r
106 core::rect<s32> r = Parent->getAbsolutePosition();
\r
107 core::rect<s32> r2(0, 5,
\r
108 r.getWidth(), Environment->getSkin()->getFont()->getDimension(L"A").Height + 10 );
\r
110 AttribName->setRelativePosition(r2);
\r
112 // get minimum height
\r
114 core::list<IGUIElement*>::Iterator it = Children.begin();
\r
115 for (; it != Children.end(); ++it)
\r
117 if (y < (*it)->getRelativePosition().LowerRightCorner.Y)
\r
118 y = (*it)->getRelativePosition().LowerRightCorner.Y;
\r
120 setMinSize( core::dimension2du(0, y+5));
\r
122 updateAttrib(false);
\r
125 //! sets the parent ID, for identifying where events came from
\r
126 void setParentID(s32 parentID)
\r
128 MyParentID = parentID;
\r
131 //! save the attribute and possibly post the event to its parent
\r
132 virtual bool updateAttrib(bool sendEvent=true)
\r
134 if (Attribs && IsEnabled && sendEvent)
\r
136 // build event and pass to parent
\r
138 event.EventType = (EEVENT_TYPE)ATTRIBEDIT_ATTRIB_CHANGED;
\r
139 event.UserEvent.UserData1 = MyParentID;
\r
140 event.UserEvent.UserData2 = Index;
\r
141 return Parent->OnEvent(event);
\r
147 virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0)
\r
149 IGUIElement::serializeAttributes(out, options);
\r
152 virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)
\r
154 IGUIElement::deserializeAttributes(in, options);
\r
156 AttribName->setText(Text.c_str());
\r
160 IGUIStaticText* AttribName;
\r
161 io::IAttributes* Attribs;
\r