diff --git a/lib/core/providers/state/toolbox_state_provider.dart b/lib/core/providers/state/toolbox_state_provider.dart index 88c27ce4..72f19f00 100644 --- a/lib/core/providers/state/toolbox_state_provider.dart +++ b/lib/core/providers/state/toolbox_state_provider.dart @@ -11,12 +11,15 @@ import 'package:paintroid/core/providers/object/tools/shapes_tool_provider.dart' import 'package:paintroid/core/providers/state/paint_provider.dart'; import 'package:paintroid/core/providers/state/spray_tool_provider.dart'; import 'package:paintroid/core/providers/state/toolbox_state_data.dart'; +import 'package:paintroid/core/tools/implementation/spray_tool.dart'; import 'package:paintroid/core/tools/tool_data.dart'; import 'package:paintroid/ui/utils/toast_utils.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; part 'toolbox_state_provider.g.dart'; +const SPRAY_TOOL_RADIUS = 10.0; + @riverpod class ToolBoxStateProvider extends _$ToolBoxStateProvider { @override @@ -49,6 +52,10 @@ class ToolBoxStateProvider extends _$ToolBoxStateProvider { } void switchTool(ToolData data) { + if (state.currentTool is SprayTool) { + final currentRadius = (state.currentTool as SprayTool).sprayRadius; + ref.read(paintProvider.notifier).updateStrokeWidth(currentRadius); + } switch (data.type) { case ToolType.BRUSH: state = state.copyWith(currentTool: ref.read(brushToolProvider)); @@ -68,7 +75,9 @@ class ToolBoxStateProvider extends _$ToolBoxStateProvider { break; case ToolType.SPRAY: state = state.copyWith(currentTool: ref.read(sprayToolProvider)); - ref.read(paintProvider.notifier).updateStrokeWidth(10); + final currentStrokeWidth = ref.read(paintProvider).strokeWidth; + (state.currentTool as SprayTool).updateSprayRadius(currentStrokeWidth); + ref.read(paintProvider.notifier).updateStrokeWidth(SPRAY_TOOL_RADIUS); break; default: state = state.copyWith(currentTool: ref.read(brushToolProvider)); diff --git a/test/integration/spray_tool_test.dart b/test/integration/spray_tool_test.dart index 66bea5ea..a9f38b33 100644 --- a/test/integration/spray_tool_test.dart +++ b/test/integration/spray_tool_test.dart @@ -43,7 +43,7 @@ void main() { ); expect(color, Colors.transparent); - await UIInteraction.tapAt(CanvasPosition.center, times: 10); + await UIInteraction.tapAt(CanvasPosition.center); color = await UIInteraction.getPixelColor( CanvasPosition.centerX, @@ -74,7 +74,7 @@ void main() { ); expect(color, Colors.transparent); - await UIInteraction.tapAt(CanvasPosition.topLeft, times: 10); + await UIInteraction.tapAt(CanvasPosition.topLeft); color = await UIInteraction.getPixelColor( CanvasPosition.left, @@ -105,7 +105,7 @@ void main() { ); expect(color, Colors.transparent); - await UIInteraction.tapAt(CanvasPosition.bottomRight, times: 10); + await UIInteraction.tapAt(CanvasPosition.bottomRight); color = await UIInteraction.getPixelColor( CanvasPosition.right, diff --git a/test/utils/ui_interaction.dart b/test/utils/ui_interaction.dart index e825d8ab..2931d6a0 100644 --- a/test/utils/ui_interaction.dart +++ b/test/utils/ui_interaction.dart @@ -96,7 +96,7 @@ class UIInteraction { if (i < 0 || i >= image.width || j < 0 || j >= image.height) { continue; } - final argbColor = getColorAtPixel(image, x, y); + final argbColor = getColorAtPixel(image, i, j); if (argbColor != 0) { return Color(argbColor); }