//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Clear.h" #include "Common.h" #include "Exception.h" #include "FullView.h" #include "MainImage.h" #include "Palette.h" #include "TPUtils.hpp" #include "WorkArea.h" #include "Undo.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_WINDOWIN StringTable[0] #define IDS_WINDOWOUT StringTable[1] //--------------------------------------------------------------------------- TClearForm *ClearForm; //--------------------------------------------------------------------------- __fastcall TClearForm::TClearForm(TComponent* Owner) : TForm(Owner) { hWnd = ((TWinControl *)Owner)->Handle; } //--------------------------------------------------------------------------- void __fastcall TClearForm::FormCreate(TObject *Sender) { //============================================================================== StringTable.Create(DirectoryBin, Language, "Clear"); SetSmallFont(Font); SpeedButtonWhole->Caption = IDS_COMMON_WHOLE; SpeedButtonWindowIn->Caption = IDS_WINDOWIN; SpeedButtonWindowOut->Caption = IDS_WINDOWOUT; //============================================================================== } //--------------------------------------------------------------------------- void __fastcall TClearForm::SpeedButtonWholeClick(TObject *Sender) { TCursor cursor; RECT r; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; r.left = 0; r.top = 0; r.right = MainImageForm->iMainImage->Bitmap->Width; r.bottom = MainImageForm->iMainImage->Bitmap->Height; MainImageForm->UndoSave(UK_ALL, r); PaletteForm->DIB256Palette->ChoiceIndex = 2; PaletteForm->DIB256Palette->UseColor = 2; MainImageForm->iMainImage->Bitmap->FillRect(r, PaletteForm->DIB256Palette->GetBGCOLORREF(MainImageForm->iMainImage->Bitmap->BitsPerPixel)); MainImageForm->WorkAreaReset(true); ::RepaintImage(); Screen->Cursor = cursor; PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TClearForm::SpeedButtonWindowInClick(TObject *Sender) { TCursor cursor; TPoint Size; TTexpiaBitmap *bp; int x, y; Byte *mp, *pp, mm; bool undoSw; COLORREF c; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; if ((undoSw = MainImageForm->UndoSave(UK_ALL, MainImageForm->WorkArea->Range)) == false) goto fail; Size.x = MainImageForm->WorkArea->Range.right-MainImageForm->WorkArea->Range.left; Size.y = MainImageForm->WorkArea->Range.bottom-MainImageForm->WorkArea->Range.top; bp = MainImageForm->iMainImage->Bitmap; if (!bp->StartScanLine()) goto fail; if (!MainImageForm->WorkArea->Mask->StartScanLine()) goto fail; if (MainImageForm->iMainImage->Bitmap->BitsPerPixel==8) { c = PaletteForm->DIB256Palette->GetBGCOLORREF(8); for (y=0; yGetScanLine(MainImageForm->WorkArea->Range.top+y)+MainImageForm->WorkArea->Range.left; mp = (Byte *)MainImageForm->WorkArea->Mask->GetScanLine(y); for (x=0; xPutScanLine(MainImageForm->WorkArea->Range.top+y); } } else { c = PaletteForm->DIB256Palette->GetBGCOLORREF(24); for (y=0; yGetScanLine(MainImageForm->WorkArea->Range.top+y)+3*MainImageForm->WorkArea->Range.left; mp = (Byte *)MainImageForm->WorkArea->Mask->GetScanLine(y); mm = 0x80; for (x=0; x>= 1; } bp->PutScanLine(MainImageForm->WorkArea->Range.top+y); } } MainImageForm->WorkArea->Mask->StopScanLine(); bp->StopScanLine(); ::RepaintImage(); Screen->Cursor = cursor; PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); return; fail: // MainImageForm->WorkArea->Mask->StopScanLine(); bp->StopScanLine(); Screen->Cursor = cursor; if (undoSw) Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TClearForm::SpeedButtonWindowOutClick(TObject *Sender) { TCursor cursor; TPoint Size; RECT r, Dst; int x, y; Byte *mp, *pp, *pBitmap, mm; bool undoSw; TTexpiaBitmap *mbp, *Bitmap; RGBQUAD rgb[256]; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; mbp = MainImageForm->iMainImage->Bitmap; r.left = 0; r.top = 0; r.right = mbp->Width; r.bottom = mbp->Height; if ((undoSw = MainImageForm->UndoSave(UK_ALL, r))== false) goto fail; Size.x = MainImageForm->WorkArea->Range.right-MainImageForm->WorkArea->Range.left; Size.y = MainImageForm->WorkArea->Range.bottom-MainImageForm->WorkArea->Range.top; if (MainImageForm->iMainImage->Bitmap->BitsPerPixel==8) { Bitmap = Undo->Last->Bitmap; Dst = Rect(0, 0, mbp->Width, mbp->Height); mbp->FillRect(Dst, PaletteForm->DIB256Palette->GetBGCOLORREF(8)); if (!mbp->StartScanLine()) goto fail; if (!Bitmap->StartScanLine()) goto fail; if (!MainImageForm->WorkArea->Mask->StartScanLine()) goto fail; for (y=0; yGetScanLine(MainImageForm->WorkArea->Range.top+y)+MainImageForm->WorkArea->Range.left; pBitmap = Bitmap->GetScanLine(MainImageForm->WorkArea->Range.top+y)+MainImageForm->WorkArea->Range.left; mp = (Byte *)MainImageForm->WorkArea->Mask->GetScanLine(y); for (x=0; xPutScanLine(MainImageForm->WorkArea->Range.top+y); } MainImageForm->WorkArea->Mask->StopScanLine(); mbp->StopScanLine(); Bitmap->StopScanLine(); } else { Bitmap = Undo->Last->Bitmap; Dst = Rect(0, 0, mbp->Width, mbp->Height); mbp->FillRect(Dst, PaletteForm->DIB256Palette->GetBGCOLORREF(24)); if (!mbp->StartScanLine()) goto fail; if (!Bitmap->StartScanLine()) goto fail; if (!MainImageForm->WorkArea->Mask->StartScanLine()) goto fail; for (y=0; yGetScanLine(MainImageForm->WorkArea->Range.top+y)+3*MainImageForm->WorkArea->Range.left; pBitmap = Bitmap->GetScanLine(MainImageForm->WorkArea->Range.top+y)+3*MainImageForm->WorkArea->Range.left; mp = (Byte *)MainImageForm->WorkArea->Mask->GetScanLine(y); mm = 0x80; for (x=0; x>= 1; } mbp->PutScanLine(MainImageForm->WorkArea->Range.top+y); } MainImageForm->WorkArea->Mask->StopScanLine(); mbp->StopScanLine(); Bitmap->StopScanLine(); } ::RepaintImage(); Screen->Cursor = cursor; PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); return; fail: // MainImageForm->WorkArea->Mask->StopScanLine(); Bitmap->StopScanLine(); mbp->StopScanLine(); Screen->Cursor = cursor; if (undoSw) Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- // Public Method //--------------------------------------------------------------------------- void __fastcall TClearForm::InitForm() { ParentHeight = Parent->Height+20; ClientHeight = 54; Parent->Height = ParentHeight+ClientHeight; if (MainImageForm->WorkArea->Mask) { SpeedButtonWindowIn->Enabled = true; SpeedButtonWindowOut->Enabled = true; } else { SpeedButtonWindowIn->Enabled = false; SpeedButtonWindowOut->Enabled = false; } } //----------------------------------------------------------------------------