Class Index | File Index

Classes


Class Stack


Defined in: stack.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Stack()
Stack holds all the figures on the screen It will also hold the groups formed on the screen
Field Summary
Field Attributes Field Name and Description
 
Keeps current generated Id.
 
Keeps all the figures on the canvas
 
Keeps all the groups in the canvas
 
Keeps a map like (figure Id, figure index).
 
Type used in serialization
Method Summary
Method Attributes Method Name and Description
 
equals(anotherStack)
See if this stack is equal to another.
 
figureAdd(figure)
Adds a figure to the Stack of figures
 
Returns all figures from a group
 
Returns a figure by id
 
Returns the Figure's id if there is a figure for the given coordinates It will return the first figure we found from top to bottom (Z-order)
 
Returns all figures ids from a group
 
Test if an (x,y) is over a figure
 
 
Removes a figure by it's id
 
Generates an returns a new unique ID
 
getIndex(figure)
Find the storage index of a figure
 
groupCreate(figureIds)
Creates a {Group} based on a set of figure IDs
 
groupDestroy(groupId)
Destroy a group by it's Id Also remove the figures from group (figure.groupId = -1)
 
groupGetById(groupId)
Finds a {Group} by it's id
<static>  
Stack.load(o)
Creates a {Stack} out of JSON parsed object
 
paint(context)
Paints all {Figure}s from back to top (Z order)
 
Recreates the index (id, index)
 
Deletes all the figure and reset any index
 
setPosition(figureId, newPosition)
Insert a figure into a position and shifts all other figures Used by moveToBack and moveToFront, sets the selected figure to the selected position, and rotates all other figures away
 
setPosition_deprecated(figure, position)
 
swapToPosition(figureId, newPosition)
Sets the new z position of a currently selected figure (if present) It actually swap figures.
 
Convert all stack to SVG representation
Class Detail
Stack()
Stack holds all the figures on the screen It will also hold the groups formed on the screen
Field Detail
currentId
Keeps current generated Id. Not for direct access

figures
Keeps all the figures on the canvas

groups
Keeps all the groups in the canvas

idToIndex
Keeps a map like (figure Id, figure index). It is similar to an index

oType
Type used in serialization
Method Detail
{Boolean} equals(anotherStack)
See if this stack is equal to another. It is a shallow compare.
Parameters:
{Stack} anotherStack
- the other stack object
Returns:
{Boolean} - true if equals, false otherwise

figureAdd(figure)
Adds a figure to the Stack of figures
Parameters:
{Figure} figure
- the figure to add

{Array} figureGetByGroupId(groupId)
Returns all figures from a group
Parameters:
{Number} groupId
- the id of the group
Returns:
{Array} - the {Array} of {Figure}s that belong to the group

{Figure} figureGetById(id)
Returns a figure by id
Parameters:
{Number} id
- the id of the figure
Returns:
{Figure} - the figure object or null if no figure with that id found TODO: use idToIndex to speed up the search....well there is no search at all :)

{Number} figureGetByXY(x, y)
Returns the Figure's id if there is a figure for the given coordinates It will return the first figure we found from top to bottom (Z-order)
Author: Alex Gheorghiu .
Parameters:
{Number} x
- the value on Ox axis
{Number} y
- the value on Ox axis
Returns:
{Number} - the id of the figure or -1 if none found

{Array} figureGetIdsByGroupId(groupId)
Returns all figures ids from a group
Parameters:
{Number} groupId
- the id of the group
Returns:
{Array} - the {Array} of {Number}s that belong to the group

{Boolean} figureIsOver(x, y)
Test if an (x,y) is over a figure
Parameters:
{Number} x
- the x coordinates
{Number} y
- the y coordinates
Returns:
{Boolean} - true if over a figure, false otherwise

figureRemove_deprecated(figure)
Parameters:
figure

figureRemoveById(figId)
Removes a figure by it's id
Author: Alex Gheorghiu .
Parameters:
{Number} figId
- the {Figure}'s id

{Number} generateId()
Generates an returns a new unique ID
Returns:
{Number} - next id

{Number} getIndex(figure)
Find the storage index of a figure
Parameters:
{Figure} figure
- the figure you search for
Returns:
{Number} - the index where you can find the Figure or -1 if not founded

{Number} groupCreate(figureIds)
Creates a {Group} based on a set of figure IDs
Parameters:
{Array} figureIds
- all the ids of {Figure}s
Returns:
{Number} - the id of newly created Group

groupDestroy(groupId)
Destroy a group by it's Id Also remove the figures from group (figure.groupId = -1)
Parameters:
{Number} groupId
- the id of the group

{Group} groupGetById(groupId)
Finds a {Group} by it's id
Parameters:
{Number} groupId
- the {Group}'s id
Returns:
{Group} founded group of null if none finded

<static> {Stack} Stack.load(o)
Creates a {Stack} out of JSON parsed object
Author: Alex Gheorghiu .
Parameters:
{JSONObject} o
- the JSON parsed object
Returns:
{Stack} a newly constructed Stack

paint(context)
Paints all {Figure}s from back to top (Z order)
Parameters:
{Context} context
- the 2D context

reindex()
Recreates the index (id, index)
Author: Alex Gheorghiu .

reset()
Deletes all the figure and reset any index

setPosition(figureId, newPosition)
Insert a figure into a position and shifts all other figures Used by moveToBack and moveToFront, sets the selected figure to the selected position, and rotates all other figures away
Author: Zack Newsham.
[0] = 0
[1] = 1
[2] = 2

change to
[0] = 1
[1] = 2
[2] = 0
figureA
figureB
figureC

change to
figureB
figureC
figureA
Parameters:
{Number} figureId
- the id of the figure
{Number} newPosition
- the new position of the figure

setPosition_deprecated(figure, position)
Parameters:
figure
position

swapToPosition(figureId, newPosition)
Sets the new z position of a currently selected figure (if present) It actually swap figures.

Note: it's just a simple switch between current position and new position

Zack: Is it just a switch? All you are doing is swapping, what if the user didn't want to swap, but shift up using this method, if you have 5 figures, and bring the very back one to the front, the front figure is moved to the very back, surely the correct solution is to move everything back 1, and move the selected figure to the front

Alex: What you are saying is an insert at a certain position which is not what we want with this method. Maybe we should rename it swapToPosition(...) or swapIntoPosition(...)


Author: Alex Gheorghiu .

Parameters:
{Number} figureId
- the id of the {Figure}
{Number} newPosition
- the new Z index of the figure. The bigger the value, close to user (last painted);

{String} toSVG()
Convert all stack to SVG representation
Returns:
{String} - the SVG string representation

Documentation generated by JsDoc Toolkit 2.4.0 on Thu Jun 09 2011 12:47:26 GMT+0300 (EEST)