MyGUI 3.4.3
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"
9#include "MyGUI_SkinManager.h"
10#include "MyGUI_RenderManager.h"
12
13namespace MyGUI
14{
15
17 {
18 CharMap::const_iterator iter = mCharMap.find(_id);
19
20 if (iter != mCharMap.end())
21 return &iter->second;
22
23 return mSubstituteGlyphInfo;
24 }
25
26 void ResourceManualFont::loadTexture()
27 {
28 if (mTexture == nullptr)
29 {
31 mTexture = render.getTexture(mSource);
32 if (mTexture == nullptr)
33 {
34 mTexture = render.createTexture(mSource);
35 if (mTexture != nullptr)
36 mTexture->loadFromFile(mSource);
37 }
38 }
39 }
40
42 {
43 Base::deserialization(_node, _version);
44
46 while (node.next())
47 {
48 if (node->getName() == "Property")
49 {
50 std::string_view key = node->findAttribute("key");
51 std::string_view value = node->findAttribute("value");
52 if (key == "Source")
53 mSource = value;
54 else if (key == "DefaultHeight")
55 mDefaultHeight = utility::parseInt(value);
56 else if (key == "Shader")
57 mShader = value;
58 }
59 }
60
61 loadTexture();
62
63 if (mTexture != nullptr)
64 {
65 if (!mShader.empty())
66 mTexture->setShader(mShader);
67 int textureWidth = mTexture->getWidth();
68 int textureHeight = mTexture->getHeight();
69
70 node = _node->getElementEnumerator();
71 while (node.next())
72 {
73 if (node->getName() == "Codes")
74 {
76 while (element.next("Code"))
77 {
78 std::string value;
79 // описане глифов
80 if (element->findAttribute("index", value))
81 {
82 Char id = 0;
83 if (value == "cursor")
84 id = static_cast<Char>(FontCodeType::Cursor);
85 else if (value == "selected")
86 id = static_cast<Char>(FontCodeType::Selected);
87 else if (value == "selected_back")
88 id = static_cast<Char>(FontCodeType::SelectedBack);
89 else if (value == "substitute")
90 id = static_cast<Char>(FontCodeType::NotDefined);
91 else
92 id = utility::parseUInt(value);
93
94 float advance(utility::parseValue<float>(element->findAttribute("advance")));
95 FloatPoint bearing(utility::parseValue<FloatPoint>(element->findAttribute("bearing")));
96
97 // texture coordinates
99
100 // glyph size, default to texture coordinate size
101 std::string sizeString;
102 FloatSize size(coord.width, coord.height);
103 if (element->findAttribute("size", sizeString))
104 {
105 size = utility::parseValue<FloatSize>(sizeString);
106 }
107
108 if (advance == 0.0f)
109 advance = size.width;
110
111 mCharMap.emplace(
112 id,
113 GlyphInfo{
114 id,
115 size.width,
116 size.height,
117 advance,
118 bearing.left,
119 bearing.top,
120 FloatRect{
121 coord.left / textureWidth,
122 coord.top / textureHeight,
123 coord.right() / textureWidth,
124 coord.bottom() / textureHeight}});
125
126 if (id == FontCodeType::NotDefined)
127 mSubstituteGlyphInfo = &mCharMap.at(FontCodeType::NotDefined);
128 }
129 }
130 }
131 }
132 }
133 }
134
136 {
137 return mTexture;
138 }
139
141 {
142 return mDefaultHeight;
143 }
144
145 void ResourceManualFont::setSource(std::string_view value)
146 {
147 mTexture = nullptr;
148 mSource = value;
149 loadTexture();
150 }
151
152 void ResourceManualFont::setShader(std::string_view value)
153 {
154 mShader = value;
155 if (mTexture != nullptr)
156 mTexture->setShader(mShader);
157 }
158
160 {
161 mTexture = texture;
162 mSource.clear();
163 }
164
166 {
167 mDefaultHeight = value;
168 }
169
171 {
172 GlyphInfo& inserted = mCharMap.insert(CharMap::value_type(id, info)).first->second;
173
174 if (id == FontCodeType::NotDefined)
175 mSubstituteGlyphInfo = &inserted;
176 }
177
178} // namespace MyGUI
virtual void setShader(const std::string &_shaderName)=0
virtual int getWidth() const =0
virtual void loadFromFile(const std::string &_filename)=0
virtual int getHeight() const =0
virtual ITexture * getTexture(const std::string &_name)=0
virtual ITexture * createTexture(const std::string &_name)=0
static RenderManager & getInstance()
ITexture * getTextureFont() const override
void addGlyphInfo(Char id, const GlyphInfo &info)
void setSource(std::string_view value)
void setShader(std::string_view value)
const GlyphInfo * getGlyphInfo(Char _id) const override
void setTexture(MyGUI::ITexture *texture)
void deserialization(xml::ElementPtr _node, Version _version) override
bool findAttribute(std::string_view _name, std::string &_value)
ElementEnumerator getElementEnumerator()
const std::string & getName() const
unsigned int parseUInt(std::string_view _value)
T parseValue(std::string_view _value)
int parseInt(std::string_view _value)
unsigned int Char
Definition MyGUI_Types.h:50