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)
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 == "big") {
29 font = white_big_text;
30 } else if(name == "small") {
31 font = white_small_text;
33 std::cerr << "Unknown font '" << name << "'.\n";
38 TextObject::set_text(const std::string& text)
44 TextObject::fade_in(float fadetime)
46 this->fadetime = fadetime;
51 TextObject::fade_out(float fadetime)
53 this->fadetime = fadetime;
58 TextObject::set_visible(bool visible)
60 this->visible = visible;
65 TextObject::draw(DrawingContext& context)
67 context.push_transform();
68 context.set_translation(Vector(0, 0));
70 context.set_alpha(static_cast<uint8_t>
71 ((fadetime-fading) * 255.0 / fadetime));
72 } else if(fading < 0) {
73 context.set_alpha(static_cast<uint8_t> (-fading * 255.0 / fadetime));
75 context.pop_transform();
79 context.draw_filled_rect(Vector(125, 50), Vector(550, 120),
80 Color(150, 180, 200, 125), LAYER_GUI-50);
81 context.draw_text(font, text, Vector(125+35, 50+35), LEFT_ALLIGN, LAYER_GUI-40);
83 context.pop_transform();
87 TextObject::update(float elapsed_time)
90 fading -= elapsed_time;
95 } else if(fading < 0) {
96 fading += elapsed_time;