import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:scence_map/controllers/controller.dart'; import 'package:scence_map/record_entity.dart'; import '../../service/pile/device_type.dart'; final ScenceMapController mapcontroller = Get.put(ScenceMapController()); // 对点 瞄准器 class SightController extends GetxController { var isNomal = true.obs; //左下圆 var sightOffset = const Offset(3, 3).obs; var sightOffsetInit = const Offset(0, 0).obs; var sightInit = const Offset(0, 0).obs; // var lastSightOffset = const Offset(0, 0).obs; // 新增变量,用于存储上一次手指离开时的位置 var isCardVisible = false.obs; // 控制卡片是否可见 RecordEntity? selectedPilePoint; var initDx = 0.0.obs; var isFirst = true.obs; var visualList = [].obs; var plot = 2.0.obs; var scale = 0.75.obs; int lastManualTapTime = 0; int lastCloseTapTime = 0; reset() { sightOffset.value = const Offset(3, 3); sightOffsetInit.value = const Offset(0, 0); sightInit.value = const Offset(0, 0); initDx.value = 0.0; update(); } } class SightView extends GetView { const SightView({super.key}); @override Widget build(BuildContext context) { final size = MediaQuery.of(context).size; MediaQueryData mediaQueryData = MediaQueryData.fromView(WidgetsBinding.instance.window); //获取当前屏幕信息 final orientation = mediaQueryData.orientation; //获得设备方向 final deviceType = getDeviceType(context); double rectWidth = size.height / 2; if (!controller.isNomal.value) { rectWidth = size.width; } else { if (orientation == Orientation.landscape) { rectWidth = size.width / 2; if (deviceType == DeviceType.mobile) { rectWidth = size.height - 5; } } else { rectWidth = size.height / 2; if (deviceType == DeviceType.mobile) { rectWidth = size.width - 5; } } } bool isDarkMode = Theme.of(context).brightness == Brightness.dark; return Stack( children: [ CustomPaint( //绘制瞄准器 size: Size(rectWidth, rectWidth), painter: DrawCicle(controller, 0, 0, isDarkMode), ) ], ); } } class DrawCicle extends CustomPainter { final SightController sight; final double tiltX; final double tiltY; final bool isDarkMode; DrawCicle(this.sight, this.tiltX, this.tiltY, this.isDarkMode); final _paint = Paint(); //创建一个画笔并配置其属性 Path path = Path(); List icons = [ Icons.arrow_drop_up, Icons.arrow_drop_down, Icons.arrow_left, Icons.arrow_right ]; List iconOffset = []; List text = ["", "", "", ""]; //['前移', '后移', '左移', '右移']; @override void paint(Canvas canvas, size) { _paint ..strokeWidth = 2 ..style = PaintingStyle.stroke ..color = const Color.fromARGB(255, 183, 183, 162); double rectWidth = (size.height / 2 - 5).roundToDouble(); if (!sight.isNomal.value) { } else {} path.moveTo(0, rectWidth + 5); path.lineTo(size.height, rectWidth + 5); path.moveTo(rectWidth + 5, 0); path.lineTo(rectWidth + 5, size.height); canvas.drawPath(path, _paint); // 总长 2m double step = (rectWidth / sight.plot.value / 10).roundToDouble(); canvas.translate(rectWidth + 5, rectWidth + 5); for (var i = 0; i < 21; i++) { if (i % 10 == 0) { double line = 7; canvas.drawLine(Offset(0, i * step), Offset(line, i * step), _paint); canvas.drawLine(Offset(i * step, 0), Offset(i * step, line), _paint); canvas.drawLine(Offset(0, -i * step), Offset(line, -i * step), _paint); canvas.drawLine(Offset(-i * step, 0), Offset(-i * step, line), _paint); drawText(canvas, Offset(line, i * step), i ~/ 10); drawText(canvas, Offset(line, -i * step), (-i ~/ 10)); if (i ~/ 10 != 0) { drawText(canvas, Offset(i * step, line), i ~/ 10); drawText(canvas, Offset(-i * step, line), (-i ~/ 10)); } } else if (i % 5 == 0) { double line = 5; canvas.drawLine(Offset(0, i * step), Offset(line, i * step), _paint); canvas.drawLine(Offset(i * step, 0), Offset(i * step, line), _paint); canvas.drawLine(Offset(0, -i * step), Offset(line, -i * step), _paint); canvas.drawLine(Offset(-i * step, 0), Offset(-i * step, line), _paint); } else { double line = 3; canvas.drawLine(Offset(0, i * step), Offset(line, i * step), _paint); canvas.drawLine(Offset(i * step, 0), Offset(i * step, line), _paint); canvas.drawLine(Offset(0, -i * step), Offset(line, -i * step), _paint); canvas.drawLine(Offset(-i * step, 0), Offset(-i * step, line), _paint); } } canvas.translate(-(rectWidth + 5), -(rectWidth + 5)); canvas.translate(rectWidth + 5, rectWidth + 5); if (sight.selectedPilePoint != null) { drawPoint(canvas); } // // 绘制水平仪 // double x = real.tiltX.value; // // double y = real.tiltY.value; // // print("----${real.centerX.value},${real.centerY.value}"); // if (real.tiltX.value == 0 || real.tiltY.value == 0) { // x = 0; // y = 0; // } // _paint.color = Colors.red; // canvas.drawCircle(Offset(x * step * 10, y * step * 10), 10, _paint); // canvas.translate(-(rectWidth + 5), -(rectWidth + 5)); } drawText(Canvas canvas, Offset offset, int i, [bool isShow = true]) { TextPainter textPainter = TextPainter( text: TextSpan( text: isShow ? "$i m" : "$i", style: TextStyle( fontSize: 12, color: isDarkMode ? Colors.white : Colors.black)), textDirection: TextDirection.ltr, textAlign: TextAlign.left); textPainter.layout(); textPainter.paint(canvas, offset); } drawPoint(Canvas canvas) { canvas.drawCircle(Offset.zero, 20, Paint()..color = const Color.fromARGB(255, 139, 33, 33)); // drawText(canvas, pos - const Offset(20, 10), i, false); } // drawRect(Canvas canvas, double rectWidth) { // double x = item.dx - real.centerX.value; // double y = item.dy - real.centerY.value; // Offset center = Offset(x, y); // canvas.drawRect( // Rect.fromCenter(center: center, width: rectWidth, height: rectWidth), // _paint); // } @override bool shouldRepaint(covariant CustomPainter oldDelegate) => true; } class DevicePointer extends StatelessWidget { // final DeviceItemController item; // DevicePointer(this.item); DevicePointer(); @override Widget build(BuildContext context) { // double carWidth = item.width / controller.pixel2MeterRatio; // double carHeight = item.height / controller.pixel2MeterRatio; return Stack( alignment: Alignment.center, children: [ SizedBox( width: 60.0, // 设置图像的宽度 height: 60.0, // 设置图像的高度 child: Image.asset( "images/navi_pointer.png", errorBuilder: (context, error, stackTrace) { return Text('无法加载图片'); }, ), ), // Obx(() { // Offset offset = controller.xy2Screen( // gnsscontroller.pilerCenter.X, gnsscontroller.pilerCenter.Y); // return Positioned( // left: offset.dx, // top: offset.dy, // child: Transform( // transform: Matrix4.identity() // ..rotateZ(-controller.rotation.value), // child: Column( // children: [Text("设备:${item.name}")], // ), // ), // ); // }), ], ); } }