MiniEngine/sdl_engine_renderer.hpp

99 lines
2.1 KiB
C++
Raw Normal View History

2017-01-05 13:25:09 +08:00
Renderer::Renderer()
{
pimpl=new impl;
}
Renderer::Renderer(const Renderer& inc) : Renderer()
{
*pimpl=*(inc.pimpl);
}
2017-01-07 09:52:56 +08:00
Renderer& Renderer::operator = (const Renderer& inc)
{
*pimpl=*(inc.pimpl);
return *this;
}
Renderer::Renderer(Renderer&& inc)
{
pimpl=inc.pimpl;
inc.pimpl=nullptr;
}
Renderer& Renderer::operator = (Renderer&& inc)
{
*pimpl=*(inc.pimpl);
inc.pimpl=nullptr;
return *this;
}
2017-01-07 09:52:56 +08:00
2017-01-05 13:25:09 +08:00
Renderer::~Renderer()
{
delete pimpl;
}
2017-01-05 13:25:09 +08:00
int Renderer::clear()
{
return SDL_RenderClear(pimpl->sRnd.get());
}
Texture Renderer::loadImage(const char* FileName)
{
Texture t;
2017-01-07 09:52:56 +08:00
t.pimpl->set(IMG_LoadTexture(pimpl->sRnd.get(),FileName));
2017-01-05 13:25:09 +08:00
return t;
}
Texture Renderer::render(Surface surface)
{
Texture t;
2017-01-07 09:52:56 +08:00
t.pimpl->set(SDL_CreateTextureFromSurface(pimpl->sRnd.get(),surface.pimpl->getRawSurface()));
2017-01-05 13:25:09 +08:00
return t;
}
void Renderer::update()
{
SDL_RenderPresent(pimpl->sRnd.get());
}
2017-01-07 09:52:56 +08:00
2017-01-05 13:25:09 +08:00
int Renderer::copy(Texture t,Rect src,Rect dst)
{
SDL_Rect s=src.toSDLRect();
SDL_Rect d=dst.toSDLRect();
2017-01-07 09:52:56 +08:00
return SDL_RenderCopy(pimpl->sRnd.get(),t.pimpl->getRawTexture(),&s,&d);
2017-01-05 13:25:09 +08:00
}
int Renderer::copyTo(Texture t,Rect dst)
{
SDL_Rect d=dst.toSDLRect();
2017-01-07 09:52:56 +08:00
return SDL_RenderCopy(pimpl->sRnd.get(),t.pimpl->getRawTexture(),NULL,&d);
2017-01-05 13:25:09 +08:00
}
int Renderer::copyFill(Texture t,Rect src)
{
SDL_Rect s=src.toSDLRect();
2017-01-07 09:52:56 +08:00
return SDL_RenderCopy(pimpl->sRnd.get(),t.pimpl->getRawTexture(),&s,NULL);
2017-01-05 13:25:09 +08:00
}
int Renderer::copyFullFill(Texture t)
{
2017-01-07 09:52:56 +08:00
return SDL_RenderCopy(pimpl->sRnd.get(),t.pimpl->getRawTexture(),NULL,NULL);
2017-01-05 13:25:09 +08:00
}
int Renderer::setColor(RGBA pack)
{
return SDL_SetRenderDrawColor(pimpl->sRnd.get(),pack.r,pack.g,pack.b,pack.a);
}
RGBA Renderer::getColor(int* pstatus)
{
Uint8 r,g,b,a;
int ret=SDL_GetRenderDrawColor(pimpl->sRnd.get(),&r,&g,&b,&a);
RGBA pack(r,g,b,a);
if(pstatus) *pstatus=ret;
return pack;
}
int Renderer::fillRect(Rect rect)
{
auto inr=rect.toSDLRect();
return SDL_RenderFillRect(pimpl->sRnd.get(),&inr);
}
int Renderer::drawRect(Rect rect)
{
auto inr=rect.toSDLRect();
return SDL_RenderDrawRect(pimpl->sRnd.get(),&inr);
}