MyGUI
3.2.0
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
6
/*
7
This file is part of MyGUI.
8
9
MyGUI is free software: you can redistribute it and/or modify
10
it under the terms of the GNU Lesser General Public License as published by
11
the Free Software Foundation, either version 3 of the License, or
12
(at your option) any later version.
13
14
MyGUI is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU Lesser General Public License for more details.
18
19
You should have received a copy of the GNU Lesser General Public License
20
along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21
*/
22
#include "
MyGUI_Precompiled.h
"
23
#include "
MyGUI_ResourceManualFont.h
"
24
#include "
MyGUI_SkinManager.h
"
25
#include "
MyGUI_RenderManager.h
"
26
#include "
MyGUI_TextureUtility.h
"
27
28
namespace
MyGUI
29
{
30
31
ResourceManualFont::ResourceManualFont
() :
32
mDefaultHeight(0),
33
mSubstituteGlyphInfo(
nullptr
),
34
mTexture(
nullptr
)
35
{
36
}
37
38
ResourceManualFont::~ResourceManualFont
()
39
{
40
}
41
42
GlyphInfo
*
ResourceManualFont::getGlyphInfo
(
Char
_id)
43
{
44
CharMap::iterator iter = mCharMap.find(_id);
45
46
if
(iter != mCharMap.end())
47
return
&iter->second;
48
49
return
mSubstituteGlyphInfo;
50
}
51
52
void
ResourceManualFont::loadTexture()
53
{
54
if
(mTexture ==
nullptr
)
55
{
56
RenderManager
& render =
RenderManager::getInstance
();
57
mTexture = render.
getTexture
(mSource);
58
if
(mTexture ==
nullptr
)
59
{
60
mTexture = render.
createTexture
(mSource);
61
mTexture->
loadFromFile
(mSource);
62
}
63
}
64
}
65
66
void
ResourceManualFont::deserialization
(
xml::ElementPtr
_node,
Version
_version)
67
{
68
Base::deserialization
(_node, _version);
69
70
xml::ElementEnumerator
node = _node->
getElementEnumerator
();
71
while
(node.
next
())
72
{
73
if
(node->
getName
() ==
"Property"
)
74
{
75
const
std::string& key = node->
findAttribute
(
"key"
);
76
const
std::string& value = node->
findAttribute
(
"value"
);
77
if
(key ==
"Source"
) mSource = value;
78
else
if
(key ==
"DefaultHeight"
) mDefaultHeight =
utility::parseInt
(value);
79
}
80
}
81
82
loadTexture();
83
84
if
(mTexture !=
nullptr
)
85
{
86
int
textureWidth = mTexture->
getWidth
();
87
int
textureHeight = mTexture->
getHeight
();
88
89
node = _node->
getElementEnumerator
();
90
while
(node.
next
())
91
{
92
if
(node->
getName
() ==
"Codes"
)
93
{
94
xml::ElementEnumerator
element = node->
getElementEnumerator
();
95
while
(element.
next
(
"Code"
))
96
{
97
std::string value;
98
// описане глифов
99
if
(element->
findAttribute
(
"index"
, value))
100
{
101
Char
id
= 0;
102
if
(value ==
"cursor"
)
103
id
=
FontCodeType::Cursor
;
104
else
if
(value ==
"selected"
)
105
id
=
FontCodeType::Selected
;
106
else
if
(value ==
"selected_back"
)
107
id
=
FontCodeType::SelectedBack
;
108
else
if
(value ==
"substitute"
)
109
id
=
FontCodeType::NotDefined
;
110
else
111
id
=
utility::parseUInt
(value);
112
113
float
advance(utility::parseValue<float>(element->
findAttribute
(
"advance"
)));
114
FloatPoint
bearing(utility::parseValue<FloatPoint>(element->
findAttribute
(
"bearing"
)));
115
FloatCoord
coord(utility::parseValue<FloatCoord>(element->
findAttribute
(
"coord"
)));
116
117
if
(advance == 0.0f)
118
advance = coord.
width
;
119
120
GlyphInfo
& glyphInfo = mCharMap.insert(CharMap::value_type(
id
,
GlyphInfo
(
121
id
,
122
coord.
width
,
123
coord.
height
,
124
advance,
125
bearing.
left
,
126
bearing.
top
,
127
FloatRect
(
128
coord.
left
/ textureWidth,
129
coord.
top
/ textureHeight,
130
coord.
right
() / textureWidth,
131
coord.
bottom
() / textureHeight)
132
))).first->second;
133
134
if
(
id
==
FontCodeType::NotDefined
)
135
mSubstituteGlyphInfo = &glyphInfo;
136
}
137
}
138
}
139
}
140
}
141
}
142
143
ITexture
*
ResourceManualFont::getTextureFont
()
144
{
145
return
mTexture;
146
}
147
148
int
ResourceManualFont::getDefaultHeight
()
149
{
150
return
mDefaultHeight;
151
}
152
153
}
// namespace MyGUI
MyGUI::types::TCoord< float >
MyGUI_TextureUtility.h
MyGUI::IResource::deserialization
virtual void deserialization(xml::ElementPtr _node, Version _version)
Definition:
MyGUI_IResource.h:61
MyGUI::FontCodeType::SelectedBack
Definition:
MyGUI_FontData.h:45
MyGUI::types::TPoint< float >
MyGUI::utility::parseInt
int parseInt(const std::string &_value)
Definition:
MyGUI_StringUtility.h:181
MyGUI_Precompiled.h
MyGUI::Singleton< RenderManager >::getInstance
static RenderManager & getInstance()
Definition:
MyGUI_Singleton.h:53
MyGUI::RenderManager::getTexture
virtual ITexture * getTexture(const std::string &_name)=0
MyGUI::utility::parseUInt
unsigned int parseUInt(const std::string &_value)
Definition:
MyGUI_StringUtility.h:186
MyGUI::xml::Element::findAttribute
bool findAttribute(const std::string &_name, std::string &_value)
Definition:
MyGUI_XmlDocument.cpp:261
MyGUI_ResourceManualFont.h
MyGUI::ResourceManualFont::getTextureFont
virtual ITexture * getTextureFont()
Definition:
MyGUI_ResourceManualFont.cpp:143
MyGUI::FontCodeType::NotDefined
Definition:
MyGUI_FontData.h:47
nullptr
#define nullptr
Definition:
MyGUI_Prerequest.h:47
MyGUI::types::TPoint::top
T top
Definition:
MyGUI_TPoint.h:36
MyGUI::types::TCoord::width
T width
Definition:
MyGUI_TCoord.h:39
MyGUI::ResourceManualFont::getGlyphInfo
virtual GlyphInfo * getGlyphInfo(Char _id)
Definition:
MyGUI_ResourceManualFont.cpp:42
MyGUI::types::TCoord::top
T top
Definition:
MyGUI_TCoord.h:38
MyGUI::xml::ElementEnumerator
Definition:
MyGUI_XmlDocument.h:124
MyGUI::ResourceManualFont::~ResourceManualFont
virtual ~ResourceManualFont()
Definition:
MyGUI_ResourceManualFont.cpp:38
MyGUI_RenderManager.h
MyGUI::types::TPoint::left
T left
Definition:
MyGUI_TPoint.h:35
MyGUI::xml::ElementEnumerator::next
bool next()
Definition:
MyGUI_XmlDocument.cpp:115
MyGUI::types::TCoord::right
T right() const
Definition:
MyGUI_TCoord.h:165
MyGUI::types::TRect< float >
MyGUI::types::TCoord::bottom
T bottom() const
Definition:
MyGUI_TCoord.h:170
MyGUI::ITexture::getHeight
virtual int getHeight()=0
MyGUI::ITexture
Definition:
MyGUI_ITexture.h:41
MyGUI::Char
unsigned int Char
Definition:
MyGUI_Types.h:66
MyGUI::xml::Element
Definition:
MyGUI_XmlDocument.h:168
MyGUI::ResourceManualFont::deserialization
virtual void deserialization(xml::ElementPtr _node, Version _version)
Definition:
MyGUI_ResourceManualFont.cpp:66
MyGUI::Version
Definition:
MyGUI_Version.h:32
MyGUI::GlyphInfo
Definition:
MyGUI_FontData.h:53
MyGUI::xml::Element::getElementEnumerator
ElementEnumerator getElementEnumerator()
Definition:
MyGUI_XmlDocument.cpp:367
MyGUI::FontCodeType::Cursor
Definition:
MyGUI_FontData.h:46
MyGUI::xml::Element::getName
const std::string & getName() const
Definition:
MyGUI_XmlDocument.cpp:347
MyGUI::ResourceManualFont::ResourceManualFont
ResourceManualFont()
Definition:
MyGUI_ResourceManualFont.cpp:31
MyGUI::types::TCoord::left
T left
Definition:
MyGUI_TCoord.h:37
MyGUI::ITexture::loadFromFile
virtual void loadFromFile(const std::string &_filename)=0
MyGUI::RenderManager::createTexture
virtual ITexture * createTexture(const std::string &_name)=0
MyGUI::RenderManager
Definition:
MyGUI_RenderManager.h:35
MyGUI_SkinManager.h
MyGUI::types::TCoord::height
T height
Definition:
MyGUI_TCoord.h:40
MyGUI::ITexture::getWidth
virtual int getWidth()=0
MyGUI::FontCodeType::Selected
Definition:
MyGUI_FontData.h:44
MyGUI::ResourceManualFont::getDefaultHeight
virtual int getDefaultHeight()
Definition:
MyGUI_ResourceManualFont.cpp:148
Generated on Sat Aug 9 2014 03:01:30 for MyGUI by
1.8.7