Skip to content

Commit 6fde44b

Browse files
committed
feat: Add zkapp panStart panUpdate panEnd events.
Add zkapp panStart panUpdate panEnd events.
1 parent 9eeac1d commit 6fde44b

22 files changed

+132
-49
lines changed

Diff for: CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# 2.7.1
2+
- Add zkapp panStart panUpdate panEnd events.
3+
4+
# 2.6.1
5+
- Fix the time difference caused by switching between front and back of the app
6+
7+
# 2.5.2
8+
- Add auxiliary methods such as getTimeRatio and toSecond
9+
- Further optimize performance.
10+
11+
112
# 2.3.6
213
- Unused import: 'dart:ui'.;
314
- Using a colon as a separator before a default value is deprecated and will not be supported in language version 3.0 and later.

Diff for: lib/src/animate/animator.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Animator {
1414
Function? onComplete;
1515
String status = "stop";
1616

17-
ListMap _aniList = new ListMap();
17+
ListMap _aniList = ListMap();
1818
Animation? _currentAni;
1919
int _framesLength = -1;
2020

@@ -68,7 +68,7 @@ class Animator {
6868
////////////////////////////////////////////////////////////
6969
void make(String name,
7070
[List? frames, int rate = Constant.RATE, bool loop = false]) {
71-
Animation ani = new Animation(name, frames, rate, loop);
71+
Animation ani = Animation(name, frames, rate, loop);
7272
ani.framesLength = framesLength;
7373
ani.onComplete = onComplete;
7474

Diff for: lib/src/app.dart

+19-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import './event/event.dart';
66
import './node/stage.dart';
77
import "./utils/util.dart";
88
import "./math/point.dart";
9+
import "./math/mathutil.dart";
910

1011
class ZKApp {
1112
String type = "ZKApp";
@@ -18,8 +19,11 @@ class ZKApp {
1819
double delay = 1000 / 60;
1920
int _fps = 60;
2021

22+
static bool enableFixLongInterval = false;
23+
static double longIntervalTime = 0.5;
24+
2125
ZKApp() {
22-
this.stage.context = new ZKContext();
26+
this.stage.context = ZKContext();
2327
}
2428

2529
ZKContext? get context {
@@ -72,6 +76,14 @@ class ZKApp {
7276
return this.context!.getRandomPosition();
7377
}
7478

79+
double toSecond(int milliseconds) {
80+
return MathUtil.toSecond(milliseconds);
81+
}
82+
83+
double getTimeRatio(int milliseconds) {
84+
return MathUtil.getTimeRatio(milliseconds);
85+
}
86+
7587
static void fullScreen() {
7688
return Util.fullScreen();
7789
}
@@ -112,6 +124,12 @@ class ZKApp {
112124
this.stage.tapUp(event);
113125
}
114126

127+
panStart(ZKEvent event) {}
128+
129+
panUpdate(ZKEvent event) {}
130+
131+
panEnd(ZKEvent event) {}
132+
115133
dispose() {
116134
if (debug == true) print('Zerker:: Dispose $this');
117135

Diff for: lib/src/core/constant.dart

+2
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ class Constant {
1414
static const String ALL_FRAMES = "__ZK_ALL_FRAMES__";
1515

1616
static double ratio = 1;
17+
18+
static double afps = 0.01666;
1719
}

Diff for: lib/src/math/mathutil.dart

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import "dart:math";
22
import 'package:flutter/widgets.dart';
3+
import '../core/constant.dart';
34

45
class MathUtil {
56
static const double PI = 3.14159267;
@@ -28,6 +29,15 @@ class MathUtil {
2829
return Random().nextDouble() * (b - a) + a;
2930
}
3031

32+
static double toSecond(int milliseconds) {
33+
return milliseconds / Duration.millisecondsPerSecond;
34+
}
35+
36+
static double getTimeRatio(int milliseconds) {
37+
double second = toSecond(milliseconds);
38+
return second / Constant.afps;
39+
}
40+
3141
static Color getRandomColor() {
3242
return Color((Random().nextDouble() * 0xFFFFFF).toInt() << 0)
3343
.withOpacity(1.0);

Diff for: lib/src/math/point.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Point {
1111
}
1212

1313
Point clone() {
14-
return new Point(this.x, this.y);
14+
return Point(this.x, this.y);
1515
}
1616

1717
void copy(dynamic p) {

Diff for: lib/src/node/graphic.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import "../utils/listmap.dart";
77

88
class ZKGraphic extends ZKNode {
99
Paint? _currentPaint;
10-
ListMap _drawList = new ListMap();
10+
ListMap _drawList = ListMap();
1111
double _alpha = 1;
1212

1313
@override
@@ -17,7 +17,7 @@ class ZKGraphic extends ZKNode {
1717
String type = "ZKGraphic";
1818

1919
ZKGraphic() : super() {
20-
//this._drawList = new ListMap();
20+
//this._drawList = ListMap();
2121
this.anchor.set(0.0, 0.0);
2222
}
2323

@@ -79,7 +79,7 @@ class ZKGraphic extends ZKNode {
7979

8080
void drawTriangle(
8181
double x1, double y1, double x2, double y2, double x3, double y3) {
82-
Path path = new Path();
82+
Path path = Path();
8383
path.moveTo(x1, y1);
8484
path.lineTo(x2, y2);
8585
path.lineTo(x3, y3);

Diff for: lib/src/node/image.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class ZKImage extends ZKNode {
6767
}
6868

6969
void lazyLoad(String url, [int delay = 0]) {
70-
_timer = new Timer(Duration(milliseconds: delay), () {
70+
_timer = Timer(Duration(milliseconds: delay), () {
7171
this.load(url);
7272
_timer?.cancel();
7373
});

Diff for: lib/src/node/node.dart

+16-12
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ class ZKNode {
1313
String id = "";
1414
String type = "ZKNode";
1515

16-
Point position = new Point(0.0, 0.0);
17-
Point anchor = new Point(0.5, 0.5);
18-
Point scale = new Point(1.0, 1.0);
19-
Point skew = new Point(0.0, 0.0);
16+
Point position = Point(0.0, 0.0);
17+
Point anchor = Point(0.5, 0.5);
18+
Point scale = Point(1.0, 1.0);
19+
Point skew = Point(0.0, 0.0);
2020

2121
double oriWidth = 0;
2222
double oriHeight = 0;
@@ -28,24 +28,24 @@ class ZKNode {
2828
ZKNode? parent;
2929
Canvas? canvas;
3030
Data data = Data();
31-
Paint paint = new Paint();
31+
Paint paint = Paint();
3232

3333
ZKContext? context;
3434
dynamic expansion;
3535
double worldAlpha = 1;
3636

37-
Matrix matrix = new Matrix();
37+
Matrix matrix = Matrix();
3838
double _alpha = 1;
3939
bool _debug = false;
4040
Color? _color;
4141

4242
ZKNode() {
4343
this.id = Util.uuid();
44-
// this.position = new Point(0.0, 0.0);
45-
// this.anchor = new Point(0.5, 0.5);
46-
// this.scale = new Point(1.0, 1.0);
47-
// this.skew = new Point(0.0, 0.0);
48-
// this.matrix = new Matrix();
44+
// this.position = Point(0.0, 0.0);
45+
// this.anchor = Point(0.5, 0.5);
46+
// this.scale = Point(1.0, 1.0);
47+
// this.skew = Point(0.0, 0.0);
48+
// this.matrix = Matrix();
4949

5050
this.init();
5151
}
@@ -55,7 +55,7 @@ class ZKNode {
5555
}
5656

5757
void createPaint() {
58-
//this.paint = new Paint();
58+
//this.paint = Paint();
5959
this.paint.color = Colors.blue;
6060
this.paint.style = PaintingStyle.fill;
6161
}
@@ -141,6 +141,10 @@ class ZKNode {
141141
return Offset(regX, regY);
142142
}
143143

144+
double getTimeRatio(int milliseconds) {
145+
return MathUtil.getTimeRatio(milliseconds);
146+
}
147+
144148
////////////////////////////////////////////////////////////
145149
///
146150
/// Update, render and other related functions

Diff for: lib/src/node/sprite.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class ZKSprite extends ZKImage {
1212
String type = "ZKSprite";
1313

1414
/// Animator
15-
Animator animator = new Animator();
15+
Animator animator = Animator();
1616
Timer? _timer;
1717

1818
ZKSprite(
@@ -23,14 +23,14 @@ class ZKSprite extends ZKImage {
2323
double width = 100,
2424
double height = 100})
2525
: super() {
26-
//this.animator = new Animator();
26+
//this.animator = Animator();
2727
if (key != null) {
2828
this.texture = ZKAssets.getAsset(key);
2929
this.textureType = ZKAssets.getType(texture)!;
3030
if (this.texture == null)
3131
throw ("Zerker:: Sorry, this Key '$key' does not get any assets!");
3232

33-
_timer = new Timer(Duration(milliseconds: 0), () {
33+
_timer = Timer(Duration(milliseconds: 0), () {
3434
this._loadComplete(this.texture!);
3535
_timer?.cancel();
3636
});

Diff for: lib/src/node/text.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class ZKText extends ZKNode {
66
TextStyle? _style;
77
TextSpan? _span;
88
bool _layouted = false;
9-
Offset _offset = new Offset(0, 0);
9+
Offset _offset = Offset(0, 0);
1010

1111
@override
1212
String type = "ZKText";
@@ -33,12 +33,12 @@ class ZKText extends ZKNode {
3333
}
3434

3535
TextSpan? createTextSpan([String t = ""]) {
36-
_span = new TextSpan(text: t, style: _style);
36+
_span = TextSpan(text: t, style: _style);
3737
return _span;
3838
}
3939

4040
TextPainter? createTextPainter() {
41-
_painter = new TextPainter(
41+
_painter = TextPainter(
4242
text: _span,
4343
textAlign: TextAlign.center,
4444
textDirection: TextDirection.ltr);

Diff for: lib/src/texture/atlas.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Atlas extends BaseTexture {
8282
var px = Util.getByPath(obj, "pivot.x");
8383
var py = Util.getByPath(obj, "pivot.y");
8484

85-
Frame frame = new Frame(this.type);
85+
Frame frame = Frame(this.type);
8686
frame.image = image!;
8787
frame.name = Util.getByPath(obj, "filename");
8888
frame.rotated = Util.getByPath(obj, "rotated");

Diff for: lib/src/texture/imgtexture.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ImgTexture extends BaseTexture {
2626
var w = image?.width.toDouble();
2727
var h = image?.height.toDouble();
2828

29-
Frame frame = new Frame(this.type);
29+
Frame frame = Frame(this.type);
3030
frame.image = image!;
3131
frame.setSrcRect(0, 0, w, h);
3232
frame.setDstRect(0, 0, w, h);

Diff for: lib/src/texture/spritesheet.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class SpriteSheet extends BaseTexture {
4242

4343
for (int i = 0; i < this.col; i++) {
4444
for (int j = 0; j < this.row; j++) {
45-
Frame frame = new Frame(this.type);
45+
Frame frame = Frame(this.type);
4646
frame.image = image!;
4747
frame.setSrcRect(j * w, i * h, w, h);
4848
frame.setDstRect(0, 0, w, h);

Diff for: lib/src/tween/miticker.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Ticker? _ticker;
55
class Miticker {
66
static Ticker? init(Function func) {
77
if (_ticker == null) {
8-
_ticker = new Ticker((Duration duration) {
8+
_ticker = Ticker((Duration duration) {
99
func(duration);
1010
});
1111
}

Diff for: lib/src/utils/imgloader.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ImgLoader {
5353
if (onError != null) onError("timeout");
5454
});
5555

56-
listener = new ImageStreamListener(onLoadHandler, onError: onErrorHandler);
56+
listener = ImageStreamListener(onLoadHandler, onError: onErrorHandler);
5757
stream.addListener(listener);
5858

5959
return await completer.future;

Diff for: lib/src/utils/listmap.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import 'dart:collection';
77
///
88
////////////////////////////////////////////////////////////
99
class ListMap {
10-
LinkedHashMap<String, dynamic> _map = new LinkedHashMap();
10+
LinkedHashMap<String, dynamic> _map = LinkedHashMap();
1111

1212
ListMap() {
13-
//this._map = new LinkedHashMap();
13+
//this._map = LinkedHashMap();
1414
}
1515

1616
void add(String id, dynamic item) {

Diff for: lib/src/utils/util.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Util {
77
///
88
////////////////////////////////////////////////////////////
99
static bool isNetUrl(String url) {
10-
RegExp reg = new RegExp(r"(https?|ftp):\/\/([\w.]+\/?)\S*");
10+
RegExp reg = RegExp(r"(https?|ftp):\/\/([\w.]+\/?)\S*");
1111
return reg.hasMatch(url);
1212
}
1313

@@ -57,8 +57,8 @@ class Util {
5757
static List convertConsecutiveList(List arr, [String? prefix]) {
5858
if (arr.length == 1 && arr[0] is String) {
5959
String str = arr[0];
60-
RegExp exp1 = new RegExp(r"^([0-9]*)\-([0-9]*)$");
61-
RegExp exp2 = new RegExp(r"{([0-9]*)\-([0-9]*)}");
60+
RegExp exp1 = RegExp(r"^([0-9]*)\-([0-9]*)$");
61+
RegExp exp2 = RegExp(r"{([0-9]*)\-([0-9]*)}");
6262

6363
if (exp1.hasMatch(str) || exp2.hasMatch(str)) {
6464
List result = [];

Diff for: lib/src/utils/uuid.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import 'dart:math' show Random;
55

66
class Uuid {
7-
final Random _random = new Random();
7+
final Random _random = Random();
88

99
String v4() {
1010
int special = 8 + _random.nextInt(4);

0 commit comments

Comments
 (0)