Oxygine  1
2g game engine
Font.h
1 #pragma once
2 #include "oxygine-include.h"
3 #include "core/Object.h"
4 #include "math/Rect.h"
5 #ifdef __S3E__
6 #include <set>
7 #else
8 #include <unordered_set>
9 #endif
10 
11 namespace oxygine
12 {
13  struct glyph
14  {
15  RectF src;
16 
17  int ch;
18  glyphOptions opt;
19 
20  short sw;
21  short sh;
22 
23  short offset_x;
24  short offset_y;
25 
26  short advance_x;
27  short advance_y;
28 
29  spNativeTexture texture;
30 
31  bool operator == (const glyph& r) const {return ch == r.ch && opt == r.opt;}
32 #ifdef __S3E__
33  bool operator < (const glyph& r) const { return ch < r.ch; }
34 #endif
35  };
36 
37  struct GlyphHasher
38  {
39  std::size_t operator()(const glyph& k) const
40  {
41  return std::hash<int>()(k.ch + k.opt);
42  }
43  };
44 
45 
46  class Font: public ObjectBase
47  {
48  public:
49  Font();
50  ~Font();
51 
52  void init(const char* name, int size, int baselineDistance, int lineHeight, bool sdf = false);
53 
54  void addGlyph(const glyph& g);
55  void sortGlyphs() {}
56 
57  void setScale(float scale) { _scale = scale; }
58  void setBaselineDistance(int d) { _baselineDistance = d; }
59 
60  const glyph* getGlyph(int code, const glyphOptions& opt) const;
61  int getBaselineDistance() const;
62  int getSize() const;
63  float getScale() const;
64  bool isSDF() const;
65 
66  protected:
67  const glyph* findGlyph(int code, const glyphOptions& opt) const;
68 
69  virtual bool loadGlyph(int code, glyph&, const glyphOptions& opt) { return false; }
70 
71 #ifdef __S3E__
72  typedef std::set<glyph> glyphs;
73 #else
74  typedef std::unordered_set<glyph, GlyphHasher> glyphs;
75 #endif
76  glyphs _glyphs;
77  bool _ignoreOptions;
78 
79  float _scale;
80  bool _sdf;
81 
82  int _size;
83  int _baselineDistance;
84  };
85 }
Definition: Font.h:37
Definition: Object.h:19
–oxgl-end–!
Definition: Actor.h:14
Definition: Font.h:46