javaquery/canvas/src/main/java/net/java/html/canvas/GraphicsContext.java
author Anton Epple <toni.epple@eppleton.de>
Thu, 26 Sep 2013 14:26:58 -0700
branchcanvas
changeset 1303 3d62ad46d744
parent 1302 e67363288df1
child 1442 0660e56b5b33
permissions -rw-r--r--
license fixes
toni@1111
     1
/**
toni@1303
     2
 * Back 2 Browser Bytecode Translator
toni@1303
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
toni@1111
     4
 *
toni@1303
     5
 * This program is free software: you can redistribute it and/or modify
toni@1303
     6
 * it under the terms of the GNU General Public License as published by
toni@1303
     7
 * the Free Software Foundation, version 2 of the License.
toni@1111
     8
 *
toni@1303
     9
 * This program is distributed in the hope that it will be useful,
toni@1303
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
toni@1303
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
toni@1303
    12
 * GNU General Public License for more details.
toni@1111
    13
 *
toni@1303
    14
 * You should have received a copy of the GNU General Public License
toni@1303
    15
 * along with this program. Look for COPYING file in the top folder.
toni@1303
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
toni@521
    17
 */
toni@1109
    18
package net.java.html.canvas;
toni@521
    19
toni@1150
    20
import net.java.html.canvas.Style.Color;
toni@1150
    21
import net.java.html.canvas.Style.LinearGradient;
toni@1150
    22
import net.java.html.canvas.Style.Pattern;
toni@1150
    23
import net.java.html.canvas.Style.RadialGradient;
toni@1136
    24
import net.java.html.canvas.spi.GraphicsEnvironment;
toni@1302
    25
import org.apidesign.html.canvas.impl.CnvsAccssr;
toni@521
    26
toni@521
    27
/**
toni@1302
    28
 * A 2D Graphics Context similar to HTML5 or JavaFX GraphicsContext. Use this to
toni@1302
    29
 * paint on your Canvas.s
toni@1302
    30
 *
toni@1109
    31
 * @author antonepple
toni@521
    32
 */
toni@1128
    33
public final class GraphicsContext {
toni@1128
    34
toni@1128
    35
    GraphicsEnvironment graphicsEnvironmentImpl;
toni@1128
    36
toni@1302
    37
    static {
toni@1302
    38
        CnvsAccssr cnvsAccssr = new CnvsAccssr() {
toni@1302
    39
            @Override
toni@1302
    40
            public GraphicsContext create(GraphicsEnvironment environment) {
toni@1302
    41
                return new GraphicsContext(environment);
toni@1302
    42
            }
toni@1302
    43
        };
toni@1302
    44
    }
toni@1302
    45
toni@1302
    46
    GraphicsContext(GraphicsEnvironment graphicsEnvironment) {
toni@1128
    47
        this.graphicsEnvironmentImpl = graphicsEnvironment;
toni@1128
    48
    }
toni@521
    49
toni@1302
    50
    /**
toni@1302
    51
     * Adds path elements to the current path to make an arc.
toni@1302
    52
     *
toni@1302
    53
     * @param centerX the center x position of the arc.
toni@1302
    54
     * @param centerY the center y position of the arc.
toni@1302
    55
     * @param radius the radius of the arc.
toni@1302
    56
     * @param endAngle teh endAngle of the arc
toni@1302
    57
     * @param ccw the direction of the arc (counterclockwise)
toni@1302
    58
     */
toni@1111
    59
    public void arc(double centerX,
toni@1111
    60
            double centerY,
toni@1111
    61
            double startAngle,
toni@1111
    62
            double radius,
toni@1111
    63
            double endAngle,
toni@1128
    64
            boolean ccw) {
toni@1128
    65
        graphicsEnvironmentImpl.arc(centerX, centerY, startAngle, radius, endAngle, ccw);
toni@1128
    66
    }
toni@521
    67
toni@1302
    68
    /**
toni@1302
    69
     * Adds segments to the current path to make an arc.
toni@1302
    70
     *
toni@1302
    71
     * @param x1 the X coordinate of the first point of the arc.
toni@1302
    72
     * @param y1 the Y coordinate of the first point of the arc.
toni@1302
    73
     * @param x2 the X coordinate of the second point of the arc.
toni@1302
    74
     * @param y2 the Y coordinate of the second point of the arc.
toni@1302
    75
     * @param radius the radius of the arc in the range {0.0-positive infinity}.
toni@1302
    76
     */
toni@1111
    77
    public void arcTo(double x1,
toni@1111
    78
            double y1,
toni@1111
    79
            double x2,
toni@1111
    80
            double y2,
toni@1302
    81
            double radius) {
toni@1302
    82
        graphicsEnvironmentImpl.arcTo(x1, y1, x2, y2, radius);
toni@1128
    83
    }
toni@521
    84
toni@1302
    85
    /**
toni@1302
    86
     * Returns true if the the given x,y point is inside the path.
toni@1302
    87
     *
toni@1302
    88
     * @param x the X coordinate to use for the check.
toni@1302
    89
     * @param y the Y coordinate to use for the check.
toni@1302
    90
     * @return true if the point given is inside the path, false otherwise.
toni@1302
    91
     */
toni@1128
    92
    public boolean isPointInPath(double x, double y) {
toni@1128
    93
        return graphicsEnvironmentImpl.isPointInPath(x, y);
toni@1128
    94
    }
toni@521
    95
toni@1302
    96
    /**
toni@1302
    97
     * Fills the path with the current fill paint.
toni@1302
    98
     */
toni@1128
    99
    public void fill() {
toni@1128
   100
        graphicsEnvironmentImpl.fill();
toni@1128
   101
    }
toni@521
   102
toni@1302
   103
    /**
toni@1302
   104
     * Strokes the path with the current stroke paint.
toni@1302
   105
     */
toni@1128
   106
    public void stroke() {
toni@1128
   107
        graphicsEnvironmentImpl.stroke();
toni@1128
   108
    }
toni@1109
   109
toni@1302
   110
    /**
toni@1302
   111
     * Starts a Path
toni@1302
   112
     */
toni@1128
   113
    public void beginPath() {
toni@1128
   114
        graphicsEnvironmentImpl.beginPath();
toni@1128
   115
    }
toni@1109
   116
toni@1302
   117
    /**
toni@1302
   118
     * Closes the path.
toni@1302
   119
     */
toni@1302
   120
    public void closePath() {
toni@1128
   121
        graphicsEnvironmentImpl.closePath();
toni@1128
   122
    }
toni@521
   123
toni@1302
   124
    /**
toni@1302
   125
     * Clips using the current path
toni@1302
   126
     */
toni@1302
   127
    public void clip() {
toni@1128
   128
        graphicsEnvironmentImpl.clip();
toni@1128
   129
    }
toni@1109
   130
toni@1302
   131
    /**
toni@1302
   132
     * Issues a move command for the current path to the given x,y coordinate.
toni@1302
   133
     *
toni@1302
   134
     * @param x0 the X position for the move to command.
toni@1302
   135
     * @param y0 the Y position for the move to command.
toni@1302
   136
     */
toni@1302
   137
    public void moveTo(double x, double y) {
toni@1128
   138
        graphicsEnvironmentImpl.moveTo(x, y);
toni@1128
   139
    }
toni@1109
   140
toni@1302
   141
    /**
toni@1302
   142
     * Adds segments to the current path to make a line at the given x,y
toni@1302
   143
     * coordinate.
toni@1302
   144
     *
toni@1302
   145
     * @param x1 the X coordinate of the ending point of the line.
toni@1302
   146
     * @param y1 the Y coordinate of the ending point of the line.
toni@1302
   147
     */
toni@1302
   148
    public void lineTo(double x, double y) {
toni@1128
   149
        graphicsEnvironmentImpl.lineTo(x, y);
toni@1128
   150
    }
toni@1109
   151
toni@1302
   152
    /**
toni@1302
   153
     * Adds segments to the current path to make a quadratic curve.
toni@1302
   154
     *
toni@1302
   155
     * @param cpx the X coordinate of the control point
toni@1302
   156
     * @param cpy the Y coordinate of the control point
toni@1302
   157
     * @param x the X coordinate of the end point
toni@1302
   158
     * @param y the Y coordinate of the end point
toni@1302
   159
     */
toni@1302
   160
    public void quadraticCurveTo(double cpx, double cpy, double x, double y) {
toni@1302
   161
        graphicsEnvironmentImpl.quadraticCurveTo(cpx, cpy, x, y);
toni@1128
   162
    }
toni@1109
   163
toni@1302
   164
    /**
toni@1302
   165
     * Adds segments to the current path to make a cubic bezier curve.
toni@1302
   166
     *
toni@1302
   167
     * @param cp1x the X coordinate of first bezier control point.
toni@1302
   168
     * @param cp1y the Y coordinate of the first bezier control point.
toni@1302
   169
     * @param cp2x the X coordinate of the second bezier control point.
toni@1302
   170
     * @param cp2y the Y coordinate of the second bezier control point.
toni@1302
   171
     * @param x the X coordinate of the end point.
toni@1302
   172
     * @param y the Y coordinate of the end point.
toni@1302
   173
     */
toni@1302
   174
    public void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y) {
toni@1128
   175
        graphicsEnvironmentImpl.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
toni@1128
   176
    }
toni@1109
   177
toni@1302
   178
    /**
toni@1302
   179
     * Fills a rectangle using the current fill paint.
toni@1302
   180
     *
toni@1302
   181
     * @param x the X position of the upper left corner of the rectangle.
toni@1302
   182
     * @param y the Y position of the upper left corner of the rectangle.
toni@1302
   183
     * @param w the width of the rectangle.
toni@1302
   184
     * @param h the height of the rectangle.
toni@1302
   185
     */
toni@1302
   186
    public void fillRect(double x, double y, double width, double height) {
toni@1128
   187
        graphicsEnvironmentImpl.fillRect(x, y, width, height);
toni@1128
   188
    }
toni@1109
   189
toni@1302
   190
    /**
toni@1302
   191
     * Strokes a rectangle using the current stroke paint.
toni@1302
   192
     *
toni@1302
   193
     * @param x the X position of the upper left corner of the rectangle.
toni@1302
   194
     * @param y the Y position of the upper left corner of the rectangle.
toni@1302
   195
     * @param width the width of the rectangle.
toni@1302
   196
     * @param height the height of the rectangle.
toni@1302
   197
     */
toni@1302
   198
    public void strokeRect(double x, double y, double width, double height) {
toni@1302
   199
        graphicsEnvironmentImpl.strokeRect(x, y, width, height);
toni@1128
   200
    }
toni@1109
   201
toni@1302
   202
    /**
toni@1302
   203
     * Clears a portion of the canvas with a transparent color value.
toni@1302
   204
     *
toni@1302
   205
     * @param x X position of the upper left corner of the rectangle.
toni@1302
   206
     * @param y Y position of the upper left corner of the rectangle.
toni@1302
   207
     * @param width width of the rectangle.
toni@1302
   208
     * @param height height of the rectangle.
toni@1302
   209
     */
toni@1302
   210
    public void clearRect(double x, double y, double width, double height) {
toni@1128
   211
        graphicsEnvironmentImpl.clearRect(x, y, width, height);
toni@1128
   212
    }
toni@1109
   213
toni@1302
   214
    /**
toni@1302
   215
     * Clears a portion of the canvas with a transparent color value.
toni@1302
   216
     *
toni@1302
   217
     * @param x X position of the upper left corner of the rectangle.
toni@1302
   218
     * @param y Y position of the upper left corner of the rectangle.
toni@1302
   219
     * @param width width of the rectangle.
toni@1302
   220
     * @param height height of the rectangle.
toni@1302
   221
     */
toni@1302
   222
    public void rect(double x, double y, double width, double height) {
toni@1128
   223
        graphicsEnvironmentImpl.rect(x, y, width, height);
toni@1128
   224
    }
toni@1109
   225
toni@1302
   226
    /**
toni@1302
   227
     * Saves the following attributes onto a stack.
toni@1302
   228
     * <ul>
toni@1302
   229
     * <li>Global Alpha</li>
toni@1302
   230
     * <li>Global Blend Operation</li>
toni@1302
   231
     * <li>Transform</li>
toni@1302
   232
     * <li>Fill Paint</li>
toni@1302
   233
     * <li>Stroke Paint</li>
toni@1302
   234
     * <li>Line Width</li>
toni@1302
   235
     * <li>Line Cap</li>
toni@1302
   236
     * <li>Line Join</li>
toni@1302
   237
     * <li>Miter Limit</li>
toni@1302
   238
     * <li>Number of Clip Paths</li>
toni@1302
   239
     * <li>Font</li>
toni@1302
   240
     * <li>Text Align</li>
toni@1302
   241
     * <li>Text Baseline</li>
toni@1302
   242
     * <li>Effect</li>
toni@1302
   243
     * <li>Fill Rule</li>
toni@1302
   244
     * </ul>
toni@1302
   245
     * This method does NOT alter the current state in any way. Also, not that
toni@1302
   246
     * the current path is not saved.
toni@1302
   247
     */
