~ubuntu-branches/ubuntu/lucid/asc/lucid

« back to all changes in this revision

Viewing changes to source/libs/paragui/src/widgets/pgimage.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese, Eddy Petrișor, Gonéri Le Bouder, Cyril Brulebois, Barry deFreese
  • Date: 2008-01-08 19:54:18 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080108195418-n19fc4eobhhqxcy5
Tags: 2.0.1.0-1
[ Eddy Petrișor ]
* fixed Homepage semifield

[ Gonéri Le Bouder ]
* add a watchfile
* move homepage from the description to the new Homepage field

[ Cyril Brulebois ]
* Added Vcs-Svn and Vcs-Browser fields in the control file.

[ Barry deFreese ]
* Fix make-clean lintian warning
* New upstream release
* Bump debhelper build-dep to match compat
* Add desktop file
* Update watch file for new upstream naming
* Remove nostrip check from rules
* Bump Standards Version to 3.7.3
* Add myself to uploaders

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    ParaGUI - crossplatform widgetset 
 
3
    Copyright (C) 2000,2001,2002  Alexander Pipelka 
 
4
  
 
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. 
 
9
  
 
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. 
 
14
  
 
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 
 
18
  
 
19
    Alexander Pipelka
 
20
    pipelka@teleweb.at
 
21
  
 
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 $ 
 
26
    Status:           $State: Exp $ 
 
27
*/
 
28
 
 
29
#include "pgimage.h"
 
30
 
 
31
 
 
32
PG_Rect PG_Image::CalcWidgetSize( const PG_Point& p, const SDL_Surface* image )
 
33
{
 
34
   if ( image )
 
35
      return PG_Rect (p.x, p.y, image->w, image->h );
 
36
   else
 
37
      return PG_Rect (p.x, p.y, 1,1 );
 
38
}
 
39
 
 
40
 
 
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);
 
43
 
 
44
        if(my_image != NULL && drawmode == PG_Draw::TILE) {
 
45
                SizeWidget(my_image->w, my_image->h);
 
46
        }
 
47
}
 
48
 
 
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) {
 
50
        LoadImage(filename);
 
51
 
 
52
        if(my_image != NULL && drawmode == PG_Draw::TILE) {
 
53
                SizeWidget(my_image->w, my_image->h);
 
54
        }
 
55
}
 
56
 
 
57
 
 
58
 
 
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);
 
61
 
 
62
        if(my_image != NULL && drawmode == PG_Draw::TILE) {
 
63
                SizeWidget(my_image->w, my_image->h);
 
64
        }
 
65
}
 
66
 
 
67
PG_Image::~PG_Image() {
 
68
        DeleteThemedSurface(my_cachedSrf);
 
69
}
 
70
 
 
71
void PG_Image::eventDraw(SDL_Surface* surface, const PG_Rect& rect) {}
 
72
 
 
73
void PG_Image::eventBlit(SDL_Surface* srf, const PG_Rect& src, const PG_Rect& dst) {
 
74
 
 
75
        if(my_cachedSrf != NULL) {
 
76
                PG_Rect my_src;
 
77
                PG_Rect my_dst;
 
78
 
 
79
                GetClipRects(my_src, my_dst, *this);
 
80
                PG_Widget::eventBlit(my_cachedSrf, my_src, my_dst);
 
81
                return;
 
82
        }
 
83
 
 
84
        if(my_image == NULL) {
 
85
                return;
 
86
        }
 
87
 
 
88
        if(my_image->w != 0 && my_image->h != 0) {
 
89
                PG_Rect my_src;
 
90
                PG_Rect my_dst;
 
91
 
 
92
                GetClipRects(my_src, my_dst, *this);
 
93
                if(my_DrawMode != PG_Draw::STRETCH) {
 
94
                        PG_Widget::eventBlit(my_image, my_src, my_dst);
 
95
                        return;
 
96
                }
 
97
 
 
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);
 
100
 
 
101
                //PG_Widget::eventBlit(my_cachedSrf, my_src, my_dst);
 
102
                eventBlit(srf, src, dst);
 
103
        }
 
104
}
 
105
 
 
106
void PG_Image::SetColorKey(const PG_Color& key) {
 
107
        SDL_SetColorKey(my_image, SDL_SRCCOLORKEY, key);
 
108
        DeleteThemedSurface(my_cachedSrf);
 
109
        my_cachedSrf = NULL;
 
110
}
 
111
 
 
112
void PG_Image::SetDrawMode(PG_Draw::BkMode mode) {
 
113
        if(mode != my_DrawMode) {
 
114
                my_DrawMode = mode;
 
115
                DeleteThemedSurface(my_cachedSrf);
 
116
                my_cachedSrf = NULL;
 
117
        }
 
118
}
 
119
 
 
120
bool PG_Image::LoadImage(const std::string& filename) {
 
121
        DeleteThemedSurface(my_cachedSrf);
 
122
        my_cachedSrf = NULL;
 
123
 
 
124
        if(PG_ThemeWidget::LoadImage(filename)) {
 
125
                return true;
 
126
        }
 
127
 
 
128
        return false;
 
129
}
 
130
 
 
131
bool PG_Image::LoadImage(const std::string& filename, const PG_Color& key) {
 
132
        DeleteThemedSurface(my_cachedSrf);
 
133
        my_cachedSrf = NULL;
 
134
 
 
135
        if(PG_ThemeWidget::LoadImage(filename, key)) {
 
136
                return true;
 
137
        }
 
138
 
 
139
        return false;
 
140
}
 
141
 
 
142
bool PG_Image::SetImage(SDL_Surface* image, bool bFreeImage) {
 
143
        DeleteThemedSurface(my_cachedSrf);
 
144
        my_cachedSrf = NULL;
 
145
 
 
146
        if(PG_ThemeWidget::SetImage(image, bFreeImage)) {
 
147
                return true;
 
148
        }
 
149
 
 
150
        return false;
 
151
}