diff --git a/lib/screens/episode_screen.dart b/lib/screens/episode_screen.dart index ae93d2e..6e470b7 100644 --- a/lib/screens/episode_screen.dart +++ b/lib/screens/episode_screen.dart @@ -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_dart/screens/difficulty_screen.dart'; import 'package:wolf_dart/screens/sprite_gallery.dart'; +import 'package:wolf_dart/screens/vga_gallery.dart'; class EpisodeScreen extends StatefulWidget { const EpisodeScreen({super.key}); @@ -33,17 +34,35 @@ class _EpisodeScreenState extends State { return Scaffold( backgroundColor: Colors.teal, - floatingActionButton: IconButton( - onPressed: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (context) { - return SpriteGallery(sprites: Wolf3d.I.sprites); - }, - ), - ); - }, - icon: Icon(Icons.bug_report), + 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: () { + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) { + return SpriteGallery(sprites: Wolf3d.I.sprites); + }, + ), + ); + }, + child: Text('Sprites'), + ), + ], ), body: Center( child: Column( diff --git a/lib/screens/vga_gallery.dart b/lib/screens/vga_gallery.dart new file mode 100644 index 0000000..a7fcbaf --- /dev/null +++ b/lib/screens/vga_gallery.dart @@ -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 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; +}