mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-02 13:49:07 +08:00
Merge branch '4.1' into 4.2-beta
# Conflicts: # spine-flutter/example/pubspec.lock
This commit is contained in:
commit
bb0151fb64
@ -27,10 +27,10 @@
|
|||||||
/// SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
/// SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
///
|
///
|
||||||
|
|
||||||
|
import 'package:spine_flutter/raw_image_provider.dart';
|
||||||
import 'package:spine_flutter/spine_flutter.dart';
|
import 'package:spine_flutter/spine_flutter.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/painting.dart' as painting;
|
import 'package:flutter/painting.dart' as painting;
|
||||||
import 'package:raw_image_provider/raw_image_provider.dart';
|
|
||||||
|
|
||||||
class DressUp extends StatefulWidget {
|
class DressUp extends StatefulWidget {
|
||||||
const DressUp({Key? key}) : super(key: key);
|
const DressUp({Key? key}) : super(key: key);
|
||||||
|
|||||||
@ -5,7 +5,7 @@ version: 1.0.0+1
|
|||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.17.6 <4.0.0'
|
sdk: '>=2.17.6 <4.0.0'
|
||||||
flutter: ">=3.10.5"
|
flutter: ">=3.16.0 <4.0.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
@ -13,12 +13,12 @@ dependencies:
|
|||||||
|
|
||||||
spine_flutter:
|
spine_flutter:
|
||||||
path: ../
|
path: ../
|
||||||
cupertino_icons: ^1.0.2
|
cupertino_icons: ^1.0.6
|
||||||
flame: ^1.4.0
|
flame: ^1.10.1
|
||||||
raw_image_provider: ^0.2.0
|
raw_image_provider: ^0.2.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_lints: ^2.0.0
|
flutter_lints: ^3.0.1
|
||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
|||||||
120
spine-flutter/lib/raw_image_provider.dart
Normal file
120
spine-flutter/lib/raw_image_provider.dart
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
// Copyright (c) 2021 Yrom Wang
|
||||||
|
//
|
||||||
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
// of this software and associated documentation files (the "Software"), to deal
|
||||||
|
// in the Software without restriction, including without limitation the rights
|
||||||
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
// copies of the Software, and to permit persons to whom the Software is
|
||||||
|
// furnished to do so, subject to the following conditions:
|
||||||
|
//
|
||||||
|
// The above copyright notice and this permission notice shall be included in all
|
||||||
|
// copies or substantial portions of the Software.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
// SOFTWARE.
|
||||||
|
import 'dart:typed_data';
|
||||||
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/painting.dart';
|
||||||
|
import 'package:crypto/crypto.dart';
|
||||||
|
|
||||||
|
/// Decodes the given [image] (raw image pixel data) as an image ('dart:ui')
|
||||||
|
class RawImageProvider extends ImageProvider<_RawImageKey> {
|
||||||
|
final RawImageData image;
|
||||||
|
final double? scale;
|
||||||
|
final int? targetWidth;
|
||||||
|
final int? targetHeight;
|
||||||
|
RawImageProvider(
|
||||||
|
this.image, {
|
||||||
|
this.scale = 1.0,
|
||||||
|
this.targetWidth,
|
||||||
|
this.targetHeight,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
ImageStreamCompleter loadImage(_RawImageKey key, ImageDecoderCallback decode) {
|
||||||
|
return MultiFrameImageStreamCompleter(
|
||||||
|
codec: _loadAsync(key),
|
||||||
|
scale: scale ?? 1.0,
|
||||||
|
debugLabel: 'RawImageProvider(${describeIdentity(key)})',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<_RawImageKey> obtainKey(ImageConfiguration configuration) {
|
||||||
|
return SynchronousFuture(image._obtainKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// see [ui.decodeImageFromPixels]
|
||||||
|
Future<ui.Codec> _loadAsync(_RawImageKey key) async {
|
||||||
|
assert(key == image._obtainKey());
|
||||||
|
// rgba8888 pixels
|
||||||
|
var buffer = await ui.ImmutableBuffer.fromUint8List(image.pixels);
|
||||||
|
|
||||||
|
final descriptor = ui.ImageDescriptor.raw(
|
||||||
|
buffer,
|
||||||
|
width: image.width,
|
||||||
|
height: image.height,
|
||||||
|
pixelFormat: image.pixelFormat,
|
||||||
|
);
|
||||||
|
assert(() {
|
||||||
|
debugPrint('ImageDescriptor: ${descriptor.width}x${descriptor.height}');
|
||||||
|
return true;
|
||||||
|
}());
|
||||||
|
return descriptor.instantiateCodec(
|
||||||
|
targetWidth: targetWidth, targetHeight: targetHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RawImageKey {
|
||||||
|
final int w;
|
||||||
|
final int h;
|
||||||
|
final int format;
|
||||||
|
final Digest dataHash;
|
||||||
|
_RawImageKey(this.w, this.h, this.format, this.dataHash);
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if (identical(this, other)) return true;
|
||||||
|
|
||||||
|
return other is _RawImageKey &&
|
||||||
|
other.w == w &&
|
||||||
|
other.h == h &&
|
||||||
|
other.format == format &&
|
||||||
|
other.dataHash == dataHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return hashValues(w, h, format, dataHash.hashCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Raw pixels data of an image
|
||||||
|
class RawImageData {
|
||||||
|
final Uint8List pixels;
|
||||||
|
final int width;
|
||||||
|
final int height;
|
||||||
|
final ui.PixelFormat pixelFormat;
|
||||||
|
|
||||||
|
RawImageData(
|
||||||
|
this.pixels,
|
||||||
|
this.width,
|
||||||
|
this.height, {
|
||||||
|
this.pixelFormat = ui.PixelFormat.rgba8888,
|
||||||
|
});
|
||||||
|
|
||||||
|
_RawImageKey? _key;
|
||||||
|
_RawImageKey _obtainKey() {
|
||||||
|
return _key ??=
|
||||||
|
_RawImageKey(width, height, pixelFormat.index, md5.convert(pixels));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -38,11 +38,12 @@ import 'package:flutter/rendering.dart' as rendering;
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
import 'package:raw_image_provider/raw_image_provider.dart';
|
|
||||||
|
|
||||||
import 'ffi_proxy.dart';
|
import 'ffi_proxy.dart';
|
||||||
import 'init.dart' if (dart.library.html) 'init_web.dart';
|
import 'init.dart' if (dart.library.html) 'init_web.dart';
|
||||||
import 'spine_flutter_bindings_generated.dart';
|
import 'spine_flutter_bindings_generated.dart';
|
||||||
|
import 'raw_image_provider.dart';
|
||||||
|
|
||||||
export 'spine_widget.dart';
|
export 'spine_widget.dart';
|
||||||
|
|
||||||
|
|||||||
@ -8,23 +8,23 @@ documentation: https://esotericsoftware.com/spine-flutter
|
|||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.17.6 <4.0.0'
|
sdk: '>=2.17.6 <4.0.0'
|
||||||
flutter: ">=3.10.5"
|
flutter: ">=3.16.0 <4.0.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
ffi: ^2.0.1
|
ffi: ^2.1.0
|
||||||
web_ffi_fork: ^0.7.4
|
web_ffi_fork: ^0.7.4
|
||||||
inject_js: ^2.0.0
|
inject_js: ^2.0.0
|
||||||
js: ^0.6.5
|
js: ^0.6.5
|
||||||
meta: ^1.8.0
|
meta: ^1.10.0
|
||||||
http: ^1.1.0
|
http: ^1.1.0
|
||||||
path: ^1.8.2
|
path: ^1.8.2
|
||||||
raw_image_provider: ^0.2.0
|
crypto: ^3.0.3
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
ffigen: ^9.0.1
|
ffigen: ^10.0.0
|
||||||
flutter_lints: ^2.0.0
|
flutter_lints: ^3.0.1
|
||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
plugin:
|
plugin:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user