This commit is contained in:
zv0n 2021-03-07 12:20:00 +01:00
parent 2661d6ca76
commit fa10620901
8 changed files with 22 additions and 39 deletions

View File

@ -50,19 +50,6 @@ void CircleRender::setOutlineColor( const std::string &color ) {
polygon->setOutlineColor( color ); polygon->setOutlineColor( color );
} }
void CircleRender::render() {
if ( !getHidden() ) {
if ( polygon )
polygon->render( *renderer );
else
std::cerr << "I don't support textures on circles yet!" << std::endl;
if ( hasCollisions() && renderer->getRenderColiders() ) {
for ( const auto &col : getCollisions() )
col->render( *renderer, colider_color );
}
}
}
std::pair< std::pair< double, double >, std::pair< double, double > > std::pair< std::pair< double, double >, std::pair< double, double > >
CircleRender::getDoubleRect() const { CircleRender::getDoubleRect() const {
return { { og_x - og_r, og_y - og_r }, { 2 * og_r, 2 * og_r } }; return { { og_x - og_r, og_y - og_r }, { 2 * og_r, 2 * og_r } };

View File

@ -19,7 +19,6 @@ public:
virtual void setColor( const std::string &color ) override; virtual void setColor( const std::string &color ) override;
virtual void setOutlineColor( const std::string &color ) override; virtual void setOutlineColor( const std::string &color ) override;
virtual void specialAction( int /*UNUSED*/ ) override{} virtual void specialAction( int /*UNUSED*/ ) override{}
virtual void render() override;
virtual void custom_move( int /*UNUSED*/ ) override{} virtual void custom_move( int /*UNUSED*/ ) override{}
virtual std::pair< std::pair< double, double >, virtual std::pair< std::pair< double, double >,
std::pair< double, double > > std::pair< double, double > >
@ -43,8 +42,6 @@ private:
void updateXY(); void updateXY();
double og_r; double og_r;
double r_; double r_;
bool centerx = false;
SDL_Rect rect;
std::string color = ""; std::string color = "";
}; };
} // end of namespace SDLPP } // end of namespace SDLPP

View File

@ -45,19 +45,6 @@ void RectangleRender::setOutlineColor( const std::string &color ) {
} }
polygon->setOutlineColor( color ); polygon->setOutlineColor( color );
} }
void RectangleRender::render() {
if ( !getHidden() ) {
if ( polygon )
polygon->render( *renderer );
if ( texture != NULL )
SDL_RenderCopy( renderer->getRendererPtr(),
texture->getTexturePtr(), NULL, &rect );
if ( hasCollisions() && renderer->getRenderColiders() ) {
for ( const auto &col : getCollisions() )
col->render( *renderer, colider_color );
}
}
}
std::pair< std::pair< double, double >, std::pair< double, double > > std::pair< std::pair< double, double >, std::pair< double, double > >
RectangleRender::getDoubleRect() const { RectangleRender::getDoubleRect() const {
return { { og_x, og_y }, { og_w, og_h } }; return { { og_x, og_y }, { og_w, og_h } };

View File

@ -22,7 +22,6 @@ public:
virtual void setColor( const std::string &color ) override; virtual void setColor( const std::string &color ) override;
virtual void setOutlineColor( const std::string &color ) override; virtual void setOutlineColor( const std::string &color ) override;
virtual void specialAction( int /*UNUSED*/ ) override{} virtual void specialAction( int /*UNUSED*/ ) override{}
virtual void render() override;
virtual void custom_move( int /*UNUSED*/ ) override {} virtual void custom_move( int /*UNUSED*/ ) override {}
virtual std::pair< std::pair< double, double >, virtual std::pair< std::pair< double, double >,
std::pair< double, double > > std::pair< double, double > >
@ -48,8 +47,6 @@ protected:
double og_h; double og_h;
double w_; double w_;
double h_; double h_;
bool centerx = false;
SDL_Rect rect;
std::string color = ""; std::string color = "";
}; };
} // end of namespace SDLPP } // end of namespace SDLPP

View File

@ -2,6 +2,19 @@
#include <cmath> #include <cmath>
namespace SDLPP { namespace SDLPP {
void RenderObject::render() {
if ( !getHidden() ) {
if ( polygon )
polygon->render( *renderer );
if ( texture != NULL )
SDL_RenderCopy( renderer->getRendererPtr(),
texture->getTexturePtr(), NULL, &rect );
if ( hasCollisions() && renderer->getRenderColiders() ) {
for ( const auto &col : getCollisions() )
col->render( *renderer, colider_color );
}
}
}
void RenderObject::setPos( double x, double y ) { void RenderObject::setPos( double x, double y ) {
og_x = x; og_x = x;
og_y = y; og_y = y;

View File

@ -16,8 +16,7 @@ class SDLPPSCOPE RenderObject {
public: public:
RenderObject( const std::shared_ptr< Renderer > &r ) : renderer( r ) {} RenderObject( const std::shared_ptr< Renderer > &r ) : renderer( r ) {}
virtual ~RenderObject() {} virtual ~RenderObject() {}
// TODO maybe do basic render() that all descandants can inherit? virtual void render();
virtual void render() = 0;
virtual int leftmost() = 0; virtual int leftmost() = 0;
virtual int topmost() = 0; virtual int topmost() = 0;
virtual int rightmost() = 0; virtual int rightmost() = 0;
@ -97,6 +96,8 @@ protected:
uint64_t scene_id = -1; uint64_t scene_id = -1;
bool permanent = false; bool permanent = false;
bool is_static = true; bool is_static = true;
bool centerx = false;
SDL_Rect rect;
private: private:
void setSceneID( int id ); void setSceneID( int id );

View File

@ -66,10 +66,7 @@ void TextRenderer::render() {
col->render( *renderer, colider_color ); col->render( *renderer, colider_color );
} }
} }
// TODO move this to method updateTexture and call that function from this void TextRenderer::updateTexture() {
void TextRenderer::updateSizeAndPosition() {
RectangleRender::updateSizeAndPosition();
int fontSize = 0.6 * getRect().h; int fontSize = 0.6 * getRect().h;
_config->getFont()->changeFontSize( fontSize ); _config->getFont()->changeFontSize( fontSize );
int intOutline = _config->getOutlineSize(); int intOutline = _config->getOutlineSize();
@ -79,7 +76,10 @@ void TextRenderer::updateSizeAndPosition() {
setTexture( *_config->getFont(), _text, _config->getColor(), setTexture( *_config->getFont(), _text, _config->getColor(),
_config->getOutlineColor(), intOutline ); _config->getOutlineColor(), intOutline );
_config->getFont()->revertSize(); _config->getFont()->revertSize();
}
void TextRenderer::updateSizeAndPosition() {
RectangleRender::updateSizeAndPosition();
updateTexture();
updateDstRect(); updateDstRect();
} }
std::shared_ptr< RenderObject > TextRenderer::copySelf() { std::shared_ptr< RenderObject > TextRenderer::copySelf() {

View File

@ -42,6 +42,7 @@ public:
private: private:
virtual void copyTo( std::shared_ptr< RenderObject > other ) override; virtual void copyTo( std::shared_ptr< RenderObject > other ) override;
void updateTexture();
void updateDstRect(); void updateDstRect();
void saveFontConfig( std::shared_ptr< Font > font, const std::string &color, void saveFontConfig( std::shared_ptr< Font > font, const std::string &color,
const std::string &outline_color, const std::string &outline_color,