1 #ifndef __C_GUI_BOOL_ATTRIBUTE_H_INCLUDED__
2 #define __C_GUI_BOOL_ATTRIBUTE_H_INCLUDED__
3 
4 #include "CGUIAttribute.h"
5 #include "IGUICheckBox.h"
6 #include "EGUIEditTypes.h"
7 
8 namespace irr
9 {
10 namespace gui
11 {
12 
13 	class CGUIBoolAttribute : public CGUIAttribute
14 	{
15 	public:
16 		//
CGUIBoolAttribute(IGUIEnvironment * environment,IGUIElement * parent,s32 myParentID)17 		CGUIBoolAttribute(IGUIEnvironment* environment, IGUIElement *parent, s32 myParentID) :
18 		  	CGUIAttribute(environment, parent, myParentID), AttribCheckBox(0)
19 		{
20 
21 			core::rect<s32> r = getAbsolutePosition();
22 			core::rect<s32> r2(0, Environment->getSkin()->getFont()->getDimension(L"A").Height + 10,
23 				r.getWidth() - 5,
24 				Environment->getSkin()->getFont()->getDimension(L"A").Height*2 + 15 );
25 
26 			AttribCheckBox = environment->addCheckBox(false, r2, this);
27 			AttribCheckBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
28 			AttribCheckBox->setSubElement(true);
29 			AttribCheckBox->grab();
30 		}
31 
~CGUIBoolAttribute()32 		virtual ~CGUIBoolAttribute()
33 		{
34 			if (AttribCheckBox)
35 				AttribCheckBox->drop();
36 		}
37 
setAttrib(io::IAttributes * attribs,u32 attribIndex)38 		virtual void setAttrib(io::IAttributes *attribs, u32 attribIndex)
39 		{
40 			AttribCheckBox->setChecked(attribs->getAttributeAsBool(attribIndex));
41 			CGUIAttribute::setAttrib(attribs, attribIndex);
42 		}
43 
44 		// save the attribute and possibly post the event to its parent
45 		virtual bool updateAttrib(bool sendEvent=true)
46 		{
47 			if (!Attribs)
48 				return true;
49 
50 			Attribs->setAttribute(Index, AttribCheckBox->isChecked());
51 
52 			return CGUIAttribute::updateAttrib(sendEvent);
53 		}
54 
55 		//! Returns the type name of the gui element.
getTypeName()56 		virtual const c8* getTypeName() const
57 		{
58 			return GUIEditElementTypeNames[EGUIEDIT_BOOLATTRIBUTE];
59 		}
60 
61 	private:
62 		IGUICheckBox*		AttribCheckBox;
63 	};
64 
65 } // namespace gui
66 } // namespace irr
67 
68 #endif
69