RetroTerminal constructor

RetroTerminal(
  1. int width,
  2. int height,
  3. String imageUrl, {
  4. HTMLCanvasElement? 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, {
  web.HTMLCanvasElement? canvas,
  required int charWidth,
  required int charHeight,
  int? scale,
}) {
  scale ??= web.window.devicePixelRatio.toInt();

  // If not given a canvas, create one, automatically size it, and add it to
  // the page.
  if (canvas == null) {
    canvas = web.HTMLCanvasElement();
    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';

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

  var display = Display(width, height);

  var image = web.HTMLImageElement();
  image.src = imageUrl;

  return RetroTerminal._(
    display,
    charWidth,
    charHeight,
    canvas,
    image,
    scale,
  );
}