CanvasPath.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/Path.h>
  8. #include <LibWeb/HTML/Canvas/CanvasState.h>
  9. #include <LibWeb/WebIDL/ExceptionOr.h>
  10. namespace Web::HTML {
  11. // https://html.spec.whatwg.org/multipage/canvas.html#canvaspath
  12. class CanvasPath {
  13. public:
  14. ~CanvasPath() = default;
  15. void close_path();
  16. void move_to(float x, float y);
  17. void line_to(float x, float y);
  18. void quadratic_curve_to(float cx, float cy, float x, float y);
  19. void bezier_curve_to(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
  20. WebIDL::ExceptionOr<void> arc_to(double x1, double y1, double x2, double y2, double radius);
  21. void rect(float x, float y, float width, float height);
  22. WebIDL::ExceptionOr<void> arc(float x, float y, float radius, float start_angle, float end_angle, bool counter_clockwise);
  23. 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);
  24. Gfx::Path& path() { return m_path; }
  25. Gfx::Path const& path() const { return m_path; }
  26. protected:
  27. explicit CanvasPath(Bindings::PlatformObject& self)
  28. : m_self(self)
  29. {
  30. }
  31. explicit CanvasPath(Bindings::PlatformObject& self, CanvasState const& canvas_state)
  32. : m_self(self)
  33. , m_canvas_state(canvas_state)
  34. {
  35. }
  36. private:
  37. Gfx::AffineTransform active_transform() const;
  38. JS::NonnullGCPtr<Bindings::PlatformObject> m_self;
  39. Optional<CanvasState const&> m_canvas_state;
  40. Gfx::Path m_path;
  41. };
  42. }