Skip to content

Commit 2c4f8f8

Browse files
committed
Show images side by side, or overlaid on top of each other.
1 parent a0b04e9 commit 2c4f8f8

File tree

2 files changed

+120
-40
lines changed

2 files changed

+120
-40
lines changed

tools/compare/compare.js

Lines changed: 76 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,12 @@ const referenceImagesNames = [];
1414

1515
let filterStrings = [];
1616

17-
async function getFile() {
18-
// open file picker
19-
[fileHandle] = await window.showOpenFilePicker();
20-
21-
if (fileHandle.kind === 'file') {
22-
// run file code
23-
} else if (fileHandle.kind === 'directory') {
24-
// run directory code
25-
}
26-
}
17+
let currentIMGElement;
18+
let referenceIMGElement;
2719

28-
const pickerOpts = {
29-
types: [
30-
{
31-
description: 'Images',
32-
accept: {
33-
'image/*': ['.png', '.gif', '.jpeg', '.jpg'],
34-
},
35-
},
36-
],
37-
excludeAcceptAllOption: true,
38-
multiple: false,
39-
};
20+
const SIDE_BY_SIDE = 0;
21+
const OVERLAY = 1;
22+
let viewMode = SIDE_BY_SIDE;
4023

4124
async function openTheFolder() {
4225
// Ask the user to choose a folder.
@@ -70,6 +53,24 @@ function addListeners() {
7053
}
7154
}
7255
});
56+
57+
document.addEventListener('keydown', (e) => {
58+
e = e || window.event;
59+
switch (e.key) {
60+
case 'Enter':
61+
openTheFolder();
62+
break;
63+
case 'ArrowLeft':
64+
case 'ArrowRight':
65+
flipBetweenImages();
66+
break;
67+
case ' ': // SPACE BAR
68+
toggleViewMode();
69+
break;
70+
default:
71+
break;
72+
}
73+
});
7374
}
7475

7576
async function listDirectoryContents(dirHandle) {
@@ -186,10 +187,57 @@ async function showImages(selectedImageFileName) {
186187
}
187188

188189
// Add the two new images.
189-
const imgC = document.createElement('img');
190-
imgC.src = cURL;
191-
imagesContainer.appendChild(imgC);
192-
const imgR = document.createElement('img');
193-
imgR.src = rURL;
194-
imagesContainer.appendChild(imgR);
190+
currentIMGElement = document.createElement('img');
191+
currentIMGElement.id = 'currentImage';
192+
currentIMGElement.src = cURL;
193+
currentIMGElement.style.zIndex = 1;
194+
imagesContainer.appendChild(currentIMGElement);
195+
196+
referenceIMGElement = document.createElement('img');
197+
referenceIMGElement.id = 'referenceImage';
198+
referenceIMGElement.src = rURL;
199+
referenceIMGElement.style.zIndex = -1;
200+
imagesContainer.appendChild(referenceIMGElement);
201+
202+
updateImagesForViewMode();
203+
updateLabelsForViewMode();
204+
}
205+
206+
function flipBetweenImages() {
207+
currentIMGElement.style.zIndex = -1 * currentIMGElement.style.zIndex;
208+
referenceIMGElement.style.zIndex = -1 * referenceIMGElement.style.zIndex;
209+
updateLabelsForViewMode();
210+
}
211+
212+
function toggleViewMode() {
213+
viewMode = 1 - viewMode;
214+
updateImagesForViewMode();
215+
updateLabelsForViewMode();
216+
}
217+
218+
function updateImagesForViewMode() {
219+
if (viewMode === SIDE_BY_SIDE) {
220+
currentIMGElement.style.position = 'static';
221+
referenceIMGElement.style.position = 'static';
222+
} else {
223+
currentIMGElement.style.position = 'absolute';
224+
referenceIMGElement.style.position = 'absolute';
225+
}
226+
}
227+
228+
function updateLabelsForViewMode() {
229+
if (viewMode === SIDE_BY_SIDE) {
230+
document.getElementById('labelCurrent').style.opacity = 1;
231+
document.getElementById('labelReference').style.opacity = 1;
232+
} else {
233+
if (currentIMGElement.style.zIndex > referenceIMGElement.style.zIndex) {
234+
console.log('CURRENT!!!');
235+
document.getElementById('labelCurrent').style.opacity = 1;
236+
document.getElementById('labelReference').style.opacity = 0.4;
237+
} else {
238+
console.log('REFERENCE');
239+
document.getElementById('labelCurrent').style.opacity = 0.4;
240+
document.getElementById('labelReference').style.opacity = 1;
241+
}
242+
}
195243
}

