LibGfx: Add shortcut to draw_scaled_bitmap_with_transform() for scales

Using `draw_scaled_bitmap()` for simple scales is almost always better
than using `draw_scaled_bitmap_with_transform()` which does not respect
the scaling mode.
This commit is contained in:
MacDue 2024-05-27 19:03:52 +01:00 committed by Andreas Kling
parent f7bf14605c
commit a5442ad70d
2 changed files with 7 additions and 4 deletions

View file

@ -35,6 +35,11 @@ public:
return m_values[0] == 1 && m_values[1] == 0 && m_values[2] == 0 && m_values[3] == 1;
}
[[nodiscard]] bool is_identity_or_translation_or_scale() const
{
return m_values[1] == 0 && m_values[2] == 0;
}
void map(float unmapped_x, float unmapped_y, float& mapped_x, float& mapped_y) const;
template<Arithmetic T>

View file

@ -2447,10 +2447,8 @@ void Painter::draw_text_run(FloatPoint baseline_start, Utf8View const& string, F
void Painter::draw_scaled_bitmap_with_transform(IntRect const& dst_rect, Bitmap const& bitmap, FloatRect const& src_rect, AffineTransform const& transform, float opacity, Painter::ScalingMode scaling_mode)
{
if (transform.is_identity_or_translation()) {
translate(transform.e(), transform.f());
draw_scaled_bitmap(dst_rect, bitmap, src_rect, opacity, scaling_mode);
translate(-transform.e(), -transform.f());
if (transform.is_identity_or_translation_or_scale()) {
draw_scaled_bitmap(transform.map(dst_rect.to_type<float>()).to_rounded<int>(), bitmap, src_rect, opacity, scaling_mode);
} else {
// The painter has an affine transform, we have to draw through it!