void ImgEditMaskUndo( LPIMAGE lpImage ) /***********************************************************************/ { LPOBJECT lpBase; LPMASK lpMask; RECT rUndo; lpBase = ImgGetBase(lpImage); if (!lpBase->AlphaDirty) return; if (lpBase->fBothDirty) return; AstralSetRectEmpty(&rUndo); if (ImgGetMask(lpImage) && lpBase->AlphaUndoType & (UT_CREATEMASK|UT_DELETEMASK) ) { RemoveMaskMarquee(lpImage); ImgGetMaskUpdateRect(lpImage, YES, NO, &rUndo); } ObjEditUndo(lpImage, lpBase, NO, YES); if (lpMask = ImgGetMask(lpImage)) { if (lpBase->AlphaUndoType & (UT_CREATEMASK|UT_DELETEMASK) ) { RemoveMaskMarquee(lpImage); ImgGetMaskUpdateRect(lpImage, YES, NO, &rUndo); } else rUndo = lpMask->Pixmap.UndoRect; } if (rUndo.right >= rUndo.left) { OffsetRect(&rUndo, lpBase->rObject.left, lpBase->rObject.top); File2DispRect(&rUndo, &rUndo); AstralToWindowsRect(&rUndo); InvalidateRect(lpImage->hWnd, NULL, NO); } }
BOOL CChromaMask::JoinChromaMask(LPIMAGE lpImage, LPRECT lpUpdateRect) { LPOBJECT lpBase; LPMASK lpMask; RECT rDummy; RECT rMask; BOOL fNewMask = NO; BOOL fCreateMask = NO; UNDO_TYPE Type; AstralSetRectEmpty(lpUpdateRect); if (ImgGetMask(lpImage)) Type = UT_ALPHA; else { fNewMask = TRUE; Type = UT_CREATEMASK; } // get mask, create one if one does not exist lpMask = ImgGetMaskEx(lpImage, iMode==SHAPE_SUBTRACT ? OFF : ON, Control.NoUndo, &fNewMask, lpUpdateRect); if (!lpMask) return(FALSE); // if not new mask and we are allowed to create undo, initialize undo lpBase = ImgGetBase(lpImage); if (!ImgEditInit(lpImage, ET_OBJECT,Type, lpBase)) return(FALSE); EnableMarqueeEx( lpImage, NO ); // add Chroma to mask MaskAddChroma(lpImage, lpMask, &rMask, !fNewMask); AstralUnionRect(lpUpdateRect, lpUpdateRect, &rMask); // if using undo, indicate in-place editing has occurred ImgEditedObject(lpImage, lpBase, IDS_CHROMA_APPLY, fNewMask ? NULL : &rMask); // after subtractive masks we dont know area if (iMode!=SHAPE_ADD) MaskRectUpdate(lpMask, &rDummy); // get area that needs to be redisplayed, may be larger // than rUpdate because of slime if (ImgGetMaskUpdateRect(lpImage, fNewMask, NO, &rMask)) AstralUnionRect(lpUpdateRect, lpUpdateRect, &rMask); EnableMarqueeEx(lpImage, YES); return(TRUE); }
void ImgEditUndo( LPIMAGE lpImage, BOOL fEditUndo, BOOL fMaskUndo ) /***********************************************************************/ { RECT rUndo, rUndoMask, rTemp; LPOBJECT lpBase, lpObject, lpNext; BOOL fNewSize, fSetupMiniViews, fRemoveMarquee, fUndoDelete; BOOL fUndoAlpha, fUndoData; int nDeleted; LPMASK lpMask; if (!lpImage) return; // Initialize things for updating the display fNewSize = fSetupMiniViews = fUndoDelete = NO; AstralSetRectEmpty(&rUndo); AstralSetRectEmpty(&rUndoMask); // loop through objects doing undo lpBase = ImgGetBase(lpImage); lpObject = NULL; while (lpObject = ImgGetNextObjectEx(lpImage, lpObject, NO, NO, fEditUndo)) { // See if this is an object we are undoing if (fEditUndo) { // check for special undo processing of a deleted object if (lpObject->fDeleted) { if (Control.UndoObjects && !ImgIsSelectedObject(lpImage, lpBase)) continue; } else if (Control.UndoObjects && !ImgIsSelectedObject(lpImage, lpObject)) continue; } // Only handle mask undo for the base object if (fMaskUndo) { if (lpObject != lpBase || lpObject->fBothDirty || !lpObject->AlphaDirty) continue; } fUndoData = fUndoAlpha = NO; // Do preprocess for doing a data undo if (fEditUndo) { if (lpObject->DataDirty) fUndoData = YES; // See if we need to undo the alpha for this object if ((lpObject != lpBase) && lpObject->lpAlpha && lpObject->AlphaDirty) fUndoAlpha = YES; if (!fUndoData && !fUndoAlpha) continue; // check to see and undoing/redoing deleted objects will change // the select state, if so undraw the object marquee if (lpObject == lpBase && lpObject->DataUndoType & UT_DELETEOBJECTS) { fUndoDelete = YES; fRemoveMarquee = NO; nDeleted = 0; lpNext = lpObject; while (lpNext = ImgGetNextObjectEx(lpImage, lpNext, YES, NO, YES)) { if (lpNext->fUndoDeleted) ++nDeleted; else if (lpNext->fDeleted && lpNext->fSelected) { fRemoveMarquee = YES; break; } } if (ImgGetSelObject(lpImage, NULL) == lpBase && !fRemoveMarquee) { if (ImgCountObjects(lpImage) - nDeleted <= 1) fRemoveMarquee = YES; } if (fRemoveMarquee) RemoveObjectMarqueeEx(lpImage, NO); } } else // fMaskUndo if (!lpObject->AlphaDirty) continue; else fUndoAlpha = YES; // do a preprocess for undoing the mask caused either by // a mask undo or by an edit function that also edits the mask if (((lpObject == lpBase) && fEditUndo && lpObject->fBothDirty) || fMaskUndo) { if ( lpObject->AlphaUndoType & (UT_CREATEMASK|UT_DELETEMASK) ) { // if the undo is going to delete the mask, // we need to undraw the mask if (ImgGetMask(lpImage)) { RemoveMaskMarquee(lpImage); if (ImgGetMaskUpdateRect(lpImage, YES, NO, &rTemp)) AstralUnionRect(&rUndoMask, &rUndoMask, &rTemp); } // if the undo is going to create the mask, // we need to undraw the object marquees if // not in mask and object marquee mode else { if (!Control.UseMaskAndObjects) RemoveObjectMarqueeEx(lpImage, NO); } } } // Actually do the undo ObjEditUndo(lpImage, lpObject, fUndoData, fUndoAlpha); // do a postprocess for undoing the mask if ((lpMask = ImgGetMask(lpImage)) && (((lpObject == lpBase) && fEditUndo && lpObject->fBothDirty) || fMaskUndo)) { // if the undo is going to add the mask, we need to redraw the mask if (lpObject->AlphaUndoType & (UT_CREATEMASK|UT_DELETEMASK) ) { if (ImgGetMaskUpdateRect(lpImage, YES, NO, &rTemp)) AstralUnionRect(&rUndoMask, &rUndoMask, &rTemp); } else // just redraw the undo area for the mask AstralUnionRect(&rUndoMask, &rUndoMask, &lpMask->Pixmap.UndoRect); } // Setup rectangle for undoing deletion of objects // Handled specially so that moved objects will still undo // and redo properly if (fEditUndo) { if (lpObject == lpBase && lpObject->DataUndoType & UT_DELETEOBJECTS) { lpNext = lpObject; while (lpNext = ImgGetNextObjectEx(lpImage, lpNext, YES, NO, YES)) { if (lpNext->fDeleted || lpNext->fUndoDeleted) AstralUnionRect(&rUndo, &rUndo, &lpNext->rObject); } fSetupMiniViews = YES; } if (lpObject->Pixmap.fNewFrame) { /* if new frame, cause window to be redisplayed */ if (lpObject == lpBase) fNewSize = YES; else { if (!fNewSize) { AstralUnionRect(&rUndo, &rUndo, &lpObject->rObject); AstralUnionRect(&rUndo, &rUndo, &lpObject->rUndoObject); } } } else { AstralSetRectEmpty(&rTemp); if (fUndoData) AstralUnionRect(&rTemp, &rTemp, &lpObject->Pixmap.UndoRect); if (fUndoAlpha) AstralUnionRect(&rTemp, &rTemp, &lpObject->lpAlpha->Pixmap.UndoRect); if (rTemp.right >= rTemp.left) { if (!fNewSize) { OffsetRect(&rTemp, lpObject->rObject.left, lpObject->rObject.top); AstralUnionRect(&rUndo, &rUndo, &rTemp); } } } } } // now redisplay whatever changes are necessary for the undo if (fNewSize) { SetupImagePalette(lpImage, NO, YES); if (lpBase->Pixmap.UndoFrame) { if ((FrameXSize(lpBase->Pixmap.UndoFrame) == FrameXSize(lpBase->Pixmap.EditFrame)) && (FrameYSize(lpBase->Pixmap.UndoFrame) == FrameYSize(lpBase->Pixmap.EditFrame))) fNewSize = NO; } if (fNewSize) UpdateImageSize(); else UpdateImageEx(lpImage, NULL, YES, YES, YES); if ( Tool.hRibbon ) SendMessage( Tool.hRibbon, WM_CONTROLENABLE, 0, 0L ); } else { if (rUndoMask.right >= rUndoMask.left) { File2DispRect(&rUndoMask, &rUndoMask); AstralToWindowsRect(&rUndoMask); InvalidateRect(lpImage->hWnd, NULL, NO); } if (rUndo.right >= rUndo.left) AnimateUndo( &rUndo ); } if (fUndoDelete) if ( Tool.hRibbon ) SendMessage( Tool.hRibbon, WM_CONTROLENABLE, 0, 0L ); if (fSetupMiniViews) SetupMiniViews(NULL, NO); }