javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/HTML5GraphicsEnvironment.java
author Anton Epple <toni.epple@eppleton.de>
Thu, 23 May 2013 10:02:14 +0200
branchcanvas
changeset 1134 0a2190f2a210
parent 1125 javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java@a3d504d7e588
permissions -rw-r--r--
temporarily disabled ImageData before we found a nice solution. Maybe introduce PixelReader PixelWriter for GraphicsContext.
toni@1111
     1
/**
toni@1111
     2
 * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
toni@1111
     3
 * <jaroslav.tulach@apidesign.org>
toni@1111
     4
 *
toni@1111
     5
 * This program is free software: you can redistribute it and/or modify it under
toni@1111
     6
 * the terms of the GNU General Public License as published by the Free Software
toni@1111
     7
 * Foundation, version 2 of the License.
toni@1111
     8
 *
toni@1111
     9
 * This program is distributed in the hope that it will be useful, but WITHOUT
toni@1111
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
toni@1111
    11
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
toni@1111
    12
 * details.
toni@1111
    13
 *
toni@1111
    14
 * You should have received a copy of the GNU General Public License along with
toni@1111
    15
 * this program. Look for COPYING file in the top folder. If not, see
toni@1111
    16
 * http://opensource.org/licenses/GPL-2.0.
toni@521
    17
 */
toni@1112
    18
package org.apidesign.bck2brwsr.htmlpage.api;
toni@521
    19
toni@1134
    20
import java.awt.Dimension;
toni@1134
    21
import java.util.HashMap;
toni@1134
    22
import java.util.Set;
toni@1134
    23
import net.java.html.canvas.GraphicsEnvironment;
toni@1134
    24
import net.java.html.canvas.Image;
toni@1134
    25
import net.java.html.canvas.LinearGradient;
toni@1134
    26
import net.java.html.canvas.Pattern;
toni@1134
    27
import net.java.html.canvas.RadialGradient;
toni@1134
    28
import net.java.html.canvas.Style;
toni@521
    29
import org.apidesign.bck2brwsr.core.JavaScriptBody;
toni@521
    30
toni@521
    31
/**
toni@521
    32
 *
toni@1112
    33
 * @author Anton Epple <toni.epple@eppleton.de>
toni@521
    34
 */
toni@1134
    35
