My favorites | English | Sign in

o3d.Canvas Class Reference

Inherits o3d.ParamObject

List of all members.


Detailed Description

Canvas provides an interface for drawing text and 2D primitives on a 2D surface. The contents of the canvas surface can be transfered to a compatible Texture2D object via the copyToTexture() method. Each Canvas object maintains a stack of 2D transformation matrices which allow fine control over the placement of drawable elements. Both geometry and drawing coordinates provided to every draw call are transformed by the concatenation of all matrices in the stack.

Public Member Functions

clear(color) o3d.Canvas
copyParams(sourceParamObject) o3d.ParamObject
copyToTexture(texture) [**DEPRECATED**] o3d.Canvas
o3d.Param  createParam(paramName, paramTypeName) o3d.ParamObject
drawBitmap(texture, left, bottom) [**DEPRECATED**] o3d.Canvas
drawRect(left, top, right, bottom, paint) o3d.Canvas
drawText(text, x, y, paint) o3d.Canvas
drawTextOnPath(text, positions, horizontalOffset, verticalOffset, paint) o3d.Canvas
o3d.Param  getParam(paramName) o3d.ParamObject
boolean  isAClassName(className) o3d.ObjectBase
boolean  removeParam(param) o3d.ParamObject
restoreMatrix() o3d.Canvas
rotate(degrees) o3d.Canvas
saveMatrix() o3d.Canvas
scale(sx, sy) o3d.Canvas
boolean  setSize(width, height) o3d.Canvas
translate(dx, dy) o3d.Canvas

Public Properties

string className o3d.ObjectBase
number clientId o3d.ObjectBase
number height o3d.Canvas
string name o3d.NamedObject
!Array.<!o3d.Param> params o3d.ParamObject
number width o3d.Canvas

Member Function Documentation

Canvas.clear ( !o3d.Float4 color )

Clears the bitmap's pixels with the specified color.

Parameters:
color The color to clear the bitmap with, provided as an array of four values [red, green, blue, alpha]. All values should be between 0.0 and 1.0. For alpha values 0.0 is transparent and 1.0 opaque.
Canvas.copyParams ( !o3d.ParamObject sourceParamObject ) [inherited from o3d.ParamObject]

Copies all the params from a the given source_param_object to this param object. Does not replace any currently existing params with the same name.

Parameters:
sourceParamObject param object to copy params from.
Canvas.copyToTexture ( !o3d.Texture2D texture )
[**DEPRECATED**]

Copies the contents of the Canvas to a 2D texture object. The size of the texture must match exactly the size of the Canvas set by the setSize() method. The format of the texture must be set to either ARGB8 or XRGB8.

Parameters:
texture Texture to copy to.
See Also:
o3d.Param Canvas.createParam ( string paramName
string paramTypeName ) [inherited from o3d.ParamObject]

Creates a Param with the given name and type on the ParamObject. Will fail if a param with the same name already exists.

Parameters:
paramName The name of the Param to be created.
paramTypeName The type of Param to create. Valid types are
  • 'o3d.ParamBoolean'
  • 'o3d.ParamBoundingBox'
  • 'o3d.ParamDrawContext'
  • 'o3d.ParamDrawList'
  • 'o3d.ParamEffect'
  • 'o3d.ParamFloat'
  • 'o3d.ParamFloat2'
  • 'o3d.ParamFloat3'
  • 'o3d.ParamFloat4'
  • 'o3d.ParamFunction'
  • 'o3d.ParamInteger'
  • 'o3d.ParamMaterial'
  • 'o3d.ParamMatrix4'
  • 'o3d.ParamParamArray'
  • 'o3d.ParamRenderSurface'
  • 'o3d.ParamRenderDepthStencilSurface'
  • 'o3d.ParamSampler'
  • 'o3d.ParamSkin'
  • 'o3d.ParamSteamBank'
  • 'o3d.ParamState'
  • 'o3d.ParamString'
  • 'o3d.ParamTexture'
  • 'o3d.ParamTransform'
  • 'o3d.ProjectionParamMatrix4'
  • 'o3d.ProjectionInverseParamMatrix4'
  • 'o3d.ProjectionTransposeParamMatrix4'
  • 'o3d.ProjectionInverseTransposeParamMatrix4'
  • 'o3d.ViewParamMatrix4'
  • 'o3d.ViewInverseParamMatrix4'
  • 'o3d.ViewTransposeParamMatrix4'
  • 'o3d.ViewInverseTransposeParamMatrix4'
  • 'o3d.ViewProjectionParamMatrix4'
  • 'o3d.ViewProjectionInverseParamMatrix4'
  • 'o3d.ViewProjectionTransposeParamMatrix4'
  • 'o3d.ViewProjectionInverseTransposeParamMatrix4'
  • 'o3d.WorldParamMatrix4'
  • 'o3d.WorldInverseParamMatrix4'
  • 'o3d.WorldTransposeParamMatrix4'
  • 'o3d.WorldInverseTransposeParamMatrix4'
  • 'o3d.WorldViewParamMatrix4'
  • 'o3d.WorldViewInverseParamMatrix4'
  • 'o3d.WorldViewTransposeParamMatrix4'
  • 'o3d.WorldViewInverseTransposeParamMatrix4'
  • 'o3d.WorldViewProjectionParamMatrix4'
  • 'o3d.WorldViewProjectionInverseParamMatrix4'
  • 'o3d.WorldViewProjectionTransposeParamMatrix4'
  • 'o3d.WorldViewProjectionInverseTransposeParamMatrix4'
  • Returns:
    o3d.Param.The newly created Param or null on failure.
    Canvas.drawBitmap ( !o3d.Texture2D texture
    number left
    number bottom )
    [**DEPRECATED**]

    Draws the contents of the specified texture onto the canvas surface. The bottom left corner of the bitmap will be at (x, y) and transformed by the current matrix. Only ARGB8 and XRGB8 textures are supported. For XRG8 textures, Alpha is assumed to be 1 (opaque).

    Parameters:
    texture The Texture2D object where the bitmap is extracted from.
    left The position of the left side of the bitmap.
    bottom The position of the bottom side of the bitmap.
    Canvas.drawRect ( number left
    number top
    number right
    number bottom
    !o3d.CanvasPaint paint )

    Draws the specified rectangle using the specified paint. The rectangle will be filled based on the color and shader in the paint.

    Parameters:
    left The left side of the rectangle to be drawn
    top The top side of the rectangle to be drawn
    right The right side of the rectangle to be drawn
    bottom The bottom side of the rectangle to be drawn
    paint The paint used to draw the rectangle
    Canvas.drawText ( string text
    number x
    number y
    !o3d.CanvasPaint paint )

    Draws the text, with origin at (x,y), using the specified paint. The origin is interpreted based on the textAlign property in the paint.

    Parameters:
    text String of text to be drawn
    x The x coordinate for the text origin
    y The y coordinate for the text origin
    paint The CanvasPaint object that specifies the text style, size, etc
    Canvas.drawTextOnPath ( string text
    !Array.<!o3d.Float2> positions
    number horizontalOffset
    number verticalOffset
    !o3d.CanvasPaint paint )

    Draws the text with its baseline along the specified path. The paint's textAlign property determines where along the path to start the text. The path must contain at least two positions.

    Parameters:
    text String of text to be drawn
    positions An array of x,y positions making up the path.
    horizontalOffset The distance along the path to add to the text starting position.
    verticalOffset The distance above(-) or below(+) the path to position the text.
    paint The CanvasPaint object that specifies the text style, size, etc.
    o3d.Param Canvas.getParam ( string paramName ) [inherited from o3d.ParamObject]

    Searches by name for a Param defined in the object.

    Parameters:
    paramName Name to search for.
    Returns:
    o3d.Param.The Param with the given name, or null otherwise.
    boolean Canvas.isAClassName ( string className ) [inherited from o3d.ObjectBase]

    Takes the name of a class as an argument, and returns true if this object is either an instance of that class or derives from that class.

    var t = pack.createObject('o3d.Transform');
    t.isAClassName('o3d.Transform');    // true
    t.isAClassName('o3d.ParamObject');  // true
    t.isAClassName('o3d.Shape');        // false
    
    Parameters:
    className Name of class to check for.
    Returns:
    boolean.true if this object is a or is derived from the given class name.
    boolean Canvas.removeParam ( !o3d.Param param ) [inherited from o3d.ParamObject]

    Removes a Param from a ParamObject. This function will fail if the param does not exist on this ParamObject or if the param is unremovable.

    Parameters:
    param param to remove.
    Returns:
    boolean.True if the param was removed.
    Canvas.restoreMatrix ( )

    Balances a call to saveMatrix(), and removes modifications to matrix since the last save call. It is an error to call this more than previous calls to saveMatrix().

    Canvas.rotate ( number degrees )

    Adds a rotation to the current canvas matrix.

    Parameters:
    degrees The amount to rotate, in degrees
    Canvas.saveMatrix ( )

    This call saves the current matrix and pushes a copy onto a private stack. Subsequent calls to translate, scale, rotate all operate on this copy. When the balancing call to restoreMatrix() is made, this copy is deleted and the previous matrix is restored.

    Canvas.scale ( number sx
    number sy )

    Adds a scale to the current canvas matrix.

    Parameters:
    sx The amount to scale in x
    sy The amount to scale in y
    boolean Canvas.setSize ( number width
    number height )

    Sets the size of the bitmap area that the Canvas uses.

    Parameters:
    width The width of the bitmap.
    height The height of the bitmap.
    Returns:
    boolean.true if the Canvas surface was allocated successfully.
    Canvas.translate ( number dx
    number dy )

    Adds a translation to the current canvas matrix.

    Parameters:
    dx The amount to translate in x
    dy The amount to translate in y

    Member Property Documentation

    string Canvas.className [inherited from o3d.ObjectBase]

    The concrete class name for an object derived from ObjectBase. If you want to know if an object is of a certain type you should use objectBase.isAClassName

    var t = pack.createObject('o3d.Transform');
    t.className == 'o3d.Transform';  // true
    
    This property is read-only.
    number Canvas.clientId [inherited from o3d.ObjectBase]

    Unique id of the object. This id will be unique, even across multiple O3D clients in the same page. This property is read-only.

    number Canvas.height

    The height of the bitmap used by the Canvas (read only). This property is read-only.

    string Canvas.name [inherited from o3d.NamedObject]

    The object's name. Setting this has no meaning to O3D, but is useful for debugging and for the functions Client.getObjects, Pack.getObject, RenderNode.getRenderNodesByNameInTree and RenderNode.getTransformsByNameInTree which search for objects by name.

    !Array.<!o3d.Param> Canvas.params [inherited from o3d.ParamObject]

    Gets all the param on this param object. Each access to this field gets the entire list, so it is best to get it just once. For example:

    var params = paramObject.params;
    for (var i = 0; i < params.length; i++) {
      var param = params[i];
    }
    
    Note that modifications to this array [e.g. push()] will not affect the underlying ParamObject, while modifications to the array's members will affect them. This property is read-only.
    number Canvas.width

    The width of the bitmap used by the Canvas (read only). This property is read-only.