From e5cd74926f1de202a979f3c82dc948883d211bbf Mon Sep 17 00:00:00 2001 From: Nyeogmi Date: Sat, 9 Sep 2023 18:58:31 -0700 Subject: [PATCH] Only use exact pixel scales again --- lib/game.dart | 2 +- lib/terminal_painter.dart | 30 +++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/game.dart b/lib/game.dart index 5152856..1ab3152 100644 --- a/lib/game.dart +++ b/lib/game.dart @@ -8,5 +8,5 @@ void main() async { .bg(Palette.subtitle) .fg(Palette.defaultBg) .big() - .puts("BEWARE OF THE BAT!"); + .puts("BEWARE OF THE BAT!\nA cool bat."); } diff --git a/lib/terminal_painter.dart b/lib/terminal_painter.dart index 612ad4d..40cd2e0 100644 --- a/lib/terminal_painter.dart +++ b/lib/terminal_painter.dart @@ -1,3 +1,4 @@ +import 'dart:developer'; import 'dart:ui' as ui; import 'dart:ui'; @@ -32,9 +33,32 @@ class TerminalCustomPainter extends CustomPainter { var image = pr .endRecording() // Renderer does something bizarre if I don't multiply by something greater than 1 - .toImageSync(cellW * Terminal.width * 2, cellH * Terminal.height * 2); - canvas.drawImageRect(image, const Offset(0, 0) & smallSize, - const Offset(0, 0) & size, Paint()..filterQuality = FilterQuality.none); + .toImageSync(cellW * Terminal.width * 1, cellH * Terminal.height * 1); + + double x0, y0, xSz, ySz; + (x0, y0) = (0.0, 0.0); + (xSz, ySz) = (size.width, size.height); + for (var multiplierBase = 16.0; multiplierBase >= 1; multiplierBase -= 1) { + final multiplier = multiplierBase / scalingFactor; + final candidateXSz = (multiplier * cellW * Terminal.width).toDouble(); + final candidateYSz = (multiplier * cellH * Terminal.height).toDouble(); + + if (candidateXSz <= size.width && candidateYSz <= size.height) { + xSz = candidateXSz; + ySz = candidateYSz; + x0 = (size.width - xSz) / 2; + y0 = (size.height - ySz) / 2; + x0 = (x0 * scalingFactor).floor() / scalingFactor; + y0 = (y0 * scalingFactor).floor() / scalingFactor; + break; + } + } + log("$x0, $y0, $xSz, $ySz"); + canvas.drawImageRect( + image, + const Offset(0, 0) & smallSize, + Offset(x0, y0) & Size(xSz, ySz), + Paint()..filterQuality = FilterQuality.none); } void virtualPaint(Canvas canvas, Size size) {