1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 21:48:11 +00:00
serenity/Libraries/LibWeb/DOM/CanvasRenderingContext2D.h
Andreas Kling a37c29e353 LibWeb: Add <canvas> element and start fleshing out CRC2D
This patch adds HTMLCanvasElement along with a LayoutCanvas object.
The DOM and layout parts are very similar to <img> elements.

The <canvas> element holds a Gfx::Bitmap which is sized according to
the "width" and "height" attributes on the element.

Calling .getContext("2d") on a <canvas> element gives you a context
object that draws into the underlying Gfx::Bitmap of the <canvas>.
The context weakly points to the <canvas> which allows it to outlive
the canvas element if needed.

This is really quite cool. :^)
2020-03-19 19:07:56 +01:00

38 lines
932 B
C++

#pragma once
#include <AK/RefCounted.h>
#include <LibGfx/Color.h>
#include <LibGfx/Forward.h>
#include <LibWeb/Bindings/Wrappable.h>
namespace Web {
class CanvasRenderingContext2D
: public RefCounted<CanvasRenderingContext2D>
, public Bindings::Wrappable {
AK_MAKE_NONCOPYABLE(CanvasRenderingContext2D);
AK_MAKE_NONMOVABLE(CanvasRenderingContext2D);
public:
using WrapperType = Bindings::CanvasRenderingContext2DWrapper;
static NonnullRefPtr<CanvasRenderingContext2D> create(HTMLCanvasElement& element) { return adopt(*new CanvasRenderingContext2D(element)); }
~CanvasRenderingContext2D();
void set_fill_style(String);
String fill_style() const;
void fill_rect(int x, int y, int width, int height);
private:
explicit CanvasRenderingContext2D(HTMLCanvasElement&);
OwnPtr<Gfx::Painter> painter();
WeakPtr<HTMLCanvasElement> m_element;
Gfx::Color m_fill_style;
};
}