CanvasPath.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/DOM/ExceptionOr.h>
  9. namespace Web::HTML {
  10. // https://html.spec.whatwg.org/multipage/canvas.html#canvaspath
  11. class CanvasPath {
  12. public:
  13. ~CanvasPath() = default;
  14. void close_path();
  15. void move_to(float x, float y);
  16. void line_to(float x, float y);
  17. void quadratic_curve_to(float cx, float cy, float x, float y);
  18. void bezier_curve_to(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
  19. void rect(float x, float y, float width, float height);
  20. DOM::ExceptionOr<void> arc(float x, float y, float radius, float start_angle, float end_angle, bool counter_clockwise);
  21. DOM::ExceptionOr<void> ellipse(float x, float y, float radius_x, float radius_y, float rotation, float start_angle, float end_angle, bool counter_clockwise);
  22. Gfx::Path& path() { return m_path; }
  23. Gfx::Path const& path() const { return m_path; }
  24. protected:
  25. explicit CanvasPath(Bindings::PlatformObject& self)
  26. : m_self(self)
  27. {
  28. }
  29. private:
  30. Bindings::PlatformObject& m_self;
  31. Gfx::Path m_path;
  32. };
  33. }