Class SpiderGL.UserInterface.CanvasHandler
The SpiderGL.UserInterface.CanvasHandler is an event handler used to implement an easy controller for WebGL canvas. It should not be directly used.
- Defined in: ui.js
- Extends SpiderGL.Core.ObjectBase
Constructor Attributes | Constructor Name and Description |
---|---|
SpiderGL.UserInterface.CanvasHandler(gl, handler, options)
Creates a SpiderGL.UserInterface.CanvasHandler.
|
Field Attributes | Field Name and Description |
---|---|
<readonly> |
Gets the elapsed time, in milliseconds, between the last and the current onAnimate event.
|
<readonly> |
Gets the time, in seconds, of the last onAnimate event.
|
Gets/Sets the frequency (calls per second) used to emit the onAnimate event.
|
|
<readonly> |
Gets the time, in seconds, of the current onAnimate event.
|
<readonly> |
Gets the associated canvas.
|
Gets the difference between the current and the previous cursor x position, relative to the canvas lower left corner.
|
|
Gets the difference between the current and the previous cursor y position, relative to the canvas lower left corner.
|
|
Gets the previous cursor x position, relative to the canvas lower left corner.
|
|
Gets the previous cursor y position, relative to the canvas lower left corner.
|
|
Gets the cursor x position, relative to the canvas lower left corner.
|
|
Gets the cursor y position, relative to the canvas lower left corner.
|
|
<static> |
SpiderGL.UserInterface.CanvasHandler.DEFAULT_ANIMATE_RATE
Default value for animate rate.
|
<static> |
SpiderGL.UserInterface.CanvasHandler.DEFAULT_IGNORE_KEY_REPEAT
Default value for ignoring key repeats.
|
<static> |
SpiderGL.UserInterface.CanvasHandler.DEFAULT_PROPERTY_NAME
Default name of the property to install in the handler object for accessing the canvas handler.
|
<static> |
SpiderGL.UserInterface.CanvasHandler.DEFAULT_STANDARD_GL_UNPACK
Default value for applying standard OpenGL pixel unpack parameters.
|
<readonly> |
Gets the number of draw events occurred in the last second.
|
<readonly> |
Gets the canvas hijacked WebGLRenderingContext.
|
<readonly> |
Gets the height of the associated canvas.
|
Gets/Sets if the key repeat must be ignored.
|
|
<readonly> |
Gets a function that, once called, sends a draw event, which once handled will call the onDraw method of the registered handler.
|
<readonly> |
Gets the width of the associated canvas.
|
- Fields borrowed from class SpiderGL.Core.ObjectBase:
- uid
Method Summary
Method Attributes | Method Name and Description |
---|---|
dragDeltaX(btn)
If dragging is ongoing, gets the difference between the current cursor x position and the cursor x position at dragging start.
|
|
dragDeltaY(btn)
If dragging is ongoing, gets the difference between the current cursor y position and the cursor x position at dragging start.
|
|
dragEndX(btn)
Gets the cursor x position when dragging has finished.
|
|
dragEndY(btn)
Gets the cursor y position when dragging has finished.
|
|
dragStartX(btn)
Gets the cursor x position when dragging has started.
|
|
dragStartY(btn)
Gets the cursor y position when dragging has started.
|
|
draw()
Calls immediately the onDraw event handler.
|
|
isDragging(btn)
Tests if a dragging (mouse move + mouse button down) operation is active.
|
|
isKeyDown(key)
Tests if a key is pressed.
|
|
isMouseButtonDown(btn)
Tests if a mouse button is pressed.
|
Class Detail
SpiderGL.UserInterface.CanvasHandler(gl, handler, options)
Creates a SpiderGL.UserInterface.CanvasHandler.
SpiderGL.UserInterface.CanvasHandler is an event handler used to implement an easy controller for WebGL canvas.
It should not be directly used. Use SpiderGL.UserInterface.handleCanvas or SpiderGL.UserInterface.handleCanvasOnLoad to install it to a listener object.
- Parameters:
- {WebGLRenderingcontext} gl
- The WebGLRenderingcontext to pass to the handler.
- {object} handler
- The event handler to which events will be dispatched.
- {object} options Optional
- Optional parameters
- {bool} options.standardGLUnpack Optional, Default: SpiderGL.UserInterface.CanvasHandler.DEFAULT_STANDARD_GL_UNPACK
- If true, sets the default OpenGL unpack behaviour.
- {number} options.animateRate Optional, Default: SpiderGL.UserInterface.CanvasHandler.DEFAULT_ANIMATE_RATE
- Additional options.
Field Detail
<readonly>
{number}
animateDeltaTime
Gets the elapsed time, in milliseconds, between the last and the current onAnimate event.
<readonly>
{number}
animatePrevTime
Gets the time, in seconds, of the last onAnimate event.
{number}
animateRate
Gets/Sets the frequency (calls per second) used to emit the onAnimate event.
If zero, the onAnimate event will be disabled. If greater than zero, specifies how many times emit the event per second.
If less than zero, the event will be emitted as fast as possible.
- Default Value:
- SpiderGL.UserInterface.CanvasHandler.DEFAULT_ANIMATE_RATE
<readonly>
{number}
animateTime
Gets the time, in seconds, of the current onAnimate event.
<readonly>
{HTMLCanvasElement}
canvas
Gets the associated canvas.
{number}
cursorDeltaX
Gets the difference between the current and the previous cursor x position, relative to the canvas lower left corner.
{number}
cursorDeltaY
Gets the difference between the current and the previous cursor y position, relative to the canvas lower left corner.
{number}
cursorPrevX
Gets the previous cursor x position, relative to the canvas lower left corner.
{number}
cursorPrevY
Gets the previous cursor y position, relative to the canvas lower left corner.
{number}
cursorX
Gets the cursor x position, relative to the canvas lower left corner.
{number}
cursorY
Gets the cursor y position, relative to the canvas lower left corner.
<static>
{number}
SpiderGL.UserInterface.CanvasHandler.DEFAULT_ANIMATE_RATE
Default value for animate rate.
- Default Value:
- 0
<static>
{bool}
SpiderGL.UserInterface.CanvasHandler.DEFAULT_IGNORE_KEY_REPEAT
Default value for ignoring key repeats.
- Default Value:
- true
<static>
{string}
SpiderGL.UserInterface.CanvasHandler.DEFAULT_PROPERTY_NAME
Default name of the property to install in the handler object for accessing the canvas handler.
- Default Value:
- "ui"
<static>
{bool}
SpiderGL.UserInterface.CanvasHandler.DEFAULT_STANDARD_GL_UNPACK
Default value for applying standard OpenGL pixel unpack parameters.
- Default Value:
- true
<readonly>
{number}
framesPerSecond
Gets the number of draw events occurred in the last second.
<readonly>
{WebGLRenderingContext}
gl
Gets the canvas hijacked WebGLRenderingContext.
<readonly>
{number}
height
Gets the height of the associated canvas.
{bool}
ignoreKeyRepeat
Gets/Sets if the key repeat must be ignored.
- Default Value:
- SpiderGL.UserInterface.CanvasHandler.DEFAULT_IGNORE_KEY_REPEAT
<readonly>
{function}
postDrawEvent
Gets a function that, once called, sends a draw event, which once handled will call the onDraw method of the registered handler.
<readonly>
{number}
width
Gets the width of the associated canvas.
Method Detail
-
{number} dragDeltaX(btn)If dragging is ongoing, gets the difference between the current cursor x position and the cursor x position at dragging start.
- Parameters:
- {number} btn
- The button to test (0 = left, 1 = right, 2 = middle).
- Returns:
- {number} The difference between the current cursor x position and the cursor x position at dragging start.
-
{number} dragDeltaY(btn)If dragging is ongoing, gets the difference between the current cursor y position and the cursor x position at dragging start.
- Parameters:
- {number} btn
- The button to test (0 = left, 1 = right, 2 = middle).
- Returns:
- {number} The difference between the current cursor y position and the cursor y position at dragging start.
-
{number} dragEndX(btn)Gets the cursor x position when dragging has finished.
- Parameters:
- {number} btn
- The button to test (0 = left, 1 = right, 2 = middle).
- Returns:
- {number} The cursor x position, relative to the canvas lower left corner, when the dragging has finished.
-
{number} dragEndY(btn)Gets the cursor y position when dragging has finished.
- Parameters:
- {number} btn
- The button to test (0 = left, 1 = right, 2 = middle).
- Returns:
- {number} The cursor y position, relative to the canvas lower left corner, when the dragging has finished.
-
{number} dragStartX(btn)Gets the cursor x position when dragging has started.
- Parameters:
- {number} btn
- The button to test (0 = left, 1 = right, 2 = middle).
- Returns:
- {number} The cursor x position, relative to the canvas lower left corner, when the dragging has started.
-
{number} dragStartY(btn)Gets the cursor y position when dragging has started.
- Parameters:
- {number} btn
- The button to test (0 = left, 1 = right, 2 = middle).
- Returns:
- {number} The cursor y position, relative to the canvas lower left corner, when the dragging has started.
-
draw()Calls immediately the onDraw event handler.
-
{bool} isDragging(btn)Tests if a dragging (mouse move + mouse button down) operation is active.
- Parameters:
- {number} btn
- The button to test (0 = left, 1 = right, 2 = middle).
- Returns:
- {bool} True if the dragging operation is active with the specified mouse button, false otherwise.
-
{bool} isKeyDown(key)Tests if a key is pressed.
- Parameters:
- {string|number} key
- The key to test.
- Returns:
- {bool} True if the key is pressed, false otherwise.
-
{bool} isMouseButtonDown(btn)Tests if a mouse button is pressed.
- Parameters:
- {number} btn
- The button to test (0 = left, 1 = right, 2 = middle).
- Returns:
- {bool} True if the mouse button is pressed, false otherwise.