-
Notifications
You must be signed in to change notification settings - Fork 0
/
Textbox.cpp
65 lines (57 loc) · 1.69 KB
/
Textbox.cpp
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
#include "Textbox.h"
#include "textlib/textlib.h"
namespace anengine
{
PropertyInfo Textbox::ColorProperty("Color", typeid(Textbox));
PropertyInfo Textbox::TextProperty("Text", typeid(Textbox));
Textbox::TextlibInit Textbox::myTexlibInit;
Textbox::TextlibInit::TextlibInit()
{
Debug("Textlib init");
textlib_initialize();
textlib_set_font(72, NULL);
textlib_set_quality(TEXT_QUALITY_HIGH);
}
Textbox::TextlibInit::~TextlibInit()
{
Debug("Textlib quit");
textlib_quit();
}
void Textbox::OnPropertyChanged(const PropertyInfo *id, bool implicit)
{
if(id == &TextProperty || id == &ColorProperty)
{
//Debug("Change text");
if(IsCreated())
UpdateText();
}
GUISprite::OnPropertyChanged(id, implicit);
}
void Textbox::OnCreate()
{
myTexture = Scene.Get()->GetAssetManager()->CreateFromMemory<Texture>("");
UpdateText();
SetTexture(myTexture);
GUISprite::OnCreate();
}
void Textbox::OnDestroy()
{
myTexture.Release();
GUISprite::OnDestroy();
}
void Textbox::UpdateText()
{
ColorRGBA c = Color.Get();
Visible.Set(!Text.Get().empty());
if(Visible.Get())
{
SDL_Surface *text = textlib_get_text(Text.Get().c_str(), c[R],c[G],c[B]);
SDL_LockSurface(text);
myTexture->SetData(text->w, text->h, GL_BGRA, text->pixels);
real height = Size.Get()[Height];
Size.Set(SizeF2(text->w * height / text->h, height));
SDL_UnlockSurface(text);
SDL_FreeSurface(text);
}
}
};