SDLPP: LineRenderer - use new features
This commit is contained in:
parent
8b3eee0673
commit
aaae85a932
@ -22,14 +22,12 @@ LineRenderer::LineRenderer( const Line< double > &line,
|
||||
setColor( color );
|
||||
}
|
||||
void LineRenderer::setColor( const std::string &color ) {
|
||||
_color = getColorsHEX( color );
|
||||
_color = getSDLColorHEX( color );
|
||||
}
|
||||
void LineRenderer::render() {
|
||||
if ( !getHidden() ) {
|
||||
SDL_SetRenderDrawColor(
|
||||
renderer->getRendererPtr(), std::get< 0 >( _color ),
|
||||
std::get< 1 >( _color ), std::get< 2 >( _color ),
|
||||
std::get< 3 >( _color ) );
|
||||
SDL_SetRenderDrawColor( renderer->getRendererPtr(), _color.r, _color.g,
|
||||
_color.b, _color.a );
|
||||
SDL_RenderDrawLine(
|
||||
renderer->getRendererPtr(), pixel_line.getStart().getX(),
|
||||
pixel_line.getStart().getY(), pixel_line.getEnd().getX(),
|
||||
@ -40,35 +38,16 @@ void LineRenderer::render() {
|
||||
col->render( *renderer, colider_color );
|
||||
}
|
||||
}
|
||||
void LineRenderer::move( int ticks ) {
|
||||
if ( permanent )
|
||||
return;
|
||||
auto addx =
|
||||
static_cast< double >( movementSpeed * movementDirection.first ) *
|
||||
( static_cast< double >( ticks ) / 1000 );
|
||||
auto addy =
|
||||
static_cast< double >( movementSpeed * movementDirection.second ) *
|
||||
( static_cast< double >( ticks ) / 1000 );
|
||||
if ( std::isnan( addx ) || std::isnan( addy ) )
|
||||
return;
|
||||
|
||||
original.add( { addx, addy } );
|
||||
|
||||
custom_move( ticks );
|
||||
|
||||
updateSizeAndPosition();
|
||||
}
|
||||
void LineRenderer::setPos( double x, double y ) {
|
||||
auto diffx = original.getEnd().getX() - original.getStart().getX();
|
||||
auto diffy = original.getEnd().getY() - original.getStart().getY();
|
||||
original = { { x, y }, { x + diffx, y + diffy } };
|
||||
updateSizeAndPosition();
|
||||
setPos( Vec2D< double >( x, y ) );
|
||||
}
|
||||
void LineRenderer::setPos( const std::pair< double, double > &pos ) {
|
||||
setPos( pos.first, pos.second );
|
||||
setPos( Vec2D< double >( pos.first, pos.second ) );
|
||||
}
|
||||
void LineRenderer::setPos( const Vec2D< double > &vec ) {
|
||||
setPos( vec.getX(), vec.getY() );
|
||||
auto diff = original.getEnd() - original.getStart();
|
||||
original = { vec, vec + diff };
|
||||
updateSizeAndPosition();
|
||||
}
|
||||
Vec2D< double > LineRenderer::getPos() const {
|
||||
return original.getStart();
|
||||
|
@ -24,7 +24,6 @@ public:
|
||||
virtual void setColor( const std::string &color ) override;
|
||||
virtual void specialAction( int /*UNUSED*/ ) override{};
|
||||
virtual void render() override;
|
||||
virtual void move( int ticks ) override;
|
||||
virtual void custom_move( int /*UNUSED*/ ) override {}
|
||||
virtual void setPos( double x, double y ) override;
|
||||
virtual void setPos( const std::pair< double, double > &pos ) override;
|
||||
@ -54,7 +53,7 @@ protected:
|
||||
Line< double > current = { { 0, 0 }, { 0, 0 } };
|
||||
Line< int > pixel_line = { { 0, 0 }, { 0, 0 } };
|
||||
bool centerx = false;
|
||||
std::tuple< int, int, int, int > _color;
|
||||
SDL_Color _color;
|
||||
};
|
||||
} // end of namespace SDLPP
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user