1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
4
5 #include "CDefaultGUIElementFactory.h"
6
7 #ifdef _IRR_COMPILE_WITH_GUI_
8
9 #include "IGUIEnvironment.h"
10
11 #include "IGUIButton.h"
12 #include "IGUICheckBox.h"
13 #include "IGUIColorSelectDialog.h"
14 #include "IGUIComboBox.h"
15 #include "IGUIContextMenu.h"
16 #include "IGUIEditBox.h"
17 #include "IGUIFileOpenDialog.h"
18 #include "IGUIInOutFader.h"
19 #include "IGUIImage.h"
20 #include "IGUIListBox.h"
21 #include "IGUIMeshViewer.h"
22 #include "IGUIScrollBar.h"
23 #include "IGUISpinBox.h"
24 #include "IGUIStaticText.h"
25 #include "IGUITabControl.h"
26 #include "IGUITable.h"
27 #include "IGUIToolbar.h"
28 #include "IGUIWindow.h"
29 #include "IGUITreeView.h"
30
31 namespace irr
32 {
33 namespace gui
34 {
35
CDefaultGUIElementFactory(IGUIEnvironment * env)36 CDefaultGUIElementFactory::CDefaultGUIElementFactory(IGUIEnvironment* env)
37 : Environment(env)
38 {
39
40 #ifdef _DEBUG
41 setDebugName("CDefaultGUIElementFactory");
42 #endif
43
44 // don't grab the gui environment here to prevent cyclic references
45 }
46
47
48 //! adds an element to the env based on its type id
addGUIElement(EGUI_ELEMENT_TYPE type,IGUIElement * parent)49 IGUIElement* CDefaultGUIElementFactory::addGUIElement(EGUI_ELEMENT_TYPE type, IGUIElement* parent)
50 {
51 switch(type)
52 {
53 case EGUIET_BUTTON:
54 return Environment->addButton(core::rect<s32>(0,0,100,100),parent);
55 case EGUIET_CHECK_BOX:
56 return Environment->addCheckBox(false, core::rect<s32>(0,0,100,100), parent);
57 case EGUIET_COLOR_SELECT_DIALOG:
58 return Environment->addColorSelectDialog(0,true,parent);
59 case EGUIET_COMBO_BOX:
60 return Environment->addComboBox(core::rect<s32>(0,0,100,100),parent);
61 case EGUIET_CONTEXT_MENU:
62 return Environment->addContextMenu(core::rect<s32>(0,0,100,100),parent);
63 case EGUIET_MENU:
64 return Environment->addMenu(parent);
65 case EGUIET_EDIT_BOX:
66 return Environment->addEditBox(0,core::rect<s32>(0,0,100,100),true, parent);
67 case EGUIET_FILE_OPEN_DIALOG:
68 return Environment->addFileOpenDialog(0,true,parent);
69 case EGUIET_IMAGE:
70 return Environment->addImage(0,core::position2di(0,0), true, parent);
71 case EGUIET_IN_OUT_FADER:
72 return Environment->addInOutFader(0,parent);
73 case EGUIET_LIST_BOX:
74 return Environment->addListBox(core::rect<s32>(0,0,100,100),parent);
75 case EGUIET_MESH_VIEWER:
76 return Environment->addMeshViewer(core::rect<s32>(0,0,100,100),parent);
77 case EGUIET_MODAL_SCREEN:
78 return Environment->addModalScreen(parent);
79 case EGUIET_MESSAGE_BOX:
80 return Environment->addMessageBox(0,0,false,0,parent);
81 case EGUIET_SCROLL_BAR:
82 return Environment->addScrollBar(false,core::rect<s32>(0,0,100,100),parent);
83 case EGUIET_STATIC_TEXT:
84 return Environment->addStaticText(0,core::rect<s32>(0,0,100,100),false,true,parent);
85 case EGUIET_TAB:
86 return Environment->addTab(core::rect<s32>(0,0,100,100),parent);
87 case EGUIET_TAB_CONTROL:
88 return Environment->addTabControl(core::rect<s32>(0,0,100,100),parent);
89 case EGUIET_TABLE:
90 return Environment->addTable(core::rect<s32>(0,0,100,100), parent);
91 case EGUIET_TOOL_BAR:
92 return Environment->addToolBar(parent);
93 case EGUIET_WINDOW:
94 return Environment->addWindow(core::rect<s32>(0,0,100,100),false,0,parent);
95 case EGUIET_SPIN_BOX:
96 return Environment->addSpinBox(L"0.0", core::rect<s32>(0,0,100,100), true, parent);
97 case EGUIET_TREE_VIEW:
98 return Environment->addTreeView(core::rect<s32>(0,0,100,100),parent);
99 default:
100 return 0;
101 }
102 }
103
104
105 //! adds an element to the environment based on its type name
addGUIElement(const c8 * typeName,IGUIElement * parent)106 IGUIElement* CDefaultGUIElementFactory::addGUIElement(const c8* typeName, IGUIElement* parent)
107 {
108 return addGUIElement( getTypeFromName(typeName), parent );
109 }
110
111
112 //! Returns the amount of element types this factory is able to create.
getCreatableGUIElementTypeCount() const113 s32 CDefaultGUIElementFactory::getCreatableGUIElementTypeCount() const
114 {
115 return EGUIET_COUNT;
116 }
117
118
119 //! Returns the type of a createable element type.
getCreateableGUIElementType(s32 idx) const120 EGUI_ELEMENT_TYPE CDefaultGUIElementFactory::getCreateableGUIElementType(s32 idx) const
121 {
122 if (idx>=0 && idx<EGUIET_COUNT)
123 return (EGUI_ELEMENT_TYPE)idx;
124
125 return EGUIET_ELEMENT;
126 }
127
128
129 //! Returns the type name of a createable element type.
getCreateableGUIElementTypeName(s32 idx) const130 const c8* CDefaultGUIElementFactory::getCreateableGUIElementTypeName(s32 idx) const
131 {
132 if (idx>=0 && idx<EGUIET_COUNT)
133 return GUIElementTypeNames[idx];
134
135 return 0;
136 }
137
138
139 //! Returns the type name of a createable element type.
getCreateableGUIElementTypeName(EGUI_ELEMENT_TYPE type) const140 const c8* CDefaultGUIElementFactory::getCreateableGUIElementTypeName(EGUI_ELEMENT_TYPE type) const
141 {
142 // for this factory, type == index
143
144 if (type>=0 && type<EGUIET_COUNT)
145 return GUIElementTypeNames[type];
146
147 return 0;
148 }
149
getTypeFromName(const c8 * name) const150 EGUI_ELEMENT_TYPE CDefaultGUIElementFactory::getTypeFromName(const c8* name) const
151 {
152 for ( u32 i=0; GUIElementTypeNames[i]; ++i)
153 if (!strcmp(name, GUIElementTypeNames[i]) )
154 return (EGUI_ELEMENT_TYPE)i;
155
156 return EGUIET_ELEMENT;
157 }
158
159
160 } // end namespace gui
161 } // end namespace irr
162
163 #endif // _IRR_COMPILE_WITH_GUI_
164
165