toni@1111: /** toni@1443: * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach toni@1443: * toni@1111: * toni@1443: * This program is free software: you can redistribute it and/or modify it under toni@1443: * the terms of the GNU General Public License as published by the Free Software toni@1443: * Foundation, version 2 of the License. toni@1111: * toni@1443: * This program is distributed in the hope that it will be useful, but WITHOUT toni@1443: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS toni@1443: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more toni@1443: * details. toni@1111: * toni@1443: * You should have received a copy of the GNU General Public License along with toni@1443: * this program. Look for COPYING file in the top folder. If not, see toni@1443: * http://opensource.org/licenses/GPL-2.0. toni@521: */ toni@1109: package net.java.html.canvas; toni@521: toni@1449: import java.util.Map; toni@1150: import net.java.html.canvas.Style.Color; toni@1150: import net.java.html.canvas.Style.LinearGradient; toni@1150: import net.java.html.canvas.Style.Pattern; toni@1150: import net.java.html.canvas.Style.RadialGradient; toni@1136: import net.java.html.canvas.spi.GraphicsEnvironment; toni@1302: import org.apidesign.html.canvas.impl.CnvsAccssr; toni@521: toni@521: /** toni@1302: * A 2D Graphics Context similar to HTML5 or JavaFX GraphicsContext. Use this to toni@1443: * paint on your Canvas toni@1302: * toni@1109: * @author antonepple toni@521: */ toni@1128: public final class GraphicsContext { toni@1128: toni@1449: public static void init() { toni@1444: // do nothing we need this in order to have the class loaded and static toni@1444: // block executed for CnvsAccssr. toni@1442: } toni@1442: toni@1128: GraphicsEnvironment graphicsEnvironmentImpl; toni@1128: toni@1302: static { toni@1302: CnvsAccssr cnvsAccssr = new CnvsAccssr() { toni@1302: @Override toni@1302: public GraphicsContext create(GraphicsEnvironment environment) { toni@1302: return new GraphicsContext(environment); toni@1302: } toni@1302: }; toni@1302: } toni@1302: toni@1302: GraphicsContext(GraphicsEnvironment graphicsEnvironment) { toni@1128: this.graphicsEnvironmentImpl = graphicsEnvironment; toni@1128: } toni@521: toni@1302: /** toni@1302: * Adds path elements to the current path to make an arc. toni@1302: * toni@1302: * @param centerX the center x position of the arc. toni@1302: * @param centerY the center y position of the arc. toni@1447: * @param startAngle the startAngle of the arc toni@1302: * @param radius the radius of the arc. toni@1447: * @param endAngle the endAngle of the arc toni@1302: * @param ccw the direction of the arc (counterclockwise) toni@1302: */ toni@1111: public void arc(double centerX, toni@1111: double centerY, toni@1111: double startAngle, toni@1111: double radius, toni@1111: double endAngle, toni@1128: boolean ccw) { toni@1128: graphicsEnvironmentImpl.arc(centerX, centerY, startAngle, radius, endAngle, ccw); toni@1128: } toni@521: toni@1302: /** toni@1302: * Adds segments to the current path to make an arc. toni@1302: * toni@1302: * @param x1 the X coordinate of the first point of the arc. toni@1302: * @param y1 the Y coordinate of the first point of the arc. toni@1302: * @param x2 the X coordinate of the second point of the arc. toni@1302: * @param y2 the Y coordinate of the second point of the arc. toni@1302: * @param radius the radius of the arc in the range {0.0-positive infinity}. toni@1302: */ toni@1111: public void arcTo(double x1, toni@1111: double y1, toni@1111: double x2, toni@1111: double y2, toni@1302: double radius) { toni@1302: graphicsEnvironmentImpl.arcTo(x1, y1, x2, y2, radius); toni@1128: } toni@521: toni@1302: /** toni@1302: * Returns true if the the given x,y point is inside the path. toni@1302: * toni@1302: * @param x the X coordinate to use for the check. toni@1302: * @param y the Y coordinate to use for the check. toni@1302: * @return true if the point given is inside the path, false otherwise. toni@1302: */ toni@1128: public boolean isPointInPath(double x, double y) { toni@1128: return graphicsEnvironmentImpl.isPointInPath(x, y); toni@1128: } toni@521: toni@1302: /** toni@1302: * Fills the path with the current fill paint. toni@1302: */ toni@1128: public void fill() { toni@1128: graphicsEnvironmentImpl.fill(); toni@1128: } toni@521: toni@1302: /** toni@1302: * Strokes the path with the current stroke paint. toni@1302: */ toni@1128: public void stroke() { toni@1128: graphicsEnvironmentImpl.stroke(); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Starts a Path toni@1302: */ toni@1128: public void beginPath() { toni@1128: graphicsEnvironmentImpl.beginPath(); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Closes the path. toni@1302: */ toni@1302: public void closePath() { toni@1128: graphicsEnvironmentImpl.closePath(); toni@1128: } toni@521: toni@1302: /** toni@1302: * Clips using the current path toni@1302: */ toni@1302: public void clip() { toni@1128: graphicsEnvironmentImpl.clip(); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Issues a move command for the current path to the given x,y coordinate. toni@1302: * toni@1302: * @param x0 the X position for the move to command. toni@1302: * @param y0 the Y position for the move to command. toni@1302: */ toni@1302: public void moveTo(double x, double y) { toni@1128: graphicsEnvironmentImpl.moveTo(x, y); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Adds segments to the current path to make a line at the given x,y toni@1302: * coordinate. toni@1302: * toni@1302: * @param x1 the X coordinate of the ending point of the line. toni@1302: * @param y1 the Y coordinate of the ending point of the line. toni@1302: */ toni@1302: public void lineTo(double x, double y) { toni@1128: graphicsEnvironmentImpl.lineTo(x, y); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Adds segments to the current path to make a quadratic curve. toni@1302: * toni@1302: * @param cpx the X coordinate of the control point toni@1302: * @param cpy the Y coordinate of the control point toni@1302: * @param x the X coordinate of the end point toni@1302: * @param y the Y coordinate of the end point toni@1302: */ toni@1302: public void quadraticCurveTo(double cpx, double cpy, double x, double y) { toni@1302: graphicsEnvironmentImpl.quadraticCurveTo(cpx, cpy, x, y); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Adds segments to the current path to make a cubic bezier curve. toni@1302: * toni@1302: * @param cp1x the X coordinate of first bezier control point. toni@1302: * @param cp1y the Y coordinate of the first bezier control point. toni@1302: * @param cp2x the X coordinate of the second bezier control point. toni@1302: * @param cp2y the Y coordinate of the second bezier control point. toni@1302: * @param x the X coordinate of the end point. toni@1302: * @param y the Y coordinate of the end point. toni@1302: */ toni@1302: public void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y) { toni@1128: graphicsEnvironmentImpl.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Fills a rectangle using the current fill paint. toni@1302: * toni@1302: * @param x the X position of the upper left corner of the rectangle. toni@1302: * @param y the Y position of the upper left corner of the rectangle. toni@1447: * @param width the width of the rectangle. toni@1447: * @param height the height of the rectangle. toni@1302: */ toni@1302: public void fillRect(double x, double y, double width, double height) { toni@1128: graphicsEnvironmentImpl.fillRect(x, y, width, height); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Strokes a rectangle using the current stroke paint. toni@1302: * toni@1302: * @param x the X position of the upper left corner of the rectangle. toni@1302: * @param y the Y position of the upper left corner of the rectangle. toni@1302: * @param width the width of the rectangle. toni@1302: * @param height the height of the rectangle. toni@1302: */ toni@1302: public void strokeRect(double x, double y, double width, double height) { toni@1302: graphicsEnvironmentImpl.strokeRect(x, y, width, height); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Clears a portion of the canvas with a transparent color value. toni@1302: * toni@1302: * @param x X position of the upper left corner of the rectangle. toni@1302: * @param y Y position of the upper left corner of the rectangle. toni@1302: * @param width width of the rectangle. toni@1302: * @param height height of the rectangle. toni@1302: */ toni@1302: public void clearRect(double x, double y, double width, double height) { toni@1128: graphicsEnvironmentImpl.clearRect(x, y, width, height); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Clears a portion of the canvas with a transparent color value. toni@1302: * toni@1302: * @param x X position of the upper left corner of the rectangle. toni@1302: * @param y Y position of the upper left corner of the rectangle. toni@1302: * @param width width of the rectangle. toni@1302: * @param height height of the rectangle. toni@1302: */ toni@1302: public void rect(double x, double y, double width, double height) { toni@1128: graphicsEnvironmentImpl.rect(x, y, width, height); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Saves the following attributes onto a stack. toni@1302: * toni@1302: * This method does NOT alter the current state in any way. Also, not that toni@1302: * the current path is not saved. toni@1302: */ toni@1302: public void save() { toni@1128: graphicsEnvironmentImpl.save(); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Pops the state off of the stack, setting the following attributes to toni@1302: * their value at the time when that state was pushed onto the stack. If the toni@1302: * stack is empty then nothing is changed. toni@1302: * toni@1302: * toni@1302: */ toni@1302: public void restore() { toni@1128: graphicsEnvironmentImpl.restore(); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Rotates the current transform in degrees. toni@1302: * toni@1302: * @param angle value in degrees to rotate the current transform. toni@1302: */ toni@1302: public void rotate(double angle) { toni@1128: graphicsEnvironmentImpl.rotate(angle); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Concatenates the input with the current transform. toni@1302: * toni@1302: * @param mxx - the X coordinate scaling element of the 3x4 matrix toni@1302: * @param myx - the Y coordinate shearing element of the 3x4 matrix toni@1302: * @param mxy - the X coordinate shearing element of the 3x4 matrix toni@1302: * @param myy - the Y coordinate scaling element of the 3x4 matrix toni@1302: * @param mxt - the X coordinate translation element of the 3x4 matrix toni@1302: * @param myt - the Y coordinate translation element of the 3x4 matrix toni@1302: */ toni@1302: public void transform(double mxx, double myx, double mxy, double myy, double mxt, double myt) { toni@1302: graphicsEnvironmentImpl.transform(mxx, myx, mxy, myy, mxt, myt); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Concatenates the input with the current transform. toni@1302: * toni@1302: * @param mxx - the X coordinate scaling element of the 3x4 matrix toni@1302: * @param myx - the Y coordinate shearing element of the 3x4 matrix toni@1302: * @param mxy - the X coordinate shearing element of the 3x4 matrix toni@1302: * @param myy - the Y coordinate scaling element of the 3x4 matrix toni@1302: * @param mxt - the X coordinate translation element of the 3x4 matrix toni@1302: * @param myt - the Y coordinate translation element of the 3x4 matrix toni@1302: */ toni@1302: public void setTransform(double mxx, double myx, double mxy, double myy, double mxt, double myt) { toni@1302: graphicsEnvironmentImpl.setTransform(mxx, myx, mxy, myy, mxt, myt); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Translates the current transform by x, y. toni@1302: * toni@1302: * @param x value to translate along the x axis. toni@1302: * @param y value to translate along the y axis. toni@1302: */ toni@1302: public void translate(double x, double y) { toni@1128: graphicsEnvironmentImpl.translate(x, y); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Scales the current transform by x, y. toni@1302: * toni@1302: * @param x value to scale in the x axis. toni@1302: * @param y value to scale in the y axis. toni@1302: */ toni@1302: public void scale(double x, double y) { toni@1128: graphicsEnvironmentImpl.scale(x, y); toni@1128: } toni@1109: toni@1302: /** toni@1302: * Draws an image at the given x, y position using the width and height of toni@1302: * the given image. toni@1302: * toni@1447: * @param image the image to be drawn. toni@1302: * @param x the X coordinate on the destination for the upper left of the toni@1302: * image. toni@1302: * @param y the Y coordinate on the destination for the upper left of the toni@1302: * image. toni@1302: */ toni@1302: public void drawImage(Image image, double x, double y) { toni@1144: Object nativeImage = graphicsEnvironmentImpl.drawImage(image, x, y, image.getCached()); toni@1144: image.cache(nativeImage); toni@1144: } toni@1144: toni@1302: /** toni@1302: * Draws an image into the given destination rectangle of the canvas. The toni@1302: * Image is scaled to fit into the destination rectagnle. toni@1302: * toni@1447: * @param image the image to be drawn. toni@1302: * @param x the X coordinate on the destination for the upper left of the toni@1302: * image. toni@1302: * @param y the Y coordinate on the destination for the upper left of the toni@1302: * image. toni@1302: * @param width the width of the destination rectangle. toni@1302: * @param height the height of the destination rectangle. toni@1302: */ toni@1302: public void drawImage(Image image, double x, double y, double width, double height) { toni@1144: Object nativeImage = graphicsEnvironmentImpl.drawImage(image, x, y, width, height, image.getCached()); toni@1144: image.cache(nativeImage); toni@1144: } toni@1144: toni@1302: /** toni@1302: * Draws the current source rectangle of the given image to the given toni@1302: * destination rectangle of the Canvas. toni@1302: * toni@1447: * @param image the image to be drawn. toni@1302: * @param sx the source rectangle's X coordinate position. toni@1302: * @param sy the source rectangle's Y coordinate position. toni@1302: * @param sw the source rectangle's width. toni@1302: * @param sh the source rectangle's height. toni@1302: * @param dx the destination rectangle's X coordinate position. toni@1302: * @param dy the destination rectangle's Y coordinate position. toni@1302: * @param dw the destination rectangle's width. toni@1302: * @param dh the destination rectangle's height. toni@1302: */ toni@1302: public void drawImage(Image image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh) { toni@1302: Object nativeImage = graphicsEnvironmentImpl.drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh, image.getCached()); toni@1144: image.cache(nativeImage); toni@1144: } toni@1302: toni@1302: /** toni@1302: * Merges two images drawing one on top of the other and returning the toni@1302: * result. toni@1302: * toni@1302: * @param a the lower Image toni@1302: * @param b the upper Image toni@1302: * @return toni@1302: */ toni@1302: public Image merge(Image a, Image b) { toni@1302: if (a.getCached() == null) { toni@1263: drawImage(a, 0, 0); toni@1263: } toni@1302: if (b.getCached() == null) { toni@1263: drawImage(b, 0, 0); toni@1263: } toni@1302: Object nativeImage = graphicsEnvironmentImpl.mergeImages(a, b, a.getCached(), b.getCached()); toni@1263: Image merged = Image.create("should add real path here"); toni@1263: merged.cache(nativeImage); toni@1263: return merged; toni@1263: } toni@1109: toni@1302: // public void setShadowColor(String color) { toni@1302: // graphicsEnvironmentImpl.setShadowColor(color); toni@1302: // } toni@1302: // toni@1302: // public void setShadowBlur(double blur) { toni@1302: // graphicsEnvironmentImpl.setShadowBlur(blur); toni@1302: // } toni@1302: // toni@1302: // public void setShadowOffsetX(double x) { toni@1302: // graphicsEnvironmentImpl.setShadowOffsetX(x); toni@1302: // } toni@1302: // toni@1302: // public void setShadowOffsetY(double y) { toni@1302: // graphicsEnvironmentImpl.setShadowOffsetY(y); toni@1302: // } toni@1302: // toni@1302: // public String getShadowColor() { toni@1302: // return graphicsEnvironmentImpl.getShadowColor(); toni@1302: // } toni@1302: // toni@1302: // public double getShadowBlur() { toni@1302: // return graphicsEnvironmentImpl.getShadowBlur(); toni@1302: // } toni@1302: // toni@1302: // public double getShadowOffsetX() { toni@1302: // return graphicsEnvironmentImpl.getShadowOffsetX(); toni@1302: // } toni@1302: // toni@1302: // public double getShadowOffsetY() { toni@1302: // return graphicsEnvironmentImpl.getShadowOffsetY(); toni@1302: // } toni@1443: toni@1444: /** toni@1444: * Gets the current stroke line cap attribute. toni@1444: * toni@1444: * @return a value of butt, round, or square. toni@1444: */ toni@1302: public String getLineCap() { toni@1128: return graphicsEnvironmentImpl.getLineCap(); toni@1128: } toni@1444: toni@1444: /** toni@1444: * Sets the current stroke line cap attribute. toni@1444: * toni@1444: * @param style a value of miter, bevel, or round. toni@1444: */ toni@1302: public void setLineCap(String style) { toni@1128: graphicsEnvironmentImpl.setLineCap(style); toni@1128: } toni@1109: toni@1444: /** toni@1444: * Gets the current stroke line join attribute. toni@1444: * toni@1444: * @return a value of miter, bevel, or round. toni@1444: */ toni@1302: public String getLineJoin() { toni@1128: return graphicsEnvironmentImpl.getLineJoin(); toni@1128: } toni@1109: toni@1444: /** toni@1444: * Sets the current stroke line join attribute. toni@1444: * toni@1444: * @param style a value of miter, bevel, or toni@1444: * round. toni@1444: */ toni@1302: public void setLineJoin(String style) { toni@1128: graphicsEnvironmentImpl.setLineJoin(style); toni@1128: } toni@1109: toni@1444: /** toni@1444: * Gets the current line width attribute. toni@1444: * toni@1444: * @return value between 0 and infinity, with any other value being ignored toni@1444: * and leaving the value unchanged. toni@1444: * toni@1444: */ toni@1302: public double getLineWidth() { toni@1128: return graphicsEnvironmentImpl.getLineWidth(); toni@1128: } toni@1109: toni@1444: /** toni@1444: * Sets the current line width attribute. toni@1444: * toni@1444: * @param lw value between 0 and infinity, with any other value being toni@1444: * ignored and leaving the value unchanged. toni@1444: * toni@1444: */ toni@1302: public void setLineWidth(double width) { toni@1128: graphicsEnvironmentImpl.setLineWidth(width); toni@1128: } toni@1109: toni@1444: /** toni@1444: * Gets the current miter limit attribute. toni@1444: * toni@1444: * @return limit value between 0 and positive infinity with any other value toni@1444: * being ignored and leaving the value unchanged. toni@1444: */ toni@1302: public double getMiterLimit() { toni@1128: return graphicsEnvironmentImpl.getMiterLimit(); toni@1128: } toni@1109: toni@1444: /** toni@1444: * Sets the current miter limit attribute. toni@1444: * toni@1444: * @param ml miter limit value between 0 and positive infinity with any toni@1444: * other value being ignored and leaving the value unchanged. toni@1444: */ toni@1302: public void setMiterLimit(double limit) { toni@1128: graphicsEnvironmentImpl.setMiterLimit(limit); toni@1128: } toni@1302: toni@1443: /** toni@1444: * Sets the fill style. Will be used when rendering something, e.g. calling toni@1444: * one of the fillText Methods. toni@1444: * toni@1444: * @param style toni@1443: */ toni@1302: public void setFillStyle(Style style) { toni@1141: Object nativeFillStyle = graphicsEnvironmentImpl.setFillStyle(style, style.getCached()); toni@1141: style.cache(nativeFillStyle); toni@1141: } toni@1109: toni@1443: /** toni@1443: * get the current font toni@1443: * toni@1444: * @return current Font. of the fillText Methods. toni@1443: */ toni@1302: public String getFont() { toni@1128: return graphicsEnvironmentImpl.getFont(); toni@1128: } toni@1109: toni@1443: /** toni@1444: * Set the Font. Will be used when rendering Text, e.g. by calling one of toni@1444: * the fillText Methods. toni@1443: * toni@1443: * @param font toni@1443: */ toni@1302: public void setFont(String font) { toni@1128: graphicsEnvironmentImpl.setFont(font); toni@1128: } toni@1302: toni@1443: /** toni@1443: * sets the Style of the Stroke. toni@1443: * toni@1443: * @param style toni@1443: */ toni@1302: public void setStrokeStyle(Style style) { toni@1141: Object nativeStrokeStyle = graphicsEnvironmentImpl.setStrokeStyle(style, style.getCached()); toni@1141: style.cache(nativeStrokeStyle); toni@1141: } toni@1109: toni@1443: /** toni@1443: * Gets the current TextAlignment attribute toni@1443: * toni@1443: * @return TextAlignment with values of left, center, right, or justify. toni@1443: */ toni@1302: public String getTextAlign() { toni@1128: return graphicsEnvironmentImpl.getTextAlign(); toni@1128: } toni@521: toni@1443: /** toni@1443: * Defines horizontal text alignment, relative to the text {@code x} origin. toni@1443: *

toni@1443: * Let horizontal bounds represent the logical width of a single line of toni@1443: * text. Where each line of text has a separate horizontal bounds. toni@1443: *

toni@1443: * Then TextAlignment is specified as: toni@1443: *

toni@1443: *

toni@1443: * toni@1443: * Note: Canvas does not support line wrapping, therefore the text alignment toni@1443: * Justify is identical to left aligned text. toni@1443: *

toni@1443: * toni@1443: * @param textAlign with values of left, center, right. toni@1443: */ toni@1302: public void setTextAlign(String textAlign) { toni@1128: graphicsEnvironmentImpl.setTextAlign(textAlign); toni@1128: } toni@521: toni@1443: /** toni@1443: * Gets the current Text Baseline attribute. toni@1443: * toni@1443: * @return baseline with values of top, center, baseline, or bottom toni@1443: */ toni@1302: public String getTextBaseline() { toni@1128: return graphicsEnvironmentImpl.getTextBaseline(); toni@1128: } toni@521: toni@1443: /** toni@1443: * Sets the current Text Baseline attribute. toni@1443: * toni@1443: * @param baseline with values of top, center, baseline, or bottom toni@1443: */ toni@1302: public void setTextBaseline(String textbaseline) { toni@1128: graphicsEnvironmentImpl.setTextBaseline(textbaseline); toni@1128: } toni@521: toni@1443: /** toni@1443: * Renders the indicated String with current fill. default is black. toni@1443: * toni@1443: * @param text the text to stroke toni@1443: * @param x x coordinate of start position toni@1443: * @param y y coordinate of start position toni@1443: */ toni@1302: public void fillText(String text, double x, double y) { toni@1128: graphicsEnvironmentImpl.fillText(text, x, y); toni@1128: } toni@521: toni@1443: /** toni@1443: * Renders the indicated String with current fill. default is black. toni@1443: * toni@1443: * @param text the text to stroke toni@1443: * @param x x coordinate of start position toni@1443: * @param y y coordinate of start position toni@1443: * @param maxWidth maximum width of text toni@1443: */ toni@1302: public void fillText(String text, double x, double y, double maxWidth) { toni@1128: graphicsEnvironmentImpl.fillText(text, x, y, maxWidth); toni@1128: } toni@521: toni@1443: /** toni@1443: * Check the length of a text before writing it to the Canvas. Takes into toni@1443: * account the current Font. toni@1443: * toni@1443: * @param text the text to measure toni@1443: * @return the length in pixels toni@1443: */ toni@1302: public Dimension measureText(String text) { toni@1128: return graphicsEnvironmentImpl.measureText(text); toni@1128: } toni@1111: toni@1443: /** toni@1443: * Renders the indicated String (with no fill) toni@1443: * toni@1443: * @param text the text to stroke toni@1443: * @param x x coordinate of start position toni@1443: * @param y y coordinate of start position toni@1443: */ toni@1302: public void strokeText(String text, double x, double y) { toni@1128: graphicsEnvironmentImpl.strokeText(text, x, y); toni@1128: } toni@1111: toni@1443: /** toni@1443: * Renders the indicated String (with no fill) toni@1443: * toni@1443: * @param text the text to stroke toni@1443: * @param x x coordinate of start position toni@1443: * @param y y coordinate of start position toni@1443: * @param maxWidth maximum width of text toni@1443: */ toni@1302: public void strokeText(String text, double x, double y, double maxWidth) { toni@1128: graphicsEnvironmentImpl.strokeText(text, x, y, maxWidth); toni@1128: } toni@1111: toni@1450: public ImageData createPixelMap(double x, double y) { toni@1450: return graphicsEnvironmentImpl.createPixelMap(x, y); toni@1450: } toni@1450: toni@1450: public ImageData createPixelMap(ImageData pixelMap) { toni@1450: return graphicsEnvironmentImpl.createPixelMap(pixelMap); toni@1450: } toni@1450: toni@1450: public ImageData getSnapshot(double x, double y, double width, double height) { toni@1450: return graphicsEnvironmentImpl.getPixelMap(x, y, width, height); toni@1450: } toni@1450: toni@1450: public void drawPixelMap(ImageData pixelMap, double x, double y) { toni@1450: graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y); toni@1450: } toni@1450: toni@1450: public void drawPixelMap(ImageData pixelMap, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) { toni@1450: graphicsEnvironmentImpl.putPixelMap(pixelMap, x, y, dirtyx, dirtyy, dirtywidth, dirtyheight); toni@1450: } toni@1302: /** toni@1302: * Sets the global alpha of the current state. toni@1302: * toni@1302: * @param alpha value in the range {@code 0.0-1.0}. The value is clamped if toni@1302: * it is out of range. toni@1302: */ toni@1302: public void setGlobalAlpha(double alpha) { toni@1128: graphicsEnvironmentImpl.setGlobalAlpha(alpha); toni@1128: } toni@1111: toni@1302: /** toni@1302: * Gets the current global alpha. toni@1302: * toni@1302: * @return the current global alpha. toni@1302: */ toni@1302: public double getGlobalAlpha() { toni@1128: return graphicsEnvironmentImpl.getGlobalAlpha(); toni@1128: } toni@1111: toni@1302: /** toni@1302: * Sets the global blend mode. toni@1302: * toni@1302: * @param op the BlendMode that will be set. toni@1302: */ toni@1302: public void setGlobalCompositeOperation(String operation) { toni@1128: graphicsEnvironmentImpl.setGlobalCompositeOperation(operation); toni@1128: } toni@1111: toni@1302: /** toni@1302: * Gets the global blend mode. toni@1302: * toni@1302: * @return the global BlendMode of the current state. toni@1302: */ toni@1302: public String getGlobalCompositeOperation() { toni@1128: return graphicsEnvironmentImpl.getGlobalCompositeOperation(); toni@1128: } toni@1111: toni@1443: /** toni@1443: * Create a LinearGradient to use in Canvas. toni@1443: * toni@1443: * @param x0 x coordinate of start point toni@1443: * @param y0 y coordinate of start point toni@1443: * @param x1 x coordinate of end point toni@1443: * @param y1 y coordinate of end point toni@1443: * @return the gradient toni@1443: */ toni@1449: public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1, Map stops) { toni@1449: return Style.LinearGradient.create(x0, y0, x1, y1, stops); toni@1128: } toni@1111: toni@1443: /** toni@1443: * Create an Image Pattern from a source Image and a repeat style. Possible toni@1443: * Styles are repeat, repeat-x, repeat-y, or no-repeat. defaults to repeat toni@1443: * toni@1443: * @param image the Image toni@1443: * @param repeat the repeat style toni@1443: * @return the Pattern toni@1443: */ toni@1302: public Pattern createPattern(Image image, String repeat) { toni@1144: return new Pattern(image, repeat); toni@1144: } toni@1111: toni@1443: /** toni@1443: * Create a RadialGradient toni@1443: * toni@1443: * @param x0 x Coordinate of starting circle toni@1443: * @param y0 y Coordinate of starting circle toni@1443: * @param r0 radius of starting circle toni@1443: * @param x1 x coordinate of ending circle toni@1443: * @param y1 y coordinate of ending circle toni@1443: * @param r1 radius of ending circle toni@1443: * @return the Gradient toni@1443: */ toni@1449: public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1, Map stops) { toni@1449: return RadialGradient.create(x0, y0, r0, x1, y1, r1, stops); toni@1128: } toni@1302: toni@1443: /** toni@1443: * Convert this String Representation of a Color to a Color Object. toni@1443: * toni@1443: * @param webColor toni@1443: * @return The Color represented by the input toni@1443: */ toni@1302: public Color getWebColor(String webColor) { toni@1150: return new Style.Color(webColor); toni@1150: } toni@1111: toni@1302: /** toni@1302: * Get the height of this GraphicsContext (which should be the same as the toni@1302: * enclosing canvas height) toni@1302: * toni@1302: * @return the height of this GraphicsContext toni@1302: */ toni@1302: public int getHeight() { toni@1128: return graphicsEnvironmentImpl.getHeight(); toni@1128: } toni@1111: toni@1302: /** toni@1302: * Get the width of this GraphicsContext (which should be the same as the toni@1302: * enclosing canvas height) toni@1302: * toni@1302: * @return the width of this GraphicsContext toni@1302: */ toni@1302: public int getWidth() { toni@1128: return graphicsEnvironmentImpl.getWidth(); toni@1128: } toni@1111: toni@1302: // public void setHeight(int height) { toni@1302: // graphicsEnvironmentImpl.setHeight(height); toni@1302: // } toni@1302: // toni@1302: // public void setWidth(int width) { toni@1302: // graphicsEnvironmentImpl.setWidth(width); toni@1302: // } toni@1302: /** toni@1302: * Fill a circle with a center position of centerX, centerY and the toni@1302: * specified radius. toni@1302: * toni@1302: * @param centerX toni@1302: * @param centerY toni@1302: * @param radius toni@1302: */ toni@1302: public void fillCircle(float centerX, float centerY, float radius) { toni@1302: graphicsEnvironmentImpl.arc(centerX, centerY, radius, 0, Math.PI * 2, false); toni@1128: } toni@1128: toni@1302: /** toni@1302: * Fills a polygon with the given points using the currently set fill paint. toni@1302: * toni@1302: * @param x_coord array containing the x coordinates of the polygon's toni@1302: * points. toni@1302: * @param y_coord array containing the y coordinates of the polygon's toni@1302: * points. toni@1302: * @param vertexCount the number of points that make the polygon. toni@1302: */ toni@1263: public void fillPolygon(double[] x_coord, double[] y_coord, int vertexCount) { toni@1302: if (vertexCount >= 1 && x_coord != null && x_coord.length >= vertexCount && y_coord != null && y_coord.length >= vertexCount) { toni@1302: graphicsEnvironmentImpl.beginPath(); toni@1302: } toni@1263: graphicsEnvironmentImpl.moveTo(x_coord[0], y_coord[0]); toni@1263: for (int i = 1; i < vertexCount; i++) { toni@1263: graphicsEnvironmentImpl.lineTo(x_coord[i], y_coord[i]); toni@1302: toni@1263: } toni@1263: graphicsEnvironmentImpl.closePath(); toni@1263: graphicsEnvironmentImpl.fill(); toni@1263: graphicsEnvironmentImpl.stroke(); toni@1263: } toni@521: }