Stage(CanvasElement canvas, { int width, int height, StageOptions options })
Source
Stage(CanvasElement canvas, {int width, int height, StageOptions options}) {
if (canvas is! CanvasElement) throw new ArgumentError("canvas");
if (canvas.tabIndex <= 0) canvas.tabIndex = 1;
if (canvas.style.outline == "") canvas.style.outline = "none";
if (options == null) options = Stage.defaultOptions;
if (width == null) width = canvas.width;
if (height == null) height = canvas.height;
backgroundColor = options.backgroundColor;
preventDefaultOnTouch = options.preventDefaultOnTouch;
preventDefaultOnMouse = options.preventDefaultOnMouse;
preventDefaultOnWheel = options.preventDefaultOnWheel;
preventDefaultOnKeyboard = options.preventDefaultOnKeyboard;
_canvas = canvas;
_stageAlign = options.stageAlign;
_stageScaleMode = options.stageScaleMode;
_stageRenderMode = options.stageRenderMode;
_inputEventMode = options.inputEventMode;
_sourceWidth = ensureInt(width);
_sourceHeight = ensureInt(height);
_pixelRatio = minNum(options.maxPixelRatio, env.devicePixelRatio);
_renderContext = _createRenderContext(canvas, options);
_renderState = new RenderState(_renderContext);
print("StageXL render engine : ${_renderContext.renderEngine}");
canvas.onKeyDown.listen(_onKeyEvent);
canvas.onKeyUp.listen(_onKeyEvent);
canvas.onKeyPress.listen(_onKeyEvent);
var listenToMouseEvents =
_inputEventMode == InputEventMode.MouseOnly ||
_inputEventMode == InputEventMode.MouseAndTouch;
if (listenToMouseEvents) {
canvas.onMouseDown.listen(_onMouseEvent);
canvas.onMouseUp.listen(_onMouseEvent);
canvas.onMouseMove.listen(_onMouseEvent);
canvas.onMouseOut.listen(_onMouseEvent);
canvas.onContextMenu.listen(_onMouseEvent);
canvas.onMouseWheel.listen(_onMouseWheelEvent);
}
var listenToTouchEvents =
_inputEventMode == InputEventMode.TouchOnly ||
_inputEventMode == InputEventMode.MouseAndTouch;
if (listenToTouchEvents && env.isTouchEventSupported) {
canvas.onTouchStart.listen(_onTouchEvent);
canvas.onTouchEnd.listen(_onTouchEvent);
canvas.onTouchMove.listen(_onTouchEvent);
canvas.onTouchEnter.listen(_onTouchEvent);
canvas.onTouchLeave.listen(_onTouchEvent);
canvas.onTouchCancel.listen(_onTouchEvent);
}
Mouse.onCursorChanged.listen((cursorName) => _updateMouseCursor());
_updateMouseCursor();
_updateCanvasSize();
_renderContext.clear(backgroundColor);
}