1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-10 09:37:34 +00:00

LibWeb: Add some basic path drawing functionality to the canvas element

This patch adds the following methods to CanvasRenderingContext2D:

- beginPath()
- moveTo(x, y)
- lineTo(x, y)
- closePath()
- stroke()

We also add the lineWidth property. :^)
This commit is contained in:
Andreas Kling 2020-04-16 21:06:03 +02:00
parent 60c2e41079
commit 0d93e249c3
6 changed files with 163 additions and 0 deletions

View file

@ -134,4 +134,35 @@ OwnPtr<Gfx::Painter> CanvasRenderingContext2D::painter()
return make<Gfx::Painter>(*m_element->bitmap());
}
void CanvasRenderingContext2D::begin_path()
{
m_path = Gfx::Path();
}
void CanvasRenderingContext2D::close_path()
{
m_path.close();
}
void CanvasRenderingContext2D::move_to(float x, float y)
{
m_path.move_to({ x, y });
}
void CanvasRenderingContext2D::line_to(float x, float y)
{
m_path.line_to({ x, y });
}
void CanvasRenderingContext2D::stroke()
{
dbg() << "stroke path " << m_path;
auto painter = this->painter();
if (!painter)
return;
painter->stroke_path(m_path, m_stroke_style, m_line_width);
}
}