mirror of
https://github.com/RGBCube/serenity
synced 2025-07-10 12:27:35 +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:
parent
60c2e41079
commit
0d93e249c3
6 changed files with 163 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue