SceneGraph

Holds a scene organized as a graph of stroke layers.

While a general graph is used as the internal representation, only a tree with root at the first node is currently used.  The reason to use a graph is so that future extensions can be implemented without changing the fundamental data structure.  For example to allow a branch of layers to be reused without duplicating the data.

Summary
SceneGraphHolds a scene organized as a graph of stroke layers.
Public data members
nameName of the scene, used as the class name in code generation.
strokeCurrently selected stroke
selectedIndexIndex of the currently selected stroke
Private data members
strokesGeneral graph data structure used to hold the scene graph strokes.
showTraceTrue when trace view is in effect, that is when layers that are not selected are set to be displayed semi-transparently behind the selected layer.
Private callback functions
onGraphSizeChangeCallback function called when the scene graph changes size
onSelectedStrokeChangeCallback function called when the selected stroke changes
onSelectedIndexChangeCallback function called when the selected stroke point changes
Private traversal data
traverseFunctionCallbackFunction callback holder used during graph traversal.
traverseFunctionArgumentFunction callback state object optionally used during graph traversal.
mapResultArray used to hold result of during map traversal
Construction/destruction
SceneGraphCreate a new scene graph object with a default stroke.
disposeDispose of all resources used or referenced in the instance.
Callback method change
setSizeChangeCallbackChange the callback function called when the scene graph changes size
setSelectionStrokeCallbackChange the callback function called when the selected stroke changes
setSelectionIndexCallbackChange the callback function called when the selected stroke point changes
Scene graph properties
rootReturns the scene graph root Stroke.
lengthReturns the number of strokes in the scene graph.
isInViewTraceReturns true if the scene is in view trace mode.
Stroke creation
addStrokeAdds the Stroke to the scene graph as a child of the stroke at the given parentIndex.
addDefaultSelectedStrokeAdds a default shape stroke to the scene graph and makes it the selected stroke.
addDefaultStrokeAdds a default shape stroke to the scene graph.
addDefaultPathAdds a default path stroke to the scene graph.
createDefaultStrokeReturns a shape stroke with default settings.
createDefaultPathReturns a path stroke with default settings.
Stroke update
updateStrokeAtChange the stroke stored at an index position.
Stroke removal
removeStrokeAtRemove the stroke with the given index.
Stroke selection
selectStrokeAtChange the selected stroke to the stroke with the given index.
selectStrokeByNameChange the selected stroke to the stroke with the given asset shape name.
Lookup methods
getStrokeAtFinds the Stroke at the index position.
getStrokeIndexByNameFinds the index of a Stroke with the shape asset name.
indexOfFinds the index of a Stroke in the scene graph.
Parent/child methods
hasChildrenCheck if the indexed stroke has any childred attached to it in the scene graph.
updateParentChildTypeNamesUpdates the Stroke class types for the stroke in the scene.
Scene traversal
applyApply a function to each stroke in the scene.
applyWrapperFunctionInternal wrapper used by apply to supply the Stroke stored at each GraphNode and the optional traverseFunctionArgument to the nodeFunction held in traverseFunctionCallback.
mapMaps a function onto each stroke in the scene and return the results as an array.
mapWrapperFunctionInternal wrapper used by map to supply the Stroke stored at each GraphNode and the optional traverseFunctionArgument to the nodeFunction held in traverseFunctionCallback.
traversePositional scene traversal that applies a function to each stroke.
traverseWrapperFunctionInternal wrapper used by traverse to supply the Stroke stored at each GraphNode, the optional traverseFunctionArgument and positional indexes to the nodeFunction held in traverseFunctionCallback.
treeTraverseInternal traversal algorithm used by traverse.
Display methods
renderRenders the strokes in the scene onto their display objects.
showSelectedStrokeShow the selected stroke.
hideSelectedStrokeHide the selected stroke.
hideControlViewsStore the control view states and hides the control points and indicators for all strokes.
restoreControlViewsRestore the control points and indicators for all strokes to their state before a call to hideControlViews.
viewTraceWhen on shows all strokes semi-transparently in the background behind the selected layer.
Query methods
hasGradientsTests for use of a gradient in any strokes.
hasPathStrokesTests for existence of path strokes.
usesBevelFilterTests for use of a bevel filter in any strokes.
usesBlurFilterTests for use of a blur filter in any strokes.
usesShadowFilterTests for use of a drop shadow filter in any strokes.
String conversion
toStringReturns information about the scene graph in a form suitable for debugging.

Public data members

name

public var name: String

Name of the scene, used as the class name in code generation.

stroke

public var stroke: Stroke

Currently selected stroke

selectedIndex

public var selectedIndex: int

Index of the currently selected stroke

Private data members

strokes

private var strokes: Graph

General graph data structure used to hold the scene graph strokes.

showTrace

private var showTrace: Boolean

True when trace view is in effect, that is when layers that are not selected are set to be displayed semi-transparently behind the selected layer.

Private callback functions

onGraphSizeChange

private var onGraphSizeChange: Function

Callback function called when the scene graph changes size

onSelectedStrokeChange

private var onSelectedStrokeChange: Function

Callback function called when the selected stroke changes

onSelectedIndexChange

private var onSelectedIndexChange: Function

Callback function called when the selected stroke point changes

Private traversal data

traverseFunctionCallback

private var traverseFunctionCallback: Function

Function callback holder used during graph traversal.  See Scene traversal.

traverseFunctionArgument

private var traverseFunctionArgument: Object

Function callback state object optionally used during graph traversal.  See Scene traversal.

mapResult

private var mapResult: Array

Array used to hold result of during map traversal

Construction/destruction

SceneGraph

public function SceneGraph(onSizeChange: Function,
onStrokeChange: Function,
onSelectionChange: Function)

Create a new scene graph object with a default stroke.

Parameters

onSizeChangeCallback function called when the scene graph changes size
onStrokeChangeCallback function called when the selected stroke changes
onSelectionChangeCallback function called when the selected stroke point changes

Callbacks

onSizeChangefunction sceneChangedSize(size:uint):void
onStrokeChangefunction sceneChangedSelectedStroke(stroke:Stroke):void
onSelectionChangefunction sceneChangedSelectedStrokePoint(index:int):void

dispose

public function dispose():void

Dispose of all resources used or referenced in the instance.

Callback method change

setSizeChangeCallback

public function setSizeChangeCallback(onSizeChangeCallback: Function):void

Change the callback function called when the scene graph changes size

Callbacks

onSizeChangeCallbackfunction sceneChangedSize(size:uint):void

setSelectionStrokeCallback

public function setSelectionStrokeCallback(
   onSelectionStrokeCallback: Function
):void

Change the callback function called when the selected stroke changes

Callbacks

onSelectionStrokeCallbackfunction sceneChangedSelectedStroke(stroke:Stroke):void

setSelectionIndexCallback

public function setSelectionIndexCallback(
   onSelectionIndexCallback: Function
):void

Change the callback function called when the selected stroke point changes

Callbacks

onSelectionIndexCallbackfunction sceneChangedSelectedStrokePoint(index:int):void

Scene graph properties

root

public function get root():Stroke

Returns the scene graph root Stroke.  That is the Stroke at index 0.

length

public function get length():int

Returns the number of strokes in the scene graph.

isInViewTrace

public function get isInViewTrace():Boolean

Returns true if the scene is in view trace mode.

Stroke creation

addStroke

private function addStroke(newStroke: Stroke,  
parentIndex: int = -1):int

Adds the Stroke to the scene graph as a child of the stroke at the given parentIndex.

A parentIndex of -1 can only be used to add the root node stroke to the scene graph.

Parameters

newStrokea new stroke to add to the scene
parentIndexa valid stroke index (default -1)

Returns

Index of the added stroke

addDefaultSelectedStroke

public function addDefaultSelectedStroke(parentIndex: int):Stroke

Adds a default shape stroke to the scene graph and makes it the selected stroke.

Parameters

parentIndexa valid stroke index

Returns

Reference to the selected stroke

addDefaultStroke

public function addDefaultStroke(parentIndex: int):int

Adds a default shape stroke to the scene graph.

Parameters

parentIndexa valid stroke index

Returns

Index of the added stroke

addDefaultPath

public function addDefaultPath(parentIndex: int):int

Adds a default path stroke to the scene graph.

Parameters

parentIndexa valid stroke index

Returns

Index of the added stroke

createDefaultStroke

public function createDefaultStroke():Stroke

Returns a shape stroke with default settings.  The stroke is not inserted into the scene graph.

createDefaultPath

public function createDefaultPath():Stroke

Returns a path stroke with default settings.  The stroke is not inserted into the scene graph.

Stroke update

updateStrokeAt

public function updateStrokeAt(updatedStroke: Stroke,
index: int):void

Change the stroke stored at an index position.

Parameters

updatedStrokenew Stroke to store at the node index
indexa valid stroke index

