mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:17:35 +00:00
SharedGraphics: Add some useful painting helpers and make use of them.
This commit is contained in:
parent
b782055b96
commit
38f589a9cb
6 changed files with 38 additions and 22 deletions
|
@ -137,7 +137,7 @@ void Painter::fill_rect_with_gradient(const Rect& a_rect, Color gradient_start,
|
|||
}
|
||||
}
|
||||
|
||||
void Painter::draw_rect(const Rect& a_rect, Color color)
|
||||
void Painter::draw_rect(const Rect& a_rect, Color color, bool rough)
|
||||
{
|
||||
Rect rect = a_rect;
|
||||
rect.move_by(m_translation);
|
||||
|
@ -150,11 +150,15 @@ void Painter::draw_rect(const Rect& a_rect, Color color)
|
|||
int max_y = clipped_rect.bottom();
|
||||
|
||||
if (rect.top() >= clipped_rect.top() && rect.top() <= clipped_rect.bottom()) {
|
||||
fast_dword_fill(m_target->scanline(rect.top()) + clipped_rect.left(), color.value(), clipped_rect.width());
|
||||
int start_x = rough ? max(rect.x() + 1, clipped_rect.x()) : clipped_rect.x();
|
||||
int width = rough ? min(rect.width() - 2, clipped_rect.width()) : clipped_rect.width();
|
||||
fast_dword_fill(m_target->scanline(rect.top()) + start_x, color.value(), width);
|
||||
++min_y;
|
||||
}
|
||||
if (rect.bottom() >= clipped_rect.top() && rect.bottom() <= clipped_rect.bottom()) {
|
||||
fast_dword_fill(m_target->scanline(rect.bottom()) + clipped_rect.left(), color.value(), clipped_rect.width());
|
||||
int start_x = rough ? max(rect.x() + 1, clipped_rect.x()) : clipped_rect.x();
|
||||
int width = rough ? min(rect.width() - 2, clipped_rect.width()) : clipped_rect.width();
|
||||
fast_dword_fill(m_target->scanline(rect.bottom()) + start_x, color.value(), width);
|
||||
--max_y;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ public:
|
|||
~Painter();
|
||||
void fill_rect(const Rect&, Color);
|
||||
void fill_rect_with_gradient(const Rect&, Color gradient_start, Color gradient_end);
|
||||
void draw_rect(const Rect&, Color);
|
||||
void draw_rect(const Rect&, Color, bool rough = false);
|
||||
void draw_bitmap(const Point&, const CharacterBitmap&, Color = Color());
|
||||
void draw_bitmap(const Point&, const GlyphBitmap&, Color = Color());
|
||||
void set_pixel(const Point&, Color);
|
||||
|
|
|
@ -67,6 +67,27 @@ public:
|
|||
set_height(height() - h);
|
||||
}
|
||||
|
||||
Rect shrunken(int w, int h)
|
||||
{
|
||||
Rect rect = *this;
|
||||
rect.shrink(w, h);
|
||||
return rect;
|
||||
}
|
||||
|
||||
Rect inflated(int w, int h)
|
||||
{
|
||||
Rect rect = *this;
|
||||
rect.inflate(w, h);
|
||||
return rect;
|
||||
}
|
||||
|
||||
Rect translated(int dx, int dy)
|
||||
{
|
||||
Rect rect = *this;
|
||||
rect.move_by(dx, dy);
|
||||
return rect;
|
||||
}
|
||||
|
||||
bool contains(int x, int y) const
|
||||
{
|
||||
return x >= m_location.x() && x <= right() && y >= m_location.y() && y <= bottom();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue