OpenCPN Partial API docs
Loading...
Searching...
No Matches
pi_tex_font.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2014 Sean D'Epagnier *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#ifndef TexFONT_H__
25#define TexFONT_H__
26
27#include <wx/font.h>
28#include <wx/string.h>
29
30/* support ascii plus degree symbol for now pack font in a single texture 16x8
31 */
32#define DEGREE_GLYPH 127
33#define MIN_GLYPH 32
34#define MAX_GLYPH 128
35
36#define NUM_GLYPHS (MAX_GLYPH - MIN_GLYPH)
37
38#define COLS_GLYPHS 16
39#define ROWS_GLYPHS ((NUM_GLYPHS / COLS_GLYPHS) + 1)
40
41#ifndef DECL_EXP
42#ifdef __WXMSW__
43#define DECL_EXP __declspec(dllexport)
44#else
45#define DECL_EXP
46#endif
47#endif
48
49struct TexGlyphInfo {
50 int x, y, width, height;
51 float advance;
52};
53
54class DECL_EXP TexFont {
55public:
56 TexFont();
57 ~TexFont();
58
59 void Build(wxFont &font, bool blur = false);
60 void Delete();
61
62 void GetTextExtent(const wxString &string, int *width, int *height);
63 void RenderString(const char *string, int x = 0, int y = 0);
64 void RenderString(const wxString &string, int x = 0, int y = 0);
65 bool IsBuilt() { return m_built; }
66
67private:
68 void GetTextExtent(const char *string, int *width, int *height);
69 void RenderGlyph(int c);
70
71 wxFont m_font;
72 bool m_blur;
73
74 TexGlyphInfo tgi[MAX_GLYPH];
75
76 unsigned int texobj;
77 int tex_w, tex_h;
78 int m_maxglyphw;
79 int m_maxglyphh;
80 bool m_built;
81
82 float m_dx;
83 float m_dy;
84};
85#endif // TexFONT_H__