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

« back to all changes in this revision

Viewing changes to Tools/FontEditor/FontTextureController.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 "FontTextureController.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
#include "CommandManager.h"
 
16
#include <MyGUI_ResourceTrueTypeFont.h>
 
17
#include "FontExportSerializer.h"
 
18
 
 
19
namespace tools
 
20
{
 
21
 
 
22
        FACTORY_ITEM_ATTRIBUTE(FontTextureController)
 
23
 
 
24
        FontTextureController::FontTextureController() :
 
25
                mControl(nullptr),
 
26
                mParentData(nullptr),
 
27
                mActivated(false)
 
28
        {
 
29
        }
 
30
 
 
31
        FontTextureController::~FontTextureController()
 
32
        {
 
33
        }
 
34
 
 
35
        void FontTextureController::setTarget(Control* _control)
 
36
        {
 
37
                mControl = _control->findControl<ScopeTextureControl>();
 
38
        }
 
39
 
 
40
        void FontTextureController::activate()
 
41
        {
 
42
                mParentTypeName = "Root";
 
43
                mScopeName = "Font";
 
44
 
 
45
                ScopeManager::getInstance().eventChangeScope.connect(this, &FontTextureController::notifyChangeScope);
 
46
                notifyChangeScope(ScopeManager::getInstance().getCurrentScope());
 
47
 
 
48
                CommandManager::getInstance().getEvent("Command_GenerateFont")->connect(this, &FontTextureController::commandGenerateFont);
 
49
        }
 
50
 
 
51
        void FontTextureController::deactivate()
 
52
        {
 
53
                ScopeManager::getInstance().eventChangeScope.disconnect(this);
 
54
                CommandManager::getInstance().getEvent("Command_GenerateFont")->disconnect(this);
 
55
        }
 
56
 
 
57
        void FontTextureController::notifyChangeDataSelector(DataPtr _data, bool _changeOnlySelection)
 
58
        {
 
59
                mParentData = _data;
 
60
                if (mParentData != nullptr && mParentData->getType()->getName() != mParentTypeName)
 
61
                        mParentData = nullptr;
 
62
 
 
63
                std::string texture;
 
64
                PropertyPtr property = PropertyUtility::getPropertyByName("Font", "FontName");
 
65
                if (property != nullptr)
 
66
                {
 
67
                        texture = property->getValue();
 
68
                }
 
69
 
 
70
                updateTexture(texture);
 
71
        }
 
72
 
 
73
        void FontTextureController::notifyChangeProperty(PropertyPtr _sender)
 
74
        {
 
75
                if (!mActivated || !PropertyUtility::isDataSelected(_sender->getOwner()))
 
76
                        return;
 
77
 
 
78
                if (_sender->getOwner()->getType()->getName() == "Font")
 
79
                {
 
80
                        if (_sender->getType()->getName() == "FontName")
 
81
                                updateTexture(_sender->getValue());
 
82
                }
 
83
        }
 
84
 
 
85
        void FontTextureController::notifyChangeScope(const std::string& _scope)
 
86
        {
 
87
                if (mControl == nullptr)
 
88
                        return;
 
89
 
 
90
                if (_scope == mScopeName)
 
91
                {
 
92
                        if (!mActivated)
 
93
                        {
 
94
                                mControl->clearAll();
 
95
 
 
96
                                DataSelectorManager::getInstance().getEvent(mParentTypeName)->connect(this, &FontTextureController::notifyChangeDataSelector);
 
97
                                mParentData = DataUtility::getSelectedDataByType(mParentTypeName);
 
98
                                notifyChangeDataSelector(mParentData, false);
 
99
 
 
100
                                mControl->getRoot()->setUserString("CurrentScopeController", mScopeName);
 
101
 
 
102
                                mActivated = true;
 
103
                        }
 
104
                }
 
105
                else
 
106
                {
 
107
                        if (mActivated)
 
108
                        {
 
109
                                DataSelectorManager::getInstance().getEvent(mParentTypeName)->disconnect(this);
 
110
                                mParentData = nullptr;
 
111
 
 
112
                                // �� ��� ��������� �������� ���������� ���
 
113
                                std::string value = mControl->getRoot()->getUserString("CurrentScopeController");
 
114
                                if (value == mScopeName)
 
115
                                {
 
116
                                        mControl->getRoot()->setUserString("CurrentScopeController", "");
 
117
                                        notifyChangeDataSelector(mParentData, false);
 
118
 
 
119
                                        mControl->clearAll();
 
120
                                }
 
121
 
 
122
                                mActivated = false;
 
123
                        }
 
124
                }
 
125
        }
 
126
 
 
127
        void FontTextureController::updateTexture(const std::string& _value)
 
128
        {
 
129
                MyGUI::IResource* resource = MyGUI::ResourceManager::getInstance().findByName(_value);
 
130
                MyGUI::ResourceTrueTypeFont* font = resource != nullptr ? resource->castType<MyGUI::ResourceTrueTypeFont>(false) : nullptr;
 
131
                
 
132
                MyGUI::ITexture* texture = font != nullptr ? font->getTextureFont() : nullptr;
 
133
                std::string value = texture != nullptr ? texture->getName() : "";
 
134
 
 
135
                mControl->setTextureValue(value);
 
136
                mControl->resetTextureRegion();
 
137
        }
 
138
 
 
139
        void FontTextureController::commandGenerateFont(const MyGUI::UString& _commandName, bool& _result)
 
140
        {
 
141
                if (mParentData != nullptr)
 
142
                {
 
143
                        DataPtr font = (mParentData != nullptr) ? mParentData->getChildSelected() : nullptr;
 
144
                        if (font != nullptr)
 
145
                        {
 
146
                                FontExportSerializer::generateFont(font);
 
147
                                notifyChangeDataSelector(mParentData, false);
 
148
                                updateResultPropery(font);
 
149
 
 
150
                                CommandManager::getInstance().executeCommand("Command_OnGenerateFont");
 
151
                        }
 
152
                }
 
153
        }
 
154
 
 
155
        void FontTextureController::updateResultPropery(DataPtr _data)
 
156
        {
 
157
                MyGUI::IResource* resource = MyGUI::ResourceManager::getInstance().findByName(_data->getPropertyValue("FontName"));
 
158
                MyGUI::ResourceTrueTypeFont* font = resource != nullptr ? resource->castType<MyGUI::ResourceTrueTypeFont>(false) : nullptr;
 
159
                MyGUI::ITexture* texture = font != nullptr ? font->getTextureFont() : nullptr;
 
160
 
 
161
                if (texture != nullptr)
 
162
                        _data->setPropertyValue("TextureSizeResult", MyGUI::utility::toString(texture->getWidth(), " ", texture->getHeight()));
 
163
                else
 
164
                        _data->setPropertyValue("TextureSizeResult", "0 0");
 
165
 
 
166
                if (font != nullptr)
 
167
                        _data->setPropertyValue("FontHeightPix", font->getDefaultHeight());
 
168
                else
 
169
                        _data->setPropertyValue("FontHeightPix", "0");
 
170
        }
 
171
 
 
172
}