src/gui/check_box.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  * Checkbox in GUI.
00020  *****************************************************************************/
00021 
00022 #include "check_box.h"
00023 #include "../graphic/font.h"
00024 #include "../graphic/sprite.h"
00025 #include "../tool/resource_manager.h"
00026 
00027 CheckBox::CheckBox(const std::string &label, const Rectanglei &rect, bool value)
00028 {
00029   Profile *res = resource_manager.LoadXMLProfile( "graphism.xml", false);   
00030   m_checked_image = resource_manager.LoadSprite( res, "menu/check");
00031   resource_manager.UnLoadXMLProfile( res);
00032   
00033   m_checked_image->cache.EnableLastFrameCache();
00034  
00035   SetPosition( rect.GetPosition() );
00036   SetSize( rect.GetSize() );
00037 
00038   SetSizeY( (*Font::GetInstance(Font::FONT_SMALL)).GetHeight() );
00039   m_value = value;
00040 
00041   txt_label = new Text(label, white_color, Font::GetInstance(Font::FONT_SMALL));
00042   hidden = false;
00043 }
00044 
00045 CheckBox::~CheckBox()
00046 {
00047   delete m_checked_image;
00048   delete txt_label;
00049 }
00050 
00051 void CheckBox::Draw(const Point2i &mousePosition, Surface& surf) const
00052 {
00053   if (!hidden)
00054     {
00055       txt_label->DrawTopLeft( GetPosition() );
00056       
00057       if (m_value)
00058         m_checked_image->SetCurrentFrame(0);
00059       else 
00060         m_checked_image->SetCurrentFrame(1);
00061       
00062       m_checked_image->Blit(surf, GetPositionX() + GetSizeX() - 16, GetPositionY());
00063     }
00064 }
00065 
00066 Widget* CheckBox::Clic(const Point2i &mousePosition, uint button)
00067 {
00068   need_redrawing = true;
00069   m_value = !m_value;
00070   return this ;
00071 }
00072 
00073 void CheckBox::SetSizePosition(const Rectanglei &rect)
00074 {
00075   StdSetSizePosition(rect);
00076 }
00077 
00078 bool CheckBox::GetValue() const
00079 {
00080   return m_value;
00081 }
00082 
00083 void CheckBox::SetValue(bool value)
00084 {
00085   m_value = value;
00086 }
00087 
00088 void CheckBox::SetVisible(bool visible)
00089 {
00090   if (hidden == visible) {
00091     hidden = !visible;
00092     need_redrawing = true;
00093   }
00094 }

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