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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/*!
@file
@author Albert Semenov
@date 08/2010
*/
#include "Precompiled.h"
#include "TextureToolControl.h"
#include "Localise.h"
#include "SettingsManager.h"
#include "CommandManager.h"
namespace tools
{
TextureToolControl::TextureToolControl() :
mCurrentScaleValue(100)
{
}
TextureToolControl::~TextureToolControl()
{
SettingsManager::getInstance().eventSettingsChanged.disconnect(this);
}
void TextureToolControl::OnInitialise(Control* _parent, MyGUI::Widget* _place, const std::string& _layoutName)
{
TextureControl::OnInitialise(_parent, _place, "TextureControl.layout");
mColourValueName = "ColourBackground";
MyGUI::Colour colour = SettingsManager::getInstance().getValue<MyGUI::Colour>("Workspace/Colours/" + mColourValueName);
setColour(colour);
CommandManager::getInstance().getEvent("Command_ChangeNextScale")->connect(this, &TextureToolControl::CommandChangeNextScale);
CommandManager::getInstance().getEvent("Command_ChangePrevScale")->connect(this, &TextureToolControl::CommandChangePrevScale);
CommandManager::getInstance().getEvent("Command_ChangeScale")->connect(this, &TextureToolControl::CommandChangeScale);
mScaleValue = SettingsManager::getInstance().getValueList<size_t>("Workspace/TextureScale/ScaleValue.List");
SettingsManager::getInstance().eventSettingsChanged.connect(this, &TextureToolControl::notifySettingsChanged);
}
void TextureToolControl::notifySettingsChanged(const std::string& _path)
{
if (_path == ("Workspace/Colours/" + mColourValueName))
{
MyGUI::Colour colour = SettingsManager::getInstance().getValue<MyGUI::Colour>("Workspace/Colours/" + mColourValueName);
setColour(colour);
}
}
void TextureToolControl::CommandChangeNextScale(const MyGUI::UString& _commandName, bool& _result)
{
if (!checkCommand())
return;
doNextScale();
_result = true;
}
void TextureToolControl::CommandChangePrevScale(const MyGUI::UString& _commandName, bool& _result)
{
if (!checkCommand())
return;
doPrevScale();
_result = true;
}
void TextureToolControl::CommandChangeScale(const MyGUI::UString& _commandName, bool& _result)
{
if (!checkMenuCommand())
return;
size_t scaleValue = MyGUI::utility::parseValue<size_t>(CommandManager::getInstance().getCommandData());
if (scaleValue == mCurrentScaleValue)
return;
if (std::find(mScaleValue.begin(), mScaleValue.end(), scaleValue) == mScaleValue.end())
return;
mCurrentScaleValue = scaleValue;
setScale((double)mCurrentScaleValue / (double)100);
_result = true;
}
bool TextureToolControl::checkMenuCommand()
{
return !getSelectorsCapture();
}
bool TextureToolControl::checkCommand()
{
return mMainWidget->getRootKeyFocus() &&
!getSelectorsCapture();
}
void TextureToolControl::onMouseWheel(int _rel)
{
if (_rel < 0)
doPrevScale();
else
doNextScale();
}
bool TextureToolControl::doPrevScale()
{
for (VectorSizeT::const_iterator item = mScaleValue.begin(); item != mScaleValue.end(); ++item)
{
if ((*item) == mCurrentScaleValue)
{
if (item != mScaleValue.begin())
{
--item;
mCurrentScaleValue = *item;
setScale((double)mCurrentScaleValue / (double)100);
return true;
}
break;
}
}
return false;
}
bool TextureToolControl::doNextScale()
{
for (VectorSizeT::const_iterator item = mScaleValue.begin(); item != mScaleValue.end(); ++item)
{
if ((*item) == mCurrentScaleValue)
{
++item;
if (item != mScaleValue.end())
{
mCurrentScaleValue = *item;
setScale((double)mCurrentScaleValue / (double)100);
return true;
}
break;
}
}
return false;
}
}
|