Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

pgimage.cpp

Go to the documentation of this file.
00001 /*
00002     ParaGUI - crossplatform widgetset 
00003     Copyright (C) 2000,2001,2002  Alexander Pipelka 
00004   
00005     This library is free software; you can redistribute it and/or 
00006     modify it under the terms of the GNU Library General Public 
00007     License as published by the Free Software Foundation; either 
00008     version 2 of the License, or (at your option) any later version. 
00009   
00010     This library 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 GNU 
00013     Library General Public License for more details. 
00014   
00015     You should have received a copy of the GNU Library General Public 
00016     License along with this library; if not, write to the Free 
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
00018   
00019     Alexander Pipelka
00020     pipelka@teleweb.at
00021   
00022     Last Update:      $Author: mbickel $ 
00023     Update Date:      $Date: 2007-04-13 16:16:03 $ 
00024     Source File:      $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/src/widgets/pgimage.cpp,v $ 
00025     CVS/RCS Revision: $Revision: 1.2 $ 
00026     Status:           $State: Exp $ 
00027 */
00028 
00029 #include "pgimage.h"
00030 
00031 
00032 PG_Rect PG_Image::CalcWidgetSize( const PG_Point& p, const SDL_Surface* image )
00033 {
00034    if ( image )
00035       return PG_Rect (p.x, p.y, image->w, image->h );
00036    else
00037       return PG_Rect (p.x, p.y, 1,1 );
00038 }
00039 
00040 
00041 PG_Image::PG_Image(PG_Widget* parent, const PG_Point& p, const std::string& filename, Uint32 colorkey, PG_Draw::BkMode drawmode, const std::string& style) : PG_ThemeWidget(parent, CalcWidgetSize(p, NULL), style), my_cachedSrf(NULL), my_DrawMode(drawmode) {
00042         LoadImage(filename, colorkey);
00043 
00044         if(my_image != NULL && drawmode == PG_Draw::TILE) {
00045                 SizeWidget(my_image->w, my_image->h);
00046         }
00047 }
00048 
00049 PG_Image::PG_Image(PG_Widget* parent, const PG_Point& p, const std::string& filename, PG_Draw::BkMode drawmode, const std::string& style) : PG_ThemeWidget(parent, CalcWidgetSize(p, NULL), style), my_cachedSrf(NULL), my_DrawMode(drawmode) {
00050         LoadImage(filename);
00051 
00052         if(my_image != NULL && drawmode == PG_Draw::TILE) {
00053                 SizeWidget(my_image->w, my_image->h);
00054         }
00055 }
00056 
00057 
00058 
00059 PG_Image::PG_Image(PG_Widget* parent, const PG_Point& p, SDL_Surface* image, bool freeimage, PG_Draw::BkMode drawmode, const std::string& style) : PG_ThemeWidget(parent, CalcWidgetSize(p, image), style), my_cachedSrf(NULL), my_DrawMode(drawmode) {
00060         SetImage(image, freeimage);
00061 
00062         if(my_image != NULL && drawmode == PG_Draw::TILE) {
00063                 SizeWidget(my_image->w, my_image->h);
00064         }
00065 }
00066 
00067 PG_Image::~PG_Image() {
00068         DeleteThemedSurface(my_cachedSrf);
00069 }
00070 
00071 void PG_Image::eventDraw(SDL_Surface* surface, const PG_Rect& rect) {}
00072 
00073 void PG_Image::eventBlit(SDL_Surface* srf, const PG_Rect& src, const PG_Rect& dst) {
00074 
00075         if(my_cachedSrf != NULL) {
00076                 PG_Rect my_src;
00077                 PG_Rect my_dst;
00078 
00079                 GetClipRects(my_src, my_dst, *this);
00080                 PG_Widget::eventBlit(my_cachedSrf, my_src, my_dst);
00081                 return;
00082         }
00083 
00084         if(my_image == NULL) {
00085                 return;
00086         }
00087 
00088         if(my_image->w != 0 && my_image->h != 0) {
00089                 PG_Rect my_src;
00090                 PG_Rect my_dst;
00091 
00092                 GetClipRects(my_src, my_dst, *this);
00093                 if(my_DrawMode != PG_Draw::STRETCH) {
00094                         PG_Widget::eventBlit(my_image, my_src, my_dst);
00095                         return;
00096                 }
00097 
00098                 my_cachedSrf = CreateThemedSurface(PG_Rect(0, 0, my_width, my_height), 0, my_background, my_DrawMode, my_blendLevel);
00099                 PG_Draw::DrawThemedSurface(my_cachedSrf, PG_Rect(0, 0, my_src.w, my_src.h), 0, my_image, my_DrawMode, my_blendLevel);
00100 
00101                 //PG_Widget::eventBlit(my_cachedSrf, my_src, my_dst);
00102                 eventBlit(srf, src, dst);
00103         }
00104 }
00105 
00106 void PG_Image::SetColorKey(const PG_Color& key) {
00107         SDL_SetColorKey(my_image, SDL_SRCCOLORKEY, key);
00108         DeleteThemedSurface(my_cachedSrf);
00109         my_cachedSrf = NULL;
00110 }
00111 
00112 void PG_Image::SetDrawMode(PG_Draw::BkMode mode) {
00113         if(mode != my_DrawMode) {
00114                 my_DrawMode = mode;
00115                 DeleteThemedSurface(my_cachedSrf);
00116                 my_cachedSrf = NULL;
00117         }
00118 }
00119 
00120 bool PG_Image::LoadImage(const std::string& filename) {
00121         DeleteThemedSurface(my_cachedSrf);
00122         my_cachedSrf = NULL;
00123 
00124         if(PG_ThemeWidget::LoadImage(filename)) {
00125                 return true;
00126         }
00127 
00128         return false;
00129 }
00130 
00131 bool PG_Image::LoadImage(const std::string& filename, const PG_Color& key) {
00132         DeleteThemedSurface(my_cachedSrf);
00133         my_cachedSrf = NULL;
00134 
00135         if(PG_ThemeWidget::LoadImage(filename, key)) {
00136                 return true;
00137         }
00138 
00139         return false;
00140 }
00141 
00142 bool PG_Image::SetImage(SDL_Surface* image, bool bFreeImage) {
00143         DeleteThemedSurface(my_cachedSrf);
00144         my_cachedSrf = NULL;
00145 
00146         if(PG_ThemeWidget::SetImage(image, bFreeImage)) {
00147                 return true;
00148         }
00149 
00150         return false;
00151 }

Generated on Tue Jun 24 01:27:48 2008 for Advanced Strategic Command by  doxygen 1.4.2