Show:

CGSGScene Class

Extends Object
Defined in: src\class.scene.js:64
Module: Scene

Represent the scene of the application. It encapsulates the scene graph itself and several methods to track mouse and touch events, ...

Constructor

CGSGScene
(
  • canvas
)
Parameters:
  • canvas HTMLElement

    a handler to the canvas HTML element

Methods

_clickOnScene
(
  • event
  • mustPickNode
)
private
Parameters:
  • event Event

    MouseEvent or TouchEvent

  • mustPickNode Boolean
_dblClickOnScene
(
  • event
)
CGSGNode private
Parameters:
  • event Event
Returns:
CGSGNode: the node that was double-clicked
_doDragSelect () protected

Select the nodes under the drag select rectangle

_getDeltaOnMove
(
  • delta
  • nodeOffsetX
  • nodeOffsetY
  • w
  • h
  • signeX
  • signeY
)
Object private
Parameters:
Returns:
_moveOnScene
(
  • event
)
private
Parameters:
  • event Event

    MouseEvent or TouchEvent

_updateFramerate () private

Update the current framerate

_updateFramerateContainer () private

Update the innerHTML of the HTMLElement passed as parameter of the "showFPS" function

_upOnScene
(
  • event
)
private
Parameters:
  • event Event

    MouseEvent or TouchEvent

deleteSelected ()

Remove the nodes selected in the scene graph

deselectAll
(
  • excludedArray
)
public

Deselect all nodes

Parameters:
  • excludedArray Array

    CGSGNodes not to deselect

getDisplayRatio () CGSGScale public
Returns:
CGSGScale: the current display ratio
invalidate () public

Inform the SceneGraph that a new render is needed

onKeyDownHandler
(
  • event
)
Number protected
Parameters:
  • event KeyboardEvent
Returns:
onKeyUpHandler
(
  • event
)
Number protected
Parameters:
  • event KeyboardEvent
Returns:
onMouseDblClick
(
  • event
)
protected

mouse double click Event handler function

Parameters:
  • event MouseEvent
onMouseDown
(
  • event
)
protected

click mouse Event handler function

Parameters:
  • event MouseEvent
onMouseMove
(
  • event
)
protected

mouse move Event handler function

Parameters:
  • event MouseEvent
onMouseUp
(
  • event
)
protected

mouse up Event handler function

Parameters:
  • event MouseEvent
onTouchEnd
(
  • event
)
protected

touch up Event handler function

Parameters:
  • event Event
onTouchMove
(
  • event
)
protected

touch move Event handler function

Parameters:
  • event Event
onTouchStart
(
  • event
)
protected

touch down Event handler function

Parameters:
  • event Event
render () protected

the main rendering loop

setCanvasDimension
(
  • newDimension
)

Change the dimension of the canvas. Does not really change the dimension of the rendering canvas container, but is used by the different computations

Parameters:
setDisplayRatio
(
  • newRatio
)
public

Set the new value for the display ratio. The display ratio is used to resize all the elements on the graph to be adapted to the screen, depending on the reference screen size. You can compute the ratio like this: x = canvas.width/reference.width ; y = canvas.height/reference.height

Parameters:
showFPS
(
  • elt
)
public
Parameters:
  • elt HTMLElement

    an HTML element to receive the FPS. Can be null if you want to remove the framerate

startPlaying () public

Call this to start the update of the scene

stopPlaying () public

Call this to stop the rendering (and so animation) update

Properties

_frameContainer Handler to the HTML Element displaying the FPS HTMLElement private
_isRunning Boolean private
_keyDownedCtrl Boolean private

True if the [CTRL} key is being pressed

Default: false

_listCursors List of the names for the cursor when overring a handlebox Array private
_mousePosition Array private

Current positions of the mouse or touch (Array of CGSGPosition)

_selectedNode The current last selected node Null private
_timerDblTouch Number private

Default: null

allowMultiSelect Boolean

Multiselection boolean.

Default: true

cgsgGlobalRenderingTimer Number private

Provided by the Util module.

Defined in src\class.scene.js:28

Provides requestAnimationFrame in a cross browser way.

context CanvasRenderingContext2D
dblTouchDelay Number

The delay between 2 touches to be considered as a dbl touch event. To remove the double touch, just set it to 0

Default: CGSG_DEFAULT_DBLTOUCH_DELAY

dragSelectAlpha Number

Alpha value for the drag selection rectangle

Default: 0.6

dragSelectFillColor String

Fill color for the drag selection selection rectangle

Default: "#C0C0C0"

dragSelectStrokeColor String

Stroke color for the drag selection selection rectangle

Default: "#808080"

fps Number

Current framerate of the application

onRenderEnd Function

Callback on end rendering event

Default: null

Example:

this.onRenderEnd = function () { //... }

onRenderStart Function

Callback on start rendering event

Default: null

Example:

this.onSceneClickStart = function () { //... }

onSceneClickEnd Function

Callback on click up on scene event

Default: null

Example:

this.onSceneClickEnd = function (event) { event.position; //Array of CGSGPosition event.event; //Event }

onSceneClickStart Function

Callback on click down on scene event.

Default: null

Example:

this.onSceneClickStart = function (event) { event.position; //Array of CGSGPosition event.event; //Event }

onSceneDblClickEnd Function

Callback on double click up on scene event

Default: null

Example:

this.onSceneDblClickEnd = function (event) { event.position; //Array of CGSGPosition event.event; //Event }

onSceneDblClickStart Function

Callback on double click start on scene event

Default: null

Example:

this.onSceneDblClickStart = function (event) { event.position; //Array of CGSGPosition event.event; //Event }

sceneGraph CGSGSceneGraph

The scene graph itself

selectedNodes Array

List of the current selected nodes in the scenegraph.