RetroTerminal constructor

RetroTerminal(
  1. int width,
  2. int height,
  3. String imageUrl, {
  4. CanvasElement? canvas,
  5. required int charWidth,
  6. required int charHeight,
  7. int? scale,
})

Creates a new terminal using a font image at imageUrl.

Implementation

factory RetroTerminal(int width, int height, String imageUrl,
    {html.CanvasElement? canvas,
    required int charWidth,
    required int charHeight,
    int? scale}) {
  scale ??= html.window.devicePixelRatio.toInt();

  // If not given a canvas, create one, automatically size it, and add it to
  // the page.
  if (canvas == null) {
    canvas = html.CanvasElement();
    var canvasWidth = charWidth * width;
    var canvasHeight = charHeight * height;
    canvas.width = canvasWidth * scale;
    canvas.height = canvasHeight * scale;
    canvas.style.width = '${canvasWidth}px';
    canvas.style.height = '${canvasHeight}px';

    html.document.body!.append(canvas);
  }

  var display = Display(width, height);

  return RetroTerminal._(display, charWidth, charHeight, canvas,
      html.ImageElement(src: imageUrl), scale);
}