| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
1 |
/* |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
2 |
* File: CppSdlImageHolder.hpp |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
3 |
* Author: poul |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
4 |
* |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
5 |
* Created on 29. september 2010, 19:46 |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
6 |
*/ |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
7 |
|
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
8 |
#ifndef _CPPSDLIMAGEHOLDER_HPP |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
9 |
#define _CPPSDLIMAGEHOLDER_HPP |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
10 |
|
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
11 |
#include "SDL.h" |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
12 |
#include <string> |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
13 |
#include "CppSdlException.hpp" |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
14 |
|
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
15 |
namespace CppSdl { |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
16 |
|
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
17 |
class CppSdlImageHolder { |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
18 |
public: |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
19 |
/** |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
20 |
* Creates a nulled ImageHolder (without data) |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
21 |
*/ |
| 8d488d32 |
sago007 |
2011-04-17 13:02 |
22 |
CppSdlImageHolder(); |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
23 |
/** |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
24 |
* Creates an image from a file |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
25 |
* @param filename to be loaded |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
26 |
*/ |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
27 |
CppSdlImageHolder(std::string filename); |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
28 |
/** |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
29 |
* Creates a copy. The new copy shares raw data with the original but is otherwise independent. |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
30 |
* @param orig |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
31 |
*/ |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
32 |
CppSdlImageHolder(const CppSdlImageHolder& orig); |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
33 |
CppSdlImageHolder(char *rawdata, int datasize); |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
34 |
virtual ~CppSdlImageHolder(); |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
35 |
/** |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
36 |
* This gives access direct access to the internal data. |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
37 |
* Careful, the data might be shared between multiple ImageHolders, |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
38 |
* chaing one will change them all. |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
39 |
* @return A pointer |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
40 |
*/ |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
41 |
SDL_Surface *GetRawDataInsecure(); |
| 8d488d32 |
sago007 |
2011-04-17 13:02 |
42 |
CppSdlImageHolder & operator=(const CppSdlImageHolder &rhs); |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
43 |
void Cut(Uint32 x,Uint32 y,Sint32 w,Sint32 h); |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
44 |
/** |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
45 |
* The width of the image |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
46 |
* 0 if the image is nulled |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
47 |
* @return The width of the image in pizels |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
48 |
*/ |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
49 |
Uint32 GetWidth(); |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
50 |
/** |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
51 |
* The height of the image |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
52 |
* 0 if the image is nulled |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
53 |
* @return The height of the image |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
54 |
*/ |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
55 |
Uint32 GetHeight(); |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
56 |
/** |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
57 |
* Draws an image to surface at a given position. |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
58 |
* If the image is nulled nothing is drawn |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
59 |
* @param target Destination surface |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
60 |
* @param x horizontal placement on destination surface |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
61 |
* @param y vertical placement on destination surface |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
62 |
*/ |
| 4f1d27f1 |
sago007 |
2011-03-18 15:53 |
63 |
void PaintTo(SDL_Surface *target, int x, int y); |
| 4f1d27f1 |
sago007 |
2011-03-18 15:53 |
64 |
void OptimizeForBlit(bool allowAlpha = true); |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
65 |
/** |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
66 |
* Tests if there are data in the object |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
67 |
* @return true if where are data in the object |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
68 |
*/ |
| 8d488d32 |
sago007 |
2011-04-17 13:02 |
69 |
bool IsNull(); |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
70 |
/** |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
71 |
* Removes the data in the object. |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
72 |
* Once all ImageHolders pointing to the same data has been freed the internal data will be freed too |
| 00127e1a |
sago007 |
2011-06-13 11:50 |
73 |
*/ |
| 8d488d32 |
sago007 |
2011-04-17 13:02 |
74 |
void MakeNull(); |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
75 |
private: |
| 8d488d32 |
sago007 |
2011-04-17 13:02 |
76 |
void Initialized(); //throws an exception if *data is null |
| 8d488d32 |
sago007 |
2011-04-17 13:02 |
77 |
int *counter; |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
78 |
SDL_Rect area; |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
79 |
SDL_Surface *data; |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
80 |
}; |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
81 |
|
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
82 |
} |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
83 |
#endif /* _CPPSDLIMAGEHOLDER_HPP */ |
| 3db6ed5d |
sago007 |
2010-12-07 17:19 |
84 |
|
|
|
1970-01-01 00:00 |
85 |
|