3 #include "text_object.h"
5 #include "video/drawing_context.h"
7 TextObject::TextObject()
8 : fading(0), fadetime(0), visible(false)
13 TextObject::~TextObject()
18 TextObject::set_font(const std::string& name)
22 } else if(name == "white") {
24 } else if(name == "blue") {
26 } else if(name == "gray") {
28 } else if(name == "white") {
30 } else if(name == "big") {
31 font = white_big_text;
32 } else if(name == "small") {
33 font = white_small_text;
35 std::cerr << "Unknown font '" << name << "'.\n";
40 TextObject::set_text(const std::string& text)
46 TextObject::fade_in(float fadetime)
48 this->fadetime = fadetime;
53 TextObject::fade_out(float fadetime)
55 this->fadetime = fadetime;
60 TextObject::set_visible(bool visible)
62 this->visible = visible;
67 TextObject::draw(DrawingContext& context)
69 context.push_transform();
70 context.set_translation(Vector(0, 0));
72 context.set_alpha(static_cast<uint8_t>
73 ((fadetime-fading) * 255.0 / fadetime));
74 } else if(fading < 0) {
75 context.set_alpha(static_cast<uint8_t> (-fading * 255.0 / fadetime));
77 context.pop_transform();
81 context.draw_filled_rect(Vector(125, 50), Vector(550, 120),
82 Color(150, 180, 200, 125), LAYER_GUI-50);
83 context.draw_text(font, text, Vector(125+35, 50+35), LEFT_ALLIGN, LAYER_GUI-40);
85 context.pop_transform();
89 TextObject::update(float elapsed_time)
92 fading -= elapsed_time;
97 } else if(fading < 0) {
98 fading += elapsed_time;