mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
LibDraw: Support dotted lines in Painter::draw_line()
Painter::draw_line() now has an optional "bool dotted" parameter that causes it to only render every other pixel. Note that this only works with horizontal and vertical lines at the moment and we'll assert if called with dotted=true for a diagonal line.
This commit is contained in:
parent
5327de2df3
commit
478cfae7c8
2 changed files with 19 additions and 7 deletions
|
@ -71,7 +71,6 @@ void Painter::clear_rect(const Rect& a_rect, Color color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
|
@ -774,7 +773,7 @@ void Painter::draw_pixel(const Point& position, Color color, int thickness)
|
||||||
fill_rect(rect, color);
|
fill_rect(rect, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Painter::draw_line(const Point& p1, const Point& p2, Color color, int thickness)
|
void Painter::draw_line(const Point& p1, const Point& p2, Color color, int thickness, bool dotted)
|
||||||
{
|
{
|
||||||
auto clip_rect = this->clip_rect();
|
auto clip_rect = this->clip_rect();
|
||||||
|
|
||||||
|
@ -797,8 +796,13 @@ void Painter::draw_line(const Point& p1, const Point& p2, Color color, int thick
|
||||||
return;
|
return;
|
||||||
int min_y = max(point1.y(), clip_rect.top());
|
int min_y = max(point1.y(), clip_rect.top());
|
||||||
int max_y = min(point2.y(), clip_rect.bottom());
|
int max_y = min(point2.y(), clip_rect.bottom());
|
||||||
for (int y = min_y; y <= max_y; ++y)
|
if (dotted) {
|
||||||
draw_pixel({ x, y }, color, thickness);
|
for (int y = min_y; y <= max_y; y += 2)
|
||||||
|
draw_pixel({ x, y }, color, thickness);
|
||||||
|
} else {
|
||||||
|
for (int y = min_y; y <= max_y; ++y)
|
||||||
|
draw_pixel({ x, y }, color, thickness);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -815,11 +819,19 @@ void Painter::draw_line(const Point& p1, const Point& p2, Color color, int thick
|
||||||
return;
|
return;
|
||||||
int min_x = max(point1.x(), clip_rect.left());
|
int min_x = max(point1.x(), clip_rect.left());
|
||||||
int max_x = min(point2.x(), clip_rect.right());
|
int max_x = min(point2.x(), clip_rect.right());
|
||||||
for (int x = min_x; x <= max_x; ++x)
|
if (dotted) {
|
||||||
draw_pixel({ x, y }, color, thickness);
|
for (int x = min_x; x <= max_x; x += 2)
|
||||||
|
draw_pixel({ x, y }, color, thickness);
|
||||||
|
} else {
|
||||||
|
for (int x = min_x; x <= max_x; ++x)
|
||||||
|
draw_pixel({ x, y }, color, thickness);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Implement dotted diagonal lines.
|
||||||
|
ASSERT(!dotted);
|
||||||
|
|
||||||
const double adx = abs(point2.x() - point1.x());
|
const double adx = abs(point2.x() - point1.x());
|
||||||
const double ady = abs(point2.y() - point1.y());
|
const double ady = abs(point2.y() - point1.y());
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ public:
|
||||||
void draw_bitmap(const Point&, const CharacterBitmap&, Color = Color());
|
void draw_bitmap(const Point&, const CharacterBitmap&, Color = Color());
|
||||||
void draw_bitmap(const Point&, const GlyphBitmap&, Color = Color());
|
void draw_bitmap(const Point&, const GlyphBitmap&, Color = Color());
|
||||||
void set_pixel(const Point&, Color);
|
void set_pixel(const Point&, Color);
|
||||||
void draw_line(const Point&, const Point&, Color, int thickness = 1);
|
void draw_line(const Point&, const Point&, Color, int thickness = 1, bool dotted = false);
|
||||||
void draw_scaled_bitmap(const Rect& dst_rect, const GraphicsBitmap&, const Rect& src_rect);
|
void draw_scaled_bitmap(const Rect& dst_rect, const GraphicsBitmap&, const Rect& src_rect);
|
||||||
void blit(const Point&, const GraphicsBitmap&, const Rect& src_rect, float opacity = 1.0f);
|
void blit(const Point&, const GraphicsBitmap&, const Rect& src_rect, float opacity = 1.0f);
|
||||||
void blit_dimmed(const Point&, const GraphicsBitmap&, const Rect& src_rect);
|
void blit_dimmed(const Point&, const GraphicsBitmap&, const Rect& src_rect);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue