//--------------------------------------------------------------------------- #include #pragma hdrstop #include "MarkRepeat.h" #include "MainImage.h" #include "Undo.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "TPSpin" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_REP_MARK StringTable[0] #define IDS_REP_MARKYARN StringTable[1] #define IDS_COLUMN StringTable[2] #define IDS_ROW StringTable[3] #define IDS_LEFT_UP StringTable[4] #define IDS_RIGHT_UP StringTable[5] #define IDS_LEFT_DOWN StringTable[6] #define IDS_RIGHT_DOWN StringTable[7] //--------------------------------------------------------------------------- TMarkRepeatForm *MarkRepeatForm; //--------------------------------------------------------------------------- __fastcall TMarkRepeatForm::TMarkRepeatForm(TComponent* Owner) : TForm(Owner) { hWnd = ((TWinControl *)Owner)->Handle; } //--------------------------------------------------------------------------- void __fastcall TMarkRepeatForm::stItemClick(TObject *Sender) { if (Item) { stItem->Caption = IDS_REP_MARK; Item = 0; } else { stItem->Caption = IDS_REP_MARKYARN; Item = 1; } } //--------------------------------------------------------------------------- void __fastcall TMarkRepeatForm::sbSubItemClick(TObject *Sender) { TSpeedButton *sp = (TSpeedButton *)Sender; SubItem = sp->Tag; } //--------------------------------------------------------------------------- void __fastcall TMarkRepeatForm::sbRunClick(TObject *Sender) { POINT sp, ep; TRect r; r = Rect(0, 0, MainImageForm->iMainImage->Bitmap->Width, MainImageForm->iMainImage->Bitmap->Height); if (Item) { if (MainImageForm->UndoSave(UK_ALL | UK_MARK, r, true)== false) goto fail; } else { if (MainImageForm->UndoSave(UK_WORKAREA | UK_MARK, r, true) == false) goto fail; } MainImageForm->WorkArea->PushUndo(); MainImageForm->WorkArea->ResetRegion(MainImageForm->iMainImage); CheckRepeatSize(); ArrangeCrossData(); // destination rect ÁÖº¯¿¡ cross ¸¦ Á¤¸® ÇÑ´Ù. RepeatProcess(); sp = Point(dsx, dsy); ep = Point(dsx + dsizex - 1, dsy + dsizey - 1); MainImageForm->WorkArea->SetShapeRegion(MainImageForm->iMainImage, sp, ep, false); ::RepaintImage(); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- ///// Private Method //////////////////////////////////////////////////////// //--------------------------------------------------------------------------- void __fastcall TMarkRepeatForm::CheckRepeatSize() { int w, h, col, row; // column, row w = MainImageForm->iMainImage->Bitmap->Width; h = MainImageForm->iMainImage->Bitmap->Height; col = spCol->Value; row = spRow->Value; if (SubItem & 1) { // Bottom if (rect.top + (size.y * row) > h) { dsizey = h - rect.top; } else { dsizey = row * size.y; } dsy = rect.top; } else { // Top if (rect.top - (size.y * (row-1)) < 0) { dsy = 0; dsizey = rect.bottom; } else { dsizey = row * size.y; dsy = rect.top - ((row-1) * size.y); } } if (SubItem & 2) { // Right if (rect.left + (size.x * col) > w) { dsizex = w - rect.left; } else { dsizex = col * size.x; } dsx = rect.left; } else { // Left if (rect.left - (size.x * (col-1)) < 0) { dsx = 0; dsizex = rect.right; } else { dsx = rect.left - ((col - 1) * size.x); dsizex = col * size.x; } } } //--------------------------------------------------------------------------- void __fastcall TMarkRepeatForm::ArrangeCrossData() { Byte *IP, *TP; int dex, y, xx, yy, i, j, k; TTexpiaBitmap *bmp = &MainImageForm->iMainImage->ArrayBitmap[1]; dex = dsx + dsizex - 1; if (!bmp->StartScanLine()) goto fail; for (y = 0; y < dsizey; y++) { IP = bmp->GetScanLine(dsy + y) + dsx; if ((*IP & 0x3F) > 1) { if (*IP & 0x80) { xx = MainImageForm->Arrange->Dmark.sp[*IP & 0x3F]->wale; yy = MainImageForm->Arrange->Dmark.sp[*IP & 0x3F]->course; for (i = 1; i < xx; i++) { if ((*(IP - i) & 0x80) == 0) { for (j = 0; j < yy; j++) { IP = bmp->GetScanLine(dsy + y + j) + dsx - i; memset(IP, 0, xx); bmp->PutScanLine(dsy + y); } break; } } } } IP = bmp->GetScanLine(dsy + y) + dex; if ((*IP & 0x3F) > 1) { xx = MainImageForm->Arrange->Dmark.sp[*IP & 0x3F]->wale; yy = MainImageForm->Arrange->Dmark.sp[*IP & 0x3F]->course; TP = IP - (xx - 1); if ((*TP & 0x3F) > 1 && (*TP & 0x80)) { // ³¡¿¡ °É·È´Ù. for (i = 0; i < xx; i++) { if ((*(IP - i) & 0x80) == 0) { for (j = 0; j < yy; j++) { IP = bmp->GetScanLine(dsy + y + j) + dex - i; memset(IP, 0, xx); bmp->PutScanLine(dsy + y + j); } break; } } } } } bmp->StopScanLine(); MainImageForm->iMainImage->SetMark(); return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMarkRepeatForm::RepeatProcess() { TPBitmap *Temp = NULL; TTexpiaBitmap *bmp; int x, y; Byte *SP, *DP; if ((Temp = new TPBitmap) == NULL) goto fail; if (!(Temp->Create(size.x, size.y, 8))) goto fail; if ((Temp->Lock()) == NULL) goto fail; bmp = &MainImageForm->iMainImage->ArrayBitmap[1]; // Mark Bitmap ReadyToBitmap(Temp, bmp); if (!bmp->StartScanLine()) goto fail; for (y = 0; y < dsizey; y++) { DP = bmp->GetScanLine(dsy + y) + dsx; SP = Temp->ScanLine(y % size.y); for (x = 0; x < dsizex; x++, DP++) { *DP = SP[x % size.x]; } bmp->PutScanLine(dsy + y); } bmp->StopScanLine(); MainImageForm->iMainImage->SetMark(); if (Item) { bmp = &MainImageForm->iMainImage->ArrayBitmap[0]; // Yarn Bitmap ReadyToBitmap(Temp, bmp); if (!bmp->StartScanLine()) goto fail; for (y = 0; y < dsizey; y++) { DP = bmp->GetScanLine(dsy + y) + dsx; SP = Temp->ScanLine(y % size.y); for (x = 0; x < dsizex; x++, DP++) { *DP = SP[x % size.x]; } bmp->PutScanLine(dsy + y); } bmp->StopScanLine(); } delete Temp; return; fail: delete Temp; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMarkRepeatForm::ReadyToBitmap(TPBitmap *pbmp, TTexpiaBitmap *tbmp) { int x, y; Byte *SP, *DP; if (!tbmp->StartScanLine()) goto fail; for (y = 0; y < size.y; y++) { SP = tbmp->GetScanLine(y + rect.top) + rect.left; DP = pbmp->ScanLine(y); for (x = 0; x < size.x; x++, SP++, DP++) { *DP = *SP; } } tbmp->StopScanLine(); // MainImageForm->iMainImage->SetMark(); ??????????????????????????? return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- ///// Public Method //////////////////////////////////////////////////////// //--------------------------------------------------------------------------- void __fastcall TMarkRepeatForm::InitForm() { ParentHeight = Parent->Height+20; ClientHeight = 138; Parent->Height = ParentHeight+ClientHeight; rect = MainImageForm->WorkArea->Range; size = Point(rect.right - rect.left, rect.bottom - rect.top); Item = 0; SubItem = 0; //================================================================= StringTable.Create(DirectoryItem, Language, "MarkRepeat"); SetSmallFont(Font); SetSmallFont(stItem->Font); stItem->Caption = IDS_REP_MARK; lbCol->Caption = IDS_COLUMN; lbRow->Caption = IDS_ROW; sbLeftUp->Caption = IDS_LEFT_UP; sbLeftDown->Caption = IDS_LEFT_DOWN; sbRightUp->Caption = IDS_RIGHT_UP; sbRightDown->Caption = IDS_RIGHT_DOWN; sbRun->Caption = IDS_COMMON_RUN; //================================================================= } //--------------------------------------------------------------------------- void __fastcall TMarkRepeatForm::ExitForm() { } //--------------------------------------------------------------------------- void __fastcall TMarkRepeatForm::iMainImageKeyDown(int Key) { if(Key==13)sbRunClick(this); //lhskys ¿£ÅÍ·Î ½ÇÇà } //---------------------------------------------------------------------------