//--------------------------------------------------------------------------- #include #pragma hdrstop #include "MarkFill.h" #include "MainImage.h" #include "Undo.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "Selector" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_INAREA StringTable[0] #define IDS_SEL_COLOR StringTable[1] //--------------------------------------------------------------------------- TMarkFillForm *MarkFillForm; //--------------------------------------------------------------------------- __fastcall TMarkFillForm::TMarkFillForm(TComponent* Owner) : TForm(Owner) { hWnd = ((TWinControl *)Owner)->Handle; } //--------------------------------------------------------------------------- void __fastcall TMarkFillForm::InitForm() { //=================================================================== StringTable.Create(DirectoryItem, Language, "MarkFill"); SetSmallFont(Font); sbArea->Caption = IDS_INAREA; sbSelColor->Caption = IDS_SEL_COLOR; sbRun->Caption = IDS_COMMON_RUN; SpeedButtonNew->Hint = IDS_COMMON_NEW; SpeedButtonAll->Hint = IDS_COMMON_ALL; SpeedButtonOne->Hint = IDS_COMMON_BLOCKCOLOR; SpeedButtonDelete->Hint = IDS_COMMON_DELETECOLOR; SpeedButtonBefore->Hint = IDS_COMMON_BEFORECOLOR; //=================================================================== sbArea->Down = true; sbSelColor->Down = false; ParentHeight = Parent->Height+20; ClientHeight = 80; Parent->Height = ParentHeight+ClientHeight; ColorSelector->SetPalette(MainImageForm->Palette); } //--------------------------------------------------------------------------- void __fastcall TMarkFillForm::ExitForm() { ColorSelector->SaveToFile(DirectoryItem+"\\MarkFill.ini", "ColorSelect"); } //--------------------------------------------------------------------------- void __fastcall TMarkFillForm::sbAreaClick(TObject *Sender) { ClientHeight = 80; Parent->Height = ParentHeight+ClientHeight; } //--------------------------------------------------------------------------- void __fastcall TMarkFillForm::sbSelColorClick(TObject *Sender) { ClientHeight = 168; Parent->Height = ParentHeight+ClientHeight; step = 0; IsDraw = false; } //--------------------------------------------------------------------------- void __fastcall TMarkFillForm::sbRunClick(TObject *Sender) { if (sbArea->Down) { Fill_Area(); } else { Fill_Color(); } PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TMarkFillForm::Fill_Area() { Byte *IP = NULL, set; int x, y, top, left, bottom, right; TRect r; bool sw; if (MainImageForm->WorkArea->Mask) { r = Rect(MainImageForm->WorkArea->Range.left, MainImageForm->WorkArea->Range.top, MainImageForm->WorkArea->Range.right, MainImageForm->WorkArea->Range.bottom); sw = MainImageForm->UndoSave(UK_WORKAREA | UK_MARK, r, true); if (!sw) goto fail; } else { r = Rect(0, 0, MainImageForm->iMainImage->Bitmap->Width, MainImageForm->iMainImage->Bitmap->Height); sw = MainImageForm->UndoSave(UK_MARK, r, true); if (!sw) goto fail; } if ((MainImageForm->Arrange->Dmark.set & 0x3F) == 0) { set = 0x00; } else if (MainImageForm->Arrange->Dmark.set == 0x01) { set = 0x01; } else if (MainImageForm->Arrange->Dmark.set == 0x41) { set = 0x41; } if (!MainImageForm->iMainImage->Bitmap->StartScanLine()) goto fail; for (y=r.Top; yiMainImage->Bitmap->GetScanLine(y); for (x=r.Left; xiMainImage->Bitmap->PutScanLine(y); } MainImageForm->iMainImage->Bitmap->StopScanLine(); MainImageForm->iMainImage->SetMark(r); // 7.41 ::RepaintImage(); return; fail : if (sw) Undo->RemoveLast(); MainImageForm->iMainImage->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMarkFillForm::Fill_Color() { Byte *MP, *YP, set; TTexpiaBitmap *Mbmp, *Ybmp; int x, y, top, left, bottom, right; TRect r; bool sw; if (MainImageForm->WorkArea->Mask) { r = Rect(MainImageForm->WorkArea->Range.left, MainImageForm->WorkArea->Range.top, MainImageForm->WorkArea->Range.right, MainImageForm->WorkArea->Range.bottom); sw = MainImageForm->UndoSave(UK_WORKAREA | UK_MARK, r, true); if (!sw) goto fail; } else { r = Rect(0, 0, MainImageForm->iMainImage->Bitmap->Width, MainImageForm->iMainImage->Bitmap->Height); sw = MainImageForm->UndoSave(UK_MARK, r, true); if (!sw) goto fail; } Ybmp = &MainImageForm->iMainImage->ArrayBitmap[0]; Mbmp = &MainImageForm->iMainImage->ArrayBitmap[1]; if ((MainImageForm->Arrange->Dmark.set & 0x3F) == 0) { set = 0x00; } else if (MainImageForm->Arrange->Dmark.set == 0x01) { set = 0x01; } else if (MainImageForm->Arrange->Dmark.set == 0x41) { set = 0x41; } if (ColorSelector->Count>0) { if (!Ybmp->StartScanLine()) goto fail; if (!Mbmp->StartScanLine()) goto fail; for(y=r.Top; yGetScanLine(y); MP = Mbmp->GetScanLine(y); for(x=r.Left; xNumber[*(YP+x)]<255) && ((*(MP+x) & 0x3F) < 2)) *(MP+x) = set; } Mbmp->PutScanLine(y); } Mbmp->StopScanLine(); Ybmp->StopScanLine(); } MainImageForm->iMainImage->SetMark(r); //7.41 ::RepaintImage(); return; fail : if (sw) Undo->RemoveLast(); Mbmp->StopScanLine(); Ybmp->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMarkFillForm::iMainImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TRect r; Byte *scan; int ix, iy; TPItemImage *MainImage = (TPItemImage *) Sender; if (Button==mbMiddle || (Shift.Contains(ssShift) && Button==mbLeft)) { if (sbSelColor->Down) { if (SpeedButtonOne->Down) { if (SpeedButtonDelete->Down) { ColorSelector->DeleteColor(MainImageForm->iMainImage->ArrayBitmap[0].GetPixelColor(X, Y)); } else { ColorSelector->AddColor(MainImageForm->iMainImage->ArrayBitmap[0].GetPixelColor(X, Y)); } } else { if (step>0) { Temp.right = X; Temp.bottom = Y; MainImageForm->DrawRectangleLocate(Temp); if (Temp.left>Temp.right) { r.Left = Temp.right; r.Right = Temp.left; } else { r.Left = Temp.left; r.Right = Temp.right; } if (Temp.top>Temp.bottom) { r.Top = Temp.bottom; r.Bottom = Temp.top; } else { r.Top = Temp.top; r.Bottom = Temp.bottom; } MainImage->ArrayBitmap[0].StartScanLine(); if (SpeedButtonDelete->Down) { for (iy=r.Top; iyArrayBitmap[0].GetScanLine(iy); for (ix=r.Left; ixDeleteColor(*(scan+ix)); } } } else { for (iy=r.Top; iyArrayBitmap[0].GetScanLine(iy); for (ix=r.Left; ixAddColor(*(scan+ix)); } } } MainImage->ArrayBitmap[0].StopScanLine(); step = 0; IsDraw = false; } else { Temp.left = X; Temp.top = Y; Temp.bottom = Temp.top; Temp.right = Temp.left; MainImageForm->DrawRectangleLocate(Temp); IsDraw = true; step = 11; } } } } } //--------------------------------------------------------------------------- void __fastcall TMarkFillForm::iMainImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if (sbSelColor->Down) { if (SpeedButtonOne->Down==false) { if (step>0) { if (IsDraw) MainImageForm->DrawRectangleLocate(Temp); Temp.right = X; Temp.bottom = Y; MainImageForm->DrawRectangleLocate(Temp); IsDraw = true; } } } } //--------------------------------------------------------------------------- void __fastcall TMarkFillForm::SpeedButtonNewClick(TObject *Sender) { ColorSelector->Initial(); } //--------------------------------------------------------------------------- void __fastcall TMarkFillForm::SpeedButtonAllClick(TObject *Sender) { TCursor cursor; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; if (MainImageForm->WorkArea->Mask) MainImageForm->SearchWorkAreaColor(ColorSelector->ChoiceColor); else MainImageForm->SearchWholeColor(ColorSelector->ChoiceColor); ColorSelector->Invalid(); Screen->Cursor = cursor; } //--------------------------------------------------------------------------- void __fastcall TMarkFillForm::SpeedButtonOneClick(TObject *Sender) { if (SpeedButtonOne->Down) SpeedButtonOne->Hint = IDS_COMMON_ONECOLOR; else SpeedButtonOne->Hint = IDS_COMMON_BLOCKCOLOR; } //--------------------------------------------------------------------------- void __fastcall TMarkFillForm::SpeedButtonDeleteClick(TObject *Sender) { if (SpeedButtonDelete->Down) SpeedButtonDelete->Hint=IDS_COMMON_DELETECOLOR; else SpeedButtonDelete->Hint = IDS_COMMON_INSERTCOLOR; } //--------------------------------------------------------------------------- void __fastcall TMarkFillForm::SpeedButtonBeforeClick(TObject *Sender) { ColorSelector->LoadFromFile(DirectoryItem+"\\MarkFill.Ini", "ColorSelect"); } //--------------------------------------------------------------------------- void __fastcall TMarkFillForm::iMainImageKeyDown(int Key) { if (Key==13)sbRunClick(this); //lhskys ¿£ÅÍ·Î ½ÇÇà } //---------------------------------------------------------------------------