Documentation in progress: please use the 3.4 Reference Manual.

Name

drawview — Adds procedural drawing APIs to view.

Synopsis

LZX: drawview
JavaScript: lz.drawview
Type: Class
Access: public
Topic: LFC.Views
Declared in: lps/components/extensions/drawview.lzx

Description

drawview adds procedural drawing APIs to view

drawview implements a subset of the WHATWG drawing APIs, which can be found at: http://www.whatwg.org/specs/web-apps/current-work/#graphics

<canvas>
            <drawview width="200" height="200">
                <handler name="oncontext">
                    this.moveTo(100, 100);
                    this.lineTo(100, 200);
                    this.quadraticCurveTo(150, 250, 200, 200);
                    this.closePath();
        
                    this.fillStyle = 0x0000ff;
                    this.globalAlpha = .5;
                    this.fill();
                    
                    this.strokeStyle = 0xffff00;
                    this.lineWidth = 5;
                    this.stroke();
                    
                    var g = this.createRadialGradient(75, 75, .7, 300, 300, 0)
                    this.globalAlpha = 0;
                    g.addColorStop(0, 0x000000);
                    this.globalAlpha = 1;
                    g.addColorStop(1, 0xffffff);
                    this.fillStyle = g;
                    this.fill();
        
                    this.strokeStyle = 0x000000;
                    this.lineWidth = 0;
                    this.stroke();
        
                    this.beginPath();
                    this.lineTo(75, 0);
                    this.lineTo(75, 75);
                    this.lineTo(0, 75);
                    this.lineTo(0, 0);
                    this.closePath();
                    
                    var g = this.createLinearGradient(0,0,75,75)
                    this.globalAlpha = 0;
                    g.addColorStop(0, 0x000000);
                    this.globalAlpha = 1;
                    g.addColorStop(1, 0xffffff);
                    this.fillStyle = g;
                    this.fill();
                </handler>
            </drawview>
        </canvas>

drawview extends LzView, which is the fundamental visual class of LZX.

Superclass Chain

node (LzNode) » view (LzView) » drawview

Known Subclasses

Details

Properties (7)

cachebitmap
<attribute name="cachebitmap" value="true" />
public var cachebitmap;
If true, the bitmap result will be cached where possible.
context
<attribute name="context" value="null" />
public var context;
Contains a reference to the raw drawview context. oncontext is sent when the context is ready to use, which can take some time in IE.
fillStyle
<attribute name="fillStyle" type="string" value="#000000" />
public var fillStyle : String;
Represents the colour or style to use for the fill inside the shapes. Can be either a hexadecimal number (0xffffff), a CSS string ('#ff00ff' or '#f0f'), or a CanvasGradient/LzCanvasGradient.
globalAlpha
<attribute name="globalAlpha" type="number" value="1" />
public var globalAlpha : Number;
Gives an alpha value that is applied to shapes and images before they are composited onto the canvas. The valid range of values is from 0.0 (fully transparent) to 1.0 (no additional transparency). If the attribute is set to values outside this range, they are ignored. When the context is created, the globalAlpha attribute initially has the value 1.0.
lineCap
<attribute name="lineCap" type="string" value="round" />
public var lineCap : string;
Gives the default lineCap value for lines. Round for consistency between swf and dhtml.
lineWidth
<attribute name="lineWidth" type="number" value="1" />
public var lineWidth : Number;
Gives the default width of lines, in coordinate space units. Negative values are ignored. 0 draws hairlines in swf - lines that are always 1 pixel wide even when scaled.
strokeStyle
<attribute name="strokeStyle" type="string" value="#000000" />
public var strokeStyle : String;
Represents the colour to use for the lines around shapes. Specified as a hexadecimal number (0xffffff) or a CSS string ('#ff00ff' or '#f0f').

Methods (14)

