Showing
1 changed file
with
23 additions
and
9 deletions
... | @@ -7,12 +7,16 @@ class GifGenerator { | ... | @@ -7,12 +7,16 @@ class GifGenerator { |
7 | this.canvas = canvas; | 7 | this.canvas = canvas; |
8 | this.width = canvas.getWidth(); | 8 | this.width = canvas.getWidth(); |
9 | this.height = canvas.getHeight(); | 9 | this.height = canvas.getHeight(); |
10 | - this.gif = new GIF(this.width, this.height); | ||
11 | 10 | ||
12 | - this.gif.start(); | 11 | + this._initializeGif(); |
12 | + } | ||
13 | + | ||
14 | + _initializeGif() { | ||
15 | + this.gif = new GIF(this.width, this.height); | ||
13 | this.gif.setTransparent(null); | 16 | this.gif.setTransparent(null); |
14 | this.gif.setRepeat(0); | 17 | this.gif.setRepeat(0); |
15 | this.gif.setQuality(10); | 18 | this.gif.setQuality(10); |
19 | + this.gif.start(); | ||
16 | } | 20 | } |
17 | 21 | ||
18 | _addFrame(delay = 0) { | 22 | _addFrame(delay = 0) { |
... | @@ -28,6 +32,8 @@ class GifGenerator { | ... | @@ -28,6 +32,8 @@ class GifGenerator { |
28 | } | 32 | } |
29 | 33 | ||
30 | make() { | 34 | make() { |
35 | + this._initializeGif(); | ||
36 | + | ||
31 | const fabricObjs = this.canvas.getObjects(); | 37 | const fabricObjs = this.canvas.getObjects(); |
32 | const objs = []; | 38 | const objs = []; |
33 | 39 | ||
... | @@ -41,6 +47,7 @@ class GifGenerator { | ... | @@ -41,6 +47,7 @@ class GifGenerator { |
41 | } | 47 | } |
42 | }); | 48 | }); |
43 | 49 | ||
50 | + return new Promise((resolve, reject) => { | ||
44 | if (objs.length > 0) { | 51 | if (objs.length > 0) { |
45 | let objIdx = 0; | 52 | let objIdx = 0; |
46 | let isAddMode = true; | 53 | let isAddMode = true; |
... | @@ -49,25 +56,32 @@ class GifGenerator { | ... | @@ -49,25 +56,32 @@ class GifGenerator { |
49 | if (isAddMode) { | 56 | if (isAddMode) { |
50 | const fabricObj = obj.getCurrentFabricObject(); | 57 | const fabricObj = obj.getCurrentFabricObject(); |
51 | obj.next(); | 58 | obj.next(); |
59 | + isAddMode = false; | ||
60 | + this.canvas.add(fabricObj); | ||
61 | + } else { | ||
62 | + this._addFrame(1); | ||
63 | + isAddMode = true; | ||
52 | if (obj.end()) { | 64 | if (obj.end()) { |
53 | - if (objIdx < objs.length - 1) objIdx++; | 65 | + if (objIdx < objs.length - 1) { |
54 | - else this.canvas.off("after:render", draw); | 66 | + objIdx++; |
67 | + draw(); | ||
55 | } else { | 68 | } else { |
56 | - isAddMode = false; | 69 | + this.canvas.off("after:render", draw); |
70 | + resolve(this._render()); | ||
57 | } | 71 | } |
58 | - this.canvas.add(fabricObj); | ||
59 | } else { | 72 | } else { |
60 | this.canvas.remove( | 73 | this.canvas.remove( |
61 | this.canvas._objects[this.canvas._objects.length - 1] | 74 | this.canvas._objects[this.canvas._objects.length - 1] |
62 | ); | 75 | ); |
63 | - isAddMode = true; | 76 | + } |
64 | } | 77 | } |
65 | }; | 78 | }; |
66 | this.canvas.on("after:render", draw); | 79 | this.canvas.on("after:render", draw); |
67 | draw(); | 80 | draw(); |
81 | + } else { | ||
82 | + reject(new Error("no objects")); | ||
68 | } | 83 | } |
69 | - | 84 | + }); |
70 | - console.log(objs); | ||
71 | } | 85 | } |
72 | } | 86 | } |
73 | 87 | ... | ... |
-
Please register or login to post a comment