mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:57:44 +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:
parent
b32893eb54
commit
6d50ff71de
2 changed files with 35 additions and 30 deletions
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue