src/gui/label.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  * Label in GUI.
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 }

Generated on Mon Jan 1 13:10:57 2007 for Wormux by  doxygen 1.4.7