3 #include "text_object.hpp"
4 #include "resources.hpp"
5 #include "video/drawing_context.hpp"
7 TextObject::TextObject()
8 : fading(0), fadetime(0), visible(false)
14 TextObject::~TextObject()
19 TextObject::set_font(const std::string& name)
23 } else if(name == "white") {
25 } else if(name == "blue") {
27 } else if(name == "gray") {
29 } else if(name == "big") {
30 font = white_big_text;
31 } else if(name == "small") {
32 font = white_small_text;
34 std::cerr << "Unknown font '" << name << "'.\n";
39 TextObject::set_text(const std::string& text)
45 TextObject::fade_in(float fadetime)
47 this->fadetime = fadetime;
52 TextObject::fade_out(float fadetime)
54 this->fadetime = fadetime;
59 TextObject::set_visible(bool visible)
61 this->visible = visible;
66 TextObject::set_centered(bool centered)
68 this->centered = centered;
72 TextObject::draw(DrawingContext& context)
74 context.push_transform();
75 context.set_translation(Vector(0, 0));
77 context.set_alpha(static_cast<uint8_t>
78 ((fadetime-fading) * 255.0 / fadetime));
79 } else if(fading < 0) {
80 context.set_alpha(static_cast<uint8_t> (-fading * 255.0 / fadetime));
82 context.pop_transform();
86 context.draw_filled_rect(Vector(125, 50), Vector(550, 120),
87 Color(150, 180, 200, 125), LAYER_GUI-50);
89 context.draw_center_text(font, text, Vector(0, 50+35), LAYER_GUI-40);
91 else context.draw_text(font, text, Vector(125+35, 50+35), LEFT_ALLIGN, LAYER_GUI-40);
93 context.pop_transform();
97 TextObject::update(float elapsed_time)
100 fading -= elapsed_time;
105 } else if(fading < 0) {
106 fading += elapsed_time;