mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibGfx: Replace Bitmap::invert() with Bitmap::inverted()
The new function return a new bitmap instead of mutating the current one in place.
This commit is contained in:
parent
1f907a834f
commit
4b3e229157
Notes:
sideshowbarker
2024-07-17 00:59:43 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/4b3e229157 Pull-request: https://github.com/SerenityOS/serenity/pull/17557 Reviewed-by: https://github.com/linusg
3 changed files with 9 additions and 10 deletions
|
@ -89,18 +89,15 @@ void Button::paint_event(PaintEvent& event)
|
|||
// Reusing that threshold here as it seems to work reasonably well.
|
||||
should_invert_icon = contrast_ratio < 4.5f && contrast_ratio < palette().button().contrast_ratio(solid_color->inverted());
|
||||
}
|
||||
if (should_invert_icon)
|
||||
m_icon->invert();
|
||||
auto icon = should_invert_icon ? m_icon->inverted().release_value_but_fixme_should_propagate_errors() : NonnullRefPtr { *m_icon };
|
||||
if (is_enabled()) {
|
||||
if (is_hovered())
|
||||
painter.blit_brightened(icon_location, *m_icon, m_icon->rect());
|
||||
painter.blit_brightened(icon_location, *icon, icon->rect());
|
||||
else
|
||||
painter.blit(icon_location, *m_icon, m_icon->rect());
|
||||
painter.blit(icon_location, *icon, icon->rect());
|
||||
} else {
|
||||
painter.blit_disabled(icon_location, *m_icon, m_icon->rect(), palette());
|
||||
painter.blit_disabled(icon_location, *icon, icon->rect(), palette());
|
||||
}
|
||||
if (should_invert_icon)
|
||||
m_icon->invert();
|
||||
}
|
||||
auto& font = is_checked() ? this->font().bold_variant() : this->font();
|
||||
if (m_icon && !text().is_empty()) {
|
||||
|
|
|
@ -476,12 +476,14 @@ ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::to_bitmap_backed_by_anonymous_buffer() co
|
|||
return bitmap;
|
||||
}
|
||||
|
||||
void Bitmap::invert()
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::inverted() const
|
||||
{
|
||||
auto inverted_bitmap = TRY(clone());
|
||||
for (auto y = 0; y < height(); y++) {
|
||||
for (auto x = 0; x < width(); x++)
|
||||
set_pixel(x, y, get_pixel(x, y).inverted());
|
||||
inverted_bitmap->set_pixel(x, y, get_pixel(x, y).inverted());
|
||||
}
|
||||
return inverted_bitmap;
|
||||
}
|
||||
|
||||
Bitmap::~Bitmap()
|
||||
|
|
|
@ -126,7 +126,7 @@ public:
|
|||
|
||||
[[nodiscard]] ShareableBitmap to_shareable_bitmap() const;
|
||||
|
||||
void invert();
|
||||
ErrorOr<NonnullRefPtr<Gfx::Bitmap>> inverted() const;
|
||||
|
||||
~Bitmap();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue