Skip to content

Commit

Permalink
PAINTROID-768: Flutter: Add Spray Can tool - CR
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenkomotive committed Oct 5, 2024
1 parent e28ad14 commit 25c14bf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
11 changes: 10 additions & 1 deletion lib/core/providers/state/toolbox_state_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions test/integration/spray_tool_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/utils/ui_interaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 25c14bf

Please sign in to comment.