Skip to content

Commit

Permalink
Issue #191 - fix preserve_aspect_ratio image positioning on rotated i…
Browse files Browse the repository at this point in the history
…mages
  • Loading branch information
mickelson committed Mar 15, 2016
1 parent 042271d commit a260acf
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/fe_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,10 +1149,16 @@ void FeImage::scale()
// We have a size set in both directions and are preserving the aspect
// ratio, so calculate how we will centre the image in the space we have
//
sf::Transform t;
t.rotate( m_sprite.getRotation() );

if ( scale_x > scale_y ) // centre in x direction
final_pos.x += ( m_size.x - ( abs( texture_rect.width ) * scale_y )) / 2.0;
final_pos += t.transformPoint(
( m_size.x - ( abs( texture_rect.width ) * scale_y )) / 2.0,
0 );
else // centre in y direction
final_pos.y += ( m_size.y - ( abs( texture_rect.height ) * scale_x )) / 2.0;
final_pos += t.transformPoint( 0,
( m_size.y - ( abs( texture_rect.height ) * scale_x )) / 2.0);
}
}

Expand Down

0 comments on commit a260acf

Please sign in to comment.