tools/compare/index.html

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
<script src="compare.js"></script>
55
<style>
66
body {
7-
font-family: sans-serif;
8-
font-size: 24px;
9-
margin: 40px;
7+
font-family: system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
8+
'Segoe UI Symbol';
9+
font-size: 20px;
10+
margin: 22px;
1011
color: #111;
1112
background-color: #f3faff;
1213
}
@@ -34,36 +35,64 @@
3435
margin: 0;
3536
width: 45%;
3637
text-indent: 10px;
37-
font-size: 13px;
38+
font-size: 12px;
3839
font-family: ui-monospace, Menlo, Monaco, 'Droid Sans Mono', 'Courier New', monospace;
3940
overflow: auto;
40-
height: 200px;
41+
height: 180px;
4142
}
4243

4344
#filter {
4445
width: 90%;
4546
padding: 12px 20px;
46-
margin: 12px 0;
47+
margin: 0 0 10px 0;
4748
font-size: 16px;
4849
box-sizing: border-box;
4950
}
5051

5152
#images {
5253
margin-top: 20px;
54+
position: relative;
55+
overflow: visible;
56+
}
57+
58+
#images img {
59+
background-color: white;
60+
margin: 4px;
61+
padding: 4px;
62+
border: 1px solid #777;
63+
}
64+
65+
#labelCurrent {
66+
left: 0;
67+
}
68+
69+
#labelReference {
70+
right: 0;
71+
}
72+
73+
.label {
74+
position: fixed;
75+
bottom: 0;
76+
background-color: #444;
77+
padding: 4px 12px;
78+
color: #ddd;
79+
z-index: 10;
5380
}
5481
</style>
5582
<script>
56-
document.addEventListener('DOMContentLoaded', function () {
83+
document.addEventListener('DOMContentLoaded', () => {
5784
addListeners();
5885
});
5986
</script>
6087
</head>
6188
<body>
6289
<p>
63-
Open the <b><code>vexflow/build/images/</code></b> folder, which contains <code>current, diff, reference</code>.
90+
<a href="#" onclick="openTheFolder()"
91+
>Click here to open the <b><code>vexflow/build/images/</code></b> folder</a
92+
>
93+
(the one which contains <code>current/, diff/, reference/</code>).
6494
</p>
65-
<p>When the pop-up appears, click <b>View Files</b>.</p>
66-
<p><button onclick="openTheFolder()">Open Folder</button></p>
95+
<p>If a "Let site view files?" pop-up appears, choose <b>View Files</b>.</p>
6796
<p>
6897
You can also drag and drop the <b><code>vexflow/build/images/</code></b> folder onto this page.
6998
</p>
@@ -80,9 +109,12 @@
80109
<select id="referenceImages" size="5" onchange="if (this.selectedIndex > -1) selectedReferenceImage();"></select>
81110
</div>
82111
<p>
83-
LEFT / RIGHT arrow keys flip between current / reference images.<br />UP / DOWN arrow keys selects the next /
84-
previous image to compare.<br />ESC shows images side by side.
112+
<b>SPACE BAR</b> - Toggle between overlaying images or showing images side by side.<br /><b>UP / DOWN</b> arrow
113+
keys - Select the previous / next image in the list. <b>LEFT / RIGHT</b> arrow keys - Flip between current /
114+
reference images, in overlay mode.
85115
</p>
86116
<div id="images" class="centered"></div>
117+
<div id="labelCurrent" class="label">CURRENT</div>
118+
<div id="labelReference" class="label">REFERENCE</div>
87119
</body>
88120
</html>

0 commit comments

Comments
 (0)