3 #include "text_object.hpp"
6 #include "resources.hpp"
7 #include "video/drawing_context.hpp"
9 TextObject::TextObject()
10 : fading(0), fadetime(0), visible(false)
16 TextObject::~TextObject()
21 TextObject::set_font(const std::string& name)
25 } else if(name == "white") {
27 } else if(name == "blue") {
29 } else if(name == "gray") {
31 } else if(name == "big") {
32 font = white_big_text;
33 } else if(name == "small") {
34 font = white_small_text;
36 std::cerr << "Unknown font '" << name << "'.\n";
41 TextObject::set_text(const std::string& text)
47 TextObject::fade_in(float fadetime)
49 this->fadetime = fadetime;
54 TextObject::fade_out(float fadetime)
56 this->fadetime = fadetime;
61 TextObject::set_visible(bool visible)
63 this->visible = visible;
68 TextObject::set_centered(bool centered)
70 this->centered = centered;
74 TextObject::draw(DrawingContext& context)
76 context.push_transform();
77 context.set_translation(Vector(0, 0));
79 context.set_alpha((fadetime-fading) / fadetime);
80 } else if(fading < 0) {
81 context.set_alpha(-fading / fadetime);
83 context.pop_transform();
87 context.draw_filled_rect(Vector(125, 50), Vector(550, 120),
88 Color(0.6, 0.7, 0.8, 0.5), LAYER_GUI-50);
90 context.draw_center_text(font, text, Vector(0, 50+35), LAYER_GUI-40);
92 else context.draw_text(font, text, Vector(125+35, 50+35), LEFT_ALLIGN, LAYER_GUI-40);
94 context.pop_transform();
98 TextObject::update(float elapsed_time)
101 fading -= elapsed_time;
106 } else if(fading < 0) {
107 fading += elapsed_time;