CanvasPath.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. void rect(float x, float y, float width, float height);
  21. WebIDL::ExceptionOr<void> arc(float x, float y, float radius, float start_angle, float end_angle, bool counter_clockwise);
  22. 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);
  23. Gfx::Path& path() { return m_path; }
  24. Gfx::Path const& path() const { return m_path; }
  25. protected:
  26. explicit CanvasPath(Bindings::PlatformObject& self)
  27. : m_self(self)
  28. {
  29. }
  30. explicit CanvasPath(Bindings::PlatformObject& self, CanvasState const& canvas_state)
  31. : m_self(self)
  32. , m_canvas_state(canvas_state)
  33. {
  34. }
  35. private:
  36. Gfx::AffineTransform active_transform() const;
  37. JS::NonnullGCPtr<Bindings::PlatformObject> m_self;
  38. Optional<CanvasState const&> m_canvas_state;
  39. Gfx::Path m_path;
  40. };
  41. }