00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef SURFACE_H
00023 #define SURFACE_H
00024
00025 #include <SDL.h>
00026 #include <string>
00027 #include "color.h"
00028 #include "../include/base.h"
00029 #include "../tool/point.h"
00030 #include "../tool/rectangle.h"
00031
00032 class Surface
00033 {
00034 private:
00035 SDL_Surface* surface;
00036 bool autoFree;
00037 int Blit(const Surface& src, SDL_Rect *srcRect, SDL_Rect *dstRect);
00038 SDL_Rect GetSDLRect(const Rectanglei &r) const;
00039 SDL_Rect GetSDLRect(const Point2i &r) const;
00040
00041 public:
00042 explicit Surface();
00043 explicit Surface(SDL_Surface *sdl_surface);
00044 explicit Surface(const Point2i &size, Uint32 flags, bool useAlpha = true);
00045 explicit Surface(const std::string &filename);
00046 Surface(const Surface &src);
00047 ~Surface();
00048
00049 Surface &operator=(const Surface &src);
00050
00051 void Free();
00052 void AutoFree();
00053 void SetAutoFree(bool newAutoFree);
00054
00055 void SetSurface(SDL_Surface *newSurface, bool freePrevious = true);
00056 void NewSurface(const Point2i &size, Uint32 flags, bool useAlpha = true);
00057
00058 SDL_Surface *GetSurface();
00059
00060 int SetAlpha(Uint32 flags, Uint8 alpha);
00061
00062 int Lock();
00063 void Unlock();
00064
00065 int Blit(const Surface& src);
00066 int Blit(const Surface& src, const Point2i& dst);
00067 int Blit(const Surface& src, const Rectanglei& srcRect, const Point2i &dstPoint);
00068
00069 int SetColorKey(Uint32 flag, Uint32 key);
00070 int SetColorKey(Uint32 flag, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
00071
00072 void GetRGBA(Uint32 color, Uint8 &r, Uint8 &g, Uint8 &b, Uint8 &a) const;
00073 Uint32 MapRGBA(Uint8 r, Uint8 g, Uint8 b, Uint8 a) const;
00074 Color GetColor(Uint32 color) const;
00075 Uint32 MapColor(Color color) const;
00076
00077 void SetClipRect(const Rectanglei &rect);
00078 void Flip();
00079
00080 int BoxColor(const Rectanglei &rect, const Color &color);
00081 int RectangleColor(const Rectanglei &rect, const Color &color, const uint &border_size = 1);
00082 int VlineColor(const uint &x1, const uint &y1, const uint &y2, const Color &color);
00083 int LineColor(const uint &x1, const uint &x2, const uint &y1, const uint &y2, const Color &color);
00084 int AALineColor(const uint &x1, const uint &x2, const uint &y1, const uint &y2, const Color &color);
00085 int CircleColor(const uint &x, const uint &y, const uint &rad, const Color &color);
00086
00087 int Fill(Uint32 color) const;
00088 int Fill(const Color &color) const;
00089 int FillRect(const Rectanglei &dstRect, Uint32 color) const;
00090 int FillRect(const Rectanglei &dstRect, const Color &color) const;
00091
00092 int ImgLoad(std::string filename);
00093 Surface RotoZoom(double angle, double zoomx, double zoomy, int smooth);
00094 Surface DisplayFormatAlpha();
00095 Surface DisplayFormat();
00096 Uint32 GetPixel(int x, int y);
00097 void PutPixel(int x, int y, Uint32 pixel);
00098
00099 inline bool IsNull() const{
00100 return surface == NULL;
00101 }
00102
00106 inline Point2i GetSize() const{
00107 return Point2i( GetWidth(), GetHeight() );
00108 }
00109
00111 inline int GetWidth() const{
00112 return surface->w;
00113 }
00114
00116 inline int GetHeight() const{
00117 return surface->h;
00118 }
00119
00120 inline Uint32 GetFlags() const{
00121 return surface->flags;
00122 }
00123
00125 inline Uint16 GetPitch() const{
00126 return surface->pitch;
00127 }
00128
00130 inline Uint8 GetBytesPerPixel() const{
00131 return surface->format->BytesPerPixel;
00132 }
00133
00135 inline unsigned char *GetPixels() const{
00136 return (unsigned char *) surface->pixels;
00137 }
00138
00139 };
00140
00141 #endif