public class HTML5GraphicsEnvironment implements GraphicsEnvironment {
toni@521
    36
toni@1112
    37
    Object context;
toni@1134
    38
    Canvas canvas;
toni@1134
    39
    HTML5GraphicsEnvironment(Object contextImpl, Canvas canvas) {
toni@1112
    40
        this.context = contextImpl;
toni@1134
    41
        this.canvas = canvas;
toni@1112
    42
    }
toni@1112
    43
toni@1112
    44
    @JavaScriptBody(args = {"centerx", "centery", "radius", "startangle", "endangle", "ccw"},
toni@1112
    45
            body = "this._context().arc(centerx,centery, radius, startangle, endangle,ccw);")
toni@1112
    46
    @Override
toni@1112
    47
    public native void arc(double centerX,
toni@1111
    48
            double centerY,
toni@1111
    49
            double startAngle,
toni@1111
    50
            double radius,
toni@1111
    51
            double endAngle,
toni@1111
    52
            boolean ccw);
toni@521
    53
toni@1112
    54
    @JavaScriptBody(args = {"x1", "y1", "x2", "y2", "r"},
toni@1112
    55
            body = "this._context().arcTo(x1,y1,x2,y2,r);")
toni@1112
    56
    @Override
toni@1112
    57
    public native void arcTo(double x1,
toni@1111
    58
            double y1,
toni@1111
    59
            double x2,
toni@1111
    60
            double y2,
toni@1111
    61
            double r);
toni@521
    62
toni@1112
    63
    @JavaScriptBody(args = {"x", "y"},
toni@1112
    64
            body = "return this._context().isPointInPath(x,y);")
toni@1112
    65
    @Override
toni@1112
    66
    public native boolean isPointInPath(double x, double y);
toni@521
    67
toni@1112
    68
    @JavaScriptBody(args = {}, body = "this._context().fill();")
toni@1112
    69
    @Override
toni@1112
    70
    public native void fill();
toni@521
    71
toni@1112
    72
    @JavaScriptBody(args = {}, body = "this._context().stroke();")
toni@1112
    73
    @Override
toni@1112
    74
    public native void stroke();
toni@1109
    75
toni@1112
    76
    @JavaScriptBody(args = {}, body = "this._context().beginPath();")
toni@1112
    77
    @Override
toni@1112
    78
    public native void beginPath();
toni@1109
    79
toni@1112
    80
    @JavaScriptBody(args = {}, body = "this._context().closePath();")
toni@1112
    81
    @Override
toni@1112
    82
    public native void closePath();
toni@521
    83
toni@1112
    84
    @JavaScriptBody(args = {}, body = "this._context().clip();")
toni@1112
    85
    @Override
toni@1112
    86
    public native void clip();
toni@1109
    87
toni@1112
    88
    @JavaScriptBody(args = {"x", "y"}, body = "this._context().moveTo(x,y);")
toni@1112
    89
    @Override
toni@1112
    90
    public native void moveTo(double x, double y);
toni@1109
    91
toni@1112
    92
    @JavaScriptBody(args = {"x", "y"}, body = "this._context().lineTo(x,y);")
toni@1112
    93
    @Override
toni@1112
    94
    public native void lineTo(double x, double y);
toni@1109
    95
toni@1112
    96
    @JavaScriptBody(args = {"cpx", "cpy", "x", "y"}, body = "this._context().quadraticCurveTo(cpx,cpy,x,y);")
toni@1112
    97
    @Override
toni@1112
    98
    public native void quadraticCurveTo(double cpx, double cpy, double x, double y);
toni@1109
    99
toni@1112
   100
    @JavaScriptBody(args = {"cp1x", "cp1y", "cp2x", "cp2y", "x", "y"},
toni@1112
   101
            body = "this._context().bezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y);")
toni@1112
   102
    @Override
toni@1112
   103
    public native void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
toni@1109
   104
toni@1112
   105
    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().fillRect(x,y,width,height);")
toni@1112
   106
    @Override
toni@1112
   107
    public native void fillRect(double x, double y, double width, double height);
toni@1109
   108
toni@1112
   109
    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().strokeRect(x,y,width,height);")
toni@1112
   110
    @Override
toni@1112
   111
    public native void strokeRect(double x, double y, double width, double height);
toni@1109
   112
toni@1112
   113
    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().clearRect(x,y,width,height);")
toni@1112
   114
    @Override
toni@1112
   115
    public native void clearRect(double x, double y, double width, double height);
toni@1109
   116
toni@1112
   117
    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().rectect(x,y,width,height);")
toni@1112
   118
    @Override
toni@1112
   119
    public native void rect(double x, double y, double width, double height);
toni@1109
   120
toni@1112
   121
    @JavaScriptBody(args = {}, body = "this._context().save();")
toni@1112
   122
    @Override
toni@1112
   123
    public native void save();
toni@1109
   124
toni@1112
   125
    @JavaScriptBody(args = {}, body = "this._context().restore();")
toni@1112
   126
    @Override
toni@1112
   127
    public native void restore();
toni@1109
   128
toni@1112
   129
    @JavaScriptBody(args = {"angle"}, body = "this._context().rotate(angle);")
toni@1112
   130
    @Override
toni@1112
   131
    public native void rotate(double angle);
toni@1109
   132
toni@1112
   133
    @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().transform(a,b,c,d,e,f);")
toni@1112
   134
    @Override
toni@1112
   135
    public native void transform(double a, double b, double c, double d, double e, double f);
toni@1109
   136
toni@1112
   137
    @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().setTransform(a,b,c,d,e,f);")
toni@1112
   138
    @Override
toni@1112
   139
    public native void setTransform(double a, double b, double c, double d, double e, double f);
toni@1109
   140
toni@1112
   141
    @JavaScriptBody(args = {"x", "y"}, body = "this._context().translate(x,y);")
toni@1112
   142
    @Override
toni@1112
   143
    public native void translate(double x, double y);
toni@1109
   144
toni@1112
   145
    @JavaScriptBody(args = {"x", "y"}, body = "this._context().scale(x,y);")
toni@1112
   146
    @Override
toni@1112
   147
    public native void scale(double x, double y);
toni@1109
   148
toni@1112
   149
    @Override
toni@1134
   150
    public void drawImage(Image image, double x, double y) {
toni@1134
   151
        drawImageImpl(context, Element.getElementById((ImageWrapper) image), x, y);
toni@1112
   152
    }
toni@1109
   153
toni@1112
   154
    @Override
toni@1134
   155
    public void drawImage(Image image, double x, double y, double width, double height) {
toni@1134
   156
        drawImageImpl(context, Element.getElementById((ImageWrapper) image), x, y, width, height);
toni@1112
   157
    }
toni@1109
   158
toni@1112
   159
    @Override
toni@1134
   160
    public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
toni@1134
   161
        drawImageImpl(context, Element.getElementById((ImageWrapper) image), sx, sy, sWidth, sHeight, x, y, width, height);
toni@1112
   162
    }
toni@1109
   163
toni@1112
   164
    @JavaScriptBody(args = {"ctx", "img", "x", "y", "width", "height"}, body = "ctx.drawImage(img,x,y,width,height);")
toni@1112
   165
    private native static void drawImageImpl(Object ctx, Object img, double x, double y, double width, double height);
toni@1109
   166
toni@1112
   167
    @JavaScriptBody(args = {"ctx", "img", "sx", "sy", "swidth", "sheight", "x", "y", "width", "height"}, body = "ctx.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);")
toni@1112
   168
    private native static void drawImageImpl(Object ctx, Object img, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height);
toni@1109
   169
toni@1112
   170
    @JavaScriptBody(args = {"ctx", "img", "x", "y"}, body = "ctx.drawImage(img,x,y);")
toni@1112
   171
    private native static void drawImageImpl(Object ctx, Object img, double x, double y);
toni@1109
   172
toni@1112
   173
    @JavaScriptBody(args = {"style"}, body = "this._context().fillStyle=style.valueOf();")
toni@1112
   174
    @Override
toni@1112
   175
    public native void setFillStyle(String style);
toni@1109
   176
toni@1112
   177
    @JavaScriptBody(args = {}, body = "return this._context().fillStyle;")
toni@1112
   178
    @Override
toni@1112
   179
    public native String getFillStyle();
toni@1109
   180
toni@1112
   181
    @Override
toni@1134
   182
    public void setFillStyle(Style style) {
toni@1134
   183
        setFillStyleImpl(context, createFillStyle(style));
toni@1112
   184
    }
toni@1109
   185
toni@1134
   186
    private Object createFillStyle(Style style) {
toni@1134
   187
        if (style instanceof RadialGradient) {
toni@1134
   188
            RadialGradientWrapper gradient = createRadialGradientWrapper(
toni@1134
   189
                    ((RadialGradient) style).getX0(),
toni@1134
   190
                    ((RadialGradient) style).getY0(),
toni@1134
   191
                    ((RadialGradient) style).getR0(),
toni@1134
   192
                    ((RadialGradient) style).getX1(),
toni@1134
   193
                    ((RadialGradient) style).getY1(),
toni@1134
   194
                    ((RadialGradient) style).getR1());
toni@1134
   195
            HashMap<Double, String> stops = ((LinearGradient) style).getStops();
toni@1134
   196
            Set<Double> keySet = stops.keySet();
toni@1134
   197
            for (Double double1 : keySet) {
toni@1134
   198
                addColorStopImpl(style, double1, stops.get(double1));
toni@1134
   199
            }
toni@1134
   200
            return gradient;
toni@1134
   201
toni@1134
   202
toni@1134
   203
        } else if (style instanceof LinearGradient) {
toni@1134
   204
            LinearGradientWrapper gradient = createLinearGradientWrapper(
toni@1134
   205
                    ((LinearGradient) style).getX0(),
toni@1134
   206
                    ((LinearGradient) style).getY0(),
toni@1134
   207
                    ((LinearGradient) style).getX1(),
toni@1134
   208
                    ((LinearGradient) style).getY1());
toni@1134
   209
            HashMap<Double, String> stops = ((LinearGradient) style).getStops();
toni@1134
   210
            Set<Double> keySet = stops.keySet();
toni@1134
   211
            for (Double double1 : keySet) {
toni@1134
   212
                addColorStopImpl(style, double1, stops.get(double1));
toni@1134
   213
            }
toni@1134
   214
            return gradient;
toni@1134
   215
        } else if (style instanceof Pattern) {
toni@1134
   216
            return createPatternWrapper(((Pattern) style).getImageData(), ((Pattern) style).getRepeat());
toni@1134
   217
        }
toni@1134
   218
        return null;
toni@1112
   219
    }
toni@1109
   220
toni@1134
   221
toni@1134
   222
    @JavaScriptBody(args = {"gradient", "position", "color"}, body =
toni@1134
   223
            "gradient.addColorStop(position,color)")
toni@1134
   224
    private static native void addColorStopImpl(Object gradient, double position, String color);
toni@1109
   225
toni@1112
   226
    @JavaScriptBody(args = {"context", "obj"}, body = "context.fillStyle=obj;")
toni@1112
   227
    private native void setFillStyleImpl(Object context, Object obj);
toni@1109
   228
toni@1112
   229
    @JavaScriptBody(args = {"style"}, body = "this._context().strokeStyle=style.valueOf();")
toni@1112
   230
    @Override
toni@1112
   231
    public native void setStrokeStyle(String style);
toni@1109
   232
toni@1112
   233
    @Override
toni@1134
   234
    public void setStrokeStyle(Style style) {
toni@1134
   235
        setStrokeStyleImpl(context, createFillStyle(style));
toni@1112
   236
    }
toni@1109
   237
toni@1112
   238
    @JavaScriptBody(args = {"context", "obj"}, body = "context.strokeStyle=obj;")
toni@1112
   239
    private native void setStrokeStyleImpl(Object context, Object obj);
toni@1109
   240
toni@1112
   241
    @JavaScriptBody(args = {"color"}, body = "this._context().shadowColor=color.valueOf();")
toni@1112
   242
    @Override
toni@1112
   243
    public native void setShadowColor(String color);
toni@1109
   244
toni@1112
   245
    @JavaScriptBody(args = {"blur"}, body = "this._context().shadowBlur=blur;")
toni@1112
   246
    @Override
toni@1112
   247
    public native void setShadowBlur(double blur);
toni@1109
   248
toni@1112
   249
    @JavaScriptBody(args = {"x"}, body = "this._context().shadowOffsetX=x;")
toni@1112
   250
    @Override
toni@1112
   251
    public native void setShadowOffsetX(double x);
toni@1109
   252
toni@1112
   253
    @JavaScriptBody(args = {"y"}, body = "this._context().shadowOffsetY=y;")
toni@1112
   254
    @Override
toni@1112
   255
    public native void setShadowOffsetY(double y);
toni@1109
   256
toni@1112
   257
    @JavaScriptBody(args = {}, body = "return this._context().strokeStyle;")
toni@1112
   258
    @Override
toni@1112
   259
    public native String getStrokeStyle();
toni@1109
   260
toni@1112
   261
    @JavaScriptBody(args = {}, body = "return this._context().shadowColor;")
toni@1112
   262
    @Override
toni@1112
   263
    public native String getShadowColor();
toni@1109
   264
toni@1112
   265
    @JavaScriptBody(args = {}, body = "return this._context().shadowBlur;")
toni@1112
   266
    @Override
toni@1112
   267
    public native double getShadowBlur();
toni@1109
   268
toni@1112
   269
    @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetX;")
toni@1112
   270
    @Override
toni@1112
   271
    public native double getShadowOffsetX();
toni@1109
   272
toni@1112
   273
    @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetY;")
toni@1112
   274
    @Override
toni@1112
   275
    public native double getShadowOffsetY();
toni@1109
   276
toni@1112
   277
    @JavaScriptBody(args = {}, body = "return this._context().lineCap;")
toni@1112
   278
    @Override
toni@1112
   279
    public native String getLineCap();
toni@1109
   280
toni@1112
   281
    @JavaScriptBody(args = {"style"}, body = "this._context().lineCap=style.valueOf();")
toni@1112
   282
    @Override
toni@1112
   283
    public native void setLineCap(String style);
toni@521
   284
toni@1112
   285
    @JavaScriptBody(args = {}, body = "return this._context().lineJoin;")
toni@1112
   286
    @Override
toni@1112
   287
    public native String getLineJoin();
toni@521
   288
toni@1112
   289
    @JavaScriptBody(args = {"style"}, body = "this._context().lineJoin=style.valueOf();")
toni@1112
   290
    @Override
toni@1112
   291
    public native void setLineJoin(String style);
toni@521
   292
toni@1112
   293
    @JavaScriptBody(args = {}, body = "return this._context().lineWidth;")
toni@1112
   294
    @Override
toni@1112
   295
    public native double getLineWidth();
toni@521
   296
toni@1112
   297
    @JavaScriptBody(args = {"width"}, body = "this._context().lineWidth=width;")
toni@1112
   298
    @Override
toni@1112
   299
    public native void setLineWidth(double width);
toni@521
   300
toni@1112
   301
    @JavaScriptBody(args = {}, body = "return this._context().miterLimit;")
toni@1112
   302
    @Override
toni@1112
   303
    public native double getMiterLimit();
toni@521
   304
toni@1112
   305
    @JavaScriptBody(args = {"limit"}, body = "this._context().miterLimit=limit;")
toni@1112
   306
    @Override
toni@1112
   307
    public native void setMiterLimit(double limit);
toni@1111
   308
toni@1112
   309
    @JavaScriptBody(args = {}, body = "return this._context().font;")
toni@1112
   310
    @Override
toni@1112
   311
    public native String getFont();
toni@1111
   312
toni@1112
   313
    @JavaScriptBody(args = {"font"}, body = "this._context().font=font.valueOf();")
toni@1112
   314
    @Override
toni@1112
   315
    public native void setFont(String font);
toni@1111
   316
toni@1112
   317
    @JavaScriptBody(args = {}, body = "return this._context().textAlign;")
toni@1112
   318
    @Override
toni@1112
   319
    public native String getTextAlign();
toni@1111
   320
toni@1112
   321
    @JavaScriptBody(args = {"textalign"}, body = "this._context().textAlign=textalign.valueOf();")
toni@1112
   322
    @Override
toni@1112
   323
    public native void setTextAlign(String textAlign);
toni@1111
   324
toni@1112
   325
    @JavaScriptBody(args = {}, body = "return this._context().textBaseline;")
toni@1112
   326
    @Override
toni@1112
   327
    public native String getTextBaseline();
toni@1111
   328
toni@1112
   329
    @JavaScriptBody(args = {"textbaseline"}, body = "this._context().textBaseline=textbaseline.valueOf();")
toni@1112
   330
    @Override
toni@1112
   331
    public native void setTextBaseline(String textbaseline);
toni@1111
   332
toni@1112
   333
    @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().fillText(text,x,y);")
toni@1112
   334
    @Override
toni@1112
   335
    public native void fillText(String text, double x, double y);
toni@1111
   336
toni@1112
   337
    @JavaScriptBody(args = {"text", "x", "y", "maxwidth"}, body = "this._context().fillText(text,x,y,maxwidth);")
toni@1112
   338
    @Override
toni@1112
   339
    public void fillText(String text, double x, double y, double maxWidth) {
toni@1112
   340
    }
toni@1111
   341
toni@1112
   342
    @Override
toni@1134
   343
    public Dimension measureText(String text) {
toni@1134
   344
        TextMetrics textMetrics = new TextMetrics(measureTextImpl(text));
toni@1134
   345
        return new Dimension((int) textMetrics.getWidth(), (int) textMetrics.getHeight());
toni@1112
   346
    }
toni@1111
   347
toni@1112
   348
    @JavaScriptBody(args = {"text"},
toni@1112
   349
            body = "return this._context().measureText(text);")
toni@1112
   350
    private native Object measureTextImpl(String text);
toni@1111
   351
toni@1112
   352
    @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().strokeText(text,x,y);")
toni@1112
   353
    @Override
toni@1112
   354
    public native void strokeText(String text, double x, double y);
toni@1111
   355
toni@1112
   356
    @JavaScriptBody(args = {"text", "x", "y", "maxWidth"}, body = "this._context().strokeText(text,x,y,maxWidth);")
toni@1112
   357
    @Override
toni@1112
   358
    public native void strokeText(String text, double x, double y, double maxWidth);
toni@1111
   359
toni@1134
   360
//    @Override
toni@1134
   361
//    public Image createImageData(double x, double y) {
toni@1134
   362
//        return new ImageDataWrapper(createImageDataImpl(x, y));
toni@1134
   363
//    }
toni@1134
   364
//
toni@1134
   365
//    @JavaScriptBody(args = {"x", "y"},
toni@1134
   366
//            body = "return this._context().createImageData(x,y);")
toni@1134
   367
//    private native Object createImageDataImpl(double x, double y);
toni@1134
   368
//
toni@1134
   369
//    @Override
toni@1134
   370
//    public Image createImageData(Image imageData) {
toni@1134
   371
//        return new ImageDataWrapper(createImageDataImpl(imageData.getWidth(), imageData.getHeight()));
toni@1134
   372
//    }
toni@1134
   373
//
toni@1134
   374
//    @Override
toni@1134
   375
//    public Image getImageData(double x, double y, double width, double height) {
toni@1134
   376
//        return new ImageDataWrapper(getImageDataImpl(x, y, width, height));
toni@1134
   377
//    }
toni@1111
   378
toni@1112
   379
    @JavaScriptBody(args = {"x", "y", "width", "height"},
toni@1112
   380
            body = "return this._context().getImageData(x,y,width,height);")
toni@1112
   381
    private native Object getImageDataImpl(double x, double y, double width, double height);
toni@1111
   382
toni@1134
   383
//    @Override
toni@1134
   384
//    public void putImageData(Image imageData, double x, double y) {
toni@1134
   385
//        putImageDataImpl(((ImageDataWrapper) imageData).object(), x, y);
toni@1134
   386
//    }
toni@1134
   387
//
toni@1134
   388
//    @JavaScriptBody(args = {"imageData", "x", "y"},
toni@1134
   389
//            body = "this._context().putImageData(imageData,x,y);")
toni@1134
   390
//    private native void putImageDataImpl(Object imageData, double x, double y);
toni@1134
   391
//
toni@1134
   392
//    @Override
toni@1134
   393
//    public void putImageData(Image imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
toni@1134
   394
//        putImageDataImpl(((ImageDataWrapper) imageData).object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
toni@1134
   395
//    }
toni@1112
   396
toni@1112
   397
    @JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"},
toni@1112
   398
            body = "this._context().putImageData(imageData,x,y, dirtyx, dirtyy, dirtywidth,dirtyheight);")
toni@1112
   399
    private native void putImageDataImpl(Object imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
toni@1112
   400
toni@1112
   401
    @JavaScriptBody(args = {"alpha"}, body = "this._context().globalAlpha=alpha;")
toni@1112
   402
    @Override
toni@1112
   403
    public native void setGlobalAlpha(double alpha);
toni@1112
   404
toni@1112
   405
    @JavaScriptBody(args = {}, body = "return this._context().globalAlpha;")
toni@1112
   406
    @Override
toni@1112
   407
    public native double getGlobalAlpha();
toni@1112
   408
toni@1112
   409
    @JavaScriptBody(args = {"operation"}, body = "this._context().globalCompositeOperation=operation.valueOf();")
toni@1112
   410
    @Override
toni@1112
   411
    public native void setGlobalCompositeOperation(String operation);
toni@1112
   412
toni@1112
   413
    @JavaScriptBody(args = {}, body = "return this._context().globalCompositeOperation;")
toni@1112
   414
    @Override
toni@1112
   415
    public native String getGlobalCompositeOperation();
toni@1112
   416
toni@1134
   417
    public LinearGradientWrapper createLinearGradientWrapper(double x0, double y0, double x1, double y1) {
toni@1134
   418
        return new LinearGradientWrapper(createLinearGradientImpl(context, x0, y0, x1, y1));
toni@1112
   419
    }
toni@1112
   420
toni@1112
   421
    @JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);")
toni@1112
   422
    private native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
toni@1112
   423
toni@1134
   424
    public PatternWrapper createPatternWrapper(Image image, String repeat) {
toni@1134
   425
        return new PatternWrapper(createPatternImpl(context, image, repeat));
toni@1112
   426
    }
toni@1112
   427
toni@1112
   428
    @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
toni@1134
   429
    private static native Object createPatternImpl(Object context, Image image, String repeat);
toni@1112
   430
toni@1134
   431
    public RadialGradientWrapper createRadialGradientWrapper(double x0, double y0, double r0, double x1, double y1, double r1) {
toni@1134
   432
        return new RadialGradientWrapper(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
toni@1112
   433
    }
toni@1112
   434
toni@1112
   435
    @JavaScriptBody(args = {"context", "x0", "y0", "r0", "x1", "y1", "r1"}, body = "return context.createRadialGradient(x0,y0,r0,x1,y1,r1);")
toni@1112
   436
    private static native Object createRadialGradientImpl(Object context, double x0, double y0, double r0, double x1, double y1, double r1);
toni@1121
   437
toni@1134
   438
  
toni@1122
   439
    @JavaScriptBody(args = {"path"}, body = "var b = new Image(); b.src=path; return b;")
toni@1134
   440
    public native ImageWrapper getImageForPath(String path);
toni@1134
   441
toni@1134
   442
    
toni@1134
   443
    
toni@1121
   444
    @Override
toni@1134
   445
    public int getHeight() {
toni@1134
   446
       return canvas.getHeight();
toni@1121
   447
    }
toni@1134
   448
toni@1134
   449
    @Override
toni@1134
   450
    public int getWidth() {
toni@1134
   451
       return canvas.getWidth();
toni@1134
   452
    }
toni@1134
   453
toni@1134
   454
    @Override
toni@1134
   455
    public void setHeight(int height) {
toni@1134
   456
       canvas.setHeight(height);
toni@1134
   457
    }
toni@1134
   458
toni@1134
   459
    @Override
toni@1134
   460
    public void setWidth(int width) {
toni@1134
   461
       canvas.setWidth(width);
toni@1134
   462
    }
toni@1134
   463
toni@521
   464
}