3 #include "text_object.hpp"
6 #include "resources.hpp"
7 #include "video/drawing_context.hpp"
10 TextObject::TextObject()
11 : fading(0), fadetime(0), visible(false)
17 TextObject::~TextObject()
22 TextObject::set_font(const std::string& name)
26 } else if(name == "white") {
28 } else if(name == "blue") {
30 } else if(name == "gray") {
32 } else if(name == "big") {
33 font = white_big_text;
34 } else if(name == "small") {
35 font = white_small_text;
37 msg_warning << "Unknown font '" << name << "'." << std::endl;
42 TextObject::set_text(const std::string& text)
48 TextObject::fade_in(float fadetime)
50 this->fadetime = fadetime;
55 TextObject::fade_out(float fadetime)
57 this->fadetime = fadetime;
62 TextObject::set_visible(bool visible)
64 this->visible = visible;
69 TextObject::set_centered(bool centered)
71 this->centered = centered;
75 TextObject::draw(DrawingContext& context)
77 context.push_transform();
78 context.set_translation(Vector(0, 0));
80 context.set_alpha((fadetime-fading) / fadetime);
81 } else if(fading < 0) {
82 context.set_alpha(-fading / fadetime);
84 context.pop_transform();
88 context.draw_filled_rect(Vector(125, 50), Vector(550, 120),
89 Color(0.6, 0.7, 0.8, 0.5), LAYER_GUI-50);
91 context.draw_center_text(font, text, Vector(0, 50+35), LAYER_GUI-40);
93 else context.draw_text(font, text, Vector(125+35, 50+35), LEFT_ALLIGN, LAYER_GUI-40);
95 context.pop_transform();
99 TextObject::update(float elapsed_time)
102 fading -= elapsed_time;
107 } else if(fading < 0) {
108 fading += elapsed_time;