arc()
<method name="arc" args="x, y, radius, startAngle, endAngle, clockwise" />
public function arc(x : Number, y : Number, radius : Number, startAngle : Number, endAngle : Number, clockwise : Number);
Adds an arc to the current path. The arc is a segment of a circle that has radius as given. The circle segment is determined by the two angles startAngle and endAngle and begins at the given coordinate (x,y). If clockwise is true, the arc is drawn clockwise from startAngle to endAngle, otherwise it is drawn counter-clockwise (anti-clockwise).
beginPath()
<method name="beginPath" />
public function beginPath();
Resets the list of subpaths to an empty list, and calls moveTo() with the point (0,0).
bezierCurveTo()
<method name="bezierCurveTo" args="cp1x, cp1y, cp2x, cp2y, x, y" />
public function bezierCurveTo(cp1x : Number, cp1y : Number, cp2x : Number, cp2y : Number, x : Number, y : Number);
bezierCurveTo() adds the given coordinate (x, y) to the list of points of the subpath, and connects the two points with a bezier curve with control points (cp1x, cp1y) and (cp2x, cp2y). It then sets the current position to the given coordinate (x, y).
clear()
<method name="clear" />
public function clear();
Clears drawing area
closePath()
<method name="closePath" />
public function closePath();
Adds a straight line from the current position to the first point in the last subpath and marks the subpath as closed, if the last subpath isn't closed, and if it has more than one point in its list of points. If the last subpath is not open or has only one point, it does nothing.
createLinearGradient()
<method name="createLinearGradient" args="x0, y0, x1, y1" />
public function createLinearGradient(x0 : Number, y0 : Number, x1 : Number, y1 : Number) : LzCanvasGradient;
Takes four arguments, representing the start point (x0, y0) and end point (x1, y1) of the gradient, in coordinate space units, and returns an object representing a linear gradient initialised with that line. Linear gradients are rendered such that at the starting point on the canvas the colour at offset 0 is used, that at the ending point the color at offset 1 is used, that all points on a line perpendicular to the line between the start and end points have the colour at the point where those two lines cross. (Of course, the colours are only painted where the shape they are being painted on needs them.)
createRadialGradient()
<method name="createRadialGradient" args="x0, y0, r0, x1, y1, r1" />
public function createRadialGradient(x0 : Number, y0 : Number, r0 : Number, x1 : Number, y1 : Number, r1 : Number) : LzCanvasGradient;
Takes six arguments, the first three representing the start point (x0, y0) and rotation r0, and the last three representing the end point (x1, y1) and radius r1. The values are in coordinate space units. Rotation doesn't appear to work for radial gradients. Even so, it can be set by specifying r0 in radians. r1 is ignored.
fill()
<method name="fill" />
public function fill();
Fills each subpath of the current path in turn, using fillStyle, and using the non-zero winding number rule. Open subpaths are implicitly closed when being filled (without affecting the actual subpaths). Note that closePath() is called before the line is filled.
lineTo()
<method name="lineTo" args="x, y" />
public function lineTo(x : Number, y : Number);
Adds the given coordinate (x, y) to the list of points of the subpath, and connects the current position to that point with a straight line. It then sets the current position to the given coordinate (x, y).
moveTo()
<method name="moveTo" args="x, y" />
public function moveTo(x, y);
Sets the current position to the given coordinate and creates a new subpath with that point as its first (and only) point. If there was a previous subpath, and it consists of just one point, then that subpath is removed from the path.
oval()
<method name="oval" args="x, y, radius, yRadius" />
public function oval(x, y, radius, yRadius);
quadraticCurveTo()
<method name="quadraticCurveTo" args="cpx, cpy, x, y" />
public function quadraticCurveTo(cpx : Number, cpy : Number, x : Number, y : Number);
Adds the given coordinate (x, y) to the list of points of the subpath, and connects the current position to that point with a quadratic curve with control point (cpx, cpy). It then sets the current position to the given coordinate (x, y).
rect()
<method name="rect" args="x, y, w, h, cornerRadius" />
public function rect(x : Number, y : Number, w : Number, h : Number, cornerRadius : Number);
Rect creates a new subpath containing just the rectangle with top left coordinate (x, y), width w and height h. based on mc.drawRect() - by Ric Ewing (ric@formequalsfunction.com)
stroke()
<method name="stroke" />
public function stroke();
Strokes each subpath of the current path in turn, using the strokeStyle and lineWidth attributes.

Events (1)

oncontext
<attribute name="oncontext" />
public event oncontext;
Sent when the context is ready to use, which can take some time in IE.

LZX Synopsis

<class name="lz.drawview" extends=" LzView ">
  <attribute name=" cachebitmap " value="true" />
  <attribute name=" context " value="null" />
  <attribute name=" fillStyle " type="string" value="#000000" />
  <attribute name=" globalAlpha " type="number" value="1" />
  <attribute name=" lineCap " type="string" value="round" />
  <attribute name=" lineWidth " type="number" value="1" />
  <attribute name=" strokeStyle " type="string" value="#000000" />
  <method name=" arc " args="x, y, radius, startAngle, endAngle, clockwise" />
  <method name=" beginPath " />
  <method name=" bezierCurveTo " args="cp1x, cp1y, cp2x, cp2y, x, y" />
  <method name=" clear " />
  <method name=" closePath " />
  <method name=" createLinearGradient " args="x0, y0, x1, y1" />
  <method name=" createRadialGradient " args="x0, y0, r0, x1, y1, r1" />
  <method name=" fill " />
  <method name=" lineTo " args="x, y" />
  <method name=" moveTo " args="x, y" />
  <event name=" oncontext " />
  <method name=" oval " args="x, y, radius, yRadius" />
  <method name=" quadraticCurveTo " args="cpx, cpy, x, y" />
  <method name=" rect " args="x, y, w, h, cornerRadius" />
  <method name=" stroke " />
</class>

JavaScript Synopsis

public lz.drawview extends  LzView  {
  public var cachebitmap ;
  public var context ;
  public var fillStyle  : String;
  public var globalAlpha  : Number;
  public var lineCap  : string;
  public var lineWidth  : Number;
  public var strokeStyle  : String;
  prototype public function arc (x : Number, y : Number, radius : Number, startAngle : Number, endAngle : Number, clockwise : Number);
  prototype public function beginPath ();
  prototype public function bezierCurveTo (cp1x : Number, cp1y : Number, cp2x : Number, cp2y : Number, x : Number, y : Number);
  prototype public function clear ();
  prototype public function closePath ();
  prototype public function createLinearGradient (x0 : Number, y0 : Number, x1 : Number, y1 : Number) : LzCanvasGradient;
  prototype public function createRadialGradient (x0 : Number, y0 : Number, r0 : Number, x1 : Number, y1 : Number, r1 : Number) : LzCanvasGradient;
  prototype public function fill ();
  prototype public function lineTo (x : Number, y : Number);
  prototype public function moveTo (x, y);
  prototype public event oncontext ;
  prototype public function oval (x, y, radius, yRadius);
  prototype public function quadraticCurveTo (cpx : Number, cpy : Number, x : Number, y : Number);
  prototype public function rect (x : Number, y : Number, w : Number, h : Number, cornerRadius : Number);
  prototype public function stroke ();
}