mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 02:57:42 +00:00
LibGfx: Add Gfx::Path, a basic 2D path with <canvas> semantics
This will be used to implement painting of 2D paths. This first patch adds support for line_to(), move_to() and close(). It will try to have the same semantics as the HTML <canvas> element. To stroke a Path, simply pass it to Painter::stroke_path().
This commit is contained in:
parent
72df9c7417
commit
60c2e41079
6 changed files with 176 additions and 0 deletions
|
@ -35,6 +35,7 @@
|
|||
#include <AK/StringBuilder.h>
|
||||
#include <AK/Utf8View.h>
|
||||
#include <LibGfx/CharacterBitmap.h>
|
||||
#include <LibGfx/Path.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
@ -1010,4 +1011,24 @@ PainterStateSaver::~PainterStateSaver()
|
|||
m_painter.restore();
|
||||
}
|
||||
|
||||
void Painter::stroke_path(const Path& path, Color color, int thickness)
|
||||
{
|
||||
FloatPoint cursor;
|
||||
|
||||
for (auto& segment : path.segments()) {
|
||||
switch (segment.type) {
|
||||
case Path::Segment::Type::Invalid:
|
||||
ASSERT_NOT_REACHED();
|
||||
break;
|
||||
case Path::Segment::Type::MoveTo:
|
||||
cursor = segment.point;
|
||||
break;
|
||||
case Path::Segment::Type::LineTo:
|
||||
draw_line(Point(cursor.x(), cursor.y()), Point(segment.point.x(), segment.point.y()), color, thickness);
|
||||
cursor = segment.point;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue