Move Rect and Surface out of main file

This commit is contained in:
Kirigaya Kazuto 2017-06-18 17:00:08 +08:00
parent 7505db992a
commit 0629ceadba
9 changed files with 549 additions and 511 deletions

View File

@ -234,71 +234,7 @@ namespace MiniEngine
} }
}/// End of namespace _internal }/// End of namespace _internal
Rect::Rect(int X, int Y, int W, int H)
{
x = X;
y = Y;
w = W;
h = H;
}
Rect::Rect(const SDL_Rect& r):Rect(r.x,r.y,r.w,r.h)
{
}
Rect::Rect()
{
x = y = w = h = 0;
}
SDL_Rect Rect::toSDLRect() const
{
SDL_Rect r;
r.x = x;
r.y = y;
r.w = w;
r.h = h;
return r;
}
bool Rect::isEmpty()
{
SDL_Rect r=toSDLRect();
return SDL_RectEmpty(&r)==SDL_TRUE;
}
bool Rect::operator == (const Rect& r) const
{
SDL_Rect a=toSDLRect(),b=r.toSDLRect();
return SDL_RectEquals(&a,&b)==SDL_TRUE;
}
bool Rect::hasIntersection(const Rect& r) const
{
SDL_Rect a=toSDLRect(),b=r.toSDLRect();
return SDL_HasIntersection(&a,&b)==SDL_TRUE;
}
Rect Rect::getIntersection(const Rect& r) const
{
SDL_Rect a=toSDLRect(),b=r.toSDLRect(),c;
if(SDL_IntersectRect(&a,&b,&c)==SDL_TRUE)
{
return Rect(c);
}
else
{
return Rect();
}
}
Rect Rect::getUnion(const Rect& r) const
{
SDL_Rect a=toSDLRect(),b=r.toSDLRect(),c;
SDL_UnionRect(&a,&b,&c);//void
return Rect(c);
}
Point::Point(int X, int Y) Point::Point(int X, int Y)
{ {
@ -432,361 +368,7 @@ namespace MiniEngine
_clear(); _clear();
} }
//private
void Surface::_set(SDL_Surface* p)
{
_surf.reset(p,SDL_FreeSurface);
}
//private
void Surface::_clear()
{
_surf.reset();
}
//private
SDL_Surface* Surface::_get() const
{
return _surf.get();
}
//private
void Surface::_set_no_delete(SDL_Surface* p)
{
_surf.reset(p,[](SDL_Surface*){});
}
Surface::Surface(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask) throw(ErrorViewer)
{
if(createAs(width,height,depth,Rmask,Gmask,Bmask,Amask)!=0)
{
ErrorViewer e;
e.fetch();
throw e;
}
}
Surface::Surface(int width,int height,int depth,RGBA maskPack) throw (ErrorViewer)
: Surface(width,height,depth,maskPack.r,maskPack.g,maskPack.b,maskPack.a)
{
}
Surface::Surface(int width,int height,int depth,Uint32 surfaceFormat) throw(ErrorViewer)
{
if(createAs(width,height,depth,surfaceFormat)!=0)
{
ErrorViewer e;
e.fetch();
throw e;
}
}
Surface::Surface(const std::string& filename) throw(ErrorViewer)
{
if(loadAs(filename)!=0)
{
ErrorViewer e;
e.fetch();
throw e;
}
}
Surface::Surface(const RWOP& rwop) throw (ErrorViewer)
{
if(loadAs(rwop)!=0)
{
ErrorViewer e;
e.fetch();
throw e;
}
}
//static
Surface Surface::load(const std::string& filename)
{
Surface s;
s.loadAs(filename);
return s;
}
//static
Surface Surface::load(const RWOP& rwop)
{
Surface s;
s.loadAs(rwop);
return s;
}
//static
Surface Surface::create(int width, int height, int depth, int Rmask, int Gmask, int Bmask, int Amask)
{
Surface s;
s.create(width,height,depth,Rmask,Gmask,Bmask,Amask);
return s;
}
//static
Surface Surface::create(int width, int height, int depth, Uint32 surfaceFormat)
{
Surface s;
s.create(width,height,depth,surfaceFormat);
return s;
}
int Surface::loadAs(const std::string& filename)
{
SDL_Surface* temp=IMG_Load(filename.c_str());
if(temp==nullptr)
{
return -1;
}
else
{
_set(temp);
return 0;
}
}
int Surface::loadAs(const RWOP& rwop)
{
SDL_Surface* temp=IMG_Load_RW(rwop._get(),0);
if(temp==nullptr)
{
return -1;
}
else
{
_set(temp);
return 0;
}
}
int Surface::createAs(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask)
{
SDL_Surface* temp=SDL_CreateRGBSurface(0,width,height,depth,Rmask,Gmask,Bmask,Amask);
if(temp==nullptr)
{
return -1;
}
else
{
_set(temp);
return 0;
}
}
int Surface::createAs(int width,int height,int depth,Uint32 surfaceFormat)
{
/// FIXME: This Function is available from SDL2.0.5. But the linker report a undefined reference.
/*
SDL_Surface* temp=SDL_CreateRGBSurfaceWithFormat(0,width,height,depth,surfaceFormat);
if(temp==nullptr)
{
return -1;
}
else
{
_set(temp);
return 0;
}
*/
SDL_SetError("[MiniEngine] SDL_CreateRGBSurfaceWithFormat Not Linked.");
return -1;
}
int Surface::getw() const
{
if(_get()!=nullptr)
{
return _get()->w;
}
else
{
/// return -1 on null surface pointer
return -1;
}
}
int Surface::geth() const
{
if(_get()!=nullptr)
{
return _get()->h;
}
else
{
/// return -1 on null surface pointer
return -1;
}
}
BlendMode Surface::getBlendMode() const
{
SDL_BlendMode temp;
/// FIXME: return value are ignored.
SDL_GetSurfaceBlendMode(_get(),&temp);
return _internal::getBlendModeFromSDLBlendMode(temp);
}
int Surface::setBlendMode(BlendMode mode)
{
return SDL_SetSurfaceBlendMode(_get(),_internal::getSDLBlendModeFromBlendMode(mode));
}
int Surface::savePNG(const std::string& filename) const
{
return IMG_SavePNG(_get(),filename.c_str());
}
int Surface::blit(const Surface& s,const Rect& src,const Rect& dst)
{
SDL_Rect rsrc=src.toSDLRect();
SDL_Rect rdst=dst.toSDLRect();
return SDL_BlitSurface(s._get(),&rsrc,_get(),&rdst);
}
int Surface::blitTo(const Surface& s,const Rect& dst)
{
SDL_Rect rdst=dst.toSDLRect();
return SDL_BlitSurface(s._get(),NULL,_get(),&rdst);
}
int Surface::blitTo(const Surface& s,const Point& lupoint)
{
return blitTo(s,Rect(lupoint.x,lupoint.y,s.getw(),s.geth()));
}
int Surface::blitFill(const Surface& s,const Rect& src)
{
SDL_Rect rsrc=src.toSDLRect();
return SDL_BlitSurface(s._get(),&rsrc,_get(),NULL);
}
int Surface::blitFullFill(const Surface& s)
{
return SDL_BlitSurface(s._get(),NULL,_get(),NULL);
}
int Surface::blitScaled(const Surface& s,const Rect& src,const Rect& dst)
{
SDL_Rect rsrc=src.toSDLRect();
SDL_Rect rdst=dst.toSDLRect();
return SDL_BlitScaled(s._get(),&rsrc,_get(),&rdst);
}
int Surface::blitScaledTo(const Surface& s,const Rect& dst)
{
SDL_Rect rdst=dst.toSDLRect();
return SDL_BlitScaled(s._get(),NULL,_get(),&rdst);
}
int Surface::blitScaledTo(const Surface& s,const Point& lupoint)
{
return blitScaledTo(s,Rect(lupoint.x,lupoint.y,s.getw(),s.geth()));
}
int Surface::blitScaledFill(const Surface& s,const Rect& src)
{
SDL_Rect rsrc=src.toSDLRect();
return SDL_BlitScaled(s._get(),&rsrc,_get(),NULL);
}
int Surface::blitScaledFullFill(const Surface& s)
{
return SDL_BlitScaled(s._get(),NULL,_get(),NULL);
}
int Surface::setClipRect(const Rect& clipRect)
{
auto m=clipRect.toSDLRect();
return (SDL_SetClipRect(_get(),&m) == SDL_TRUE) ? 0 : -1;
}
Rect Surface::getClipRect() const
{
SDL_Rect rect;
SDL_GetClipRect(_get(),&rect);
return Rect(rect);
}
void Surface::disableClipping()
{
SDL_SetClipRect(_get(),NULL);
}
int Surface::setAlphaMode(int alpha)
{
return SDL_SetSurfaceAlphaMod(_get(),alpha);
}
int Surface::getAlphaMode() const
{
Uint8 al;
SDL_GetSurfaceAlphaMod(_get(),&al);
return al;
}
int Surface::setColorMode(ColorMode mode)
{
return SDL_SetSurfaceColorMod(_get(),mode.r,mode.g,mode.b);
}
ColorMode Surface::getColorMode() const
{
Uint8 r,g,b;
SDL_GetSurfaceColorMod(_get(),&r,&g,&b);
ColorMode mode;
mode.r=r;
mode.g=g;
mode.b=b;
return mode;
}
void Surface::setRGBA(const RGBA& pack)
{
setColorMode(pack.toColorMode());
setAlphaMode(pack.a);
}
RGBA Surface::getRGBA() const
{
return RGBA(getColorMode(),getAlphaMode());
}
bool Surface::mustlock() const
{
return SDL_MUSTLOCK(_get());
}
int Surface::lock()
{
return SDL_LockSurface(_get());
}
void Surface::unlock()
{
SDL_UnlockSurface(_get());
}
bool Surface::isReady() const
{
return _get()!=nullptr;
}
void Surface::release()
{
_clear();
}
/// Experimental (Not constant)
SDL_Surface* Surface::getRawPointer()
{
return _get();
}
//private //private
void Texture::_set(SDL_Texture* p) void Texture::_set(SDL_Texture* p)

