-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwxGLString.h
197 lines (156 loc) · 5.93 KB
/
wxGLString.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#ifndef _glstring_
#define _glstring_
#ifdef __WXMAC__
#include "OpenGL/gl.h"
#else
#include <GL/gl.h>
#endif
#include "wx/wx.h"
#include <vector>
class TextTexture;
/** base class for renderable elements. You won't create this one directly,
but may use its public members from wxGLString since it inherits from TextGLDrawable.
This class will be useful if you wish to apply effects to the text like rotation or
scaling. */
class TextGLDrawable
{
friend class wxGLString;
friend class wxGLStringArray;
friend class wxGLStringNumber;
protected:
int x,y, angle;
float xscale, yscale;
TextTexture* image;
bool xflip, yflip;
float tex_coord_x1, tex_coord_y1;
float tex_coord_x2, tex_coord_y2;
int w, h, texw, texh;
TextGLDrawable(TextTexture* image=(TextTexture*)0);
void render();
void setImage(TextTexture* image);
void move(int x, int y);
public:
/** allows you to flip the rendering vertically and/or horizontally */
void setFlip(bool x, bool y);
/** scale the rendering , horizontally and vertically (allows stretching) */
void scale(float x, float y);
/** scale the rendering and keep the same aspect ratio */
void scale(float k);
/** rotate the rendering by 'angle' degrees */
void rotate(int angle);
/** returns the width of this element */
int getWidth() const { return w; }
/** returns the height of this element */
int getheight() const { return h; }
};
class wxGLStringArray;
/** wxGLString is the simplest class you can use. It draws a single string on a single line.
If you plan to render multiple strings, this class is not the fastest.
Use example :
wxGLString my_message(wxT("Hello World"));
...
if(first_render)
my_message.consolidate(&dc);
glColor3f(0,0,0); // black text
my_message.bind();
my_message.render(x, y);
*/
class wxGLString : public wxString, public TextGLDrawable
{
protected:
TextTexture* img;
wxFont font;
friend class wxGLStringArray;
void calculateSize(wxDC* dc, const bool ignore_font=false /* when from array */);
void consolidateFromArray(wxDC* dc, int x, int y);
public:
/** constructs an empty GLString. Set string later with operator=. */
wxGLString();
/** constructs a GLstring with 'message' as contents. */
wxGLString(wxString message);
virtual ~wxGLString();
/** call just before render() - binds the OpenGL. If you render the same string many
times, or render from an array, bind only once, this will improve performance */
void bind();
/** set how to draw string for next consolidate() - has no immediate effect,
you need to call consolidate() to get results */
void setFont(wxFont font);
/** consolidates the current string info into a GL string. call this after
setting up strings, font and color (if necessary), and before rendering.
The wxDC argument is only used to calculate text extents and will not be rendered on. */
virtual void consolidate(wxDC* dc);
/** render this string at coordinates (x,y). Must be called after bind(). */
void render(const int x, const int y);
/** changes the string of this element */
void operator=(wxString& string);
};
/** This class allows rendering numbers.
Use example :
wxGLNumberRenderer glnumbers;
...
if(first_render)
glnumbers.consolidate();
glColor3f(0,0,0); // black numbers
glnumbers.bind();
glnumbers.renderNumber( 3.141593f, x, y );
*/
class wxGLNumberRenderer : public wxGLString
{
int* number_location;
int space_w;
public:
wxGLNumberRenderer();
virtual ~wxGLNumberRenderer();
/** inits the class to be ready to render.
The wxDC argument is only used to calculate text extents and will not be rendered on. */
void consolidate(wxDC* dc);
/** render this number at coordinates (x,y), where wxString s contains the string
representation of a number. Must be called after bind(). */
void renderNumber(wxString s, int x, int y);
/** render this number at coordinates (x,y). Must be called after bind(). */
void renderNumber(int i, int x, int y);
/** render this number at coordinates (x,y). Must be called after bind(). */
void renderNumber(float f, int x, int y);
};
/** This class is useful to render a serie of strings that are usually rendered at the same time.
It behaves exactly like wxGLString but is more efficient.
Use example :
wxGLStringArray my_messages();
my_messages.addString("wxMac");
my_messages.addString("wxGTK");
my_messages.addString("wxMSW");
...
glColor3f(0,0,0); // black text
my_messages.bind();
my_messages.get(0).render( x, y );
my_messages.get(1).render( x, y + 25 );
my_messages.get(2).render( x, y + 50 );
*/
class wxGLStringArray
{
std::vector<wxGLString> strings;
TextTexture* img;
wxFont font;
public:
/** constructs an empty array - add elements later using addString */
wxGLStringArray();
/** construct an array with 'strings_arg' elemnts in it */
wxGLStringArray(const wxString strings_arg[], int amount);
~wxGLStringArray();
/** get a sub-element - useful mainly for rendering, e.g. my_array.get(0).render(x, y); */
wxGLString& get(const int id);
/** call just before render() - binds the OpenGL. If you render the same string many
times, or render from an array, bind only once, this will improve performance */
void bind();
/** add a string to the list for next consolidate() - has no
immediate effect, you need to call consolidate() to get results */
void addString(wxString string);
/** set how to draw string for next consolidate() - has no immediate effect,
you need to call consolidate() to get results */
void setFont(wxFont font);
/** consolidates the current string info into a GL string. call this after
setting up strings, font and color (if necessary), and before rendering.
The wxDC argument is only used to calculate text extents and will not be rendered on. */
void consolidate(wxDC* dc);
};
#endif