2020-11-21 19:57:40 +00:00
|
|
|
#include "sdlpp_renderer.hpp"
|
|
|
|
|
|
|
|
namespace SDLPP {
|
|
|
|
Renderer::Renderer( Window &window ) {
|
|
|
|
renderer = SDL_CreateRenderer( window.getWindowPtr(), -1,
|
|
|
|
SDL_RENDERER_ACCELERATED );
|
|
|
|
if ( renderer == NULL ) {
|
|
|
|
std::cerr << "SDL could not create a renderer! SDL_Error: "
|
|
|
|
<< SDL_GetError();
|
|
|
|
throw "Couldn't create renderer";
|
|
|
|
}
|
|
|
|
SDL_SetRenderDrawColor( renderer, 0xFF, 0xFF, 0xFF, 0xFF );
|
|
|
|
}
|
|
|
|
Renderer::~Renderer() {
|
|
|
|
SDL_DestroyRenderer( renderer );
|
|
|
|
}
|
|
|
|
SDL_Renderer *Renderer::getRendererPtr() {
|
|
|
|
return renderer;
|
|
|
|
}
|
2021-03-15 13:37:53 +00:00
|
|
|
Vec2D< int > Renderer::getDimensions() const {
|
2020-11-21 19:57:40 +00:00
|
|
|
int width = 0, height = 0;
|
|
|
|
SDL_GetRendererOutputSize( renderer, &width, &height );
|
|
|
|
return { width, height };
|
2021-04-26 19:57:31 +00:00
|
|
|
}
|
|
|
|
Vec2D< double > Renderer::getDoubleDimensions() const {
|
|
|
|
auto dimensions = getDimensions();
|
2021-04-27 13:54:30 +00:00
|
|
|
if ( dimensions == dimensions_cache )
|
|
|
|
return double_dimensions_cache;
|
|
|
|
dimensions_cache = dimensions;
|
2021-04-26 19:57:31 +00:00
|
|
|
double smaller = dimensions.getX() < dimensions.getY() ? dimensions.getX()
|
|
|
|
: dimensions.getY();
|
2021-04-27 13:54:30 +00:00
|
|
|
double_dimensions_cache = {
|
|
|
|
static_cast< double >( dimensions.getX() ) / smaller,
|
|
|
|
static_cast< double >( dimensions.getY() ) / smaller
|
|
|
|
};
|
|
|
|
return double_dimensions_cache;
|
2020-11-21 19:57:40 +00:00
|
|
|
}
|
|
|
|
int Renderer::getWidth() const {
|
2021-03-15 13:37:53 +00:00
|
|
|
return getDimensions().getX();
|
2020-11-21 19:57:40 +00:00
|
|
|
}
|
|
|
|
int Renderer::getHeight() const {
|
2021-03-15 13:37:53 +00:00
|
|
|
return getDimensions().getY();
|
2020-11-21 19:57:40 +00:00
|
|
|
}
|
|
|
|
int Renderer::getSmallerSide() const {
|
|
|
|
auto dimensions = getDimensions();
|
2021-03-15 13:37:53 +00:00
|
|
|
return dimensions.getX() < dimensions.getY() ? dimensions.getX()
|
|
|
|
: dimensions.getY();
|
2020-11-21 19:57:40 +00:00
|
|
|
}
|
|
|
|
int Renderer::getLargerSide() const {
|
|
|
|
auto dimensions = getDimensions();
|
2021-03-15 13:37:53 +00:00
|
|
|
return dimensions.getX() > dimensions.getY() ? dimensions.getX()
|
|
|
|
: dimensions.getY();
|
2020-11-21 19:57:40 +00:00
|
|
|
}
|
|
|
|
void Renderer::setBlendMode( SDL_BlendMode blendMode ) {
|
|
|
|
SDL_SetRenderDrawBlendMode( renderer, blendMode );
|
|
|
|
}
|
|
|
|
void Renderer::setRenderColiders( bool render ) {
|
|
|
|
render_coliders = render;
|
|
|
|
}
|
|
|
|
bool Renderer::getRenderColiders() {
|
|
|
|
return render_coliders;
|
|
|
|
}
|
|
|
|
void Renderer::clearRenderer() {
|
|
|
|
SDL_RenderClear( getRendererPtr() );
|
|
|
|
}
|
|
|
|
void Renderer::presentRenderer() {
|
|
|
|
SDL_RenderPresent( getRendererPtr() );
|
|
|
|
}
|
|
|
|
} // namespace SDLPP
|