00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "global.hpp"
00016
00017 #include "widgets/label.hpp"
00018 #include "marked-up_text.hpp"
00019 #include "video.hpp"
00020
00021 namespace gui {
00022
00023 label::label(CVideo& video, const std::string& text, int size, const SDL_Color& colour, const bool auto_join) : widget(video, auto_join), text_(text), size_(size), colour_(colour)
00024 {
00025 update_label_size();
00026 }
00027
00028 const std::string& label::set_text(const std::string& text)
00029 {
00030 if (text_ == text)
00031 return text_;
00032
00033 text_ = text;
00034 update_label_size();
00035 set_dirty();
00036 return text_;
00037 }
00038
00039 const std::string& label::get_text() const
00040 {
00041 return text_;
00042 }
00043
00044 int label::set_size(int size)
00045 {
00046 size_ = size;
00047 update_label_size();
00048 set_dirty();
00049 return size_;
00050 }
00051
00052 int label::get_size() const
00053 {
00054 return size_;
00055 }
00056
00057 const SDL_Color& label::set_colour(const SDL_Color& colour)
00058 {
00059 colour_ = colour;
00060 set_dirty();
00061 return get_colour();
00062 }
00063
00064 const SDL_Color& label::get_colour() const
00065 {
00066 return (enabled()) ? colour_ : font::DISABLED_COLOUR;
00067 }
00068
00069 void label::draw_contents()
00070 {
00071 font::draw_text(&video(), location(), size_, get_colour(), text_, location().x, location().y);
00072 }
00073
00074 void label::update_label_size()
00075 {
00076 SDL_Rect area = font::text_area(text_, size_);
00077 set_measurements(area.w, area.h);
00078 }
00079
00080
00081 }