This repository has been archived by the owner on Aug 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguicontrols.js
95 lines (90 loc) · 3.74 KB
/
guicontrols.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function posFromCursor(e) {
var hitbox = document.querySelector("#leftwrap").getBoundingClientRect();
var truex = e.clientX - hitbox.x;
var truey = e.clientY - hitbox.y;
var scale = hitbox.width / docWidth;
var pointX = truex / scale;
var pointY = truey / scale;
return [Math.round(pointX), Math.round(pointY)];
}
var centerpoint = document.createElement("div");
centerpoint.className = "controlpoint";
document.querySelector("#leftwrap").appendChild(centerpoint);
centerpoint.style.left = `${100 * parseFloat(document.querySelector("#lightx").value) / docWidth}%`;
centerpoint.style.top = `${100 * parseFloat(document.querySelector("#lighty").value) / docHeight}%`;
var topoint = document.createElement("div");
topoint.className = "controlpoint";
document.querySelector("#leftwrap").appendChild(topoint);
topoint.style.left = `${100 * parseFloat(document.querySelector("#toX").value) / docWidth}%`;
topoint.style.top = `${100 * parseFloat(document.querySelector("#toY").value) / docHeight}%`;
function dragFunc(e, target) {
var pos = posFromCursor(e);
pos[0] = 100 * pos[0] / docWidth;
pos[1] = 100 * pos[1] / docHeight;
target.style.left = `${pos[0]}%`;
target.style.top = `${pos[1]}%`;
}
centerpoint.addEventListener("mousedown", function() {
var listener = function(e) {
dragFunc(e, centerpoint);
var pos = posFromCursor(e);
document.querySelector("#lightx").value = pos[0];
document.querySelector("#lighty").value = pos[1];
drawFromInputs();
e.preventDefault();
};
document.body.addEventListener("mousemove", listener);
this.addEventListener("mouseup", function() {
document.body.removeEventListener("mousemove", listener);
})
});
topoint.addEventListener("mousedown", function() {
var listener = function(e) {
dragFunc(e, topoint);
var pos = posFromCursor(e);
document.querySelector("#toX").value = pos[0];
document.querySelector("#toY").value = pos[1];
drawFromInputs();
e.preventDefault();
};
document.body.addEventListener("mousemove", listener);
this.addEventListener("mouseup", function() {
document.body.removeEventListener("mousemove", listener);
})
});
document.querySelector("#lightx").addEventListener("change", function() {
centerpoint.style.left = `${100 * parseFloat(this.value) / docWidth}%`;
});
document.querySelector("#lighty").addEventListener("change", function() {
centerpoint.style.top = `${100 * parseFloat(this.value) / docHeight}%`;
});
document.querySelector("#toX").addEventListener("change", function() {
topoint.style.left = `${100 * parseFloat(this.value) / docWidth}%`;
});
document.querySelector("#toY").addEventListener("change", function() {
topoint.style.top = `${100 * parseFloat(this.value) / docHeight}%`;
});
fetch("presetlibrary.json").then(x => x.json()).then(function(data) {
console.log(data);
var gallery = document.querySelector("#presetlib");
gallery.style.textAlign = "center";
for (var presetName in data) {
var img = new Image(96, 96);
gallery.appendChild(img);
img.src = "images/previews/" + presetName + ".jpg";
img.style.padding = "5px";
img.style.verticalAlign = "bottom";
img.setAttribute("draggable", "false");
img.style.backgroundColor = "#111111";
img.addEventListener("mouseover", function() {
this.style.backgroundColor = "#333333";
});
img.addEventListener("mouseout", function() {
this.style.backgroundColor = "#111111";
});
img.dataset.corres = JSON.stringify(data[presetName]);
img.addEventListener("click", function() {
loadPreset(this.dataset.corres, true);
});
}
});