-
Notifications
You must be signed in to change notification settings - Fork 5
/
TextBox.h
86 lines (79 loc) · 2.09 KB
/
TextBox.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
#pragma once
#include "Prop2D.h"
#include "Font.h"
#if !defined(__linux__)
#include "freetype-gl/vertex-buffer.h"
#endif
class TextBox : public Prop2D {
public:
wchar_t *str;
Font *font;
int len_str;
Mesh *mesh;
TrackerTextBox *tracker;
bool skip_meshing; // true for repreproxy
TextBox() : str(NULL), font(0), len_str(0), mesh(NULL), tracker(0), skip_meshing(false) {
setScl(1,1);
}
~TextBox() {
if(mesh) {
mesh->deleteBuffers();
delete mesh;
}
if(tracker) delete tracker;
}
inline void setFont( Font *f ){
assert(f);
font = f;
}
void render(Camera *cam, DrawBatchList *bl );
inline void setString( const char *s ){
setString( (char*) s );
}
inline void setString( char *u8s ){
int l = strlen(u8s);
wchar_t *out = (wchar_t*)MALLOC((l+1)*sizeof(wchar_t));
mbstowcs(out, u8s, l+1 );
setString(out);
FREE(out);
}
inline void setString( const wchar_t *s ){
setString( (wchar_t*)s );
}
inline void setString( wchar_t *s ){
size_t l = wcslen(s);
if(str){
FREE(str);
}
str = (wchar_t*)MALLOC( (l+1) * sizeof(wchar_t) );
wcscpy( str, s );
assert( wcslen(str) == wcslen(s) );
len_str = l;
clearMesh();
if(!skip_meshing) updateMesh();
}
bool compareString( const char *u8s ) {
int l = strlen(u8s);
wchar_t *out = (wchar_t*)MALLOC((l+1)*sizeof(wchar_t));
mbstowcs(out, u8s, l+1 );
int ret = wcscmp( str, out );
FREE(out);
// print("compareString: %d '%S' '%S'",ret, str, out );
return ret == 0;
}
int getStringLength() { return len_str; }
void clearMesh() {
if(mesh) {
mesh->deleteBuffers();
delete mesh;
mesh = NULL;
}
}
void updateMesh();
virtual void onTrack( RemoteHead *rh, Prop2D *parentprop );
virtual void onColorChanged() {
clearMesh();
if(!skip_meshing) updateMesh();
}
static void drawToDBL( Layer *l, DrawBatchList *bl, bool additiveblend, Font *font, const char *s, Color col, Vec2 loc, float scl, float rot );
};