-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTextDisplay.h
66 lines (54 loc) · 1.43 KB
/
TextDisplay.h
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#pragma once
#include "Image.h"
#include "utils.h"
class Renderer;
class StyleManager;
class BitmapFont {
public:
BitmapFont(Renderer& renderer);
~BitmapFont();
NO_MOVE_NO_COPY(BitmapFont);
void displayText(const char* text, COLORREF color, int x, int y);
private:
Renderer& renderer;
GLuint glDisplayList = 0;
};
class TextDisplay {
Renderer& renderer;
StyleManager& styleManager;
wil::com_ptr<IDWriteFactory> writeFactory;
wil::com_ptr<IDWriteGdiInterop> gdiInterop;
wil::com_ptr<ID2D1Factory> d2Factory;
wil::com_ptr<IWICImagingFactory> wicFactory;
public:
enum HAlignment {
left,
center,
right,
};
enum VAlignment {
top,
middle,
bottom,
};
explicit TextDisplay(Renderer& renderer, StyleManager& styleManager);
void displayText(const std::string& text, std::vector<size_t> highlight, int x, int y);
void clearCache();
private:
struct DisplayTexture {
std::string text;
std::vector<size_t> highlight;
unsigned int age = 0;
GLTexture glTex;
int texWidth = 0;
int texHeight = 0;
int centerX = 0;
int centerY = 0;
};
const DisplayTexture& getTexture(const std::string& text,
const std::vector<size_t>& highlight);
DisplayTexture createTexture(const std::string& text,
const std::vector<size_t>& highlight);
static const int cache_size = 10;
std::vector<DisplayTexture> texCache;
};