From baea7660be289e19f7f7d0aeb14da0b4c4cb6e7d Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Wed, 8 Nov 2023 13:40:07 +0100 Subject: [PATCH] Fix pointer list on window exit, closes #521 --- app/lib/cubits/current_index.dart | 4 +++- app/lib/renderers/renderer.dart | 12 ++++++++---- app/lib/views/view.dart | 4 ++++ fastlane/metadata/android/en-US/changelogs/79.txt | 1 + 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/lib/cubits/current_index.dart b/app/lib/cubits/current_index.dart index 03e4d6c30692..15317c25202d 100644 --- a/app/lib/cubits/current_index.dart +++ b/app/lib/cubits/current_index.dart @@ -106,6 +106,7 @@ class CurrentIndexCubit extends Cubit { Handler? changeTool(DocumentBloc bloc, int index, [Handler? handler, bool justAdded = false, bool runSelected = true]) { + resetInput(bloc); final blocState = bloc.state; if (blocState is! DocumentLoadSuccess) return null; final document = blocState.data; @@ -286,7 +287,8 @@ class CurrentIndexCubit extends Cubit { } void addPointer(int pointer) { - emit(state.copyWith(pointers: state.pointers.toList()..add(pointer))); + emit(state.copyWith( + pointers: (state.pointers.toSet()..add(pointer)).toList())); } void removePointer(int pointer) { diff --git a/app/lib/renderers/renderer.dart b/app/lib/renderers/renderer.dart index b52d9fda3238..5959420fe25d 100644 --- a/app/lib/renderers/renderer.dart +++ b/app/lib/renderers/renderer.dart @@ -182,14 +182,18 @@ abstract class Renderer { position ??= relative ? Offset.zero : rect.topLeft; final nextPosition = relative ? position + rect.topLeft : position; - final scale = Offset(scaleX, scaleY); - // .rotate(const Offset(1, 1), useRotation / 180 * pi); + final radians = rotation * (pi / 180); + final cosRotation = cos(radians); + final sinRotation = sin(radians); + + scaleX = scaleX * cosRotation - scaleY * sinRotation; + scaleY = scaleX * sinRotation + scaleY * cosRotation; return _transform( position: nextPosition, rotation: nextRotation, - scaleX: scale.dx, - scaleY: scale.dy, + scaleX: scaleX, + scaleY: scaleY, ); } diff --git a/app/lib/views/view.dart b/app/lib/views/view.dart index 8f6c37b42fa0..70617e1eef7e 100644 --- a/app/lib/views/view.dart +++ b/app/lib/views/view.dart @@ -350,6 +350,10 @@ class _MainViewViewportState extends State child: BlocBuilder( builder: (context, transform) => MouseRegion( cursor: currentIndex.currentCursor, + onExit: (event) { + cubit.removePointer(event.pointer); + cubit.removeButtons(); + }, child: ClipRRect( child: Stack(children: [ Container(color: Colors.white), diff --git a/fastlane/metadata/android/en-US/changelogs/79.txt b/fastlane/metadata/android/en-US/changelogs/79.txt index d2dce39d26ff..96d3d89ef295 100644 --- a/fastlane/metadata/android/en-US/changelogs/79.txt +++ b/fastlane/metadata/android/en-US/changelogs/79.txt @@ -1,4 +1,5 @@ * Add templates to data settings * Fix icon button if no display icon available +* Fix pointer list on window exit ([#521](https://github.com/LinwoodDev/Butterfly/issues/521)) View all changes in the blog: https://linwood.dev/butterfly/2.0.0-beta.15 \ No newline at end of file