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%; width: 100%;
margin-left: 10px; margin-left: 10px;
} }
.disabled-btn{
opacity : 0.65;
cursor : not-allowed;
}
</style> </style>
<body> <body>
@ -558,7 +562,7 @@
width="300px" height="100px" /> width="300px" height="100px" />
</div> </div>
<div class="imgButton"> <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>
</div> </div>
</td> </td>
@ -569,7 +573,7 @@
width="100px" height="100px" /> width="100px" height="100px" />
</div> </div>
<div class="imgButton"> <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>
</div> </div>
</td> </td>

View File

@ -112,21 +112,8 @@ const eventHandler = async (event, descriptor) => {
require("photoshop").action.addNotificationListener(['set','move'], eventHandler); 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,12 +593,7 @@ for (let rbModeElement of rbModeElements) {
} }
}) })
} }
async function postModeSelection(){ async function createTempInpaintMaskLayer(){
//
try{
if(g_sd_mode === generationMode['Inpaint']){
//check if the we already have created a mask layer
if(!g_b_mask_layer_exist){ if(!g_b_mask_layer_exist){
//make new layer "Mask -- Paint White to Mask -- temporary" //make new layer "Mask -- Paint White to Mask -- temporary"
@ -626,8 +608,8 @@ try{
} }
} }
else{// if we switch from inpaint mode, delete the mask layer async function deleteTempInpaintMaskLayer(){
// 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) 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")) const historyBrushTools = app.activeDocument.historyStates.filter(h => (h.id > g_inpaint_mask_layer_history_id) && (h.name === "Brush Tool"))
console.log(historyBrushTools) console.log(historyBrushTools)
@ -638,6 +620,18 @@ try{
g_b_mask_layer_exist = false 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
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
await deleteTempInpaintMaskLayer()
}
} }
catch(e){ catch(e){
console.warn(e) console.warn(e)

View File

@ -87,11 +87,21 @@ class GenerationSession{
} }
//delete the old selection area
g_selection = {}
this.isFirstGeneration = true // only before the first generation is requested should this be true 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 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){ }catch(e){
console.warn(e) console.warn(e)
} }