File: CGUIAttributeEditor.cpp

package info (click to toggle)
irrlicht 1.7.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 32,124 kB
  • ctags: 44,051
  • sloc: cpp: 137,592; ansic: 3,232; makefile: 801; sh: 16; sed: 11
file content (118 lines) | stat: -rw-r--r-- 2,746 bytes parent folder | download
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
115
116
117
118

#include "CGUIAttributeEditor.h"
#include "IGUIEnvironment.h"
#include "IFileSystem.h"
#include "IVideoDriver.h"
#include "IAttributes.h"
#include "IGUIFont.h"
#include "IGUIScrollBar.h"
#include "CGUIEditWorkspace.h"
#include "CGUIAttribute.h"
#include "CGUIStringAttribute.h"

namespace irr
{
namespace gui
{

using namespace core;
using namespace io;

CGUIAttributeEditor::CGUIAttributeEditor(IGUIEnvironment* environment, s32 id, IGUIElement *parent) :
	CGUIPanel(environment, parent, id, rect<s32>(0, 0, 100, 100)),
		Attribs(0), Panel(0)
{
	#ifdef _DEBUG
	setDebugName("CGUIAttributeEditor");
	#endif

	// create attributes
	Attribs = environment->getFileSystem()->createEmptyAttributes(Environment->getVideoDriver());

	calculateClientArea();
	resizeInnerPane();

	// refresh attrib list
	refreshAttribs();

	IGUIScrollBar* sb = getVScrollBar();
	core::rect<s32> r = sb->getRelativePosition();
	r.LowerRightCorner.Y -= 16;
	sb->setRelativePosition(r);
}

CGUIAttributeEditor::~CGUIAttributeEditor()
{
	for (u32 i=0; i<AttribList.size(); ++i)
	{
		AttribList[i]->remove();
		AttribList[i]->drop();
	}
	AttribList.clear();

	Attribs->drop();
}


IAttributes* CGUIAttributeEditor::getAttribs()
{
	return Attribs;
}

void CGUIAttributeEditor::refreshAttribs()
{
	// clear the attribute list
	u32 i;
	for (i=0; i<AttribList.size(); ++i)
	{
		AttribList[i]->remove();
		AttribList[i]->drop();
	}
	AttribList.clear();

	position2di top(10, 5);
	rect<s32> r(top.X, top.Y,
			getClientArea().getWidth() - 10,
			5 + Environment->getSkin()->getFont()->getDimension(L"A").Height);

	// add attribute elements
	u32 c = Attribs->getAttributeCount();
	for (i=0; i<c; ++i)
	{

		// try to create attribute
		stringc str = Attribs->getAttributeTypeString(i);
		str += "_attribute";
		CGUIAttribute* n = (CGUIAttribute*)Environment->addGUIElement(str.c_str(), this);

		if (n)
		{
			// add custom attribute editor
			AttribList.push_back(n);
			n->setParentID(getID());
			n->grab();
		}
		else
		{
			// create a generic string editor
			AttribList.push_back(new CGUIStringAttribute(Environment, this, getID()));
			// dont grab it because we created it with new
		}

		AttribList[i]->setSubElement(true);
		AttribList[i]->setRelativePosition(r);
		AttribList[i]->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
		AttribList[i]->setAttrib(Attribs, i);
		r += position2di(0, AttribList[i]->getRelativePosition().getHeight() + 5);
	}
}

void CGUIAttributeEditor::updateAttribs()
{
	for (u32 i=0; i<AttribList.size(); ++i)
		AttribList[i]->updateAttrib(false);
}

} // namespace gui
} // namespace irr