kfb-view 2.2.5 → 2.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/workspace.xml +22 -15
- package/lib/kfb-view.js +1 -1
- package/package.json +1 -1
- package/src/tool/Image.js +12 -8
package/package.json
CHANGED
package/src/tool/Image.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import {Brush} from './Brush';
|
|
2
2
|
import {pointsToRegion} from '../util/calculate';
|
|
3
|
+
import {EventEmitter} from '../util/event-emitter';
|
|
4
|
+
|
|
5
|
+
const et = new EventEmitter();
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* 线段类
|
|
@@ -22,18 +25,19 @@ class Image extends Brush {
|
|
|
22
25
|
*/
|
|
23
26
|
draw(points, scale = 1) {
|
|
24
27
|
const region = pointsToRegion(points);
|
|
25
|
-
const ctx = this.canvas.getContext('2d');
|
|
26
|
-
const drawImage = () => {
|
|
27
|
-
ctx.drawImage(this.options.img, region.x, region.y, region.width,
|
|
28
|
-
region.height);
|
|
29
|
-
this.options.img.removeEventListener('load', drawImage);
|
|
30
|
-
};
|
|
31
28
|
if (this.options.imgLoadSuccess) {
|
|
32
|
-
drawImage();
|
|
29
|
+
this.drawImage(this.options.img, region);
|
|
33
30
|
} else if (this.options.img) {
|
|
34
|
-
|
|
31
|
+
et.$once('load', () => {
|
|
32
|
+
this.drawImage(this.options.img, region);
|
|
33
|
+
}, true, this.options.img);
|
|
35
34
|
}
|
|
36
35
|
}
|
|
36
|
+
|
|
37
|
+
drawImage(img, region) {
|
|
38
|
+
const ctx = this.canvas.getContext('2d');
|
|
39
|
+
ctx.drawImage(img, region.x, region.y, region.width, region.height);
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
|
|
39
43
|
export {
|