File: PropertyFieldManager.cpp

package info (click to toggle)
mygui 3.2.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 36,224 kB
  • sloc: cpp: 118,031; ansic: 30,202; xml: 15,544; cs: 12,602; tcl: 776; python: 417; makefile: 34
file content (95 lines) | stat: -rw-r--r-- 3,471 bytes parent folder | download | duplicates (4)
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
/*!
	@file
	@author		Albert Semenov
	@date		08/2010
*/

#include "Precompiled.h"
#include "PropertyFieldManager.h"
#include "PropertyFieldComboBox.h"
#include "PropertyFieldEditBox.h"
#include "PropertyFieldSkin.h"
#include "PropertyFieldType.h"
#include "PropertyFieldFont.h"
#include "PropertyFieldFileName.h"
#include "PropertyFieldNumeric.h"
#include "PropertyFieldAlpha.h"
#include "PropertyFieldPosition.h"
#include "PropertyFieldColour.h"

template <> tools::PropertyFieldManager* MyGUI::Singleton<tools::PropertyFieldManager>::msInstance = nullptr;
template <> const char* MyGUI::Singleton<tools::PropertyFieldManager>::mClassTypeName = "PropertyFieldManager";

namespace tools
{

	template <typename Type>
	class GenericFactory
	{
	public:
		typedef MyGUI::delegates::CDelegate2<IPropertyField*&, MyGUI::Widget*> Delegate;
		static typename Delegate::IDelegate* getFactory()
		{
			return MyGUI::newDelegate(createFromFactory);
		}

	private:
		static void createFromFactory(IPropertyField*& _instance, MyGUI::Widget* _parent)
		{
			_instance = new Type(_parent);
		}
	};

	PropertyFieldManager::PropertyFieldManager()
	{
	}

	PropertyFieldManager::~PropertyFieldManager()
	{
	}

	void PropertyFieldManager::initialise()
	{
		mFactories["Name"] = GenericFactory<PropertyFieldEditBox>::getFactory();
		mFactories["Type"] = GenericFactory<PropertyFieldType>::getFactory();
		mFactories["Skin"] = GenericFactory<PropertyFieldSkin>::getFactory();
		mFactories["Font"] = GenericFactory<PropertyFieldFont>::getFactory();
		mFactories["Position"] = GenericFactory<PropertyFieldPosition>::getFactory();
		mFactories["Layer"] = GenericFactory<PropertyFieldComboBox>::getFactory();
		mFactories["String"] = GenericFactory<PropertyFieldEditBox>::getFactory();
		mFactories["Align"] = GenericFactory<PropertyFieldComboBox>::getFactory();
		mFactories["FileName"] = GenericFactory<PropertyFieldFileName>::getFactory();
		mFactories["1 int"] = GenericFactory<PropertyFieldNumeric>::getFactory();
		mFactories["2 int"] = GenericFactory<PropertyFieldNumeric>::getFactory();
		mFactories["4 int"] = GenericFactory<PropertyFieldNumeric>::getFactory();
		mFactories["1 float"] = GenericFactory<PropertyFieldNumeric>::getFactory();
		mFactories["2 float"] = GenericFactory<PropertyFieldNumeric>::getFactory();
		mFactories["Alpha"] = GenericFactory<PropertyFieldAlpha>::getFactory();
		mFactories["Colour"] = GenericFactory<PropertyFieldColour>::getFactory();
		mFactories["Bool"] = GenericFactory<PropertyFieldComboBox>::getFactory();
		mFactories["TextAlign"] = GenericFactory<PropertyFieldComboBox>::getFactory();
		mFactories["FlowDirection"] = GenericFactory<PropertyFieldComboBox>::getFactory();
		mFactories["CanvasAlign"] = GenericFactory<PropertyFieldComboBox>::getFactory();
		mFactories["MenuItemType"] = GenericFactory<PropertyFieldComboBox>::getFactory();
		mFactories["ItemResizingPolicy"] = GenericFactory<PropertyFieldComboBox>::getFactory();
		mFactories["Function"] = GenericFactory<PropertyFieldComboBox>::getFactory();
	}

	void PropertyFieldManager::shutdown()
	{
	}

	IPropertyField* PropertyFieldManager::createPropertyField(MyGUI::Widget* _window, const std::string& _type)
	{
		IPropertyField* result = nullptr;

		MapFactoryItem::iterator item = mFactories.find(_type);
		MYGUI_ASSERT(item != mFactories.end(), "Factory PropertyField '" << _type << "' not found.");

		(*item).second(result, _window);
		result->initialise(_type);

		return result;
	}

}