Packagecom.nocircleno.graffiti
Classpublic class GraffitiCanvas
InheritanceGraffitiCanvas Inheritance flash.display.Sprite

Language Version : ActionScript 3.0
Runtime Versions : AIR 1.0, Flash Player 10 - AIR 1.5

The GraffitiCanvas Class provides an area on stage to draw in. It extends the Sprite Class, so you can add it as a child anywhere in the display list. Once you've created an instance of the GraffitiCanvas Class you can assign different tools to the canvas.

1.2 Features:

It is up to the developer to implement a UI for these features.



Public Properties
 PropertyDefined By
  activeTool : ITool
GraffitiCanvas
  canvasEnabled : Boolean
GraffitiCanvas
  canvasHeight : uint
GraffitiCanvas
  canvasWidth : uint
GraffitiCanvas
  historyLength : uint
[read-only] Get the current number of saved history items.
GraffitiCanvas
  historyPosition : uint
[read-only] Get the current history position.
GraffitiCanvas
  maxHistoryLength : uint
[read-only] Get the maximum number of history items.
GraffitiCanvas
  maxZoom : Number
[read-only] Maximum Zoom value.
GraffitiCanvas
  minZoom : Number
[read-only] Minimum Zoom value.
GraffitiCanvas
  mouseDrag : Boolean
GraffitiCanvas
  overlay : DisplayObject
[write-only] Display Object displayed above the drawing.
GraffitiCanvas
  underlay : DisplayObject
[write-only] Display Object displayed under the drawing.
GraffitiCanvas
  zoom : Number
GraffitiCanvas
Public Methods
 MethodDefined By
  
GraffitiCanvas(canvasWidth:uint = 100, canvasHeight:uint = 100, numberHistoryLevels:uint = 0, overlay:DisplayObject = null, underlay:DisplayObject = null)
The GraffitiCanvas constructor.
GraffitiCanvas
  
The clearCanvas method will clear the Canvas.
GraffitiCanvas
  
The clearHistory method will clear all history items.
GraffitiCanvas
  
drawing():BitmapData
The drawing method will return the bitmapdata object that captures the drawn canvas including any overlay or underlay assets.
GraffitiCanvas
  
drawToCanvas(asset:Object):void
The drawToCanvas method will draw a display object or bitmapdata object to the canvas.
GraffitiCanvas
  
fill(point:Point, color:uint):void
The fill method will flood fill an area of the drawing with the supplied color.
GraffitiCanvas
  
getColorAtPoint(point:Point, useEntireCanvas:Boolean = false):int
The getColorAtPoint method will return the color at a specific point on the drawing.
GraffitiCanvas
  
getViewableRect():Rectangle
The getViewableRect method will return a Rectangle defining the viewable area of the Canvas.
GraffitiCanvas
  
The nextHistory method will step forward and display the next item in the history.
GraffitiCanvas
  
The prevHistory method will step backwards and display the next item in the history.
GraffitiCanvas
  
setCanvasPos(pos:Point):void
The setCanvasPos method will change the position of the canvas.
GraffitiCanvas
Public Constants
 ConstantDefined By
  HISTORY_LENGTH_CHANGE : String = historyLengthChange
[static]
GraffitiCanvas
Property Detail
activeToolproperty
activeTool:ITool  [read-write]


Implementation
    public function get activeTool():ITool
    public function set activeTool(value:ITool):void
canvasEnabledproperty 
canvasEnabled:Boolean  [read-write]


Implementation
    public function get canvasEnabled():Boolean
    public function set canvasEnabled(value:Boolean):void
canvasHeightproperty 
canvasHeight:uint  [read-write]


Implementation
    public function get canvasHeight():uint
    public function set canvasHeight(value:uint):void
canvasWidthproperty 
canvasWidth:uint  [read-write]


Implementation
    public function get canvasWidth():uint
    public function set canvasWidth(value:uint):void
historyLengthproperty 
historyLength:uint  [read-only]

Get the current number of saved history items.


Implementation
    public function get historyLength():uint
historyPositionproperty 
historyPosition:uint  [read-only]

Get the current history position.


Implementation
    public function get historyPosition():uint
maxHistoryLengthproperty 
maxHistoryLength:uint  [read-only]

Get the maximum number of history items.


Implementation
    public function get maxHistoryLength():uint
maxZoomproperty 
maxZoom:Number  [read-only]

Maximum Zoom value.


Implementation
    public function get maxZoom():Number
minZoomproperty 
minZoom:Number  [read-only]

Minimum Zoom value.


Implementation
    public function get minZoom():Number
mouseDragproperty 
mouseDrag:Boolean  [read-write]


Implementation
    public function get mouseDrag():Boolean
    public function set mouseDrag(value:Boolean):void
