//--------------------------------------------------------------------------- #include #pragma hdrstop #include "MarkClear.h" #include "FullView.h" #include "MainImage.h" #include "Palette.h" #include "Undo.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_WINDOWIN StringTable[0] #define IDS_WINDOWOUT StringTable[1] #define IDS_BOTH StringTable[2] #define IDS_YARN StringTable[3] #define IDS_MARK StringTable[4] //--------------------------------------------------------------------------- TMClearForm *MClearForm; //--------------------------------------------------------------------------- __fastcall TMClearForm::TMClearForm(TComponent* Owner) : TForm(Owner) { hWnd = ((TWinControl *)Owner)->Handle; //============================================================================== StringTable.Create(DirectoryItem, Language, "MarkClear"); SetSmallFont(Font); sbWhole->Caption = IDS_COMMON_WHOLE; sbWinIn->Caption = IDS_WINDOWIN; sbWinOut->Caption = IDS_WINDOWOUT; sbBoth->Caption = IDS_BOTH; sbYarn->Caption = IDS_YARN; sbMark->Caption = IDS_MARK; //============================================================================== } //--------------------------------------------------------------------------- void __fastcall TMClearForm::FormCreate(TObject *Sender) { // } //--------------------------------------------------------------------------- // Public Method //--------------------------------------------------------------------------- void __fastcall TMClearForm::InitForm() { ParentHeight = Parent->Height+20; ClientHeight = 83; Parent->Height = ParentHeight+ClientHeight; Yarn = false; Mark = false; Both = false; width = MainImageForm->iMainImage->Bitmap->Width; height = MainImageForm->iMainImage->Bitmap->Height; r = Rect(0, 0, width, height); rect = MainImageForm->WorkArea->Range; if (MainImageForm->WorkArea->Mask) { sbWinIn->Enabled = true; sbWinOut->Enabled = true; size = Point(rect.right - rect.left, rect.bottom - rect.top); } else { sbWinIn->Enabled = false; sbWinOut->Enabled = false; } } //---------------------------------------------------------------------------- void __fastcall TMClearForm::WholeYarnClear() { TCursor cursor; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; PaletteForm->DIB256Palette->ChoiceIndex = 2; PaletteForm->DIB256Palette->UseColor = 2; MainImageForm->iMainImage->ArrayBitmap[0].FillRect(r, PaletteForm->DIB256Palette->GetBGCOLORREF(8)); ::RepaintImage(); Screen->Cursor = cursor; PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TMClearForm::WinInYarnClear() { TCursor cursor; COLORREF c; Byte *mp, *pp; int i, j; TTexpiaBitmap *bmp; bmp = &MainImageForm->iMainImage->ArrayBitmap[0]; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; c = PaletteForm->DIB256Palette->GetBGCOLORREF(8); if (!bmp->StartScanLine()) goto fail; if (!MainImageForm->WorkArea->Mask->StartScanLine()) goto fail; for (i = 0;i < size.y; i++) { pp = bmp->GetScanLine(rect.top+i)+rect.left; mp = (Byte *)MainImageForm->WorkArea->Mask->GetScanLine(i); for (j = 0;j < size.x; j++, pp++, mp++) { if (*mp) *pp = c; } bmp->PutScanLine(rect.top+i); } MainImageForm->WorkArea->Mask->StopScanLine(); bmp->StopScanLine(); ::RepaintImage(); Screen->Cursor = cursor; PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); return; fail: bmp->StopScanLine(); Screen->Cursor = cursor; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMClearForm::WinOutYarnClear() { TCursor cursor; int x, y; Byte *IP, *IP1, *mp; TTexpiaBitmap *Bitmap, *bmp; bmp = &MainImageForm->iMainImage->ArrayBitmap[0]; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; Bitmap = Undo->Last->Bitmap; bmp->FillRect(r, PaletteForm->DIB256Palette->GetBGCOLORREF(8)); if (!bmp->StartScanLine()) goto fail; if (!Bitmap->StartScanLine()) goto fail; if (!MainImageForm->WorkArea->Mask->StartScanLine()) goto fail; for (y=0; yGetScanLine(rect.top+y) + rect.left; IP1 = Bitmap->GetScanLine(rect.top+y) + rect.left; mp = MainImageForm->WorkArea->Mask->GetScanLine(y); for (x=0; xPutScanLine(rect.top+y); } MainImageForm->WorkArea->Mask->StopScanLine(); Bitmap->StopScanLine(); bmp->StopScanLine(); ::RepaintImage(); Screen->Cursor = cursor; PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); return; fail: Bitmap->StopScanLine(); bmp->StopScanLine(); Screen->Cursor = cursor; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMClearForm::WholeMarkClear() { TCursor cursor; TTexpiaBitmap *bmp; bmp = &MainImageForm->iMainImage->ArrayBitmap[1]; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; bmp->FillRect(r, 0); MainImageForm->iMainImage->SetMark(); ::RepaintImage(); Screen->Cursor = cursor; PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TMClearForm::WinInMarkClear() { TCursor cursor; int i, j, k, w; Byte *IP, *IP1; TTexpiaBitmap *bmp; bmp = &MainImageForm->iMainImage->ArrayBitmap[1]; /* cursor = Screen->Cursor; Screen->Cursor = crHourGlass; size.y = rect.bottom - rect.top; if (!bmp->StartScanLine()) goto fail; for (i = 0;i < size.y; i++) { IP = bmp->GetScanLine(rect.top + i) + rect.left; if ((*IP & 0x3F) > 1) { if (*IP & 0x80) { w = MainImageForm->Arrange->Dmark.sp[*IP & 0x3F]->wale; for (j = 0; j < w; j++) { IP1 = (IP - 1) - j; if ((*IP1 & 0x3F)>1 && (*IP1 & 0x80) == 0) { for (k = 0; k < w; k++, IP1++) { *IP1 = 0; } bmp->PutScanLine(rect.top + i); break; } } } } IP = bmp->GetScanLine(rect.top + i) + rect.right + 1; if ((*IP & 0x3F) > 1) { if (*IP & 0x80) { w = MainImageForm->Arrange->Dmark.sp[*IP & 0x3F]->wale; for (j = 0; j < w; j++) { IP1 = IP - j; if ((*IP1 & 0x3F)>1 && (*IP1 & 0x80) == 0) { for (k = 0; k < w; k++, IP1++) { *IP1 = 0; } bmp->PutScanLine(rect.top + i); break; } } } } } bmp->StopScanLine(); */ RECT rc = rect; MainImageForm->check(rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, &rc); bmp->FillRect(rect, 0); MainImageForm->iMainImage->SetMark(rc); ::RepaintImage(); Screen->Cursor = cursor; PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); return; fail : bmp->StopScanLine(); Screen->Cursor = cursor; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMClearForm::WinOutMarkClear() { TCursor cursor; int sizeY, j, k, i; Byte *IP, *IP1; TTexpiaBitmap *Bitmap, *bmp; bool sw; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; bmp = &MainImageForm->iMainImage->ArrayBitmap[1]; Bitmap = Undo->Last->Mark; bmp->FillRect(r, 0); if (!bmp->StartScanLine()) goto fail; if (!Bitmap->StartScanLine()) goto fail; for (i = 0; i < size.y; i++) { IP = Bitmap->GetScanLine(rect.top+i) + rect.left; IP1 = bmp->GetScanLine(rect.top+i) + rect.left; sw = true; for (j = 0; j < size.x; j++, IP++, IP1++) { if ((*IP & 0x3F) > 1) { if ((*IP & 0x80) != 0) { if (sw) *IP1 = 0; else *IP1 = *IP; } else { k = MainImageForm->Arrange->Dmark.sp[*IP & 0x3F]->wale; if ( (k + j) > size.x) {sw = true; *IP1 = 0;} else *IP1 = *IP; } } else { *IP1 = *IP; sw = false; } } bmp->PutScanLine(rect.top+i); } bmp->StopScanLine(); Bitmap->StopScanLine(); MainImageForm->iMainImage->SetMark(); ::RepaintImage(); Screen->Cursor = cursor; PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); return; fail: Bitmap->StopScanLine(); bmp->StopScanLine(); Screen->Cursor = cursor; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMClearForm::sbWholeClick(TObject *Sender) { if (Both) { if (!MainImageForm->UndoSave(UK_ALL | UK_MARK, r, true)) goto fail; WholeYarnClear(); WholeMarkClear(); MainImageForm->WorkArea->Reset(true); } else if (Yarn) { if (!MainImageForm->UndoSave(UK_ALL, r, true)) goto fail; WholeYarnClear(); } else if (Mark) { if (!MainImageForm->UndoSave(UK_MARK | UK_WORKAREA, r, true)) goto fail; WholeMarkClear(); } return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMClearForm::sbWinInClick(TObject *Sender) { if (Both) { if (!MainImageForm->UndoSave(UK_ALL | UK_MARK, rect, true)) goto fail; WinInYarnClear(); WinInMarkClear(); } else if (Yarn) { if (!MainImageForm->UndoSave(UK_ALL, rect, true)) goto fail; WinInYarnClear(); } else if (Mark) { if (!MainImageForm->UndoSave(UK_MARK | UK_WORKAREA, rect, true)) goto fail; WinInMarkClear(); } return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMClearForm::sbWinOutClick(TObject *Sender) { if (Both) { if (!MainImageForm->UndoSave(UK_ALL | UK_MARK, r, true)) goto fail; WinOutYarnClear(); WinOutMarkClear(); } else if (Yarn) { if (!MainImageForm->UndoSave(UK_ALL, r, true)) goto fail; WinOutYarnClear(); } else if (Mark) { if (!MainImageForm->UndoSave(UK_MARK | UK_WORKAREA, r, true)) goto fail; WinOutMarkClear(); } return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMClearForm::sbBothClick(TObject *Sender) { Yarn = true; Mark = true; Both = true; } //--------------------------------------------------------------------------- void __fastcall TMClearForm::sbYarnClick(TObject *Sender) { Mark = false; Both = false; Yarn = true; } //--------------------------------------------------------------------------- void __fastcall TMClearForm::sbMarkClick(TObject *Sender) { Yarn = false; Both = false; Mark = true; } //---------------------------------------------------------------------------