-
Notifications
You must be signed in to change notification settings - Fork 0
/
stampTool.js
62 lines (57 loc) · 1.41 KB
/
stampTool.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class StampTool {
constructor() {
this.icon = "assets/stamp.jpg";
this.name = "stamp";
this.description = "Stamp Tool allow you to select an image, resize and paste on the canvas. Click on the canvas to use it"
let img;
let input;
let slider;
//handle File picked
const handleFile = (file) => {
if (file.type === "image") {
createImg(file.data, "", "", (image) => {
img = image
if (!slider) {
slider = createSlider(
5,
img.size().width*1.5,
img.size().width / 2,
5
);
slider.parent(Gopt);
img.hide();
}
else {
img.hide();
}
});
} else {
img = null;
}
};
this.populateOptions = () => {
input = createFileInput(handleFile);
input.parent(Gopt);
};
this.draw = () => {
if (img) {
cursor("grab");
}
};
this.mousePressed = () => {
if (img) {
if (mouseX > 0 && mouseX < width && mouseY > 5 && mouseY < height) {
let size = slider.value();
let x = mouseX + size / 2;
let y = mouseY + size / 2;
if (img) {
image(img, mouseX, mouseY, size);
}
}
}
else {
input.elt.click() //automatically trigger image selection
}
};
}
}