mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:47:35 +00:00
LibWeb: Add canvas.fill
This implements only one of the two forms of this function, ctx.fill(winding_rule). Also tweaks the quadratic curve demo to have a nice looking filled shape.
This commit is contained in:
parent
f54b41f748
commit
a82419469f
5 changed files with 52 additions and 0 deletions
|
@ -61,6 +61,7 @@ CanvasRenderingContext2DWrapper::CanvasRenderingContext2DWrapper(CanvasRendering
|
|||
put_native_function("beginPath", begin_path, 0);
|
||||
put_native_function("closePath", close_path, 0);
|
||||
put_native_function("stroke", stroke, 0);
|
||||
put_native_function("fill", fill, 0);
|
||||
put_native_function("moveTo", move_to, 2);
|
||||
put_native_function("lineTo", line_to, 2);
|
||||
put_native_function("quadraticCurveTo", quadratic_curve_to, 4);
|
||||
|
@ -219,6 +220,33 @@ JS::Value CanvasRenderingContext2DWrapper::stroke(JS::Interpreter& interpreter)
|
|||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
JS::Value CanvasRenderingContext2DWrapper::fill(JS::Interpreter& interpreter)
|
||||
{
|
||||
auto* impl = impl_from(interpreter);
|
||||
if (!impl)
|
||||
return {};
|
||||
auto winding = Gfx::Painter::WindingRule::Nonzero;
|
||||
|
||||
if (interpreter.argument_count() == 1) {
|
||||
auto arg0 = interpreter.argument(0);
|
||||
if (arg0.is_string()) {
|
||||
const auto& winding_name = arg0.as_string().string();
|
||||
if (winding_name == "evenodd") {
|
||||
winding = Gfx::Painter::WindingRule::EvenOdd;
|
||||
} else if (winding_name != "nonzero") {
|
||||
return interpreter.throw_exception<JS::TypeError>("fill winding rule must be either 'nonzero' or 'evenodd'");
|
||||
}
|
||||
} else {
|
||||
return interpreter.throw_exception<JS::TypeError>("fill called with non-string");
|
||||
}
|
||||
} else {
|
||||
// FIXME: Path2D object
|
||||
return JS::js_undefined();
|
||||
}
|
||||
impl->fill(winding);
|
||||
return JS::js_undefined();
|
||||
}
|
||||
|
||||
JS::Value CanvasRenderingContext2DWrapper::move_to(JS::Interpreter& interpreter)
|
||||
{
|
||||
auto* impl = impl_from(interpreter);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue