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 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/*!
@file
@author Albert Semenov
@date 07/2012
*/
#include "Precompiled.h"
#include "GroupTextureController.h"
#include "FactoryManager.h"
#include "DataSelectorManager.h"
#include "DataManager.h"
#include "PropertyUtility.h"
#include "ScopeManager.h"
#include "DataUtility.h"
namespace tools
{
FACTORY_ITEM_ATTRIBUTE(GroupTextureController)
GroupTextureController::GroupTextureController() :
mControl(nullptr),
mParentData(nullptr),
mActivated(false)
{
}
GroupTextureController::~GroupTextureController()
{
}
void GroupTextureController::setTarget(Control* _control)
{
mControl = _control->findControl<ScopeTextureControl>();
}
void GroupTextureController::activate()
{
mParentTypeName = "Image";
mScopeName = "Group";
ScopeManager::getInstance().eventChangeScope.connect(this, &GroupTextureController::notifyChangeScope);
notifyChangeScope(ScopeManager::getInstance().getCurrentScope());
}
void GroupTextureController::deactivate()
{
ScopeManager::getInstance().eventChangeScope.disconnect(this);
}
void GroupTextureController::notifyChangeDataSelector(DataPtr _data, bool _changeOnlySelection)
{
mParentData = _data;
if (mParentData != nullptr && mParentData->getType()->getName() != mParentTypeName)
mParentData = nullptr;
std::string texture;
PropertyPtr property = PropertyUtility::getPropertyByName("Group", "Texture");
if (property != nullptr)
{
texture = property->getValue();
if (!property->eventChangeProperty.exist(this, &GroupTextureController::notifyChangeProperty))
property->eventChangeProperty.connect(this, &GroupTextureController::notifyChangeProperty);
}
std::string coord;
property = PropertyUtility::getPropertyByName("Group", "Size");
if (property != nullptr)
{
coord = property->getValue();
if (!property->eventChangeProperty.exist(this, &GroupTextureController::notifyChangeProperty))
property->eventChangeProperty.connect(this, &GroupTextureController::notifyChangeProperty);
}
mControl->setTextureValue(texture);
updateCoords(coord);
}
void GroupTextureController::notifyChangeProperty(PropertyPtr _sender)
{
if (!mActivated || !PropertyUtility::isDataSelected(_sender->getOwner()))
return;
if (_sender->getOwner()->getType()->getName() == "Group")
{
if (_sender->getType()->getName() == "Texture")
mControl->setTextureValue(_sender->getValue());
else if (_sender->getType()->getName() == "Size")
updateCoords(_sender->getValue());
}
}
void GroupTextureController::notifyChangeValue(const std::string& _value)
{
PropertyPtr property = PropertyUtility::getPropertyByName("Group", "Size");
if (property != nullptr)
PropertyUtility::executeAction(property, _value, true);
}
void GroupTextureController::notifyChangeScope(const std::string& _scope)
{
if (mControl == nullptr)
return;
if (_scope == mScopeName)
{
if (!mActivated)
{
mControl->eventChangeValue.connect(this, &GroupTextureController::notifyChangeValue);
mControl->clearAll();
DataSelectorManager::getInstance().getEvent(mParentTypeName)->connect(this, &GroupTextureController::notifyChangeDataSelector);
mParentData = DataUtility::getSelectedDataByType(mParentTypeName);
notifyChangeDataSelector(mParentData, false);
mControl->getRoot()->setUserString("CurrentScopeController", mScopeName);
mActivated = true;
}
}
else
{
if (mActivated)
{
mControl->eventChangeValue.disconnect(this);
DataSelectorManager::getInstance().getEvent(mParentTypeName)->disconnect(this);
mParentData = nullptr;
//
std::string value = mControl->getRoot()->getUserString("CurrentScopeController");
if (value == mScopeName)
{
mControl->getRoot()->setUserString("CurrentScopeController", "");
notifyChangeDataSelector(mParentData, false);
mControl->clearAll();
}
mActivated = false;
}
}
}
void GroupTextureController::updateCoords(const std::string& _value)
{
MyGUI::IntCoord coord;
if (MyGUI::utility::parseComplex(_value, coord.left, coord.top, coord.width, coord.height))
{
mControl->setCoordValue(coord, ScopeTextureControl::SelectorCoord);
}
else
{
mControl->clearCoordValue();
}
}
}
|