toni@1302
   248
    public void save() {
toni@1128
   249
        graphicsEnvironmentImpl.save();
toni@1128
   250
    }
toni@1109
   251
toni@1302
   252
    /**
toni@1302
   253
     * Pops the state off of the stack, setting the following attributes to
toni@1302
   254
     * their value at the time when that state was pushed onto the stack. If the
toni@1302
   255
     * stack is empty then nothing is changed.
toni@1302
   256
     *
toni@1302
   257
     * <ul>
toni@1302
   258
     * <li>Global Alpha</li>
toni@1302
   259
     * <li>Global Blend Operation</li>
toni@1302
   260
     * <li>Transform</li>
toni@1302
   261
     * <li>Fill Paint</li>
toni@1302
   262
     * <li>Stroke Paint</li>
toni@1302
   263
     * <li>Line Width</li>
toni@1302
   264
     * <li>Line Cap</li>
toni@1302
   265
     * <li>Line Join</li>
toni@1302
   266
     * <li>Miter Limit</li>
toni@1302
   267
     * <li>Number of Clip Paths</li>
toni@1302
   268
     * <li>Font</li>
toni@1302
   269
     * <li>Text Align</li>
toni@1302
   270
     * <li>Text Baseline</li>
toni@1302
   271
     * <li>Effect</li>
toni@1302
   272
     * <li>Fill Rule</li>
toni@1302
   273
     * </ul>
toni@1302
   274
     */
toni@1302
   275
    public void restore() {
toni@1128
   276
        graphicsEnvironmentImpl.restore();
toni@1128
   277
    }
toni@1109
   278
toni@1302
   279
    /**
toni@1302
   280
     * Rotates the current transform in degrees.
toni@1302
   281
     *
toni@1302
   282
     * @param angle value in degrees to rotate the current transform.
toni@1302
   283
     */
toni@1302
   284
    public void rotate(double angle) {
toni@1128
   285
        graphicsEnvironmentImpl.rotate(angle);
toni@1128
   286
    }
toni@1109
   287
toni@1302
   288
    /**
toni@1302
   289
     * Concatenates the input with the current transform.
toni@1302
   290
     *
toni@1302
   291
     * @param mxx - the X coordinate scaling element of the 3x4 matrix
toni@1302
   292
     * @param myx - the Y coordinate shearing element of the 3x4 matrix
toni@1302
   293
     * @param mxy - the X coordinate shearing element of the 3x4 matrix
toni@1302
   294
     * @param myy - the Y coordinate scaling element of the 3x4 matrix
toni@1302
   295
     * @param mxt - the X coordinate translation element of the 3x4 matrix
toni@1302
   296
     * @param myt - the Y coordinate translation element of the 3x4 matrix
toni@1302
   297
     */
toni@1302
   298
    public void transform(double mxx, double myx, double mxy, double myy, double mxt, double myt) {
toni@1302
   299
        graphicsEnvironmentImpl.transform(mxx, myx, mxy, myy, mxt, myt);
toni@1128
   300
    }
toni@1109
   301
toni@1302
   302
    /**
toni@1302
   303
     * Concatenates the input with the current transform.
toni@1302
   304
     *
toni@1302
   305
     * @param mxx - the X coordinate scaling element of the 3x4 matrix
toni@1302
   306
     * @param myx - the Y coordinate shearing element of the 3x4 matrix
toni@1302
   307
     * @param mxy - the X coordinate shearing element of the 3x4 matrix
toni@1302
   308
     * @param myy - the Y coordinate scaling element of the 3x4 matrix
toni@1302
   309
     * @param mxt - the X coordinate translation element of the 3x4 matrix
toni@1302
   310
     * @param myt - the Y coordinate translation element of the 3x4 matrix
toni@1302
   311
     */
toni@1302
   312
    public void setTransform(double mxx, double myx, double mxy, double myy, double mxt, double myt) {
toni@1302
   313
        graphicsEnvironmentImpl.setTransform(mxx, myx, mxy, myy, mxt, myt);
toni@1128
   314
    }
toni@1109
   315
toni@1302
   316
    /**
toni@1302
   317
     * Translates the current transform by x, y.
toni@1302
   318
     *
toni@1302
   319
     * @param x value to translate along the x axis.
toni@1302
   320
     * @param y value to translate along the y axis.
toni@1302
   321
     */
toni@1302
   322
    public void translate(double x, double y) {
toni@1128
   323
        graphicsEnvironmentImpl.translate(x, y);
toni@1128
   324
    }
toni@1109
   325
toni@1302
   326
    /**
toni@1302
   327
     * Scales the current transform by x, y.
toni@1302
   328
     *
toni@1302
   329
     * @param x value to scale in the x axis.
toni@1302
   330
     * @param y value to scale in the y axis.
toni@1302
   331
     */
toni@1302
   332
    public void scale(double x, double y) {
toni@1128
   333
        graphicsEnvironmentImpl.scale(x, y);
toni@1128
   334
    }
toni@1109
   335
toni@1302
   336
    /**
toni@1302
   337
     * Draws an image at the given x, y position using the width and height of
toni@1302
   338
     * the given image.
toni@1302
   339
     *
toni@1302
   340
     * @param img the image to be drawn.
toni@1302
   341
     * @param x the X coordinate on the destination for the upper left of the
toni@1302
   342
     * image.
toni@1302
   343
     * @param y the Y coordinate on the destination for the upper left of the
toni@1302
   344
     * image.
toni@1302
   345
     */
toni@1302
   346
    public void drawImage(Image image, double x, double y) {
toni@1144
   347
        Object nativeImage = graphicsEnvironmentImpl.drawImage(image, x, y, image.getCached());
toni@1144
   348
        image.cache(nativeImage);
toni@1144
   349
    }
toni@1144
   350
toni@1302
   351
    /**
toni@1302
   352
     * Draws an image into the given destination rectangle of the canvas. The
toni@1302
   353
     * Image is scaled to fit into the destination rectagnle.
toni@1302
   354
     *
toni@1302
   355
     * @param img the image to be drawn.
toni@1302
   356
     * @param x the X coordinate on the destination for the upper left of the
toni@1302
   357
     * image.
toni@1302
   358
     * @param y the Y coordinate on the destination for the upper left of the
toni@1302
   359
     * image.
toni@1302
   360
     * @param width the width of the destination rectangle.
toni@1302
   361
     * @param height the height of the destination rectangle.
toni@1302
   362
     */
toni@1302
   363
    public void drawImage(Image image, double x, double y, double width, double height) {
toni@1144
   364
        Object nativeImage = graphicsEnvironmentImpl.drawImage(image, x, y, width, height, image.getCached());
toni@1144
   365
        image.cache(nativeImage);
toni@1144
   366
    }
toni@1144
   367
toni@1302
   368
    /**
toni@1302
   369
     * Draws the current source rectangle of the given image to the given
toni@1302
   370
     * destination rectangle of the Canvas.
toni@1302
   371
     *
toni@1302
   372
     * @param img the image to be drawn.
toni@1302
   373
     * @param sx the source rectangle's X coordinate position.
toni@1302
   374
     * @param sy the source rectangle's Y coordinate position.
toni@1302
   375
     * @param sw the source rectangle's width.
toni@1302
   376
     * @param sh the source rectangle's height.
toni@1302
   377
     * @param dx the destination rectangle's X coordinate position.
toni@1302
   378
     * @param dy the destination rectangle's Y coordinate position.
toni@1302
   379
     * @param dw the destination rectangle's width.
toni@1302
   380
     * @param dh the destination rectangle's height.
toni@1302
   381
     */
toni@1302
   382
    public void drawImage(Image image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh) {
toni@1302
   383
        Object nativeImage = graphicsEnvironmentImpl.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh, image.getCached());
toni@1144
   384
        image.cache(nativeImage);
toni@1144
   385
    }
toni@1302
   386
toni@1302
   387
    /**
toni@1302
   388
     * Merges two images drawing one on top of the other and returning the
toni@1302
   389
     * result.
toni@1302
   390
     *
toni@1302
   391
     * @param a the lower Image
toni@1302
   392
     * @param b the upper Image
toni@1302
   393
     * @return
toni@1302
   394
     */
toni@1302
   395
    public Image merge(Image a, Image b) {
toni@1302
   396
        if (a.getCached() == null) {
toni@1263
   397
            drawImage(a, 0, 0);
toni@1263
   398
        }
toni@1302
   399
        if (b.getCached() == null) {
toni@1263
   400
            drawImage(b, 0, 0);
toni@1263
   401
        }
toni@1302
   402
        Object nativeImage = graphicsEnvironmentImpl.mergeImages(a, b, a.getCached(), b.getCached());
toni@1263
   403
        Image merged = Image.create("should add real path here");
toni@1263
   404
        merged.cache(nativeImage);
toni@1263
   405
        return merged;
toni@1263
   406
    }
toni@1109
   407
toni@1302
   408
//    public void setShadowColor(String color) {
toni@1302
   409
//        graphicsEnvironmentImpl.setShadowColor(color);
toni@1302
   410
//    }
toni@1302
   411
//
toni@1302
   412
//    public void setShadowBlur(double blur) {
toni@1302
   413
//        graphicsEnvironmentImpl.setShadowBlur(blur);
toni@1302
   414
//    }
toni@1302
   415
//
toni@1302
   416
//    public void setShadowOffsetX(double x) {
toni@1302
   417
//        graphicsEnvironmentImpl.setShadowOffsetX(x);
toni@1302
   418
//    }
toni@1302
   419
//
toni@1302
   420
//    public void setShadowOffsetY(double y) {
toni@1302
   421
//        graphicsEnvironmentImpl.setShadowOffsetY(y);
toni@1302
   422
//    }
toni@1302
   423
//
toni@1302
   424
//    public String getShadowColor() {
toni@1302
   425
//        return graphicsEnvironmentImpl.getShadowColor();
toni@1302
   426
//    }
toni@1302
   427
//
toni@1302
   428
//    public double getShadowBlur() {
toni@1302
   429
//        return graphicsEnvironmentImpl.getShadowBlur();
toni@1302
   430
//    }
toni@1302
   431
//
toni@1302
   432
//    public double getShadowOffsetX() {
toni@1302
   433
//        return graphicsEnvironmentImpl.getShadowOffsetX();
toni@1302
   434
//    }
toni@1302
   435
//
toni@1302
   436
//    public double getShadowOffsetY() {
toni@1302
   437
//        return graphicsEnvironmentImpl.getShadowOffsetY();
toni@1302
   438
//    }
toni@1302
   439
    public String getLineCap() {
toni@1128
   440
        return graphicsEnvironmentImpl.getLineCap();
toni@1128
   441
    }
toni@1109
   442
toni@1302
   443
    public void setLineCap(String style) {
toni@1128
   444
        graphicsEnvironmentImpl.setLineCap(style);
toni@1128
   445
    }
toni@1109
   446
toni@1302
   447
    public String getLineJoin() {
toni@1128
   448
        return graphicsEnvironmentImpl.getLineJoin();
toni@1128
   449
    }
toni@1109
   450
toni@1302
   451
    public void setLineJoin(String style) {
toni@1128
   452
        graphicsEnvironmentImpl.setLineJoin(style);
toni@1128
   453
    }
toni@1109
   454
toni@1302
   455
    public double getLineWidth() {
toni@1128
   456
        return graphicsEnvironmentImpl.getLineWidth();
toni@1128
   457
    }
toni@1109
   458
toni@1302
   459
    public void setLineWidth(double width) {
toni@1128
   460
        graphicsEnvironmentImpl.setLineWidth(width);
toni@1128
   461
    }
toni@1109
   462
toni@1302
   463
    public double getMiterLimit() {
toni@1128
   464
        return graphicsEnvironmentImpl.getMiterLimit();
toni@1128
   465
    }
toni@1109
   466
toni@1302
   467
    public void setMiterLimit(double limit) {
toni@1128
   468
        graphicsEnvironmentImpl.setMiterLimit(limit);
toni@1128
   469
    }
toni@1302
   470
toni@1302
   471
    public void setFillStyle(Style style) {
toni@1141
   472
        Object nativeFillStyle = graphicsEnvironmentImpl.setFillStyle(style, style.getCached());
toni@1141
   473
        style.cache(nativeFillStyle);
toni@1141
   474
    }
toni@1109
   475
toni@1302
   476
    public String getFont() {
toni@1128
   477
        return graphicsEnvironmentImpl.getFont();
toni@1128
   478
    }
toni@1109
   479
toni@1302
   480
    public void setFont(String font) {
toni@1128
   481
        graphicsEnvironmentImpl.setFont(font);
toni@1128
   482
    }
toni@1302
   483
toni@1302
   484
    public void setStrokeStyle(Style style) {
toni@1141
   485
        Object nativeStrokeStyle = graphicsEnvironmentImpl.setStrokeStyle(style, style.getCached());
toni@1141
   486
        style.cache(nativeStrokeStyle);
toni@1141
   487
    }
toni@1109
   488
toni@1302
   489
    public String getTextAlign() {
toni@1128
   490
        return graphicsEnvironmentImpl.getTextAlign();
toni@1128
   491
    }
toni@521
   492
toni@1302
   493
    public void setTextAlign(String textAlign) {
toni@1128
   494
        graphicsEnvironmentImpl.setTextAlign(textAlign);
toni@1128
   495
    }
toni@521
   496
toni@1302
   497
    public String getTextBaseline() {
toni@1128
   498
        return graphicsEnvironmentImpl.getTextBaseline();
toni@1128
   499
    }
toni@521
   500
toni@1302
   501
    public void setTextBaseline(String textbaseline) {
toni@1128
   502
        graphicsEnvironmentImpl.setTextBaseline(textbaseline);
toni@1128
   503
    }
toni@521
   504
toni@1302
   505
    public void fillText(String text, double x, double y) {
toni@1128
   506
        graphicsEnvironmentImpl.fillText(text, x, y);
toni@1128
   507
    }
toni@521
   508
toni@1302
   509
    public void fillText(String text, double x, double y, double maxWidth) {
toni@1128
   510
        graphicsEnvironmentImpl.fillText(text, x, y, maxWidth);
toni@1128
   511
    }
toni@521
   512
toni@1302
   513
    public Dimension measureText(String text) {
toni@1128
   514
        return graphicsEnvironmentImpl.measureText(text);
toni@1128
   515
    }
toni@1111
   516
toni@1302
   517
    public void strokeText(String text, double x, double y) {
toni@1128
   518
        graphicsEnvironmentImpl.strokeText(text, x, y);
toni@1128
   519
    }
toni@1111
   520
toni@1302
   521
    public void strokeText(String text, double x, double y, double maxWidth) {
toni@1128
   522
        graphicsEnvironmentImpl.strokeText(text, x, y, maxWidth);
toni@1128
   523
    }
toni@1111
   524
toni@1302
   525
//    public ImageData createPixelMap(double x, double y) {
toni@1302
   526
//        return graphicsEnvironmentImpl.createPixelMap(x, y);
toni@1302
   527
//    }
toni@1302
   528
//
toni@1302
   529
//    public ImageData createPixelMap(ImageData pixelMap) {
toni@1302
   530
//        return graphicsEnvironmentImpl.createPixelMap(pixelMap);
toni@1302
   531
//    }
toni@1302
   532
//
toni@1302
   533
//    public ImageData getSnapshot(double x, double y, double width, double height) {
toni@1302
   534
//        return graphicsEnvironmentImpl.getPixelMap(x, y, width, height);
toni@1302
   535
//    }
toni@1302
   536
//
toni@1302
   537
//    public void drawPixelMap(ImageData pixelMap, double x, double y) {
toni@1302
   538
//        graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y);
toni@1302
   539
//    }
toni@1302
   540
//
toni@1302
   541
//    public void drawPixelMap(ImageData pixelMap, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
toni@1302
   542
//        graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
toni@1302
   543
//    }
toni@1302
   544
    /**
toni@1302
   545
     * Sets the global alpha of the current state.
toni@1302
   546
     *
toni@1302
   547
     * @param alpha value in the range {@code 0.0-1.0}. The value is clamped if
toni@1302
   548
     * it is out of range.
toni@1302
   549
     */
toni@1302
   550
    public void setGlobalAlpha(double alpha) {
toni@1128
   551
        graphicsEnvironmentImpl.setGlobalAlpha(alpha);
toni@1128
   552
    }
toni@1111
   553
toni@1302
   554
    /**
toni@1302
   555
     * Gets the current global alpha.
toni@1302
   556
     *
toni@1302
   557
     * @return the current global alpha.
toni@1302
   558
     */
toni@1302
   559
    public double getGlobalAlpha() {
toni@1128
   560
        return graphicsEnvironmentImpl.getGlobalAlpha();
toni@1128
   561
    }
toni@1111
   562
toni@1302
   563
    /**
toni@1302
   564
     * Sets the global blend mode.
toni@1302
   565
     *
toni@1302
   566
     * @param op the BlendMode that will be set.
toni@1302
   567
     */
toni@1302
   568
    public void setGlobalCompositeOperation(String operation) {
toni@1128
   569
        graphicsEnvironmentImpl.setGlobalCompositeOperation(operation);
toni@1128
   570
    }
toni@1111
   571
toni@1302
   572
    /**
toni@1302
   573
     * Gets the global blend mode.
toni@1302
   574
     *
toni@1302
   575
     * @return the global BlendMode of the current state.
toni@1302
   576
     */
toni@1302
   577
    public String getGlobalCompositeOperation() {
toni@1128
   578
        return graphicsEnvironmentImpl.getGlobalCompositeOperation();
toni@1128
   579
    }
toni@1111
   580
toni@1302
   581
    public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
toni@1150
   582
        return new Style.LinearGradient(x0, y0, x1, y1);
toni@1128
   583
    }
toni@1111
   584
toni@1302
   585
    public Pattern createPattern(Image image, String repeat) {
toni@1144
   586
        return new Pattern(image, repeat);
toni@1144
   587
    }
toni@1111
   588
toni@1302
   589
    public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
toni@1131
   590
        return new RadialGradient(x0, y0, r0, x1, y1, r1);
toni@1128
   591
    }
toni@1302
   592
toni@1302
   593
    public Color getWebColor(String webColor) {
toni@1150
   594
        return new Style.Color(webColor);
toni@1150
   595
    }
toni@1111
   596
toni@1302
   597
    /**
toni@1302
   598
     * Get the height of this GraphicsContext (which should be the same as the
toni@1302
   599
     * enclosing canvas height)
toni@1302
   600
     *
toni@1302
   601
     * @return the height of this GraphicsContext
toni@1302
   602
     */
toni@1302
   603
    public int getHeight() {
toni@1128
   604
        return graphicsEnvironmentImpl.getHeight();
toni@1128
   605
    }
toni@1111
   606
toni@1302
   607
    /**
toni@1302
   608
     * Get the width of this GraphicsContext (which should be the same as the
toni@1302
   609
     * enclosing canvas height)
toni@1302
   610
     *
toni@1302
   611
     * @return the width of this GraphicsContext
toni@1302
   612
     */
toni@1302
   613
    public int getWidth() {
toni@1128
   614
        return graphicsEnvironmentImpl.getWidth();
toni@1128
   615
    }
toni@1111
   616
toni@1302
   617
//    public void setHeight(int height) {
toni@1302
   618
//        graphicsEnvironmentImpl.setHeight(height);
toni@1302
   619
//    }
toni@1302
   620
//
toni@1302
   621
//    public void setWidth(int width) {
toni@1302
   622
//        graphicsEnvironmentImpl.setWidth(width);
toni@1302
   623
//    }
toni@1302
   624
    /**
toni@1302
   625
     * Fill a circle with a center position of centerX, centerY and the
toni@1302
   626
     * specified radius.
toni@1302
   627
     *
toni@1302
   628
     * @param centerX
toni@1302
   629
     * @param centerY
toni@1302
   630
     * @param radius
toni@1302
   631
     */
toni@1302
   632
    public void fillCircle(float centerX, float centerY, float radius) {
toni@1302
   633
        graphicsEnvironmentImpl.arc(centerX, centerY, radius, 0, Math.PI * 2, false);
toni@1128
   634
    }
toni@1128
   635
toni@1302
   636
    /**
toni@1302
   637
     * Fills a polygon with the given points using the currently set fill paint.
toni@1302
   638
     *
toni@1302
   639
     * @param x_coord array containing the x coordinates of the polygon's
toni@1302
   640
     * points.
toni@1302
   641
     * @param y_coord array containing the y coordinates of the polygon's
toni@1302
   642
     * points.
toni@1302
   643
     * @param vertexCount the number of points that make the polygon.
toni@1302
   644
     */
toni@1263
   645
    public void fillPolygon(double[] x_coord, double[] y_coord, int vertexCount) {
toni@1302
   646
        if (vertexCount >= 1 && x_coord != null && x_coord.length >= vertexCount && y_coord != null && y_coord.length >= vertexCount) {
toni@1302
   647
            graphicsEnvironmentImpl.beginPath();
toni@1302
   648
        }
toni@1263
   649
        graphicsEnvironmentImpl.moveTo(x_coord[0], y_coord[0]);
toni@1263
   650
        for (int i = 1; i < vertexCount; i++) {
toni@1263
   651
            graphicsEnvironmentImpl.lineTo(x_coord[i], y_coord[i]);
toni@1302
   652
toni@1263
   653
        }
toni@1263
   654
        graphicsEnvironmentImpl.closePath();
toni@1263
   655
        graphicsEnvironmentImpl.fill();
toni@1263
   656
        graphicsEnvironmentImpl.stroke();
toni@1263
   657
    }
toni@521
   658
}