Stroke removal

removeStrokeAt

public function removeStrokeAt(index: int):void

Remove the stroke with the given index.

If the stroke to be deleted is the selected stroke then the caller should change the selected stroke before calling this method.

The parent child arcs are removed and the graph is reorganized to remove the null graph node.

Note that the GraphNode code has been fixed so arcs are actually removed.

Parameters

indexa valid stroke index

Stroke selection

selectStrokeAt

public function selectStrokeAt(index: int):Stroke

Change the selected stroke to the stroke with the given index.

Parameters

indexa valid stroke index

Returns

A reference to the selected stroke

selectStrokeByName

public function selectStrokeByName(name: String):Stroke

Change the selected stroke to the stroke with the given asset shape name.

Parameters

namea valid stroke asset name

Returns

A reference to the selected stroke

Lookup methods

getStrokeAt

public function getStrokeAt(index: int):Stroke

Finds the Stroke at the index position.

Parameters

indexa valid scene graph node index

Returns

Reference to the found stroke or null if not found

getStrokeIndexByName

public function getStrokeIndexByName(name: String):int

Finds the index of a Stroke with the shape asset name.

Parameters

namea stroke asset name

Returns

Found index of the stroke or -1 if not found

indexOf

public function indexOf(aStroke: Stroke):int

Finds the index of a Stroke in the scene graph.  The index for a stroke can change as strokes are added and removed from the graph.  Only root is guaranteed to stay at index 0.

Parameters

aStrokereference to stroke to search for

Returns

Found index of the stroke or -1 if not found

Parent/child methods

hasChildren

public function hasChildren(index: int):Boolean

Check if the indexed stroke has any childred attached to it in the scene graph.

Parameters

indexa valid scene graph index

Returns

True if it has children, false otherwise

updateParentChildTypeNames

public function updateParentChildTypeNames():void

Updates the Stroke class types for the stroke in the scene.  A stroke node may change from being of a shape to a sprite class type or back when child strokes are added or removed.

The primary use of this is to ensure that code generated for strokes can take advantage of the most light-weight display object representation.

The current implementation assumes that child strokes only has one parent, so currently the same stroke can not be reused in multiple places in the scene.

Scene traversal

apply

public function apply(nodeFunction: Function,  
functionArgument: Object = null,
startIndex: int = 0):void

Apply a function to each stroke in the scene.  The traversal is in depth-first order and defaults to start at the root.

Parameters

nodeFunctionfunction that applies an operation on each stroke
functionArgumentoptional object that can keep state during the traversal (default null)
startIndexindex of the stroke where the traversal begins (default root index 0)

Callbacks

nodeFunction signature if functionArgument is null

  • function applyFunction(stroke:Stroke):void

nodeFunction signature if functionArgument is not null

  • function applyFunction(stroke:Stroke, arg:Object):void

applyWrapperFunction

private function applyWrapperFunction(node: GraphNode):void

Internal wrapper used by apply to supply the Stroke stored at each GraphNode and the optional traverseFunctionArgument to the nodeFunction held in traverseFunctionCallback.

Parameters

nodea GraphNode in the scene graph

map

public function map(nodeFunction: Function,  
functionArgument: Object = null,
startIndex: int = 0):Array

Maps a function onto each stroke in the scene and return the results as an array.  The traversal is in depth-first order and defaults to start at the root.

Parameters

nodeFunctionfunction that is returns a result when mapped onto each stroke
functionArgumentoptional object that can keep state during the traversal (default null)
startIndexindex of the stroke where the traversal begins (default root index 0)

Returns

Array with the results from each call to the nodeFunction

Callbacks

nodeFunction signature if functionArgument is null

  • function f(stroke:Stroke):*

nodeFunction signature if functionArgument is not null

  • function f(stroke:Stroke, arg:Object):*

mapWrapperFunction

private function mapWrapperFunction(node: GraphNode):void

Internal wrapper used by map to supply the Stroke stored at each GraphNode and the optional traverseFunctionArgument to the nodeFunction held in traverseFunctionCallback.

Stores the result from the call to the traverseFunctionCallback onto the mapResult array.

Parameters

nodea GraphNode in the scene graph

traverse

public function traverse(nodeFunction: Function,  
functionArgument: Object = null,
startIndex: int = 0):void

Positional scene traversal that applies a function to each stroke.  The traversal defaults to start at the root.  The traversal is performed as if the graph was a tree and keeps track of the parent/child positions.

