Skip to content

Commit 7a518e9

Browse files
committed
Only use the repaint event in ActiveShape.
1 parent a08bd53 commit 7a518e9

File tree

5 files changed

+15
-20
lines changed

5 files changed

+15
-20
lines changed

patterns/memento/memento_editor/editor/manipulator.dart

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,19 @@
11
import '../../../adapter/flutter_adapter/classic_app/classic_app.dart';
22
import '../shapes/shapes.dart';
33

4-
mixin Manipulator implements ClassicApp, Shapes {
4+
mixin Manipulator implements Shapes {
55
var _isMouseDown = false;
66

77
@override
88
void onMouseDown(double x, double y) {
99
_isMouseDown = true;
10-
final currSelection = activeShape;
11-
1210
select(x, y);
13-
14-
if (currSelection == activeShape) {
15-
return;
16-
}
17-
18-
if (activeShape == null) {
19-
unSelect();
20-
}
21-
22-
repaint();
2311
}
2412

2513
@override
2614
void onMouseMove(double x, double y) {
2715
if (_isMouseDown) {
2816
activeShape?.dragTo(x, y);
29-
repaint();
3017
}
3118
}
3219

patterns/memento/memento_editor/memento_pattern/originator.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import 'dart:convert';
22
import 'dart:typed_data';
33
import 'dart:ui';
44

5-
import '../../../adapter/flutter_adapter/classic_app/classic_app.dart';
65
import '../shapes/shapes.dart';
76
import '../shapes/shape.dart';
87
import 'snapshot.dart';
98

10-
mixin Originator implements Shapes, ClassicApp {
9+
mixin Originator implements Shapes {
1110
Snapshot backup() {
1211
final data = _allocateBuffer();
1312
_writeShapes(data);

patterns/memento/memento_editor/shapes/active_shape.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ class ActiveShape {
44
final Shape shape;
55
final void Function() repaint;
66

7-
ActiveShape(this.shape, this._xStart, this._yStart, this.repaint);
7+
ActiveShape(this.shape, this._xStart, this._yStart, this.repaint) {
8+
repaint();
9+
}
810

911
void changeSize(double delta) {
1012
final currentSize = shape.size;
@@ -30,7 +32,6 @@ class ActiveShape {
3032
void dragTo(double x, double y) {
3133
shape._x = x + _xStart;
3234
shape._y = y + _yStart;
33-
3435
repaint();
3536
}
3637

@@ -53,4 +54,8 @@ class ActiveShape {
5354
..color = Color(0xff26e6ff),
5455
);
5556
}
57+
58+
void dispose() {
59+
repaint();
60+
}
5661
}

patterns/memento/memento_editor/shapes/shapes.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mixin Shapes implements ClassicApp {
1515
if (shape != null) {
1616
_activeShape = ActiveShape(shape, shape.x - x, shape.y - y, repaint);
1717
} else {
18-
_activeShape = null;
18+
unSelect();
1919
}
2020
}
2121

@@ -30,6 +30,11 @@ mixin Shapes implements ClassicApp {
3030
}
3131

3232
void unSelect() {
33+
if (_activeShape == null) {
34+
return;
35+
}
36+
37+
_activeShape?.dispose();
3338
_activeShape = null;
3439
}
3540

patterns/memento/memento_editor/widgets/panels/shape_properties_widget.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class ShapePropertiesWidget extends StatelessWidget {
5353
colors: colors,
5454
onColorSelect: (newColor) {
5555
app.editor.activeShape?.changeColor(newColor);
56-
5756
},
5857
),
5958
],

0 commit comments

Comments
 (0)