| 1 |
#ifndef _CSURFACE_ |
| 2 |
#define _CSURFACE_ |
| 3 |
|
| 4 |
#include "SDL.h" |
| 5 |
#include "CColor.h" |
| 6 |
#include "CVector.h" |
| 7 |
#include "CRect.h" |
| 8 |
#include "CGfxPrimitives.h" |
| 9 |
#include <list> |
| 10 |
using namespace std; |
| 11 |
// TODO: Abstract the surface class, use base class CSurface and derived class CSDLSurface. This will make it easy to move away from SDL if necessary (or optimize stuff). |
| 12 |
|
| 13 |
|
| 14 |
class CSurface |
| 15 |
{ |
| 16 |
|
| 17 |
friend class CGfxPrimitives; |
| 18 |
|
| 19 |
public: |
| 20 |
enum SurfaceTypes |
| 21 |
{ |
| 22 |
SOFTWARE_SURFACE = SDL_SWSURFACE, |
| 23 |
HARDWARE_SURFACE = SDL_HWSURFACE, |
| 24 |
SRC_COLORKEY = SDL_SRCCOLORKEY, |
| 25 |
SRC_ALPHA = SDL_SRCALPHA |
| 26 |
}; |
| 27 |
|
| 28 |
//! Constructs surface with given paramaters |
| 29 |
/*! These are simply passed to SDL_CreateRGBSurface() |
| 30 |
\exception ex_sdlSurfaceCreationFailed { Call to SDL_CreateRGBSurface() failed } |
| 31 |
*/ |
| 32 |
CSurface(Uint32 flags, int width, int height, int depth, |
| 33 |
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask); |
| 34 |
|
| 35 |
//! Copy constructor |
| 36 |
CSurface(const CSurface& surf); |
| 37 |
|
| 38 |
//! Construct CSurface from pre-existing surface |
| 39 |
/*! 'Ownership' of the surface specified by s is transfered this CSurface |
| 40 |
\param s Pointer to surface that this CSurface will assimilate |
| 41 |
|
| 42 |
\exception ex_illegalArguments { s is NULL pointer } |
| 43 |
*/ |
| 44 |
CSurface(SDL_Surface* s); |
| 45 |
|
| 46 |
//! Destructor |
| 47 |
/*! Calls SDL_FreeSurface() on s |
| 48 |
*/ |
| 49 |
~CSurface(); |
| 50 |
|
| 51 |
//void blit(const CSurface& src, int srcx, int srcy, int srcwidth, int srcheight); |
| 52 |
void blit(const CSurface &src, int x, int y); |
| 53 |
void blitSrcRect(const CSurface& src, CRect r); |
| 54 |
void blitScale(const CSurface& src, CRect r, double scale); |
| 55 |
void blitScaleEx(const CSurface& src, CRect r, double scaleX, double scaleY); |
| 56 |
void blitRotScale(const CSurface& src, CRect r, double scale, double rad); |
| 57 |
void blitBothRect(const CSurface& src, CRect rsrc, CRect rdest); |
| 58 |
void rotateAndScale(double scale, double rad); |
| 59 |
void fill(CColor color); |
| 60 |
void doneDrawing(); |
| 61 |
void setAlpha(Uint32 flags, Uint8 alpha); |
| 62 |
|
| 63 |
//! Gets a section of this surface |
| 64 |
/*! Gets a section of this surface and returns a new CSurface |
| 65 |
\param x x cord of top-left corner of section to get |
| 66 |
\param y y cord of top-left corner of section to get |
| 67 |
\param width width of section to get |
| 68 |
\param height height of section to get |
| 69 |
\exeption ex_sdlSurfaceCreationFailed { Call to SDL_CreateRGBSurface() failed } |
| 70 |
*/ |
| 71 |
CSurface* getSection(int x, int y, int width, int height) const; |
| 72 |
void setClippingRect(CRect r); |
| 73 |
void resetClippingRect(); |
| 74 |
void displayFormat(); |
| 75 |
void displayFormatAlpha(); |
| 76 |
int getWidth() const; |
| 77 |
int getHeight() const; |
| 78 |
// CColor getColor(int r, int g, int b); |
| 79 |
|
| 80 |
const CSurface& operator=(const CSurface &s); |
| 81 |
|
| 82 |
bool onSurface(const CVector &pos) const; |
| 83 |
bool onSurface(int x, int y) const; |
| 84 |
|
| 85 |
void lock(); |
| 86 |
void unlock(); |
| 87 |
void getPixel(int x, int y, CColor &color); |
| 88 |
void setPixel(int x, int y, CColor &color); |
| 89 |
|
| 90 |
friend ostream& operator<<(ostream& os, const CSurface& v); // similar to toString in java |
| 91 |
|
| 92 |
private: |
| 93 |
|
| 94 |
SDL_Surface* createSurface(Uint32 flags, int width, int height, int depth, |
| 95 |
Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask); |
| 96 |
SDL_Surface* getSurface() const; |
| 97 |
|
| 98 |
Uint32 getPixel(int x, int y); |
| 99 |
void setPixel(int x, int y, Uint32 val); |
| 100 |
|
| 101 |
int width, height; |
| 102 |
int depth; |
| 103 |
Uint32 Rmask, Gmask, Bmask, Amask; |
| 104 |
Uint32 creationFlags; |
| 105 |
SDL_Surface* s; |
| 106 |
int locked; |
| 107 |
list<CRect> dirty; |
| 108 |
}; |
| 109 |
|
| 110 |
#endif |