From 187808d543b006949b7e9248d5dee1543e1ca461 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 17 Nov 2022 18:42:09 +0100 Subject: [PATCH] [flutter] More work on dress-up example. --- spine-flutter/example/lib/dress_up.dart | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/spine-flutter/example/lib/dress_up.dart b/spine-flutter/example/lib/dress_up.dart index d55750774..fc0c51ee4 100644 --- a/spine-flutter/example/lib/dress_up.dart +++ b/spine-flutter/example/lib/dress_up.dart @@ -1,3 +1,4 @@ +import 'dart:math'; import 'dart:ui' as ui; import 'package:flutter/material.dart'; @@ -21,27 +22,30 @@ class DressUpState extends State { super.initState(); SkeletonDrawable.fromAsset("assets/mix-and-match-pro.skel", "assets/mix-and-match.atlas").then((drawable) async { for (var skin in drawable.skeletonData.getSkins()) { - //if (skin.getName() == "default") continue; + if (skin.getName() == "default") continue; var skeleton = drawable.skeleton; skeleton.setSkin(skin); skeleton.setToSetupPose(); skeleton.updateWorldTransform(); var bounds = skeleton.getBounds(); - var scale = 1 / (bounds.width > bounds.height ? bounds.width / thumbnailSize * 1.1 : bounds.height / thumbnailSize * 1.1); + var scale = 1 / (bounds.width > bounds.height ? bounds.width / thumbnailSize : bounds.height / thumbnailSize); + scale *= 0.9; var recorder = ui.PictureRecorder(); - var canvas = Canvas(recorder, const Rect.fromLTWH(0, 0, thumbnailSize, thumbnailSize)); + var canvas = Canvas(recorder); + var bgColor = Random().nextInt(0xffffffff) | 0xff0000000; var paint = Paint() - ..color = const ui.Color(0xffff00ff) + ..color = ui.Color(bgColor) ..style = PaintingStyle.fill; canvas.drawRect(const Rect.fromLTWH(0, 0, thumbnailSize, thumbnailSize), paint); canvas.scale(scale, scale); canvas.translate(-bounds.x, -bounds.y); + canvas.drawRect(Rect.fromLTRB(-5, -5, 5, -5), paint..color = Colors.red); drawable.renderToCanvas(canvas); var imageData = await (await recorder.endRecording().toImage(thumbnailSize.toInt(), thumbnailSize.toInt())).toByteData(format: ui.ImageByteFormat.png); - _skinImages.add(Image.memory(imageData!.buffer.asUint8List(), fit: BoxFit.none)); + _skinImages.add(Image.memory(imageData!.buffer.asUint8List(), fit: BoxFit.contain)); } _drawable = drawable; setState(() {}); @@ -59,7 +63,7 @@ class DressUpState extends State { Expanded( child:ListView( children: _skinImages.map((image) { - return SizedBox(width: 100, height: 100, child: image); + return SizedBox(width: 200, height: 200, child: image); }).toList() ) ),