~ubuntu-branches/ubuntu/vivid/mygui/vivid

« back to all changes in this revision

Viewing changes to Tools/SkinEditor/StateTextureController.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Howard, Bret Curtis, Scott Howard
  • Date: 2014-09-18 17:57:48 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20140918175748-dd8va78mvpw1jbes
Tags: 3.2.1-1
[ Bret Curtis ]
* Updated license for majority of files from LGPL to Expat (MIT)

[ Scott Howard ]
* New upstream release
* Updated patch to add build option for system GLEW libraries
* All patches accepted upstream except shared_libraries.patch
* Bumped SONAME due to dropped symbols, updated *.symbols and package
  names
* Updated license of debian/* to Expat with permission of all authors
* Don't install Doxygen autogenerated md5 and map files (thanks
  lintian)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*!
 
2
        @file
 
3
        @author         Albert Semenov
 
4
        @date           07/2012
 
5
*/
 
6
 
 
7
#include "Precompiled.h"
 
8
#include "StateTextureController.h"
 
9
#include "FactoryManager.h"
 
10
#include "DataSelectorManager.h"
 
11
#include "DataManager.h"
 
12
#include "PropertyUtility.h"
 
13
#include "ScopeManager.h"
 
14
#include "DataUtility.h"
 
15
 
 
16
namespace tools
 
