Add Texture-like functions in class Surface

This commit is contained in:
Kirigaya Kazuto 2017-04-13 09:03:44 +08:00
parent a2a3e493c5
commit 3043ae0684
2 changed files with 84 additions and 0 deletions

View File

@ -295,6 +295,75 @@ namespace MiniEngine
return SDL_BlitSurface(s._get(),NULL,_get(),NULL);
}
int Surface::setAlphaMode(int alpha)
{
return SDL_SetSurfaceAlphaMod(_get(),alpha);
}
int Surface::getAlphaMode()
{
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()
{
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(RGBA pack)
{
setColorMode(pack.toColorMode());
setAlphaMode(pack.a);
}
RGBA Surface::getRGBA()
{
return RGBA(getColorMode(),getAlphaMode());
}
bool Surface::mustlock()
{
return SDL_MUSTLOCK(_get());
}
int Surface::lock()
{
return SDL_LockSurface(_get());
}
void Surface::unlock()
{
SDL_UnlockSurface(_get());
}
//static
Surface Surface::createSurface(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask) throw(ErrorViewer)
{
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;
}
void Texture::_set(SDL_Texture* p)//private
{
_text.reset(p,SDL_DestroyTexture);

View File

@ -106,6 +106,21 @@ namespace MiniEngine
int blitTo(Surface t, Point lupoint);
int blitFill(Surface t, Rect src);
int blitFullFill(Surface t);
int setAlphaMode(int alpha);
int getAlphaMode();
ColorMode getColorMode();
int setColorMode(ColorMode mode);
RGBA getRGBA();
void setRGBA(RGBA pack);
bool mustlock();
int lock();
void unlock();
static Surface createSurface(int width,int height,int depth,int Rmask,int Gmask,int Bmask,int Amask) throw(ErrorViewer);
protected:
Surface() = default;
private: