|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.google.gwt.widgetideas.graphics.client.GWTCanvas
public class GWTCanvas
2D Graphics API. API mimicks functionality found in the Javascript canvas API (see canvas tutorial).
Performance may scale differently for IE than for browsers with a native canvas implementation. Sub-pixel precision is supported where possible.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject |
|---|
com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled |
| Field Summary | |
|---|---|
static java.lang.String |
BEVEL
Use this constant as a parameter for the setLineJoin(String) method. |
static java.lang.String |
BUTT
Use this constant as a parameter for the setLineCap(String) method. |
static java.lang.String |
DESTINATION_OVER
Use this constant as a parameter for the setGlobalCompositeOperation(String) method. |
static java.lang.String |
MITER
Use this constant as a parameter for the setLineJoin(String) method. |
static java.lang.String |
ROUND
Use this constant either as a parameter for the setLineCap(String) or the setLineJoin(String) method. |
static java.lang.String |
SOURCE_OVER
Use this constant as a parameter for the setGlobalCompositeOperation(String) method. |
static java.lang.String |
SQUARE
Use this constant as a parameter for the setLineCap(String) method. |
static Color |
TRANSPARENT
Use this constant as a parameter for the setBackgroundColor(Color) method. |
| Fields inherited from class com.google.gwt.user.client.ui.UIObject |
|---|
DEBUG_ID_PREFIX |
| Constructor Summary | |
|---|---|
GWTCanvas()
Creates a GWTCanvas element. |
|
GWTCanvas(int coordX,
int coordY)
Creates a GWTCanvas element. |
|
GWTCanvas(int coordX,
int coordY,
int pixelX,
int pixelY)
Creates a GWTCanvas element. |
|
| Method Summary | |
|---|---|
void |
arc(double x,
double y,
double radius,
double startAngle,
double endAngle,
boolean antiClockwise)
Draws an arc. |
void |
beginPath()
Erases the current path and prepares it for a new path. |
void |
clear()
Clears the entire canvas. |
void |
closePath()
Closes the current path. |
CanvasGradient |
createLinearGradient(double x0,
double y0,
double x1,
double y1)
Creates a LinearGradient Object for use as a fill or stroke style. |
CanvasGradient |
createRadialGradient(double x0,
double y0,
double r0,
double x1,
double y1,
double r1)
Creates a RadialGradient Object for use as a fill or stroke style. |
void |
cubicCurveTo(double cp1x,
double cp1y,
double cp2x,
double cp2y,
double x,
double y)
Does nothing if the context's path is empty. |
void |
drawImage(com.google.gwt.dom.client.ImageElement img,
double offsetX,
double offsetY)
Draws an input image to a specified position on the canvas. |
void |
drawImage(com.google.gwt.dom.client.ImageElement img,
double offsetX,
double offsetY,
double width,
double height)
Draws an input image at a given position on the canvas. |
void |
fill()
Fills the current path according to the current fillstyle. |
void |
fillRect(double startX,
double startY,
double width,
double height)
Fills a rectangle of the specified dimensions, at the specified start coords, according to the current fillstyle. |
int |
getCoordHeight()
Returns the height in pixels of the canvas. |
int |
getCoordWidth()
Returns the width in pixels of the canvas. |
double |
getGlobalAlpha()
See setter method for a fully detailed description. |
java.lang.String |
getGlobalCompositeOperation()
See setter method for a fully detailed description. |
java.lang.String |
getLineCap()
See setter method for a fully detailed description. |
java.lang.String |
getLineJoin()
See setter method for a fully detailed description. |
double |
getLineWidth()
See setter method for a fully detailed description. |
double |
getMiterLimit()
See setter method for a fully detailed description. |
void |
lineTo(double x,
double y)
Adds a line from the last point in the current path to the point defined by x and y. |
void |
moveTo(double x,
double y)
Makes the last point in the current path be (x,y). |
void |
quadraticCurveTo(double cpx,
double cpy,
double x,
double y)
Does nothing if the context has an empty path. |
void |
rect(double startX,
double startY,
double width,
double height)
Adds a rectangle to the current path, and closes the path. |
void |
resize(int width,
int height)
Convenience function for resizing the canvas with consistent coordinate and screen pixel spaces. |
void |
restoreContext()
Restores the last saved context from the context stack. |
void |
rotate(double angle)
Adds a rotation of the specified angle to the current transform. |
void |
saveContext()
Saves the current context to the context stack. |
void |
scale(double x,
double y)
Adds a scale transformation to the current transformation matrix. |
void |
setBackgroundColor(Color color)
Sets the background color of the canvas element. |
void |
setCoordHeight(int height)
Sets the coordinate height of the Canvas. |
void |
setCoordSize(int width,
int height)
Sets the coordinate space of the Canvas. |
void |
setCoordWidth(int width)
Sets the coordinate width of the Canvas. |
void |
setFillStyle(CanvasGradient grad)
Set the current Fill Style to the specified color gradient. |
void |
setFillStyle(Color color)
Set the current Fill Style to the specified color. |
void |
setGlobalAlpha(double alpha)
Set the global transparency to the specified alpha. |
void |
setGlobalCompositeOperation(java.lang.String globalCompositeOperation)
Determines how the canvas is displayed relative to any background content. |
void |
setLineCap(java.lang.String lineCap)
A string value that determines the end style used when drawing a line. |
void |
setLineJoin(java.lang.String lineJoin)
A string value that determines the join style between lines. |
void |
setLineWidth(double width)
Sets the current context's linewidth. |
void |
setMiterLimit(double miterLimit)
A double value with the new miter limit. |
void |
setPixelHeight(int height)
Sets the CSS height of the canvas in pixels. |
void |
setPixelWidth(int width)
Sets the CSS width in pixels for the canvas. |
void |
setStrokeStyle(CanvasGradient grad)
Set the current Stroke Style to the specified color gradient. |
void |
setStrokeStyle(Color color)
Set the current Stroke Style to the specified color. |
void |
stroke()
Strokes the current path according to the current stroke style. |
void |
strokeRect(double startX,
double startY,
double width,
double height)
Strokes a rectangle defined by the supplied arguments. |
void |
transform(double m11,
double m12,
double m21,
double m22,
double dx,
double dy)
The transform(m11, m12, m21, m22, dx, dy) method must multiply the
current transformation matrix with the input matrix. |
void |
translate(double x,
double y)
Applies a translation (linear shift) by x in the horizontal and by y in the vertical. |
| Methods inherited from class com.google.gwt.user.client.ui.Widget |
|---|
doAttachChildren, doDetachChildren, getParent, isAttached, onAttach, onBrowserEvent, onDetach, onLoad, onUnload, removeFromParent |
| Methods inherited from class com.google.gwt.user.client.ui.UIObject |
|---|
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkEvents, toString, unsinkEvents |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String BEVEL
setLineJoin(String) method.
public static final java.lang.String BUTT
setLineCap(String) method.
public static final java.lang.String DESTINATION_OVER
setGlobalCompositeOperation(String) method.
public static final java.lang.String MITER
setLineJoin(String) method.
public static final java.lang.String ROUND
setLineCap(String) or the setLineJoin(String) method.
public static final java.lang.String SOURCE_OVER
setGlobalCompositeOperation(String) method.
public static final java.lang.String SQUARE
setLineCap(String) method.
public static final Color TRANSPARENT
setBackgroundColor(Color) method.
| Constructor Detail |
|---|
public GWTCanvas()
Screen size of canvas in pixels defaults to 300x150 pixels.
public GWTCanvas(int coordX,
int coordY)
Screen size of canvas in pixels defaults to the coordinate space dimensions for this constructor.
coordX - the size of the coordinate space in the x directioncoordY - the size of the coordinate space in the y direction
public GWTCanvas(int coordX,
int coordY,
int pixelX,
int pixelY)
Different coordinate spaces and pixel spaces will cause aliased scaling.
Use scale(double,double) and consistent coordinate and pixel
spaces for better results.
coordX - the size of the coordinate space in the x directioncoordY - the size of the coordinate space in the y directionpixelX - the CSS width in pixels of the canvas elementpixelY - the CSS height in pixels of the canvas element| Method Detail |
|---|
public void arc(double x,
double y,
double radius,
double startAngle,
double endAngle,
boolean antiClockwise)
x - center X coordinatey - center Y coordinateradius - radius of drawn arcstartAngle - angle measured from positive X axis to start of arc CWendAngle - angle measured from positive X axis to end of arc CWantiClockwise - direction that the arc line is drawnpublic void beginPath()
public void clear()
public void closePath()
public CanvasGradient createLinearGradient(double x0,
double y0,
double x1,
double y1)
x0 - x coord of start point of gradienty0 - y coord of start point of gradientx1 - x coord of end point of gradienty1 - y coord of end point of gradient
public CanvasGradient createRadialGradient(double x0,
double y0,
double r0,
double x1,
double y1,
double r1)
x0 - x coord of origin of start circley0 - y coord of origin of start circler0 - radius of start circlex1 - x coord of origin of end circley1 - y coord of origin of end circler1 - radius of the end circle
public void cubicCurveTo(double cp1x,
double cp1y,
double cp2x,
double cp2y,
double x,
double y)
bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)
method in canvas element Javascript API.
cp1x - x coord of first Control Pointcp1y - y coord of first Control Pointcp2x - x coord of second Control Pointcp2y - y coord of second Control Pointx - x coord of pointy - x coord of point
public void drawImage(com.google.gwt.dom.client.ImageElement img,
double offsetX,
double offsetY)
img - the image to be drawnoffsetX - x coord of the top left corner in the destination spaceoffsetY - y coord of the top left corner in the destination space
public void drawImage(com.google.gwt.dom.client.ImageElement img,
double offsetX,
double offsetY,
double width,
double height)
We recommend that the pixel and coordinate spaces be the same to provide consistent positioning and scaling results
img - The image to be drawnoffsetX - x coord of the top left corner in the destination spaceoffsetY - y coord of the top left corner in the destination spacewidth - the size of the image in the destination spaceheight - the size of the image in the destination spacepublic void fill()
public void fillRect(double startX,
double startY,
double width,
double height)
startX - x coord of the top left corner in the destination spacestartY - y coord of the top left corner in the destination spacewidth - destination width of imageheight - destination height of imagepublic int getCoordHeight()
public int getCoordWidth()
public double getGlobalAlpha()
setGlobalAlpha(double)public java.lang.String getGlobalCompositeOperation()
setGlobalCompositeOperation(String)public java.lang.String getLineCap()
setLineCap(String)public java.lang.String getLineJoin()
setLineJoin(String)public double getLineWidth()
setLineWidth(double)public double getMiterLimit()
setMiterLimit(double)
public void lineTo(double x,
double y)
x - x coord of pointy - y coord of point
public void moveTo(double x,
double y)
x - x coord of pointy - y coord of point
public void quadraticCurveTo(double cpx,
double cpy,
double x,
double y)
cpx - x coord of the control pointcpy - y coord of the control pointx - x coord of the pointy - y coord of the point
public void rect(double startX,
double startY,
double width,
double height)
startX - x coord of the top left corner of the rectanglestartY - y coord of the top left corner of the rectanglewidth - the width of the rectangleheight - the height of the rectangle
public void resize(int width,
int height)
canvas.setCoordSize(width, height);
canvas.setPixelHeight(height);
canvas.setPixelWidth(width);
width - height - public void restoreContext()
public void rotate(double angle)
angle - the angle to rotate by, in radianspublic void saveContext()
public void scale(double x,
double y)
x - ratio that we must scale in the X directiony - ratio that we must scale in the Y directionpublic void setBackgroundColor(Color color)
color - the background color.public void setCoordHeight(int height)
This will erase the canvas contents!
height - the size of the y component of the coordinate space
public void setCoordSize(int width,
int height)
This will erase the canvas contents!
width - the size of the x component of the coordinate spaceheight - the size of the y component of the coordinate spacepublic void setCoordWidth(int width)
This will erase the canvas contents!
width - the size of the x component of the coordinate spacepublic void setFillStyle(CanvasGradient grad)
grad - CanvasGradientpublic void setFillStyle(Color color)
color - Colorpublic void setGlobalAlpha(double alpha)
alpha - alpha valuepublic void setGlobalCompositeOperation(java.lang.String globalCompositeOperation)
GWTCanvas.SOURCE_OVER compositing mode.
The valid compositing operators are:
GWTCanvas.SOURCE_OVER
GWTCanvas.DESTINATION_OVER
globalCompositeOperation - public void setLineCap(java.lang.String lineCap)
GWTCanvas.BUTT for a flat edge that is
perpendicular to the line itself, GWTCanvas.ROUND for round
endpoints, or GWTCanvas.SQUARE for square endpoints. If you
do not set this value explicitly, the canvas uses the
GWTCanvas.BUTT line cap style.
lineCap - public void setLineJoin(java.lang.String lineJoin)
GWTCanvas.ROUND for round joins,
GWTCanvas.BEVEL for beveled joins, or
GWTCanvas.MITER for miter joins. If you do not set this
value explicitly, the canvas uses the GWTCanvas.MITER
line join style.
lineJoin - public void setLineWidth(double width)
width - the width of the canvaspublic void setMiterLimit(double miterLimit)
GWTCanvas.MITER, the canvas uses the
miter limit to determine whether the lines should be joined with a bevel
instead of a miter. The canvas divides the length of the miter by the
line width. If the result is greater than the miter limit, the style is
converted to a bevel.
miterLimit - public void setPixelHeight(int height)
height - the height of the canvas in pixelspublic void setPixelWidth(int width)
width - width of the canvas in pixelspublic void setStrokeStyle(CanvasGradient grad)
grad - CanvasGradientpublic void setStrokeStyle(Color color)
color - Colorpublic void stroke()
public void strokeRect(double startX,
double startY,
double width,
double height)
startX - x coord of the top left cornerstartY - y coord of the top left cornerwidth - width of the rectangleheight - height of the rectangle
public void transform(double m11,
double m12,
double m21,
double m22,
double dx,
double dy)
The transform(m11, m12, m21, m22, dx, dy) method must multiply the
current transformation matrix with the input matrix. Input described by:
m11 m21 dx m12 m22 dy 0 0 1
m11 - top left cell of 2x2 rotation matrixm12 - top right cell of 2x2 rotation matrixm21 - bottom left cell of 2x2 rotation matrixm22 - bottom right cell of 2x2 rotation matrixdx - Translation in X directiondy - Translation in Y direction
public void translate(double x,
double y)
x - amount to shift in the x directiony - amount to shift in the y direction
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||