blob: 3be24440db09000abc522445284cf4b810a52b95 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
#include "textureFont.h"
using namespace Graphics;
TextureFont::TextureFont(const sf::Texture &texture,
TextureFont::Descr description)
: tex_(texture)
, description_(description)
{
sf::Vector2u totalSize = tex_.getSize();
glyphSize_ = sf::Vector2i( totalSize.x / description_.numcols,
totalSize.y / description_.numrows );
for(unsigned int i=0; i<description.mapping.size(); i++){
sf::Glyph glyph;
glyph.advance = glyphSize_.x;
unsigned int x = i % description_.numcols;
unsigned int y = (i - x) / description_.numcols;
glyph.textureRect = sf::IntRect(x*glyphSize_.x,
y*glyphSize_.y,
glyphSize_.x,
glyphSize_.y);
glyph.bounds = sf::FloatRect(0,
0,
glyphSize_.x,
glyphSize_.y);
glyphTable_.insert(std::make_pair(description.mapping[i], glyph));
}
}
const sf::Glyph & TextureFont::getGlyph(char ch) const{
auto pair = glyphTable_.find(ch);
return pair->second;
}
const sf::Texture * TextureFont::getTexture(unsigned int _){
return &tex_;
}
|