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 );
|
setColor( color );
|
||||||
}
|
}
|
||||||
void LineRenderer::setColor( const std::string &color ) {
|
void LineRenderer::setColor( const std::string &color ) {
|
||||||
_color = getColorsHEX( color );
|
_color = getSDLColorHEX( color );
|
||||||
}
|
}
|
||||||
void LineRenderer::render() {
|
void LineRenderer::render() {
|
||||||
if ( !getHidden() ) {
|
if ( !getHidden() ) {
|
||||||
SDL_SetRenderDrawColor(
|
SDL_SetRenderDrawColor( renderer->getRendererPtr(), _color.r, _color.g,
|
||||||
renderer->getRendererPtr(), std::get< 0 >( _color ),
|
_color.b, _color.a );
|
||||||
std::get< 1 >( _color ), std::get< 2 >( _color ),
|
|
||||||
std::get< 3 >( _color ) );
|
|
||||||
SDL_RenderDrawLine(
|
SDL_RenderDrawLine(
|
||||||
renderer->getRendererPtr(), pixel_line.getStart().getX(),
|
renderer->getRendererPtr(), pixel_line.getStart().getX(),
|
||||||
pixel_line.getStart().getY(), pixel_line.getEnd().getX(),
|
pixel_line.getStart().getY(), pixel_line.getEnd().getX(),
|
||||||
@ -40,35 +38,16 @@ void LineRenderer::render() {
|
|||||||
col->render( *renderer, colider_color );
|
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 ) {
|
void LineRenderer::setPos( double x, double y ) {
|
||||||
auto diffx = original.getEnd().getX() - original.getStart().getX();
|
setPos( Vec2D< double >( x, y ) );
|
||||||
auto diffy = original.getEnd().getY() - original.getStart().getY();
|
|
||||||
original = { { x, y }, { x + diffx, y + diffy } };
|
|
||||||
updateSizeAndPosition();
|
|
||||||
}
|
}
|
||||||
void LineRenderer::setPos( const std::pair< double, double > &pos ) {
|
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 ) {
|
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 {
|
Vec2D< double > LineRenderer::getPos() const {
|
||||||
return original.getStart();
|
return original.getStart();
|
||||||
|
@ -24,7 +24,6 @@ public:
|
|||||||
virtual void setColor( const std::string &color ) override;
|
virtual void setColor( const std::string &color ) override;
|
||||||
virtual void specialAction( int /*UNUSED*/ ) override{};
|
virtual void specialAction( int /*UNUSED*/ ) override{};
|
||||||
virtual void render() override;
|
virtual void render() override;
|
||||||
virtual void move( int ticks ) override;
|
|
||||||
virtual void custom_move( int /*UNUSED*/ ) override {}
|
virtual void custom_move( int /*UNUSED*/ ) override {}
|
||||||
virtual void setPos( double x, double y ) override;
|
virtual void setPos( double x, double y ) override;
|
||||||
virtual void setPos( const std::pair< double, double > &pos ) override;
|
virtual void setPos( const std::pair< double, double > &pos ) override;
|
||||||
@ -54,7 +53,7 @@ protected:
|
|||||||
Line< double > current = { { 0, 0 }, { 0, 0 } };
|
Line< double > current = { { 0, 0 }, { 0, 0 } };
|
||||||
Line< int > pixel_line = { { 0, 0 }, { 0, 0 } };
|
Line< int > pixel_line = { { 0, 0 }, { 0, 0 } };
|
||||||
bool centerx = false;
|
bool centerx = false;
|
||||||
std::tuple< int, int, int, int > _color;
|
SDL_Color _color;
|
||||||
};
|
};
|
||||||
} // end of namespace SDLPP
|
} // end of namespace SDLPP
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user