Pull common parts into BaseRenderLayer

This commit is contained in:
Daniel Imms
2017-08-31 17:13:15 -07:00
parent fd18f7cba7
commit a91380a76f
7 changed files with 47 additions and 64 deletions
+23
View File
@@ -0,0 +1,23 @@
import { IRenderLayer } from './Interfaces';
import { ITerminal } from '../Interfaces';
export abstract class BaseRenderLayer implements IRenderLayer {
protected _canvas: HTMLCanvasElement;
protected _ctx: CanvasRenderingContext2D;
constructor(container: HTMLElement, id: string, zIndex: number) {
this._canvas = document.createElement('canvas');
this._canvas.id = `xterm-${id}-layer`;
this._canvas.style.zIndex = zIndex.toString();
this._ctx = this._canvas.getContext('2d');
this._ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
container.appendChild(this._canvas);
}
public resize(terminal: ITerminal, canvasWidth: number, canvasHeight: number, charSizeChanged: boolean): void {
this._canvas.width = canvasWidth * window.devicePixelRatio;
this._canvas.height = canvasHeight * window.devicePixelRatio;
this._canvas.style.width = `${canvasWidth}px`;
this._canvas.style.height = `${canvasHeight}px`;
}
}