mirror of
https://github.com/Kiritow/MiniEngine.git
synced 2024-03-22 13:11:22 +08:00
Update constant attribute to functions in class Surface
This commit is contained in:
parent
9019971e19
commit
5581a57e1b
|
@ -441,7 +441,7 @@ namespace MiniEngine
|
||||||
|
|
||||||
Surface::Surface(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask) throw(ErrorViewer)
|
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)
|
if(createAs(width,height,depth,Rmask,Gmask,Bmask,Amask)!=0)
|
||||||
{
|
{
|
||||||
ErrorViewer e;
|
ErrorViewer e;
|
||||||
e.fetch();
|
e.fetch();
|
||||||
|
@ -457,7 +457,7 @@ namespace MiniEngine
|
||||||
|
|
||||||
Surface::Surface(int width,int height,int depth,Uint32 surfaceFormat) throw(ErrorViewer)
|
Surface::Surface(int width,int height,int depth,Uint32 surfaceFormat) throw(ErrorViewer)
|
||||||
{
|
{
|
||||||
if(create(width,height,depth,surfaceFormat)!=0)
|
if(createAs(width,height,depth,surfaceFormat)!=0)
|
||||||
{
|
{
|
||||||
ErrorViewer e;
|
ErrorViewer e;
|
||||||
e.fetch();
|
e.fetch();
|
||||||
|
@ -467,7 +467,7 @@ namespace MiniEngine
|
||||||
|
|
||||||
Surface::Surface(const std::string& filename) throw(ErrorViewer)
|
Surface::Surface(const std::string& filename) throw(ErrorViewer)
|
||||||
{
|
{
|
||||||
if(load(filename)!=0)
|
if(loadAs(filename)!=0)
|
||||||
{
|
{
|
||||||
ErrorViewer e;
|
ErrorViewer e;
|
||||||
e.fetch();
|
e.fetch();
|
||||||
|
@ -477,7 +477,7 @@ namespace MiniEngine
|
||||||
|
|
||||||
Surface::Surface(const RWOP& rwop) throw (ErrorViewer)
|
Surface::Surface(const RWOP& rwop) throw (ErrorViewer)
|
||||||
{
|
{
|
||||||
if(load(rwop)!=0)
|
if(loadAs(rwop)!=0)
|
||||||
{
|
{
|
||||||
ErrorViewer e;
|
ErrorViewer e;
|
||||||
e.fetch();
|
e.fetch();
|
||||||
|
@ -485,7 +485,7 @@ namespace MiniEngine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::load(const std::string& filename)
|
int Surface::loadAs(const std::string& filename)
|
||||||
{
|
{
|
||||||
SDL_Surface* temp=IMG_Load(filename.c_str());
|
SDL_Surface* temp=IMG_Load(filename.c_str());
|
||||||
if(temp==nullptr)
|
if(temp==nullptr)
|
||||||
|
@ -499,7 +499,7 @@ namespace MiniEngine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::load(const RWOP& rwop)
|
int Surface::loadAs(const RWOP& rwop)
|
||||||
{
|
{
|
||||||
SDL_Surface* temp=IMG_Load_RW(rwop._get(),0);
|
SDL_Surface* temp=IMG_Load_RW(rwop._get(),0);
|
||||||
if(temp==nullptr)
|
if(temp==nullptr)
|
||||||
|
@ -513,7 +513,7 @@ namespace MiniEngine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::create(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask)
|
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);
|
SDL_Surface* temp=SDL_CreateRGBSurface(0,width,height,depth,Rmask,Gmask,Bmask,Amask);
|
||||||
if(temp==nullptr)
|
if(temp==nullptr)
|
||||||
|
@ -527,7 +527,7 @@ namespace MiniEngine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::create(int width,int height,int depth,Uint32 surfaceFormat)
|
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.
|
/// FIXME: This Function is available from SDL2.0.5. But the linker report a undefined reference.
|
||||||
|
|
||||||
|
@ -548,7 +548,7 @@ namespace MiniEngine
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::getw()
|
int Surface::getw() const
|
||||||
{
|
{
|
||||||
if(_get()!=nullptr)
|
if(_get()!=nullptr)
|
||||||
{
|
{
|
||||||
|
@ -561,7 +561,7 @@ namespace MiniEngine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::geth()
|
int Surface::geth() const
|
||||||
{
|
{
|
||||||
if(_get()!=nullptr)
|
if(_get()!=nullptr)
|
||||||
{
|
{
|
||||||
|
@ -574,7 +574,7 @@ namespace MiniEngine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BlendMode Surface::getBlendMode()
|
BlendMode Surface::getBlendMode() const
|
||||||
{
|
{
|
||||||
SDL_BlendMode temp;
|
SDL_BlendMode temp;
|
||||||
/// FIXME: return value are ignored.
|
/// FIXME: return value are ignored.
|
||||||
|
@ -587,65 +587,65 @@ namespace MiniEngine
|
||||||
return SDL_SetSurfaceBlendMode(_get(),_internal::getSDLBlendModeFromBlendMode(mode));
|
return SDL_SetSurfaceBlendMode(_get(),_internal::getSDLBlendModeFromBlendMode(mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::savePNG(const std::string& filename)
|
int Surface::savePNG(const std::string& filename) const
|
||||||
{
|
{
|
||||||
return IMG_SavePNG(_get(),filename.c_str());
|
return IMG_SavePNG(_get(),filename.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::blit(Surface s,Rect src,Rect dst)
|
int Surface::blit(const Surface& s,Rect src,Rect dst)
|
||||||
{
|
{
|
||||||
SDL_Rect rsrc=src.toSDLRect();
|
SDL_Rect rsrc=src.toSDLRect();
|
||||||
SDL_Rect rdst=dst.toSDLRect();
|
SDL_Rect rdst=dst.toSDLRect();
|
||||||
return SDL_BlitSurface(s._get(),&rsrc,_get(),&rdst);
|
return SDL_BlitSurface(s._get(),&rsrc,_get(),&rdst);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::blitTo(Surface s,Rect dst)
|
int Surface::blitTo(const Surface& s,Rect dst)
|
||||||
{
|
{
|
||||||
SDL_Rect rdst=dst.toSDLRect();
|
SDL_Rect rdst=dst.toSDLRect();
|
||||||
return SDL_BlitSurface(s._get(),NULL,_get(),&rdst);
|
return SDL_BlitSurface(s._get(),NULL,_get(),&rdst);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::blitTo(Surface s,Point lupoint)
|
int Surface::blitTo(const Surface& s,Point lupoint)
|
||||||
{
|
{
|
||||||
return blitTo(s,Rect(lupoint.x,lupoint.y,s.getw(),s.geth()));
|
return blitTo(s,Rect(lupoint.x,lupoint.y,s.getw(),s.geth()));
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::blitFill(Surface s,Rect src)
|
int Surface::blitFill(const Surface& s,Rect src)
|
||||||
{
|
{
|
||||||
SDL_Rect rsrc=src.toSDLRect();
|
SDL_Rect rsrc=src.toSDLRect();
|
||||||
return SDL_BlitSurface(s._get(),&rsrc,_get(),NULL);
|
return SDL_BlitSurface(s._get(),&rsrc,_get(),NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::blitFullFill(Surface s)
|
int Surface::blitFullFill(const Surface& s)
|
||||||
{
|
{
|
||||||
return SDL_BlitSurface(s._get(),NULL,_get(),NULL);
|
return SDL_BlitSurface(s._get(),NULL,_get(),NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::blitScaled(Surface s,Rect src,Rect dst)
|
int Surface::blitScaled(const Surface& s,Rect src,Rect dst)
|
||||||
{
|
{
|
||||||
SDL_Rect rsrc=src.toSDLRect();
|
SDL_Rect rsrc=src.toSDLRect();
|
||||||
SDL_Rect rdst=dst.toSDLRect();
|
SDL_Rect rdst=dst.toSDLRect();
|
||||||
return SDL_BlitScaled(s._get(),&rsrc,_get(),&rdst);
|
return SDL_BlitScaled(s._get(),&rsrc,_get(),&rdst);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::blitScaledTo(Surface s,Rect dst)
|
int Surface::blitScaledTo(const Surface& s,Rect dst)
|
||||||
{
|
{
|
||||||
SDL_Rect rdst=dst.toSDLRect();
|
SDL_Rect rdst=dst.toSDLRect();
|
||||||
return SDL_BlitScaled(s._get(),NULL,_get(),&rdst);
|
return SDL_BlitScaled(s._get(),NULL,_get(),&rdst);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::blitScaledTo(Surface s,Point lupoint)
|
int Surface::blitScaledTo(const Surface& s,Point lupoint)
|
||||||
{
|
{
|
||||||
return blitScaledTo(s,Rect(lupoint.x,lupoint.y,s.getw(),s.geth()));
|
return blitScaledTo(s,Rect(lupoint.x,lupoint.y,s.getw(),s.geth()));
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::blitScaledFill(Surface s,Rect src)
|
int Surface::blitScaledFill(const Surface& s,Rect src)
|
||||||
{
|
{
|
||||||
SDL_Rect rsrc=src.toSDLRect();
|
SDL_Rect rsrc=src.toSDLRect();
|
||||||
return SDL_BlitScaled(s._get(),&rsrc,_get(),NULL);
|
return SDL_BlitScaled(s._get(),&rsrc,_get(),NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::blitScaledFullFill(Surface s)
|
int Surface::blitScaledFullFill(const Surface& s)
|
||||||
{
|
{
|
||||||
return SDL_BlitScaled(s._get(),NULL,_get(),NULL);
|
return SDL_BlitScaled(s._get(),NULL,_get(),NULL);
|
||||||
}
|
}
|
||||||
|
@ -673,7 +673,7 @@ namespace MiniEngine
|
||||||
return SDL_SetSurfaceAlphaMod(_get(),alpha);
|
return SDL_SetSurfaceAlphaMod(_get(),alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Surface::getAlphaMode()
|
int Surface::getAlphaMode() const
|
||||||
{
|
{
|
||||||
Uint8 al;
|
Uint8 al;
|
||||||
SDL_GetSurfaceAlphaMod(_get(),&al);
|
SDL_GetSurfaceAlphaMod(_get(),&al);
|
||||||
|
@ -685,7 +685,7 @@ namespace MiniEngine
|
||||||
return SDL_SetSurfaceColorMod(_get(),mode.r,mode.g,mode.b);
|
return SDL_SetSurfaceColorMod(_get(),mode.r,mode.g,mode.b);
|
||||||
}
|
}
|
||||||
|
|
||||||
ColorMode Surface::getColorMode()
|
ColorMode Surface::getColorMode() const
|
||||||
{
|
{
|
||||||
Uint8 r,g,b;
|
Uint8 r,g,b;
|
||||||
SDL_GetSurfaceColorMod(_get(),&r,&g,&b);
|
SDL_GetSurfaceColorMod(_get(),&r,&g,&b);
|
||||||
|
@ -702,12 +702,12 @@ namespace MiniEngine
|
||||||
setAlphaMode(pack.a);
|
setAlphaMode(pack.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
RGBA Surface::getRGBA()
|
RGBA Surface::getRGBA() const
|
||||||
{
|
{
|
||||||
return RGBA(getColorMode(),getAlphaMode());
|
return RGBA(getColorMode(),getAlphaMode());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Surface::mustlock()
|
bool Surface::mustlock() const
|
||||||
{
|
{
|
||||||
return SDL_MUSTLOCK(_get());
|
return SDL_MUSTLOCK(_get());
|
||||||
}
|
}
|
||||||
|
@ -732,8 +732,8 @@ namespace MiniEngine
|
||||||
_clear();
|
_clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Experimental
|
/// Experimental (Not constant)
|
||||||
SDL_Surface* Surface::getRawPointer() const
|
SDL_Surface* Surface::getRawPointer()
|
||||||
{
|
{
|
||||||
return _get();
|
return _get();
|
||||||
}
|
}
|
||||||
|
|
54
MiniEngine.h
54
MiniEngine.h
|
@ -106,43 +106,50 @@ namespace MiniEngine
|
||||||
Surface(const RWOP& rwop) throw(ErrorViewer);
|
Surface(const RWOP& rwop) throw(ErrorViewer);
|
||||||
~Surface() = default;
|
~Surface() = default;
|
||||||
|
|
||||||
int load(const std::string& filename);
|
/// static functions
|
||||||
int load(const RWOP& rwop);
|
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);
|
||||||
|
|
||||||
int create(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask);
|
/// xxxAs will clear the current surface if loaded or created successfully.
|
||||||
int create(int width,int height,int depth,Uint32 surfaceFormat);
|
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);
|
int savePNG(const std::string& filename) const;
|
||||||
int getw();
|
int getw() const;
|
||||||
int geth();
|
int geth() const;
|
||||||
BlendMode getBlendMode();
|
BlendMode getBlendMode() const;
|
||||||
int setBlendMode(BlendMode mode);
|
int setBlendMode(BlendMode mode);
|
||||||
|
|
||||||
int blit(Surface s,Rect src,Rect dst);
|
/// Rendering functions. Copy an external surface to this surface. So it has no constant attribute.
|
||||||
int blitTo(Surface t, Rect dst);
|
int blit(const Surface& s,Rect src,Rect dst);
|
||||||
int blitTo(Surface t, Point lupoint);
|
int blitTo(const Surface& t, Rect dst);
|
||||||
int blitFill(Surface t, Rect src);
|
int blitTo(const Surface& t, Point lupoint);
|
||||||
int blitFullFill(Surface t);
|
int blitFill(const Surface& t, Rect src);
|
||||||
|
int blitFullFill(const Surface& t);
|
||||||
|
|
||||||
int blitScaled(Surface s,Rect src,Rect dst);
|
int blitScaled(const Surface& s,Rect src,Rect dst);
|
||||||
int blitScaledTo(Surface t, Rect dst);
|
int blitScaledTo(const Surface& t, Rect dst);
|
||||||
int blitScaledTo(Surface t, Point lupoint);
|
int blitScaledTo(const Surface& t, Point lupoint);
|
||||||
int blitScaledFill(Surface t, Rect src);
|
int blitScaledFill(const Surface& t, Rect src);
|
||||||
int blitScaledFullFill(Surface t);
|
int blitScaledFullFill(const Surface& t);
|
||||||
|
|
||||||
int setClipRect(const Rect& clipRect);
|
int setClipRect(const Rect& clipRect);
|
||||||
Rect getClipRect() const;
|
Rect getClipRect() const;
|
||||||
void disableClipping();
|
void disableClipping();
|
||||||
|
|
||||||
int setAlphaMode(int alpha);
|
int setAlphaMode(int alpha);
|
||||||
int getAlphaMode();
|
int getAlphaMode() const;
|
||||||
|
|
||||||
ColorMode getColorMode();
|
ColorMode getColorMode() const;
|
||||||
int setColorMode(ColorMode mode);
|
int setColorMode(ColorMode mode);
|
||||||
RGBA getRGBA();
|
RGBA getRGBA() const;
|
||||||
void setRGBA(RGBA pack);
|
void setRGBA(RGBA pack);
|
||||||
|
|
||||||
bool mustlock();
|
bool mustlock() const;
|
||||||
int lock();
|
int lock();
|
||||||
void unlock();
|
void unlock();
|
||||||
|
|
||||||
|
@ -150,7 +157,8 @@ namespace MiniEngine
|
||||||
void release();
|
void release();
|
||||||
|
|
||||||
/// Experimental : Get SDL_Surface Pointer and then do anything you want!
|
/// Experimental : Get SDL_Surface Pointer and then do anything you want!
|
||||||
SDL_Surface* getRawPointer() const;
|
/// In case you can do anything with this pointer, this function should not has constant attribute.
|
||||||
|
SDL_Surface* getRawPointer();
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<SDL_Surface> _surf;
|
std::shared_ptr<SDL_Surface> _surf;
|
||||||
void _set(SDL_Surface*);
|
void _set(SDL_Surface*);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user