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