1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:38:11 +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:
Brian Gianforcaro 2020-04-07 01:09:17 -07:00 committed by Andreas Kling
parent 7291d5c86f
commit 39855fe9ef
5 changed files with 80 additions and 3 deletions

View file

@ -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());
}
}
}