The positional parameters supplied to the nodeFunction are logical indexes as if the nodes were mapped onto a 2-D grid with children in the X and siblings in the Y dimensions.  Root is at (0, 0).

Parameters

nodeFunctionfunction that applies an operation on each stroke
functionArgumentoptional object that can keep state during the traversal (default null)
startIndexindex of the stroke where the traversal begins (default root index 0)

Callbacks

nodeFunction signature if functionArgument is null

  • function f(stroke:Stroke, parentx:int, parenty:int, x:int, y:int):void

nodeFunction signature if functionArgument is not null

  • function f(stroke:Stroke, arg:Object, parentx:int, parenty:int, x:int, y:int):void

traverseWrapperFunction

private function traverseWrapperFunction(node: GraphNode,
px: int,
py: int,
x: int,
y: int):void

Internal wrapper used by traverse to supply the Stroke stored at each GraphNode, the optional traverseFunctionArgument and positional indexes to the nodeFunction held in traverseFunctionCallback.

Parameters

nodea GraphNode in the scene graph
pxlogical parent X index
pylogical parent Y index
xlogical node X index
ylogical node Y index

treeTraverse

private function treeTraverse(node: GraphNode,
process: Function,
px: int,
py: int,
x: int,
y: int):int

Internal traversal algorithm used by traverse.  Performs a depth-first recursive traversal on the graph as if it was a tree.  It keeps track of the position of the nodes in an imaginary 2-D grid with children in the X and siblings in the Y dimension.

Parameters

nodeThe starting graph node.
processA function to apply to each traversed node.
pxparent X position
pyparent Y position
xnode X position
ynode Y position

Returns

node sibling extent

Display methods

render

public function render():void

Renders the strokes in the scene onto their display objects.

showSelectedStroke

private function showSelectedStroke():void

Show the selected stroke.  If trace view is on then the stroke and its controls are restored.

hideSelectedStroke

private function hideSelectedStroke():void

Hide the selected stroke.  If trace view is on then the stroke is dimmed and its controls are hidden.

hideControlViews

public function hideControlViews():void

Store the control view states and hides the control points and indicators for all strokes.

restoreControlViews

public function restoreControlViews():void

Restore the control points and indicators for all strokes to their state before a call to hideControlViews.

viewTrace

public function viewTrace(state: Boolean):void

When on shows all strokes semi-transparently in the background behind the selected layer.  When off only the selected stroke is shown.

The implementation is experimental and requires further work to

  • Offset strokes according to their coordinate systems
  • Take stroke position, scale and rotation into account
  • Render background stroke in the scene graph order

Parameters

stateTrue turns trace view on, false turns it off

Query methods

hasGradients

public function hasGradients():Boolean

Tests for use of a gradient in any strokes.

Returns

True if found, false otherwise.

hasPathStrokes

public function hasPathStrokes():Boolean

Tests for existence of path strokes.

Returns

True if found, false otherwise.

usesBevelFilter

public function usesBevelFilter():Boolean

Tests for use of a bevel filter in any strokes.

Returns

True if found, false otherwise.

usesBlurFilter

public function usesBlurFilter():Boolean

Tests for use of a blur filter in any strokes.

Returns

True if found, false otherwise.

usesShadowFilter

public function usesShadowFilter():Boolean

Tests for use of a drop shadow filter in any strokes.

Returns

True if found, false otherwise.

String conversion

toString

public function toString():String

Returns information about the scene graph in a form suitable for debugging.

