Get an attribute from a GWT object via jsni?

247 views
Skip to first unread message

markww

unread,
Nov 24, 2012, 10:05:28 AM11/24/12
to google-we...@googlegroups.com
Hi,

I'm using Canvas, I need to get a property from the context:

    context.webkitBackingStorePixelRatio;

I'm not sure how to make a jsni function to do this (this property does not seem to have a wrapper already in the gwt Context2d class):

    // How do we define this function and pass in our GWT Context2d instance?
    public static native double getBackingStoreRatio(Context2d context) /*-{
        return context.webkitBackingStorePixelRatio || 1;
    }-*/;

    Canvas canvas = Canvas.createIfSupported();
    Context2d context = canvas.getContext2d();
    double isThatRight = getBackingStoreRation(context);

Yeah I'm not sure what the sytax is for this, the Context2d variable is a GWT object already,

Thanks

(trying to get the variables from this article for hdpi screen support)

Sebastián Gurin

unread,
Nov 24, 2012, 3:51:40 PM11/24/12
to google-we...@googlegroups.com
that should work... What is the result ?

Andrea Boscolo

unread,
Nov 25, 2012, 6:30:46 AM11/25/12
to google-we...@googlegroups.com
Try with

return context.@com.google.gwt.canvas.dom.client.Context2d::webkitBackingStorePixelRatio;

but I don't think it will ever work.

Sebastián Gurin

unread,
Nov 25, 2012, 12:25:55 PM11/25/12
to google-we...@googlegroups.com
no,
com.google.gwt.canvas.dom.client.Context2d is a JavaScriptObject so just treat it as a javascript object not as a java object in jsni code. . 
Reply all
Reply to author
Forward
0 new messages