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