SDLPP: can set minimal width/height on rectangle renderer

This commit is contained in:
zvon 2021-05-02 14:03:26 +02:00
parent 61e45e89a5
commit e84284e613
3 changed files with 19 additions and 1 deletions

View File

@ -146,6 +146,10 @@ void RectangleRender::updateSizeAndPosition() {
rect.h = rect.h =
std::round( ( current.getY() + original_size.getY() ) * dimension ) - std::round( ( current.getY() + original_size.getY() ) * dimension ) -
rect.y; rect.y;
if(rect.w < min_size.getX())
rect.w = min_size.getX();
if(rect.h < min_size.getY())
rect.h = min_size.getY();
if ( polygon ) if ( polygon )
polygon->updateCollision( collisionPushX(), collisionPushY(), polygon->updateCollision( collisionPushX(), collisionPushY(),
collisionWidth(), collisionHeight(), collisionWidth(), collisionHeight(),
@ -169,4 +173,14 @@ void RectangleRender::copyTo( std::shared_ptr< RenderObject > other ) {
std::string RectangleRender::getColor() const { std::string RectangleRender::getColor() const {
return color; return color;
} }
void RectangleRender::setMinWidth( uint64_t width ) {
min_size = {width, min_size.getY()};
}
void RectangleRender::setMinHeight( uint64_t height ) {
min_size = {min_size.getX(), height};
}
void RectangleRender::setSize( Vec2D< double > size ) {
original_size = size;
updateSizeAndPosition();
}
} // namespace SDLPP } // namespace SDLPP

View File

@ -76,12 +76,16 @@ public:
virtual SDL_Rect getRect() override; virtual SDL_Rect getRect() override;
virtual std::shared_ptr< RenderObject > copySelf() override; virtual std::shared_ptr< RenderObject > copySelf() override;
std::string getColor() const; std::string getColor() const;
void setMinWidth( uint64_t width );
void setMinHeight( uint64_t height );
void setSize( Vec2D< double > size );
protected: protected:
virtual void copyTo( std::shared_ptr< RenderObject > other ) override; virtual void copyTo( std::shared_ptr< RenderObject > other ) override;
Vec2D< double > original_size; Vec2D< double > original_size;
Vec2D< double > size; Vec2D< double > size;
std::string color = ""; std::string color = "";
Vec2D< uint64_t > min_size = {0, 0};
}; };
} // end of namespace SDLPP } // end of namespace SDLPP
#endif #endif

View File

@ -110,7 +110,7 @@ public:
void resumeAnimation(); void resumeAnimation();
void removeAnimation(); void removeAnimation();
void animate( int ticks ); void animate( int ticks );
void visit( Visitor &visitor ); virtual void visit( Visitor &visitor );
void setAlignment( ObjectAlignment horizontal, ObjectAlignment vertical ); void setAlignment( ObjectAlignment horizontal, ObjectAlignment vertical );
void flipHorizontally(); void flipHorizontally();
void flipVertically(); void flipVertically();