MyGUI
3.4.2
Main Page
Related Pages
Namespaces
Data Structures
Files
Examples
File List
Globals
MyGUIEngine
src
MyGUI_ResourceManualFont.cpp
Go to the documentation of this file.
1
/*
2
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
3
* Distributed under the MIT License
4
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5
*/
6
7
#include "
MyGUI_Precompiled.h
"
8
#include "
MyGUI_ResourceManualFont.h
"
9
#include "
MyGUI_SkinManager.h
"
10
#include "
MyGUI_RenderManager.h
"
11
#include "
MyGUI_TextureUtility.h
"
12
13
namespace
MyGUI
14
{
15
16
ResourceManualFont::ResourceManualFont
() :
17
mDefaultHeight(0),
18
mSubstituteGlyphInfo(
nullptr
),
19
mTexture(
nullptr
)
20
{
21
}
22
23
const
GlyphInfo
*
ResourceManualFont::getGlyphInfo
(
Char
_id
)
const
24
{
25
CharMap::const_iterator
iter
= mCharMap.find(
_id
);
26
27
if
(
iter
!= mCharMap.end())
28
return
&
iter
->second;
29
30
return
mSubstituteGlyphInfo;
31
}
32
33
void
ResourceManualFont::loadTexture()
34
{
35
if
(mTexture ==
nullptr
)
36
{
37
RenderManager
&
render
=
RenderManager::getInstance
();
38
mTexture =
render
.getTexture(mSource);
39
if
(mTexture ==
nullptr
)
40
{
41
mTexture =
render
.createTexture(mSource);
42
if
(mTexture !=
nullptr
)
43
mTexture->
loadFromFile
(mSource);
44
}
45
}
46
}
47
48
void
ResourceManualFont::deserialization
(
xml::ElementPtr
_node
,
Version
_version
)
49
{
50
Base::deserialization
(
_node
,
_version
);
51
52
xml::ElementEnumerator
node
=
_node
->getElementEnumerator();
53
while
(
node
.
next
())
54
{
55
if
(
node
->getName() ==
"Property"
)
56
{
57
const
std::string& key =
node
->findAttribute(
"key"
);
58
const
std::string& value =
node
->findAttribute(
"value"
);
59
if
(key ==
"Source"
) mSource = value;
60
else
if
(key ==
"DefaultHeight"
) mDefaultHeight =
utility::parseInt
(value);
61
else
if
(key ==
"Shader"
) mShader = value;
62
}
63
}
64
65
loadTexture();
66
67
if
(mTexture !=
nullptr
)
68
{
69
if
(!mShader.empty())
70
mTexture->
setShader
(mShader);
71
int
textureWidth
= mTexture->
getWidth
();
72
int
textureHeight
= mTexture->
getHeight
();
73
74
node
=
_node
->getElementEnumerator();
75
while
(
node
.
next
())
76
{
77
if
(
node
->getName() ==
"Codes"
)
78
{
79
xml::ElementEnumerator
element
=
node
->getElementEnumerator();
80
while
(
element
.
next
(
"Code"
))
81
{
82
std::string value;
83
// описане глифов
84
if
(
element
->findAttribute(
"index"
, value))
85
{
86
Char
id
= 0;
87
if
(value ==
"cursor"
)
88
id
=
static_cast<
Char
>
(
FontCodeType::Cursor
);
89
else
if
(value ==
"selected"
)
90
id
=
static_cast<
Char
>
(
FontCodeType::Selected
);
91
else
if
(value ==
"selected_back"
)
92
id
=
static_cast<
Char
>
(
FontCodeType::SelectedBack
);
93
else
if
(value ==
"substitute"
)
94
id
=
static_cast<
Char
>
(
FontCodeType::NotDefined
);
95
else
96
id
=
utility::parseUInt
(value);
97
98
float
advance(utility::parseValue<float>(
element
->findAttribute(
"advance"
)));
99
FloatPoint
bearing
(utility::parseValue<FloatPoint>(
element
->findAttribute(
"bearing"
)));
100
101
// texture coordinates
102
FloatCoord
coord(utility::parseValue<FloatCoord>(
element
->findAttribute(
"coord"
)));
103
104
// glyph size, default to texture coordinate size
105
std::string
sizeString
;
106
FloatSize
size(coord.
width
, coord.
height
);
107
if
(
element
->findAttribute(
"size"
,
sizeString
))
108
{
109
size = utility::parseValue<FloatSize>(
sizeString
);
110
}
111
112
if
(advance == 0.0f)
113
advance = size.
width
;
114
115
GlyphInfo
&
glyphInfo
= mCharMap.insert(CharMap::value_type(
id
,
GlyphInfo
(
116
id
,
117
size.
width
,
118
size.
height
,
119
advance,
120
bearing
.left,
121
bearing
.top,
122
FloatRect
(
123
coord.
left
/
textureWidth
,
124
coord.
top
/
textureHeight
,
125
coord.
right
() /
textureWidth
,
126
coord.
bottom
() /
textureHeight
)
127
))).first->second;
128
129
if
(
id
==
FontCodeType::NotDefined
)
130
mSubstituteGlyphInfo = &
glyphInfo
;
131
}
132
}
133
}
134
}
135
}
136
}
137
138
ITexture
*
ResourceManualFont::getTextureFont
()
const
139
{
140
return
mTexture;
141
}
142
143
int
ResourceManualFont::getDefaultHeight
()
const
144
{
145
return
mDefaultHeight;
146
}
147
148
void
ResourceManualFont::setSource
(
const
std::string& value)
149
{
150
mTexture =
nullptr
;
151
mSource = value;
152
loadTexture();
153
}
154
155
void
ResourceManualFont::setShader
(
const
std::string& value)
156
{
157
mShader = value;
158
if
(mTexture !=
nullptr
)
159
mTexture->
setShader
(mShader);
160
}
161
162
void
ResourceManualFont::setTexture
(
ITexture
*texture)
163
{
164
mTexture = texture;
165
mSource.clear();
166
}
167
168
void
ResourceManualFont::setDefaultHeight
(
int
value)
169
{
170
mDefaultHeight = value;
171
}
172
173
void
ResourceManualFont::addGlyphInfo
(
Char
id
,
const
GlyphInfo
&
info
)
174
{
175
GlyphInfo
&
inserted
= mCharMap.insert(CharMap::value_type(
id
,
info
)).first->second;
176
177
if
(
id
==
FontCodeType::NotDefined
)
178
mSubstituteGlyphInfo = &
inserted
;
179
}
180
181
}
// namespace MyGUI
MyGUI_Precompiled.h
MyGUI_RenderManager.h
MyGUI_ResourceManualFont.h
MyGUI_SkinManager.h
MyGUI_TextureUtility.h
MyGUI::Enumerator
Definition
MyGUI_Enumerator.h:49
MyGUI::Enumerator::next
bool next()
Definition
MyGUI_Enumerator.h:70
MyGUI::ITexture
Definition
MyGUI_ITexture.h:28
MyGUI::ITexture::setShader
virtual void setShader(const std::string &_shaderName)=0
MyGUI::ITexture::getWidth
virtual int getWidth() const =0
MyGUI::ITexture::loadFromFile
virtual void loadFromFile(const std::string &_filename)=0
MyGUI::ITexture::getHeight
virtual int getHeight() const =0
MyGUI::RenderManager
Definition
MyGUI_RenderManager.h:21
MyGUI::RenderManager::getInstance
static RenderManager & getInstance()
MyGUI::ResourceManualFont::getTextureFont
ITexture * getTextureFont() const override
Definition
MyGUI_ResourceManualFont.cpp:138
MyGUI::ResourceManualFont::setShader
void setShader(const std::string &value)
Definition
MyGUI_ResourceManualFont.cpp:155
MyGUI::ResourceManualFont::addGlyphInfo
void addGlyphInfo(Char id, const GlyphInfo &info)
Definition
MyGUI_ResourceManualFont.cpp:173
MyGUI::ResourceManualFont::setSource
void setSource(const std::string &value)
Definition
MyGUI_ResourceManualFont.cpp:148
MyGUI::ResourceManualFont::ResourceManualFont
ResourceManualFont()
Definition
MyGUI_ResourceManualFont.cpp:16
MyGUI::ResourceManualFont::setDefaultHeight
void setDefaultHeight(int value)
Definition
MyGUI_ResourceManualFont.cpp:168
MyGUI::ResourceManualFont::getDefaultHeight
int getDefaultHeight() const override
Definition
MyGUI_ResourceManualFont.cpp:143
MyGUI::ResourceManualFont::getGlyphInfo
const GlyphInfo * getGlyphInfo(Char _id) const override
Definition
MyGUI_ResourceManualFont.cpp:23
MyGUI::ResourceManualFont::setTexture
void setTexture(MyGUI::ITexture *texture)
Definition
MyGUI_ResourceManualFont.cpp:162
MyGUI::ResourceManualFont::deserialization
void deserialization(xml::ElementPtr _node, Version _version) override
Definition
MyGUI_ResourceManualFont.cpp:48
MyGUI::Version
Definition
MyGUI_Version.h:18
MyGUI::xml::ElementEnumerator
Definition
MyGUI_XmlDocument.h:115
MyGUI::xml::Element
Definition
MyGUI_XmlDocument.h:159
MyGUI::FontCodeType::Selected
@ Selected
Definition
MyGUI_FontData.h:30
MyGUI::FontCodeType::NotDefined
@ NotDefined
Definition
MyGUI_FontData.h:33
MyGUI::FontCodeType::Cursor
@ Cursor
Definition
MyGUI_FontData.h:32
MyGUI::FontCodeType::SelectedBack
@ SelectedBack
Definition
MyGUI_FontData.h:31
MyGUI::utility::parseInt
int parseInt(const std::string &_value)
Definition
MyGUI_StringUtility.h:164
MyGUI::utility::parseUInt
unsigned int parseUInt(const std::string &_value)
Definition
MyGUI_StringUtility.h:169
MyGUI
Definition
MyGUI_ActionController.h:15
MyGUI::Char
unsigned int Char
Definition
MyGUI_Types.h:50
MyGUI::GlyphInfo
Definition
MyGUI_FontData.h:40
MyGUI::types::TCoord< float >
MyGUI::types::TCoord::height
T height
Definition
MyGUI_TCoord.h:25
MyGUI::types::TCoord::right
T right() const
Definition
MyGUI_TCoord.h:150
MyGUI::types::TCoord::width
T width
Definition
MyGUI_TCoord.h:24
MyGUI::types::TCoord::top
T top
Definition
MyGUI_TCoord.h:23
MyGUI::types::TCoord::left
T left
Definition
MyGUI_TCoord.h:22
MyGUI::types::TCoord::bottom
T bottom() const
Definition
MyGUI_TCoord.h:155
MyGUI::types::TPoint< float >
MyGUI::types::TRect< float >
MyGUI::types::TSize
Definition
MyGUI_TSize.h:19
MyGUI::types::TSize::width
T width
Definition
MyGUI_TSize.h:20
MyGUI::types::TSize::height
T height
Definition
MyGUI_TSize.h:21
Generated by
1.9.8