javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/HTML5GraphicsEnvironment.java
author Anton Epple <toni.epple@eppleton.de>
Fri, 24 May 2013 12:34:38 +0200
branchcanvas
changeset 1142 7db01893aaf8
parent 1138 94bd7330ff58
child 1145 0e2c3676d77a
permissions -rw-r--r--
added caching of style to implementation
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@1142
    39
toni@1142
    40
    public HTML5GraphicsEnvironment(Object contextImpl, Canvas canvas) {
toni@1112
    41
        this.context = contextImpl;
toni@1134
    42
        this.canvas = canvas;
toni@1112
    43
    }
toni@1112
    44
toni@1112
    45
    @JavaScriptBody(args = {"centerx", "centery", "radius", "startangle", "endangle", "ccw"},
toni@1112
    46
            body = "this._context().arc(centerx,centery, radius, startangle, endangle,ccw);")
toni@1112
    47
    @Override
toni@1112
    48
    public native void arc(double centerX,
toni@1111
    49
            double centerY,
toni@1111
    50
            double startAngle,
toni@1111
    51
            double radius,
toni@1111
    52
            double endAngle,
toni@1111
    53
            boolean ccw);
toni@521
    54
toni@1112
    55
    @JavaScriptBody(args = {"x1", "y1", "x2", "y2", "r"},
toni@1112
    56
            body = "this._context().arcTo(x1,y1,x2,y2,r);")
toni@1112
    57
    @Override
toni@1112
    58
    public native void arcTo(double x1,
toni@1111
    59
            double y1,
toni@1111
    60
            double x2,
toni@1111
    61
            double y2,
toni@1111
    62
            double r);
toni@521
    63
toni@1112
    64
    @JavaScriptBody(args = {"x", "y"},
toni@1112
    65
            body = "return this._context().isPointInPath(x,y);")
toni@1112
    66
    @Override
toni@1112
    67
    public native boolean isPointInPath(double x, double y);
toni@521
    68
toni@1112
    69
    @JavaScriptBody(args = {}, body = "this._context().fill();")
toni@1112
    70
    @Override
toni@1112
    71
    public native void fill();
toni@521
    72
toni@1112
    73
    @JavaScriptBody(args = {}, body = "this._context().stroke();")
toni@1112
    74
    @Override
toni@1112
    75
    public native void stroke();
toni@1109
    76
toni@1112
    77
    @JavaScriptBody(args = {}, body = "this._context().beginPath();")
toni@1112
    78
    @Override
toni@1112
    79
    public native void beginPath();
toni@1109
    80
toni@1112
    81
    @JavaScriptBody(args = {}, body = "this._context().closePath();")
toni@1112
    82
    @Override
toni@1112
    83
    public native void closePath();
toni@521
    84
toni@1112
    85
    @JavaScriptBody(args = {}, body = "this._context().clip();")
toni@1112
    86
    @Override
toni@1112
    87
    public native void clip();
toni@1109
    88
toni@1112
    89
    @JavaScriptBody(args = {"x", "y"}, body = "this._context().moveTo(x,y);")
toni@1112
    90
    @Override
toni@1112
    91
    public native void moveTo(double x, double y);
toni@1109
    92
toni@1112
    93
    @JavaScriptBody(args = {"x", "y"}, body = "this._context().lineTo(x,y);")
toni@1112
    94
    @Override
toni@1112
    95
    public native void lineTo(double x, double y);
toni@1109
    96
toni@1112
    97
    @JavaScriptBody(args = {"cpx", "cpy", "x", "y"}, body = "this._context().quadraticCurveTo(cpx,cpy,x,y);")
toni@1112
    98
    @Override
toni@1112
    99
    public native void quadraticCurveTo(double cpx, double cpy, double x, double y);
toni@1109
   100
toni@1112
   101
    @JavaScriptBody(args = {"cp1x", "cp1y", "cp2x", "cp2y", "x", "y"},
toni@1112
   102
            body = "this._context().bezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y);")
toni@1112
   103
    @Override
toni@1112
   104
    public native void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
toni@1109
   105
toni@1112
   106
    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().fillRect(x,y,width,height);")
