1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:37:45 +00:00

LibWeb: Encapsulate canvas drawing state in a struct

This will allow us to easily add copies of the relevant canvas drawing
state to a stack, and likewise replace the current drawing  state with
an entry from that stack.
This commit is contained in:
Linus Groh 2021-12-27 14:30:08 +01:00 committed by Andreas Kling
parent b32893eb54
commit 6d50ff71de
2 changed files with 35 additions and 30 deletions

View file

@ -46,8 +46,8 @@ public:
void translate(float x, float y);
void rotate(float degrees);
void set_line_width(float line_width) { m_line_width = line_width; }
float line_width() const { return m_line_width; }
void set_line_width(float line_width) { m_drawing_state.line_width = line_width; }
float line_width() const { return m_drawing_state.line_width; }
void begin_path();
void close_path();
@ -80,10 +80,15 @@ private:
WeakPtr<HTMLCanvasElement> m_element;
Gfx::AffineTransform m_transform;
Gfx::Color m_fill_style { Gfx::Color::Black };
Gfx::Color m_stroke_style { Gfx::Color::Black };
float m_line_width { 1 };
// https://html.spec.whatwg.org/multipage/canvas.html#drawing-state
struct DrawingState {
Gfx::AffineTransform transform;
Gfx::Color fill_style { Gfx::Color::Black };
Gfx::Color stroke_style { Gfx::Color::Black };
float line_width { 1 };
};
DrawingState m_drawing_state;
Gfx::Path m_path;
};