CanvasPath.h 1.9 KB

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