diff --git a/index.html b/index.html index 40f04745..2ff2df0c 100644 --- a/index.html +++ b/index.html @@ -87,7 +87,7 @@ max-height:100%; max-width:100%; } - .viewer-image-button { + .thumbnail-image-button { display: none; /* background-color: #495b79; */ color: white; @@ -102,16 +102,13 @@ max-height:100%; max-width:100%; } - /* .viewer-image-button:hover { - background-color: #333f52; - } */ - .viewer-image-container { + .thumbnail-image-container { position: relative; width: 100px; height: 100px; margin: 0; } - .viewer-image-container:hover .viewer-image-button { + .thumbnail-image-container:hover .thumbnail-image-button { display: flex; } .viewer-container { @@ -536,7 +533,7 @@ -
+
@@ -673,13 +670,13 @@
- - +
diff --git a/index.js b/index.js index ade6d62b..dc8129e0 100644 --- a/index.js +++ b/index.js @@ -2941,17 +2941,9 @@ document.getElementById('btnLoadHistory').addEventListener('click',async functio img.dataset.path =`${output_dir_relative}/${image_path}` img.className = "history-image" img.dataset.metadata_json_string = JSON.stringify(metadata_jsons[i]) - container.appendChild(img) - img.addEventListener('click',async (e)=>{ - const metadata_json = JSON.parse(e.target.dataset.metadata_json_string) - console.log("metadata_json: ",metadata_json) - // document.querySelector('#tiSeed').value = metadata_json.Seed - document.querySelector('#historySeedLabel').textContent = metadata_json.Seed - autoFillInSettings(metadata_json) - let image_path = img.dataset.path - const image_path_escape = image_path.replace(/\o/g,"/o") //escape string "\o" in "\output" - await placeEmbedded(image_path_escape) - }) + img_container = viewer.Thumbnail.wrapImgInContainer(img, "thumbnail-image-container") + viewer.Thumbnail.addSPButtonToContainer(img_container, "svg_sp_btn_datadownload", "Copy Meta Data", loadMetaData, img) + container.appendChild(img_container) i++ } @@ -2961,6 +2953,19 @@ document.getElementById('btnLoadHistory').addEventListener('click',async functio }) +async function loadMetaData(img){ + debugger + const metadata_json = JSON.parse(img.dataset.metadata_json_string) + console.log("metadata_json: ",metadata_json) + // document.querySelector('#tiSeed').value = metadata_json.Seed + document.querySelector('#historySeedLabel').textContent = metadata_json.Seed + autoFillInSettings(metadata_json) + let image_path = img.dataset.path + const image_path_escape = image_path.replace(/\o/g,"/o") //escape string "\o" in "\output" + await placeEmbedded(image_path_escape) +} + + document.getElementById('btnImageSearch').addEventListener('click',async function(){ try{ diff --git a/viewer.js b/viewer.js index c152bdfd..668ac6f8 100644 --- a/viewer.js +++ b/viewer.js @@ -152,51 +152,27 @@ class ViewerImage { } } + AddButtonHtml(){ - addButtonHtml(){ - // Create new container element - const container = document.createElement('div'); - - - container.className = "viewer-image-container"; - - - const elem = document.getElementById('svg_sp_btn'); - - // Create a copy of it - const clone = elem.cloneNode(true); - const button = clone - button.style.display = null - button.setAttribute('title',"use this image to generate more variance like it") - - // Create button element - // const button = document.createElement('sp-button'); - button.className = "viewer-image-button"; - // button.innerHTML = "Button"; - - button.addEventListener('click', async ()=> { - //set init image event listener, use when settion is active - const layer = await app.activeDocument.activeLayers[0] - const image_name = await psapi.setInitImage(layer, random_session_id) - const path = `./server/python_server/init_images/${image_name}` - g_viewer_manager.addInitImageLayers(layer,path,false) - - }) - + const container = Thumbnail.wrapImgInContainer(this.img_html, "thumbnail-image-container") + Thumbnail.addSPButtonToContainer(container, "svg_sp_btn", "use this image to generate more variance like it", addImageToLayer, this) - - // Append elements to container - container.appendChild(this.img_html); - container.appendChild(button); - - - this.img_html = container; } + } +async function addImageToLayer(e){ + //set init image event listener, use when settion is active + const layer = await app.activeDocument.activeLayers[0] + const image_name = await psapi.setInitImage(layer, random_session_id) + const path = `./server/python_server/init_images/${image_name}` + g_viewer_manager.addInitImageLayers(layer,path,false) +} + + class OutputImage extends ViewerImage { constructor (layer, path) { super() @@ -628,10 +604,34 @@ class InitMaskImage extends ViewerImage { } } + class Thumbnail{ + static wrapImgInContainer(img, container_style_class){ + const container = document.createElement('div'); + container.className = container_style_class; + container.appendChild(img); + return container; + } + + static addSPButtonToContainer(container, button_id, title, callbackFunction, param1){ + const elem = document.getElementById(button_id); + const clone = elem.cloneNode(true); + const button = clone + button.style.display = null + button.setAttribute('title',title) + + // Create button element + button.className = "thumbnail-image-button"; + button.addEventListener('click', () => callbackFunction(param1)) + container.appendChild(button) + } + + } + module.exports = { OutputImage, InitImage, InitMaskImage, ViewerObjState, - ViewerManager + ViewerManager, + Thumbnail }