Go back to widescreen. Try a new upscaling method
This commit is contained in:
parent
79e5e94cc2
commit
50a5fc6985
Binary file not shown.
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 4.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 4.9 KiB |
Binary file not shown.
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 33 KiB |
@ -5,10 +5,8 @@ import 'package:dartterm/terminal_painter.dart';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class Terminal {
|
class Terminal {
|
||||||
static const int width = 80;
|
static const int width = 88;
|
||||||
static const int height = 50;
|
static const int height = 50;
|
||||||
static const int cellW = 64;
|
|
||||||
static const int cellH = 64;
|
|
||||||
static const int nTiles = width * height;
|
static const int nTiles = width * height;
|
||||||
|
|
||||||
late List<Tile> tiles;
|
late List<Tile> tiles;
|
||||||
@ -90,8 +88,6 @@ class Content {
|
|||||||
Terminal terminal = Terminal();
|
Terminal terminal = Terminal();
|
||||||
const int width = Terminal.width;
|
const int width = Terminal.width;
|
||||||
const int height = Terminal.height;
|
const int height = Terminal.height;
|
||||||
const int cellW = Terminal.cellW;
|
|
||||||
const int cellH = Terminal.cellH;
|
|
||||||
const int nTiles = Terminal.nTiles;
|
const int nTiles = Terminal.nTiles;
|
||||||
|
|
||||||
Widget toWidget(BuildContext context) {
|
Widget toWidget(BuildContext context) {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:dartterm/assets.dart';
|
import 'package:dartterm/assets.dart';
|
||||||
import 'package:dartterm/fonts.dart';
|
import 'package:dartterm/fonts.dart';
|
||||||
@ -9,6 +10,9 @@ class TerminalCustomPainter extends CustomPainter {
|
|||||||
Terminal t;
|
Terminal t;
|
||||||
double scalingFactor;
|
double scalingFactor;
|
||||||
|
|
||||||
|
static const int cellW = 8;
|
||||||
|
static const int cellH = 8;
|
||||||
|
|
||||||
TerminalCustomPainter(this.t, this.scalingFactor);
|
TerminalCustomPainter(this.t, this.scalingFactor);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -18,76 +22,32 @@ class TerminalCustomPainter extends CustomPainter {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void paint(Canvas canvas, Size size) {
|
void paint(Canvas canvas, Size size) {
|
||||||
final paint = Paint()..filterQuality = FilterQuality.high;
|
var pr = PictureRecorder();
|
||||||
|
|
||||||
// == Fill backdrop ==
|
var smallSize = Size((cellW * Terminal.width).toDouble(),
|
||||||
final paint2 = Paint()
|
(cellH * Terminal.height).toDouble());
|
||||||
..color = Colors.black
|
|
||||||
..style = PaintingStyle.fill;
|
|
||||||
canvas.drawRect(const Offset(0, 0) & size, paint2);
|
|
||||||
|
|
||||||
// == Estimate dimensions for scaling ==
|
var virtualCanvas = Canvas(pr, const Offset(0, 0) & smallSize);
|
||||||
var sx = size.width / Terminal.width;
|
virtualPaint(virtualCanvas, smallSize);
|
||||||
var sy = size.height / Terminal.height;
|
var image = pr
|
||||||
var dpx = 0.0;
|
.endRecording()
|
||||||
var dpy = 0.0;
|
// Renderer does something bizarre if I don't multiply by something greater than 1
|
||||||
var invScalingFactor = 1 / scalingFactor;
|
.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);
|
||||||
|
}
|
||||||
|
|
||||||
for (double preferredSx in [64, 56, 48, 40, 32, 24, 16, 8]) {
|
void virtualPaint(Canvas canvas, Size size) {
|
||||||
preferredSx *= invScalingFactor;
|
final paint = Paint();
|
||||||
var preferredSy = preferredSx;
|
|
||||||
if (preferredSx < sx && preferredSy < sy) {
|
|
||||||
sx = preferredSx.toDouble();
|
|
||||||
sy = preferredSy.toDouble();
|
|
||||||
dpx = ((size.width - (sx * Terminal.width)) / 2);
|
|
||||||
dpy = ((size.height - (sy * Terminal.height)) / 2);
|
|
||||||
|
|
||||||
dpx /= invScalingFactor;
|
|
||||||
dpx = dpx.floorToDouble();
|
|
||||||
dpx *= invScalingFactor;
|
|
||||||
|
|
||||||
dpy /= invScalingFactor;
|
|
||||||
dpy = dpy.floorToDouble();
|
|
||||||
dpy *= invScalingFactor;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < nTiles; i++) {
|
|
||||||
final tile = t.tiles[i];
|
|
||||||
|
|
||||||
final (pcxDst, pcyDst) = terminal.toXY(i) ?? (0, 0);
|
|
||||||
final (pxDst, pyDst) = (dpx + pcxDst * sx, dpy + pcyDst * sy);
|
|
||||||
final rectDst = Rect.fromLTWH(pxDst, pyDst, sx, sy);
|
|
||||||
|
|
||||||
var content = tile.content;
|
|
||||||
if (content != null) {
|
|
||||||
var source = content.sourceImage;
|
|
||||||
var image = assets.getImageIfAvailable(source);
|
|
||||||
if (image != null) {
|
|
||||||
var fgRect = Rect.fromLTWH(
|
|
||||||
content.sourceCx.toDouble() * cellW,
|
|
||||||
content.sourceCy.toDouble() * cellH,
|
|
||||||
cellW.toDouble(),
|
|
||||||
cellH.toDouble());
|
|
||||||
canvas.drawImageRect(
|
|
||||||
image,
|
|
||||||
fgRect,
|
|
||||||
rectDst,
|
|
||||||
paint,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var todos = Todos();
|
var todos = Todos();
|
||||||
|
|
||||||
// == Draw the background and foreground of every tile ==
|
// == Draw the background and foreground of every tile ==
|
||||||
for (var i = 0; i < nTiles; i++) {
|
for (var i = 0; i < nTiles; i++) {
|
||||||
final (pcxDst, pcyDst) = terminal.toXY(i) ?? (0, 0);
|
final (pcxDst, pcyDst) = terminal.toXY(i) ?? (0, 0);
|
||||||
final (pxDst, pyDst) = (dpx + pcxDst * sx, dpy + pcyDst * sy);
|
final (pxDst, pyDst) = (pcxDst * cellW, pcyDst * cellH);
|
||||||
final rectDst = Rect.fromLTWH(pxDst, pyDst, sx, sy);
|
final rectDst = Rect.fromLTWH(pxDst.toDouble(), pyDst.toDouble(),
|
||||||
|
cellW.toDouble(), cellH.toDouble());
|
||||||
|
|
||||||
final tile = t.tiles[i];
|
final tile = t.tiles[i];
|
||||||
|
|
||||||
@ -137,15 +97,9 @@ class ImageTodos {
|
|||||||
ImageTodos(this.atlas);
|
ImageTodos(this.atlas);
|
||||||
|
|
||||||
void add(Rect src, Rect dst, Color color) {
|
void add(Rect src, Rect dst, Color color) {
|
||||||
// NOTE: Because main.dart uses aspectRatio, scaleX and scaleY should be close to the same
|
|
||||||
var scaleX = dst.width / src.width;
|
|
||||||
// dst.width / src.width;
|
|
||||||
// log("scaleX: $scaleX ($dstWidth, $srcWidth)");
|
|
||||||
// var scaleY = dst.height / src.height;
|
|
||||||
|
|
||||||
transforms.add(RSTransform.fromComponents(
|
transforms.add(RSTransform.fromComponents(
|
||||||
rotation: 0.0,
|
rotation: 0.0,
|
||||||
scale: scaleX,
|
scale: 1.0,
|
||||||
anchorX: 0.0,
|
anchorX: 0.0,
|
||||||
anchorY: 0.0,
|
anchorY: 0.0,
|
||||||
translateX: dst.left,
|
translateX: dst.left,
|
||||||
|
Loading…
Reference in New Issue
Block a user