Question

I want to extend Context2d in order to create a specific method that can be invoked by context.myMethod();

Using this class:

class MyContext extends Context2d {
    public myMethod();
}

BUT I'm creating the canvas by Canvas canvas = Canvas.createIfSupported(); and thus I would get the Context2d by canvas.getContext2d();

How can I now force the latest method to return MyContext class which extends the Context2d, as there is no setContext2d() on a canvas element...

Était-ce utile?

La solution

Context2d is a JavaScriptObject so all you need is to cast it to MyContext and/or use the cast() method:

MyContext ctx = canvas.getContext2d().cast();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top