View File

@ -9,22 +9,6 @@
namespace MiniEngine namespace MiniEngine
{ {
class Rect
{
public:
int x, y, w, h;
Rect(int X, int Y, int W, int H);
explicit Rect(const SDL_Rect&);
Rect();
SDL_Rect toSDLRect() const;
bool isEmpty();
bool operator == (const Rect&) const;
bool hasIntersection(const Rect&) const;
Rect getIntersection(const Rect&) const;
Rect getUnion(const Rect&) const;
};
class Point class Point
{ {
public: public:
@ -95,83 +79,6 @@ namespace MiniEngine
enum class BlendMode { None,Blend,Add,Mod }; enum class BlendMode { None,Blend,Add,Mod };
class Surface
{
public:
Surface()=default;
Surface(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask) throw(ErrorViewer);
Surface(int width,int height,int depth,RGBA colorPack) throw(ErrorViewer);
Surface(int width,int height,int depth,Uint32 surfaceFormat) throw(ErrorViewer);
Surface(const std::string& filename) throw(ErrorViewer);
Surface(const RWOP& rwop) throw(ErrorViewer);
~Surface() = default;
/// static functions
static Surface load(const std::string& filename);
static Surface load(const RWOP& rwop);
static Surface create(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask);
static Surface create(int width,int height,int depth,Uint32 surfaceFormat);
/// xxxAs will clear the current surface if loaded or created successfully.
int loadAs(const std::string& filename);
int loadAs(const RWOP& rwop);
int createAs(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask);
int createAs(int width,int height,int depth,Uint32 surfaceFormat);
int savePNG(const std::string& filename) const;
int getw() const;
int geth() const;
BlendMode getBlendMode() const;
int setBlendMode(BlendMode mode);
/// Rendering functions. Copy an external surface to this surface. So it has no constant attribute.
int blit(const Surface& s,const Rect& src,const Rect& dst);
int blitTo(const Surface& t, const Rect& dst);
int blitTo(const Surface& t, const Point& lupoint);
int blitFill(const Surface& t, const Rect& src);
int blitFullFill(const Surface& t);
int blitScaled(const Surface& s,const Rect& src,const Rect& dst);
int blitScaledTo(const Surface& t, const Rect& dst);
int blitScaledTo(const Surface& t, const Point& lupoint);
int blitScaledFill(const Surface& t, const Rect& src);
int blitScaledFullFill(const Surface& t);
int setClipRect(const Rect& clipRect);
Rect getClipRect() const;
void disableClipping();
int setAlphaMode(int alpha);
int getAlphaMode() const;
ColorMode getColorMode() const;
int setColorMode(ColorMode mode);
RGBA getRGBA() const;
void setRGBA(const RGBA& pack);
bool mustlock() const;
int lock();
void unlock();
bool isReady() const;
void release();
/// Experimental : Get SDL_Surface Pointer and then do anything you want!
/// In case you can do anything with this pointer, this function should not has constant attribute.
SDL_Surface* getRawPointer();
private:
std::shared_ptr<SDL_Surface> _surf;
void _set(SDL_Surface*);
void _set_no_delete(SDL_Surface*);
void _clear();
SDL_Surface* _get() const;
friend class Window;
friend class Renderer;
friend class Font;
friend class Cursor;
};
class Texture class Texture
{ {
public: public:

71
SDLWrapper/Rect.cpp Normal file
View File

@ -0,0 +1,71 @@
#include "Rect.h"
#include "begin_code.h"
Rect::Rect(int X, int Y, int W, int H)
{
x = X;
y = Y;
w = W;
h = H;
}
Rect::Rect(const SDL_Rect& r):Rect(r.x,r.y,r.w,r.h)
{
}
Rect::Rect()
{
x = y = w = h = 0;
}
SDL_Rect Rect::toSDLRect() const
{
SDL_Rect r;
r.x = x;
r.y = y;
r.w = w;
r.h = h;
return r;
}
bool Rect::isEmpty()
{
SDL_Rect r=toSDLRect();
return SDL_RectEmpty(&r)==SDL_TRUE;
}
bool Rect::operator == (const Rect& r) const
{
SDL_Rect a=toSDLRect(),b=r.toSDLRect();
return SDL_RectEquals(&a,&b)==SDL_TRUE;
}
bool Rect::hasIntersection(const Rect& r) const
{
SDL_Rect a=toSDLRect(),b=r.toSDLRect();
return SDL_HasIntersection(&a,&b)==SDL_TRUE;
}
Rect Rect::getIntersection(const Rect& r) const
{
SDL_Rect a=toSDLRect(),b=r.toSDLRect(),c;
if(SDL_IntersectRect(&a,&b,&c)==SDL_TRUE)
{
return Rect(c);
}
else
{
return Rect();
}
}
Rect Rect::getUnion(const Rect& r) const
{
SDL_Rect a=toSDLRect(),b=r.toSDLRect(),c;
SDL_UnionRect(&a,&b,&c);//void
return Rect(c);
}
#include "end_code.h"

21
SDLWrapper/Rect.h Normal file
View File

@ -0,0 +1,21 @@
#pragma once
#include "include.h"
#include "begin_code.h"
class Rect
{
public:
int x, y, w, h;
Rect(int X, int Y, int W, int H);
explicit Rect(const SDL_Rect&);
Rect();
SDL_Rect toSDLRect() const;
bool isEmpty();
bool operator == (const Rect&) const;
bool hasIntersection(const Rect&) const;
Rect getIntersection(const Rect&) const;
Rect getUnion(const Rect&) const;
};
#include "end_code.h"

358
SDLWrapper/Surface.cpp Normal file
View File

@ -0,0 +1,358 @@
#include "Surface.h"
#include "begin_code.h"
//private
void Surface::_set(SDL_Surface* p)
{
_surf.reset(p,SDL_FreeSurface);
}
//private
void Surface::_clear()
{
_surf.reset();
}
//private
SDL_Surface* Surface::_get() const
{
return _surf.get();
}
//private
void Surface::_set_no_delete(SDL_Surface* p)
{
_surf.reset(p,[](SDL_Surface*) {});
}
Surface::Surface(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask) throw(ErrorViewer)
{
if(createAs(width,height,depth,Rmask,Gmask,Bmask,Amask)!=0)
{
ErrorViewer e;
e.fetch();
throw e;
}
}
Surface::Surface(int width,int height,int depth,RGBA maskPack) throw (ErrorViewer)
: Surface(width,height,depth,maskPack.r,maskPack.g,maskPack.b,maskPack.a)
{
}
Surface::Surface(int width,int height,int depth,Uint32 surfaceFormat) throw(ErrorViewer)
{
if(createAs(width,height,depth,surfaceFormat)!=0)
{
ErrorViewer e;
e.fetch();
throw e;
}
}
Surface::Surface(const std::string& filename) throw(ErrorViewer)
{
if(loadAs(filename)!=0)
{
ErrorViewer e;
e.fetch();
throw e;
}
}
Surface::Surface(const RWOP& rwop) throw (ErrorViewer)
{
if(loadAs(rwop)!=0)
{
ErrorViewer e;
e.fetch();
throw e;
}
}
//static
Surface Surface::load(const std::string& filename)
{
Surface s;
s.loadAs(filename);
return s;
}
//static
Surface Surface::load(const RWOP& rwop)
{
Surface s;
s.loadAs(rwop);
return s;
}
//static
Surface Surface::create(int width, int height, int depth, int Rmask, int Gmask, int Bmask, int Amask)
{
Surface s;
s.create(width,height,depth,Rmask,Gmask,Bmask,Amask);
return s;
}
//static
Surface Surface::create(int width, int height, int depth, Uint32 surfaceFormat)
{
Surface s;
s.create(width,height,depth,surfaceFormat);
return s;
}
int Surface::loadAs(const std::string& filename)
{
SDL_Surface* temp=IMG_Load(filename.c_str());
if(temp==nullptr)
{
return -1;
}
else
{
_set(temp);
return 0;
}
}
int Surface::loadAs(const RWOP& rwop)
{
SDL_Surface* temp=IMG_Load_RW(rwop._get(),0);
if(temp==nullptr)
{
return -1;
}
else
{
_set(temp);
return 0;
}
}
int Surface::createAs(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask)
{
SDL_Surface* temp=SDL_CreateRGBSurface(0,width,height,depth,Rmask,Gmask,Bmask,Amask);
if(temp==nullptr)
{
return -1;
}
else
{
_set(temp);
return 0;
}
}
int Surface::createAs(int width,int height,int depth,Uint32 surfaceFormat)
{
/// FIXME: This Function is available from SDL2.0.5. But the linker report a undefined reference.
/*
SDL_Surface* temp=SDL_CreateRGBSurfaceWithFormat(0,width,height,depth,surfaceFormat);
if(temp==nullptr)
{
return -1;
}
else
{
_set(temp);
return 0;
}
*/
SDL_SetError("[MiniEngine] SDL_CreateRGBSurfaceWithFormat Not Linked.");
return -1;
}
int Surface::getw() const
{
if(_get()!=nullptr)
{
return _get()->w;
}
else
{
/// return -1 on null surface pointer
return -1;
}
}
int Surface::geth() const
{
if(_get()!=nullptr)
{
return _get()->h;
}
else
{
/// return -1 on null surface pointer
return -1;
}
}
BlendMode Surface::getBlendMode() const
{
SDL_BlendMode temp;
/// FIXME: return value are ignored.
SDL_GetSurfaceBlendMode(_get(),&temp);
return _internal::getBlendModeFromSDLBlendMode(temp);
}
int Surface::setBlendMode(BlendMode mode)
{
return SDL_SetSurfaceBlendMode(_get(),_internal::getSDLBlendModeFromBlendMode(mode));
}
int Surface::savePNG(const std::string& filename) const
{
return IMG_SavePNG(_get(),filename.c_str());
}
int Surface::blit(const Surface& s,const Rect& src,const Rect& dst)
{
SDL_Rect rsrc=src.toSDLRect();
SDL_Rect rdst=dst.toSDLRect();
return SDL_BlitSurface(s._get(),&rsrc,_get(),&rdst);
}
int Surface::blitTo(const Surface& s,const Rect& dst)
{
SDL_Rect rdst=dst.toSDLRect();
return SDL_BlitSurface(s._get(),NULL,_get(),&rdst);
}
int Surface::blitTo(const Surface& s,const Point& lupoint)
{
return blitTo(s,Rect(lupoint.x,lupoint.y,s.getw(),s.geth()));
}
int Surface::blitFill(const Surface& s,const Rect& src)
{
SDL_Rect rsrc=src.toSDLRect();
return SDL_BlitSurface(s._get(),&rsrc,_get(),NULL);
}
int Surface::blitFullFill(const Surface& s)
{
return SDL_BlitSurface(s._get(),NULL,_get(),NULL);
}
int Surface::blitScaled(const Surface& s,const Rect& src,const Rect& dst)
{
SDL_Rect rsrc=src.toSDLRect();
SDL_Rect rdst=dst.toSDLRect();
return SDL_BlitScaled(s._get(),&rsrc,_get(),&rdst);
}
int Surface::blitScaledTo(const Surface& s,const Rect& dst)
{
SDL_Rect rdst=dst.toSDLRect();
return SDL_BlitScaled(s._get(),NULL,_get(),&rdst);
}
int Surface::blitScaledTo(const Surface& s,const Point& lupoint)
{
return blitScaledTo(s,Rect(lupoint.x,lupoint.y,s.getw(),s.geth()));
}
int Surface::blitScaledFill(const Surface& s,const Rect& src)
{
SDL_Rect rsrc=src.toSDLRect();
return SDL_BlitScaled(s._get(),&rsrc,_get(),NULL);
}
int Surface::blitScaledFullFill(const Surface& s)
{
return SDL_BlitScaled(s._get(),NULL,_get(),NULL);
}
int Surface::setClipRect(const Rect& clipRect)
{
auto m=clipRect.toSDLRect();
return (SDL_SetClipRect(_get(),&m) == SDL_TRUE) ? 0 : -1;
}
Rect Surface::getClipRect() const
{
SDL_Rect rect;
SDL_GetClipRect(_get(),&rect);
return Rect(rect);
}
void Surface::disableClipping()
{
SDL_SetClipRect(_get(),NULL);
}
int Surface::setAlphaMode(int alpha)
{
return SDL_SetSurfaceAlphaMod(_get(),alpha);
}
int Surface::getAlphaMode() const
{
Uint8 al;
SDL_GetSurfaceAlphaMod(_get(),&al);
return al;
}
int Surface::setColorMode(ColorMode mode)
{
return SDL_SetSurfaceColorMod(_get(),mode.r,mode.g,mode.b);
}
ColorMode Surface::getColorMode() const
{
Uint8 r,g,b;
SDL_GetSurfaceColorMod(_get(),&r,&g,&b);
ColorMode mode;
mode.r=r;
mode.g=g;
mode.b=b;
return mode;
}
void Surface::setRGBA(const RGBA& pack)
{
setColorMode(pack.toColorMode());
setAlphaMode(pack.a);
}
RGBA Surface::getRGBA() const
{
return RGBA(getColorMode(),getAlphaMode());
}
bool Surface::mustlock() const
{
return SDL_MUSTLOCK(_get());
}
int Surface::lock()
{
return SDL_LockSurface(_get());
}
void Surface::unlock()
{
SDL_UnlockSurface(_get());
}
bool Surface::isReady() const
{
return _get()!=nullptr;
}
void Surface::release()
{
_clear();
}
/// Experimental (Not constant)
SDL_Surface* Surface::getRawPointer()
{
return _get();
}
#include "end_code.h"

83
SDLWrapper/Surface.h Normal file
View File

@ -0,0 +1,83 @@
#pragma once
#include "include.h"
#include "begin_code.h"
class Surface
{
public:
Surface()=default;
Surface(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask) throw(ErrorViewer);
Surface(int width,int height,int depth,RGBA colorPack) throw(ErrorViewer);
Surface(int width,int height,int depth,Uint32 surfaceFormat) throw(ErrorViewer);
Surface(const std::string& filename) throw(ErrorViewer);
Surface(const RWOP& rwop) throw(ErrorViewer);
~Surface() = default;
/// static functions
static Surface load(const std::string& filename);
static Surface load(const RWOP& rwop);
static Surface create(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask);
static Surface create(int width,int height,int depth,Uint32 surfaceFormat);
/// xxxAs will clear the current surface if loaded or created successfully.
int loadAs(const std::string& filename);
int loadAs(const RWOP& rwop);
int createAs(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask);
int createAs(int width,int height,int depth,Uint32 surfaceFormat);
int savePNG(const std::string& filename) const;
int getw() const;
int geth() const;
BlendMode getBlendMode() const;
int setBlendMode(BlendMode mode);
/// Rendering functions. Copy an external surface to this surface. So it has no constant attribute.
int blit(const Surface& s,const Rect& src,const Rect& dst);
int blitTo(const Surface& t, const Rect& dst);
int blitTo(const Surface& t, const Point& lupoint);
int blitFill(const Surface& t, const Rect& src);
int blitFullFill(const Surface& t);
int blitScaled(const Surface& s,const Rect& src,const Rect& dst);
int blitScaledTo(const Surface& t, const Rect& dst);
int blitScaledTo(const Surface& t, const Point& lupoint);
int blitScaledFill(const Surface& t, const Rect& src);
int blitScaledFullFill(const Surface& t);
int setClipRect(const Rect& clipRect);
Rect getClipRect() const;
void disableClipping();
int setAlphaMode(int alpha);
int getAlphaMode() const;
ColorMode getColorMode() const;
int setColorMode(ColorMode mode);
RGBA getRGBA() const;
void setRGBA(const RGBA& pack);
bool mustlock() const;
int lock();
void unlock();
bool isReady() const;
void release();
/// Experimental : Get SDL_Surface Pointer and then do anything you want!
/// In case you can do anything with this pointer, this function should not has constant attribute.
SDL_Surface* getRawPointer();
private:
std::shared_ptr<SDL_Surface> _surf;
void _set(SDL_Surface*);
void _set_no_delete(SDL_Surface*);
void _clear();
SDL_Surface* _get() const;
friend class Window;
friend class Renderer;
friend class Font;
friend class Cursor;
};
#include "end_code.h"

5
SDLWrapper/begin_code.h Normal file
View File

@ -0,0 +1,5 @@
namespace MiniEngine
{
inline namespace _SDLWrapper
{

3
SDLWrapper/end_code.h Normal file
View File

@ -0,0 +1,3 @@
} /// End of namespace MiniEngine::_SDLWrapper
} /// End of namespace MiniEngine

8
SDLWrapper/include.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
/// Include SDL Library Headers.
#include <SDL2/SDL.h>
#undef main
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_mixer.h>