Added VGA gallery

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-16 00:29:03 +01:00
parent e9e56eac9a
commit 222e3c51ee
2 changed files with 125 additions and 11 deletions

View File

@@ -3,6 +3,7 @@ import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
import 'package:wolf_3d_flutter/wolf_3d.dart'; import 'package:wolf_3d_flutter/wolf_3d.dart';
import 'package:wolf_dart/screens/difficulty_screen.dart'; import 'package:wolf_dart/screens/difficulty_screen.dart';
import 'package:wolf_dart/screens/sprite_gallery.dart'; import 'package:wolf_dart/screens/sprite_gallery.dart';
import 'package:wolf_dart/screens/vga_gallery.dart';
class EpisodeScreen extends StatefulWidget { class EpisodeScreen extends StatefulWidget {
const EpisodeScreen({super.key}); const EpisodeScreen({super.key});
@@ -33,7 +34,23 @@ class _EpisodeScreenState extends State<EpisodeScreen> {
return Scaffold( return Scaffold(
backgroundColor: Colors.teal, backgroundColor: Colors.teal,
floatingActionButton: IconButton( floatingActionButtonLocation:
FloatingActionButtonLocation.miniCenterFloat,
floatingActionButton: Row(
children: [
FloatingActionButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) {
return VgaGallery(images: Wolf3d.I.vgaImages);
},
),
);
},
child: Text('VGA Gallery'),
),
FloatingActionButton(
onPressed: () { onPressed: () {
Navigator.of(context).push( Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
@@ -43,7 +60,9 @@ class _EpisodeScreenState extends State<EpisodeScreen> {
), ),
); );
}, },
icon: Icon(Icons.bug_report), child: Text('Sprites'),
),
],
), ),
body: Center( body: Center(
child: Column( child: Column(

View File

@@ -0,0 +1,95 @@
import 'package:flutter/material.dart';
import 'package:wolf_3d_data_types/wolf_3d_data_types.dart';
class VgaGallery extends StatelessWidget {
final List<VgaImage> images;
const VgaGallery({super.key, required this.images});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("VGA Image Gallery")),
backgroundColor: Colors.black,
body: GridView.builder(
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 150,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
),
itemCount: images.length,
itemBuilder: (context, index) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Index: $index\n${images[index].width} x ${images[index].height}",
style: const TextStyle(color: Colors.white, fontSize: 12),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Expanded(
child: Center(
child: CustomPaint(
painter: VgaPainter(image: images[index]),
// Scale it up so tiny fonts are readable
size: Size(
images[index].width * 2.0,
images[index].height * 2.0,
),
),
),
),
],
);
},
),
);
}
}
class VgaPainter extends CustomPainter {
final VgaImage image;
VgaPainter({required this.image});
@override
void paint(Canvas canvas, Size size) {
int planeWidth = image.width ~/ 4;
int planeSize = planeWidth * image.height;
double pixelW = size.width / image.width;
double pixelH = size.height / image.height;
final Paint paint = Paint()..isAntiAlias = false;
for (int y = 0; y < image.height; y++) {
for (int x = 0; x < image.width; x++) {
int plane = x % 4;
int sx = x ~/ 4;
int colorByte =
image.pixels[(plane * planeSize) + (y * planeWidth) + sx];
if (colorByte != 255) {
int abgr = ColorPalette.vga32Bit[colorByte];
// Extract the bytes
int r = abgr & 0xFF;
int g = (abgr >> 8) & 0xFF;
int b = (abgr >> 16) & 0xFF;
int a = (abgr >> 24) & 0xFF;
// Repack them as ARGB for Flutter's Color object
int argb = (a << 24) | (r << 16) | (g << 8) | b;
paint.color = Color(argb);
canvas.drawRect(
Rect.fromLTWH(x * pixelW, y * pixelH, pixelW + 0.5, pixelH + 0.5),
paint,
);
}
}
}
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}