overlayproperty 
overlay:DisplayObject  [write-only]

Display Object displayed above the drawing.


Implementation
    public function set overlay(value:DisplayObject):void
underlayproperty 
underlay:DisplayObject  [write-only]

Display Object displayed under the drawing.


Implementation
    public function set underlay(value:DisplayObject):void
zoomproperty 
zoom:Number  [read-write]


Implementation
    public function get zoom():Number
    public function set zoom(value:Number):void
Constructor Detail
GraffitiCanvas()Constructor
public function GraffitiCanvas(canvasWidth:uint = 100, canvasHeight:uint = 100, numberHistoryLevels:uint = 0, overlay:DisplayObject = null, underlay:DisplayObject = null)

The GraffitiCanvas constructor.

Parameters
canvasWidth:uint (default = 100) — Width of the canvas.
 
canvasHeight:uint (default = 100) — Height of the canvas.
 
numberHistoryLevels:uint (default = 0) — Max number of History items to keep, if 0 then no history is kept.
 
overlay:DisplayObject (default = null) — An optional DisplayObject that can be used as an overlay to the Canvas. DisplayObject should be partially transparent.
 
underlay:DisplayObject (default = null) — An optional DisplayObject that can be used as an underlay to the Canvas.

Example
The following code creates a Graffiti Canvas instance.
        package {
        
            import flash.display.Sprite;
            import com.nocircleno.graffiti.GraffitiCanvas;
            import com.nocircleno.graffiti.tools.BrushTool;
            import com.nocircleno.graffiti.tools.BrushType;
            
            public class Main extends Sprite {
                
                public function Main() {
                    
                    // create new instance of graffiti canvas, with a width and height of 400 and 10 history levels.
                    // by default a Brush instance is created inside the GraffitiCanvas Class and assigned as the active tool.
                    var canvas:GraffitiCanvas = new GraffitiCanvas(400, 400, 10);
                    addChild(canvas);
                    
                    // create a new BrushTool instance, brush size of 8, brush color is Red, fully opaque, no blur and Brush type is Backward line.
                    var angledBrush:BrushTool = new BrushTool(8, 0xFF0000, 1, 0, BrushType.BACKWARD_LINE);
                    
                    // assign the Brush as the active tool used by the Canvas
                    canvas.activeTool = angledBrush;
                    
                }
                
            }
        }
        
Method Detail
clearCanvas()method
public function clearCanvas():void

The clearCanvas method will clear the Canvas.

clearHistory()method 
public function clearHistory():void

The clearHistory method will clear all history items. the Canvas.

See also

drawing()method 
public function drawing():BitmapData

The drawing method will return the bitmapdata object that captures the drawn canvas including any overlay or underlay assets.

Returns
BitmapData — A BitmapData object containing the entire canvas.
drawToCanvas()method 
public function drawToCanvas(asset:Object):void

The drawToCanvas method will draw a display object or bitmapdata object to the canvas. This allows you to add an image that will be editable by the drawing engine.

Parameters

asset:Object — Image to write to canvas. Object must IBitmapDrawable. This includes MovieClips, Sprites, Bitmaps, BitmapData.

fill()method 
public function fill(point:Point, color:uint):void

The fill method will flood fill an area of the drawing with the supplied color. The fill DOES NOT take into account an overlay or underlayed image.

Parameters

point:Point — Point at which to flood fill with color.
 
color:uint — Color to fill with.

getColorAtPoint()method 
public function getColorAtPoint(point:Point, useEntireCanvas:Boolean = false):int

The getColorAtPoint method will return the color at a specific point on the drawing. If the point is out of bounds then -1 is returned.

Parameters

point:Point — Point to get color from.
 
useEntireCanvas:Boolean (default = false) — A Boolean value that specifies whether to include any overlay or underlay display objects when reading the color at the point specified.

Returns
int — Returns the color value at the point passed, returns -1 if point is outside of canvas dimensions.
getViewableRect()method 
public function getViewableRect():Rectangle

The getViewableRect method will return a Rectangle defining the viewable area of the Canvas.

Returns
Rectangle — A Rectangle object that represents the viewable are of the Canvas. If the canvas is zoomed all they way out then the dimensions of the Rectangle are same as the Canvas width and height.
nextHistory()method 
public function nextHistory():void

The nextHistory method will step forward and display the next item in the history.

See also

prevHistory()method 
public function prevHistory():void

The prevHistory method will step backwards and display the next item in the history.

See also

setCanvasPos()method 
public function setCanvasPos(pos:Point):void

The setCanvasPos method will change the position of the canvas.

Parameters

pos:Point — Point to move canvas to.

Constant Detail
HISTORY_LENGTH_CHANGEConstant
public static const HISTORY_LENGTH_CHANGE:String = historyLengthChange