src/gui/picture_text_cbox.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  * A beautiful checkbox with picture and text
00020  *****************************************************************************/
00021 
00022 #include "picture_text_cbox.h"
00023 #include "../include/app.h"
00024 #include "../graphic/font.h"
00025 #include "../graphic/sprite.h"
00026 #include "../tool/resource_manager.h"
00027 
00028 PictureTextCBox::PictureTextCBox(const std::string &label, const std::string &resource_id, 
00029                                  const Rectanglei &rect, bool value):
00030   CheckBox(label, rect, value)
00031 {
00032   Profile *res = resource_manager.LoadXMLProfile( "graphism.xml", false);   
00033   m_image = resource_manager.LoadImage(res, resource_id);
00034   resource_manager.UnLoadXMLProfile( res);
00035  
00036   SetPosition( rect.GetPosition() );
00037   SetSize( rect.GetSize() );
00038 
00039   SetSizeY( m_image.GetHeight() + (*Font::GetInstance(Font::FONT_NORMAL, Font::BOLD)).GetHeight() );
00040   m_value = value;
00041 
00042   txt_label = new Text(label, dark_gray_color, Font::GetInstance(Font::FONT_NORMAL, Font::BOLD), false);
00043   txt_label->SetMaxWidth (GetSizeX());
00044 }
00045 
00046 void PictureTextCBox::Draw(const Point2i &mousePosition, Surface& surf) const
00047 {
00048   if (!hidden)
00049     {
00050       // center the image
00051       uint tmp_x = GetPositionX() + (GetSizeX() - m_image.GetWidth() - 20)/2 ;
00052       uint tmp_y = GetPositionY() + (GetSizeY() - m_image.GetHeight() - txt_label->GetHeight() - 5) /2;
00053       
00054       AppWormux::GetInstance()->video.window.Blit(m_image, Point2i(tmp_x, tmp_y));
00055       
00056       txt_label->DrawCenterTop( GetPositionX() + GetSizeX()/2, 
00057                                 GetPositionY() + GetSizeY() - txt_label->GetHeight() );
00058       
00059       if (m_value)
00060         m_checked_image->SetCurrentFrame(0);
00061       else 
00062         m_checked_image->SetCurrentFrame(1);
00063       
00064       m_checked_image->Blit(surf, 
00065                             GetPositionX() + GetSizeX() - 16, 
00066                             GetPositionY() + (GetSizeY()-16)/2 );
00067     }
00068 }
00069 
00070 void PictureTextCBox::SetSizePosition(const Rectanglei &rect)
00071 {
00072   StdSetSizePosition(rect);
00073   txt_label->SetMaxWidth (GetSizeX());
00074 }

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