|
@@ -0,0 +1,68 @@
|
|
|
+import 'package:flutter/material.dart';
|
|
|
+
|
|
|
+import 'package:flutter/services.dart';
|
|
|
+import 'dart:ui' as ui;
|
|
|
+
|
|
|
+/// Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
|
|
|
+///
|
|
|
+/// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
|
|
|
+/// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
|
|
|
+/// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
|
|
|
+/// This notice may not be removed from this file.
|
|
|
+
|
|
|
+class CPDFImageSliderThumbShape extends SliderComponentShape {
|
|
|
+ final double imageWidth;
|
|
|
+ final double imageHeight;
|
|
|
+ final ui.Image image;
|
|
|
+
|
|
|
+ CPDFImageSliderThumbShape({
|
|
|
+ this.imageWidth = 20,
|
|
|
+ this.imageHeight = 20,
|
|
|
+ required this.image,
|
|
|
+ });
|
|
|
+
|
|
|
+ @override
|
|
|
+ Size getPreferredSize(bool isEnabled, bool isDiscrete) {
|
|
|
+ return Size(imageWidth, imageHeight);
|
|
|
+ }
|
|
|
+
|
|
|
+ @override
|
|
|
+ void paint(
|
|
|
+ PaintingContext context,
|
|
|
+ Offset center, {
|
|
|
+ Animation<double>? activationAnimation,
|
|
|
+ Animation<double>? enableAnimation,
|
|
|
+ bool? isDiscrete,
|
|
|
+ TextPainter? labelPainter,
|
|
|
+ RenderBox? parentBox,
|
|
|
+ SliderThemeData? sliderTheme,
|
|
|
+ TextDirection? textDirection,
|
|
|
+ double? value,
|
|
|
+ double? textScaleFactor,
|
|
|
+ Size? sizeWithOverflow,
|
|
|
+ }) {
|
|
|
+ final canvas = context.canvas;
|
|
|
+ final imageOffset =
|
|
|
+ Offset(center.dx - imageWidth / 2, center.dy - imageHeight / 2);
|
|
|
+
|
|
|
+ // 计算缩放比例
|
|
|
+ final double targetWidth = imageWidth; // 目标宽度
|
|
|
+ final double targetHeight = imageHeight; // 目标高度
|
|
|
+ final double scaleX = targetWidth / image.width.toDouble();
|
|
|
+ final double scaleY = targetHeight / image.height.toDouble();
|
|
|
+ final double scale = scaleX < scaleY ? scaleX : scaleY;
|
|
|
+
|
|
|
+ // 计算缩放后的图片尺寸
|
|
|
+ final double destWidth = image.width.toDouble() * scale;
|
|
|
+ final double destHeight = image.height.toDouble() * scale;
|
|
|
+ // canvas.translate(imageOffset.dx, imageOffset.dy);
|
|
|
+ // canvas.rotate(1.6);
|
|
|
+
|
|
|
+ // 绘制图片,并指定位置和大小
|
|
|
+ final paint = Paint();
|
|
|
+ final srcRect = Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble());
|
|
|
+ final dstRect = Rect.fromLTWH(imageOffset.dx, imageOffset.dy, destWidth, destHeight);
|
|
|
+
|
|
|
+ canvas.drawImageRect(image, srcRect, dstRect, paint);
|
|
|
+ }
|
|
|
+}
|