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.
SceneGraph | Holds a scene organized as a graph of stroke layers. |
Public data members | |
name | Name of the scene, used as the class name in code generation. |
stroke | Currently selected stroke |
selectedIndex | Index of the currently selected stroke |
Private data members | |
strokes | General graph data structure used to hold the scene graph strokes. |
showTrace | 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 | Callback function called when the scene graph changes size |
onSelectedStrokeChange | Callback function called when the selected stroke changes |
onSelectedIndexChange | Callback function called when the selected stroke point changes |
Private traversal data | |
traverseFunctionCallback | Function callback holder used during graph traversal. |
traverseFunctionArgument | Function callback state object optionally used during graph traversal. |
mapResult | Array used to hold result of during map traversal |
Construction/ | |
SceneGraph | Create a new scene graph object with a default stroke. |
dispose | Dispose of all resources used or referenced in the instance. |
Callback method change | |
setSizeChangeCallback | Change the callback function called when the scene graph changes size |
setSelectionStrokeCallback | Change the callback function called when the selected stroke changes |
setSelectionIndexCallback | Change the callback function called when the selected stroke point changes |
Scene graph properties | |
root | Returns the scene graph root Stroke. |
length | Returns the number of strokes in the scene graph. |
isInViewTrace | Returns true if the scene is in view trace mode. |
Stroke creation | |
addStroke | Adds the Stroke to the scene graph as a child of the stroke at the given parentIndex. |
addDefaultSelectedStroke | Adds a default shape stroke to the scene graph and makes it the selected stroke. |
addDefaultStroke | Adds a default shape stroke to the scene graph. |
addDefaultPath | Adds a default path stroke to the scene graph. |
createDefaultStroke | Returns a shape stroke with default settings. |
createDefaultPath | Returns a path stroke with default settings. |
Stroke update | |
updateStrokeAt | Change the stroke stored at an index position. |
Stroke removal | |
removeStrokeAt | Remove the stroke with the given index. |
Stroke selection | |
selectStrokeAt | Change the selected stroke to the stroke with the given index. |
selectStrokeByName | Change the selected stroke to the stroke with the given asset shape name. |
Lookup methods | |
getStrokeAt | Finds the Stroke at the index position. |
getStrokeIndexByName | Finds the index of a Stroke with the shape asset name. |
indexOf | Finds the index of a Stroke in the scene graph. |
Parent/ | |
hasChildren | Check if the indexed stroke has any childred attached to it in the scene graph. |
updateParentChildTypeNames | Updates the Stroke class types for the stroke in the scene. |
Scene traversal | |
apply | Apply a function to each stroke in the scene. |
applyWrapperFunction | Internal wrapper used by apply to supply the Stroke stored at each GraphNode and the optional traverseFunctionArgument to the nodeFunction held in traverseFunctionCallback. |
map | Maps a function onto each stroke in the scene and return the results as an array. |
mapWrapperFunction | Internal wrapper used by map to supply the Stroke stored at each GraphNode and the optional traverseFunctionArgument to the nodeFunction held in traverseFunctionCallback. |
traverse | Positional scene traversal that applies a function to each stroke. |
traverseWrapperFunction | 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. |
treeTraverse | Internal traversal algorithm used by traverse. |
Display methods | |
render | Renders the strokes in the scene onto their display objects. |
showSelectedStroke | Show the selected stroke. |
hideSelectedStroke | Hide the selected stroke. |
hideControlViews | Store the control view states and hides the control points and indicators for all strokes. |
restoreControlViews | Restore the control points and indicators for all strokes to their state before a call to hideControlViews. |
viewTrace | When on shows all strokes semi-transparently in the background behind the selected layer. |
Query methods | |
hasGradients | Tests for use of a gradient in any strokes. |
hasPathStrokes | Tests for existence of path strokes. |
usesBevelFilter | Tests for use of a bevel filter in any strokes. |
usesBlurFilter | Tests for use of a blur filter in any strokes. |
usesShadowFilter | Tests for use of a drop shadow filter in any strokes. |
String conversion | |
toString | Returns information about the scene graph in a form suitable for debugging. |
private var traverseFunctionCallback: Function
Function callback holder used during graph traversal. See Scene traversal.
private var traverseFunctionArgument: Object
Function callback state object optionally used during graph traversal. See Scene traversal.
private var mapResult: Array
Array used to hold result of during map traversal
public function SceneGraph( onSizeChange: Function, onStrokeChange: Function, onSelectionChange: Function )
Create a new scene graph object with a default stroke.
onSizeChange | Callback function called when the scene graph changes size |
onStrokeChange | Callback function called when the selected stroke changes |
onSelectionChange | Callback function called when the selected stroke point changes |
onSizeChange | function sceneChangedSize(size:uint):void |
onStrokeChange | function sceneChangedSelectedStroke(stroke:Stroke):void |
onSelectionChange | function sceneChangedSelectedStrokePoint(index:int):void |
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.
newStroke | a new stroke to add to the scene |
parentIndex | a valid stroke index (default -1) |
Index of the added stroke
public function updateStrokeAt( updatedStroke: Stroke, index: int ):void
Change the stroke stored at an index position.
updatedStroke | new Stroke to store at the node index |
index | a valid stroke index |
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.
index | a valid stroke index |
public function getStrokeAt( index: int ):Stroke
Finds the Stroke at the index position.
index | a valid scene graph node index |
Reference to the found stroke or null if not found
public function getStrokeIndexByName( name: String ):int
Finds the index of a Stroke with the shape asset name.
name | a stroke asset name |
Found index of the stroke or -1 if not found
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.
aStroke | reference to stroke to search for |
Found index of the stroke or -1 if not found
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.
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.
nodeFunction | function that applies an operation on each stroke |
functionArgument | optional object that can keep state during the traversal (default null) |
startIndex | index of the stroke where the traversal begins (default root index 0) |
nodeFunction signature if functionArgument is null
nodeFunction signature if functionArgument is not null
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.
node | a GraphNode in the scene graph |
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.
nodeFunction | function that is returns a result when mapped onto each stroke |
functionArgument | optional object that can keep state during the traversal (default null) |
startIndex | index of the stroke where the traversal begins (default root index 0) |
Array with the results from each call to the nodeFunction
nodeFunction signature if functionArgument is null
nodeFunction signature if functionArgument is not null
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.
node | a GraphNode in the scene graph |
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).
nodeFunction | function that applies an operation on each stroke |
functionArgument | optional object that can keep state during the traversal (default null) |
startIndex | index of the stroke where the traversal begins (default root index 0) |
nodeFunction signature if functionArgument is null
nodeFunction signature if functionArgument is not null
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.
node | a GraphNode in the scene graph |
px | logical parent X index |
py | logical parent Y index |
x | logical node X index |
y | logical node Y index |
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.
node | The starting graph node. |
process | A function to apply to each traversed node. |
px | parent X position |
py | parent Y position |
x | node X position |
y | node Y position |
node sibling extent
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. When off only the selected stroke is shown.
The implementation is experimental and requires further work to
state | True turns trace view on, false turns it off |
Name of the scene, used as the class name in code generation.
public var name: String
Currently selected stroke
public var stroke: Stroke
Index of the currently selected stroke
public var selectedIndex: int
General graph data structure used to hold the scene graph strokes.
private var strokes: Graph
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 showTrace: Boolean
Callback function called when the scene graph changes size
private var onGraphSizeChange: Function
Callback function called when the selected stroke changes
private var onSelectedStrokeChange: Function
Callback function called when the selected stroke point changes
private var onSelectedIndexChange: Function
Function callback holder used during graph traversal.
private var traverseFunctionCallback: Function
Function callback state object optionally used during graph traversal.
private var traverseFunctionArgument: Object
Array used to hold result of during map traversal
private var mapResult: Array
Maps a function onto each stroke in the scene and return the results as an array.
public function map( nodeFunction: Function, functionArgument: Object = null, startIndex: int = 0 ):Array
Create a new scene graph object with a default stroke.
public function SceneGraph( onSizeChange: Function, onStrokeChange: Function, onSelectionChange: Function )
Dispose of all resources used or referenced in the instance.
public function dispose():void
Change the callback function called when the scene graph changes size
public function setSizeChangeCallback( onSizeChangeCallback: Function ):void
Change the callback function called when the selected stroke changes
public function setSelectionStrokeCallback( onSelectionStrokeCallback: Function ):void
Change the callback function called when the selected stroke point changes
public function setSelectionIndexCallback( onSelectionIndexCallback: Function ):void
Returns the scene graph root Stroke.
public function get root():Stroke
Returns the number of strokes in the scene graph.
public function get length():int
Returns true if the scene is in view trace mode.
public function get isInViewTrace():Boolean
Adds the Stroke to the scene graph as a child of the stroke at the given parentIndex.
private function addStroke( newStroke: Stroke, parentIndex: int = -1 ):int
Adds a default shape stroke to the scene graph and makes it the selected stroke.
public function addDefaultSelectedStroke( parentIndex: int ):Stroke
Adds a default shape stroke to the scene graph.
public function addDefaultStroke( parentIndex: int ):int
Adds a default path stroke to the scene graph.
public function addDefaultPath( parentIndex: int ):int
Returns a shape stroke with default settings.
public function createDefaultStroke():Stroke
Returns a path stroke with default settings.
public function createDefaultPath():Stroke
Change the stroke stored at an index position.
public function updateStrokeAt( updatedStroke: Stroke, index: int ):void
Remove the stroke with the given index.
public function removeStrokeAt( index: int ):void
Change the selected stroke to the stroke with the given index.
public function selectStrokeAt( index: int ):Stroke
Change the selected stroke to the stroke with the given asset shape name.
public function selectStrokeByName( name: String ):Stroke
Finds the Stroke at the index position.
public function getStrokeAt( index: int ):Stroke
Finds the index of a Stroke with the shape asset name.
public function getStrokeIndexByName( name: String ):int
Finds the index of a Stroke in the scene graph.
public function indexOf( aStroke: Stroke ):int
Check if the indexed stroke has any childred attached to it in the scene graph.
public function hasChildren( index: int ):Boolean
Updates the Stroke class types for the stroke in the scene.
public function updateParentChildTypeNames():void
Apply a function to each stroke in the scene.
public function apply( nodeFunction: Function, functionArgument: Object = null, startIndex: int = 0 ):void
Internal wrapper used by apply to supply the Stroke stored at each GraphNode and the optional traverseFunctionArgument to the nodeFunction held in traverseFunctionCallback.
private function applyWrapperFunction( 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.
private function mapWrapperFunction( node: GraphNode ):void
Positional scene traversal that applies a function to each stroke.
public function traverse( nodeFunction: Function, functionArgument: Object = null, startIndex: int = 0 ):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 traverseWrapperFunction( node: GraphNode, px: int, py: int, x: int, y: int ):void
Internal traversal algorithm used by traverse.
private function treeTraverse( node: GraphNode, process: Function, px: int, py: int, x: int, y: int ):int
Renders the strokes in the scene onto their display objects.
public function render():void
Show the selected stroke.
private function showSelectedStroke():void
Hide the selected stroke.
private function hideSelectedStroke():void
Store the control view states and hides the control points and indicators for all strokes.
public function hideControlViews():void
Restore the control points and indicators for all strokes to their state before a call to hideControlViews.
public function restoreControlViews():void
When on shows all strokes semi-transparently in the background behind the selected layer.
public function viewTrace( state: Boolean ):void
Tests for use of a gradient in any strokes.
public function hasGradients():Boolean
Tests for existence of path strokes.
public function hasPathStrokes():Boolean
Tests for use of a bevel filter in any strokes.
public function usesBevelFilter():Boolean
Tests for use of a blur filter in any strokes.
public function usesBlurFilter():Boolean
Tests for use of a drop shadow filter in any strokes.
public function usesShadowFilter():Boolean
Returns information about the scene graph in a form suitable for debugging.
public function toString():String