00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "label.h"
00023
00024 Label::Label (const std::string &label, const Rectanglei &rect, Font& _font,
00025 const Color& color, bool _center, bool _shadowed)
00026 : font_color(color)
00027 {
00028 position = rect.GetPosition();
00029 size = rect.GetSize();
00030 font = &_font;
00031 center = _center;
00032 shadowed = _shadowed;
00033 hidden = false;
00034 txt_label = new Text(label, font_color, &_font, shadowed);
00035 txt_label->SetMaxWidth(GetSizeX());
00036 size.y = txt_label->GetHeight();
00037 }
00038
00039 Label::~Label()
00040 {
00041 delete txt_label;
00042 }
00043
00044 void Label::Draw(const Point2i &mousePosition, Surface& surf) const
00045 {
00046 if (!hidden)
00047 {
00048 if (!center)
00049 txt_label->DrawTopLeft(position);
00050 else
00051 txt_label->DrawCenterTop(position.x + size.x/2, position.y);
00052 }
00053 }
00054
00055 void Label::SetSizePosition(const Rectanglei &rect)
00056 {
00057 StdSetSizePosition(rect);
00058 txt_label->SetMaxWidth(GetSizeX());
00059 size.y = txt_label->GetHeight();
00060 }
00061
00062 void Label::SetText(const std::string &new_txt)
00063 {
00064 need_redrawing = true;
00065 delete txt_label;
00066 txt_label = new Text(new_txt, font_color, font, shadowed);
00067 txt_label->SetMaxWidth(GetSizeX());
00068 }
00069
00070 const std::string& Label::GetText() const
00071 {
00072 return txt_label->GetText();
00073 }
00074
00075 void Label::SetVisible(bool visible)
00076 {
00077 if (hidden == visible) {
00078 hidden = !visible;
00079 need_redrawing = true;
00080 }
00081 }