diff -r 8c88d0f187d8 -r 024b165f8f21 javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/HTML5GraphicsContext.java --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/HTML5GraphicsContext.java Fri May 17 12:06:36 2013 +0200 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/HTML5GraphicsContext.java Fri May 17 12:06:55 2013 +0200 @@ -1,23 +1,29 @@ /** - * Back 2 Browser Bytecode Translator - * Copyright (C) 2012 Jaroslav Tulach + * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach + * * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2 of the License. + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 2 of the License. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. * - * You should have received a copy of the GNU General Public License - * along with this program. Look for COPYING file in the top folder. - * If not, see http://opensource.org/licenses/GPL-2.0. + * You should have received a copy of the GNU General Public License along with + * this program. Look for COPYING file in the top folder. If not, see + * http://opensource.org/licenses/GPL-2.0. */ package org.apidesign.bck2brwsr.htmlpage.api; import net.java.html.canvas.GraphicsContext; +import net.java.html.canvas.Image; +import net.java.html.canvas.ImageData; +import net.java.html.canvas.LinearGradient; +import net.java.html.canvas.Pattern; +import net.java.html.canvas.RadialGradient; +import net.java.html.canvas.TextMetrics; import org.apidesign.bck2brwsr.core.JavaScriptBody; /** @@ -137,16 +143,19 @@ @Override public native void scale(double x, double y); + @Override public void drawImage(Image image, double x, double y) { - drawImageImpl(context, Element.getElementById(image), x, y); + drawImageImpl(context, Element.getElementById((HTML5Image)image), x, y); } + @Override public void drawImage(Image image, double x, double y, double width, double height) { - drawImageImpl(context, Element.getElementById(image), x, y, width, height); + drawImageImpl(context, Element.getElementById((HTML5Image)image), x, y, width, height); } + @Override public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) { - drawImageImpl(context, Element.getElementById(image), sx, sy, sWidth, sHeight, x, y, width, height); + drawImageImpl(context, Element.getElementById((HTML5Image)image), sx, sy, sWidth, sHeight, x, y, width, height); } @JavaScriptBody(args = {"ctx", "img", "x", "y", "width", "height"}, body = "ctx.drawImage(img,x,y,width,height);") @@ -166,39 +175,44 @@ @Override public native String getFillStyle(); + @Override public void setFillStyle(LinearGradient style) { - setFillStyleImpl(context, style.object()); + setFillStyleImpl(context, ((HTML5LinearGradient)style).object()); } + @Override public void setFillStyle(RadialGradient style) { - setFillStyleImpl(context, style.object()); + setFillStyleImpl(context, ((HTML5RadialGradient)style).object()); } + @Override public void setFillStyle(Pattern style) { - setFillStyleImpl(context, style.object()); + setFillStyleImpl(context, ((HTML5Pattern)style).object()); } - @JavaScriptBody(args = {"context","obj"}, body = "context.fillStyle=obj;") + @JavaScriptBody(args = {"context", "obj"}, body = "context.fillStyle=obj;") private native void setFillStyleImpl(Object context, Object obj); @JavaScriptBody(args = {"style"}, body = "this._context().strokeStyle=style.valueOf();") @Override public native void setStrokeStyle(String style); + @Override public void setStrokeStyle(LinearGradient style) { - setStrokeStyleImpl(context, style.object()); + setStrokeStyleImpl(context, ((HTML5LinearGradient)style).object()); } public void setStrokeStyle(RadialGradient style) { - setStrokeStyleImpl(context, style.object()); + setStrokeStyleImpl(context, ((HTML5RadialGradient)style).object()); } @JavaScriptBody(args = {"style"}, body = "this._context().fillStyle=style;") + @Override public void setStrokeStyle(Pattern style) { - setStrokeStyleImpl(context, style.object()); + setStrokeStyleImpl(context, ((HTML5LinearGradient)style).object()); } - @JavaScriptBody(args = {"context","obj"}, body = "context.strokeStyle=obj;") + @JavaScriptBody(args = {"context", "obj"}, body = "context.strokeStyle=obj;") private native void setStrokeStyleImpl(Object context, Object obj); @JavaScriptBody(args = {"color"}, body = "this._context().shadowColor=color.valueOf();") @@ -208,7 +222,7 @@ @JavaScriptBody(args = {"blur"}, body = "this._context().shadowBlur=blur;") @Override public native void setShadowBlur(double blur); - + @JavaScriptBody(args = {"x"}, body = "this._context().shadowOffsetX=x;") @Override public native void setShadowOffsetX(double x); @@ -302,8 +316,9 @@ public void fillText(String text, double x, double y, double maxWidth) { } + @Override public TextMetrics measureText(String text) { - return new TextMetrics(measureTextImpl(text)); + return new HTML5TextMetrics(measureTextImpl(text)); } @JavaScriptBody(args = {"text"}, @@ -318,36 +333,41 @@ @Override public native void strokeText(String text, double x, double y, double maxWidth); + @Override public ImageData createImageData(double x, double y) { - return new ImageData(createImageDataImpl(x, y)); + return new HTML5ImageData(createImageDataImpl(x, y)); } @JavaScriptBody(args = {"x", "y"}, body = "return this._context().createImageData(x,y);") private native Object createImageDataImpl(double x, double y); + @Override public ImageData createImageData(ImageData imageData) { - return new ImageData(createImageDataImpl(imageData.getWidth(), imageData.getHeight())); + return new HTML5ImageData(createImageDataImpl(imageData.getWidth(), imageData.getHeight())); } + @Override public ImageData getImageData(double x, double y, double width, double height) { - return new ImageData(getImageDataImpl(x, y, width, height)); + return new HTML5ImageData(getImageDataImpl(x, y, width, height)); } @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "return this._context().getImageData(x,y,width,height);") private native Object getImageDataImpl(double x, double y, double width, double height); + @Override public void putImageData(ImageData imageData, double x, double y) { - putImageDataImpl(imageData.object(), x, y); + putImageDataImpl(((HTML5ImageData)imageData).object(), x, y); } @JavaScriptBody(args = {"imageData", "x", "y"}, body = "this._context().putImageData(imageData,x,y);") private native void putImageDataImpl(Object imageData, double x, double y); + @Override public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) { - putImageDataImpl(imageData.object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight); + putImageDataImpl(((HTML5ImageData)imageData).object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight); } @JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"}, @@ -370,22 +390,25 @@ @Override public native String getGlobalCompositeOperation(); - public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) { - return new LinearGradient(createLinearGradientImpl(context, x0, y0, x1, y1)); + @Override + public HTML5LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) { + return new HTML5LinearGradient(createLinearGradientImpl(context, x0, y0, x1, y1)); } @JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);") - private native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1); + private native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1); + @Override public Pattern createPattern(Image image, String repeat) { - return new Pattern(createPatternImpl(context, image, repeat)); + return new HTML5Pattern(createPatternImpl(context, image, repeat)); } @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);") private static native Object createPatternImpl(Object context, Image image, String repeat); - public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) { - return new RadialGradient(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1)); + @Override + public HTML5RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) { + return new HTML5RadialGradient(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1)); } @JavaScriptBody(args = {"context", "x0", "y0", "r0", "x1", "y1", "r1"}, body = "return context.createRadialGradient(x0,y0,r0,x1,y1,r1);")