javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/HTML5GraphicsEnvironment.java
author Anton Epple <toni.epple@eppleton.de>
Fri, 24 May 2013 07:37:46 +0200
branchcanvas
changeset 1138 94bd7330ff58
parent 1135 836bc1845c65
child 1142 7db01893aaf8
permissions -rw-r--r--
Added Dimension class to fix problem with TextMetrics
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@1135
    18
package org.apidesign.bck2brwsr.htmlpage;
toni@521
    19
toni@1134
    20
import java.util.HashMap;
toni@1134
    21
import java.util.Set;
toni@1138
    22
import net.java.html.canvas.Dimension;
toni@1134
    23
import net.java.html.canvas.LinearGradient;
toni@1134
    24
import net.java.html.canvas.Pattern;
toni@1134
    25
import net.java.html.canvas.RadialGradient;
toni@1134
    26
import net.java.html.canvas.Style;
toni@1138
    27
import net.java.html.canvas.spi.GraphicsEnvironment;
toni@521
    28
import org.apidesign.bck2brwsr.core.JavaScriptBody;
toni@1135
    29
import org.apidesign.bck2brwsr.htmlpage.api.Canvas;
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@1135
    39
   public  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@1138
   149
////    @Override
toni@1138
   150
////    public void drawImage(Image image, double x, double y) {
toni@1138
   151
////        drawImageImpl(context, Element.getElementById((Image) image), x, y);
toni@1138
   152
////    }
toni@1138
   153
////
toni@1138
   154
////    @Override
toni@1138
   155
////    public void drawImage(Image image, double x, double y, double width, double height) {
toni@1138
   156
////        drawImageImpl(context, Element.getElementById((Image) image), x, y, width, height);
toni@1138
   157
////    }
toni@1138
   158
////
toni@1138
   159
////    @Override
toni@1138
   160
////    public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
toni@1138
   161
////        drawImageImpl(context, Element.getElementById((Image) image), sx, sy, sWidth, sHeight, x, y, width, height);
toni@1138
   162
////    }
toni@1138
   163
//
toni@1138
   164
////    @JavaScriptBody(args = {"ctx", "img", "x", "y", "width", "height"}, body = "ctx.drawImage(img,x,y,width,height);")
toni@1138
   165
////    private native static void drawImageImpl(Object ctx, Object img, double x, double y, double width, double height);
toni@1138
   166
////
toni@1138
   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@1138
   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@1138
   169
////
toni@1138
   170
////    @JavaScriptBody(args = {"ctx", "img", "x", "y"}, body = "ctx.drawImage(img,x,y);")
toni@1138
   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@1138
   215
        } 
toni@1138
   216
        else if (style instanceof Pattern) {
toni@1138
   217
//            return createPatternWrapper(((Pattern) style).getImage(), ((Pattern) style).getRepeat());
toni@1134
   218
        }
toni@1134
   219
        return null;
toni@1112
   220
    }
toni@1109
   221
toni@1134
   222
toni@1134
   223
    @JavaScriptBody(args = {"gradient", "position", "color"}, body =
toni@1134
   224
            "gradient.addColorStop(position,color)")
toni@1134
   225
    private static native void addColorStopImpl(Object gradient, double position, String color);
toni@1109
   226
toni@1112
   227
    @JavaScriptBody(args = {"context", "obj"}, body = "context.fillStyle=obj;")
toni@1112
   228
    private native void setFillStyleImpl(Object context, Object obj);
toni@1109
   229
toni@1112
   230
    @JavaScriptBody(args = {"style"}, body = "this._context().strokeStyle=style.valueOf();")
toni@1112
   231
    @Override
toni@1112
   232
    public native void setStrokeStyle(String style);
toni@1109
   233
toni@1112
   234
    @Override
toni@1134
   235
    public void setStrokeStyle(Style style) {
toni@1134
   236
        setStrokeStyleImpl(context, createFillStyle(style));
toni@1112
   237
    }
toni@1109
   238
toni@1112
   239
    @JavaScriptBody(args = {"context", "obj"}, body = "context.strokeStyle=obj;")
toni@1112
   240
    private native void setStrokeStyleImpl(Object context, Object obj);
toni@1109
   241
toni@1112
   242
    @JavaScriptBody(args = {"color"}, body = "this._context().shadowColor=color.valueOf();")
toni@1112
   243
    @Override
toni@1112
   244
    public native void setShadowColor(String color);
toni@1109
   245
toni@1112
   246
    @JavaScriptBody(args = {"blur"}, body = "this._context().shadowBlur=blur;")
toni@1112
   247
    @Override
toni@1112
   248
    public native void setShadowBlur(double blur);
toni@1109
   249
toni@1112
   250
    @JavaScriptBody(args = {"x"}, body = "this._context().shadowOffsetX=x;")
toni@1112
   251
    @Override
toni@1112
   252
    public native void setShadowOffsetX(double x);
toni@1109
   253
toni@1112
   254
    @JavaScriptBody(args = {"y"}, body = "this._context().shadowOffsetY=y;")
toni@1112
   255
    @Override
toni@1112
   256
    public native void setShadowOffsetY(double y);
toni@1109
   257
toni@1112
   258
    @JavaScriptBody(args = {}, body = "return this._context().strokeStyle;")
toni@1112
   259
    @Override
toni@1112
   260
    public native String getStrokeStyle();
toni@1109
   261
toni@1112
   262
    @JavaScriptBody(args = {}, body = "return this._context().shadowColor;")
toni@1112
   263
    @Override
toni@1112
   264
    public native String getShadowColor();
toni@1109
   265
toni@1112
   266
    @JavaScriptBody(args = {}, body = "return this._context().shadowBlur;")
toni@1112
   267
    @Override
toni@1112
   268
    public native double getShadowBlur();
toni@1109
   269
toni@1112
   270
    @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetX;")
toni@1112
   271
    @Override
toni@1112
   272
    public native double getShadowOffsetX();
toni@1109
   273
toni@1112
   274
    @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetY;")
toni@1112
   275
    @Override
toni@1112
   276
    public native double getShadowOffsetY();
toni@1109
   277
toni@1112
   278
    @JavaScriptBody(args = {}, body = "return this._context().lineCap;")
toni@1112
   279
    @Override
toni@1112
   280
    public native String getLineCap();
toni@1109
   281
toni@1112
   282
    @JavaScriptBody(args = {"style"}, body = "this._context().lineCap=style.valueOf();")
toni@1112
   283
    @Override
toni@1112
   284
    public native void setLineCap(String style);
toni@521
   285
toni@1112
   286
    @JavaScriptBody(args = {}, body = "return this._context().lineJoin;")
toni@1112
   287
    @Override
toni@1112
   288
    public native String getLineJoin();
toni@521
   289
toni@1112
   290
    @JavaScriptBody(args = {"style"}, body = "this._context().lineJoin=style.valueOf();")
toni@1112
   291
    @Override
toni@1112
   292
    public native void setLineJoin(String style);
toni@521
   293
toni@1112
   294
    @JavaScriptBody(args = {}, body = "return this._context().lineWidth;")
toni@1112
   295
    @Override
toni@1112
   296
    public native double getLineWidth();
toni@521
   297
toni@1112
   298
    @JavaScriptBody(args = {"width"}, body = "this._context().lineWidth=width;")
toni@1112
   299
    @Override
toni@1112
   300
    public native void setLineWidth(double width);
toni@521
   301
toni@1112
   302
    @JavaScriptBody(args = {}, body = "return this._context().miterLimit;")
toni@1112
   303
    @Override
toni@1112
   304
    public native double getMiterLimit();
toni@521
   305
toni@1112
   306
    @JavaScriptBody(args = {"limit"}, body = "this._context().miterLimit=limit;")
toni@1112
   307
    @Override
toni@1112
   308
    public native void setMiterLimit(double limit);
toni@1111
   309
toni@1112
   310
    @JavaScriptBody(args = {}, body = "return this._context().font;")
toni@1112
   311
    @Override
toni@1112
   312
    public native String getFont();
toni@1111
   313
toni@1112
   314
    @JavaScriptBody(args = {"font"}, body = "this._context().font=font.valueOf();")
toni@1112
   315
    @Override
toni@1112
   316
    public native void setFont(String font);
toni@1111
   317
toni@1112
   318
    @JavaScriptBody(args = {}, body = "return this._context().textAlign;")
toni@1112
   319
    @Override
