Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #define GETTEXT_DOMAIN "wesnoth-lib"
00017
00018 #include "global.hpp"
00019
00020 #include "widgets/label.hpp"
00021 #include "marked-up_text.hpp"
00022
00023 namespace gui {
00024
00025 label::label(CVideo& video, const std::string& text, int size, const SDL_Color& color, const bool auto_join) : widget(video, auto_join), text_(text), size_(size), color_(color)
00026 {
00027 update_label_size();
00028 }
00029
00030 const std::string& label::set_text(const std::string& text)
00031 {
00032 if (text_ == text)
00033 return text_;
00034
00035 text_ = text;
00036 update_label_size();
00037 set_dirty();
00038 return text_;
00039 }
00040
00041 const std::string& label::get_text() const
00042 {
00043 return text_;
00044 }
00045
00046 const SDL_Color& label::set_color(const SDL_Color& color)
00047 {
00048 color_ = color;
00049 set_dirty();
00050 return get_color();
00051 }
00052
00053 const SDL_Color& label::get_color() const
00054 {
00055 return (enabled()) ? color_ : font::DISABLED_COLOR;
00056 }
00057
00058 void label::draw_contents()
00059 {
00060 const SDL_Rect& loc = location();
00061 if (!text_.empty() && loc.w > 0 && loc.h > 0)
00062 font::draw_text(&video(), loc, size_, get_color(), text_, loc.x, loc.y);
00063 }
00064
00065 void label::update_label_size()
00066 {
00067 SDL_Rect area = font::text_area(text_, size_);
00068 set_measurements(area.w, area.h);
00069 }
00070
00071
00072 }