summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Libraries/LibWeb/DOM/CanvasRenderingContext2D.cpp28
-rw-r--r--Libraries/LibWeb/DOM/CanvasRenderingContext2D.h7
2 files changed, 9 insertions, 26 deletions
diff --git a/Libraries/LibWeb/DOM/CanvasRenderingContext2D.cpp b/Libraries/LibWeb/DOM/CanvasRenderingContext2D.cpp
index b89ba9e5fc..cab39d638f 100644
--- a/Libraries/LibWeb/DOM/CanvasRenderingContext2D.cpp
+++ b/Libraries/LibWeb/DOM/CanvasRenderingContext2D.cpp
@@ -56,7 +56,7 @@ void CanvasRenderingContext2D::fill_rect(float x, float y, float width, float he
if (!painter)
return;
- Gfx::FloatRect rect = compute_rect(x, y, width, height);
+ auto rect = m_transform.map(Gfx::FloatRect(x, y, width, height));
painter->fill_rect(enclosing_int_rect(rect), m_fill_style);
did_draw(rect);
}
@@ -77,35 +77,21 @@ void CanvasRenderingContext2D::stroke_rect(float x, float y, float width, float
if (!painter)
return;
- Gfx::FloatRect rect = compute_rect(x, y, width, height);
+ auto rect = m_transform.map(Gfx::FloatRect(x, y, width, height));
painter->draw_rect(enclosing_int_rect(rect), m_stroke_style);
did_draw(rect);
}
void CanvasRenderingContext2D::scale(float sx, float sy)
{
- // FIXME: Actually do something with the scale factor!
- dbg() << "CanvasRenderingContext2D::scale(): " << String::format("%f", sx) << ", " << String::format("%f", sy);
- m_scale_x = sx;
- m_scale_y = sy;
+ dbg() << "CanvasRenderingContext2D::scale(): " << sx << ", " << sy;
+ m_transform.scale(sx, sy);
}
-void CanvasRenderingContext2D::translate(float x, float y)
+void CanvasRenderingContext2D::translate(float tx, float ty)
{
- // FIXME: Actually do something with the translation!
- dbg() << "CanvasRenderingContext2D::translate(): " << String::format("%f", x) << ", " << String::format("%f", y);
- m_translate_x = x;
- m_translate_y = y;
-}
-
-Gfx::FloatRect CanvasRenderingContext2D::compute_rect(float x, float y, float width, float height)
-{
- return {
- (x + m_translate_x) * m_scale_x,
- (y + m_translate_y) * m_scale_y,
- width * m_scale_x,
- height * m_scale_y
- };
+ dbg() << "CanvasRenderingContext2D::translate(): " << tx << ", " << ty;
+ m_transform.translate(tx, ty);
}
void CanvasRenderingContext2D::did_draw(const Gfx::FloatRect&)
diff --git a/Libraries/LibWeb/DOM/CanvasRenderingContext2D.h b/Libraries/LibWeb/DOM/CanvasRenderingContext2D.h
index f391eb3b62..0e31a1638c 100644
--- a/Libraries/LibWeb/DOM/CanvasRenderingContext2D.h
+++ b/Libraries/LibWeb/DOM/CanvasRenderingContext2D.h
@@ -27,6 +27,7 @@
#pragma once
#include <AK/RefCounted.h>
+#include <LibGfx/AffineTransform.h>
#include <LibGfx/Color.h>
#include <LibGfx/Forward.h>
#include <LibWeb/Bindings/Wrappable.h>
@@ -60,17 +61,13 @@ public:
private:
explicit CanvasRenderingContext2D(HTMLCanvasElement&);
- Gfx::FloatRect compute_rect(float x, float y, float width, float height);
void did_draw(const Gfx::FloatRect&);
OwnPtr<Gfx::Painter> painter();
WeakPtr<HTMLCanvasElement> m_element;
- float m_scale_x { 1 };
- float m_scale_y { 1 };
- float m_translate_x { 0 };
- float m_translate_y { 0 };
+ Gfx::AffineTransform m_transform;
Gfx::Color m_fill_style;
Gfx::Color m_stroke_style;
};