|
||||||||||
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 |
---|
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(float x,
float y,
float radius,
float startAngle,
float 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. |
void |
cubicCurveTo(float cp1x,
float cp1y,
float cp2x,
float cp2y,
float x,
float y)
Does nothing if the context's path is empty. |
void |
drawImage(ImageHandle img,
int offsetX,
int offsetY)
Draws an input image to a specified position on the canvas. |
void |
drawImage(ImageHandle img,
int offsetX,
int offsetY,
int width,
int 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(float startX,
float startY,
float width,
float height)
Fills a rectangle of the specified dimensions, at the specified start coords, according to the current fillstyle. |
int |
getHeight()
Returns the height in pixels of the canvas. |
int |
getWidth()
Returns the width in pixels of the canvas. |
void |
lineTo(float x,
float y)
Adds a line from the last point in the current path to the point defined by x and y. |
void |
moveTo(float x,
float y)
Makes the last point in the current path be (x,y). |
void |
quadraticCurveTo(float cpx,
float cpy,
float x,
float y)
Does nothing if the context has an empty path. |
void |
rect(float startX,
float startY,
float width,
float 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(float angle)
Adds a rotation of the specified angle to the current transform. |
void |
saveContext()
Saves the current context to the context stack. |
void |
scale(float x,
float y)
Adds a scale transformation to the current transformation matrix. |
void |
setCoordSize(int width,
int height)
Sets the coordinate space of the Canvas. |
void |
setFillStyle(Color color)
Set the current Fill Style to the specified color. |
void |
setGlobalAlpha(float alpha)
Set the global transparency to the specified alpha. |
void |
setLineWidth(float width)
Sets the current context's linewidth. |
void |
setPixelHeight(int height)
Sets the height of the canvas in pixels. |
void |
setPixelWidth(int width)
Sets the CSS property in pixels for the canvas. |
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(float startX,
float startY,
float width,
float height)
Strokes a rectangle defined by the supplied arguments. |
void |
transform(float m11,
float m12,
float m21,
float m22,
float dx,
float dy)
The transform(m11, m12, m21, m22, dx, dy) method must multiply the
current transformation matrix with the input matrix. |
void |
translate(float x,
float 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, setElement |
Methods inherited from class com.google.gwt.user.client.ui.UIObject |
---|
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, 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 |
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 directionpublic GWTCanvas(int coordX, int coordY, int pixelX, int pixelY)
Different coordinate spaces and pixel spaces will cause aliased scaling.
Use scale(float,float)
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 elementMethod Detail |
---|
public void arc(float x, float y, float radius, float startAngle, float 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 void cubicCurveTo(float cp1x, float cp1y, float cp2x, float cp2y, float x, float 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 pointpublic void drawImage(ImageHandle img, int offsetX, int 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 spacepublic void drawImage(ImageHandle img, int offsetX, int offsetY, int width, int 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(float startX, float startY, float width, float 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 getHeight()
public int getWidth()
public void lineTo(float x, float y)
x
- x coord of pointy
- y coord of pointpublic void moveTo(float x, float y)
x
- x coord of pointy
- y coord of pointpublic void quadraticCurveTo(float cpx, float cpy, float x, float y)
cpx
- x coord of the control pointcpy
- y coord of the control pointx
- x coord of the pointy
- y coord of the pointpublic void rect(float startX, float startY, float width, float 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 rectanglepublic void resize(int width, int height)
canvas.setCoordSize(width, height);
canvas.setPixelHeight(height);
canvas.setPixelWidth(width);
width
- height
- public void restoreContext()
public void rotate(float angle)
angle
- the angle to rotate by, in radianspublic void saveContext()
public void scale(float x, float y)
x
- ratio that we must scale in the X directiony
- ratio that we must scale in the Y directionpublic 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 setFillStyle(Color color)
color
- Color
public void setGlobalAlpha(float alpha)
alpha
- alpha valuepublic void setLineWidth(float width)
width
- the width of the canvaspublic void setPixelHeight(int height)
height
- the height of the canvaspublic void setPixelWidth(int width)
width
- width of the canvaspublic void setStrokeStyle(Color color)
color
- Color
public void stroke()
public void strokeRect(float startX, float startY, float width, float height)
startX
- x coord of the top left cornerstartY
- y coord of the top left cornerwidth
- width of the rectangleheight
- height of the rectanglepublic void transform(float m11, float m12, float m21, float m22, float dx, float 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 directionpublic void translate(float x, float 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 |