mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
Add more functions to class Surface
This commit is contained in:
parent
1b2ba7b2d8
commit
79b97736b4
168
MiniEngine.cpp
168
MiniEngine.cpp
|
@ -376,7 +376,7 @@ namespace MiniEngine
|
|||
}
|
||||
|
||||
// private
|
||||
SDL_RWops* RWOP::_get()
|
||||
SDL_RWops* RWOP::_get() const
|
||||
{
|
||||
return _op.get();
|
||||
}
|
||||
|
@ -412,17 +412,20 @@ namespace MiniEngine
|
|||
_clear();
|
||||
}
|
||||
|
||||
void Surface::_set(SDL_Surface* p)//private
|
||||
//private
|
||||
void Surface::_set(SDL_Surface* p)
|
||||
{
|
||||
_surf.reset(p,SDL_FreeSurface);
|
||||
}
|
||||
|
||||
void Surface::_clear()//private
|
||||
//private
|
||||
void Surface::_clear()
|
||||
{
|
||||
_surf.reset();
|
||||
}
|
||||
|
||||
SDL_Surface* Surface::_get()//private
|
||||
//private
|
||||
SDL_Surface* Surface::_get() const
|
||||
{
|
||||
return _surf.get();
|
||||
}
|
||||
|
@ -432,6 +435,115 @@ namespace MiniEngine
|
|||
return _surf;
|
||||
}
|
||||
|
||||
Surface::Surface(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask) throw(ErrorViewer)
|
||||
{
|
||||
if(create(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(create(width,height,depth,surfaceFormat)!=0)
|
||||
{
|
||||
ErrorViewer e;
|
||||
e.fetch();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Surface::Surface(const std::string& filename) throw(ErrorViewer)
|
||||
{
|
||||
if(load(filename)!=0)
|
||||
{
|
||||
ErrorViewer e;
|
||||
e.fetch();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Surface::Surface(const RWOP& rwop) throw (ErrorViewer)
|
||||
{
|
||||
if(load(rwop)!=0)
|
||||
{
|
||||
ErrorViewer e;
|
||||
e.fetch();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
int Surface::load(const std::string& filename)
|
||||
{
|
||||
SDL_Surface* temp=IMG_Load(filename.c_str());
|
||||
if(temp==nullptr)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_set(temp);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int Surface::load(const RWOP& rwop)
|
||||
{
|
||||
SDL_Surface* temp=IMG_Load_RW(rwop._get(),0);
|
||||
if(temp==nullptr)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_set(temp);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int Surface::create(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::create(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()
|
||||
{
|
||||
if(_get()!=nullptr)
|
||||
|
@ -588,19 +700,9 @@ namespace MiniEngine
|
|||
SDL_UnlockSurface(_get());
|
||||
}
|
||||
|
||||
//static
|
||||
Surface Surface::createSurface(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask) throw(ErrorViewer)
|
||||
bool Surface::isReady() const
|
||||
{
|
||||
SDL_Surface* temp=SDL_CreateRGBSurface(0,width,height,depth,Rmask,Gmask,Bmask,Amask);
|
||||
if(temp==nullptr)
|
||||
{
|
||||
ErrorViewer e;
|
||||
e.fetch();
|
||||
throw e;
|
||||
}
|
||||
Surface surf;
|
||||
surf._set(temp);
|
||||
return surf;
|
||||
return _get()!=nullptr;
|
||||
}
|
||||
|
||||
void Surface::release()
|
||||
|
@ -608,6 +710,12 @@ namespace MiniEngine
|
|||
_clear();
|
||||
}
|
||||
|
||||
/// Experimental
|
||||
SDL_Surface* Surface::getRawPointer()
|
||||
{
|
||||
return _get();
|
||||
}
|
||||
|
||||
void Texture::_set(SDL_Texture* p)//private
|
||||
{
|
||||
_text.reset(p,SDL_DestroyTexture);
|
||||
|
@ -871,34 +979,6 @@ namespace MiniEngine
|
|||
return SDL_RenderCopyEx(_get(),t._get(),pR1,pR2,angle,pPoint,flip);
|
||||
}
|
||||
|
||||
Surface Renderer::loadSurface(std::string FileName) throw(ErrorViewer)
|
||||
{
|
||||
Surface surf;
|
||||
SDL_Surface* temp = IMG_Load(FileName.c_str());
|
||||
if (temp == nullptr)
|
||||
{
|
||||
ErrorViewer e;
|
||||
e.fetch();
|
||||
throw e;
|
||||
}
|
||||
surf._set(temp);
|
||||
return surf;
|
||||
}
|
||||
|
||||
Surface Renderer::loadSurfaceRW(RWOP rwop) throw (ErrorViewer)
|
||||
{
|
||||
Surface surf;
|
||||
SDL_Surface* temp=IMG_Load_RW(rwop._get(),0);
|
||||
if(temp==nullptr)
|
||||
{
|
||||
ErrorViewer e;
|
||||
e.fetch();
|
||||
throw e;
|
||||
}
|
||||
surf._set(temp);
|
||||
return surf;
|
||||
}
|
||||
|
||||
Texture Renderer::render(Surface surf) throw(ErrorViewer)
|
||||
{
|
||||
Texture t;
|
||||
|
|
28
MiniEngine.h
28
MiniEngine.h
|
@ -84,9 +84,10 @@ namespace MiniEngine
|
|||
void release();
|
||||
private:
|
||||
std::shared_ptr<SDL_RWops> _op;
|
||||
SDL_RWops* _get();
|
||||
SDL_RWops* _get() const;
|
||||
void _clear();
|
||||
void _set(SDL_RWops*);
|
||||
friend class Surface;
|
||||
friend class Renderer;
|
||||
};
|
||||
|
||||
|
@ -95,7 +96,20 @@ namespace MiniEngine
|
|||
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;
|
||||
|
||||
int load(const std::string& filename);
|
||||
int load(const RWOP& rwop);
|
||||
|
||||
int create(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask);
|
||||
int create(int width,int height,int depth,Uint32 surfaceFormat);
|
||||
|
||||
int savePNG(const std::string& filename);
|
||||
int getw();
|
||||
int geth();
|
||||
|
@ -126,16 +140,16 @@ namespace MiniEngine
|
|||
int lock();
|
||||
void unlock();
|
||||
|
||||
static Surface createSurface(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask) throw(ErrorViewer);
|
||||
|
||||
bool isReady() const;
|
||||
void release();
|
||||
protected:
|
||||
Surface() = default;
|
||||
|
||||
/// Experimental : Get SDL_Surface Pointer and then do anything you want!
|
||||
SDL_Surface* getRawPointer();
|
||||
private:
|
||||
std::shared_ptr<SDL_Surface> _surf;
|
||||
void _set(SDL_Surface*);
|
||||
void _clear();
|
||||
SDL_Surface* _get();
|
||||
SDL_Surface* _get() const;
|
||||
std::shared_ptr<SDL_Surface>& _getex();
|
||||
|
||||
friend class Window;
|
||||
|
@ -208,8 +222,6 @@ namespace MiniEngine
|
|||
|
||||
int supercopy(Texture t,bool srcfull,Rect src,bool dstfull,Rect dst,double angle,bool haspoint,Point center,FlipMode mode);
|
||||
|
||||
Surface loadSurface(std::string FileName) throw(ErrorViewer);
|
||||
Surface loadSurfaceRW(RWOP rwop) throw(ErrorViewer);
|
||||
Texture render(Surface surf) throw (ErrorViewer);
|
||||
Texture loadTexture(std::string FileName) throw(ErrorViewer);
|
||||
Texture loadTextureRW(RWOP rwop) throw(ErrorViewer);
|
||||
|
|
Loading…
Reference in New Issue
Block a user