mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:37:46 +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)
|
void Painter::fill_rect(const Rect& a_rect, Color color)
|
||||||
{
|
{
|
||||||
if (color.alpha() == 0)
|
if (color.alpha() == 0)
|
||||||
|
@ -64,6 +82,11 @@ void Painter::fill_rect(const Rect& a_rect, Color color)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (color.alpha() == 0xff) {
|
||||||
|
clear_rect(a_rect, color);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto rect = a_rect.translated(translation()).intersected(clip_rect());
|
auto rect = a_rect.translated(translation()).intersected(clip_rect());
|
||||||
if (rect.is_empty())
|
if (rect.is_empty())
|
||||||
return;
|
return;
|
||||||
|
@ -73,14 +96,6 @@ void Painter::fill_rect(const Rect& a_rect, Color color)
|
||||||
RGBA32* dst = m_target->scanline(rect.top()) + rect.left();
|
RGBA32* dst = m_target->scanline(rect.top()) + rect.left();
|
||||||
const size_t dst_skip = m_target->pitch() / sizeof(RGBA32);
|
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 i = rect.height() - 1; i >= 0; --i) {
|
||||||
for (int j = 0; j < rect.width(); ++j)
|
for (int j = 0; j < rect.width(); ++j)
|
||||||
dst[j] = Color::from_rgba(dst[j]).blend(color).value();
|
dst[j] = Color::from_rgba(dst[j]).blend(color).value();
|
||||||
|
|
|
@ -19,6 +19,7 @@ class Painter {
|
||||||
public:
|
public:
|
||||||
explicit Painter(GraphicsBitmap&);
|
explicit Painter(GraphicsBitmap&);
|
||||||
~Painter();
|
~Painter();
|
||||||
|
void clear_rect(const Rect&, Color);
|
||||||
void fill_rect(const Rect&, Color);
|
void fill_rect(const Rect&, Color);
|
||||||
void fill_rect_with_gradient(const Rect&, Color gradient_start, Color gradient_end);
|
void fill_rect_with_gradient(const Rect&, Color gradient_start, Color gradient_end);
|
||||||
void draw_rect(const Rect&, Color, bool rough = false);
|
void draw_rect(const Rect&, Color, bool rough = false);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue