mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
LibWeb: Add canvas.strokeRect(), and fix scale & translate
Add an implementation of CanvasRenderingContext2DWrapper.strokeRect(). While implementing this I fixed fillRect() and the new strokeRect() to honor the .scale() and .translate() values that had previously been plumbed. Also enhance the canvas.html demo to utilize strokeRect(), scale(), and translate().
This commit is contained in:
parent
7291d5c86f
commit
39855fe9ef
5 changed files with 80 additions and 3 deletions
|
@ -47,6 +47,8 @@ CanvasRenderingContext2DWrapper::CanvasRenderingContext2DWrapper(CanvasRendering
|
|||
put_native_function("fillRect", fill_rect, 4);
|
||||
put_native_function("scale", scale, 2);
|
||||
put_native_function("translate", translate, 2);
|
||||
put_native_property("strokeStyle", stroke_style_getter, stroke_style_setter);
|
||||
put_native_function("strokeRect", stroke_rect, 4);
|
||||
}
|
||||
|
||||
CanvasRenderingContext2DWrapper::~CanvasRenderingContext2DWrapper()
|
||||
|
@ -73,6 +75,17 @@ JS::Value CanvasRenderingContext2DWrapper::fill_rect(JS::Interpreter& interprete
|
|||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
JS::Value CanvasRenderingContext2DWrapper::stroke_rect(JS::Interpreter& interpreter)
|
||||
{
|
||||
auto* impl = impl_from(interpreter);
|
||||
if (!impl)
|
||||
return {};
|
||||
auto& arguments = interpreter.call_frame().arguments;
|
||||
if (arguments.size() >= 4)
|
||||
impl->stroke_rect(arguments[0].to_i32(), arguments[1].to_i32(), arguments[2].to_i32(), arguments[3].to_i32());
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
JS::Value CanvasRenderingContext2DWrapper::scale(JS::Interpreter& interpreter)
|
||||
{
|
||||
auto* impl = impl_from(interpreter);
|
||||
|
@ -109,5 +122,19 @@ void CanvasRenderingContext2DWrapper::fill_style_setter(JS::Interpreter& interpr
|
|||
impl->set_fill_style(value.to_string());
|
||||
}
|
||||
|
||||
JS::Value CanvasRenderingContext2DWrapper::stroke_style_getter(JS::Interpreter& interpreter)
|
||||
{
|
||||
auto* impl = impl_from(interpreter);
|
||||
if (!impl)
|
||||
return {};
|
||||
return JS::js_string(interpreter, impl->stroke_style());
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DWrapper::stroke_style_setter(JS::Interpreter& interpreter, JS::Value value)
|
||||
{
|
||||
if (auto* impl = impl_from(interpreter))
|
||||
impl->set_stroke_style(value.to_string());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,10 +43,13 @@ private:
|
|||
virtual const char* class_name() const override { return "CanvasRenderingContext2DWrapper"; }
|
||||
|
||||
static JS::Value fill_rect(JS::Interpreter&);
|
||||
static JS::Value stroke_rect(JS::Interpreter&);
|
||||
static JS::Value scale(JS::Interpreter&);
|
||||
static JS::Value translate(JS::Interpreter&);
|
||||
static JS::Value fill_style_getter(JS::Interpreter&);
|
||||
static void fill_style_setter(JS::Interpreter&, JS::Value);
|
||||
static JS::Value stroke_style_getter(JS::Interpreter&);
|
||||
static void stroke_style_setter(JS::Interpreter&, JS::Value);
|
||||
|
||||
NonnullRefPtr<CanvasRenderingContext2D> m_impl;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue