/src/serenity/Userland/Libraries/LibWeb/HTML/Canvas/CanvasPath.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <LibGfx/Path.h> |
10 | | #include <LibWeb/Geometry/DOMPointReadOnly.h> |
11 | | #include <LibWeb/HTML/Canvas/CanvasState.h> |
12 | | #include <LibWeb/WebIDL/ExceptionOr.h> |
13 | | |
14 | | namespace Web::HTML { |
15 | | |
16 | | // https://html.spec.whatwg.org/multipage/canvas.html#canvaspath |
17 | | class CanvasPath { |
18 | | public: |
19 | 0 | ~CanvasPath() = default; |
20 | | |
21 | | void close_path(); |
22 | | |
23 | | void move_to(float x, float y); |
24 | | void line_to(float x, float y); |
25 | | void quadratic_curve_to(float cx, float cy, float x, float y); |
26 | | void bezier_curve_to(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y); |
27 | | WebIDL::ExceptionOr<void> arc_to(double x1, double y1, double x2, double y2, double radius); |
28 | | void rect(double x, double y, double w, double h); |
29 | | WebIDL::ExceptionOr<void> round_rect(double x, double y, double w, double h, Variant<double, Geometry::DOMPointInit, Vector<Variant<double, Geometry::DOMPointInit>>> radii = { 0 }); |
30 | | WebIDL::ExceptionOr<void> arc(float x, float y, float radius, float start_angle, float end_angle, bool counter_clockwise); |
31 | | WebIDL::ExceptionOr<void> ellipse(float x, float y, float radius_x, float radius_y, float rotation, float start_angle, float end_angle, bool counter_clockwise); |
32 | | |
33 | 0 | Gfx::Path& path() { return m_path; } |
34 | 0 | Gfx::Path const& path() const { return m_path; } |
35 | | |
36 | | protected: |
37 | | explicit CanvasPath(Bindings::PlatformObject& self) |
38 | 0 | : m_self(self) |
39 | 0 | { |
40 | 0 | } |
41 | | |
42 | | explicit CanvasPath(Bindings::PlatformObject& self, CanvasState const& canvas_state) |
43 | 0 | : m_self(self) |
44 | 0 | , m_canvas_state(canvas_state) |
45 | 0 | { |
46 | 0 | } |
47 | | |
48 | | private: |
49 | | Gfx::AffineTransform active_transform() const; |
50 | | |
51 | | void ensure_subpath(float x, float y); |
52 | | |
53 | | JS::NonnullGCPtr<Bindings::PlatformObject> m_self; |
54 | | Optional<CanvasState const&> m_canvas_state; |
55 | | Gfx::Path m_path; |
56 | | }; |
57 | | |
58 | | } |