1 /*!
2 	@file
3 	@author		Albert Semenov
4 	@date		09/2010
5 */
6 
7 #include "Precompiled.h"
8 #include "ColourManager.h"
9 #include "CommandManager.h"
10 #include "SettingsManager.h"
11 
12 template <> tools::ColourManager* MyGUI::Singleton<tools::ColourManager>::msInstance = nullptr;
13 template <> const char* MyGUI::Singleton<tools::ColourManager>::mClassTypeName = "ColourManager";
14 
15 namespace tools
16 {
17 
ColourManager()18 	ColourManager::ColourManager() :
19 		mColourPanel(nullptr)
20 	{
21 		CommandManager::getInstance().getEvent("Command_ChangeColourBackground")->connect(this, &ColourManager::commandChangeColourBackground);
22 		CommandManager::getInstance().getEvent("Command_ChangeColourSelector")->connect(this, &ColourManager::commandChangeColourSelector);
23 		CommandManager::getInstance().getEvent("Command_ChangeColourSelectorInactive")->connect(this, &ColourManager::commandChangeColourSelectorInactive);
24 	}
25 
initialise()26 	void ColourManager::initialise()
27 	{
28 		mColourPanel = new ColourPanel();
29 		mColourPanel->Initialise();
30 		mColourPanel->eventEndDialog.connect(this, &ColourManager::notifyEndDialog);
31 		mColourPanel->eventPreviewColour.connect(this, &ColourManager::notifyPreviewColour);
32 	}
33 
shutdown()34 	void ColourManager::shutdown()
35 	{
36 		delete mColourPanel;
37 		mColourPanel = nullptr;
38 	}
39 
commandChangeColourBackground(const MyGUI::UString & _commandName,bool & _result)40 	void ColourManager::commandChangeColourBackground(const MyGUI::UString& _commandName, bool& _result)
41 	{
42 		mCurrentColourType = "ColourBackground";
43 		showColourDialog();
44 
45 		_result = true;
46 	}
47 
commandChangeColourSelector(const MyGUI::UString & _commandName,bool & _result)48 	void ColourManager::commandChangeColourSelector(const MyGUI::UString& _commandName, bool& _result)
49 	{
50 		mCurrentColourType = "ColourSelector";
51 		showColourDialog();
52 
53 		_result = true;
54 	}
55 
commandChangeColourSelectorInactive(const MyGUI::UString & _commandName,bool & _result)56 	void ColourManager::commandChangeColourSelectorInactive(const MyGUI::UString& _commandName, bool& _result)
57 	{
58 		mCurrentColourType = "ColourSelectorInactive";
59 		showColourDialog();
60 
61 		_result = true;
62 	}
63 
notifyEndDialog(Dialog * _sender,bool _result)64 	void ColourManager::notifyEndDialog(Dialog* _sender, bool _result)
65 	{
66 		mColourPanel->endModal();
67 
68 		if (_result)
69 			setColour(mColourPanel->getColour());
70 		else
71 			setColour(mPreviewColour);
72 	}
73 
notifyPreviewColour(const MyGUI::Colour & _value)74 	void ColourManager::notifyPreviewColour(const MyGUI::Colour& _value)
75 	{
76 		setColour(_value);
77 	}
78 
showColourDialog()79 	void ColourManager::showColourDialog()
80 	{
81 		mPreviewColour = getColour();
82 		mColourPanel->setColour(mPreviewColour);
83 		mColourPanel->doModal();
84 	}
85 
setColour(const MyGUI::Colour & _color)86 	void ColourManager::setColour(const MyGUI::Colour& _color)
87 	{
88 		SettingsManager::getInstance().setValue("Workspace/Colours/" + mCurrentColourType, _color);
89 	}
90 
getColour()91 	MyGUI::Colour ColourManager::getColour()
92 	{
93 		return SettingsManager::getInstance().getValue<MyGUI::Colour>("Workspace/Colours/" + mCurrentColourType);
94 	}
95 
96 }
97