toni@1112
   107
    @Override
toni@1112
   108
    public native void fillRect(double x, double y, double width, double height);
toni@1109
   109
toni@1112
   110
    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().strokeRect(x,y,width,height);")
toni@1112
   111
    @Override
toni@1112
   112
    public native void strokeRect(double x, double y, double width, double height);
toni@1109
   113
toni@1112
   114
    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().clearRect(x,y,width,height);")
toni@1112
   115
    @Override
toni@1112
   116
    public native void clearRect(double x, double y, double width, double height);
toni@1109
   117
toni@1112
   118
    @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().rectect(x,y,width,height);")
toni@1112
   119
    @Override
toni@1112
   120
    public native void rect(double x, double y, double width, double height);
toni@1109
   121
toni@1112
   122
    @JavaScriptBody(args = {}, body = "this._context().save();")
toni@1112
   123
    @Override
toni@1112
   124
    public native void save();
toni@1109
   125
toni@1112
   126
    @JavaScriptBody(args = {}, body = "this._context().restore();")
toni@1112
   127
    @Override
toni@1112
   128
    public native void restore();
toni@1109
   129
toni@1112
   130
    @JavaScriptBody(args = {"angle"}, body = "this._context().rotate(angle);")
toni@1112
   131
    @Override
toni@1112
   132
    public native void rotate(double angle);
toni@1109
   133
toni@1112
   134
    @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().transform(a,b,c,d,e,f);")
toni@1112
   135
    @Override
toni@1112
   136
    public native void transform(double a, double b, double c, double d, double e, double f);
toni@1109
   137
toni@1112
   138
    @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().setTransform(a,b,c,d,e,f);")
toni@1112
   139
    @Override
toni@1112
   140
    public native void setTransform(double a, double b, double c, double d, double e, double f);
toni@1109
   141
toni@1112
   142
    @JavaScriptBody(args = {"x", "y"}, body = "this._context().translate(x,y);")
toni@1112
   143
    @Override
toni@1112
   144
    public native void translate(double x, double y);
toni@1109
   145
toni@1112
   146
    @JavaScriptBody(args = {"x", "y"}, body = "this._context().scale(x,y);")
toni@1112
   147
    @Override
toni@1112
   148
    public native void scale(double x, double y);
toni@1109
   149
toni@1138
   150
////    @Override
toni@1138
   151
////    public void drawImage(Image image, double x, double y) {
toni@1138
   152
////        drawImageImpl(context, Element.getElementById((Image) image), x, y);
toni@1138
   153
////    }
toni@1138
   154
////
toni@1138
   155
////    @Override
toni@1138
   156
////    public void drawImage(Image image, double x, double y, double width, double height) {
toni@1138
   157
////        drawImageImpl(context, Element.getElementById((Image) image), x, y, width, height);
toni@1138
   158
////    }
toni@1138
   159
////
toni@1138
   160
////    @Override
toni@1138
   161
////    public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
toni@1138
   162
////        drawImageImpl(context, Element.getElementById((Image) image), sx, sy, sWidth, sHeight, x, y, width, height);
toni@1138
   163
////    }
toni@1138
   164
//
toni@1138
   165
////    @JavaScriptBody(args = {"ctx", "img", "x", "y", "width", "height"}, body = "ctx.drawImage(img,x,y,width,height);")
toni@1138
   166
////    private native static void drawImageImpl(Object ctx, Object img, double x, double y, double width, double height);
toni@1138
   167
////
toni@1138
   168
////    @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
   169
////    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
   170
////
toni@1138
   171
////    @JavaScriptBody(args = {"ctx", "img", "x", "y"}, body = "ctx.drawImage(img,x,y);")
toni@1138
   172
////    private native static void drawImageImpl(Object ctx, Object img, double x, double y);
toni@1142
   173
    public Object setFillStyle(Style style, Object nativeStyle) {
toni@1142
   174
        if (nativeStyle == null) {
toni@1142
   175
            nativeStyle = createNativeStyle(style);
toni@1142
   176
        }
toni@1142
   177
        setFillStyleImpl(context, nativeStyle);
toni@1142
   178
        return nativeStyle;
toni@1112
   179
    }
toni@1109
   180
toni@1142
   181
    private Object createNativeStyle(Style style) {
toni@1134
   182
        if (style instanceof RadialGradient) {
toni@1134
   183
            RadialGradientWrapper gradient = createRadialGradientWrapper(
toni@1134
   184
                    ((RadialGradient) style).getX0(),
toni@1134
   185
                    ((RadialGradient) style).getY0(),
toni@1134
   186
                    ((RadialGradient) style).getR0(),
toni@1134
   187
                    ((RadialGradient) style).getX1(),
toni@1134
   188
                    ((RadialGradient) style).getY1(),
toni@1134
   189
                    ((RadialGradient) style).getR1());
toni@1134
   190
            HashMap<Double, String> stops = ((LinearGradient) style).getStops();
toni@1134
   191
            Set<Double> keySet = stops.keySet();
toni@1134
   192
            for (Double double1 : keySet) {
toni@1134
   193
                addColorStopImpl(style, double1, stops.get(double1));
toni@1134
   194
            }
toni@1134
   195
            return gradient;
toni@1134
   196
toni@1134
   197
toni@1134
   198
        } else if (style instanceof LinearGradient) {
toni@1134
   199
            LinearGradientWrapper gradient = createLinearGradientWrapper(
toni@1134
   200
                    ((LinearGradient) style).getX0(),
toni@1134
   201
                    ((LinearGradient) style).getY0(),
toni@1134
   202
                    ((LinearGradient) style).getX1(),
toni@1134
   203
                    ((LinearGradient) style).getY1());
toni@1134
   204
            HashMap<Double, String> stops = ((LinearGradient) style).getStops();
toni@1134
   205
            Set<Double> keySet = stops.keySet();
toni@1134
   206
            for (Double double1 : keySet) {
toni@1134
   207
                addColorStopImpl(style, double1, stops.get(double1));
toni@1134
   208
            }
toni@1134
   209
            return gradient;
toni@1142
   210
        } else if (style instanceof Pattern) {
toni@1138
   211
//            return createPatternWrapper(((Pattern) style).getImage(), ((Pattern) style).getRepeat());
toni@1134
   212
        }
toni@1134
   213
        return null;
toni@1112
   214
    }
toni@1109
   215
toni@1134
   216
    @JavaScriptBody(args = {"gradient", "position", "color"}, body =
toni@1134
   217
            "gradient.addColorStop(position,color)")
toni@1134
   218
    private static native void addColorStopImpl(Object gradient, double position, String color);
toni@1109
   219
toni@1112
   220
    @JavaScriptBody(args = {"context", "obj"}, body = "context.fillStyle=obj;")
toni@1112
   221
    private native void setFillStyleImpl(Object context, Object obj);
toni@1109
   222
toni@1112
   223
    @JavaScriptBody(args = {"style"}, body = "this._context().strokeStyle=style.valueOf();")
toni@1112
   224
    public native void setStrokeStyle(String style);
toni@1109
   225
toni@1112
   226
    @Override
toni@1142
   227
    public Object setStrokeStyle(Style style, Object nativeStyle) {
toni@1142
   228
        if (nativeStyle == null){
toni@1142
   229
            nativeStyle = createNativeStyle(style);
toni@1142
   230
        }
toni@1142
   231
        setStrokeStyleImpl(context, nativeStyle);
toni@1142
   232
        return nativeStyle;
toni@1112
   233
    }
toni@1109
   234
toni@1112
   235
    @JavaScriptBody(args = {"context", "obj"}, body = "context.strokeStyle=obj;")
toni@1112
   236
    private native void setStrokeStyleImpl(Object context, Object obj);
toni@1109
   237
toni@1112
   238
    @JavaScriptBody(args = {"color"}, body = "this._context().shadowColor=color.valueOf();")
toni@1112
   239
    @Override
toni@1112
   240
    public native void setShadowColor(String color);
toni@1109
   241
toni@1112
   242
    @JavaScriptBody(args = {"blur"}, body = "this._context().shadowBlur=blur;")
toni@1112
   243
    @Override
toni@1112
   244
    public native void setShadowBlur(double blur);
toni@1109
   245
toni@1112
   246
    @JavaScriptBody(args = {"x"}, body = "this._context().shadowOffsetX=x;")
toni@1112
   247
    @Override
toni@1112
   248
    public native void setShadowOffsetX(double x);
toni@1109
   249
toni@1112
   250
    @JavaScriptBody(args = {"y"}, body = "this._context().shadowOffsetY=y;")
toni@1112
   251
    @Override
toni@1112
   252
    public native void setShadowOffsetY(double y);
toni@1109
   253
toni@1112
   254
    @JavaScriptBody(args = {}, body = "return this._context().strokeStyle;")
toni@1112
   255
    public native String getStrokeStyle();
toni@1109
   256
toni@1112
   257
    @JavaScriptBody(args = {}, body = "return this._context().shadowColor;")
toni@1112
   258
    @Override
toni@1112
   259
    public native String getShadowColor();
toni@1109
   260
toni@1112
   261
    @JavaScriptBody(args = {}, body = "return this._context().shadowBlur;")
toni@1112
   262
    @Override
toni@1112
   263
    public native double getShadowBlur();
toni@1109
   264
toni@1112
   265
    @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetX;")
toni@1112
   266
    @Override
toni@1112
   267
    public native double getShadowOffsetX();
toni@1109
   268
toni@1112
   269
    @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetY;")
toni@1112
   270
    @Override
toni@1112
   271
    public native double getShadowOffsetY();
toni@1109
   272
toni@1112
   273
    @JavaScriptBody(args = {}, body = "return this._context().lineCap;")
toni@1112
   274
    @Override
toni@1112
   275
    public native String getLineCap();
toni@1109
   276
toni@1112
   277
    @JavaScriptBody(args = {"style"}, body = "this._context().lineCap=style.valueOf();")
toni@1112
   278
    @Override
toni@1112
   279
    public native void setLineCap(String style);
toni@521
   280
toni@1112
   281
    @JavaScriptBody(args = {}, body = "return this._context().lineJoin;")
toni@1112
   282
    @Override
toni@1112
   283
    public native String getLineJoin();
toni@521
   284
toni@1112
   285
    @JavaScriptBody(args = {"style"}, body = "this._context().lineJoin=style.valueOf();")
toni@1112
   286
    @Override
toni@1112
   287
    public native void setLineJoin(String style);
toni@521
   288
toni@1112
   289
    @JavaScriptBody(args = {}, body = "return this._context().lineWidth;")
toni@1112
   290
    @Override
toni@1112
   291
    public native double getLineWidth();
toni@521
   292
toni@1112
   293
    @JavaScriptBody(args = {"width"}, body = "this._context().lineWidth=width;")
toni@1112
   294
    @Override
toni@1112
   295
    public native void setLineWidth(double width);
toni@521
   296
toni@1112
   297
    @JavaScriptBody(args = {}, body = "return this._context().miterLimit;")
toni@1112
   298
    @Override
toni@1112
   299
    public native double getMiterLimit();
toni@521
   300
toni@1112
   301
    @JavaScriptBody(args = {"limit"}, body = "this._context().miterLimit=limit;")
toni@1112
   302
    @Override
toni@1112
   303
    public native void setMiterLimit(double limit);
toni@1111
   304
toni@1112
   305
    @JavaScriptBody(args = {}, body = "return this._context().font;")
toni@1112
   306
    @Override
toni@1112
   307
    public native String getFont();
toni@1111
   308
toni@1112
   309
    @JavaScriptBody(args = {"font"}, body = "this._context().font=font.valueOf();")
toni@1112
   310
    @Override
toni@1112
   311
    public native void setFont(String font);
toni@1111
   312
toni@1112
   313
    @JavaScriptBody(args = {}, body = "return this._context().textAlign;")
toni@1112
   314
    @Override
toni@1112
   315
    public native String getTextAlign();
toni@1111
   316
toni@1112
   317
    @JavaScriptBody(args = {"textalign"}, body = "this._context().textAlign=textalign.valueOf();")
toni@1112
   318
    @Override
toni@1112
   319
    public native void setTextAlign(String textAlign);
toni@1111
   320
toni@1112
   321
    @JavaScriptBody(args = {}, body = "return this._context().textBaseline;")
toni@1112
   322
    @Override
toni@1112
   323
    public native String getTextBaseline();
toni@1111
   324
toni@1112
   325
    @JavaScriptBody(args = {"textbaseline"}, body = "this._context().textBaseline=textbaseline.valueOf();")
toni@1112
   326
    @Override
toni@1112
   327
    public native void setTextBaseline(String textbaseline);
toni@1111
   328
toni@1112
   329
    @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().fillText(text,x,y);")
toni@1138
   330
//    @JavaScriptBody(args = {"text", "x", "y"}, body = "console.log(text);")
toni@1112
   331
    @Override
toni@1112
   332
    public native void fillText(String text, double x, double y);
toni@1111
   333
toni@1112
   334
    @JavaScriptBody(args = {"text", "x", "y", "maxwidth"}, body = "this._context().fillText(text,x,y,maxwidth);")
toni@1112
   335
    @Override
toni@1112
   336
    public void fillText(String text, double x, double y, double maxWidth) {
toni@1112
   337
    }
toni@1111
   338
toni@1112
   339
    @Override
toni@1134
   340
    public Dimension measureText(String text) {
toni@1138
   341
        measureTextImpl(text);
toni@1142
   342
        return new Dimension(1, 1);
toni@1112
   343
    }
toni@1111
   344
toni@1112
   345
    @JavaScriptBody(args = {"text"},
toni@1112
   346
            body = "return this._context().measureText(text);")
toni@1112
   347
    private native Object measureTextImpl(String text);
toni@1111
   348
toni@1112
   349
    @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().strokeText(text,x,y);")
toni@1112
   350
    @Override
toni@1112
   351
    public native void strokeText(String text, double x, double y);
toni@1111
   352
toni@1112
   353
    @JavaScriptBody(args = {"text", "x", "y", "maxWidth"}, body = "this._context().strokeText(text,x,y,maxWidth);")
toni@1112
   354
    @Override
toni@1112
   355
    public native void strokeText(String text, double x, double y, double maxWidth);
toni@1111
   356
toni@1138
   357
////    @Override
toni@1138
   358
////    public ImageData createImageData(double x, double y) {
toni@1138
   359
////        return new ImageDataWrapper(createImageDataImpl(x, y));
toni@1138
   360
////    }
toni@1138
   361
////
toni@1138
   362
////    @JavaScriptBody(args = {"x", "y"},
toni@1138
   363
////            body = "return this._context().createImageData(x,y);")
toni@1138
   364
////    private native Object createImageDataImpl(double x, double y);
toni@1138
   365
////
toni@1138
   366
////    @Override
toni@1138
   367
////    public ImageData createImageData(ImageData imageData) {
toni@1138
   368
////        return new ImageDataWrapper(createImageDataImpl(imageData.getWidth(), imageData.getHeight()));
toni@1138
   369
////    }
toni@1138
   370
////
toni@1138
   371
////    @Override
toni@1138
   372
////    public ImageData getImageData(double x, double y, double width, double height) {
toni@1138
   373
////        return new ImageDataWrapper(getImageDataImpl(x, y, width, height));
toni@1138
   374
////    }
toni@1134
   375
//
toni@1138
   376
//    @JavaScriptBody(args = {"x", "y", "width", "height"},
toni@1138
   377
//            body = "return this._context().getImageData(x,y,width,height);")
toni@1138
   378
//    private native Object getImageDataImpl(double x, double y, double width, double height);
toni@1134
   379
//
toni@1138
   380
////    @Override
toni@1138
   381
////    public void putImageData(ImageData imageData, double x, double y) {
toni@1138
   382
////        putImageDataImpl(((ImageDataWrapper) imageData).object(), x, y);
toni@1138
   383
////    }
toni@1138
   384
////
toni@1138
   385
////    @JavaScriptBody(args = {"imageData", "x", "y"},
toni@1138
   386
////            body = "this._context().putImageData(imageData,x,y);")
toni@1138
   387
////    private native void putImageDataImpl(Object imageData, double x, double y);
toni@1138
   388
////
toni@1138
   389
////    @Override
toni@1138
   390
////    public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
toni@1138
   391
////        putImageDataImpl(((ImageDataWrapper) imageData).object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
toni@1138
   392
////    }
toni@1112
   393
    @JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"},
toni@1112
   394
            body = "this._context().putImageData(imageData,x,y, dirtyx, dirtyy, dirtywidth,dirtyheight);")
toni@1112
   395
    private native void putImageDataImpl(Object imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
toni@1112
   396
toni@1112
   397
    @JavaScriptBody(args = {"alpha"}, body = "this._context().globalAlpha=alpha;")
toni@1112
   398
    @Override
toni@1112
   399
    public native void setGlobalAlpha(double alpha);
toni@1112
   400
toni@1112
   401
    @JavaScriptBody(args = {}, body = "return this._context().globalAlpha;")
toni@1112
   402
    @Override
toni@1112
   403
    public native double getGlobalAlpha();
toni@1112
   404
toni@1112
   405
    @JavaScriptBody(args = {"operation"}, body = "this._context().globalCompositeOperation=operation.valueOf();")
toni@1112
   406
    @Override
toni@1112
   407
    public native void setGlobalCompositeOperation(String operation);
toni@1112
   408
toni@1112
   409
    @JavaScriptBody(args = {}, body = "return this._context().globalCompositeOperation;")
toni@1112
   410
    @Override
toni@1112
   411
    public native String getGlobalCompositeOperation();
toni@1112
   412
toni@1134
   413
    public LinearGradientWrapper createLinearGradientWrapper(double x0, double y0, double x1, double y1) {
toni@1134
   414
        return new LinearGradientWrapper(createLinearGradientImpl(context, x0, y0, x1, y1));
toni@1112
   415
    }
toni@1112
   416
toni@1112
   417
    @JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);")
toni@1112
   418
    private native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
toni@1112
   419
toni@1138
   420
//    public PatternWrapper createPatternWrapper(Image image, String repeat) {
toni@1138
   421
//        return new PatternWrapper(createPatternImpl(context, image, repeat));
toni@1138
   422
//    }
toni@1138
   423
//
toni@1138
   424
//    @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
toni@1138
   425
//    private static native Object createPatternImpl(Object context, Image image, String repeat);
toni@1134
   426
    public RadialGradientWrapper createRadialGradientWrapper(double x0, double y0, double r0, double x1, double y1, double r1) {
toni@1134
   427
        return new RadialGradientWrapper(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
toni@1112
   428
    }
toni@1112
   429
toni@1112
   430
    @JavaScriptBody(args = {"context", "x0", "y0", "r0", "x1", "y1", "r1"}, body = "return context.createRadialGradient(x0,y0,r0,x1,y1,r1);")
toni@1112
   431
    private static native Object createRadialGradientImpl(Object context, double x0, double y0, double r0, double x1, double y1, double r1);
toni@1121
   432
toni@1138
   433
////  
toni@1138
   434
////    @JavaScriptBody(args = {"path"}, body = "var b = new Image(); b.src=path; return b;")
toni@1138
   435
////    public native Image getImageForPath(String path);
toni@1121
   436
    @Override
toni@1134
   437
    public int getHeight() {
toni@1142
   438
        return canvas.getHeight();
toni@1121
   439
    }
toni@1134
   440
toni@1134
   441
    @Override
toni@1134
   442
    public int getWidth() {
toni@1142
   443
        return canvas.getWidth();
toni@1134
   444
    }
toni@1134
   445
toni@1134
   446
    @Override
toni@1134
   447
    public void setHeight(int height) {
toni@1142
   448
        canvas.setHeight(height);
toni@1134
   449
    }
toni@1134
   450
toni@1134
   451
    @Override
toni@1134
   452
    public void setWidth(int width) {
toni@1142
   453
        canvas.setWidth(width);
toni@1134
   454
    }
toni@521
   455
}