17
{
 
18
 
 
19
        FACTORY_ITEM_ATTRIBUTE(StateTextureController)
 
20
 
 
21
        StateTextureController::StateTextureController() :
 
22
                mControl(nullptr),
 
23
                mParentData(nullptr),
 
24
                mActivated(false)
 
25
        {
 
26
        }
 
27
 
 
28
        StateTextureController::~StateTextureController()
 
29
        {
 
30
        }
 
31
 
 
32
        void StateTextureController::setTarget(Control* _control)
 
33
        {
 
34
                mControl = _control->findControl<ScopeTextureControl>();
 
35
        }
 
36
 
 
37
        void StateTextureController::activate()
 
38
        {
 
39
                mParentTypeName = "Skin";
 
40
                mThisType = "State";
 
41
                mScopeName = "State";
 
42
 
 
43
                ScopeManager::getInstance().eventChangeScope.connect(this, &StateTextureController::notifyChangeScope);
 
44
                notifyChangeScope(ScopeManager::getInstance().getCurrentScope());
 
45
        }
 
46
 
 
47
        void StateTextureController::deactivate()
 
48
        {
 
49
                ScopeManager::getInstance().eventChangeScope.disconnect(this);
 
50
        }
 
51
 
 
52
        void StateTextureController::notifyChangeDataSelector(DataPtr _data, bool _changeOnlySelection)
 
53
        {
 
54
                mParentData = _data;
 
55
                if (mParentData != nullptr && mParentData->getType()->getName() != mParentTypeName)
 
56
                        mParentData = nullptr;
 
57
 
 
58
                std::string texture;
 
59
                PropertyPtr property = PropertyUtility::getPropertyByName("Skin", "Texture");
 
60
                if (property != nullptr)
 
61
                {
 
62
                        texture = property->getValue();
 
63
 
 
64
                        if (!property->eventChangeProperty.exist(this, &StateTextureController::notifyChangeProperty))
 
65
                                property->eventChangeProperty.connect(this, &StateTextureController::notifyChangeProperty);
 
66
                }
 
67
 
 
68
                std::string coord;
 
69
                property = PropertyUtility::getPropertyByName("Skin", "Size");
 
70
                if (property != nullptr)
 
71
                {
 
72
                        coord = property->getValue();
 
73
 
 
74
                        if (!property->eventChangeProperty.exist(this, &StateTextureController::notifyChangeProperty))
 
75
                                property->eventChangeProperty.connect(this, &StateTextureController::notifyChangeProperty);
 
76
                }
 
77
 
 
78
                if (mParentData != nullptr)
 
79
                {
 
80
                        for (Data::VectorData::const_iterator child = mParentData->getChilds().begin(); child != mParentData->getChilds().end(); child ++)
 
81
                        {
 
82
                                if ((*child)->getType()->getName() != mThisType)
 
83
                                        continue;
 
84
 
 
85
                                property = (*child)->getProperty("Point");
 
86
                                if (!property->eventChangeProperty.exist(this, &StateTextureController::notifyChangeProperty))
 
87
                                        property->eventChangeProperty.connect(this, &StateTextureController::notifyChangeProperty);
 
88
 
 
89
                                property = (*child)->getProperty("Visible");
 
90
                                if (!property->eventChangeProperty.exist(this, &StateTextureController::notifyChangeProperty))
 
91
                                        property->eventChangeProperty.connect(this, &StateTextureController::notifyChangeProperty);
 
92
                        }
 
93
                }
 
94
 
 
95
                updateTexture(texture);
 
96
                updateCoords(coord);
 
97
        }
 
98
 
 
99
        void StateTextureController::notifyChangeProperty(PropertyPtr _sender)
 
100
        {
 
101
                if (!mActivated)
 
102
                        return;
 
103
 
 
104
                if (_sender->getOwner()->getType()->getName() == "Skin")
 
105
                {
 
106
                        if (_sender->getType()->getName() == "Texture")
 
107
                                updateTexture(_sender->getValue());
 
108
                        else if (_sender->getType()->getName() == "Size")
 
109
                                updateCoords(_sender->getValue());
 
110
                }
 
111
                else if (_sender->getOwner()->getType()->getName() == "State")
 
112
                {
 
113
                        if (_sender->getType()->getName() == "Point")
 
114
                                updateFrames();
 
115
                        else if (_sender->getType()->getName() == "Visible")
 
116
                                updateFrames();
 
117
                }
 
118
        }
 
119
 
 
120
        void StateTextureController::notifyChangeValue(const std::string& _value)
 
121
        {
 
122
                if (mParentData != nullptr)
 
123
                {
 
124
                        DataPtr selected = mParentData->getChildSelected();
 
125
                        if (selected != nullptr && selected->getType()->getName() == "State")
 
126
                        {
 
127
                                MyGUI::IntCoord coord = MyGUI::IntCoord::parse(_value);
 
128
                                PropertyPtr property = selected->getProperty("Point");
 
129
                                PropertyUtility::executeAction(property, coord.point().print(), true);
 
130
                        }
 
131
                }
 
132
        }
 
133
 
 
134
        void StateTextureController::notifyChangeScope(const std::string& _scope)
 
135
        {
 
136
                if (mControl == nullptr)
 
137
                        return;
 
138
 
 
139
                if (_scope == mScopeName)
 
140
                {
 
141
                        if (!mActivated)
 
142
                        {
 
143
                                mControl->eventChangeValue.connect(this, &StateTextureController::notifyChangeValue);
 
144
                                mControl->clearAll();
 
145
 
 
146
                                DataSelectorManager::getInstance().getEvent(mParentTypeName)->connect(this, &StateTextureController::notifyChangeDataSelector);
 
147
                                mParentData = DataUtility::getSelectedDataByType(mParentTypeName);
 
148
                                notifyChangeDataSelector(mParentData, false);
 
149
 
 
150
                                mControl->getRoot()->setUserString("CurrentScopeController", mScopeName);
 
151
 
 
152
                                mActivated = true;
 
153
                        }
 
154
                }
 
155
                else
 
156
                {
 
157
                        if (mActivated)
 
158
                        {
 
159
                                mControl->eventChangeValue.disconnect(this);
 
160
 
 
161
                                DataSelectorManager::getInstance().getEvent(mParentTypeName)->disconnect(this);
 
162
                                mParentData = nullptr;
 
163
 
 
164
                                // �� ��� ��������� �������� ���������� ���
 
165
                                std::string value = mControl->getRoot()->getUserString("CurrentScopeController");
 
166
                                if (value == mScopeName)
 
167
                                {
 
168
                                        mControl->getRoot()->setUserString("CurrentScopeController", "");
 
169
                                        notifyChangeDataSelector(mParentData, false);
 
170
 
 
171
                                        mControl->clearAll();
 
172
                                }
 
173
 
 
174
                                mActivated = false;
 
175
                        }
 
176
                }
 
177
        }
 
178
 
 
179
        void StateTextureController::updateCoords(const std::string& _value)
 
180
        {
 
181
                MyGUI::IntCoord coord;
 
182
                if (MyGUI::utility::parseComplex(_value, coord.left, coord.top, coord.width, coord.height))
 
183
                        mSize = coord.size();
 
184
                else
 
185
                        mSize.clear();
 
186
 
 
187
                updateFrames();
 
188
        }
 
189
 
 
190
        void StateTextureController::updateFrames()
 
191
        {
 
192
                mFrames.clear();
 
193
 
 
194
                if (mParentData != nullptr)
 
195
                {
 
196
                        DataPtr selected = mParentData->getChildSelected();
 
197
                        for (Data::VectorData::const_iterator child = mParentData->getChilds().begin(); child != mParentData->getChilds().end(); child ++)
 
198
                        {
 
199
                                if ((*child)->getType()->getName() != mThisType)
 
200
                                        continue;
 
201
 
 
202
                                bool visible = (*child)->getPropertyValue<bool>("Visible");
 
203
                                MyGUI::IntPoint value = (*child)->getPropertyValue<MyGUI::IntPoint>("Point");
 
204
 
 
205
                                if (selected == *child)
 
206
                                {
 
207
                                        if (visible)
 
208
                                                mControl->setCoordValue(MyGUI::IntCoord(value, mSize), ScopeTextureControl::SelectorPosition);
 
209
                                        else
 
210
                                                mControl->clearCoordValue();
 
211
                                }
 
212
                                else
 
213
                                {
 
214
                                        if (visible)
 
215
                                                mFrames.push_back(std::make_pair(MyGUI::IntCoord(value, mSize), ScopeTextureControl::SelectorPosition));
 
216
                                }
 
217
                        }
 
218
 
 
219
                        if (selected == nullptr)
 
220
                        {
 
221
                                mControl->clearCoordValue();
 
222
                        }
 
223
                }
 
224
 
 
225
                if (mControl != nullptr)
 
226
                        mControl->setViewSelectors(mFrames);
 
227
        }
 
228
 
 
229
        void StateTextureController::updateTexture(const std::string& _value)
 
230
        {
 
231
                mControl->setTextureValue(_value);
 
232
                mControl->resetTextureRegion();
 
233
        }
 
234
 
 
235
}