toni@1112
   320
    public native String getTextAlign();
toni@1111
   321
toni@1112
   322
    @JavaScriptBody(args = {"textalign"}, body = "this._context().textAlign=textalign.valueOf();")
toni@1112
   323
    @Override
toni@1112
   324
    public native void setTextAlign(String textAlign);
toni@1111
   325
toni@1112
   326
    @JavaScriptBody(args = {}, body = "return this._context().textBaseline;")
toni@1112
   327
    @Override
toni@1112
   328
    public native String getTextBaseline();
toni@1111
   329
toni@1112
   330
    @JavaScriptBody(args = {"textbaseline"}, body = "this._context().textBaseline=textbaseline.valueOf();")
toni@1112
   331
    @Override
toni@1112
   332
    public native void setTextBaseline(String textbaseline);
toni@1111
   333
toni@1112
   334
    @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().fillText(text,x,y);")
toni@1138
   335
//    @JavaScriptBody(args = {"text", "x", "y"}, body = "console.log(text);")
toni@1112
   336
    @Override
toni@1112
   337
    public native void fillText(String text, double x, double y);
toni@1111
   338
toni@1112
   339
    @JavaScriptBody(args = {"text", "x", "y", "maxwidth"}, body = "this._context().fillText(text,x,y,maxwidth);")
toni@1112
   340
    @Override
toni@1112
   341
    public void fillText(String text, double x, double y, double maxWidth) {
toni@1112
   342
    }
toni@1111
   343
toni@1112
   344
    @Override
toni@1134
   345
    public Dimension measureText(String text) {
toni@1138
   346
        measureTextImpl(text);
toni@1138
   347
        return new Dimension(1,1);
toni@1112
   348
    }
toni@1111
   349
toni@1112
   350
    @JavaScriptBody(args = {"text"},
toni@1112
   351
            body = "return this._context().measureText(text);")
toni@1112
   352
    private native Object measureTextImpl(String text);
toni@1111
   353
toni@1112
   354
    @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().strokeText(text,x,y);")
toni@1112
   355
    @Override
toni@1112
   356
    public native void strokeText(String text, double x, double y);
toni@1111
   357
toni@1112
   358
    @JavaScriptBody(args = {"text", "x", "y", "maxWidth"}, body = "this._context().strokeText(text,x,y,maxWidth);")
toni@1112
   359
    @Override
toni@1112
   360
    public native void strokeText(String text, double x, double y, double maxWidth);
toni@1111
   361
toni@1138
   362
////    @Override
toni@1138
   363
////    public ImageData createImageData(double x, double y) {
toni@1138
   364
////        return new ImageDataWrapper(createImageDataImpl(x, y));
toni@1138
   365
////    }
toni@1138
   366
////
toni@1138
   367
////    @JavaScriptBody(args = {"x", "y"},
toni@1138
   368
////            body = "return this._context().createImageData(x,y);")
toni@1138
   369
////    private native Object createImageDataImpl(double x, double y);
toni@1138
   370
////
toni@1138
   371
////    @Override
toni@1138
   372
////    public ImageData createImageData(ImageData imageData) {
toni@1138
   373
////        return new ImageDataWrapper(createImageDataImpl(imageData.getWidth(), imageData.getHeight()));
toni@1138
   374
////    }
toni@1138
   375
////
toni@1138
   376
////    @Override
toni@1138
   377
////    public ImageData getImageData(double x, double y, double width, double height) {
toni@1138
   378
////        return new ImageDataWrapper(getImageDataImpl(x, y, width, height));
toni@1138
   379
////    }
toni@1134
   380
//
toni@1138
   381
//    @JavaScriptBody(args = {"x", "y", "width", "height"},
toni@1138
   382
//            body = "return this._context().getImageData(x,y,width,height);")
toni@1138
   383
//    private native Object getImageDataImpl(double x, double y, double width, double height);
toni@1134
   384
//
toni@1138
   385
////    @Override
toni@1138
   386
////    public void putImageData(ImageData imageData, double x, double y) {
toni@1138
   387
////        putImageDataImpl(((ImageDataWrapper) imageData).object(), x, y);
toni@1138
   388
////    }
toni@1138
   389
////
toni@1138
   390
////    @JavaScriptBody(args = {"imageData", "x", "y"},
toni@1138
   391
////            body = "this._context().putImageData(imageData,x,y);")
toni@1138
   392
////    private native void putImageDataImpl(Object imageData, double x, double y);
toni@1138
   393
////
toni@1138
   394
////    @Override
toni@1138
   395
////    public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
toni@1138
   396
////        putImageDataImpl(((ImageDataWrapper) imageData).object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
toni@1138
   397
////    }
toni@1112
   398
toni@1112
   399
    @JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"},
toni@1112
   400
            body = "this._context().putImageData(imageData,x,y, dirtyx, dirtyy, dirtywidth,dirtyheight);")
toni@1112
   401
    private native void putImageDataImpl(Object imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
toni@1112
   402
toni@1112
   403
    @JavaScriptBody(args = {"alpha"}, body = "this._context().globalAlpha=alpha;")
toni@1112
   404
    @Override
toni@1112
   405
    public native void setGlobalAlpha(double alpha);
toni@1112
   406
toni@1112
   407
    @JavaScriptBody(args = {}, body = "return this._context().globalAlpha;")
toni@1112
   408
    @Override
toni@1112
   409
    public native double getGlobalAlpha();
toni@1112
   410
toni@1112
   411
    @JavaScriptBody(args = {"operation"}, body = "this._context().globalCompositeOperation=operation.valueOf();")
toni@1112
   412
    @Override
toni@1112
   413
    public native void setGlobalCompositeOperation(String operation);
toni@1112
   414
toni@1112
   415
    @JavaScriptBody(args = {}, body = "return this._context().globalCompositeOperation;")
toni@1112
   416
    @Override
toni@1112
   417
    public native String getGlobalCompositeOperation();
toni@1112
   418
toni@1134
   419
    public LinearGradientWrapper createLinearGradientWrapper(double x0, double y0, double x1, double y1) {
toni@1134
   420
        return new LinearGradientWrapper(createLinearGradientImpl(context, x0, y0, x1, y1));
toni@1112
   421
    }
toni@1112
   422
toni@1112
   423
    @JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);")
toni@1112
   424
    private native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
toni@1112
   425
toni@1138
   426
//    public PatternWrapper createPatternWrapper(Image image, String repeat) {
toni@1138
   427
//        return new PatternWrapper(createPatternImpl(context, image, repeat));
toni@1138
   428
//    }
toni@1138
   429
//
toni@1138
   430
//    @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
toni@1138
   431
//    private static native Object createPatternImpl(Object context, Image image, String repeat);
toni@1112
   432
toni@1134
   433
    public RadialGradientWrapper createRadialGradientWrapper(double x0, double y0, double r0, double x1, double y1, double r1) {
toni@1134
   434
        return new RadialGradientWrapper(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
toni@1112
   435
    }
toni@1112
   436
toni@1112
   437
    @JavaScriptBody(args = {"context", "x0", "y0", "r0", "x1", "y1", "r1"}, body = "return context.createRadialGradient(x0,y0,r0,x1,y1,r1);")
toni@1112
   438
    private static native Object createRadialGradientImpl(Object context, double x0, double y0, double r0, double x1, double y1, double r1);
toni@1121
   439
toni@1138
   440
////  
toni@1138
   441
////    @JavaScriptBody(args = {"path"}, body = "var b = new Image(); b.src=path; return b;")
toni@1138
   442
////    public native Image getImageForPath(String path);
toni@1134
   443
toni@1134
   444
    
toni@1134
   445
    
toni@1121
   446
    @Override
toni@1134
   447
    public int getHeight() {
toni@1134
   448
       return canvas.getHeight();
toni@1121
   449
    }
toni@1134
   450
toni@1134
   451
    @Override
toni@1134
   452
    public int getWidth() {
toni@1134
   453
       return canvas.getWidth();
toni@1134
   454
    }
toni@1134
   455
toni@1134
   456
    @Override
toni@1134
   457
    public void setHeight(int height) {
toni@1134
   458
       canvas.setHeight(height);
toni@1134
   459
    }
toni@1134
   460
toni@1134
   461
    @Override
toni@1134
   462
    public void setWidth(int width) {
toni@1134
   463
       canvas.setWidth(width);
toni@1134
   464
    }
toni@1134
   465
toni@521
   466
}