mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +00:00
LibDraw: Add Painter::clear_rect() for filling a rect without blending
Sometimes you want to fill a rect with a specific color without alpha blending it with whatever's already there.
This commit is contained in:
parent
029455cb40
commit
c645d9fe4a
2 changed files with 24 additions and 8 deletions
|
@ -54,6 +54,24 @@ void Painter::fill_rect_with_draw_op(const Rect& a_rect, Color color)
|
|||
}
|
||||
}
|
||||
|
||||
void Painter::clear_rect(const Rect& a_rect, Color color)
|
||||
{
|
||||
auto rect = a_rect.translated(translation()).intersected(clip_rect());
|
||||
if (rect.is_empty())
|
||||
return;
|
||||
|
||||
ASSERT(m_target->rect().contains(rect));
|
||||
|
||||
RGBA32* dst = m_target->scanline(rect.top()) + rect.left();
|
||||
const size_t dst_skip = m_target->pitch() / sizeof(RGBA32);
|
||||
|
||||
for (int i = rect.height() - 1; i >= 0; --i) {
|
||||
fast_u32_fill(dst, color.value(), rect.width());
|
||||
dst += dst_skip;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Painter::fill_rect(const Rect& a_rect, Color color)
|
||||
{
|
||||
if (color.alpha() == 0)
|
||||
|
@ -64,6 +82,11 @@ void Painter::fill_rect(const Rect& a_rect, Color color)
|
|||
return;
|
||||
}
|
||||
|
||||
if (color.alpha() == 0xff) {
|
||||
clear_rect(a_rect, color);
|
||||
return;
|
||||
}
|
||||
|
||||
auto rect = a_rect.translated(translation()).intersected(clip_rect());
|
||||
if (rect.is_empty())
|
||||
return;
|
||||
|
@ -73,14 +96,6 @@ void Painter::fill_rect(const Rect& a_rect, Color color)
|
|||
RGBA32* dst = m_target->scanline(rect.top()) + rect.left();
|
||||
const size_t dst_skip = m_target->pitch() / sizeof(RGBA32);
|
||||
|
||||
if (color.alpha() == 0xff) {
|
||||
for (int i = rect.height() - 1; i >= 0; --i) {
|
||||
fast_u32_fill(dst, color.value(), rect.width());
|
||||
dst += dst_skip;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = rect.height() - 1; i >= 0; --i) {
|
||||
for (int j = 0; j < rect.width(); ++j)
|
||||
dst[j] = Color::from_rgba(dst[j]).blend(color).value();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue