Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/core/commands/command_factory/command_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ import 'package:paintroid/core/commands/command_implementation/graphic/shape/squ
import 'package:paintroid/core/commands/command_implementation/graphic/shape/star_shape_command.dart';
import 'package:paintroid/core/commands/command_implementation/graphic/spray_command.dart';
import 'package:paintroid/core/commands/command_implementation/graphic/color_changed_command.dart';
import 'package:paintroid/core/commands/path_with_action_history.dart';
import 'package:paintroid/core/models/path_model.dart';
import 'package:paintroid/core/enums/shape_style.dart';

class CommandFactory {
const CommandFactory();

PathCommand createPathCommand(
PathWithActionHistory path,
PathModel path,
Paint paint, {
bool isCursor = false,
}) =>
PathCommand(path, paint, isCursorPath: isCursor);

LineCommand createLineCommand(
PathWithActionHistory path,
PathModel path,
Paint paint,
Offset startPoint,
Offset endPoint,
Expand Down
18 changes: 10 additions & 8 deletions lib/core/commands/command_implementation/graphic/line_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ import 'dart:ui';
import 'package:freezed_annotation/freezed_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/models/path_model.dart';
import 'package:paintroid/core/models/path_actions/move_to_action.dart';
import 'package:paintroid/core/models/path_actions/line_to_action.dart';
import 'package:paintroid/core/json_serialization/converter/offset_converter.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 'line_command.g.dart';

@JsonSerializable()
@JsonSerializable(explicitToJson: true)
class LineCommand extends GraphicCommand {
final String type;
final int version;
bool isSourcePath = false;

@PathWithActionHistoryConverter()
PathWithActionHistory path;
PathModel path;

@OffsetConverter()
Offset startPoint;
Expand All @@ -41,7 +41,7 @@ class LineCommand extends GraphicCommand {

@override
void call(Canvas canvas) {
canvas.drawPath(path.path, paint);
canvas.drawPath(path.nativePath, paint);
}

@override
Expand All @@ -51,7 +51,7 @@ class LineCommand extends GraphicCommand {
isSourcePath = true;
}

void updatePath(PathWithActionHistory newPath) {
void updatePath(PathModel newPath) {
path = newPath;
final moveAction = path.actions.first as MoveToAction;
final lineAction = path.actions.last as LineToAction;
Expand All @@ -63,11 +63,13 @@ class LineCommand extends GraphicCommand {
Map<String, dynamic> toJson() => _$LineCommandToJson(this);

factory LineCommand.fromJson(Map<String, dynamic> json) {
int version = json['version'] as int;
int? version = json['version'] as int?;

switch (version) {
case Version.v1:
return _$LineCommandFromJson(json);
case null:
return _$LineCommandFromJson(json);
case Version.v2:
// For different versions of PathCommand the deserialization
// has to be implemented manually.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ 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/models/path_model.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 'path_command.g.dart';

@JsonSerializable()
@JsonSerializable(explicitToJson: true)
class PathCommand extends GraphicCommand {
final String type;
final int version;
Expand All @@ -28,12 +27,11 @@ class PathCommand extends GraphicCommand {
}) : version =
version ?? VersionStrategyManager.strategy.getPathCommandVersion();

@PathWithActionHistoryConverter()
final PathWithActionHistory path;
final PathModel path;

@override
void call(Canvas canvas) {
canvas.drawPath(path.path, paint);
canvas.drawPath(path.nativePath, paint);
}

@override
Expand All @@ -43,11 +41,13 @@ class PathCommand extends GraphicCommand {
Map<String, dynamic> toJson() => _$PathCommandToJson(this);

factory PathCommand.fromJson(Map<String, dynamic> json) {
int version = json['version'] as int;
int? version = json['version'] as int?;

switch (version) {
case Version.v1:
return _$PathCommandFromJson(json);
case null:
return _$PathCommandFromJson(json);
case Version.v2:
// For different versions of PathCommand the deserialization
// has to be implemented manually.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions lib/core/commands/graphic_factory/graphic_factory.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:paintroid/core/commands/path_with_action_history.dart';
import 'package:paintroid/core/models/path_model.dart';

class GraphicFactory {
const GraphicFactory();
Expand Down Expand Up @@ -52,8 +52,7 @@ class GraphicFactory {
..strokeJoin = StrokeJoin.round;
}

PathWithActionHistory createPathWithActionHistory() =>
PathWithActionHistory();
PathModel createPathModel() => PathModel();

PictureRecorder createPictureRecorder() => PictureRecorder();

Expand Down
93 changes: 0 additions & 93 deletions lib/core/commands/path_with_action_history.dart

This file was deleted.

45 changes: 0 additions & 45 deletions lib/core/json_serialization/converter/path_action_converter.dart

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SerializerVersion {
static const int CLIPBOARD_COMMAND_VERSION = Version.v1;
static const int DELETE_REGION_COMMAND_VERSION = Version.v1;
static const int COLOR_CHANGED_COMMAND_VERSION = Version.v1;
static const int PATH_MODEL_VERSION = Version.v1;
}

class Version {
Expand Down
4 changes: 4 additions & 0 deletions lib/core/json_serialization/versioning/version_strategy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ abstract class IVersionStrategy {
int getDeleteRegionCommandVersion();

int getColorChangedCommandVersion();
int getPathModelVersion();
}

class ProductionVersionStrategy implements IVersionStrategy {
Expand Down Expand Up @@ -69,6 +70,9 @@ class ProductionVersionStrategy implements IVersionStrategy {
@override
int getColorChangedCommandVersion() =>
SerializerVersion.COLOR_CHANGED_COMMAND_VERSION;

@override
int getPathModelVersion() => SerializerVersion.PATH_MODEL_VERSION;
}

class VersionStrategyManager {
Expand Down
Loading
Loading