bullet movement navigatior

This commit is contained in:
Jan Pleterski
2026-11-16 12:04:03 +01:00
parent d0c44157f1
commit f40271ed7b
2 changed files with 240 additions and 62 deletions
+226 -53
View File
@@ -3,7 +3,7 @@ import 'dart:typed_data';
import 'package:flutter/material.dart';
import '../utils/target_colors.dart';
import '../theme/app_theme.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:flutter/services.dart' show rootBundle, HapticFeedback;
import 'package:image/image.dart' as img;
import 'package:path_provider/path_provider.dart';
import 'yolo_detector.dart';
@@ -63,6 +63,15 @@ class _PreviewScreenState extends State<PreviewScreen> {
bool _isEditMode = false;
int? _selectedBulletIndexInEdit;
// Hold-and-drag on the edit controller: moves the selected bullet with the
// finger while a magnifier shows the area around it.
bool _isDragMovingBullet = false;
Offset _lastDragOffset = Offset.zero;
double _displayScaleX = 1;
double _displayScaleY = 1;
static const double _loupeSize = 130;
static const double _loupeZoom = 2.5;
Color get _editColor => Colors.deepOrangeAccent;
Color get _activeColor => _isEditMode ? _editColor : _bulletColor;
Color get _activeColorWithOpacity =>
@@ -625,7 +634,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
final targetData = {
'date': dateString,
'totalScore': _totalScore,
'bulletCount': widget.bulletCount, // shots fired; missed ones are absent from 'bullets'
'bulletCount': widget
.bulletCount, // shots fired; missed ones are absent from 'bullets'
'bullets': bulletsInDefaultCoordinates,
};
@@ -641,76 +651,219 @@ class _PreviewScreenState extends State<PreviewScreen> {
}
}
/// Score of the bullet at [index], live for manual and detected bullets.
int _scoreAt(int index) {
final manualStart = _mappedBullets.length - _manualBulletScores.length;
if (index >= manualStart) {
return _manualBulletScores[index - manualStart];
}
final b = _mappedBullets[index];
return _scoreForBullet(
Offset(b.dx / _scaleFactorX, b.dy / _scaleFactorY),
fixedRingTargetCenter,
);
}
Widget _buildEditController() {
if (!_isEditMode || _selectedBulletIndexInEdit == null) {
final index = _selectedBulletIndexInEdit;
if (!_isEditMode || index == null || index >= _mappedBullets.length) {
return const SizedBox.shrink();
}
final s = Surfaces.current;
final accent = _bulletColor;
final dragging = _isDragMovingBullet;
const padSize = 156.0;
const step = 3.0;
Widget arrow(IconData icon, Offset delta, Alignment align) {
return Align(
alignment: align,
child: Material(
color: Colors.transparent,
shape: const CircleBorder(),
clipBehavior: Clip.antiAlias,
child: InkWell(
onTap: () => _moveBullet(delta),
child: SizedBox(
width: 52,
height: 52,
child: Icon(icon, size: 34, color: s.textPrimary),
),
),
),
);
}
return Positioned(
bottom: 20,
left: 0,
right: 0,
child: Center(
child: Container(
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 20),
child: GestureDetector(
// Hold anywhere on the controller, then drag to move the bullet fast
onLongPressStart: (_) {
HapticFeedback.mediumImpact();
setState(() {
_isDragMovingBullet = true;
_lastDragOffset = Offset.zero;
});
},
onLongPressMoveUpdate: (details) {
final delta = details.offsetFromOrigin - _lastDragOffset;
_lastDragOffset = details.offsetFromOrigin;
// Finger movement on screen = bullet movement on screen
_moveBullet(Offset(
delta.dx / _displayScaleX,
delta.dy / _displayScaleY,
));
},
onLongPressEnd: (_) => setState(() => _isDragMovingBullet = false),
onLongPressCancel: () => setState(() => _isDragMovingBullet = false),
child: AnimatedContainer(
duration: const Duration(milliseconds: 150),
width: 200,
decoration: BoxDecoration(
color: Colors.black.withValues(alpha: 0.75),
borderRadius: BorderRadius.circular(16),
color: s.card,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: dragging ? accent : Colors.transparent,
width: 2,
),
boxShadow: const [
BoxShadow(
color: Colors.black38,
offset: Offset(0, 4),
blurRadius: 12,
),
],
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Up
IconButton(
icon: const Icon(Icons.keyboard_arrow_up,
size: 36, color: Colors.white),
onPressed: () => _moveBullet(const Offset(0, -3)),
splashRadius: 24,
),
// Left - Check - Right
Row(
mainAxisSize: MainAxisSize.min,
// Header: which bullet, and its live score
Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 12, 4),
child: Row(
children: [
IconButton(
icon: const Icon(Icons.keyboard_arrow_left,
size: 36, color: Colors.white),
onPressed: () => _moveBullet(const Offset(-3, 0)),
splashRadius: 24,
Text(
'${_t('Bullet')} ${index + 1}'.toUpperCase(),
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
letterSpacing: 1.4,
color: s.textSecondary,
),
const SizedBox(width: 8),
),
const Spacer(),
Container(
constraints: const BoxConstraints(minWidth: 36),
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: accent,
borderRadius: BorderRadius.circular(10),
),
alignment: Alignment.center,
child: Text(
'${_scoreAt(index)}',
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
// Round d-pad with "done" in the middle
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Container(
width: padSize,
height: padSize,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.greenAccent.withValues(alpha: 0.2),
border: Border.all(color: Colors.greenAccent, width: 2),
color: s.textPrimary.withValues(alpha: 0.06),
border: Border.all(color: s.divider),
),
child: Stack(
children: [
arrow(Icons.keyboard_arrow_up_rounded,
const Offset(0, -step), Alignment.topCenter),
arrow(Icons.keyboard_arrow_down_rounded,
const Offset(0, step), Alignment.bottomCenter),
arrow(Icons.keyboard_arrow_left_rounded,
const Offset(-step, 0), Alignment.centerLeft),
arrow(Icons.keyboard_arrow_right_rounded,
const Offset(step, 0), Alignment.centerRight),
Center(
child: Material(
color: accent,
shape: const CircleBorder(),
elevation: 2,
child: InkWell(
customBorder: const CircleBorder(),
onTap: () => setState(
() => _selectedBulletIndexInEdit = null),
child: SizedBox(
width: 52,
height: 52,
child: Icon(
dragging
? Icons.open_with_rounded
: Icons.check_rounded,
color: Colors.white,
size: 28,
),
),
child: IconButton(
icon: const Icon(Icons.check,
color: Colors.greenAccent, size: 28),
onPressed: () =>
setState(() => _selectedBulletIndexInEdit = null),
splashRadius: 22,
),
),
const SizedBox(width: 8),
IconButton(
icon: const Icon(Icons.keyboard_arrow_right,
size: 36, color: Colors.white),
onPressed: () => _moveBullet(const Offset(3, 0)),
splashRadius: 24,
),
],
),
),
),
Padding(
padding: const EdgeInsets.only(bottom: 12),
child: Text(
_t('Hold and drag to move'),
style: TextStyle(fontSize: 11, color: s.textSecondary),
),
),
],
),
),
),
),
);
}
// Down
IconButton(
icon: const Icon(Icons.keyboard_arrow_down,
size: 36, color: Colors.white),
onPressed: () => _moveBullet(const Offset(0, 3)),
splashRadius: 24,
/// Magnifier shown above the selected bullet while it is being dragged.
Widget _buildBulletLoupe(Offset bullet, double scaleX, double scaleY,
double offsetX, double offsetY) {
final bx = bullet.dx * scaleX + offsetX;
final by = bullet.dy * scaleY + offsetY;
const gap = _loupeSize / 2 + 40;
// Put the loupe above the bullet, or below it when there is no room.
final cy = by - gap - _loupeSize / 2 >= 0 ? by - gap : by + gap;
return Positioned(
left: bx - _loupeSize / 2,
top: cy - _loupeSize / 2,
child: IgnorePointer(
child: RawMagnifier(
size: const Size(_loupeSize, _loupeSize),
magnificationScale: _loupeZoom,
focalPointOffset: Offset(0, by - cy),
decoration: const MagnifierDecoration(
shape: CircleBorder(
side: BorderSide(color: Colors.white, width: 3),
),
],
shadows: [BoxShadow(color: Colors.black54, blurRadius: 8)],
),
child: const Center(
child: Icon(Icons.add, color: Colors.red, size: 24),
),
),
),
@@ -773,8 +926,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
final num = int.parse(training.group(1)!);
if (num >= trainingCount) trainingCount = num + 1;
}
final tournament =
RegExp(r'^(?:Tournament|Tekmovanje|Wettkampf) (\d+)$').firstMatch(name);
final tournament = RegExp(r'^(?:Tournament|Tekmovanje|Wettkampf) (\d+)$')
.firstMatch(name);
if (tournament != null) {
final num = int.parse(tournament.group(1)!);
if (num >= tournamentCount) tournamentCount = num + 1;
@@ -1112,6 +1265,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
final scaleX = displayWidth / imgWidth;
final scaleY = displayHeight / imgHeight;
_displayScaleX = scaleX;
_displayScaleY = scaleY;
final imageWidget =
Image.memory(displayImage, fit: BoxFit.fill);
@@ -1220,6 +1375,18 @@ class _PreviewScreenState extends State<PreviewScreen> {
),
);
}),
if (_mode == PreviewMode.mappedTarget &&
_isDragMovingBullet &&
_selectedBulletIndexInEdit != null &&
_selectedBulletIndexInEdit! <
_mappedBullets.length)
_buildBulletLoupe(
_mappedBullets[_selectedBulletIndexInEdit!],
scaleX,
scaleY,
offsetX,
offsetY,
),
],
);
},
@@ -1313,7 +1480,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
Container(
height: 30,
decoration: BoxDecoration(
color: Surfaces.current.card,
color:
Surfaces.current.card,
borderRadius:
const BorderRadius
.only(
@@ -1330,7 +1498,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
fontWeight:
FontWeight.bold,
fontSize: 14,
color: Surfaces.current.textPrimary,
color: Surfaces.current
.textPrimary,
),
),
),
@@ -1405,7 +1574,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
Container(
height: 30,
decoration: BoxDecoration(
color: Surfaces.current.card,
color:
Surfaces.current.card,
borderRadius:
const BorderRadius
.only(
@@ -1422,7 +1592,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
fontWeight:
FontWeight.bold,
fontSize: 14,
color: Surfaces.current.textPrimary,
color: Surfaces.current
.textPrimary,
),
),
),
@@ -1530,7 +1701,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
mainAxisAlignment: MainAxisAlignment.end,
children: [
IconButton(
icon: const Icon(Icons.create_new_folder_outlined, color: Colors.white, size: 24),
icon: const Icon(Icons.create_new_folder_outlined,
color: Colors.white, size: 24),
onPressed: _saveTargetDataWithDialog,
tooltip: _t("Save to folder"),
),
@@ -1546,7 +1718,8 @@ class _PreviewScreenState extends State<PreviewScreen> {
_selectedBulletIndexInEdit = null;
});
},
tooltip: _isEditMode ? _t("Done Editing") : _t("Edit Mode"),
tooltip:
_isEditMode ? _t("Done Editing") : _t("Edit Mode"),
),
const SizedBox(width: 4),
],
+5
View File
@@ -192,6 +192,11 @@ class AppTranslations {
},
// Camera settings
'Hold and drag to move': {
'English': 'Hold and drag to move',
'Slovenian': 'Pridrži in povleci za premik',
'German': 'Halten und ziehen zum Verschieben',
},
'About': {
'English': 'About',
'Slovenian': 'O aplikaciji',