1
0
Fork 0

Add tag for clocks that use clockbg, and allow custom image upload for clockbg

master
Gordon Williams 2024-05-21 09:32:39 +01:00
parent 1869baeaae
commit 662cb75dfa
4 changed files with 25 additions and 11 deletions

View File

@ -6,7 +6,7 @@
"icon": "icon.png",
"screenshots" : [ { "url":"screenshot.png" }, { "url":"screenshot2.png" } ],
"type": "clock",
"tags": "clock,clkinfo,analog",
"tags": "clock,clkinfo,analog,clockbg",
"supports" : ["BANGLEJS2"],
"dependencies" : { "clock_info":"module", "clockbg":"module" },
"storage": [

View File

@ -2,7 +2,7 @@
<head>
<link rel="stylesheet" href="../../css/spectre.min.css">
<style>
.flag {
.thumbnail {
width : 100px;
cursor: pointer;
}
@ -14,8 +14,8 @@
</style>
</head>
<body>
<p>Upload an image:</p>
<div id="flaglist"></div>
<p>Upload an image: <input class="form-input" id="customfile" type="file"></p>
<div id="thumbnaillist"></div>
<p>If you'd like to contribute images you can <a href="https://github.com/espruino/BangleApps/tree/master/apps/patriotclk/img" target="_blank">add them on GitHub</a>!</p>
<div style="float:right">Preview:<br/><canvas width="176" height="176" id="preview"></canvas></div>
<div class="form-group">
@ -89,21 +89,20 @@
var selectedImage;
var bgImageData;
document.getElementById("flaglist").innerHTML =
IMAGES.map(f => `<img class="flag" src="${f.path}" data-file="${f.path}"/>`).join("\n");
var elements = document.querySelectorAll(".flag");
document.getElementById("thumbnaillist").innerHTML = `<img class="thumbnail" id="customimage" src="" face="custom" style="display:none"/>\n`+
IMAGES.map(f => `<img class="thumbnail" src="${f.path}" data-file="${f.path}"/>`).join("\n");
var elements = document.querySelectorAll(".thumbnail");
for (var i=0;i<elements.length;i++)
elements[i].addEventListener("click", function(e) {
selectedImage = e.target;
drawPreview();
document.getElementById("upload").classList.remove("disabled")
});
function drawPreview() {
if (!selectedImage) return;
var imgPath = selectedImage.getAttribute("data-file");
var img = IMAGES.find(img => img.path == imgPath);
var img = IMAGES.find(img => img.path == imgPath) || {"dither":true}; // No IMAGES entry for custom images
var zoom = document.getElementById("box_zoom").value;
var dither = document.getElementById("box_dither").value;
if (dither=="" && img.dither) dither="bayer2";
@ -144,6 +143,7 @@
brightness:64*brightness
};
bgImageData = imageconverter.canvastoString(canvas, options);
document.getElementById("upload").classList.remove("disabled")
}
// If options changed
@ -172,6 +172,20 @@
});
});
});
// Custom image upload
document.getElementById('customfile').onchange = function (evt) {
var tgt = evt.target || window.event.srcElement, files = tgt.files;
if (FileReader && files && files.length) {
var fr = new FileReader();
fr.onload = function () {
document.getElementById("customimage").src = fr.result;
document.getElementById("customimage").style.display = "inline-block";
selectedImage = document.getElementById("customimage");
drawPreview();
}
fr.readAsDataURL(files[0]);
}
}
function onInit() {
Util.readStorageJSON("clockbg.json", function(data) {

View File

@ -7,7 +7,7 @@
"icon": "app.png",
"screenshots": [{"url":"screenshot.png"}],
"type": "clock",
"tags": "clock,clkinfo",
"tags": "clock,clkinfo,clockbg",
"supports": ["BANGLEJS2"],
"dependencies" : { "clock_info":"module", "clockbg":"module" },
"storage": [

View File

@ -5,7 +5,7 @@
"description": "A clock with the time split over two lines, with custom backgrounds and two ClockInfos",
"icon": "icon.png",
"type": "clock",
"tags": "clock,clkinfo",
"tags": "clock,clkinfo,clockbg",
"supports" : ["BANGLEJS2"],
"dependencies" : { "clock_info":"module", "clockbg":"module" },
"screenshots": [{"url":"screenshot.png"}],