create a temp mask layer when transitioning from inpaint session to another inpaint session

pull/62/head
Abdullah Alfaraj 2023-01-23 04:33:28 +03:00
parent 410ec58a4f
commit e77a2439e3
3 changed files with 45 additions and 37 deletions

View File

@ -319,6 +319,10 @@
width: 100%;
margin-left: 10px;
}
.disabled-btn{
opacity : 0.65;
cursor : not-allowed;
}
</style>
<body>
@ -558,7 +562,7 @@
width="300px" height="100px" />
</div>
<div class="imgButton">
<button class="column-item button-style" id="bSetInitImage">Set Image</button>
<button class="column-item button-style disabled-btn" disabled id="bSetInitImage">Image</button>
</div>
</div>
</td>
@ -569,7 +573,7 @@
width="100px" height="100px" />
</div>
<div class="imgButton">
<button class="column-item button-style" id="bSetInitImageMask">Set Mask</button>
<button class="column-item button-style disabled-btn" disabled id="bSetInitImageMask">Mask</button>
</div>
</div>
</td>

View File

@ -112,21 +112,8 @@ const eventHandler = async (event, descriptor) => {
require("photoshop").action.addNotificationListener(['set','move'], eventHandler);
// require("photoshop").action.addNotificationListener(['historyStateChanged'], eventHandler);
// const onSelect = (event, descriptor) => {
// // console.log(`descriptor._target?.[0]._ref === "layer" : `,descriptor._target?.[0]._ref === "layer" )
// // console.log(`descriptor._target?.[0]._name === "Mask -- Paint White to Mask -- temporary" : `,descriptor._target?.[0]._name === "Mask -- Paint White to Mask -- temporary" )
// console.log(event,descriptor)
// // if(descriptor._target?.[0]._ref === "layer" && descriptor._target?.[0]._name === "Mask -- Paint White to Mask -- temporary") {
// // // -> The layer with name "Test Layer 1" was selected
// // console.log(" onSelect event got triggered!")
// // console.log("descriptor: ",descriptor)
// // // console.log()
// // }
// }
// require("photoshop").action.addNotificationListener(['all'], onSelect);
@ -606,37 +593,44 @@ for (let rbModeElement of rbModeElements) {
}
})
}
async function createTempInpaintMaskLayer(){
if(!g_b_mask_layer_exist){
//make new layer "Mask -- Paint White to Mask -- temporary"
const name = "Mask -- Paint White to Mask -- temporary"
g_inpaint_mask_layer = await util_layer.createNewLayerExe(name)
g_b_mask_layer_exist = true
const index = app.activeDocument.historyStates.length -1
g_inpaint_mask_layer_history_id = app.activeDocument.historyStates[index].id
console.log("g_inpaint_mask_layer_history_id: ",g_inpaint_mask_layer_history_id)
}
}
async function deleteTempInpaintMaskLayer(){
console.log("g_inpaint_mask_layer_history_id: ",g_inpaint_mask_layer_history_id)
const historyBrushTools = app.activeDocument.historyStates.filter(h => (h.id > g_inpaint_mask_layer_history_id) && (h.name === "Brush Tool"))
console.log(historyBrushTools)
if(historyBrushTools.length === 0 && g_b_mask_layer_exist){
await util_layer.deleteLayers([g_inpaint_mask_layer])
g_b_mask_layer_exist = false
}
}
async function postModeSelection(){
//
try{
if(g_sd_mode === generationMode['Inpaint']){
//check if the we already have created a mask layer
if(!g_b_mask_layer_exist){
//make new layer "Mask -- Paint White to Mask -- temporary"
const name = "Mask -- Paint White to Mask -- temporary"
g_inpaint_mask_layer = await util_layer.createNewLayerExe(name)
g_b_mask_layer_exist = true
const index = app.activeDocument.historyStates.length -1
g_inpaint_mask_layer_history_id = app.activeDocument.historyStates[index].id
console.log("g_inpaint_mask_layer_history_id: ",g_inpaint_mask_layer_history_id)
}
await createTempInpaintMaskLayer()
}
else{// if we switch from inpaint mode, delete the mask layer
// Find all history states after the creation of the inpaint mask and their name brush tool
console.log("g_inpaint_mask_layer_history_id: ",g_inpaint_mask_layer_history_id)
const historyBrushTools = app.activeDocument.historyStates.filter(h => (h.id > g_inpaint_mask_layer_history_id) && (h.name === "Brush Tool"))
console.log(historyBrushTools)
if(historyBrushTools.length === 0 && g_b_mask_layer_exist){
await util_layer.deleteLayers([g_inpaint_mask_layer])
g_b_mask_layer_exist = false
}
await deleteTempInpaintMaskLayer()
}
}
catch(e){

View File

@ -87,10 +87,20 @@ class GenerationSession{
}
//delete the old selection area
g_selection = {}
this.isFirstGeneration = true // only before the first generation is requested should this be true
await util_layer.collapseFolderExe([this.outputGroup],false)// close the folder group
if(this.mode === generationMode['Inpaint'] && g_sd_mode === generationMode['Inpaint']){
//create "Mask -- Paint White to Mask -- temporary" layer if current session was inpiant and the selected session is inpaint
// the current inpaint session ended on inpaint
g_b_mask_layer_exist = false
await util_layer.deleteLayers([g_inpaint_mask_layer])
await createTempInpaintMaskLayer()
}
}catch(e){
console.warn(e)