src/gui/picture_widget.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  * Picture widget: A widget containing a picture
00020  *****************************************************************************/
00021 #include "picture_widget.h"
00022 //#include <SDL_gfxPrimitives.h>
00023 #include "../graphic/colors.h"
00024 #include "../include/app.h"
00025 #include "../tool/resource_manager.h"
00026 
00027 PictureWidget::PictureWidget (const Rectanglei &rect) : Widget(rect)
00028 {
00029   spr = NULL;
00030   disabled = false;
00031 }
00032 
00033 PictureWidget::PictureWidget (const Rectanglei &rect, std::string resource_id) : Widget(rect)
00034 {
00035   spr = NULL;
00036   disabled = false;
00037 
00038   Profile *res = resource_manager.LoadXMLProfile( "graphism.xml", false);
00039   Surface tmp = resource_manager.LoadImage(res, resource_id);
00040   SetSurface(tmp, false);  
00041   resource_manager.UnLoadXMLProfile( res);
00042 }
00043 
00044 PictureWidget::~PictureWidget()
00045 {
00046   if (spr != NULL)
00047     delete spr;
00048 }
00049 
00050 void PictureWidget::SetSurface(const Surface& s, bool enable_scaling)
00051 {
00052   need_redrawing = true;
00053 
00054   if (spr != NULL)
00055     delete spr;
00056 
00057   spr = new Sprite(s);
00058   if (enable_scaling) {
00059     float scale = std::min( float(GetSizeY())/spr->GetHeight(),
00060                             float(GetSizeX())/spr->GetWidth() ) ;
00061   
00062     spr->Scale (scale, scale);
00063   }
00064 }
00065 
00066 void PictureWidget::SetNoSurface()
00067 {
00068   need_redrawing = true;
00069 
00070   if (spr != NULL)
00071     delete spr;
00072 
00073   spr = NULL;
00074 }
00075 
00076 void PictureWidget::Draw(const Point2i &mousePosition,
00077                          Surface& surf) const
00078 {
00079   if (spr != NULL) {
00080     int x = GetPositionX() + ( GetSizeX()/2 ) - (spr->GetWidth()/2);
00081     int y = GetPositionY() + ( GetSizeY()/2 ) - (spr->GetHeight()/2);
00082 
00083     spr->Blit ( surf, x, y);
00084 
00085     // Draw a transparency mask
00086     if (disabled) {
00087       surf.BoxColor(Rectanglei(x,y,spr->GetWidth(),spr->GetHeight()),
00088                     defaultOptionColorBox);
00089     }
00090   }
00091 }
00092 
00093 void PictureWidget::SetSizePosition(const Rectanglei &rect)
00094 {
00095   StdSetSizePosition(rect);
00096 }
00097 
00098 void PictureWidget::Disable()
00099 {
00100   disabled = true;
00101 }

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