// Gets the current mask if any. // If no mask exists then create one using fOn and fNoUndo. // bCreated is TRUE if a new mask was created. LPMASK CImage::GetMaskEx(BOOL fOn, BOOL fNoUndo, LPINT bCreated, LPRECT lpUpdateRect) { LPMASK lpMask; LPFRAME lpFrame; FRMTYPEINFO TypeInfo; FRMDATATYPE FrameType = FDT_GRAYSCALE; AstralSetRectEmpty(lpUpdateRect); if (lpMask = GetMask()) { if (bCreated) *bCreated = FALSE; return(lpMask); } lpFrame = GetBaseEditFrame(); FrameGetTypeInfo(lpFrame, &TypeInfo); if (TypeInfo.DataType == FDT_LINEART && Mask.OneBitMask) FrameType = FDT_LINEART; if (!(lpMask = MaskCreate(NULL, FrameXSize(lpFrame), FrameYSize(lpFrame), fOn, fNoUndo, FrameType))) { Message( IDS_EMEMALLOC ); return(NULL); } // sync up the resolution of the image data and the mask // don't ever rely on the mask's resolution being correct // cause other size can change the image data resolution // without changing the mask's resolution. Also, there are // other places the mask gets created without syncing up // the resolution. I am doing it here so we can begin // to track it correctly (Ted) FrameSetResolution(AlphaGetEditFrame(lpMask), FrameResolution(lpFrame)); if (bCreated) *bCreated = TRUE; if (!Control.UseMaskAndObjects) GetObjectMarqueeRect(this, lpUpdateRect); SetMask(lpMask); return(lpMask); }
void CImage::EditUndo( BOOL fEditUndo, BOOL fMaskUndo, LPUPDATE_TYPE lpUpdateType, LPRECT lpUpdateRect) { RECT rUndo, rUndoMask, rTemp; LPOBJECT lpBase, lpObject, lpNext; BOOL fNewSize, fSetupMiniViews, fRemoveMarquee, fUndoDelete, fColorMapChanged; BOOL fUndoAlpha, fUndoData; int nDeleted; LPMASK lpMask; EDIT_TARGET Target; AstralSetRectEmpty(lpUpdateRect); // Initialize things for updating the display fNewSize = fSetupMiniViews = fUndoDelete = fColorMapChanged = NO; AstralSetRectEmpty(&rUndo); AstralSetRectEmpty(&rUndoMask); // loop through objects doing undo lpBase = GetBase(); lpObject = NULL; // get the target of the last edit Target = EditTarget; while (lpObject = GetNextObject(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) continue; // do no undo processing for a deleted object // { // if (Control.UndoObjects && !IsSelectedObject(lpBase)) // continue; // } else // if target is not the entire image and we are in undo // object mode and the object is not selected then // skip this object if (Target != ET_ALLOBJECTS && Control.UndoObjects && !IsSelectedObject(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 = GetNextObject(lpNext, YES, NO, YES)) { if (lpNext->fUndoDeleted) ++nDeleted; else if (lpNext->fDeleted && lpNext->fSelected) { fRemoveMarquee = YES; break; } } if (GetSelObject(NULL) == lpBase && !fRemoveMarquee) { if (CountObjects() - nDeleted <= 1) fRemoveMarquee = YES; } if (fRemoveMarquee) { GetObjectMarqueeRect(this, &rTemp); AstralUnionRect(lpUpdateRect, lpUpdateRect, &rTemp); } } } 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 (GetMask()) { GetMaskMarqueeRect(this, &rTemp); AstralUnionRect(lpUpdateRect, lpUpdateRect, &rTemp); if (GetMaskUpdateRect(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) { GetObjectMarqueeRect(this, &rTemp); AstralUnionRect(lpUpdateRect, lpUpdateRect, &rTemp); } } } } // Actually do the undo ObjEditUndo(lpObject, fUndoData, fUndoAlpha); // do a postprocess for undoing the mask if ((lpMask = GetMask()) && (((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 (GetMaskUpdateRect(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 = GetNextObject(lpNext, YES, NO, YES)) { if (lpNext->fDeleted || lpNext->fUndoDeleted) AstralUnionRect(&rUndo, &rUndo, &lpNext->rObject); } fSetupMiniViews = YES; } if (lpObject->DataUndoType & UT_COLORMAP) fColorMapChanged = 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); } } if( lpObject->DataUndoType & UT_OBJECTRECT ) { AstralUnionRect( &rUndo, &rUndo, &lpObject->rObject ); AstralUnionRect( &rUndo, &rUndo, &lpObject->rUndoObject ); } } } } // now redisplay whatever changes are necessary for the undo if (fColorMapChanged) { ImgColorMapChanged(this); *lpUpdateType |= UT_DATATYPE; } if (fNewSize) { *lpUpdateType |= UT_DATATYPE; 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) *lpUpdateType |= UT_SIZE; else { int dx, dy; GetInfo(&dx, &dy, NULL, NULL); SetRect(lpUpdateRect, 0, 0, dx-1, dy-1); } } else { if (!AstralIsRectEmpty(lpUpdateRect)) *lpUpdateType |= UT_ACTIVEAREA; if (rUndoMask.right >= rUndoMask.left) { *lpUpdateType |= UT_ACTIVEAREA; AstralUnionRect(lpUpdateRect, lpUpdateRect, &rUndoMask); } if (rUndo.right >= rUndo.left) { *lpUpdateType |= UT_AREA; AstralUnionRect(lpUpdateRect, lpUpdateRect, &rUndo); } } }
BOOL CImage::CombineObjects(BOOL fNoUndo, BOOL fCreateMask, BOOL fForceIt, ITEMID idDirty, LPRECT lpUpdateRect) { LPOBJECT lpBase, lpObject; int iWidth, iHeight, depth, y, iImageWidth, iImageHeight; LPTR lpDataBuf, lpMaskPtr; RECT rFloaters, rMask, rTemp; BOOL fNewMask; LPMASK lpMask; UNDO_TYPE UndoType; AstralSetRectEmpty(lpUpdateRect); // get rectangle for all floating objects if (!GetFloatingObjectsRect(&rFloaters)) return(FALSE); // Get base object lpBase = GetBase(); // get pixmap information PixmapGetInfo(&lpBase->Pixmap, PMT_EDIT, &iImageWidth, &iImageHeight, &depth, NULL); BoundRect(&rFloaters, 0, 0, iImageWidth-1, iImageHeight-1); iWidth = RectWidth(&rFloaters); iHeight = RectHeight(&rFloaters); // allocate buffer for alpha channel combining if (!(lpDataBuf = Alloc((long)iWidth*depth))) { Message(IDS_EMEMALLOC); return(FALSE); } lpMask = NULL; if (fCreateMask) { lpMask = GetMaskEx(OFF, Control.NoUndo, &fNewMask, &rTemp); AstralUnionRect(lpUpdateRect, lpUpdateRect, &rTemp); } // do it to it ProgressBegin(lpMask != NULL ? 2 : 1, idDirty-IDS_UNDOFIRST+IDS_PROGFIRST); if (!fNoUndo) { UndoType = UT_DATA|UT_DELETEOBJECTS; if (lpMask) { if (fNewMask) UndoType |= UT_CREATEMASK; else UndoType |= UT_ALPHA; } if (!ImgEditInit(this, ET_OBJECT, UndoType, lpBase)) { if (!fForceIt) { ProgressEnd(); FreeUp(lpDataBuf); return(FALSE); } } } // do it to it ProgressBegin(1, 0); for (y = rFloaters.top; y <= rFloaters.bottom; ++y) { AstralClockCursor(y-rFloaters.top, iHeight, NO); ImgGetLine(this, NULL, rFloaters.left, y, iWidth, lpDataBuf); PixmapWrite(&lpBase->Pixmap, PMT_EDIT, rFloaters.left, y, iWidth, lpDataBuf, iWidth); } ProgressEnd(); if (lpMask && (lpObject = GetNextObject(lpBase, YES, NO))) { ProgressBegin(1, 0); for (y = rFloaters.top; y <= rFloaters.bottom; ++y) { AstralClockCursor(y-rFloaters.top, iHeight, NO); lpMaskPtr = PixmapPtr(&lpMask->Pixmap, PMT_EDIT, rFloaters.left, y, YES); if (!lpMaskPtr) continue; ImgMaskLoad(this, lpObject, NULL, rFloaters.left, y, iWidth, lpDataBuf, NO, CR_OR, 0, 0); CombineData(lpDataBuf, lpMaskPtr, iWidth, NO, CR_OR); } MaskRectUpdate(lpMask, &rMask); ProgressEnd(); } FreeUp(lpDataBuf); GetObjectMarqueeRect(this, &rTemp); AstralUnionRect(lpUpdateRect, lpUpdateRect, &rTemp); lpObject = lpBase; while (lpObject = GetNextObject(lpObject, YES, NO)) { // always let undo stuff initialize this // lpObject->fUndoDeleted = NO; lpObject->fDeleted = YES; } //DeleteObjects((LPOBJECT)lpBase->lpNext, NO); if (!fNoUndo) ImgEditedObject(this, lpBase, idDirty, &rFloaters); else fChanged = YES; //if ( Tool.hRibbon ) // SendMessage( Tool.hRibbon, WM_CONTROLENABLE, 0, 0L ); ProgressEnd(); //SetupMiniViews(NULL, NO); return(TRUE); }