2
ParaGUI - crossplatform widgetset
3
Copyright (C) 2000,2001,2002 Alexander Pipelka
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public
16
License along with this library; if not, write to the Free
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
Last Update: $Author: mbickel $
23
Update Date: $Date: 2007-04-13 16:16:03 $
24
Source File: $Source: /home/cvspsrv/cvsroot/games/asc/source/libs/paragui/src/widgets/pgimage.cpp,v $
25
CVS/RCS Revision: $Revision: 1.2 $
32
PG_Rect PG_Image::CalcWidgetSize( const PG_Point& p, const SDL_Surface* image )
35
return PG_Rect (p.x, p.y, image->w, image->h );
37
return PG_Rect (p.x, p.y, 1,1 );
41
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) {
42
LoadImage(filename, colorkey);
44
if(my_image != NULL && drawmode == PG_Draw::TILE) {
45
SizeWidget(my_image->w, my_image->h);
49
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) {
52
if(my_image != NULL && drawmode == PG_Draw::TILE) {
53
SizeWidget(my_image->w, my_image->h);
59
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) {
60
SetImage(image, freeimage);
62
if(my_image != NULL && drawmode == PG_Draw::TILE) {
63
SizeWidget(my_image->w, my_image->h);
67
PG_Image::~PG_Image() {
68
DeleteThemedSurface(my_cachedSrf);
71
void PG_Image::eventDraw(SDL_Surface* surface, const PG_Rect& rect) {}
73
void PG_Image::eventBlit(SDL_Surface* srf, const PG_Rect& src, const PG_Rect& dst) {
75
if(my_cachedSrf != NULL) {
79
GetClipRects(my_src, my_dst, *this);
80
PG_Widget::eventBlit(my_cachedSrf, my_src, my_dst);
84
if(my_image == NULL) {
88
if(my_image->w != 0 && my_image->h != 0) {
92
GetClipRects(my_src, my_dst, *this);
93
if(my_DrawMode != PG_Draw::STRETCH) {
94
PG_Widget::eventBlit(my_image, my_src, my_dst);
98
my_cachedSrf = CreateThemedSurface(PG_Rect(0, 0, my_width, my_height), 0, my_background, my_DrawMode, my_blendLevel);
99
PG_Draw::DrawThemedSurface(my_cachedSrf, PG_Rect(0, 0, my_src.w, my_src.h), 0, my_image, my_DrawMode, my_blendLevel);
101
//PG_Widget::eventBlit(my_cachedSrf, my_src, my_dst);
102
eventBlit(srf, src, dst);
106
void PG_Image::SetColorKey(const PG_Color& key) {
107
SDL_SetColorKey(my_image, SDL_SRCCOLORKEY, key);
108
DeleteThemedSurface(my_cachedSrf);
112
void PG_Image::SetDrawMode(PG_Draw::BkMode mode) {
113
if(mode != my_DrawMode) {
115
DeleteThemedSurface(my_cachedSrf);
120
bool PG_Image::LoadImage(const std::string& filename) {
121
DeleteThemedSurface(my_cachedSrf);
124
if(PG_ThemeWidget::LoadImage(filename)) {
131
bool PG_Image::LoadImage(const std::string& filename, const PG_Color& key) {
132
DeleteThemedSurface(my_cachedSrf);
135
if(PG_ThemeWidget::LoadImage(filename, key)) {
142
bool PG_Image::SetImage(SDL_Surface* image, bool bFreeImage) {
143
DeleteThemedSurface(my_cachedSrf);
146
if(PG_ThemeWidget::SetImage(image, bFreeImage)) {