import { EventEmitter } from "../utils" ; import { Frame } from "../Frame" ; export interface IRendererOptions { canvas ? : HTMLCanvasElement ; } export const RENDERER_DEFAULT_OPTIONS = { canvas : null } ; const CANVAS_DEFAULT_WIDTH = 480 ; const CANVAS_DEFAULT_HEIGHT = 320 ; export abstract class AbstractRenderer extends EventEmitter { private _canvas : HTMLCanvasElement = null ; param options public constructor ( options ? ) { super ( ) ; options = Object . assign ( { } , RENDERER_DEFAULT_OPTIONS , options ) ; this . _canvas = options . canvas ; if ( ! ( this . _canvas instanceof HTMLCanvasElement ) ) { this . _canvas = document . createElement ( "canvas" ) ; this . _canvas . width = CANVAS_DEFAULT_WIDTH ; this . _canvas . height = CANVAS_DEFAULT_HEIGHT ; } } /**
     * The rendering surface to render into
     * TODO: allow other targets such as FBOs
     */ public getCanvas ( ) { return this . _canvas ; } /**
     * The width of the rendering surface
     */ public getWidth ( ) { return this . _canvas . width ; } /**
     * The height of the rendering surface
     */ public getHeight ( ) { return this . _canvas . height ; } param width param height public resize ( width , height ) { this . _canvas . width = width ; this . _canvas . height = height ; this . emit ( "resize" ) ; } param frame public abstract render ( frame ) ; /**
     * Destroy this Object
     */ public destroy ( ) { this . _canvas = null ; this . emit ( "destroy" ) ; } }