public var name: String
Name of the scene, used as the class name in code generation.
public var stroke: Stroke
Currently selected stroke
public var selectedIndex: int
Index of the currently selected stroke
private var strokes: Graph
General graph data structure used to hold the scene graph strokes.
private var showTrace: Boolean
True when trace view is in effect, that is when layers that are not selected are set to be displayed semi-transparently behind the selected layer.
private var onGraphSizeChange: Function
Callback function called when the scene graph changes size
private var onSelectedStrokeChange: Function
Callback function called when the selected stroke changes
private var onSelectedIndexChange: Function
Callback function called when the selected stroke point changes
private var traverseFunctionCallback: Function
Function callback holder used during graph traversal.
private var traverseFunctionArgument: Object
Function callback state object optionally used during graph traversal.
private var mapResult: Array
Array used to hold result of during map traversal
public function map(nodeFunction: Function,  
functionArgument: Object = null,
startIndex: int = 0):Array
Maps a function onto each stroke in the scene and return the results as an array.
public function SceneGraph(onSizeChange: Function,
onStrokeChange: Function,
onSelectionChange: Function)
Create a new scene graph object with a default stroke.
public function dispose():void
Dispose of all resources used or referenced in the instance.
public function setSizeChangeCallback(onSizeChangeCallback: Function):void
Change the callback function called when the scene graph changes size
public function setSelectionStrokeCallback(
   onSelectionStrokeCallback: Function
):void
Change the callback function called when the selected stroke changes
public function setSelectionIndexCallback(
   onSelectionIndexCallback: Function
):void
Change the callback function called when the selected stroke point changes
public function get root():Stroke
Returns the scene graph root Stroke.
Defines a stroke object consisting of curves, line segments and primitive graphics objects.
public function get length():int
Returns the number of strokes in the scene graph.
public function get isInViewTrace():Boolean
Returns true if the scene is in view trace mode.
private function addStroke(newStroke: Stroke,  
parentIndex: int = -1):int
Adds the Stroke to the scene graph as a child of the stroke at the given parentIndex.
public function addDefaultSelectedStroke(parentIndex: int):Stroke
Adds a default shape stroke to the scene graph and makes it the selected stroke.
public function addDefaultStroke(parentIndex: int):int
Adds a default shape stroke to the scene graph.
public function addDefaultPath(parentIndex: int):int
Adds a default path stroke to the scene graph.
public function createDefaultStroke():Stroke
Returns a shape stroke with default settings.
public function createDefaultPath():Stroke
Returns a path stroke with default settings.
public function updateStrokeAt(updatedStroke: Stroke,
index: int):void
Change the stroke stored at an index position.
public function removeStrokeAt(index: int):void
Remove the stroke with the given index.
public function selectStrokeAt(index: int):Stroke
Change the selected stroke to the stroke with the given index.
public function selectStrokeByName(name: String):Stroke
Change the selected stroke to the stroke with the given asset shape name.
public function getStrokeAt(index: int):Stroke
Finds the Stroke at the index position.
public function getStrokeIndexByName(name: String):int
Finds the index of a Stroke with the shape asset name.
public function indexOf(aStroke: Stroke):int
Finds the index of a Stroke in the scene graph.
public function hasChildren(index: int):Boolean
Check if the indexed stroke has any childred attached to it in the scene graph.
public function updateParentChildTypeNames():void
Updates the Stroke class types for the stroke in the scene.
public function apply(nodeFunction: Function,  
functionArgument: Object = null,
startIndex: int = 0):void
Apply a function to each stroke in the scene.
private function applyWrapperFunction(node: GraphNode):void
Internal wrapper used by apply to supply the Stroke stored at each GraphNode and the optional traverseFunctionArgument to the nodeFunction held in traverseFunctionCallback.
A graph node.
private function mapWrapperFunction(node: GraphNode):void
Internal wrapper used by map to supply the Stroke stored at each GraphNode and the optional traverseFunctionArgument to the nodeFunction held in traverseFunctionCallback.
public function traverse(nodeFunction: Function,  
functionArgument: Object = null,
startIndex: int = 0):void
Positional scene traversal that applies a function to each stroke.
private function traverseWrapperFunction(node: GraphNode,
px: int,
py: int,
x: int,
y: int):void
Internal wrapper used by traverse to supply the Stroke stored at each GraphNode, the optional traverseFunctionArgument and positional indexes to the nodeFunction held in traverseFunctionCallback.
private function treeTraverse(node: GraphNode,
process: Function,
px: int,
py: int,
x: int,
y: int):int
Internal traversal algorithm used by traverse.
public function render():void
Renders the strokes in the scene onto their display objects.
private function showSelectedStroke():void
Show the selected stroke.
private function hideSelectedStroke():void
Hide the selected stroke.
public function hideControlViews():void
Store the control view states and hides the control points and indicators for all strokes.
public function restoreControlViews():void
Restore the control points and indicators for all strokes to their state before a call to hideControlViews.
public function viewTrace(state: Boolean):void
When on shows all strokes semi-transparently in the background behind the selected layer.
public function hasGradients():Boolean
Tests for use of a gradient in any strokes.
public function hasPathStrokes():Boolean
Tests for existence of path strokes.
public function usesBevelFilter():Boolean
Tests for use of a bevel filter in any strokes.
public function usesBlurFilter():Boolean
Tests for use of a blur filter in any strokes.
public function usesShadowFilter():Boolean
Tests for use of a drop shadow filter in any strokes.
public function toString():String
Returns information about the scene graph in a form suitable for debugging.
Close