diff --git a/lib/core/commands/command_factory/command_factory.dart b/lib/core/commands/command_factory/command_factory.dart index 202d9010..f89fb41b 100644 --- a/lib/core/commands/command_factory/command_factory.dart +++ b/lib/core/commands/command_factory/command_factory.dart @@ -5,6 +5,8 @@ import 'package:flutter/material.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/clipboard_command.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/delete_region_command.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/text_command.dart'; +import 'package:paintroid/core/commands/command_implementation/graphic/clip_area_command.dart'; +import 'package:paintroid/core/commands/command_implementation/graphic/clip_path_command.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/line_command.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/path_command.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/shape/ellipse_shape_command.dart'; @@ -18,39 +20,43 @@ import 'package:paintroid/core/enums/shape_style.dart'; class CommandFactory { const CommandFactory(); - PathCommand createPathCommand( - PathWithActionHistory path, - Paint paint, - ) => + PathCommand createPathCommand(PathWithActionHistory path, + Paint paint,) => PathCommand(path, paint); - LineCommand createLineCommand( - PathWithActionHistory path, - Paint paint, - Offset startPoint, - Offset endPoint, - ) => + ClipPathCommand createClipPathCommand(PathWithActionHistory path, + Paint paint, { + Offset? startPoint, + Offset? endPoint, + }) => + ClipPathCommand( + path, + paint, + startPoint: startPoint, + endPoint: endPoint, + ); + + LineCommand createLineCommand(PathWithActionHistory path, + Paint paint, + Offset startPoint, + Offset endPoint,) => LineCommand(path, paint, startPoint, endPoint); - SquareShapeCommand createSquareShapeCommand( - Paint paint, - Offset topLeft, - Offset topRight, - Offset bottomLeft, - Offset bottomRight, - ShapeStyle style, - ) => + SquareShapeCommand createSquareShapeCommand(Paint paint, + Offset topLeft, + Offset topRight, + Offset bottomLeft, + Offset bottomRight, + ShapeStyle style,) => SquareShapeCommand( paint, topLeft, topRight, bottomLeft, bottomRight, style); - EllipseShapeCommand createEllipseShapeCommand( - Paint paint, - double radiusX, - double radiusY, - Offset center, - ShapeStyle style, - double angle, - ) => + EllipseShapeCommand createEllipseShapeCommand(Paint paint, + double radiusX, + double radiusY, + Offset center, + ShapeStyle style, + double angle,) => EllipseShapeCommand( paint, radiusX, @@ -60,13 +66,11 @@ class CommandFactory { angle, ); - ClipboardCommand createClipboardCommand( - Paint paint, - Uint8List imageData, - ui.Offset offset, - double scale, - double rotation, - ) => + ClipboardCommand createClipboardCommand(Paint paint, + Uint8List imageData, + ui.Offset offset, + double scale, + double rotation,) => ClipboardCommand( paint, imageData, @@ -75,16 +79,15 @@ class CommandFactory { rotation, ); - TextCommand createTextCommand( - Offset point, - String text, - TextStyle style, - double fontSize, - Paint paint, - double rotationAngle, { - double scaleX = 1.0, - double scaleY = 1.0, - }) => + TextCommand createTextCommand(Offset point, + String text, + TextStyle style, + double fontSize, + Paint paint, + double rotationAngle, { + double scaleX = 1.0, + double scaleY = 1.0, + }) => TextCommand( point, text, @@ -96,15 +99,13 @@ class CommandFactory { scaleY: scaleY, ); - StarShapeCommand createStarShapeCommand( - Paint paint, - int numPoints, - double angle, - Offset center, - ShapeStyle style, - double radiusX, - double radiusY, - ) => + StarShapeCommand createStarShapeCommand(Paint paint, + int numPoints, + double angle, + Offset center, + ShapeStyle style, + double radiusX, + double radiusY,) => StarShapeCommand( paint, numPoints, @@ -115,23 +116,23 @@ class CommandFactory { radiusY, ); - HeartShapeCommand createHeartShapeCommand( - Paint paint, - double width, - double height, - double angle, - Offset center, - ShapeStyle style, - ) => + HeartShapeCommand createHeartShapeCommand(Paint paint, + double width, + double height, + double angle, + Offset center, + ShapeStyle style,) => HeartShapeCommand(paint, width, height, angle, center, style); SprayCommand createSprayCommand(List points, Paint paint) { return SprayCommand(points, paint); } - DeleteRegionCommand createDeleteRegionCommand( - ui.Rect region, - ) => + ClipAreaCommand createClipAreaCommand(PathWithActionHistory path, + Paint paint,) => + ClipAreaCommand(path, paint); + + DeleteRegionCommand createDeleteRegionCommand(ui.Rect region,) => DeleteRegionCommand( Paint(), region, diff --git a/lib/core/commands/command_implementation/command.dart b/lib/core/commands/command_implementation/command.dart index 3265bfb8..1e846523 100644 --- a/lib/core/commands/command_implementation/command.dart +++ b/lib/core/commands/command_implementation/command.dart @@ -1,4 +1,6 @@ import 'package:equatable/equatable.dart'; +import 'package:paintroid/core/commands/command_implementation/graphic/clip_area_command.dart'; +import 'package:paintroid/core/commands/command_implementation/graphic/clip_path_command.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/clipboard_command.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/delete_region_command.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/line_command.dart'; @@ -38,6 +40,11 @@ abstract class Command with EquatableMixin { return HeartShapeCommand.fromJson(json); case SerializerType.STAR_SHAPE_COMMAND: return StarShapeCommand.fromJson(json); + case SerializerType.CLIP_PATH_COMMAND: + return ClipPathCommand.fromJson(json); + case SerializerType.CLIP_AREA_COMMAND: + return ClipAreaCommand.fromJson(json); + default: return PathCommand.fromJson(json); } diff --git a/lib/core/commands/command_implementation/graphic/clip_area_command.dart b/lib/core/commands/command_implementation/graphic/clip_area_command.dart new file mode 100644 index 00000000..607934d4 --- /dev/null +++ b/lib/core/commands/command_implementation/graphic/clip_area_command.dart @@ -0,0 +1,69 @@ +import 'dart:ui'; + +import 'package:json_annotation/json_annotation.dart'; +import 'package:paintroid/core/commands/command_implementation/graphic/graphic_command.dart'; +import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/json_serialization/converter/paint_converter.dart'; +import 'package:paintroid/core/json_serialization/converter/path_with_action_history_converter.dart'; +import 'package:paintroid/core/json_serialization/versioning/serializer_version.dart'; +import 'package:paintroid/core/json_serialization/versioning/version_strategy.dart'; + +part 'clip_area_command.g.dart'; + +@JsonSerializable() +class ClipAreaCommand extends GraphicCommand { + @JsonKey(includeToJson: true, includeFromJson: true) + final String type; + @JsonKey(includeToJson: true, includeFromJson: true) + final int version; + + @PathWithActionHistoryConverter() + final PathWithActionHistory clipPathData; + + ClipAreaCommand( + this.clipPathData, + Paint paint, { + this.type = SerializerType.CLIP_AREA_COMMAND, + int? version, + }) : version = version ?? + VersionStrategyManager.strategy.getClipAreaCommandVersion(), + super(paint); + + @override + void call(Canvas canvas) { + final Rect canvasBounds = canvas.getLocalClipBounds(); + + Path areaToClear = Path.combine( + PathOperation.difference, + Path()..addRect(canvasBounds), + clipPathData.path, + ); + + canvas.drawPath( + areaToClear, + Paint() + ..blendMode = BlendMode.clear + ..style = PaintingStyle.fill); + } + + @override + List get props => [paint, clipPathData, type, version]; + + factory ClipAreaCommand.fromJson(Map json) { + int version = json['version'] as int; + + switch (version) { + case Version.v1: + return _$ClipAreaCommandFromJson(json); + case Version.v2: + // For different versions of ClipAreaCommand the deserialization + // has to be implemented manually. + // Autogenerated code can only be used for one version + default: + return _$ClipAreaCommandFromJson(json); + } + } + + @override + Map toJson() => _$ClipAreaCommandToJson(this); +} diff --git a/lib/core/commands/command_implementation/graphic/clip_area_command.g.dart b/lib/core/commands/command_implementation/graphic/clip_area_command.g.dart new file mode 100644 index 00000000..c8c75133 --- /dev/null +++ b/lib/core/commands/command_implementation/graphic/clip_area_command.g.dart @@ -0,0 +1,25 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'clip_area_command.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +ClipAreaCommand _$ClipAreaCommandFromJson(Map json) => + ClipAreaCommand( + const PathWithActionHistoryConverter() + .fromJson(json['clipPathData'] as Map), + const PaintConverter().fromJson(json['paint'] as Map), + type: json['type'] as String? ?? SerializerType.CLIP_AREA_COMMAND, + version: (json['version'] as num?)?.toInt(), + ); + +Map _$ClipAreaCommandToJson(ClipAreaCommand instance) => + { + 'paint': const PaintConverter().toJson(instance.paint), + 'type': instance.type, + 'version': instance.version, + 'clipPathData': + const PathWithActionHistoryConverter().toJson(instance.clipPathData), + }; diff --git a/lib/core/commands/command_implementation/graphic/clip_path_command.dart b/lib/core/commands/command_implementation/graphic/clip_path_command.dart new file mode 100644 index 00000000..5fa3248b --- /dev/null +++ b/lib/core/commands/command_implementation/graphic/clip_path_command.dart @@ -0,0 +1,89 @@ +import 'dart:ui'; + +import 'package:flutter/widgets.dart'; +import 'package:json_annotation/json_annotation.dart'; +import 'package:paintroid/core/commands/command_implementation/graphic/graphic_command.dart'; +import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/json_serialization/converter/offset_converter.dart'; +import 'package:paintroid/core/json_serialization/converter/path_with_action_history_converter.dart'; +import 'package:paintroid/core/json_serialization/converter/paint_converter.dart'; +import 'package:paintroid/core/json_serialization/versioning/serializer_version.dart'; +import 'package:paintroid/core/json_serialization/versioning/version_strategy.dart'; +import 'package:path_drawing/path_drawing.dart'; + +part 'clip_path_command.g.dart'; + +@JsonSerializable() +class ClipPathCommand extends GraphicCommand { + @JsonKey(includeToJson: true, includeFromJson: true) + final String type; + @JsonKey(includeToJson: true, includeFromJson: true) + final int version; + + @PathWithActionHistoryConverter() + final PathWithActionHistory path; + + @OffsetConverter() + final Offset? startPoint; + @OffsetConverter() + final Offset? endPoint; + + ClipPathCommand( + this.path, + super.paint, { + this.startPoint, + this.endPoint, + this.type = SerializerType.CLIP_PATH_COMMAND, + int? version, + }) : version = version ?? + VersionStrategyManager.strategy.getClipPathCommandVersion(); + + @override + void call(Canvas canvas) { + final dashLength = paint.strokeWidth * 4; + final dashGap = paint.strokeWidth * 2; + + final dashedPath = dashPath( + path.path, + dashArray: CircularIntervalList([dashLength, dashGap]), + ); + canvas.drawPath(dashedPath, paint); + + if (startPoint != null && + endPoint != null && + (startPoint!.dx != endPoint!.dx || startPoint!.dy != endPoint!.dy)) { + final solidPaint = Paint() + ..color = paint.color + ..style = PaintingStyle.stroke + ..strokeWidth = paint.strokeWidth + ..isAntiAlias = true; + + final solidPath = Path() + ..moveTo(startPoint!.dx, startPoint!.dy) + ..lineTo(endPoint!.dx, endPoint!.dy); + + canvas.drawPath(solidPath, solidPaint); + } + } + + @override + List get props => [paint, path, startPoint, endPoint, type, version]; + + factory ClipPathCommand.fromJson(Map json) { + int version = json['version'] as int; + + switch (version) { + case Version.v1: + return _$ClipPathCommandFromJson(json); + case Version.v2: + // For different versions of ClipPathCommand the deserialization + // has to be implemented manually. + // Autogenerated code can only be used for one version + default: + return _$ClipPathCommandFromJson(json); + } + } + + @override + Map toJson() => _$ClipPathCommandToJson(this); +} diff --git a/lib/core/commands/command_implementation/graphic/clip_path_command.g.dart b/lib/core/commands/command_implementation/graphic/clip_path_command.g.dart new file mode 100644 index 00000000..3f88e3d5 --- /dev/null +++ b/lib/core/commands/command_implementation/graphic/clip_path_command.g.dart @@ -0,0 +1,44 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'clip_path_command.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +ClipPathCommand _$ClipPathCommandFromJson(Map json) => + ClipPathCommand( + const PathWithActionHistoryConverter() + .fromJson(json['path'] as Map), + const PaintConverter().fromJson(json['paint'] as Map), + startPoint: _$JsonConverterFromJson, Offset>( + json['startPoint'], const OffsetConverter().fromJson), + endPoint: _$JsonConverterFromJson, Offset>( + json['endPoint'], const OffsetConverter().fromJson), + type: json['type'] as String? ?? SerializerType.CLIP_PATH_COMMAND, + version: (json['version'] as num?)?.toInt(), + ); + +Map _$ClipPathCommandToJson(ClipPathCommand instance) => + { + 'paint': const PaintConverter().toJson(instance.paint), + 'type': instance.type, + 'version': instance.version, + 'path': const PathWithActionHistoryConverter().toJson(instance.path), + 'startPoint': _$JsonConverterToJson, Offset>( + instance.startPoint, const OffsetConverter().toJson), + 'endPoint': _$JsonConverterToJson, Offset>( + instance.endPoint, const OffsetConverter().toJson), + }; + +Value? _$JsonConverterFromJson( + Object? json, + Value? Function(Json json) fromJson, +) => + json == null ? null : fromJson(json as Json); + +Json? _$JsonConverterToJson( + Value? value, + Json? Function(Value value) toJson, +) => + value == null ? null : toJson(value); diff --git a/lib/core/commands/command_manager/command_manager.dart b/lib/core/commands/command_manager/command_manager.dart index ffa1ce97..dfc34c21 100644 --- a/lib/core/commands/command_manager/command_manager.dart +++ b/lib/core/commands/command_manager/command_manager.dart @@ -1,6 +1,8 @@ import 'dart:ui'; import 'package:paintroid/core/commands/command_implementation/command.dart'; +import 'package:paintroid/core/commands/command_implementation/graphic/clip_area_command.dart'; +import 'package:paintroid/core/commands/command_implementation/graphic/clip_path_command.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/clipboard_command.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/text_command.dart'; import 'package:paintroid/core/commands/command_implementation/graphic/graphic_command.dart'; @@ -27,13 +29,19 @@ class CommandManager { _undoStack.add(command); } + void removeCommand(Command commandToRemove) { + _undoStack.remove(commandToRemove); + } + void setUndoStack(List commands) { _undoStack.clear(); _undoStack.addAll(commands); } void executeLastCommand(Canvas canvas) { - if (_undoStack.isEmpty) return; + if (_undoStack.isEmpty) { + return; + } final lastCommand = _undoStack.last; if (lastCommand is GraphicCommand) { lastCommand.call(canvas); @@ -49,7 +57,9 @@ class CommandManager { } void discardLastCommand() { - if (_undoStack.isNotEmpty) _undoStack.removeLast(); + if (_undoStack.isNotEmpty) { + _undoStack.removeLast(); + } } void clearUndoStack({Iterable? newCommands}) { @@ -123,6 +133,9 @@ class CommandManager { return ToolData.TEXT; } else if (command.runtimeType == SprayCommand) { return ToolData.SPRAY; + } else if (command.runtimeType == ClipAreaCommand || + command.runtimeType == ClipPathCommand) { + return ToolData.CLIPPING; } else if (command.runtimeType == StarShapeCommand) { return ToolData.SHAPES; } else if (command.runtimeType == HeartShapeCommand) { diff --git a/lib/core/json_serialization/versioning/serializer_version.dart b/lib/core/json_serialization/versioning/serializer_version.dart index de4c3048..7ef223e2 100644 --- a/lib/core/json_serialization/versioning/serializer_version.dart +++ b/lib/core/json_serialization/versioning/serializer_version.dart @@ -9,6 +9,8 @@ class SerializerVersion { static const int STAR_SHAPE_COMMAND_VERSION = Version.v1; static const int HEART_SHAPE_COMMAND_VERSION = Version.v1; static const int SPRAY_COMMAND_VERSION = Version.v1; + static const int CLIP_PATH_COMMAND_VERSION = Version.v1; + static const int CLIP_AREA_COMMAND_VERSION = Version.v1; static const int CLIPBOARD_COMMAND_VERSION = Version.v1; static const int DELETE_REGION_COMMAND_VERSION = Version.v1; } @@ -31,6 +33,8 @@ class SerializerType { static const String STAR_SHAPE_COMMAND = 'StarShapeCommand'; static const String HEART_SHAPE_COMMAND = 'HeartShapeCommand'; static const String SPRAY_COMMAND = 'SprayCommand'; + static const String CLIP_PATH_COMMAND = 'ClipPathCommand'; + static const String CLIP_AREA_COMMAND = 'ClipAreaCommand'; static const String CLIPBOARD_COMMAND = 'ClipboardCommand'; static const String DELETE_REGION_COMMAND = 'DeleteRegionCommand'; } diff --git a/lib/core/json_serialization/versioning/version_strategy.dart b/lib/core/json_serialization/versioning/version_strategy.dart index 2c3d843f..676a2bc9 100644 --- a/lib/core/json_serialization/versioning/version_strategy.dart +++ b/lib/core/json_serialization/versioning/version_strategy.dart @@ -19,6 +19,10 @@ abstract class IVersionStrategy { int getSprayCommandVersion(); + int getClipPathCommandVersion(); + + int getClipAreaCommandVersion(); + int getClipboardCommandVersion(); int getDeleteRegionCommandVersion(); @@ -56,6 +60,14 @@ class ProductionVersionStrategy implements IVersionStrategy { @override int getSprayCommandVersion() => SerializerVersion.SPRAY_COMMAND_VERSION; + @override + int getClipPathCommandVersion() => + SerializerVersion.CLIP_PATH_COMMAND_VERSION; + + @override + int getClipAreaCommandVersion() => + SerializerVersion.CLIP_AREA_COMMAND_VERSION; + @override int getClipboardCommandVersion() => SerializerVersion.CLIPBOARD_COMMAND_VERSION; diff --git a/lib/core/providers/object/tools/clipping_tool_provider.dart b/lib/core/providers/object/tools/clipping_tool_provider.dart new file mode 100644 index 00000000..402b5faa --- /dev/null +++ b/lib/core/providers/object/tools/clipping_tool_provider.dart @@ -0,0 +1,26 @@ +import 'package:riverpod_annotation/riverpod_annotation.dart'; + +import 'package:paintroid/core/commands/command_factory/command_factory_provider.dart'; +import 'package:paintroid/core/commands/command_manager/command_manager_provider.dart'; +import 'package:paintroid/core/commands/graphic_factory/graphic_factory_provider.dart'; +import 'package:paintroid/core/enums/tool_types.dart'; +import 'package:paintroid/core/tools/implementation/clipping_tool.dart'; +import 'package:paintroid/core/providers/object/tools/clipping_tool_state_provider.dart'; +import 'package:paintroid/core/providers/state/canvas_state_provider.dart'; + +part 'clipping_tool_provider.g.dart'; + +@riverpod +class ClippingToolProvider extends _$ClippingToolProvider { + @override + ClippingTool build() { + return ClippingTool( + commandManager: ref.watch(commandManagerProvider), + commandFactory: ref.watch(commandFactoryProvider), + graphicFactory: ref.watch(graphicFactoryProvider), + clippingToolState: ref.watch(clippingToolState.notifier), + canvasStateProvider: ref.watch(canvasStateProvider.notifier), + type: ToolType.CLIPPING, + ); + } +} diff --git a/lib/core/providers/object/tools/clipping_tool_provider.g.dart b/lib/core/providers/object/tools/clipping_tool_provider.g.dart new file mode 100644 index 00000000..f46fddd5 --- /dev/null +++ b/lib/core/providers/object/tools/clipping_tool_provider.g.dart @@ -0,0 +1,27 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'clipping_tool_provider.dart'; + +// ************************************************************************** +// RiverpodGenerator +// ************************************************************************** + +String _$clippingToolProviderHash() => + r'10381b6a787aef98e726b246d488001814bcb1e5'; + +/// See also [ClippingToolProvider]. +@ProviderFor(ClippingToolProvider) +final clippingToolProvider = + AutoDisposeNotifierProvider.internal( + ClippingToolProvider.new, + name: r'clippingToolProvider', + debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product') + ? null + : _$clippingToolProviderHash, + dependencies: null, + allTransitiveDependencies: null, +); + +typedef _$ClippingToolProvider = AutoDisposeNotifier; +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package diff --git a/lib/core/providers/object/tools/clipping_tool_state_provider.dart b/lib/core/providers/object/tools/clipping_tool_state_provider.dart new file mode 100644 index 00000000..203d4381 --- /dev/null +++ b/lib/core/providers/object/tools/clipping_tool_state_provider.dart @@ -0,0 +1,21 @@ +import 'package:riverpod_annotation/riverpod_annotation.dart'; + +part 'clipping_tool_state_provider.g.dart'; + +@riverpod +class ClippingToolState extends _$ClippingToolState { + @override + bool build() { + return false; + } + + void setHasActiveClipPath(bool hasActive) { + state = hasActive; + } + + void clearClipPath() { + state = false; + } + + bool get hasActiveClipPath => state; +} diff --git a/lib/core/providers/object/tools/clipping_tool_state_provider.g.dart b/lib/core/providers/object/tools/clipping_tool_state_provider.g.dart new file mode 100644 index 00000000..8cf879e7 --- /dev/null +++ b/lib/core/providers/object/tools/clipping_tool_state_provider.g.dart @@ -0,0 +1,26 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'clipping_tool_state_provider.dart'; + +// ************************************************************************** +// RiverpodGenerator +// ************************************************************************** + +String _$clippingToolStateHash() => r'd6a9d9e023dc616a6a7eb99c55b38590d14b2311'; + +/// See also [ClippingToolState]. +@ProviderFor(ClippingToolState) +final clippingToolState = + AutoDisposeNotifierProvider.internal( + ClippingToolState.new, + name: r'clippingToolState', + debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product') + ? null + : _$clippingToolStateHash, + dependencies: null, + allTransitiveDependencies: null, +); + +typedef _$ClippingToolState = AutoDisposeNotifier; +// ignore_for_file: type=lint +// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, deprecated_member_use_from_same_package diff --git a/lib/core/providers/state/toolbox_state_provider.dart b/lib/core/providers/state/toolbox_state_provider.dart index e051305a..debd4137 100644 --- a/lib/core/providers/state/toolbox_state_provider.dart +++ b/lib/core/providers/state/toolbox_state_provider.dart @@ -4,6 +4,7 @@ import 'package:paintroid/core/commands/command_manager/command_manager_provider import 'package:paintroid/core/enums/tool_types.dart'; import 'package:paintroid/core/providers/object/canvas_painter_provider.dart'; import 'package:paintroid/core/providers/object/tools/brush_tool_provider.dart'; +import 'package:paintroid/core/providers/object/tools/clipping_tool_provider.dart'; import 'package:paintroid/core/providers/object/tools/clipboard_tool_provider.dart'; import 'package:paintroid/core/providers/object/tools/eraser_tool_provider.dart'; import 'package:paintroid/core/providers/object/tools/hand_tool_provider.dart'; @@ -86,6 +87,8 @@ class ToolBoxStateProvider extends _$ToolBoxStateProvider { (state.currentTool as SprayTool).updateSprayRadius(currentStrokeWidth); ref.read(paintProvider.notifier).updateStrokeWidth(SPRAY_TOOL_RADIUS); break; + case ToolType.CLIPPING: + state = state.copyWith(currentTool: ref.read(clippingToolProvider)); case ToolType.CLIPBOARD: state = state.copyWith(currentTool: ref.read(clipboardToolProvider)); ref.read(canvasPainterProvider.notifier).repaint(); diff --git a/lib/core/providers/state/toolbox_state_provider.g.dart b/lib/core/providers/state/toolbox_state_provider.g.dart index d75b380b..cdf5d9b8 100644 --- a/lib/core/providers/state/toolbox_state_provider.g.dart +++ b/lib/core/providers/state/toolbox_state_provider.g.dart @@ -7,7 +7,7 @@ part of 'toolbox_state_provider.dart'; // ************************************************************************** String _$toolBoxStateProviderHash() => - r'206acf9ae4e9afd5aead49ae432264b37e7c63ab'; + r'0245a09ab87b5d06c4389850c356b6f2ff284fca'; /// See also [ToolBoxStateProvider]. @ProviderFor(ToolBoxStateProvider) diff --git a/lib/core/tools/implementation/clipping_tool.dart b/lib/core/tools/implementation/clipping_tool.dart new file mode 100644 index 00000000..f7187ace --- /dev/null +++ b/lib/core/tools/implementation/clipping_tool.dart @@ -0,0 +1,227 @@ +import 'dart:ui'; + +import 'package:flutter/foundation.dart'; +import 'package:paintroid/core/commands/command_implementation/graphic/graphic_command.dart'; +import 'package:paintroid/core/commands/graphic_factory/graphic_factory.dart'; +import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/providers/state/canvas_state_provider.dart'; +import 'package:paintroid/core/tools/tool.dart'; +import 'package:paintroid/core/enums/tool_types.dart'; +import 'package:paintroid/core/providers/object/tools/clipping_tool_state_provider.dart'; + +class ClippingTool extends Tool { + final GraphicFactory graphicFactory; + final ClippingToolState clippingToolState; + final CanvasStateProvider canvasStateProvider; + + @visibleForTesting + late PathWithActionHistory pathToDraw; + Offset? _startPoint; + GraphicCommand? _activePreviewCommand; + GraphicCommand? _liveDrawingCommand; + + ClippingTool({ + required super.commandFactory, + required super.commandManager, + required this.graphicFactory, + required this.clippingToolState, + required this.canvasStateProvider, + super.type = ToolType.CLIPPING, + super.hasAddFunctionality = false, + super.hasFinalizeFunctionality = true, + }); + + @override + void onDown(Offset point, Paint paint) { + bool requiresRefresh = false; + if (clippingToolState.hasActiveClipPath) { + if (_activePreviewCommand != null) { + commandManager.removeCommand(_activePreviewCommand!); + _activePreviewCommand = null; + requiresRefresh = true; + } + clippingToolState.clearClipPath(); + } + + if (_liveDrawingCommand != null) { + commandManager.removeCommand(_liveDrawingCommand!); + _liveDrawingCommand = null; + requiresRefresh = true; + } + + if (requiresRefresh) { + canvasStateProvider.resetCanvasWithExistingCommands(); + } + + _startPoint = point; + pathToDraw = graphicFactory.createPathWithActionHistory() + ..moveTo(point.dx, point.dy); + + final newLiveDrawingCommand = + commandFactory.createClipPathCommand(pathToDraw, paint); + commandManager.addGraphicCommand(newLiveDrawingCommand); + _liveDrawingCommand = newLiveDrawingCommand; + } + + @override + void onDrag(Offset point, Paint paint) { + pathToDraw.lineTo(point.dx, point.dy); + } + + @override + void onUp(Offset point, Paint paint) { + bool requiresRefresh = false; + if (_liveDrawingCommand != null) { + commandManager.removeCommand(_liveDrawingCommand!); + _liveDrawingCommand = null; + requiresRefresh = true; + } + + bool pointAddedInUp = false; + if (pathToDraw.actions.isNotEmpty) { + final lastAction = pathToDraw.actions.last; + bool isSameAsLastPoint = false; + + if (lastAction is LineToAction) { + isSameAsLastPoint = + (lastAction.x == point.dx && lastAction.y == point.dy); + } else if (lastAction is MoveToAction && pathToDraw.actions.length == 1) { + isSameAsLastPoint = + (lastAction.x == point.dx && lastAction.y == point.dy); + } + + if (!isSameAsLastPoint) { + pathToDraw.lineTo(point.dx, point.dy); + pointAddedInUp = true; + } + } else { + pathToDraw.moveTo(point.dx, point.dy); + pathToDraw.lineTo(point.dx, point.dy); + pointAddedInUp = true; + } + + Offset currentEndPoint = point; + if (pathToDraw.actions.isNotEmpty) { + if (pathToDraw.actions.last is LineToAction) { + final lastLineTo = pathToDraw.actions.last as LineToAction; + currentEndPoint = Offset(lastLineTo.x, lastLineTo.y); + } else if (pathToDraw.actions.last is MoveToAction) { + final lastMoveTo = pathToDraw.actions.last as MoveToAction; + currentEndPoint = Offset(lastMoveTo.x, lastMoveTo.y); + } + } + + GraphicCommand newPreviewCommand; + if (_startPoint != null && pathToDraw.actions.isNotEmpty) { + bool needsSolidClosingLine = !(currentEndPoint.dx == _startPoint!.dx && + currentEndPoint.dy == _startPoint!.dy); + + bool isEffectivelySingleTap = + pathToDraw.actions.length <= (pointAddedInUp ? 2 : 1) && + (currentEndPoint.dx == _startPoint!.dx && + currentEndPoint.dy == _startPoint!.dy); + + if (needsSolidClosingLine && !isEffectivelySingleTap) { + newPreviewCommand = commandFactory.createClipPathCommand( + pathToDraw, + paint, + startPoint: currentEndPoint, + endPoint: _startPoint!, + ); + } else { + pathToDraw.close(); + newPreviewCommand = commandFactory.createClipPathCommand( + pathToDraw, + paint, + ); + } + } else { + pathToDraw.close(); + newPreviewCommand = commandFactory.createClipPathCommand( + pathToDraw, + paint, + ); + } + commandManager.addGraphicCommand(newPreviewCommand); + _activePreviewCommand = newPreviewCommand; + clippingToolState.setHasActiveClipPath(true); + _startPoint = null; + + if (requiresRefresh) { + canvasStateProvider.resetCanvasWithExistingCommands(); + } + canvasStateProvider.updateCachedImage(); + } + + @override + void onCancel() { + bool requiresRefresh = false; + if (_liveDrawingCommand != null) { + commandManager.removeCommand(_liveDrawingCommand!); + _liveDrawingCommand = null; + requiresRefresh = true; + } + + if (clippingToolState.hasActiveClipPath) { + if (_activePreviewCommand != null) { + commandManager.removeCommand(_activePreviewCommand!); + _activePreviewCommand = null; + requiresRefresh = true; + } + clippingToolState.clearClipPath(); + } + + if (requiresRefresh) { + canvasStateProvider.resetCanvasWithExistingCommands(); + } + _startPoint = null; + } + + @override + void onCheckmark(Paint paint) { + bool requiresRefresh = false; + if (clippingToolState.hasActiveClipPath) { + if (_activePreviewCommand != null) { + commandManager.removeCommand(_activePreviewCommand!); + _activePreviewCommand = null; + requiresRefresh = true; + } + clippingToolState.clearClipPath(); + } + + if (_liveDrawingCommand != null) { + commandManager.removeCommand(_liveDrawingCommand!); + _liveDrawingCommand = null; + requiresRefresh = true; + } + + if (pathToDraw.actions.isNotEmpty) { + pathToDraw.close(); + + final cropCommand = + commandFactory.createClipAreaCommand(pathToDraw, paint); + commandManager.addGraphicCommand(cropCommand); + requiresRefresh = true; + } + + if (requiresRefresh) { + canvasStateProvider.resetCanvasWithExistingCommands(); + } + _startPoint = null; + } + + @override + void onPlus() {} + + @override + void onRedo() { + commandManager.redo(); + canvasStateProvider.resetCanvasWithExistingCommands(); + } + + @override + void onUndo() { + commandManager.undo(); + canvasStateProvider.resetCanvasWithExistingCommands(); + } +} diff --git a/lib/ui/pages/workspace_page/components/bottom_bar/tool_options/tool_options.dart b/lib/ui/pages/workspace_page/components/bottom_bar/tool_options/tool_options.dart index d1343033..1b89adf5 100644 --- a/lib/ui/pages/workspace_page/components/bottom_bar/tool_options/tool_options.dart +++ b/lib/ui/pages/workspace_page/components/bottom_bar/tool_options/tool_options.dart @@ -39,6 +39,7 @@ class ToolOptions extends ConsumerWidget { ToolType.SPRAY => const SprayToolOptions(), ToolType.CLIPBOARD => const ClipboardToolOptions(), ToolType.TEXT => const TextToolOptions(), + ToolType.CLIPPING => const StrokeToolOptions(), _ => Container(), }, ), diff --git a/lib/ui/pages/workspace_page/components/top_bar/top_app_bar.dart b/lib/ui/pages/workspace_page/components/top_bar/top_app_bar.dart index 319a2f39..e0039ff7 100644 --- a/lib/ui/pages/workspace_page/components/top_bar/top_app_bar.dart +++ b/lib/ui/pages/workspace_page/components/top_bar/top_app_bar.dart @@ -74,7 +74,7 @@ class TopAppBar extends ConsumerWidget implements PreferredSizeWidget { currentTool is LineTool && currentTool.vertexStack.isNotEmpty; final isShapeTool = currentTool.type == ToolType.SHAPES; final isTextTool = currentTool is TextTool; - if (isLineTool || isShapeTool || isTextTool) { + if (isLineTool || isShapeTool || isTextTool || currentTool.type == ToolType.CLIPPING) { return () { currentTool.onCheckmark(ref.read(paintProvider)); ref.read(appBarProvider.notifier).update(); diff --git a/test/integration/clipping_tool_test.dart b/test/integration/clipping_tool_test.dart new file mode 100644 index 00000000..ad9310b5 --- /dev/null +++ b/test/integration/clipping_tool_test.dart @@ -0,0 +1,140 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:paintroid/app.dart'; +import 'package:paintroid/core/tools/tool_data.dart'; +import 'package:paintroid/core/utils/color_utils.dart'; + +import '../utils/canvas_positions.dart'; +import '../utils/ui_interaction.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + const String testIDStr = String.fromEnvironment('id', defaultValue: '-1'); + final testID = int.tryParse(testIDStr) ?? testIDStr; + + late Widget sut; + + setUp(() async { + sut = ProviderScope( + child: App( + showOnboardingPage: false, + ), + ); + }); + + if (testID == -1 || testID == 0) { + testWidgets('[CLIPPING_TOOL]: clip a part of the image', + (WidgetTester tester) async { + UIInteraction.initialize(tester); + await tester.pumpWidget(sut); + await UIInteraction.createNewImage(); + UIInteraction.setColor(Colors.black); + await UIInteraction.selectTool(ToolData.BRUSH.name); + + await UIInteraction.dragFromTo( + CanvasPosition.topLeft, + CanvasPosition.bottomRight, + ); + + await UIInteraction.selectTool(ToolData.CLIPPING.name); + + final Offset center = CanvasPosition.center; + final Offset p1 = center + const Offset(-50, -50); + final Offset p2 = center + const Offset(50, -50); + final Offset p3 = center + const Offset(50, 50); + final Offset p4 = center + const Offset(-50, 50); + + final TestGesture gesture = await tester.startGesture(p1); + await tester.pumpAndSettle(); + await gesture.moveTo(p2); + await tester.pumpAndSettle(); + await gesture.moveTo(p3); + await tester.pumpAndSettle(); + await gesture.moveTo(p4); + await tester.pumpAndSettle(); + await gesture.moveTo(p1); + await tester.pumpAndSettle(); + await gesture.up(); + await tester.pumpAndSettle(); + + await UIInteraction.clickCheckmark(); + + var centerColor = await UIInteraction.getPixelColor( + CanvasPosition.centerX, + CanvasPosition.centerY, + ); + expect(centerColor.toValue(), Colors.black.toValue()); + + var topLeftColor = await UIInteraction.getPixelColor( + CanvasPosition.left, + CanvasPosition.top, + ); + expect(topLeftColor.toValue(), Colors.transparent.toValue()); + + var bottomRightColor = await UIInteraction.getPixelColor( + CanvasPosition.right, + CanvasPosition.bottom, + ); + expect(bottomRightColor.toValue(), Colors.transparent.toValue()); + }); + } + + if (testID == -1 || testID == 1) { + testWidgets('[CLIPPING_TOOL]: cancel clipping', + (WidgetTester tester) async { + UIInteraction.initialize(tester); + await tester.pumpWidget(sut); + await UIInteraction.createNewImage(); + UIInteraction.setColor(Colors.black); + await UIInteraction.selectTool(ToolData.BRUSH.name); + + await UIInteraction.dragFromTo( + CanvasPosition.topLeft, + CanvasPosition.bottomRight, + ); + + await UIInteraction.selectTool(ToolData.CLIPPING.name); + + final Offset center = CanvasPosition.center; + final Offset p1 = center + const Offset(-50, -50); + final Offset p2 = center + const Offset(50, -50); + final Offset p3 = center + const Offset(50, 50); + final Offset p4 = center + const Offset(-50, 50); + + final TestGesture gesture = await tester.startGesture(p1); + await tester.pumpAndSettle(); + await gesture.moveTo(p2); + await tester.pumpAndSettle(); + await gesture.moveTo(p3); + await tester.pumpAndSettle(); + await gesture.moveTo(p4); + await tester.pumpAndSettle(); + await gesture.moveTo(p1); + await tester.pumpAndSettle(); + await gesture.up(); + await tester.pumpAndSettle(); + await UIInteraction.clickBackButton(); + + var centerColor = await UIInteraction.getPixelColor( + CanvasPosition.centerX, + CanvasPosition.centerY, + ); + expect(centerColor.toValue(), Colors.black.toValue()); + + var topLeftColor = await UIInteraction.getPixelColor( + CanvasPosition.left, + CanvasPosition.top, + ); + expect(topLeftColor.toValue(), Colors.black.toValue()); + + var bottomRightColor = await UIInteraction.getPixelColor( + CanvasPosition.right, + CanvasPosition.bottom, + ); + expect(bottomRightColor.toValue(), Colors.black.toValue()); + }); + } +} diff --git a/test/unit/serialization/utils/dummy_version_strategy.dart b/test/unit/serialization/utils/dummy_version_strategy.dart index e1a78232..786f5543 100644 --- a/test/unit/serialization/utils/dummy_version_strategy.dart +++ b/test/unit/serialization/utils/dummy_version_strategy.dart @@ -13,6 +13,8 @@ class DummyVersionStrategy implements IVersionStrategy { final int clipboardCommandVersion; final int deleteRegionCommandVersion; final int textCommandVersion; + final int clipPathCommandVersion; + final int clipAreaCommandVersion; DummyVersionStrategy({ this.pathCommandVersion = SerializerVersion.PATH_COMMAND_VERSION, @@ -30,6 +32,8 @@ class DummyVersionStrategy implements IVersionStrategy { this.deleteRegionCommandVersion = SerializerVersion.DELETE_REGION_COMMAND_VERSION, this.textCommandVersion = SerializerVersion.TEXT_COMMAND_VERSION, + this.clipPathCommandVersion = SerializerVersion.CLIP_PATH_COMMAND_VERSION, + this.clipAreaCommandVersion = SerializerVersion.CLIP_AREA_COMMAND_VERSION, }); @override @@ -64,4 +68,10 @@ class DummyVersionStrategy implements IVersionStrategy { @override int getTextCommandVersion() => textCommandVersion; + + @override + int getClipPathCommandVersion() => clipPathCommandVersion; + + @override + int getClipAreaCommandVersion() => clipAreaCommandVersion; } diff --git a/test/unit/tools/clipboard_tool_test.mocks.dart b/test/unit/tools/clipboard_tool_test.mocks.dart index f5c42016..c4f87772 100644 --- a/test/unit/tools/clipboard_tool_test.mocks.dart +++ b/test/unit/tools/clipboard_tool_test.mocks.dart @@ -3,48 +3,52 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i28; -import 'dart:typed_data' as _i26; +import 'dart:async' as _i30; +import 'dart:typed_data' as _i28; import 'dart:ui' as _i2; -import 'package:flutter/material.dart' as _i27; -import 'package:logging/logging.dart' as _i15; +import 'package:flutter/material.dart' as _i29; +import 'package:logging/logging.dart' as _i17; import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i19; +import 'package:mockito/src/dummies.dart' as _i21; import 'package:paintroid/core/commands/command_factory/command_factory.dart' - as _i23; + as _i25; import 'package:paintroid/core/commands/command_implementation/command.dart' as _i3; +import 'package:paintroid/core/commands/command_implementation/graphic/clip_area_command.dart' + as _i15; +import 'package:paintroid/core/commands/command_implementation/graphic/clip_path_command.dart' + as _i6; import 'package:paintroid/core/commands/command_implementation/graphic/clipboard_command.dart' - as _i9; + as _i10; import 'package:paintroid/core/commands/command_implementation/graphic/delete_region_command.dart' - as _i14; + as _i16; import 'package:paintroid/core/commands/command_implementation/graphic/graphic_command.dart' - as _i21; + as _i23; import 'package:paintroid/core/commands/command_implementation/graphic/line_command.dart' - as _i6; + as _i7; import 'package:paintroid/core/commands/command_implementation/graphic/path_command.dart' as _i5; import 'package:paintroid/core/commands/command_implementation/graphic/shape/ellipse_shape_command.dart' - as _i8; + as _i9; import 'package:paintroid/core/commands/command_implementation/graphic/shape/heart_shape_command.dart' - as _i12; + as _i13; import 'package:paintroid/core/commands/command_implementation/graphic/shape/square_shape_command.dart' - as _i7; + as _i8; import 'package:paintroid/core/commands/command_implementation/graphic/shape/star_shape_command.dart' - as _i11; + as _i12; import 'package:paintroid/core/commands/command_implementation/graphic/spray_command.dart' - as _i13; + as _i14; import 'package:paintroid/core/commands/command_implementation/graphic/text_command.dart' - as _i10; + as _i11; import 'package:paintroid/core/commands/command_manager/command_manager.dart' - as _i20; -import 'package:paintroid/core/commands/path_with_action_history.dart' as _i24; -import 'package:paintroid/core/enums/bounding_box_action.dart' as _i17; -import 'package:paintroid/core/enums/bounding_box_resize_action.dart' as _i18; -import 'package:paintroid/core/enums/shape_style.dart' as _i25; -import 'package:paintroid/core/tools/bounding_box.dart' as _i16; -import 'package:paintroid/core/tools/line_tool/vertex_stack.dart' as _i22; + as _i22; +import 'package:paintroid/core/commands/path_with_action_history.dart' as _i26; +import 'package:paintroid/core/enums/bounding_box_action.dart' as _i19; +import 'package:paintroid/core/enums/bounding_box_resize_action.dart' as _i20; +import 'package:paintroid/core/enums/shape_style.dart' as _i27; +import 'package:paintroid/core/tools/bounding_box.dart' as _i18; +import 'package:paintroid/core/tools/line_tool/vertex_stack.dart' as _i24; import 'package:paintroid/core/tools/tool_data.dart' as _i4; // ignore_for_file: type=lint @@ -111,8 +115,9 @@ class _FakePathCommand_4 extends _i1.SmartFake implements _i5.PathCommand { ); } -class _FakeLineCommand_5 extends _i1.SmartFake implements _i6.LineCommand { - _FakeLineCommand_5( +class _FakeClipPathCommand_5 extends _i1.SmartFake + implements _i6.ClipPathCommand { + _FakeClipPathCommand_5( Object parent, Invocation parentInvocation, ) : super( @@ -121,9 +126,8 @@ class _FakeLineCommand_5 extends _i1.SmartFake implements _i6.LineCommand { ); } -class _FakeSquareShapeCommand_6 extends _i1.SmartFake - implements _i7.SquareShapeCommand { - _FakeSquareShapeCommand_6( +class _FakeLineCommand_6 extends _i1.SmartFake implements _i7.LineCommand { + _FakeLineCommand_6( Object parent, Invocation parentInvocation, ) : super( @@ -132,9 +136,9 @@ class _FakeSquareShapeCommand_6 extends _i1.SmartFake ); } -class _FakeEllipseShapeCommand_7 extends _i1.SmartFake - implements _i8.EllipseShapeCommand { - _FakeEllipseShapeCommand_7( +class _FakeSquareShapeCommand_7 extends _i1.SmartFake + implements _i8.SquareShapeCommand { + _FakeSquareShapeCommand_7( Object parent, Invocation parentInvocation, ) : super( @@ -143,9 +147,9 @@ class _FakeEllipseShapeCommand_7 extends _i1.SmartFake ); } -class _FakeClipboardCommand_8 extends _i1.SmartFake - implements _i9.ClipboardCommand { - _FakeClipboardCommand_8( +class _FakeEllipseShapeCommand_8 extends _i1.SmartFake + implements _i9.EllipseShapeCommand { + _FakeEllipseShapeCommand_8( Object parent, Invocation parentInvocation, ) : super( @@ -154,8 +158,9 @@ class _FakeClipboardCommand_8 extends _i1.SmartFake ); } -class _FakeTextCommand_9 extends _i1.SmartFake implements _i10.TextCommand { - _FakeTextCommand_9( +class _FakeClipboardCommand_9 extends _i1.SmartFake + implements _i10.ClipboardCommand { + _FakeClipboardCommand_9( Object parent, Invocation parentInvocation, ) : super( @@ -164,9 +169,8 @@ class _FakeTextCommand_9 extends _i1.SmartFake implements _i10.TextCommand { ); } -class _FakeStarShapeCommand_10 extends _i1.SmartFake - implements _i11.StarShapeCommand { - _FakeStarShapeCommand_10( +class _FakeTextCommand_10 extends _i1.SmartFake implements _i11.TextCommand { + _FakeTextCommand_10( Object parent, Invocation parentInvocation, ) : super( @@ -175,9 +179,9 @@ class _FakeStarShapeCommand_10 extends _i1.SmartFake ); } -class _FakeHeartShapeCommand_11 extends _i1.SmartFake - implements _i12.HeartShapeCommand { - _FakeHeartShapeCommand_11( +class _FakeStarShapeCommand_11 extends _i1.SmartFake + implements _i12.StarShapeCommand { + _FakeStarShapeCommand_11( Object parent, Invocation parentInvocation, ) : super( @@ -186,8 +190,9 @@ class _FakeHeartShapeCommand_11 extends _i1.SmartFake ); } -class _FakeSprayCommand_12 extends _i1.SmartFake implements _i13.SprayCommand { - _FakeSprayCommand_12( +class _FakeHeartShapeCommand_12 extends _i1.SmartFake + implements _i13.HeartShapeCommand { + _FakeHeartShapeCommand_12( Object parent, Invocation parentInvocation, ) : super( @@ -196,9 +201,8 @@ class _FakeSprayCommand_12 extends _i1.SmartFake implements _i13.SprayCommand { ); } -class _FakeDeleteRegionCommand_13 extends _i1.SmartFake - implements _i14.DeleteRegionCommand { - _FakeDeleteRegionCommand_13( +class _FakeSprayCommand_13 extends _i1.SmartFake implements _i14.SprayCommand { + _FakeSprayCommand_13( Object parent, Invocation parentInvocation, ) : super( @@ -207,8 +211,9 @@ class _FakeDeleteRegionCommand_13 extends _i1.SmartFake ); } -class _FakeLogger_14 extends _i1.SmartFake implements _i15.Logger { - _FakeLogger_14( +class _FakeClipAreaCommand_14 extends _i1.SmartFake + implements _i15.ClipAreaCommand { + _FakeClipAreaCommand_14( Object parent, Invocation parentInvocation, ) : super( @@ -217,8 +222,29 @@ class _FakeLogger_14 extends _i1.SmartFake implements _i15.Logger { ); } -class _FakeImage_15 extends _i1.SmartFake implements _i2.Image { - _FakeImage_15( +class _FakeDeleteRegionCommand_15 extends _i1.SmartFake + implements _i16.DeleteRegionCommand { + _FakeDeleteRegionCommand_15( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeLogger_16 extends _i1.SmartFake implements _i17.Logger { + _FakeLogger_16( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeImage_17 extends _i1.SmartFake implements _i2.Image { + _FakeImage_17( Object parent, Invocation parentInvocation, ) : super( @@ -230,7 +256,7 @@ class _FakeImage_15 extends _i1.SmartFake implements _i2.Image { /// A class which mocks [BoundingBox]. /// /// See the documentation for Mockito's code generation for more information. -class MockBoundingBox extends _i1.Mock implements _i16.BoundingBox { +class MockBoundingBox extends _i1.Mock implements _i18.BoundingBox { MockBoundingBox() { _i1.throwOnMissingStub(this); } @@ -299,13 +325,13 @@ class MockBoundingBox extends _i1.Mock implements _i16.BoundingBox { ); @override - _i17.BoundingBoxAction get currentAction => (super.noSuchMethod( + _i19.BoundingBoxAction get currentAction => (super.noSuchMethod( Invocation.getter(#currentAction), - returnValue: _i17.BoundingBoxAction.none, - ) as _i17.BoundingBoxAction); + returnValue: _i19.BoundingBoxAction.none, + ) as _i19.BoundingBoxAction); @override - set currentAction(_i17.BoundingBoxAction? _currentAction) => + set currentAction(_i19.BoundingBoxAction? _currentAction) => super.noSuchMethod( Invocation.setter( #currentAction, @@ -315,15 +341,15 @@ class MockBoundingBox extends _i1.Mock implements _i16.BoundingBox { ); @override - _i18.BoundingBoxResizeAction get currentBoundingBoxResizeAction => + _i20.BoundingBoxResizeAction get currentBoundingBoxResizeAction => (super.noSuchMethod( Invocation.getter(#currentBoundingBoxResizeAction), - returnValue: _i18.BoundingBoxResizeAction.none, - ) as _i18.BoundingBoxResizeAction); + returnValue: _i20.BoundingBoxResizeAction.none, + ) as _i20.BoundingBoxResizeAction); @override set currentBoundingBoxResizeAction( - _i18.BoundingBoxResizeAction? _currentBoundingBoxResizeAction) => + _i20.BoundingBoxResizeAction? _currentBoundingBoxResizeAction) => super.noSuchMethod( Invocation.setter( #currentBoundingBoxResizeAction, @@ -371,7 +397,7 @@ class MockBoundingBox extends _i1.Mock implements _i16.BoundingBox { @override _i2.Paint get boxPaint => (super.noSuchMethod( Invocation.getter(#boxPaint), - returnValue: _i19.dummyValue<_i2.Paint>( + returnValue: _i21.dummyValue<_i2.Paint>( this, Invocation.getter(#boxPaint), ), @@ -389,7 +415,7 @@ class MockBoundingBox extends _i1.Mock implements _i16.BoundingBox { @override _i2.Paint get handlePaint => (super.noSuchMethod( Invocation.getter(#handlePaint), - returnValue: _i19.dummyValue<_i2.Paint>( + returnValue: _i21.dummyValue<_i2.Paint>( this, Invocation.getter(#handlePaint), ), @@ -407,7 +433,7 @@ class MockBoundingBox extends _i1.Mock implements _i16.BoundingBox { @override _i2.Paint get rotationHandlePaint => (super.noSuchMethod( Invocation.getter(#rotationHandlePaint), - returnValue: _i19.dummyValue<_i2.Paint>( + returnValue: _i21.dummyValue<_i2.Paint>( this, Invocation.getter(#rotationHandlePaint), ), @@ -496,7 +522,7 @@ class MockBoundingBox extends _i1.Mock implements _i16.BoundingBox { /// A class which mocks [CommandManager]. /// /// See the documentation for Mockito's code generation for more information. -class MockCommandManager extends _i1.Mock implements _i20.CommandManager { +class MockCommandManager extends _i1.Mock implements _i22.CommandManager { MockCommandManager() { _i1.throwOnMissingStub(this); } @@ -514,7 +540,7 @@ class MockCommandManager extends _i1.Mock implements _i20.CommandManager { ) as List<_i3.Command>); @override - void addGraphicCommand(_i21.GraphicCommand? command) => super.noSuchMethod( + void addGraphicCommand(_i23.GraphicCommand? command) => super.noSuchMethod( Invocation.method( #addGraphicCommand, [command], @@ -522,6 +548,15 @@ class MockCommandManager extends _i1.Mock implements _i20.CommandManager { returnValueForMissingStub: null, ); + @override + void removeCommand(_i3.Command? commandToRemove) => super.noSuchMethod( + Invocation.method( + #removeCommand, + [commandToRemove], + ), + returnValueForMissingStub: null, + ); + @override void setUndoStack(List<_i3.Command>? commands) => super.noSuchMethod( Invocation.method( @@ -581,8 +616,8 @@ class MockCommandManager extends _i1.Mock implements _i20.CommandManager { @override void drawLineToolGhostPaths( _i2.Canvas? canvas, - _i6.LineCommand? ingoingGhostPathCommand, - _i6.LineCommand? outgoingGhostPathCommand, + _i7.LineCommand? ingoingGhostPathCommand, + _i7.LineCommand? outgoingGhostPathCommand, ) => super.noSuchMethod( Invocation.method( @@ -599,7 +634,7 @@ class MockCommandManager extends _i1.Mock implements _i20.CommandManager { @override void drawLineToolVertices( _i2.Canvas? canvas, - _i22.VertexStack? vertexStack, + _i24.VertexStack? vertexStack, ) => super.noSuchMethod( Invocation.method( @@ -637,7 +672,7 @@ class MockCommandManager extends _i1.Mock implements _i20.CommandManager { ); @override - _i4.ToolData getNextTool(_i20.ActionType? actionType) => (super.noSuchMethod( + _i4.ToolData getNextTool(_i22.ActionType? actionType) => (super.noSuchMethod( Invocation.method( #getNextTool, [actionType], @@ -652,26 +687,26 @@ class MockCommandManager extends _i1.Mock implements _i20.CommandManager { ) as _i4.ToolData); @override - List<_i6.LineCommand> getTopLineCommandSequence() => (super.noSuchMethod( + List<_i7.LineCommand> getTopLineCommandSequence() => (super.noSuchMethod( Invocation.method( #getTopLineCommandSequence, [], ), - returnValue: <_i6.LineCommand>[], - ) as List<_i6.LineCommand>); + returnValue: <_i7.LineCommand>[], + ) as List<_i7.LineCommand>); } /// A class which mocks [CommandFactory]. /// /// See the documentation for Mockito's code generation for more information. -class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { +class MockCommandFactory extends _i1.Mock implements _i25.CommandFactory { MockCommandFactory() { _i1.throwOnMissingStub(this); } @override _i5.PathCommand createPathCommand( - _i24.PathWithActionHistory? path, + _i26.PathWithActionHistory? path, _i2.Paint? paint, ) => (super.noSuchMethod( @@ -695,8 +730,43 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { ) as _i5.PathCommand); @override - _i6.LineCommand createLineCommand( - _i24.PathWithActionHistory? path, + _i6.ClipPathCommand createClipPathCommand( + _i26.PathWithActionHistory? path, + _i2.Paint? paint, { + _i2.Offset? startPoint, + _i2.Offset? endPoint, + }) => + (super.noSuchMethod( + Invocation.method( + #createClipPathCommand, + [ + path, + paint, + ], + { + #startPoint: startPoint, + #endPoint: endPoint, + }, + ), + returnValue: _FakeClipPathCommand_5( + this, + Invocation.method( + #createClipPathCommand, + [ + path, + paint, + ], + { + #startPoint: startPoint, + #endPoint: endPoint, + }, + ), + ), + ) as _i6.ClipPathCommand); + + @override + _i7.LineCommand createLineCommand( + _i26.PathWithActionHistory? path, _i2.Paint? paint, _i2.Offset? startPoint, _i2.Offset? endPoint, @@ -711,7 +781,7 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { endPoint, ], ), - returnValue: _FakeLineCommand_5( + returnValue: _FakeLineCommand_6( this, Invocation.method( #createLineCommand, @@ -723,16 +793,16 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { ], ), ), - ) as _i6.LineCommand); + ) as _i7.LineCommand); @override - _i7.SquareShapeCommand createSquareShapeCommand( + _i8.SquareShapeCommand createSquareShapeCommand( _i2.Paint? paint, _i2.Offset? topLeft, _i2.Offset? topRight, _i2.Offset? bottomLeft, _i2.Offset? bottomRight, - _i25.ShapeStyle? style, + _i27.ShapeStyle? style, ) => (super.noSuchMethod( Invocation.method( @@ -746,7 +816,7 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { style, ], ), - returnValue: _FakeSquareShapeCommand_6( + returnValue: _FakeSquareShapeCommand_7( this, Invocation.method( #createSquareShapeCommand, @@ -760,15 +830,15 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { ], ), ), - ) as _i7.SquareShapeCommand); + ) as _i8.SquareShapeCommand); @override - _i8.EllipseShapeCommand createEllipseShapeCommand( + _i9.EllipseShapeCommand createEllipseShapeCommand( _i2.Paint? paint, double? radiusX, double? radiusY, _i2.Offset? center, - _i25.ShapeStyle? style, + _i27.ShapeStyle? style, double? angle, ) => (super.noSuchMethod( @@ -783,7 +853,7 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { angle, ], ), - returnValue: _FakeEllipseShapeCommand_7( + returnValue: _FakeEllipseShapeCommand_8( this, Invocation.method( #createEllipseShapeCommand, @@ -797,12 +867,12 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { ], ), ), - ) as _i8.EllipseShapeCommand); + ) as _i9.EllipseShapeCommand); @override - _i9.ClipboardCommand createClipboardCommand( + _i10.ClipboardCommand createClipboardCommand( _i2.Paint? paint, - _i26.Uint8List? imageData, + _i28.Uint8List? imageData, _i2.Offset? offset, double? scale, double? rotation, @@ -818,7 +888,7 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { rotation, ], ), - returnValue: _FakeClipboardCommand_8( + returnValue: _FakeClipboardCommand_9( this, Invocation.method( #createClipboardCommand, @@ -831,13 +901,13 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { ], ), ), - ) as _i9.ClipboardCommand); + ) as _i10.ClipboardCommand); @override - _i10.TextCommand createTextCommand( + _i11.TextCommand createTextCommand( _i2.Offset? point, String? text, - _i27.TextStyle? style, + _i29.TextStyle? style, double? fontSize, _i2.Paint? paint, double? rotationAngle, { @@ -860,7 +930,7 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { #scaleY: scaleY, }, ), - returnValue: _FakeTextCommand_9( + returnValue: _FakeTextCommand_10( this, Invocation.method( #createTextCommand, @@ -878,15 +948,15 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { }, ), ), - ) as _i10.TextCommand); + ) as _i11.TextCommand); @override - _i11.StarShapeCommand createStarShapeCommand( + _i12.StarShapeCommand createStarShapeCommand( _i2.Paint? paint, int? numPoints, double? angle, _i2.Offset? center, - _i25.ShapeStyle? style, + _i27.ShapeStyle? style, double? radiusX, double? radiusY, ) => @@ -903,7 +973,7 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { radiusY, ], ), - returnValue: _FakeStarShapeCommand_10( + returnValue: _FakeStarShapeCommand_11( this, Invocation.method( #createStarShapeCommand, @@ -918,16 +988,16 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { ], ), ), - ) as _i11.StarShapeCommand); + ) as _i12.StarShapeCommand); @override - _i12.HeartShapeCommand createHeartShapeCommand( + _i13.HeartShapeCommand createHeartShapeCommand( _i2.Paint? paint, double? width, double? height, double? angle, _i2.Offset? center, - _i25.ShapeStyle? style, + _i27.ShapeStyle? style, ) => (super.noSuchMethod( Invocation.method( @@ -941,7 +1011,7 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { style, ], ), - returnValue: _FakeHeartShapeCommand_11( + returnValue: _FakeHeartShapeCommand_12( this, Invocation.method( #createHeartShapeCommand, @@ -955,10 +1025,10 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { ], ), ), - ) as _i12.HeartShapeCommand); + ) as _i13.HeartShapeCommand); @override - _i13.SprayCommand createSprayCommand( + _i14.SprayCommand createSprayCommand( List<_i2.Offset>? points, _i2.Paint? paint, ) => @@ -970,7 +1040,7 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { paint, ], ), - returnValue: _FakeSprayCommand_12( + returnValue: _FakeSprayCommand_13( this, Invocation.method( #createSprayCommand, @@ -980,38 +1050,63 @@ class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { ], ), ), - ) as _i13.SprayCommand); + ) as _i14.SprayCommand); + + @override + _i15.ClipAreaCommand createClipAreaCommand( + _i26.PathWithActionHistory? path, + _i2.Paint? paint, + ) => + (super.noSuchMethod( + Invocation.method( + #createClipAreaCommand, + [ + path, + paint, + ], + ), + returnValue: _FakeClipAreaCommand_14( + this, + Invocation.method( + #createClipAreaCommand, + [ + path, + paint, + ], + ), + ), + ) as _i15.ClipAreaCommand); @override - _i14.DeleteRegionCommand createDeleteRegionCommand(_i2.Rect? region) => + _i16.DeleteRegionCommand createDeleteRegionCommand(_i2.Rect? region) => (super.noSuchMethod( Invocation.method( #createDeleteRegionCommand, [region], ), - returnValue: _FakeDeleteRegionCommand_13( + returnValue: _FakeDeleteRegionCommand_15( this, Invocation.method( #createDeleteRegionCommand, [region], ), ), - ) as _i14.DeleteRegionCommand); + ) as _i16.DeleteRegionCommand); } /// A class which mocks [ClipboardCommand]. /// /// See the documentation for Mockito's code generation for more information. -class MockClipboardCommand extends _i1.Mock implements _i9.ClipboardCommand { +class MockClipboardCommand extends _i1.Mock implements _i10.ClipboardCommand { MockClipboardCommand() { _i1.throwOnMissingStub(this); } @override - _i26.Uint8List get imageData => (super.noSuchMethod( + _i28.Uint8List get imageData => (super.noSuchMethod( Invocation.getter(#imageData), - returnValue: _i26.Uint8List(0), - ) as _i26.Uint8List); + returnValue: _i28.Uint8List(0), + ) as _i28.Uint8List); @override _i2.Offset get offset => (super.noSuchMethod( @@ -1043,7 +1138,7 @@ class MockClipboardCommand extends _i1.Mock implements _i9.ClipboardCommand { @override String get type => (super.noSuchMethod( Invocation.getter(#type), - returnValue: _i19.dummyValue( + returnValue: _i21.dummyValue( this, Invocation.getter(#type), ), @@ -1058,30 +1153,30 @@ class MockClipboardCommand extends _i1.Mock implements _i9.ClipboardCommand { @override _i2.Paint get paint => (super.noSuchMethod( Invocation.getter(#paint), - returnValue: _i19.dummyValue<_i2.Paint>( + returnValue: _i21.dummyValue<_i2.Paint>( this, Invocation.getter(#paint), ), ) as _i2.Paint); @override - _i15.Logger get logger => (super.noSuchMethod( + _i17.Logger get logger => (super.noSuchMethod( Invocation.getter(#logger), - returnValue: _FakeLogger_14( + returnValue: _FakeLogger_16( this, Invocation.getter(#logger), ), - ) as _i15.Logger); + ) as _i17.Logger); @override - _i28.Future prepareForRuntime() => (super.noSuchMethod( + _i30.Future prepareForRuntime() => (super.noSuchMethod( Invocation.method( #prepareForRuntime, [], ), - returnValue: _i28.Future.value(), - returnValueForMissingStub: _i28.Future.value(), - ) as _i28.Future); + returnValue: _i30.Future.value(), + returnValueForMissingStub: _i30.Future.value(), + ) as _i30.Future); @override void call(_i2.Canvas? canvas) => super.noSuchMethod( @@ -1144,7 +1239,7 @@ class MockImage extends _i1.Mock implements _i2.Image { ); @override - _i28.Future<_i26.ByteData?> toByteData( + _i30.Future<_i28.ByteData?> toByteData( {_i2.ImageByteFormat? format = _i2.ImageByteFormat.rawRgba}) => (super.noSuchMethod( Invocation.method( @@ -1152,8 +1247,8 @@ class MockImage extends _i1.Mock implements _i2.Image { [], {#format: format}, ), - returnValue: _i28.Future<_i26.ByteData?>.value(), - ) as _i28.Future<_i26.ByteData?>); + returnValue: _i30.Future<_i28.ByteData?>.value(), + ) as _i30.Future<_i28.ByteData?>); @override _i2.Image clone() => (super.noSuchMethod( @@ -1161,7 +1256,7 @@ class MockImage extends _i1.Mock implements _i2.Image { #clone, [], ), - returnValue: _FakeImage_15( + returnValue: _FakeImage_17( this, Invocation.method( #clone, diff --git a/test/unit/tools/clipping_tool_test.dart b/test/unit/tools/clipping_tool_test.dart new file mode 100644 index 00000000..4fc4c46f --- /dev/null +++ b/test/unit/tools/clipping_tool_test.dart @@ -0,0 +1,206 @@ +import 'dart:ui'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:paintroid/core/commands/command_factory/command_factory.dart'; +import 'package:mockito/annotations.dart'; +import 'package:paintroid/core/commands/command_implementation/graphic/clip_area_command.dart'; +import 'package:paintroid/core/commands/command_implementation/graphic/clip_path_command.dart'; +import 'package:paintroid/core/commands/command_implementation/graphic/graphic_command.dart'; +import 'package:paintroid/core/commands/graphic_factory/graphic_factory.dart'; +import 'package:paintroid/core/commands/path_with_action_history.dart'; +import 'package:paintroid/core/providers/state/canvas_state_provider.dart'; +import 'package:paintroid/core/tools/implementation/clipping_tool.dart'; +import 'package:paintroid/core/providers/object/tools/clipping_tool_state_provider.dart'; +import 'package:paintroid/core/commands/command_manager/command_manager.dart'; + +import 'clipping_tool_test.mocks.dart'; + +@GenerateMocks([ + CommandManager, + CommandFactory, + GraphicFactory, + GraphicCommand, + CanvasStateProvider, + ClippingToolState, + PathWithActionHistory, + ClipPathCommand, + ClipAreaCommand, +]) +void main() { + late MockCommandManager commandManager; + late MockCommandFactory commandFactory; + late MockGraphicFactory graphicFactory; + late MockCanvasStateProvider canvasStateProvider; + late MockClippingToolState clippingToolState; + late MockPathWithActionHistory pathMock; + late ClippingTool clippingTool; + late Paint paint; + + setUp(() { + commandManager = MockCommandManager(); + commandFactory = MockCommandFactory(); + graphicFactory = MockGraphicFactory(); + canvasStateProvider = MockCanvasStateProvider(); + clippingToolState = MockClippingToolState(); + pathMock = MockPathWithActionHistory(); + paint = Paint(); + + when(graphicFactory.createPathWithActionHistory()).thenReturn(pathMock); + + when(commandFactory.createClipPathCommand(any, any, + startPoint: anyNamed('startPoint'), endPoint: anyNamed('endPoint'))) + .thenAnswer((_) => MockClipPathCommand()); + when(commandFactory.createClipPathCommand(any, any)) + .thenAnswer((_) => MockClipPathCommand()); + when(commandFactory.createClipAreaCommand(any, any)) + .thenAnswer((_) => MockClipAreaCommand()); + + when(clippingToolState.hasActiveClipPath).thenReturn(false); + when(pathMock.actions).thenReturn([MoveToAction(0, 0)]); + + clippingTool = ClippingTool( + commandFactory: commandFactory, + commandManager: commandManager, + graphicFactory: graphicFactory, + clippingToolState: clippingToolState, + canvasStateProvider: canvasStateProvider, + ); + }); + + group('[CLIPPING_TOOL]: onDown', () { + test( + '[CLIPPING_TOOL]: creates a live drawing command when no active clip path', + () { + when(clippingToolState.hasActiveClipPath).thenReturn(false); + clippingTool.onDown(const Offset(10, 20), paint); + + verify(graphicFactory.createPathWithActionHistory()).called(1); + verify(commandFactory.createClipPathCommand(pathMock, paint)).called(1); + final captured = + verify(commandManager.addGraphicCommand(captureAny)).captured; + expect(captured.single, isA()); + + verifyNever(commandManager.removeCommand(any)); + verifyNever(canvasStateProvider.resetCanvasWithExistingCommands()); + }); + + test( + '[CLIPPING_TOOL]: clears existing preview and creates live drawing command when active clip path exists', + () { + clippingTool.onDown(const Offset(5, 5), paint); + clippingTool.onUp(const Offset(10, 10), paint); + + clearInteractions(commandManager); + clearInteractions(commandFactory); + clearInteractions(graphicFactory); + clearInteractions(canvasStateProvider); + clearInteractions(clippingToolState); + + when(graphicFactory.createPathWithActionHistory()).thenReturn(pathMock); + when(commandFactory.createClipPathCommand(any, any)) + .thenAnswer((_) => MockClipPathCommand()); + when(clippingToolState.hasActiveClipPath).thenReturn(true); + + clippingTool.onDown(const Offset(30, 40), paint); + + final capturedRemove = + verify(commandManager.removeCommand(captureAny)).captured; + expect(capturedRemove.single, isA()); + + verify(clippingToolState.clearClipPath()).called(1); + verify(canvasStateProvider.resetCanvasWithExistingCommands()).called(1); + + verify(graphicFactory.createPathWithActionHistory()).called(1); + verify(commandFactory.createClipPathCommand(pathMock, paint)).called(1); + + final capturedAdd = + verify(commandManager.addGraphicCommand(captureAny)).captured; + expect(capturedAdd.single, isA()); + }); + }); + + test( + '[CLIPPING_TOOL]: onUp removes live command, creates and adds preview command', + () { + when(pathMock.actions).thenReturn([MoveToAction(5, 5)]); + + clippingTool.onDown(const Offset(5, 5), paint); + + clearInteractions(commandManager); + clearInteractions(clippingToolState); + clearInteractions(canvasStateProvider); + clearInteractions(commandFactory); + + when(commandFactory.createClipPathCommand(any, any, + startPoint: anyNamed('startPoint'), endPoint: anyNamed('endPoint'))) + .thenAnswer((_) => MockClipPathCommand()); + + clippingTool.onUp(const Offset(15, 15), paint); + + final capturedRemove = + verify(commandManager.removeCommand(captureAny)).captured; + expect(capturedRemove.single, isA()); + + verify(commandFactory.createClipPathCommand(pathMock, paint, + startPoint: anyNamed('startPoint'), endPoint: anyNamed('endPoint'))) + .called(1); + final capturedAdd = + verify(commandManager.addGraphicCommand(captureAny)).captured; + expect(capturedAdd.single, isA()); + + verify(clippingToolState.setHasActiveClipPath(true)).called(1); + verify(canvasStateProvider.resetCanvasWithExistingCommands()).called(1); + verify(canvasStateProvider.updateCachedImage()).called(1); + }); + + test('[CLIPPING_TOOL]: onCancel clears live and preview commands', () { + clippingTool.onDown(const Offset(1, 1), paint); + clippingTool.onUp(const Offset(2, 2), paint); + + clearInteractions(commandManager); + clearInteractions(clippingToolState); + clearInteractions(canvasStateProvider); + + when(clippingToolState.hasActiveClipPath).thenReturn(true); + + clippingTool.onCancel(); + + final capturedRemove = + verify(commandManager.removeCommand(captureAny)).captured; + expect(capturedRemove.single, isA()); + + verify(clippingToolState.clearClipPath()).called(1); + verify(canvasStateProvider.resetCanvasWithExistingCommands()).called(1); + }); + + test('[CLIPPING_TOOL]: onCheckmark finalizes the clip area', () { + when(pathMock.actions).thenReturn([MoveToAction(0, 0), LineToAction(1, 1)]); + + clippingTool.onDown(const Offset(0, 0), paint); + clippingTool.onUp(const Offset(1, 1), paint); + + clearInteractions(commandManager); + clearInteractions(commandFactory); + clearInteractions(clippingToolState); + clearInteractions(canvasStateProvider); + + when(commandFactory.createClipAreaCommand(any, any)) + .thenAnswer((_) => MockClipAreaCommand()); + when(clippingToolState.hasActiveClipPath).thenReturn(true); + + clippingTool.onCheckmark(paint); + + final capturedRemove = + verify(commandManager.removeCommand(captureAny)).captured; + expect(capturedRemove.single, isA()); + + verify(clippingToolState.clearClipPath()).called(1); + verify(commandFactory.createClipAreaCommand(pathMock, paint)).called(1); + + final capturedAdd = + verify(commandManager.addGraphicCommand(captureAny)).captured; + expect(capturedAdd.single, isA()); + + verify(canvasStateProvider.resetCanvasWithExistingCommands()).called(1); + }); +} diff --git a/test/unit/tools/clipping_tool_test.mocks.dart b/test/unit/tools/clipping_tool_test.mocks.dart new file mode 100644 index 00000000..a456c8f8 --- /dev/null +++ b/test/unit/tools/clipping_tool_test.mocks.dart @@ -0,0 +1,1546 @@ +// Mocks generated by Mockito 5.4.5 from annotations +// in paintroid/test/unit/tools/clipping_tool_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i30; +import 'dart:typed_data' as _i26; +import 'dart:ui' as _i17; + +import 'package:flutter/material.dart' as _i27; +import 'package:logging/logging.dart' as _i20; +import 'package:mockito/mockito.dart' as _i1; +import 'package:mockito/src/dummies.dart' as _i29; +import 'package:paintroid/core/commands/command_factory/command_factory.dart' + as _i24; +import 'package:paintroid/core/commands/command_implementation/command.dart' + as _i2; +import 'package:paintroid/core/commands/command_implementation/graphic/clip_area_command.dart' + as _i14; +import 'package:paintroid/core/commands/command_implementation/graphic/clip_path_command.dart' + as _i5; +import 'package:paintroid/core/commands/command_implementation/graphic/clipboard_command.dart' + as _i9; +import 'package:paintroid/core/commands/command_implementation/graphic/delete_region_command.dart' + as _i15; +import 'package:paintroid/core/commands/command_implementation/graphic/graphic_command.dart' + as _i22; +import 'package:paintroid/core/commands/command_implementation/graphic/line_command.dart' + as _i6; +import 'package:paintroid/core/commands/command_implementation/graphic/path_command.dart' + as _i4; +import 'package:paintroid/core/commands/command_implementation/graphic/shape/ellipse_shape_command.dart' + as _i8; +import 'package:paintroid/core/commands/command_implementation/graphic/shape/heart_shape_command.dart' + as _i12; +import 'package:paintroid/core/commands/command_implementation/graphic/shape/square_shape_command.dart' + as _i7; +import 'package:paintroid/core/commands/command_implementation/graphic/shape/star_shape_command.dart' + as _i11; +import 'package:paintroid/core/commands/command_implementation/graphic/spray_command.dart' + as _i13; +import 'package:paintroid/core/commands/command_implementation/graphic/text_command.dart' + as _i10; +import 'package:paintroid/core/commands/command_manager/command_manager.dart' + as _i21; +import 'package:paintroid/core/commands/graphic_factory/graphic_factory.dart' + as _i28; +import 'package:paintroid/core/commands/path_with_action_history.dart' as _i16; +import 'package:paintroid/core/enums/shape_style.dart' as _i25; +import 'package:paintroid/core/providers/object/tools/clipping_tool_state_provider.dart' + as _i32; +import 'package:paintroid/core/providers/state/canvas_state_data.dart' as _i19; +import 'package:paintroid/core/providers/state/canvas_state_provider.dart' + as _i31; +import 'package:paintroid/core/tools/line_tool/vertex_stack.dart' as _i23; +import 'package:paintroid/core/tools/tool_data.dart' as _i3; +import 'package:riverpod_annotation/riverpod_annotation.dart' as _i18; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: must_be_immutable +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakeCommand_0 extends _i1.SmartFake implements _i2.Command { + _FakeCommand_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeToolData_1 extends _i1.SmartFake implements _i3.ToolData { + _FakeToolData_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakePathCommand_2 extends _i1.SmartFake implements _i4.PathCommand { + _FakePathCommand_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeClipPathCommand_3 extends _i1.SmartFake + implements _i5.ClipPathCommand { + _FakeClipPathCommand_3( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeLineCommand_4 extends _i1.SmartFake implements _i6.LineCommand { + _FakeLineCommand_4( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeSquareShapeCommand_5 extends _i1.SmartFake + implements _i7.SquareShapeCommand { + _FakeSquareShapeCommand_5( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeEllipseShapeCommand_6 extends _i1.SmartFake + implements _i8.EllipseShapeCommand { + _FakeEllipseShapeCommand_6( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeClipboardCommand_7 extends _i1.SmartFake + implements _i9.ClipboardCommand { + _FakeClipboardCommand_7( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeTextCommand_8 extends _i1.SmartFake implements _i10.TextCommand { + _FakeTextCommand_8( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeStarShapeCommand_9 extends _i1.SmartFake + implements _i11.StarShapeCommand { + _FakeStarShapeCommand_9( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeHeartShapeCommand_10 extends _i1.SmartFake + implements _i12.HeartShapeCommand { + _FakeHeartShapeCommand_10( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeSprayCommand_11 extends _i1.SmartFake implements _i13.SprayCommand { + _FakeSprayCommand_11( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeClipAreaCommand_12 extends _i1.SmartFake + implements _i14.ClipAreaCommand { + _FakeClipAreaCommand_12( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeDeleteRegionCommand_13 extends _i1.SmartFake + implements _i15.DeleteRegionCommand { + _FakeDeleteRegionCommand_13( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakePathWithActionHistory_14 extends _i1.SmartFake + implements _i16.PathWithActionHistory { + _FakePathWithActionHistory_14( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakePictureRecorder_15 extends _i1.SmartFake + implements _i17.PictureRecorder { + _FakePictureRecorder_15( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeCanvas_16 extends _i1.SmartFake implements _i17.Canvas { + _FakeCanvas_16( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeSize_17 extends _i1.SmartFake implements _i17.Size { + _FakeSize_17( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeNotifierProviderRef_18 extends _i1.SmartFake + implements _i18.NotifierProviderRef { + _FakeNotifierProviderRef_18( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeCanvasStateData_19 extends _i1.SmartFake + implements _i19.CanvasStateData { + _FakeCanvasStateData_19( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeLogger_20 extends _i1.SmartFake implements _i20.Logger { + _FakeLogger_20( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeAutoDisposeNotifierProviderRef_21 extends _i1.SmartFake + implements _i18.AutoDisposeNotifierProviderRef { + _FakeAutoDisposeNotifierProviderRef_21( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakePath_22 extends _i1.SmartFake implements _i17.Path { + _FakePath_22( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [CommandManager]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockCommandManager extends _i1.Mock implements _i21.CommandManager { + MockCommandManager() { + _i1.throwOnMissingStub(this); + } + + @override + List<_i2.Command> get redoStack => (super.noSuchMethod( + Invocation.getter(#redoStack), + returnValue: <_i2.Command>[], + ) as List<_i2.Command>); + + @override + List<_i2.Command> get undoStack => (super.noSuchMethod( + Invocation.getter(#undoStack), + returnValue: <_i2.Command>[], + ) as List<_i2.Command>); + + @override + void addGraphicCommand(_i22.GraphicCommand? command) => super.noSuchMethod( + Invocation.method( + #addGraphicCommand, + [command], + ), + returnValueForMissingStub: null, + ); + + @override + void removeCommand(_i2.Command? commandToRemove) => super.noSuchMethod( + Invocation.method( + #removeCommand, + [commandToRemove], + ), + returnValueForMissingStub: null, + ); + + @override + void setUndoStack(List<_i2.Command>? commands) => super.noSuchMethod( + Invocation.method( + #setUndoStack, + [commands], + ), + returnValueForMissingStub: null, + ); + + @override + void executeLastCommand(_i17.Canvas? canvas) => super.noSuchMethod( + Invocation.method( + #executeLastCommand, + [canvas], + ), + returnValueForMissingStub: null, + ); + + @override + void executeAllCommands(_i17.Canvas? canvas) => super.noSuchMethod( + Invocation.method( + #executeAllCommands, + [canvas], + ), + returnValueForMissingStub: null, + ); + + @override + void discardLastCommand() => super.noSuchMethod( + Invocation.method( + #discardLastCommand, + [], + ), + returnValueForMissingStub: null, + ); + + @override + void clearUndoStack({Iterable<_i2.Command>? newCommands}) => + super.noSuchMethod( + Invocation.method( + #clearUndoStack, + [], + {#newCommands: newCommands}, + ), + returnValueForMissingStub: null, + ); + + @override + void clearRedoStack() => super.noSuchMethod( + Invocation.method( + #clearRedoStack, + [], + ), + returnValueForMissingStub: null, + ); + + @override + void drawLineToolGhostPaths( + _i17.Canvas? canvas, + _i6.LineCommand? ingoingGhostPathCommand, + _i6.LineCommand? outgoingGhostPathCommand, + ) => + super.noSuchMethod( + Invocation.method( + #drawLineToolGhostPaths, + [ + canvas, + ingoingGhostPathCommand, + outgoingGhostPathCommand, + ], + ), + returnValueForMissingStub: null, + ); + + @override + void drawLineToolVertices( + _i17.Canvas? canvas, + _i23.VertexStack? vertexStack, + ) => + super.noSuchMethod( + Invocation.method( + #drawLineToolVertices, + [ + canvas, + vertexStack, + ], + ), + returnValueForMissingStub: null, + ); + + @override + _i2.Command redo() => (super.noSuchMethod( + Invocation.method( + #redo, + [], + ), + returnValue: _FakeCommand_0( + this, + Invocation.method( + #redo, + [], + ), + ), + ) as _i2.Command); + + @override + void undo() => super.noSuchMethod( + Invocation.method( + #undo, + [], + ), + returnValueForMissingStub: null, + ); + + @override + _i3.ToolData getNextTool(_i21.ActionType? actionType) => (super.noSuchMethod( + Invocation.method( + #getNextTool, + [actionType], + ), + returnValue: _FakeToolData_1( + this, + Invocation.method( + #getNextTool, + [actionType], + ), + ), + ) as _i3.ToolData); + + @override + List<_i6.LineCommand> getTopLineCommandSequence() => (super.noSuchMethod( + Invocation.method( + #getTopLineCommandSequence, + [], + ), + returnValue: <_i6.LineCommand>[], + ) as List<_i6.LineCommand>); +} + +/// A class which mocks [CommandFactory]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockCommandFactory extends _i1.Mock implements _i24.CommandFactory { + MockCommandFactory() { + _i1.throwOnMissingStub(this); + } + + @override + _i4.PathCommand createPathCommand( + _i16.PathWithActionHistory? path, + _i17.Paint? paint, + ) => + (super.noSuchMethod( + Invocation.method( + #createPathCommand, + [ + path, + paint, + ], + ), + returnValue: _FakePathCommand_2( + this, + Invocation.method( + #createPathCommand, + [ + path, + paint, + ], + ), + ), + ) as _i4.PathCommand); + + @override + _i5.ClipPathCommand createClipPathCommand( + _i16.PathWithActionHistory? path, + _i17.Paint? paint, { + _i17.Offset? startPoint, + _i17.Offset? endPoint, + }) => + (super.noSuchMethod( + Invocation.method( + #createClipPathCommand, + [ + path, + paint, + ], + { + #startPoint: startPoint, + #endPoint: endPoint, + }, + ), + returnValue: _FakeClipPathCommand_3( + this, + Invocation.method( + #createClipPathCommand, + [ + path, + paint, + ], + { + #startPoint: startPoint, + #endPoint: endPoint, + }, + ), + ), + ) as _i5.ClipPathCommand); + + @override + _i6.LineCommand createLineCommand( + _i16.PathWithActionHistory? path, + _i17.Paint? paint, + _i17.Offset? startPoint, + _i17.Offset? endPoint, + ) => + (super.noSuchMethod( + Invocation.method( + #createLineCommand, + [ + path, + paint, + startPoint, + endPoint, + ], + ), + returnValue: _FakeLineCommand_4( + this, + Invocation.method( + #createLineCommand, + [ + path, + paint, + startPoint, + endPoint, + ], + ), + ), + ) as _i6.LineCommand); + + @override + _i7.SquareShapeCommand createSquareShapeCommand( + _i17.Paint? paint, + _i17.Offset? topLeft, + _i17.Offset? topRight, + _i17.Offset? bottomLeft, + _i17.Offset? bottomRight, + _i25.ShapeStyle? style, + ) => + (super.noSuchMethod( + Invocation.method( + #createSquareShapeCommand, + [ + paint, + topLeft, + topRight, + bottomLeft, + bottomRight, + style, + ], + ), + returnValue: _FakeSquareShapeCommand_5( + this, + Invocation.method( + #createSquareShapeCommand, + [ + paint, + topLeft, + topRight, + bottomLeft, + bottomRight, + style, + ], + ), + ), + ) as _i7.SquareShapeCommand); + + @override + _i8.EllipseShapeCommand createEllipseShapeCommand( + _i17.Paint? paint, + double? radiusX, + double? radiusY, + _i17.Offset? center, + _i25.ShapeStyle? style, + double? angle, + ) => + (super.noSuchMethod( + Invocation.method( + #createEllipseShapeCommand, + [ + paint, + radiusX, + radiusY, + center, + style, + angle, + ], + ), + returnValue: _FakeEllipseShapeCommand_6( + this, + Invocation.method( + #createEllipseShapeCommand, + [ + paint, + radiusX, + radiusY, + center, + style, + angle, + ], + ), + ), + ) as _i8.EllipseShapeCommand); + + @override + _i9.ClipboardCommand createClipboardCommand( + _i17.Paint? paint, + _i26.Uint8List? imageData, + _i17.Offset? offset, + double? scale, + double? rotation, + ) => + (super.noSuchMethod( + Invocation.method( + #createClipboardCommand, + [ + paint, + imageData, + offset, + scale, + rotation, + ], + ), + returnValue: _FakeClipboardCommand_7( + this, + Invocation.method( + #createClipboardCommand, + [ + paint, + imageData, + offset, + scale, + rotation, + ], + ), + ), + ) as _i9.ClipboardCommand); + + @override + _i10.TextCommand createTextCommand( + _i17.Offset? point, + String? text, + _i27.TextStyle? style, + double? fontSize, + _i17.Paint? paint, + double? rotationAngle, { + double? scaleX = 1.0, + double? scaleY = 1.0, + }) => + (super.noSuchMethod( + Invocation.method( + #createTextCommand, + [ + point, + text, + style, + fontSize, + paint, + rotationAngle, + ], + { + #scaleX: scaleX, + #scaleY: scaleY, + }, + ), + returnValue: _FakeTextCommand_8( + this, + Invocation.method( + #createTextCommand, + [ + point, + text, + style, + fontSize, + paint, + rotationAngle, + ], + { + #scaleX: scaleX, + #scaleY: scaleY, + }, + ), + ), + ) as _i10.TextCommand); + + @override + _i11.StarShapeCommand createStarShapeCommand( + _i17.Paint? paint, + int? numPoints, + double? angle, + _i17.Offset? center, + _i25.ShapeStyle? style, + double? radiusX, + double? radiusY, + ) => + (super.noSuchMethod( + Invocation.method( + #createStarShapeCommand, + [ + paint, + numPoints, + angle, + center, + style, + radiusX, + radiusY, + ], + ), + returnValue: _FakeStarShapeCommand_9( + this, + Invocation.method( + #createStarShapeCommand, + [ + paint, + numPoints, + angle, + center, + style, + radiusX, + radiusY, + ], + ), + ), + ) as _i11.StarShapeCommand); + + @override + _i12.HeartShapeCommand createHeartShapeCommand( + _i17.Paint? paint, + double? width, + double? height, + double? angle, + _i17.Offset? center, + _i25.ShapeStyle? style, + ) => + (super.noSuchMethod( + Invocation.method( + #createHeartShapeCommand, + [ + paint, + width, + height, + angle, + center, + style, + ], + ), + returnValue: _FakeHeartShapeCommand_10( + this, + Invocation.method( + #createHeartShapeCommand, + [ + paint, + width, + height, + angle, + center, + style, + ], + ), + ), + ) as _i12.HeartShapeCommand); + + @override + _i13.SprayCommand createSprayCommand( + List<_i17.Offset>? points, + _i17.Paint? paint, + ) => + (super.noSuchMethod( + Invocation.method( + #createSprayCommand, + [ + points, + paint, + ], + ), + returnValue: _FakeSprayCommand_11( + this, + Invocation.method( + #createSprayCommand, + [ + points, + paint, + ], + ), + ), + ) as _i13.SprayCommand); + + @override + _i14.ClipAreaCommand createClipAreaCommand( + _i16.PathWithActionHistory? path, + _i17.Paint? paint, + ) => + (super.noSuchMethod( + Invocation.method( + #createClipAreaCommand, + [ + path, + paint, + ], + ), + returnValue: _FakeClipAreaCommand_12( + this, + Invocation.method( + #createClipAreaCommand, + [ + path, + paint, + ], + ), + ), + ) as _i14.ClipAreaCommand); + + @override + _i15.DeleteRegionCommand createDeleteRegionCommand(_i17.Rect? region) => + (super.noSuchMethod( + Invocation.method( + #createDeleteRegionCommand, + [region], + ), + returnValue: _FakeDeleteRegionCommand_13( + this, + Invocation.method( + #createDeleteRegionCommand, + [region], + ), + ), + ) as _i15.DeleteRegionCommand); +} + +/// A class which mocks [GraphicFactory]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockGraphicFactory extends _i1.Mock implements _i28.GraphicFactory { + MockGraphicFactory() { + _i1.throwOnMissingStub(this); + } + + @override + _i17.Paint createPaint() => (super.noSuchMethod( + Invocation.method( + #createPaint, + [], + ), + returnValue: _i29.dummyValue<_i17.Paint>( + this, + Invocation.method( + #createPaint, + [], + ), + ), + ) as _i17.Paint); + + @override + _i16.PathWithActionHistory createPathWithActionHistory() => + (super.noSuchMethod( + Invocation.method( + #createPathWithActionHistory, + [], + ), + returnValue: _FakePathWithActionHistory_14( + this, + Invocation.method( + #createPathWithActionHistory, + [], + ), + ), + ) as _i16.PathWithActionHistory); + + @override + _i17.PictureRecorder createPictureRecorder() => (super.noSuchMethod( + Invocation.method( + #createPictureRecorder, + [], + ), + returnValue: _FakePictureRecorder_15( + this, + Invocation.method( + #createPictureRecorder, + [], + ), + ), + ) as _i17.PictureRecorder); + + @override + _i17.Canvas createCanvasWithRecorder(_i17.PictureRecorder? recorder) => + (super.noSuchMethod( + Invocation.method( + #createCanvasWithRecorder, + [recorder], + ), + returnValue: _FakeCanvas_16( + this, + Invocation.method( + #createCanvasWithRecorder, + [recorder], + ), + ), + ) as _i17.Canvas); + + @override + _i17.Paint createWatercolorPaint( + _i17.Paint? originalPaint, + double? blurSigma, + ) => + (super.noSuchMethod( + Invocation.method( + #createWatercolorPaint, + [ + originalPaint, + blurSigma, + ], + ), + returnValue: _i29.dummyValue<_i17.Paint>( + this, + Invocation.method( + #createWatercolorPaint, + [ + originalPaint, + blurSigma, + ], + ), + ), + ) as _i17.Paint); + + @override + _i17.Paint copyPaint(_i17.Paint? original) => (super.noSuchMethod( + Invocation.method( + #copyPaint, + [original], + ), + returnValue: _i29.dummyValue<_i17.Paint>( + this, + Invocation.method( + #copyPaint, + [original], + ), + ), + ) as _i17.Paint); +} + +/// A class which mocks [GraphicCommand]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockGraphicCommand extends _i1.Mock implements _i22.GraphicCommand { + MockGraphicCommand() { + _i1.throwOnMissingStub(this); + } + + @override + _i17.Paint get paint => (super.noSuchMethod( + Invocation.getter(#paint), + returnValue: _i29.dummyValue<_i17.Paint>( + this, + Invocation.getter(#paint), + ), + ) as _i17.Paint); + + @override + List get props => (super.noSuchMethod( + Invocation.getter(#props), + returnValue: [], + ) as List); + + @override + void call(_i17.Canvas? canvas) => super.noSuchMethod( + Invocation.method( + #call, + [canvas], + ), + returnValueForMissingStub: null, + ); + + @override + Map toJson() => (super.noSuchMethod( + Invocation.method( + #toJson, + [], + ), + returnValue: {}, + ) as Map); + + @override + _i30.Future prepareForRuntime() => (super.noSuchMethod( + Invocation.method( + #prepareForRuntime, + [], + ), + returnValue: _i30.Future.value(), + returnValueForMissingStub: _i30.Future.value(), + ) as _i30.Future); +} + +/// A class which mocks [CanvasStateProvider]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockCanvasStateProvider extends _i1.Mock + implements _i31.CanvasStateProvider { + MockCanvasStateProvider() { + _i1.throwOnMissingStub(this); + } + + @override + _i17.Size get initialCanvasSize => (super.noSuchMethod( + Invocation.getter(#initialCanvasSize), + returnValue: _FakeSize_17( + this, + Invocation.getter(#initialCanvasSize), + ), + ) as _i17.Size); + + @override + set initialCanvasSize(_i17.Size? _initialCanvasSize) => super.noSuchMethod( + Invocation.setter( + #initialCanvasSize, + _initialCanvasSize, + ), + returnValueForMissingStub: null, + ); + + @override + _i18.NotifierProviderRef<_i19.CanvasStateData> get ref => (super.noSuchMethod( + Invocation.getter(#ref), + returnValue: _FakeNotifierProviderRef_18<_i19.CanvasStateData>( + this, + Invocation.getter(#ref), + ), + ) as _i18.NotifierProviderRef<_i19.CanvasStateData>); + + @override + _i19.CanvasStateData get state => (super.noSuchMethod( + Invocation.getter(#state), + returnValue: _FakeCanvasStateData_19( + this, + Invocation.getter(#state), + ), + ) as _i19.CanvasStateData); + + @override + set state(_i19.CanvasStateData? value) => super.noSuchMethod( + Invocation.setter( + #state, + value, + ), + returnValueForMissingStub: null, + ); + + @override + _i20.Logger get logger => (super.noSuchMethod( + Invocation.getter(#logger), + returnValue: _FakeLogger_20( + this, + Invocation.getter(#logger), + ), + ) as _i20.Logger); + + @override + _i19.CanvasStateData build() => (super.noSuchMethod( + Invocation.method( + #build, + [], + ), + returnValue: _FakeCanvasStateData_19( + this, + Invocation.method( + #build, + [], + ), + ), + ) as _i19.CanvasStateData); + + @override + void setBackgroundImage(_i17.Image? image) => super.noSuchMethod( + Invocation.method( + #setBackgroundImage, + [image], + ), + returnValueForMissingStub: null, + ); + + @override + void clearBackgroundImageAndResetDimensions() => super.noSuchMethod( + Invocation.method( + #clearBackgroundImageAndResetDimensions, + [], + ), + returnValueForMissingStub: null, + ); + + @override + _i30.Future updateCachedImage() => (super.noSuchMethod( + Invocation.method( + #updateCachedImage, + [], + ), + returnValue: _i30.Future.value(), + returnValueForMissingStub: _i30.Future.value(), + ) as _i30.Future); + + @override + _i30.Future resetCanvasWithNewCommands( + Iterable<_i2.Command>? commands) => + (super.noSuchMethod( + Invocation.method( + #resetCanvasWithNewCommands, + [commands], + ), + returnValue: _i30.Future.value(), + returnValueForMissingStub: _i30.Future.value(), + ) as _i30.Future); + + @override + _i30.Future resetCanvasWithExistingCommands() => (super.noSuchMethod( + Invocation.method( + #resetCanvasWithExistingCommands, + [], + ), + returnValue: _i30.Future.value(), + returnValueForMissingStub: _i30.Future.value(), + ) as _i30.Future); + + @override + void listenSelf( + void Function( + _i19.CanvasStateData?, + _i19.CanvasStateData, + )? listener, { + void Function( + Object, + StackTrace, + )? onError, + }) => + super.noSuchMethod( + Invocation.method( + #listenSelf, + [listener], + {#onError: onError}, + ), + returnValueForMissingStub: null, + ); + + @override + bool updateShouldNotify( + _i19.CanvasStateData? previous, + _i19.CanvasStateData? next, + ) => + (super.noSuchMethod( + Invocation.method( + #updateShouldNotify, + [ + previous, + next, + ], + ), + returnValue: false, + ) as bool); +} + +/// A class which mocks [ClippingToolState]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockClippingToolState extends _i1.Mock implements _i32.ClippingToolState { + MockClippingToolState() { + _i1.throwOnMissingStub(this); + } + + @override + bool get hasActiveClipPath => (super.noSuchMethod( + Invocation.getter(#hasActiveClipPath), + returnValue: false, + ) as bool); + + @override + _i18.AutoDisposeNotifierProviderRef get ref => (super.noSuchMethod( + Invocation.getter(#ref), + returnValue: _FakeAutoDisposeNotifierProviderRef_21( + this, + Invocation.getter(#ref), + ), + ) as _i18.AutoDisposeNotifierProviderRef); + + @override + bool get state => (super.noSuchMethod( + Invocation.getter(#state), + returnValue: false, + ) as bool); + + @override + set state(bool? value) => super.noSuchMethod( + Invocation.setter( + #state, + value, + ), + returnValueForMissingStub: null, + ); + + @override + bool build() => (super.noSuchMethod( + Invocation.method( + #build, + [], + ), + returnValue: false, + ) as bool); + + @override + void setHasActiveClipPath(bool? hasActive) => super.noSuchMethod( + Invocation.method( + #setHasActiveClipPath, + [hasActive], + ), + returnValueForMissingStub: null, + ); + + @override + void clearClipPath() => super.noSuchMethod( + Invocation.method( + #clearClipPath, + [], + ), + returnValueForMissingStub: null, + ); + + @override + void listenSelf( + void Function( + bool?, + bool, + )? listener, { + void Function( + Object, + StackTrace, + )? onError, + }) => + super.noSuchMethod( + Invocation.method( + #listenSelf, + [listener], + {#onError: onError}, + ), + returnValueForMissingStub: null, + ); + + @override + bool updateShouldNotify( + bool? previous, + bool? next, + ) => + (super.noSuchMethod( + Invocation.method( + #updateShouldNotify, + [ + previous, + next, + ], + ), + returnValue: false, + ) as bool); +} + +/// A class which mocks [PathWithActionHistory]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockPathWithActionHistory extends _i1.Mock + implements _i16.PathWithActionHistory { + MockPathWithActionHistory() { + _i1.throwOnMissingStub(this); + } + + @override + _i17.Path get path => (super.noSuchMethod( + Invocation.getter(#path), + returnValue: _FakePath_22( + this, + Invocation.getter(#path), + ), + ) as _i17.Path); + + @override + List<_i16.PathAction> get actions => (super.noSuchMethod( + Invocation.getter(#actions), + returnValue: <_i16.PathAction>[], + ) as List<_i16.PathAction>); + + @override + void moveTo( + double? x, + double? y, + ) => + super.noSuchMethod( + Invocation.method( + #moveTo, + [ + x, + y, + ], + ), + returnValueForMissingStub: null, + ); + + @override + void lineTo( + double? x, + double? y, + ) => + super.noSuchMethod( + Invocation.method( + #lineTo, + [ + x, + y, + ], + ), + returnValueForMissingStub: null, + ); + + @override + void close() => super.noSuchMethod( + Invocation.method( + #close, + [], + ), + returnValueForMissingStub: null, + ); + + @override + Map toJson() => (super.noSuchMethod( + Invocation.method( + #toJson, + [], + ), + returnValue: {}, + ) as Map); +} + +/// A class which mocks [ClipPathCommand]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockClipPathCommand extends _i1.Mock implements _i5.ClipPathCommand { + MockClipPathCommand() { + _i1.throwOnMissingStub(this); + } + + @override + String get type => (super.noSuchMethod( + Invocation.getter(#type), + returnValue: _i29.dummyValue( + this, + Invocation.getter(#type), + ), + ) as String); + + @override + int get version => (super.noSuchMethod( + Invocation.getter(#version), + returnValue: 0, + ) as int); + + @override + _i16.PathWithActionHistory get path => (super.noSuchMethod( + Invocation.getter(#path), + returnValue: _FakePathWithActionHistory_14( + this, + Invocation.getter(#path), + ), + ) as _i16.PathWithActionHistory); + + @override + List get props => (super.noSuchMethod( + Invocation.getter(#props), + returnValue: [], + ) as List); + + @override + _i17.Paint get paint => (super.noSuchMethod( + Invocation.getter(#paint), + returnValue: _i29.dummyValue<_i17.Paint>( + this, + Invocation.getter(#paint), + ), + ) as _i17.Paint); + + @override + void call(_i17.Canvas? canvas) => super.noSuchMethod( + Invocation.method( + #call, + [canvas], + ), + returnValueForMissingStub: null, + ); + + @override + Map toJson() => (super.noSuchMethod( + Invocation.method( + #toJson, + [], + ), + returnValue: {}, + ) as Map); + + @override + _i30.Future prepareForRuntime() => (super.noSuchMethod( + Invocation.method( + #prepareForRuntime, + [], + ), + returnValue: _i30.Future.value(), + returnValueForMissingStub: _i30.Future.value(), + ) as _i30.Future); +} + +/// A class which mocks [ClipAreaCommand]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockClipAreaCommand extends _i1.Mock implements _i14.ClipAreaCommand { + MockClipAreaCommand() { + _i1.throwOnMissingStub(this); + } + + @override + String get type => (super.noSuchMethod( + Invocation.getter(#type), + returnValue: _i29.dummyValue( + this, + Invocation.getter(#type), + ), + ) as String); + + @override + int get version => (super.noSuchMethod( + Invocation.getter(#version), + returnValue: 0, + ) as int); + + @override + _i16.PathWithActionHistory get clipPathData => (super.noSuchMethod( + Invocation.getter(#clipPathData), + returnValue: _FakePathWithActionHistory_14( + this, + Invocation.getter(#clipPathData), + ), + ) as _i16.PathWithActionHistory); + + @override + List get props => (super.noSuchMethod( + Invocation.getter(#props), + returnValue: [], + ) as List); + + @override + _i17.Paint get paint => (super.noSuchMethod( + Invocation.getter(#paint), + returnValue: _i29.dummyValue<_i17.Paint>( + this, + Invocation.getter(#paint), + ), + ) as _i17.Paint); + + @override + void call(_i17.Canvas? canvas) => super.noSuchMethod( + Invocation.method( + #call, + [canvas], + ), + returnValueForMissingStub: null, + ); + + @override + Map toJson() => (super.noSuchMethod( + Invocation.method( + #toJson, + [], + ), + returnValue: {}, + ) as Map); + + @override + _i30.Future prepareForRuntime() => (super.noSuchMethod( + Invocation.method( + #prepareForRuntime, + [], + ), + returnValue: _i30.Future.value(), + returnValueForMissingStub: _i30.Future.value(), + ) as _i30.Future); +} diff --git a/test/unit/tools/text_tool_test.mocks.dart b/test/unit/tools/text_tool_test.mocks.dart index cfa1831b..9b25eff5 100644 --- a/test/unit/tools/text_tool_test.mocks.dart +++ b/test/unit/tools/text_tool_test.mocks.dart @@ -3,51 +3,55 @@ // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i25; -import 'dart:typed_data' as _i23; -import 'dart:ui' as _i15; +import 'dart:async' as _i27; +import 'dart:typed_data' as _i25; +import 'dart:ui' as _i17; -import 'package:flutter/material.dart' as _i16; +import 'package:flutter/material.dart' as _i18; import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i24; +import 'package:mockito/src/dummies.dart' as _i26; import 'package:paintroid/core/commands/command_factory/command_factory.dart' - as _i21; + as _i23; import 'package:paintroid/core/commands/command_implementation/command.dart' as _i2; +import 'package:paintroid/core/commands/command_implementation/graphic/clip_area_command.dart' + as _i14; +import 'package:paintroid/core/commands/command_implementation/graphic/clip_path_command.dart' + as _i5; import 'package:paintroid/core/commands/command_implementation/graphic/clipboard_command.dart' - as _i8; + as _i9; import 'package:paintroid/core/commands/command_implementation/graphic/delete_region_command.dart' - as _i13; + as _i15; import 'package:paintroid/core/commands/command_implementation/graphic/graphic_command.dart' - as _i19; + as _i21; import 'package:paintroid/core/commands/command_implementation/graphic/line_command.dart' - as _i5; + as _i6; import 'package:paintroid/core/commands/command_implementation/graphic/path_command.dart' as _i4; import 'package:paintroid/core/commands/command_implementation/graphic/shape/ellipse_shape_command.dart' - as _i7; + as _i8; import 'package:paintroid/core/commands/command_implementation/graphic/shape/heart_shape_command.dart' - as _i11; + as _i12; import 'package:paintroid/core/commands/command_implementation/graphic/shape/square_shape_command.dart' - as _i6; + as _i7; import 'package:paintroid/core/commands/command_implementation/graphic/shape/star_shape_command.dart' - as _i10; + as _i11; import 'package:paintroid/core/commands/command_implementation/graphic/spray_command.dart' - as _i12; + as _i13; import 'package:paintroid/core/commands/command_implementation/graphic/text_command.dart' - as _i9; + as _i10; import 'package:paintroid/core/commands/command_manager/command_manager.dart' - as _i18; + as _i20; import 'package:paintroid/core/commands/graphic_factory/graphic_factory.dart' - as _i26; -import 'package:paintroid/core/commands/path_with_action_history.dart' as _i17; -import 'package:paintroid/core/enums/bounding_box_action.dart' as _i28; -import 'package:paintroid/core/enums/bounding_box_resize_action.dart' as _i29; -import 'package:paintroid/core/enums/shape_style.dart' as _i22; -import 'package:paintroid/core/tools/bounding_box.dart' as _i27; -import 'package:paintroid/core/tools/line_tool/vertex_stack.dart' as _i20; + as _i28; +import 'package:paintroid/core/commands/path_with_action_history.dart' as _i19; +import 'package:paintroid/core/enums/bounding_box_action.dart' as _i30; +import 'package:paintroid/core/enums/bounding_box_resize_action.dart' as _i31; +import 'package:paintroid/core/enums/shape_style.dart' as _i24; +import 'package:paintroid/core/tools/bounding_box.dart' as _i29; +import 'package:paintroid/core/tools/line_tool/vertex_stack.dart' as _i22; import 'package:paintroid/core/tools/tool_data.dart' as _i3; -import 'package:riverpod/src/internals.dart' as _i14; +import 'package:riverpod/src/internals.dart' as _i16; // ignore_for_file: type=lint // ignore_for_file: avoid_redundant_argument_values @@ -93,8 +97,9 @@ class _FakePathCommand_2 extends _i1.SmartFake implements _i4.PathCommand { ); } -class _FakeLineCommand_3 extends _i1.SmartFake implements _i5.LineCommand { - _FakeLineCommand_3( +class _FakeClipPathCommand_3 extends _i1.SmartFake + implements _i5.ClipPathCommand { + _FakeClipPathCommand_3( Object parent, Invocation parentInvocation, ) : super( @@ -103,9 +108,8 @@ class _FakeLineCommand_3 extends _i1.SmartFake implements _i5.LineCommand { ); } -class _FakeSquareShapeCommand_4 extends _i1.SmartFake - implements _i6.SquareShapeCommand { - _FakeSquareShapeCommand_4( +class _FakeLineCommand_4 extends _i1.SmartFake implements _i6.LineCommand { + _FakeLineCommand_4( Object parent, Invocation parentInvocation, ) : super( @@ -114,9 +118,9 @@ class _FakeSquareShapeCommand_4 extends _i1.SmartFake ); } -class _FakeEllipseShapeCommand_5 extends _i1.SmartFake - implements _i7.EllipseShapeCommand { - _FakeEllipseShapeCommand_5( +class _FakeSquareShapeCommand_5 extends _i1.SmartFake + implements _i7.SquareShapeCommand { + _FakeSquareShapeCommand_5( Object parent, Invocation parentInvocation, ) : super( @@ -125,9 +129,9 @@ class _FakeEllipseShapeCommand_5 extends _i1.SmartFake ); } -class _FakeClipboardCommand_6 extends _i1.SmartFake - implements _i8.ClipboardCommand { - _FakeClipboardCommand_6( +class _FakeEllipseShapeCommand_6 extends _i1.SmartFake + implements _i8.EllipseShapeCommand { + _FakeEllipseShapeCommand_6( Object parent, Invocation parentInvocation, ) : super( @@ -136,8 +140,9 @@ class _FakeClipboardCommand_6 extends _i1.SmartFake ); } -class _FakeTextCommand_7 extends _i1.SmartFake implements _i9.TextCommand { - _FakeTextCommand_7( +class _FakeClipboardCommand_7 extends _i1.SmartFake + implements _i9.ClipboardCommand { + _FakeClipboardCommand_7( Object parent, Invocation parentInvocation, ) : super( @@ -146,9 +151,8 @@ class _FakeTextCommand_7 extends _i1.SmartFake implements _i9.TextCommand { ); } -class _FakeStarShapeCommand_8 extends _i1.SmartFake - implements _i10.StarShapeCommand { - _FakeStarShapeCommand_8( +class _FakeTextCommand_8 extends _i1.SmartFake implements _i10.TextCommand { + _FakeTextCommand_8( Object parent, Invocation parentInvocation, ) : super( @@ -157,9 +161,9 @@ class _FakeStarShapeCommand_8 extends _i1.SmartFake ); } -class _FakeHeartShapeCommand_9 extends _i1.SmartFake - implements _i11.HeartShapeCommand { - _FakeHeartShapeCommand_9( +class _FakeStarShapeCommand_9 extends _i1.SmartFake + implements _i11.StarShapeCommand { + _FakeStarShapeCommand_9( Object parent, Invocation parentInvocation, ) : super( @@ -168,8 +172,9 @@ class _FakeHeartShapeCommand_9 extends _i1.SmartFake ); } -class _FakeSprayCommand_10 extends _i1.SmartFake implements _i12.SprayCommand { - _FakeSprayCommand_10( +class _FakeHeartShapeCommand_10 extends _i1.SmartFake + implements _i12.HeartShapeCommand { + _FakeHeartShapeCommand_10( Object parent, Invocation parentInvocation, ) : super( @@ -178,9 +183,8 @@ class _FakeSprayCommand_10 extends _i1.SmartFake implements _i12.SprayCommand { ); } -class _FakeDeleteRegionCommand_11 extends _i1.SmartFake - implements _i13.DeleteRegionCommand { - _FakeDeleteRegionCommand_11( +class _FakeSprayCommand_11 extends _i1.SmartFake implements _i13.SprayCommand { + _FakeSprayCommand_11( Object parent, Invocation parentInvocation, ) : super( @@ -189,9 +193,9 @@ class _FakeDeleteRegionCommand_11 extends _i1.SmartFake ); } -class _FakeProviderContainer_12 extends _i1.SmartFake - implements _i14.ProviderContainer { - _FakeProviderContainer_12( +class _FakeClipAreaCommand_12 extends _i1.SmartFake + implements _i14.ClipAreaCommand { + _FakeClipAreaCommand_12( Object parent, Invocation parentInvocation, ) : super( @@ -200,9 +204,9 @@ class _FakeProviderContainer_12 extends _i1.SmartFake ); } -class _FakeKeepAliveLink_13 extends _i1.SmartFake - implements _i14.KeepAliveLink { - _FakeKeepAliveLink_13( +class _FakeDeleteRegionCommand_13 extends _i1.SmartFake + implements _i15.DeleteRegionCommand { + _FakeDeleteRegionCommand_13( Object parent, Invocation parentInvocation, ) : super( @@ -211,9 +215,9 @@ class _FakeKeepAliveLink_13 extends _i1.SmartFake ); } -class _FakeProviderSubscription_14 extends _i1.SmartFake - implements _i14.ProviderSubscription { - _FakeProviderSubscription_14( +class _FakeProviderContainer_14 extends _i1.SmartFake + implements _i16.ProviderContainer { + _FakeProviderContainer_14( Object parent, Invocation parentInvocation, ) : super( @@ -222,8 +226,9 @@ class _FakeProviderSubscription_14 extends _i1.SmartFake ); } -class _FakeRect_15 extends _i1.SmartFake implements _i15.Rect { - _FakeRect_15( +class _FakeKeepAliveLink_15 extends _i1.SmartFake + implements _i16.KeepAliveLink { + _FakeKeepAliveLink_15( Object parent, Invocation parentInvocation, ) : super( @@ -232,8 +237,9 @@ class _FakeRect_15 extends _i1.SmartFake implements _i15.Rect { ); } -class _FakeOffset_16 extends _i1.SmartFake implements _i15.Offset { - _FakeOffset_16( +class _FakeProviderSubscription_16 extends _i1.SmartFake + implements _i16.ProviderSubscription { + _FakeProviderSubscription_16( Object parent, Invocation parentInvocation, ) : super( @@ -242,8 +248,28 @@ class _FakeOffset_16 extends _i1.SmartFake implements _i15.Offset { ); } -class _FakeTextStyle_17 extends _i1.SmartFake implements _i16.TextStyle { - _FakeTextStyle_17( +class _FakeRect_17 extends _i1.SmartFake implements _i17.Rect { + _FakeRect_17( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeOffset_18 extends _i1.SmartFake implements _i17.Offset { + _FakeOffset_18( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeTextStyle_19 extends _i1.SmartFake implements _i18.TextStyle { + _FakeTextStyle_19( Object parent, Invocation parentInvocation, ) : super( @@ -253,13 +279,13 @@ class _FakeTextStyle_17 extends _i1.SmartFake implements _i16.TextStyle { @override String toString( - {_i16.DiagnosticLevel? minLevel = _i16.DiagnosticLevel.info}) => + {_i18.DiagnosticLevel? minLevel = _i18.DiagnosticLevel.info}) => super.toString(); } -class _FakePathWithActionHistory_18 extends _i1.SmartFake - implements _i17.PathWithActionHistory { - _FakePathWithActionHistory_18( +class _FakePathWithActionHistory_20 extends _i1.SmartFake + implements _i19.PathWithActionHistory { + _FakePathWithActionHistory_20( Object parent, Invocation parentInvocation, ) : super( @@ -268,9 +294,9 @@ class _FakePathWithActionHistory_18 extends _i1.SmartFake ); } -class _FakePictureRecorder_19 extends _i1.SmartFake - implements _i15.PictureRecorder { - _FakePictureRecorder_19( +class _FakePictureRecorder_21 extends _i1.SmartFake + implements _i17.PictureRecorder { + _FakePictureRecorder_21( Object parent, Invocation parentInvocation, ) : super( @@ -279,8 +305,8 @@ class _FakePictureRecorder_19 extends _i1.SmartFake ); } -class _FakeCanvas_20 extends _i1.SmartFake implements _i15.Canvas { - _FakeCanvas_20( +class _FakeCanvas_22 extends _i1.SmartFake implements _i17.Canvas { + _FakeCanvas_22( Object parent, Invocation parentInvocation, ) : super( @@ -292,7 +318,7 @@ class _FakeCanvas_20 extends _i1.SmartFake implements _i15.Canvas { /// A class which mocks [CommandManager]. /// /// See the documentation for Mockito's code generation for more information. -class MockCommandManager extends _i1.Mock implements _i18.CommandManager { +class MockCommandManager extends _i1.Mock implements _i20.CommandManager { MockCommandManager() { _i1.throwOnMissingStub(this); } @@ -310,7 +336,7 @@ class MockCommandManager extends _i1.Mock implements _i18.CommandManager { ) as List<_i2.Command>); @override - void addGraphicCommand(_i19.GraphicCommand? command) => super.noSuchMethod( + void addGraphicCommand(_i21.GraphicCommand? command) => super.noSuchMethod( Invocation.method( #addGraphicCommand, [command], @@ -318,6 +344,15 @@ class MockCommandManager extends _i1.Mock implements _i18.CommandManager { returnValueForMissingStub: null, ); + @override + void removeCommand(_i2.Command? commandToRemove) => super.noSuchMethod( + Invocation.method( + #removeCommand, + [commandToRemove], + ), + returnValueForMissingStub: null, + ); + @override void setUndoStack(List<_i2.Command>? commands) => super.noSuchMethod( Invocation.method( @@ -328,7 +363,7 @@ class MockCommandManager extends _i1.Mock implements _i18.CommandManager { ); @override - void executeLastCommand(_i15.Canvas? canvas) => super.noSuchMethod( + void executeLastCommand(_i17.Canvas? canvas) => super.noSuchMethod( Invocation.method( #executeLastCommand, [canvas], @@ -337,7 +372,7 @@ class MockCommandManager extends _i1.Mock implements _i18.CommandManager { ); @override - void executeAllCommands(_i15.Canvas? canvas) => super.noSuchMethod( + void executeAllCommands(_i17.Canvas? canvas) => super.noSuchMethod( Invocation.method( #executeAllCommands, [canvas], @@ -376,9 +411,9 @@ class MockCommandManager extends _i1.Mock implements _i18.CommandManager { @override void drawLineToolGhostPaths( - _i15.Canvas? canvas, - _i5.LineCommand? ingoingGhostPathCommand, - _i5.LineCommand? outgoingGhostPathCommand, + _i17.Canvas? canvas, + _i6.LineCommand? ingoingGhostPathCommand, + _i6.LineCommand? outgoingGhostPathCommand, ) => super.noSuchMethod( Invocation.method( @@ -394,8 +429,8 @@ class MockCommandManager extends _i1.Mock implements _i18.CommandManager { @override void drawLineToolVertices( - _i15.Canvas? canvas, - _i20.VertexStack? vertexStack, + _i17.Canvas? canvas, + _i22.VertexStack? vertexStack, ) => super.noSuchMethod( Invocation.method( @@ -433,7 +468,7 @@ class MockCommandManager extends _i1.Mock implements _i18.CommandManager { ); @override - _i3.ToolData getNextTool(_i18.ActionType? actionType) => (super.noSuchMethod( + _i3.ToolData getNextTool(_i20.ActionType? actionType) => (super.noSuchMethod( Invocation.method( #getNextTool, [actionType], @@ -448,27 +483,27 @@ class MockCommandManager extends _i1.Mock implements _i18.CommandManager { ) as _i3.ToolData); @override - List<_i5.LineCommand> getTopLineCommandSequence() => (super.noSuchMethod( + List<_i6.LineCommand> getTopLineCommandSequence() => (super.noSuchMethod( Invocation.method( #getTopLineCommandSequence, [], ), - returnValue: <_i5.LineCommand>[], - ) as List<_i5.LineCommand>); + returnValue: <_i6.LineCommand>[], + ) as List<_i6.LineCommand>); } /// A class which mocks [CommandFactory]. /// /// See the documentation for Mockito's code generation for more information. -class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { +class MockCommandFactory extends _i1.Mock implements _i23.CommandFactory { MockCommandFactory() { _i1.throwOnMissingStub(this); } @override _i4.PathCommand createPathCommand( - _i17.PathWithActionHistory? path, - _i15.Paint? paint, + _i19.PathWithActionHistory? path, + _i17.Paint? paint, ) => (super.noSuchMethod( Invocation.method( @@ -491,11 +526,46 @@ class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { ) as _i4.PathCommand); @override - _i5.LineCommand createLineCommand( - _i17.PathWithActionHistory? path, - _i15.Paint? paint, - _i15.Offset? startPoint, - _i15.Offset? endPoint, + _i5.ClipPathCommand createClipPathCommand( + _i19.PathWithActionHistory? path, + _i17.Paint? paint, { + _i17.Offset? startPoint, + _i17.Offset? endPoint, + }) => + (super.noSuchMethod( + Invocation.method( + #createClipPathCommand, + [ + path, + paint, + ], + { + #startPoint: startPoint, + #endPoint: endPoint, + }, + ), + returnValue: _FakeClipPathCommand_3( + this, + Invocation.method( + #createClipPathCommand, + [ + path, + paint, + ], + { + #startPoint: startPoint, + #endPoint: endPoint, + }, + ), + ), + ) as _i5.ClipPathCommand); + + @override + _i6.LineCommand createLineCommand( + _i19.PathWithActionHistory? path, + _i17.Paint? paint, + _i17.Offset? startPoint, + _i17.Offset? endPoint, ) => (super.noSuchMethod( Invocation.method( @@ -507,7 +577,7 @@ class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { endPoint, ], ), - returnValue: _FakeLineCommand_3( + returnValue: _FakeLineCommand_4( this, Invocation.method( #createLineCommand, @@ -519,16 +589,16 @@ class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { ], ), ), - ) as _i5.LineCommand); + ) as _i6.LineCommand); @override - _i6.SquareShapeCommand createSquareShapeCommand( - _i15.Paint? paint, - _i15.Offset? topLeft, - _i15.Offset? topRight, - _i15.Offset? bottomLeft, - _i15.Offset? bottomRight, - _i22.ShapeStyle? style, + _i7.SquareShapeCommand createSquareShapeCommand( + _i17.Paint? paint, + _i17.Offset? topLeft, + _i17.Offset? topRight, + _i17.Offset? bottomLeft, + _i17.Offset? bottomRight, + _i24.ShapeStyle? style, ) => (super.noSuchMethod( Invocation.method( @@ -542,7 +612,7 @@ class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { style, ], ), - returnValue: _FakeSquareShapeCommand_4( + returnValue: _FakeSquareShapeCommand_5( this, Invocation.method( #createSquareShapeCommand, @@ -556,15 +626,15 @@ class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { ], ), ), - ) as _i6.SquareShapeCommand); + ) as _i7.SquareShapeCommand); @override - _i7.EllipseShapeCommand createEllipseShapeCommand( - _i15.Paint? paint, + _i8.EllipseShapeCommand createEllipseShapeCommand( + _i17.Paint? paint, double? radiusX, double? radiusY, - _i15.Offset? center, - _i22.ShapeStyle? style, + _i17.Offset? center, + _i24.ShapeStyle? style, double? angle, ) => (super.noSuchMethod( @@ -579,7 +649,7 @@ class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { angle, ], ), - returnValue: _FakeEllipseShapeCommand_5( + returnValue: _FakeEllipseShapeCommand_6( this, Invocation.method( #createEllipseShapeCommand, @@ -593,13 +663,13 @@ class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { ], ), ), - ) as _i7.EllipseShapeCommand); + ) as _i8.EllipseShapeCommand); @override - _i8.ClipboardCommand createClipboardCommand( - _i15.Paint? paint, - _i23.Uint8List? imageData, - _i15.Offset? offset, + _i9.ClipboardCommand createClipboardCommand( + _i17.Paint? paint, + _i25.Uint8List? imageData, + _i17.Offset? offset, double? scale, double? rotation, ) => @@ -614,7 +684,7 @@ class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { rotation, ], ), - returnValue: _FakeClipboardCommand_6( + returnValue: _FakeClipboardCommand_7( this, Invocation.method( #createClipboardCommand, @@ -627,15 +697,15 @@ class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { ], ), ), - ) as _i8.ClipboardCommand); + ) as _i9.ClipboardCommand); @override - _i9.TextCommand createTextCommand( - _i15.Offset? point, + _i10.TextCommand createTextCommand( + _i17.Offset? point, String? text, - _i16.TextStyle? style, + _i18.TextStyle? style, double? fontSize, - _i15.Paint? paint, + _i17.Paint? paint, double? rotationAngle, { double? scaleX = 1.0, double? scaleY = 1.0, @@ -656,7 +726,7 @@ class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { #scaleY: scaleY, }, ), - returnValue: _FakeTextCommand_7( + returnValue: _FakeTextCommand_8( this, Invocation.method( #createTextCommand, @@ -674,15 +744,15 @@ class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { }, ), ), - ) as _i9.TextCommand); + ) as _i10.TextCommand); @override - _i10.StarShapeCommand createStarShapeCommand( - _i15.Paint? paint, + _i11.StarShapeCommand createStarShapeCommand( + _i17.Paint? paint, int? numPoints, double? angle, - _i15.Offset? center, - _i22.ShapeStyle? style, + _i17.Offset? center, + _i24.ShapeStyle? style, double? radiusX, double? radiusY, ) => @@ -699,7 +769,7 @@ class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { radiusY, ], ), - returnValue: _FakeStarShapeCommand_8( + returnValue: _FakeStarShapeCommand_9( this, Invocation.method( #createStarShapeCommand, @@ -714,16 +784,16 @@ class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { ], ), ), - ) as _i10.StarShapeCommand); + ) as _i11.StarShapeCommand); @override - _i11.HeartShapeCommand createHeartShapeCommand( - _i15.Paint? paint, + _i12.HeartShapeCommand createHeartShapeCommand( + _i17.Paint? paint, double? width, double? height, double? angle, - _i15.Offset? center, - _i22.ShapeStyle? style, + _i17.Offset? center, + _i24.ShapeStyle? style, ) => (super.noSuchMethod( Invocation.method( @@ -737,7 +807,7 @@ class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { style, ], ), - returnValue: _FakeHeartShapeCommand_9( + returnValue: _FakeHeartShapeCommand_10( this, Invocation.method( #createHeartShapeCommand, @@ -751,12 +821,12 @@ class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { ], ), ), - ) as _i11.HeartShapeCommand); + ) as _i12.HeartShapeCommand); @override - _i12.SprayCommand createSprayCommand( - List<_i15.Offset>? points, - _i15.Paint? paint, + _i13.SprayCommand createSprayCommand( + List<_i17.Offset>? points, + _i17.Paint? paint, ) => (super.noSuchMethod( Invocation.method( @@ -766,7 +836,7 @@ class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { paint, ], ), - returnValue: _FakeSprayCommand_10( + returnValue: _FakeSprayCommand_11( this, Invocation.method( #createSprayCommand, @@ -776,50 +846,75 @@ class MockCommandFactory extends _i1.Mock implements _i21.CommandFactory { ], ), ), - ) as _i12.SprayCommand); + ) as _i13.SprayCommand); + + @override + _i14.ClipAreaCommand createClipAreaCommand( + _i19.PathWithActionHistory? path, + _i17.Paint? paint, + ) => + (super.noSuchMethod( + Invocation.method( + #createClipAreaCommand, + [ + path, + paint, + ], + ), + returnValue: _FakeClipAreaCommand_12( + this, + Invocation.method( + #createClipAreaCommand, + [ + path, + paint, + ], + ), + ), + ) as _i14.ClipAreaCommand); @override - _i13.DeleteRegionCommand createDeleteRegionCommand(_i15.Rect? region) => + _i15.DeleteRegionCommand createDeleteRegionCommand(_i17.Rect? region) => (super.noSuchMethod( Invocation.method( #createDeleteRegionCommand, [region], ), - returnValue: _FakeDeleteRegionCommand_11( + returnValue: _FakeDeleteRegionCommand_13( this, Invocation.method( #createDeleteRegionCommand, [region], ), ), - ) as _i13.DeleteRegionCommand); + ) as _i15.DeleteRegionCommand); } /// A class which mocks [Ref]. /// /// See the documentation for Mockito's code generation for more information. class MockRef extends _i1.Mock - implements _i14.Ref { + implements _i16.Ref { MockRef() { _i1.throwOnMissingStub(this); } @override - _i14.ProviderContainer get container => (super.noSuchMethod( + _i16.ProviderContainer get container => (super.noSuchMethod( Invocation.getter(#container), - returnValue: _FakeProviderContainer_12( + returnValue: _FakeProviderContainer_14( this, Invocation.getter(#container), ), - ) as _i14.ProviderContainer); + ) as _i16.ProviderContainer); @override - T refresh(_i14.Refreshable? provider) => (super.noSuchMethod( + T refresh(_i16.Refreshable? provider) => (super.noSuchMethod( Invocation.method( #refresh, [provider], ), - returnValue: _i24.dummyValue( + returnValue: _i26.dummyValue( this, Invocation.method( #refresh, @@ -829,7 +924,7 @@ class MockRef extends _i1.Mock ) as T); @override - void invalidate(_i14.ProviderOrFamily? provider) => super.noSuchMethod( + void invalidate(_i16.ProviderOrFamily? provider) => super.noSuchMethod( Invocation.method( #invalidate, [provider], @@ -921,12 +1016,12 @@ class MockRef extends _i1.Mock ); @override - T read(_i14.ProviderListenable? provider) => (super.noSuchMethod( + T read(_i16.ProviderListenable? provider) => (super.noSuchMethod( Invocation.method( #read, [provider], ), - returnValue: _i24.dummyValue( + returnValue: _i26.dummyValue( this, Invocation.method( #read, @@ -936,7 +1031,7 @@ class MockRef extends _i1.Mock ) as T); @override - bool exists(_i14.ProviderBase? provider) => (super.noSuchMethod( + bool exists(_i16.ProviderBase? provider) => (super.noSuchMethod( Invocation.method( #exists, [provider], @@ -945,12 +1040,12 @@ class MockRef extends _i1.Mock ) as bool); @override - T watch(_i14.ProviderListenable? provider) => (super.noSuchMethod( + T watch(_i16.ProviderListenable? provider) => (super.noSuchMethod( Invocation.method( #watch, [provider], ), - returnValue: _i24.dummyValue( + returnValue: _i26.dummyValue( this, Invocation.method( #watch, @@ -960,23 +1055,23 @@ class MockRef extends _i1.Mock ) as T); @override - _i14.KeepAliveLink keepAlive() => (super.noSuchMethod( + _i16.KeepAliveLink keepAlive() => (super.noSuchMethod( Invocation.method( #keepAlive, [], ), - returnValue: _FakeKeepAliveLink_13( + returnValue: _FakeKeepAliveLink_15( this, Invocation.method( #keepAlive, [], ), ), - ) as _i14.KeepAliveLink); + ) as _i16.KeepAliveLink); @override - _i14.ProviderSubscription listen( - _i14.ProviderListenable? provider, + _i16.ProviderSubscription listen( + _i16.ProviderListenable? provider, void Function( T?, T, @@ -999,7 +1094,7 @@ class MockRef extends _i1.Mock #fireImmediately: fireImmediately, }, ), - returnValue: _FakeProviderSubscription_14( + returnValue: _FakeProviderSubscription_16( this, Invocation.method( #listen, @@ -1013,13 +1108,13 @@ class MockRef extends _i1.Mock }, ), ), - ) as _i14.ProviderSubscription); + ) as _i16.ProviderSubscription); } /// A class which mocks [Canvas]. /// /// See the documentation for Mockito's code generation for more information. -class MockCanvas extends _i1.Mock implements _i15.Canvas { +class MockCanvas extends _i1.Mock implements _i17.Canvas { MockCanvas() { _i1.throwOnMissingStub(this); } @@ -1035,8 +1130,8 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void saveLayer( - _i15.Rect? bounds, - _i15.Paint? paint, + _i17.Rect? bounds, + _i17.Paint? paint, ) => super.noSuchMethod( Invocation.method( @@ -1134,7 +1229,7 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { ); @override - void transform(_i23.Float64List? matrix4) => super.noSuchMethod( + void transform(_i25.Float64List? matrix4) => super.noSuchMethod( Invocation.method( #transform, [matrix4], @@ -1143,18 +1238,18 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { ); @override - _i23.Float64List getTransform() => (super.noSuchMethod( + _i25.Float64List getTransform() => (super.noSuchMethod( Invocation.method( #getTransform, [], ), - returnValue: _i23.Float64List(0), - ) as _i23.Float64List); + returnValue: _i25.Float64List(0), + ) as _i25.Float64List); @override void clipRect( - _i15.Rect? rect, { - _i15.ClipOp? clipOp = _i15.ClipOp.intersect, + _i17.Rect? rect, { + _i17.ClipOp? clipOp = _i17.ClipOp.intersect, bool? doAntiAlias = true, }) => super.noSuchMethod( @@ -1171,7 +1266,7 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void clipRRect( - _i15.RRect? rrect, { + _i17.RRect? rrect, { bool? doAntiAlias = true, }) => super.noSuchMethod( @@ -1185,7 +1280,7 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void clipPath( - _i15.Path? path, { + _i17.Path? path, { bool? doAntiAlias = true, }) => super.noSuchMethod( @@ -1198,39 +1293,39 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { ); @override - _i15.Rect getLocalClipBounds() => (super.noSuchMethod( + _i17.Rect getLocalClipBounds() => (super.noSuchMethod( Invocation.method( #getLocalClipBounds, [], ), - returnValue: _FakeRect_15( + returnValue: _FakeRect_17( this, Invocation.method( #getLocalClipBounds, [], ), ), - ) as _i15.Rect); + ) as _i17.Rect); @override - _i15.Rect getDestinationClipBounds() => (super.noSuchMethod( + _i17.Rect getDestinationClipBounds() => (super.noSuchMethod( Invocation.method( #getDestinationClipBounds, [], ), - returnValue: _FakeRect_15( + returnValue: _FakeRect_17( this, Invocation.method( #getDestinationClipBounds, [], ), ), - ) as _i15.Rect); + ) as _i17.Rect); @override void drawColor( - _i15.Color? color, - _i15.BlendMode? blendMode, + _i17.Color? color, + _i17.BlendMode? blendMode, ) => super.noSuchMethod( Invocation.method( @@ -1245,9 +1340,9 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawLine( - _i15.Offset? p1, - _i15.Offset? p2, - _i15.Paint? paint, + _i17.Offset? p1, + _i17.Offset? p2, + _i17.Paint? paint, ) => super.noSuchMethod( Invocation.method( @@ -1262,7 +1357,7 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { ); @override - void drawPaint(_i15.Paint? paint) => super.noSuchMethod( + void drawPaint(_i17.Paint? paint) => super.noSuchMethod( Invocation.method( #drawPaint, [paint], @@ -1272,8 +1367,8 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawRect( - _i15.Rect? rect, - _i15.Paint? paint, + _i17.Rect? rect, + _i17.Paint? paint, ) => super.noSuchMethod( Invocation.method( @@ -1288,8 +1383,8 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawRRect( - _i15.RRect? rrect, - _i15.Paint? paint, + _i17.RRect? rrect, + _i17.Paint? paint, ) => super.noSuchMethod( Invocation.method( @@ -1304,9 +1399,9 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawDRRect( - _i15.RRect? outer, - _i15.RRect? inner, - _i15.Paint? paint, + _i17.RRect? outer, + _i17.RRect? inner, + _i17.Paint? paint, ) => super.noSuchMethod( Invocation.method( @@ -1322,8 +1417,8 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawOval( - _i15.Rect? rect, - _i15.Paint? paint, + _i17.Rect? rect, + _i17.Paint? paint, ) => super.noSuchMethod( Invocation.method( @@ -1338,9 +1433,9 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawCircle( - _i15.Offset? c, + _i17.Offset? c, double? radius, - _i15.Paint? paint, + _i17.Paint? paint, ) => super.noSuchMethod( Invocation.method( @@ -1356,11 +1451,11 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawArc( - _i15.Rect? rect, + _i17.Rect? rect, double? startAngle, double? sweepAngle, bool? useCenter, - _i15.Paint? paint, + _i17.Paint? paint, ) => super.noSuchMethod( Invocation.method( @@ -1378,8 +1473,8 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawPath( - _i15.Path? path, - _i15.Paint? paint, + _i17.Path? path, + _i17.Paint? paint, ) => super.noSuchMethod( Invocation.method( @@ -1394,9 +1489,9 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawImage( - _i15.Image? image, - _i15.Offset? offset, - _i15.Paint? paint, + _i17.Image? image, + _i17.Offset? offset, + _i17.Paint? paint, ) => super.noSuchMethod( Invocation.method( @@ -1412,10 +1507,10 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawImageRect( - _i15.Image? image, - _i15.Rect? src, - _i15.Rect? dst, - _i15.Paint? paint, + _i17.Image? image, + _i17.Rect? src, + _i17.Rect? dst, + _i17.Paint? paint, ) => super.noSuchMethod( Invocation.method( @@ -1432,10 +1527,10 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawImageNine( - _i15.Image? image, - _i15.Rect? center, - _i15.Rect? dst, - _i15.Paint? paint, + _i17.Image? image, + _i17.Rect? center, + _i17.Rect? dst, + _i17.Paint? paint, ) => super.noSuchMethod( Invocation.method( @@ -1451,7 +1546,7 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { ); @override - void drawPicture(_i15.Picture? picture) => super.noSuchMethod( + void drawPicture(_i17.Picture? picture) => super.noSuchMethod( Invocation.method( #drawPicture, [picture], @@ -1461,8 +1556,8 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawParagraph( - _i15.Paragraph? paragraph, - _i15.Offset? offset, + _i17.Paragraph? paragraph, + _i17.Offset? offset, ) => super.noSuchMethod( Invocation.method( @@ -1477,9 +1572,9 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawPoints( - _i15.PointMode? pointMode, - List<_i15.Offset>? points, - _i15.Paint? paint, + _i17.PointMode? pointMode, + List<_i17.Offset>? points, + _i17.Paint? paint, ) => super.noSuchMethod( Invocation.method( @@ -1495,9 +1590,9 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawRawPoints( - _i15.PointMode? pointMode, - _i23.Float32List? points, - _i15.Paint? paint, + _i17.PointMode? pointMode, + _i25.Float32List? points, + _i17.Paint? paint, ) => super.noSuchMethod( Invocation.method( @@ -1513,9 +1608,9 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawVertices( - _i15.Vertices? vertices, - _i15.BlendMode? blendMode, - _i15.Paint? paint, + _i17.Vertices? vertices, + _i17.BlendMode? blendMode, + _i17.Paint? paint, ) => super.noSuchMethod( Invocation.method( @@ -1531,13 +1626,13 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawAtlas( - _i15.Image? atlas, - List<_i15.RSTransform>? transforms, - List<_i15.Rect>? rects, - List<_i15.Color>? colors, - _i15.BlendMode? blendMode, - _i15.Rect? cullRect, - _i15.Paint? paint, + _i17.Image? atlas, + List<_i17.RSTransform>? transforms, + List<_i17.Rect>? rects, + List<_i17.Color>? colors, + _i17.BlendMode? blendMode, + _i17.Rect? cullRect, + _i17.Paint? paint, ) => super.noSuchMethod( Invocation.method( @@ -1557,13 +1652,13 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawRawAtlas( - _i15.Image? atlas, - _i23.Float32List? rstTransforms, - _i23.Float32List? rects, - _i23.Int32List? colors, - _i15.BlendMode? blendMode, - _i15.Rect? cullRect, - _i15.Paint? paint, + _i17.Image? atlas, + _i25.Float32List? rstTransforms, + _i25.Float32List? rects, + _i25.Int32List? colors, + _i17.BlendMode? blendMode, + _i17.Rect? cullRect, + _i17.Paint? paint, ) => super.noSuchMethod( Invocation.method( @@ -1583,8 +1678,8 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { @override void drawShadow( - _i15.Path? path, - _i15.Color? color, + _i17.Path? path, + _i17.Color? color, double? elevation, bool? transparentOccluder, ) => @@ -1605,22 +1700,22 @@ class MockCanvas extends _i1.Mock implements _i15.Canvas { /// A class which mocks [TextCommand]. /// /// See the documentation for Mockito's code generation for more information. -class MockTextCommand extends _i1.Mock implements _i9.TextCommand { +class MockTextCommand extends _i1.Mock implements _i10.TextCommand { MockTextCommand() { _i1.throwOnMissingStub(this); } @override - _i15.Offset get point => (super.noSuchMethod( + _i17.Offset get point => (super.noSuchMethod( Invocation.getter(#point), - returnValue: _FakeOffset_16( + returnValue: _FakeOffset_18( this, Invocation.getter(#point), ), - ) as _i15.Offset); + ) as _i17.Offset); @override - set point(_i15.Offset? _point) => super.noSuchMethod( + set point(_i17.Offset? _point) => super.noSuchMethod( Invocation.setter( #point, _point, @@ -1629,18 +1724,18 @@ class MockTextCommand extends _i1.Mock implements _i9.TextCommand { ); @override - _i16.TextStyle get style => (super.noSuchMethod( + _i18.TextStyle get style => (super.noSuchMethod( Invocation.getter(#style), - returnValue: _FakeTextStyle_17( + returnValue: _FakeTextStyle_19( this, Invocation.getter(#style), ), - ) as _i16.TextStyle); + ) as _i18.TextStyle); @override String get text => (super.noSuchMethod( Invocation.getter(#text), - returnValue: _i24.dummyValue( + returnValue: _i26.dummyValue( this, Invocation.getter(#text), ), @@ -1661,7 +1756,7 @@ class MockTextCommand extends _i1.Mock implements _i9.TextCommand { @override String get type => (super.noSuchMethod( Invocation.getter(#type), - returnValue: _i24.dummyValue( + returnValue: _i26.dummyValue( this, Invocation.getter(#type), ), @@ -1698,16 +1793,16 @@ class MockTextCommand extends _i1.Mock implements _i9.TextCommand { ) as bool); @override - _i15.Paint get paint => (super.noSuchMethod( + _i17.Paint get paint => (super.noSuchMethod( Invocation.getter(#paint), - returnValue: _i24.dummyValue<_i15.Paint>( + returnValue: _i26.dummyValue<_i17.Paint>( this, Invocation.getter(#paint), ), - ) as _i15.Paint); + ) as _i17.Paint); @override - void call(_i15.Canvas? canvas) => super.noSuchMethod( + void call(_i17.Canvas? canvas) => super.noSuchMethod( Invocation.method( #call, [canvas], @@ -1725,89 +1820,89 @@ class MockTextCommand extends _i1.Mock implements _i9.TextCommand { ) as Map); @override - _i25.Future prepareForRuntime() => (super.noSuchMethod( + _i27.Future prepareForRuntime() => (super.noSuchMethod( Invocation.method( #prepareForRuntime, [], ), - returnValue: _i25.Future.value(), - returnValueForMissingStub: _i25.Future.value(), - ) as _i25.Future); + returnValue: _i27.Future.value(), + returnValueForMissingStub: _i27.Future.value(), + ) as _i27.Future); } /// A class which mocks [GraphicFactory]. /// /// See the documentation for Mockito's code generation for more information. -class MockGraphicFactory extends _i1.Mock implements _i26.GraphicFactory { +class MockGraphicFactory extends _i1.Mock implements _i28.GraphicFactory { MockGraphicFactory() { _i1.throwOnMissingStub(this); } @override - _i15.Paint createPaint() => (super.noSuchMethod( + _i17.Paint createPaint() => (super.noSuchMethod( Invocation.method( #createPaint, [], ), - returnValue: _i24.dummyValue<_i15.Paint>( + returnValue: _i26.dummyValue<_i17.Paint>( this, Invocation.method( #createPaint, [], ), ), - ) as _i15.Paint); + ) as _i17.Paint); @override - _i17.PathWithActionHistory createPathWithActionHistory() => + _i19.PathWithActionHistory createPathWithActionHistory() => (super.noSuchMethod( Invocation.method( #createPathWithActionHistory, [], ), - returnValue: _FakePathWithActionHistory_18( + returnValue: _FakePathWithActionHistory_20( this, Invocation.method( #createPathWithActionHistory, [], ), ), - ) as _i17.PathWithActionHistory); + ) as _i19.PathWithActionHistory); @override - _i15.PictureRecorder createPictureRecorder() => (super.noSuchMethod( + _i17.PictureRecorder createPictureRecorder() => (super.noSuchMethod( Invocation.method( #createPictureRecorder, [], ), - returnValue: _FakePictureRecorder_19( + returnValue: _FakePictureRecorder_21( this, Invocation.method( #createPictureRecorder, [], ), ), - ) as _i15.PictureRecorder); + ) as _i17.PictureRecorder); @override - _i15.Canvas createCanvasWithRecorder(_i15.PictureRecorder? recorder) => + _i17.Canvas createCanvasWithRecorder(_i17.PictureRecorder? recorder) => (super.noSuchMethod( Invocation.method( #createCanvasWithRecorder, [recorder], ), - returnValue: _FakeCanvas_20( + returnValue: _FakeCanvas_22( this, Invocation.method( #createCanvasWithRecorder, [recorder], ), ), - ) as _i15.Canvas); + ) as _i17.Canvas); @override - _i15.Paint createWatercolorPaint( - _i15.Paint? originalPaint, + _i17.Paint createWatercolorPaint( + _i17.Paint? originalPaint, double? blurSigma, ) => (super.noSuchMethod( @@ -1818,7 +1913,7 @@ class MockGraphicFactory extends _i1.Mock implements _i26.GraphicFactory { blurSigma, ], ), - returnValue: _i24.dummyValue<_i15.Paint>( + returnValue: _i26.dummyValue<_i17.Paint>( this, Invocation.method( #createWatercolorPaint, @@ -1828,43 +1923,43 @@ class MockGraphicFactory extends _i1.Mock implements _i26.GraphicFactory { ], ), ), - ) as _i15.Paint); + ) as _i17.Paint); @override - _i15.Paint copyPaint(_i15.Paint? original) => (super.noSuchMethod( + _i17.Paint copyPaint(_i17.Paint? original) => (super.noSuchMethod( Invocation.method( #copyPaint, [original], ), - returnValue: _i24.dummyValue<_i15.Paint>( + returnValue: _i26.dummyValue<_i17.Paint>( this, Invocation.method( #copyPaint, [original], ), ), - ) as _i15.Paint); + ) as _i17.Paint); } /// A class which mocks [BoundingBox]. /// /// See the documentation for Mockito's code generation for more information. -class MockBoundingBox extends _i1.Mock implements _i27.BoundingBox { +class MockBoundingBox extends _i1.Mock implements _i29.BoundingBox { MockBoundingBox() { _i1.throwOnMissingStub(this); } @override - _i15.Offset get center => (super.noSuchMethod( + _i17.Offset get center => (super.noSuchMethod( Invocation.getter(#center), - returnValue: _FakeOffset_16( + returnValue: _FakeOffset_18( this, Invocation.getter(#center), ), - ) as _i15.Offset); + ) as _i17.Offset); @override - set center(_i15.Offset? _center) => super.noSuchMethod( + set center(_i17.Offset? _center) => super.noSuchMethod( Invocation.setter( #center, _center, @@ -1918,13 +2013,13 @@ class MockBoundingBox extends _i1.Mock implements _i27.BoundingBox { ); @override - _i28.BoundingBoxAction get currentAction => (super.noSuchMethod( + _i30.BoundingBoxAction get currentAction => (super.noSuchMethod( Invocation.getter(#currentAction), - returnValue: _i28.BoundingBoxAction.none, - ) as _i28.BoundingBoxAction); + returnValue: _i30.BoundingBoxAction.none, + ) as _i30.BoundingBoxAction); @override - set currentAction(_i28.BoundingBoxAction? _currentAction) => + set currentAction(_i30.BoundingBoxAction? _currentAction) => super.noSuchMethod( Invocation.setter( #currentAction, @@ -1934,15 +2029,15 @@ class MockBoundingBox extends _i1.Mock implements _i27.BoundingBox { ); @override - _i29.BoundingBoxResizeAction get currentBoundingBoxResizeAction => + _i31.BoundingBoxResizeAction get currentBoundingBoxResizeAction => (super.noSuchMethod( Invocation.getter(#currentBoundingBoxResizeAction), - returnValue: _i29.BoundingBoxResizeAction.none, - ) as _i29.BoundingBoxResizeAction); + returnValue: _i31.BoundingBoxResizeAction.none, + ) as _i31.BoundingBoxResizeAction); @override set currentBoundingBoxResizeAction( - _i29.BoundingBoxResizeAction? _currentBoundingBoxResizeAction) => + _i31.BoundingBoxResizeAction? _currentBoundingBoxResizeAction) => super.noSuchMethod( Invocation.setter( #currentBoundingBoxResizeAction, @@ -1952,7 +2047,7 @@ class MockBoundingBox extends _i1.Mock implements _i27.BoundingBox { ); @override - set lastDragGlobalPosition(_i15.Offset? _lastDragGlobalPosition) => + set lastDragGlobalPosition(_i17.Offset? _lastDragGlobalPosition) => super.noSuchMethod( Invocation.setter( #lastDragGlobalPosition, @@ -1962,7 +2057,7 @@ class MockBoundingBox extends _i1.Mock implements _i27.BoundingBox { ); @override - set dragStartLocalPosition(_i15.Offset? _dragStartLocalPosition) => + set dragStartLocalPosition(_i17.Offset? _dragStartLocalPosition) => super.noSuchMethod( Invocation.setter( #dragStartLocalPosition, @@ -1988,16 +2083,16 @@ class MockBoundingBox extends _i1.Mock implements _i27.BoundingBox { ); @override - _i15.Paint get boxPaint => (super.noSuchMethod( + _i17.Paint get boxPaint => (super.noSuchMethod( Invocation.getter(#boxPaint), - returnValue: _i24.dummyValue<_i15.Paint>( + returnValue: _i26.dummyValue<_i17.Paint>( this, Invocation.getter(#boxPaint), ), - ) as _i15.Paint); + ) as _i17.Paint); @override - set boxPaint(_i15.Paint? _boxPaint) => super.noSuchMethod( + set boxPaint(_i17.Paint? _boxPaint) => super.noSuchMethod( Invocation.setter( #boxPaint, _boxPaint, @@ -2006,16 +2101,16 @@ class MockBoundingBox extends _i1.Mock implements _i27.BoundingBox { ); @override - _i15.Paint get handlePaint => (super.noSuchMethod( + _i17.Paint get handlePaint => (super.noSuchMethod( Invocation.getter(#handlePaint), - returnValue: _i24.dummyValue<_i15.Paint>( + returnValue: _i26.dummyValue<_i17.Paint>( this, Invocation.getter(#handlePaint), ), - ) as _i15.Paint); + ) as _i17.Paint); @override - set handlePaint(_i15.Paint? _handlePaint) => super.noSuchMethod( + set handlePaint(_i17.Paint? _handlePaint) => super.noSuchMethod( Invocation.setter( #handlePaint, _handlePaint, @@ -2024,16 +2119,16 @@ class MockBoundingBox extends _i1.Mock implements _i27.BoundingBox { ); @override - _i15.Paint get rotationHandlePaint => (super.noSuchMethod( + _i17.Paint get rotationHandlePaint => (super.noSuchMethod( Invocation.getter(#rotationHandlePaint), - returnValue: _i24.dummyValue<_i15.Paint>( + returnValue: _i26.dummyValue<_i17.Paint>( this, Invocation.getter(#rotationHandlePaint), ), - ) as _i15.Paint); + ) as _i17.Paint); @override - set rotationHandlePaint(_i15.Paint? _rotationHandlePaint) => + set rotationHandlePaint(_i17.Paint? _rotationHandlePaint) => super.noSuchMethod( Invocation.setter( #rotationHandlePaint, @@ -2058,25 +2153,25 @@ class MockBoundingBox extends _i1.Mock implements _i27.BoundingBox { ); @override - _i15.Rect get rect => (super.noSuchMethod( + _i17.Rect get rect => (super.noSuchMethod( Invocation.getter(#rect), - returnValue: _FakeRect_15( + returnValue: _FakeRect_17( this, Invocation.getter(#rect), ), - ) as _i15.Rect); + ) as _i17.Rect); @override - List<_i15.Offset> getCorners() => (super.noSuchMethod( + List<_i17.Offset> getCorners() => (super.noSuchMethod( Invocation.method( #getCorners, [], ), - returnValue: <_i15.Offset>[], - ) as List<_i15.Offset>); + returnValue: <_i17.Offset>[], + ) as List<_i17.Offset>); @override - void determineAction(_i15.Offset? globalPoint) => super.noSuchMethod( + void determineAction(_i17.Offset? globalPoint) => super.noSuchMethod( Invocation.method( #determineAction, [globalPoint], @@ -2085,7 +2180,7 @@ class MockBoundingBox extends _i1.Mock implements _i27.BoundingBox { ); @override - void updateDrag(_i15.Offset? globalPoint) => super.noSuchMethod( + void updateDrag(_i17.Offset? globalPoint) => super.noSuchMethod( Invocation.method( #updateDrag, [globalPoint], @@ -2103,7 +2198,7 @@ class MockBoundingBox extends _i1.Mock implements _i27.BoundingBox { ); @override - void drawGuides(_i15.Canvas? canvas) => super.noSuchMethod( + void drawGuides(_i17.Canvas? canvas) => super.noSuchMethod( Invocation.method( #drawGuides, [canvas], diff --git a/test/unit/workspace/render_image_for_export_test.mocks.dart b/test/unit/workspace/render_image_for_export_test.mocks.dart index b8276da8..45d34a79 100644 --- a/test/unit/workspace/render_image_for_export_test.mocks.dart +++ b/test/unit/workspace/render_image_for_export_test.mocks.dart @@ -677,6 +677,15 @@ class MockCommandManager extends _i1.Mock implements _i6.CommandManager { returnValueForMissingStub: null, ); + @override + void removeCommand(_i3.Command? commandToRemove) => super.noSuchMethod( + Invocation.method( + #removeCommand, + [commandToRemove], + ), + returnValueForMissingStub: null, + ); + @override void setUndoStack(List<_i3.Command>? commands) => super.noSuchMethod( Invocation.method( diff --git a/test/widget/workspace_page/clipping_tool_test.dart b/test/widget/workspace_page/clipping_tool_test.dart new file mode 100644 index 00000000..40845228 --- /dev/null +++ b/test/widget/workspace_page/clipping_tool_test.dart @@ -0,0 +1,45 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:paintroid/app.dart'; +import 'package:paintroid/core/tools/tool_data.dart'; +import '../../utils/test_utils.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + late Widget sut; + + setUp(() async => sut = ProviderScope(child: App(showOnboardingPage: false))); + + testWidgets('[CLIPPING_TOOL]: selecting clipping tool shows checkmark', + (WidgetTester tester) async { + UIInteraction.initialize(tester); + await tester.pumpWidget(sut); + await UIInteraction.createNewImage(); + + expect(WidgetFinder.checkMark, findsNothing); + + await UIInteraction.selectTool(ToolData.CLIPPING.name); + + expect(WidgetFinder.checkMark, findsOneWidget); + }); + + testWidgets('[CLIPPING_TOOL]: selecting other tools hide the checkmark', + (WidgetTester tester) async { + UIInteraction.initialize(tester); + await tester.pumpWidget(sut); + await UIInteraction.createNewImage(); + + expect(WidgetFinder.checkMark, findsNothing); + + await UIInteraction.selectTool(ToolData.CLIPPING.name); + + expect(WidgetFinder.checkMark, findsOneWidget); + + await UIInteraction.selectTool(ToolData.BRUSH.name); + + expect(WidgetFinder.checkMark, findsNothing); + }); +}