sdlmm_basesurface.h Source File

Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members File Members Related Pages

# sdlmm_basesurface.h

Go to the documentation of this file.

    00001 /*
    00002  * SDmm - a C++ wrapper for SDL and related libraries
    00003  * Copyright © 2001 David Hedbor <david@hedbor.org>
    00004  *
    00005  * This program is free software; you can redistribute it and/or
    00006  * modify it under the terms of the GNU General Public License as
    00007  * published by the Free Software Foundation; either version 2 of the
    00008  * License, or (at your option) any later version.
    00009  *
    00010  * This program is distributed in the hope that it will be useful, but
    00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013  * General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU General Public License
    00016  * along with this program; if not, write to the Free Software
    00017  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00018  *
    00019  */
    00020
    00021
    00022 #ifndef SDLMM_BASESURFACE_H
    00023 #define SDLMM_BASESURFACE_H
    00024 #include "sdlmm_config.h"
    00025 #include "sdlmm_spoint.h"
    00026 #include "sdlmm_srect.h"
    00027 #include "sdlmm_color.h"
    00028 #include "sdlmm_pixelformat.h"
    00029 #include <string>
    00030
    00031 namespace SDLmm {
    00033
    00043   class BaseSurface {
    00044
    00045   protected:
    00047     SDL_Surface *me;
    00048     virtual void SetSurface(SDL_Surface *surface) {
    00049       if(me) {
    00050         SDL_FreeSurface(me);
    00051       }
    00052       me = surface;
    00053     }
    00054
    00056
    00063     explicit BaseSurface(SDL_Surface *surface)
    00064       : me(surface) {
    00065     }
    00066
    00067     BaseSurface(const BaseSurface& other)
    00068       : me(other.me) {
    00069     }
    00070
    00071     BaseSurface &operator=(const BaseSurface& other) {
    00072       if(this != &other)
    00073         SetSurface(other.me);
    00074       return *this;
    00075     }
    00076
    00077   public:
    00078
    00080     virtual ~BaseSurface() {
    00081       if(me) {
    00082         SDL_FreeSurface(me);
    00083       }
    00084     }
    00085
    00086     SDL_Surface *GetSurface() {
    00087       ASSERT(me);
    00088       return me;
    00089     }
    00090
    00091     const SDL_Surface *GetSurface() const {
    00092       ASSERT(me);
    00093       return me;
    00094     }
    00095
    00098     bool Lock();
    00099
    00101     void Unlock();
    00102
    00104
    00105
    00106
    00107     bool valid() const { return me != 0; }
    00108
    00110     Uint32 flags() const { return GetSurface()->flags; }
    00111
    00113     const PixelFormat GetPixelFormat() const { return PixelFormat(GetSurface()->format); }
    00114     PixelFormat GetPixelFormat() { return PixelFormat(GetSurface()->format); }
    00115
    00117     int w() const { return GetSurface()->w; }
    00118
    00120     int h() const { return GetSurface()->h; }
    00121
    00123     Uint16 pitch() const { return GetSurface()->pitch; }
    00124
    00126     const SRect clip_rect() const { return SRect(GetSurface()->clip_rect); }
    00127
    00129
    00132     void *pixels() { return GetSurface()->pixels; }
    00133
    00135
    00138     const void *pixels() const { return GetSurface()->pixels; }
    00139
    00141     struct private_hwdata *hwdata() const { return GetSurface()->hwdata; }
    00143
    00145
    00148     void SetPixel(int x, int y, Color color);
    00149
    00151
    00155     void SetPixel1(int x, int y, Color color);
    00156
    00158
    00162     void SetPixel2(int x, int y, Color color);
    00163
    00165
    00169     void SetPixel3(int x, int y, Color color);
    00170
    00172
    00176     void SetPixel4(int x, int y, Color color);
    00177
    00179
    00182     void SetPixel(const SRect& point, Color color) { SetPixel(point.x, point.y, color); }
    00183
    00185
    00188     Color GetPixel(int x, int y) const;
    00189
    00191
    00194     Color GetPixel(const SRect& point) const { return GetPixel(point.x, point.y); }
    00195
    00198
    00207     bool SetColorKey(Uint32 flag, Color key);
    00208
    00210
    00232     bool SetAlpha(Uint32 flag, Uint8 alpha);
    00233
    00235
    00236
    00237
    00241     void ResetClipRect();
    00242
    00244
    00255     void SetClipRect(const SDL_Rect& rect);
    00256
    00258
    00267     void GetClipRect(SDL_Rect& rect) const;
    00269
    00271
    00272
    00273
    00287     int Blit(const BaseSurface& src);
    00288
    00291
    00309     int Blit(const BaseSurface& src, SDL_Rect& dstrect);
    00310
    00313
    00330     int Blit(const BaseSurface& src, const SPoint& dstpoint, SDL_Rect& dstrect) { dstrect.x = dstpoint.x; dstrect.y = dstpoint.y; Blit(src, dstrect); }
    00331
    00334
    00349     int Blit(const BaseSurface& src, const SPoint& dstpoint);
    00350
    00353
    00374     int Blit(const BaseSurface& src, const SDL_Rect& srcrect, SDL_Rect& dstrect);
    00375
    00378
    00398     int Blit(const BaseSurface& src, const SDL_Rect& srcrect, const SPoint& dstpoint, SDL_Rect& dstrect) { dstrect.x = dstpoint.x; dstrect.y = dstpoint.y; Blit(src, srcrect, dstrect); }
    00399
    00402
    00419     int Blit(const BaseSurface& src, const SDL_Rect& srcrect, const SPoint& dstpoint);
    00420
    00422
    00428     bool Fill(Color color);
    00429
    00431
    00437     bool Fill(Uint8 r, Uint8 g, Uint8 b) { return Fill(GetPixelFormat().MapRGB(r, g, b)); }
    00438
    00440
    00447     bool Fill(Uint8 r, Uint8 g, Uint8 b, Uint8 a) { return Fill(GetPixelFormat().MapRGBA(r, g, b, a)); }
    00448
    00450
    00459     bool FillRect(SDL_Rect& dstrect, Color color);
    00460
    00462
    00471     bool FillRect(SDL_Rect& dstrect, Uint8 r, Uint8 g, Uint8 b) { return FillRect(dstrect, GetPixelFormat().MapRGB(r, g, b)); }
    00472
    00474
    00484     bool FillRect(SDL_Rect& dstrect, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { return FillRect(dstrect, GetPixelFormat().MapRGBA(r, g, b, a)); }
    00485
    00487
    00489
    00508     virtual bool SetDisplayFormat() = 0;
    00509
    00511
    00530     virtual bool SetDisplayFormatAlpha() = 0;
    00531
    00533
    00537     bool SaveBMP(const char *file) const;
    00538
    00540
    00544     bool SaveBMP(const std::string& file) const { return SaveBMP(file.c_str()); }
    00545
    00546   };
    00547 }
    00548
    00549 #endif // SDLMM_BASESURFACE_H
    00550

Documentation automatically generated by written by Dimitri van Heesch. | Project hosted at