1 /*!
2 	@file
3 	@author		Albert Semenov
4 	@date		08/2010
5 */
6 
7 #include "Precompiled.h"
8 #include "TextureToolControl.h"
9 #include "Localise.h"
10 #include "SettingsManager.h"
11 #include "CommandManager.h"
12 
13 namespace tools
14 {
15 
TextureToolControlLE(MyGUI::Widget * _parent)16 	TextureToolControlLE::TextureToolControlLE(MyGUI::Widget* _parent) :
17 		TextureControlLE("TextureControl.layout", _parent),
18 		mCurrentScaleValue(100),
19 		mActivate(true)
20 	{
21 		MyGUI::Colour colour = SettingsManager::getInstance().getValue<MyGUI::Colour>("Workspace/Colours/ColourBackground");
22 		setColour(colour);
23 
24 		CommandManager::getInstance().getEvent("Command_ChangeNextScale")->connect(this, &TextureToolControlLE::CommandChangeNextScale);
25 		CommandManager::getInstance().getEvent("Command_ChangePrevScale")->connect(this, &TextureToolControlLE::CommandChangePrevScale);
26 		CommandManager::getInstance().getEvent("Command_ChangeScale")->connect(this, &TextureToolControlLE::CommandChangeScale);
27 
28 		mScaleValue = SettingsManager::getInstance().getValueList<size_t>("Workspace/TextureScale/ScaleValue.List");
29 
30 		SettingsManager::getInstance().eventSettingsChanged.connect(this, &TextureToolControlLE::notifySettingsChanged);
31 	}
32 
~TextureToolControlLE()33 	TextureToolControlLE::~TextureToolControlLE()
34 	{
35 		SettingsManager::getInstance().eventSettingsChanged.disconnect(this);
36 	}
37 
notifySettingsChanged(const std::string & _path)38 	void TextureToolControlLE::notifySettingsChanged(const std::string& _path)
39 	{
40 		if (_path == "Workspace/Colours/ColourBackground")
41 		{
42 			MyGUI::Colour colour = SettingsManager::getInstance().getValue<MyGUI::Colour>("Workspace/Colours/ColourBackground");
43 			setColour(colour);
44 		}
45 	}
46 
CommandChangeNextScale(const MyGUI::UString & _commandName,bool & _result)47 	void TextureToolControlLE::CommandChangeNextScale(const MyGUI::UString& _commandName, bool& _result)
48 	{
49 		if (!checkCommand())
50 			return;
51 
52 		doNextScale();
53 
54 		_result = true;
55 	}
56 
CommandChangePrevScale(const MyGUI::UString & _commandName,bool & _result)57 	void TextureToolControlLE::CommandChangePrevScale(const MyGUI::UString& _commandName, bool& _result)
58 	{
59 		if (!checkCommand())
60 			return;
61 
62 		doPrevScale();
63 
64 		_result = true;
65 	}
66 
CommandChangeScale(const MyGUI::UString & _commandName,bool & _result)67 	void TextureToolControlLE::CommandChangeScale(const MyGUI::UString& _commandName, bool& _result)
68 	{
69 		if (!checkMenuCommand())
70 			return;
71 
72 		size_t scaleValue = MyGUI::utility::parseValue<size_t>(CommandManager::getInstance().getCommandData());
73 		if (scaleValue == mCurrentScaleValue)
74 			return;
75 
76 		if (std::find(mScaleValue.begin(), mScaleValue.end(), scaleValue) == mScaleValue.end())
77 			return;
78 
79 		mCurrentScaleValue = scaleValue;
80 		setScale((double)mCurrentScaleValue / (double)100);
81 
82 		_result = true;
83 	}
84 
checkMenuCommand()85 	bool TextureToolControlLE::checkMenuCommand()
86 	{
87 		return mActivate &&
88 			!getSelectorsCapture();
89 	}
90 
checkCommand()91 	bool TextureToolControlLE::checkCommand()
92 	{
93 		return mMainWidget->getRootKeyFocus() &&
94 			mActivate &&
95 			!getSelectorsCapture();
96 	}
97 
onMouseWheel(int _rel)98 	void TextureToolControlLE::onMouseWheel(int _rel)
99 	{
100 		if (_rel < 0)
101 			doPrevScale();
102 		else
103 			doNextScale();
104 	}
105 
doPrevScale()106 	bool TextureToolControlLE::doPrevScale()
107 	{
108 		for (VectorSizeT::const_iterator item = mScaleValue.begin(); item != mScaleValue.end(); ++item)
109 		{
110 			if ((*item) == mCurrentScaleValue)
111 			{
112 				if (item != mScaleValue.begin())
113 				{
114 					--item;
115 					mCurrentScaleValue = *item;
116 					setScale((double)mCurrentScaleValue / (double)100);
117 					return true;
118 				}
119 				break;
120 			}
121 		}
122 		return false;
123 	}
124 
doNextScale()125 	bool TextureToolControlLE::doNextScale()
126 	{
127 		for (VectorSizeT::const_iterator item = mScaleValue.begin(); item != mScaleValue.end(); ++item)
128 		{
129 			if ((*item) == mCurrentScaleValue)
130 			{
131 				++item;
132 				if (item != mScaleValue.end())
133 				{
134 					mCurrentScaleValue = *item;
135 					setScale((double)mCurrentScaleValue / (double)100);
136 					return true;
137 				}
138 				break;
139 			}
140 		}
141 		return false;
142 	}
143 
setActivate(bool _value)144 	void TextureToolControlLE::setActivate(bool _value)
145 	{
146 		mActivate = _value;
147 
148 		onChangeActivate();
149 	}
150 
getActivate() const151 	bool TextureToolControlLE::getActivate() const
152 	{
153 		return mActivate;
154 	}
155 
onChangeActivate()156 	void TextureToolControlLE::onChangeActivate()
157 	{
158 	}
159 
160 }
161