//--------------------------------------------------------------------------- #include #include #include #pragma hdrstop #include "Stripe_F.h" #include "FileManager_F.h" #include "MainImage.h" #include "Palette.h" #include "Undo.h" #ifndef ACADEMY #include "UserColor_F.h" #endif //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "Rulers" #pragma link "TPImage" #pragma link "TPTextileImage" #pragma link "TPSpin" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_STRIPEMAKER StringTable[0] #define IDS_AMENDMENT StringTable[1] #define IDS_NEW StringTable[2] #define IDS_ADDSTRIPE StringTable[3] #define IDS_DELETESTRIPE StringTable[4] #define IDS_PREVIEW StringTable[5] #define IDS_SPREADVIEW StringTable[6] #define IDS_PART StringTable[7] #define IDS_BRINGTOIMAGE StringTable[8] #define IDS_TOP StringTable[9] #define IDS_BOTTOM StringTable[10] #define IDS_ONEREPEAT StringTable[11] #define IDS_THICKNESS StringTable[12] #define IDS_RATIO StringTable[13] #define IDS_OVERLENWID StringTable[14] //--------------------------------------------------------------------------- TStripeForm *StripeForm; //--------------------------------------------------------------------------- __fastcall TStripeForm::TStripeForm(TComponent* Owner) : TForm(Owner) { hWnd = ((TWinControl *)Owner)->Handle; //=========================================================== StringTable.Create(DirectoryCommon, Language, "Stripe"); SetSmallFont(Font); SetSmallFont(Label1->Font); SetSmallFont(Label2->Font); SetSmallFont(Label3->Font); SetSmallFont(LengthText->Font); SetSmallFont(RatioText->Font); Caption = IDS_STRIPEMAKER; Label1->Caption = IDS_AMENDMENT; sbNew->Caption = IDS_NEW; sbAdd->Caption = IDS_ADDSTRIPE; sbDelete->Caption = IDS_DELETESTRIPE; Label2->Caption = IDS_PREVIEW; sbView->Caption = IDS_SPREADVIEW; Label4->Caption = IDS_COMMON_SIZE; SizeCombo->Items->Clear(); SizeCombo->Items->Add(IDS_PART); SizeCombo->Items->Add(IDS_COMMON_WHOLE); SizeCombo->Text = IDS_PART; Label3->Caption = IDS_BRINGTOIMAGE; sbOneRepeat->Caption = IDS_ONEREPEAT; sbWhole->Caption = IDS_COMMON_WHOLE; Label8->Caption = IDS_THICKNESS; Label5->Caption = IDS_COMMON_ANGLE + "(Deg.)"; LabelThick->Caption = "Cm"; sbRun->Caption = IDS_COMMON_RUN; sbExit->Caption = IDS_COMMON_EXIT; sbFile->Caption = IDS_COMMON_FILE; Label7->Caption = IDS_COMMON_LENGTH; Label9->Caption = IDS_RATIO; //=========================================================== } //--------------------------------------------------------------------------- void __fastcall TStripeForm::FormClose(TObject *Sender, TCloseAction &Action) { PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::FormCreate(TObject *Sender) { // } //--------------------------------------------------------------------------- void __fastcall TStripeForm::FormResize(TObject *Sender) { StringGrid->Width = ClientWidth-295;//290; MenuPanel->Left = StringGrid->Width+4; stRuler->Width = ClientWidth-5;//3; bottomBevel->Width = ClientWidth-3;//1; StripeImage->Width = ClientWidth-5;//3; ScrollBar->Width = ClientWidth-4; bottomBevel->Height = ClientHeight-337; StripeImage->Height = ClientHeight-334; ScrollBar->Top = ClientHeight-24; if (StripeImage->Height > 0 && StripeImage->Width > 0) {// by celberus if (StripeImage->Bitmap->Create(StripeImage->Width, StripeImage->Height, 8, rgb)==false) PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); ImageDrawing(); StripeImage->Repaint(); } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::sbNewClick(TObject *Sender) { InitData(); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::sbAddClick(TObject *Sender) { if (stop) { sbAdd->Down = false; MessageDlg(IDS_MESSAGE_INSERTCOLOR,mtConfirmation, TMsgDlgButtons()<Count == 150){ sbAdd->Down = false; ShowMessage(IDS_MESSAGE_NOTADDSTRIPE); return; }else sadd = true; } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::sbDeleteClick(TObject *Sender) { sdel = true; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::sbViewClick(TObject *Sender) { if (stop) { sbView->Down = false; MessageDlg(IDS_MESSAGE_INSERTCOLOR,mtConfirmation, TMsgDlgButtons()<Down) { SpreadView(); spread = true; } else { spread = false; ImageDrawing(); StripeImage->Repaint(); } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::SizeComboChange(TObject *Sender) { c_size = SizeCombo->ItemIndex; stRuler->Start = 0; ScrollBar->Position = 0; StripeImage->PositionX = 0; switch (c_size) { case 0: PartMethod(); break; case 1: WholeMethod(); break; } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::ScrollBarScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { ScrollBar->Max = StripeImage->Bitmap->Width-StripeImage->Width; StripeImage->PositionX = ScrollPos; stRuler->Start = ScrollPos; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::sbOneRepeatClick(TObject *Sender) { ThickEdit->Enabled = true; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::sbWholeClick(TObject *Sender) { ThickEdit->Enabled = false; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::ThickEditClick(TObject *Sender) { ThickEdit->SetFocus(); ThickEdit->SelectAll(); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::sbRunClick(TObject *Sender) { DEG = cbDeg->Text; //2001.12.18 lhskys ½ÇÇà½Ã °ªÀ» °¡Á®¿À°í À§ÇØ ImageDrawing();//by jeegeo //a,s Ű »ç¿ë½Ã °¢µµº¯È­¿¡ a,s°¡ keydownµÇ¾î ¿¡·¯ TRect r; bool undosw = false; if(LengthWidth()==false){ ShowMessage(IDS_OVERLENWID); return; } if (stop) { MessageDlg(IDS_MESSAGE_INSERTCOLOR,mtConfirmation, TMsgDlgButtons()<WorkAreaReset(); if (sbWhole->Down) { r = Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height); if ((undosw = MainImageForm->UndoSave(UK_ALL, r)) == false) goto fail; MainImageForm->iMainImage->SubEnabled = false; WholeDrawing(); if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) MainImageForm->RedrawingRepeat(false, true); } else { MainImageForm->iMainImage->SubEnabled = true; OneRepeatDrawing(); MainImageForm->Center.x = MainImageForm->iMainImage->SubBitmap->Width / 2; MainImageForm->Center.y = MainImageForm->iMainImage->SubBitmap->Height / 2; } Visible = false; ::RepaintColor(); Item = 1; // Visible = false; if (sbWhole->Down) { PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } return; fail: MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::sbFileClick(TObject *Sender) { //TFileManagerForm *Form = NULL; if ((FileManagerForm = new TFileManagerForm(NULL)) == NULL) goto fail; FileManagerForm->SpeedButtonRead->Down = true; FileManagerForm->SpeedButtonReadClick(this); FileManagerForm->Extension = 2; //Stripe¸¦ fileManager¿¡°Ô ¾Ë¸². FileManagerForm->FilterComboBox->Filter = "Texpro Stripe File (*.stp)|*.stp"; FileManagerForm->OnRead = STPOnRead; FileManagerForm->OnFileName = STPOnFileName; FileManagerForm->OnSave = STPOnSave; FileManagerForm->ShowModal(); delete FileManagerForm; return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::sbExitClick(TObject *Sender) { PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::StringGridDrawCell(TObject *Sender, int Col, int Row, TRect &dRect, TGridDrawState State) { int tab, i; AnsiString str; TColorData *ColorMap; PStripeData sd; if (store == NULL) return; if (Row==0) { switch (Col) { case 0: str = "NO"; break; case 1: str = "Color"; break; case 2: str = "Method"; break; case 3: str = "Length"; break; case 4: str = "Repeat"; break; } tab = ((dRect.Right-dRect.Left)-StringGrid->Canvas->TextWidth(str)) / 2; if (tab<0) tab = 0; StringGrid->Canvas->TextRect(dRect, tab+dRect.Left, dRect.Top, str); } else { if (Col==0) { str = Format(" %d", OPENARRAY (TVarRec, (Row))); tab = ((dRect.Right-dRect.Left)-StringGrid->Canvas->TextWidth(str)) / 2; if (tab<0) tab = 0; StringGrid->Canvas->TextRect(dRect, tab+dRect.Left, dRect.Top, str); } else { i = store->Count; if (Row>i) return; sd = (PStripeData) store->Items[Row-1]; if (sd->Ins) return; switch (Col) { case 1: ColorMap = MainImageForm->Palette->ColorData[sd->color]; StringGrid->Canvas->Brush->Color = RGB2TColor(ColorMap->RGB.rgbRed, ColorMap->RGB.rgbGreen, ColorMap->RGB.rgbBlue); StringGrid->Canvas->FillRect(Rect(dRect.Left+2, dRect.Top+2, dRect.Right-2, dRect.Bottom-2)); break; case 2: switch (sd->method) { case 0: str = "Normal"; break; case 1: str = "Reverse"; break; case 2: str = "Center"; break; } tab = ((dRect.Right-dRect.Left)-StringGrid->Canvas->TextWidth(str)) / 2; if (tab<0) tab = 0; StringGrid->Canvas->TextRect(dRect, tab+dRect.Left, dRect.Top, str); break; case 3: if (IsNumber(StringGrid->Cells[Col][Row], Col)) { switch (UnitItem) { case 0: if (Init) { StringGrid->Cells[Col][Row] = sd->length; if (Row == i)Init = false; } //else // sd->length = StrToFloat(StringGrid->Cells[Col][Row]); break; case 1: if (Init) { StringGrid->Cells[Col][Row] = Format("%.2f", OPENARRAY (TVarRec, ((double)sd->length/Mdpi))); if (Row == i)Init = false; } //else // sd->length = StrToFloat(StringGrid->Cells[Col][Row])*Mdpi + 0.5; break; case 2: if (Init) { StringGrid->Cells[Col][Row] = Format("%.2f", OPENARRAY (TVarRec, (2.54*sd->length/Mdpi))); if (Row == i)Init = false; } //else // sd->length = StrToFloat(StringGrid->Cells[Col][Row])*Mdpi/2.54 + 0.5; break; } } else { switch (UnitItem) { case 0: StringGrid->Cells[Col][Row] = sd->length; break; case 1: StringGrid->Cells[Col][Row] = Format("%.2f", OPENARRAY (TVarRec, ((double)sd->length/Mdpi))); break; case 2: StringGrid->Cells[Col][Row] = Format("%.2f", OPENARRAY (TVarRec, (2.54*sd->length/Mdpi))); break; } } break; case 4: if (sd->length) { if (IsNumber(StringGrid->Cells[Col][Row], Col)) { sd->repetition = StrToInt(StringGrid->Cells[Col][Row]); } else StringGrid->Cells[Col][Row] = sd->repetition; } break; } } } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::StringGridKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if (Key==VK_RETURN) { TStringGrid *grid = (TStringGrid *) Sender; grid->EditorMode = false; if ((grid->Col==3)||(grid->Col==4)) { if (grid->Row!=0) { InputData(grid); ImageDrawing(); StringGrid->Repaint(); StripeImage->Repaint(); ImageDrawing(); grid->Row = grid->Row+1; } } grid->EditorMode = false; } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::InputData(TStringGrid *grid) { if (grid->Row>store->Count) return; PStripeData sd = (PStripeData) store->Items[grid->Row-1]; if (IsNumber(grid->Cells[grid->Col][grid->Row], grid->Col)) { if (grid->Col == 3) { switch (UnitItem) { case 0: sd->length = StrToFloat(grid->Cells[grid->Col][grid->Row]); break; case 1: sd->length = StrToFloat(grid->Cells[grid->Col][grid->Row])*Mdpi + 0.5; break; case 2: sd->length = StrToFloat(grid->Cells[grid->Col][grid->Row])*Mdpi/2.54 + 0.5; break; } } else if (grid->Col == 4) { if (sd->length) sd->repetition = StrToInt(grid->Cells[grid->Col][grid->Row]); } } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::StringGridSelectCell(TObject *Sender, int Col, int Row, bool &CanSelect) { TGridOptions options = StringGrid->Options; if (CanSelect) { if ((Row > 0) && (Row <= store->Count)) { switch (Col) { case 0: case 1: case 2: options>>goEditing; break; case 3: case 4: options<>goEditing; StringGrid->Options = options; } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::ReadSTPIni() { int i, count, i_col, angle; AnsiString str; PStripeData sd; TIniFile *STPIni = NULL; STPIni = new TIniFile(DirectoryItem+"\\Stripe.ini"); if (STPIni) { count = STPIni->ReadInteger("Infor", "Count", 0); i = count; while (count>0) { sd = new TStripeData; str = Format("%d", OPENARRAY (TVarRec, (i-count))); i_col =STPIni->ReadInteger(str, "Color", 0); sd->color = i_col; sd->method = STPIni->ReadInteger(str, "Method", 0); sd->repetition = STPIni->ReadInteger(str, "Repetition", 0); sd->length = STPIni->ReadInteger(str, "Length", 0); // sd->Ins = STPIni->ReadInteger(str, "Ins", 0); sd->Ins = false; store->Add(sd); count = count-1; } angle = STPIni->ReadInteger("Infor", "Angle", 0); cbDeg->Text = IntToStr(angle); angle = STPIni->ReadInteger("Infor", "One_Whole", 0); if (angle) { sbWhole->Down = true; ThickEdit->Enabled = false; } else { sbOneRepeat->Down = true; ThickEdit->Enabled = true; } delete STPIni; } if (store->Count>0) { InitialFunc(1); enterfunc = false; StringGrid->Row = store->Count; // ½ºÆ®¸µ±×¸®µåÀÇ ½ºÅ©·Ñ¹Ù¸¦ ¿òÁ÷ÀÌ°í ½ÍÀºµð... enterfunc = true; // ÀÚ²Ù Click À¸·Î ºüÁ®¼­... ¸·À¸·Á°í¿ä~~ StringGrid->Repaint(); } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::WriteSTPIni() { int count, availCount, i; AnsiString str; PStripeData sd; TIniFile *STPIni = NULL; STPIni = new TIniFile(DirectoryItem+"\\Stripe.ini"); if (STPIni) { count = STPIni->ReadInteger("Infor", "Count", 0); if (store->CountCount; iEraseSection(str); } } availCount = store->Count; for (int i=0; iCount; i++) { sd = (PStripeData) store->Items[i]; if (sd->Ins) availCount--; } STPIni->WriteInteger("Infor", "Count", availCount); count = store->Count; while (count>0) { sd = (PStripeData) store->Items[count-1]; if (!sd->Ins) { str = Format("%d", OPENARRAY (TVarRec, (availCount-1))); STPIni->WriteInteger(str, "Color", sd->color); STPIni->WriteInteger(str, "Method", sd->method); STPIni->WriteInteger(str, "Repetition", sd->repetition); STPIni->WriteInteger(str, "Length", sd->length); // STPIni->WriteInteger(str, "Ins", sd->Ins); availCount = availCount - 1; } count = count-1; } STPIni->WriteInteger("Infor", "Angle", StrToInt(DEG)); if (sbOneRepeat->Down) i = 0; else i = 1; STPIni->WriteInteger("Infor", "One_Whole", i); delete STPIni; } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::InitData() { PStripeData sd; while (store->Count>0) { StringGrid->Cells[3][store->Count] = ""; StringGrid->Cells[4][store->Count] = ""; sd = (PStripeData) store->Last(); store->Remove(sd); delete sd; } stop = false; InitialFunc(0); ImageDrawing(); StripeImage->Repaint(); StringGrid->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::InitialFunc(Byte i) { switch (i) { case 0: sbNew->Enabled = false; sbAdd->Enabled = false; sbDelete->Enabled = false; sbView->Enabled = false; SizeCombo->Enabled = false; ScrollBar->Position = 0; StripeImage->PositionX = 0; stRuler->Start = 0; ScrollBar->Enabled = false; sbRun->Enabled = false; sbOneRepeat->Enabled = false; sbWhole->Enabled = false; break; case 1: sbNew->Enabled = true; sbAdd->Enabled = true; sbDelete->Enabled = true; sbView->Enabled = true; sbRun->Enabled = true; sbOneRepeat->Enabled = true; sbWhole->Enabled = true; break; } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::ChangeLabel() { AnsiString un = MainImageForm->UnitName((TUnit)UnitItem); LabelThick->Caption = un; switch (UnitItem) { case 0: len = (double) b_width; LengthText->Caption = Format("%.0f %s", OPENARRAY (TVarRec, (len, un))); break; case 1: len = (double) b_width/Mdpi; LengthText->Caption = Format("%.2f %s", OPENARRAY (TVarRec, (len, un))); break; case 2: len = 2.54*b_width/Mdpi; LengthText->Caption = Format("%.2f %s", OPENARRAY (TVarRec, (len, un))); break; } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::ConvertValue() { int i; PStripeData sd; switch (UnitItem) { case 0: if (store->Count>0) { for (i=0; iCount; i++) { sd = (PStripeData) store->Items[i]; StringGrid->Cells[3][i+1] = IntToStr((int)sd->length); } } ThickEdit->Text = IntToStr((int)Thick); break; case 1: if (store->Count>0) { for (i=0; iCount; i++) { sd = (PStripeData) store->Items[i]; StringGrid->Cells[3][i+1] = Format("%.2f", OPENARRAY (TVarRec, ((double)sd->length/Mdpi))); } } ThickEdit->Text = Format("%.2f", OPENARRAY (TVarRec, ((double)Thick/Mdpi))); break; case 2: if (store->Count>0) { for (i=0; iCount; i++) { sd = (PStripeData) store->Items[i]; StringGrid->Cells[3][i+1] = Format("%.2f", OPENARRAY (TVarRec, (2.54*sd->length/Mdpi))); } } ThickEdit->Text = Format("%.2f", OPENARRAY (TVarRec, (2.54*Thick/Mdpi))); break; } StringGrid->Repaint(); } //--------------------------------------------------------------------------- bool __fastcall TStripeForm::IsNumber(AnsiString str, int col) { if (str == "") return false; float k; try { if (col ==3) k = StrToFloat(str); else k = StrToInt(str); } catch (EConvertError *error) { return false; } return true; /* char *kkk; Cardinal lt, i; kkk = Str.c_str(); if (Str!="") { lt = StrLen(kkk); for (i=0; iCount>0) { BitmapDrawing(); stRuler->Start = 0; ScrollBar->Position = 0; StripeImage->PositionX = 0; if (b_width<=StripeImage->Width) { SizeCombo->Enabled = false; ScrollBar->Enabled = false; if (spread) SpreadView(); else { Src = Rect(0, 0, StripeImage->Bitmap->Width, StripeImage->Bitmap->Height); Dst = Src; if ((hDC = StripeImage->Bitmap->CreateDC()) == NULL) goto fail; BitBlt(StripeImage->Canvas->Handle, Dst.Left, Dst.Top, (Dst.Right-Dst.Left), (Dst.Bottom-Dst.Top), hDC, Src.Left, Src.Top, SRCCOPY); StripeImage->Bitmap->DeleteDC(hDC); } } else { SizeCombo->Enabled = true; sbView->Down = false; sbView->Enabled = false; switch (c_size) { case 0: PartMethod(); break; case 1: WholeMethod(); break; } } } else { if (StripeImage->Bitmap->Create(StripeImage->Width, StripeImage->Height, 8, rgb) == false) PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); rect = Rect(0, 0, StripeImage->Width, StripeImage->Height); StripeImage->Bitmap->FillRect(rect, PALETTEINDEX(255)); } ChangeLabel(); //StripeImage->Repaint(); return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::BitmapDrawing() { HDC dcDst,dcSrc; int x, y, z, r, sp, ep, ctr, length,height, ht; PStripeData sd; RECT rect; Byte *b_col; length = GetLength(); height = GetHeight(); if (StripeImage->Width>length) length = StripeImage->Width; if (Stripebmp2->Create(length, height, 8, rgb) == NULL) goto fail;//by jeegeo if ((dcSrc = Stripebmp2->CreateDC()) == NULL) goto fail; MainImageForm->Palette->ToRGBQUAD(rgb, 256); rgb[255].rgbRed = 255; rgb[255].rgbBlue = 255; rgb[255].rgbGreen = 255; Stripebmp2->PutColors(0, 256, rgb); rect = Rect(0, 0, StripeImage->Width, height); //by jeegeo Stripebmp2->FillRect(rect, PALETTEINDEX(255)); if (Stripebmp2->StartScanLine() == false) goto fail; b_col = (Byte *) Stripebmp2->GetScanLine(0); ctr = -1; x = 0; while (xCount) { sd = (PStripeData) store->Items[x]; r = sd->repetition; if (sd->method!=2) { sp = x; ep = x; y = x+1; while (yCount) { sd = (PStripeData) store->Items[y]; if ((r==sd->repetition) && (sd->method!=2)) { ep = y; y = y+1; continue; } else { ep = y-1; break; } } x = x+ep-sp+1; DrawMethod_1(sp, ep, r, b_col); } else { DrawMethod_1(x, x, r, b_col); y = x-1; while (y>ctr) { sd = (PStripeData) store->Items[y]; sp = y; ep = y; if (sd->method==1) { r = sd->repetition; z = y-1; while (z>ctr) { sd = (PStripeData) store->Items[z]; if ((r==sd->repetition) && (sd->method==1)) { ep = z; z = z-1; continue; } else { ep = z+1; break; } } DrawMethod_2(sp, ep, r, b_col); } y = y-(sp-ep+1); } ctr = x; x = x+1; } } for (ht=0; ht< height; ht++) //by jeegeo Stripebmp2->PutScanLine(ht); Stripebmp2->StopScanLine(); if (StripeImage->Bitmap->Create(length, StripeImage->Height, 8, rgb) == NULL) goto fail; //by jeegeo if ((dcDst = StripeImage->Bitmap->CreateDC()) == NULL) goto fail; SetStretchBltMode(dcDst,COLORONCOLOR); StretchBlt(dcDst, 0, 0, length,StripeImage->Height,dcSrc , 0, 0, length,height, SRCCOPY); StripeImage->Bitmap->DeleteDC(dcDst); dcDst = NULL; Stripebmp2->DeleteDC(dcSrc); dcSrc = NULL; return; fail : Stripebmp2->Destroy(); Stripebmp2->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- int __fastcall TStripeForm::GetLength() { int i, j, ctr, tot; PStripeData sd; i = 0; tot = 0; ctr = -1; while (iCount) { sd = (PStripeData) store->Items[i]; tot = tot+sd->length*sd->repetition; if (sd->method==2) { j = i-1; while (j>ctr) { sd = (PStripeData)store->Items[j]; if (sd->method==1) tot = tot+sd->length*sd->repetition; j = j-1; } ctr = i; } i = i+1; } return tot; } //--------------------------------------------------------------------------- int __fastcall TStripeForm::GetHeight() { int thick; CheckRange(); switch (UnitItem) { case 0: thick = StrToFloat(ThickEdit->Text); break; case 1: thick = StrToFloat(ThickEdit->Text)*Mdpi; break; case 2: thick = StrToFloat(ThickEdit->Text)*Mdpi/2.54; break; } return thick; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::DrawMethod_1(int sp, int ep, int r, Byte *c) { int k, m, w; PStripeData sd; for (m=1; m<=r; m++) { for (k=sp; k<=ep; k++) { sd = (PStripeData)store->Items[k]; for (w=b_width; wlength; w++) *(c+w) = sd->color; b_width = b_width+sd->length; } } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::DrawMethod_2(int sp, int ep, int r, Byte *c) { int k, m, w; PStripeData sd; for (m=1; m<=r; m++) { for (k=sp; k>=ep; k--) { sd = (PStripeData)store->Items[k]; for (w=b_width; wlength; w++) *(c+w) = sd->color; b_width = b_width+sd->length; } } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::SpreadView() { int v, w, y, z; TRect Src, Dst; HDC hDC; Src = Rect(0, 0, b_width, StripeImage->Height); w = StripeImage->Width / b_width; v = StripeImage->Width % b_width; if ((hDC = StripeImage->Bitmap->CreateDC()) == NULL) goto fail; for (z=0; z<=w; z++) { y = b_width*(z+1); if (y>StripeImage->Width) { y = StripeImage->Width; Src = Rect(0, 0, v, StripeImage->Height); } Dst = Rect(b_width*z, 0, y, StripeImage->Height); BitBlt(StripeImage->Canvas->Handle, Dst.Left, Dst.Top, (Dst.Right-Dst.Left), (Dst.Bottom-Dst.Top), hDC, Src.Left, Src.Top, SRCCOPY); } StripeImage->Bitmap->DeleteDC(hDC); return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::PartMethod() { StripeImage->Stretch = false; RatioText->Caption = "100 %"; stRuler->Zoom = 1; ScrollBar->Enabled = true; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::WholeMethod() { int ratio; StripeImage->Stretch = true; ratio = (100*StripeImage->Width) / StripeImage->Bitmap->Width; RatioText->Caption = Format("%d %%", OPENARRAY(TVarRec, (ratio))); stRuler->Zoom = (double) ratio/100.0; ScrollBar->Enabled = false; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::CheckRange() { double t, cmpL; if(ThickEdit->Text=="")ThickEdit->Text="0"; if (IsNumber(ThickEdit->Text, 3)) { t = StrToFloat(ThickEdit->Text); if ((c_direct==0) || (c_direct==1)) { cmpL = MainImageForm->iMainImage->uBitmap->Height; } else { cmpL = MainImageForm->iMainImage->uBitmap->Width; } if (UnitItem == 1) { cmpL = cmpL /160.0; } else if (UnitItem ==2) { cmpL = 2.54 * cmpL /160.0; } if (t>cmpL) ThickEdit->Text = FloatToStr(cmpL); else if (t<0) ThickEdit->Text = "0"; } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::WholeDrawing() { TPItemImage *Image = MainImageForm->iMainImage; Byte *IP, *DP; int x, y, w, k, width, height, vx, px; int startx,starty; double theta, cosv, sinv; PStripeData sd; TPalette *pPalette; COLORREF crrf; k = MainImageForm->Palette->UseColor; width = Image->uBitmap->Width; height = Image->uBitmap->Height; startx=0; starty=0; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)){ startx=MainImageForm->arwindow.s.x; width=MainImageForm->arwindow.e.x; starty=MainImageForm->arwindow.s.y; height=MainImageForm->arwindow.e.y; } theta = StrToInt(cbDeg->Text)*M_PI/180; cosv = cos(theta); sinv = sin(theta); w = sqrt(width*width + height*height); w = b_width*(w/b_width + 1); // Max. value for min. value(less than 0) if ((StripeImage->Bitmap->StartScanLine()) == false) goto fail; if ((Image->uBitmap->StartScanLine()) == false) goto fail; IP = StripeImage->Bitmap->GetScanLine(0); if (Image->uBitmap->BitsPerPixel == 8) { for (y = starty; y < height; y++) { DP = Image->uBitmap->GetScanLine(y); for (x = startx; x < width; x++) { vx = x*cosv + y*sinv; vx += w; //to be greater than 0 px = vx - b_width*(vx/b_width); DP[x] = IP[px]; } Image->uBitmap->PutScanLine(y); } } else { pPalette = MainImageForm->Palette; for (y = starty; y < height; y++) { DP = Image->uBitmap->GetScanLine(y); for (x = startx; x < width; x++, DP+=3) { vx = x*cosv + y*sinv; vx += w; //to bt grater than 0 px = vx - b_width*(vx/b_width); crrf = pPalette->Color[IP[px]]; SetPixel24(DP, crrf); } Image->uBitmap->PutScanLine(y); } } Image->uBitmap->StopScanLine(); StripeImage->Bitmap->StopScanLine(); // if (Image->LayerMask) Image->LayerMask->FillRect(Rect(0, 0, width, height), 0); if (Image->LayerMask) Image->LayerMask->FillRect(Rect(startx, starty, width, height), 0); for (x = 0; x < store->Count; x++) { sd = (PStripeData) store->Items[x]; if (k < sd->color) k = sd->color; } MainImageForm->Palette->UseColor = k; return; fail: StripeImage->Bitmap->StopScanLine(); Image->uBitmap->StopScanLine(); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::OneRepeatDrawing() { TPItemImage *Image = MainImageForm->iMainImage; int x, y, deg, width, height, thick; Byte *DP, *IP, mm; COLORREF c; width = MainImageForm->iMainImage->uBitmap->Width; height = MainImageForm->iMainImage->uBitmap->Height; deg = StrToInt(cbDeg->Text)*100; CheckRange(); switch (UnitItem) { case 0: thick = StrToFloat(ThickEdit->Text); break; case 1: thick = StrToFloat(ThickEdit->Text)*Mdpi; break; case 2: thick = StrToFloat(ThickEdit->Text)*Mdpi/2.54; break; } // if (b_width > width) b_width = width; // if (thick > height) thick = height; if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { if (MainImageForm->iMainImage->SubBitmap->Create(b_width, thick, 8, rgb) == false) goto fail; MainImageForm->iMainImage->SubBitmap->Copy(Stripebmp2, SRCCOPY); if (!MainImageForm->iMainImage->SubBitmap->Rotate(deg, true, 0)) goto fail; if (MainImageForm->iMainImage->SubMask->Create(MainImageForm->iMainImage->SubBitmap->Width, MainImageForm->iMainImage->SubBitmap->Height, 8, rgb) == false) goto fail; MainImageForm->iMainImage->SubBitmap->StartScanLine(); MainImageForm->iMainImage->SubMask->StartScanLine(); for (y = 0; y < MainImageForm->iMainImage->SubBitmap->Height; y++) { IP = MainImageForm->iMainImage->SubBitmap->GetScanLine(y); DP = MainImageForm->iMainImage->SubMask->GetScanLine(y); for (x = 0; x < MainImageForm->iMainImage->SubBitmap->Width; x++, DP++, IP++) { if (*IP) *DP = 0; else *DP = 0xFF; } MainImageForm->iMainImage->SubMask->PutScanLine(y); } MainImageForm->iMainImage->SubBitmap->StopScanLine(); MainImageForm->iMainImage->SubMask->StopScanLine(); if ((Stripebmp = new TUnionBitmap) == NULL) goto fail; // convert by celberus if ((Stripebmp->Create(MainImageForm->iMainImage->SubBitmap->Width, MainImageForm->iMainImage->SubBitmap->Height, 8, rgb)) == false) goto fail; } else { if (MainImageForm->iMainImage->SubBitmap->Create(b_width, thick, 24) == false) goto fail; MainImageForm->iMainImage->SubBitmap->Copy(Stripebmp2, SRCCOPY); FillColor = SearchFillColor(); if (!MainImageForm->iMainImage->SubBitmap->Rotate(deg, true, FillColor)) goto fail; if (MainImageForm->iMainImage->SubMask->Create(Image->SubBitmap->Width, MainImageForm->iMainImage->SubBitmap->Height, 1) == false) goto fail; MainImageForm->iMainImage->SubBitmap->StartScanLine(); MainImageForm->iMainImage->SubMask->StartScanLine(); for (y = 0; y < MainImageForm->iMainImage->SubBitmap->Height; y++) { IP = MainImageForm->iMainImage->SubBitmap->GetScanLine(y); DP = MainImageForm->iMainImage->SubMask->GetScanLine(y); x = 0; *DP = 0; mm = 0x80; while(1) { GetPixel24(IP, c); if (c == FillColor) *DP |= mm; x++; if (x >= MainImageForm->iMainImage->SubBitmap->Width) break; IP += 3; if (mm == 1) { DP++; *DP = 0; mm = 0x80; } else mm >>= 1; } MainImageForm->iMainImage->SubMask->PutScanLine(y); } MainImageForm->iMainImage->SubBitmap->StopScanLine(); MainImageForm->iMainImage->SubMask->StopScanLine(); if ((Stripebmp = new TUnionBitmap) == NULL) goto fail; // convert by celberus if ((Stripebmp->Create(MainImageForm->iMainImage->SubBitmap->Width, MainImageForm->iMainImage->SubBitmap->Height, 24)) == false) goto fail; } Stripebmp->Copy(MainImageForm->iMainImage->SubBitmap, SRCCOPY); return; fail: if (Stripebmp) { delete Stripebmp; Stripebmp = NULL; } EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- COLORREF __fastcall TStripeForm::SearchFillColor() { int x, y, i, j; Byte *sl; Byte rgb[3][256]; int r, g, b; COLORREF crrf; TUnionBitmap *sBitmap = MainImageForm->iMainImage->SubBitmap; // convert by celberus memset(rgb, 0, 256 * 3); if (sBitmap->StartScanLine() == false) goto fail; for (y = 0; y < sBitmap->Height; y++) { sl = sBitmap->GetScanLine(y); for (x = 0; x < sBitmap->Width; x++, sl += 3) { GetPixel24(sl, crrf); r = crrf & 0xFF; g = (crrf>>8) & 0xFF; b = (crrf>>16) & 0xFF; rgb[0][r] = 1; rgb[1][g] = 1; rgb[2][b] = 1; } } sBitmap->StopScanLine(); for (i = 0; i < 3; i++) { for (j = 0; j < 256; j++) { if (rgb[i][j] == 0) return 0x00000000 | (j<<(8*i)); } } return 0; fail : sBitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return 0; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::OpenImage() { int x, y, t; Byte *sip, *mip, *lp; COLORREF tcol ; TPItemImage *Image = MainImageForm->iMainImage; TPoint p; RECT rc, rc1; bool undosw = false; p.x = Image->SubRange.left; p.y = Image->SubRange.top; rc = Rect(p.x, p.y, p.x+Image->SubBitmap->Width, p.y+Image->SubBitmap->Height); rc1 = Rect(p.x, p.y, p.x+Image->SubBitmap->Width, p.y+Image->SubBitmap->Height); if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) rc = MainImageForm->AutoRep_UndoRect(rc); //2001.6.19 by lhskys autorepeat if (sbOneRepeat->Down) { if ((undosw = MainImageForm->UndoSave(UK_ALL, rc)) == false) goto fail; if ((Image->uBitmap->StartScanLine()) == false) goto fail; if ((Image->SubBitmap->StartScanLine()) == false) goto fail; if (Image->uBitmap->BitsPerPixel == 8) { for (y=0; ySubBitmap->Height; y++) { mip = Image->uBitmap->GetScanLine(p.y + y); sip = Image->SubBitmap->GetScanLine(y); for (x=0; xSubBitmap->Width; x++) { mip[p.x + x] = sip[x]; } Image->uBitmap->PutScanLine(p.y + y); } } else { for (y=0; ySubBitmap->Height; y++) { mip = Image->uBitmap->GetScanLine(p.y + y) + 3*p.x; sip = Image->SubBitmap->GetScanLine(y); for (x=0; x < Image->SubBitmap->Width; x++, mip += 3, sip += 3) { GetPixel24(sip, tcol); if (tcol != FillColor) { CopyPixel24(mip, sip); } } Image->uBitmap->PutScanLine(p.y + y); } } Image->SubBitmap->StopScanLine(); Image->uBitmap->StopScanLine(); if (Stripebmp) { delete Stripebmp; Stripebmp = NULL; } if (Image->LayerMask) Image->LayerMask->CopyToRect(p.x, p.y, Image->SubMask, SRCAND); } MainImageForm->WorkArea->SetRectangle(rc1); if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) MainImageForm->RedrawingRepeat(false, false); //2001.6.19 by lhskys autorepeat MainImageForm->WorkAreaChange(); PaletteForm->DIB256Palette->ChoiceIndex = 2; Image->SubVisible = false; Image->SubEnabled = false; ::RepaintColor(); Item = 0; return; fail: if (Stripebmp) { delete Stripebmp; Stripebmp = NULL; } if (undosw) MainImageForm->Undo->RemoveLast(); Image->uBitmap->StopScanLine(); Image->SubBitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::InitForm() { TUnit u = MainImageForm->CurrentUnit; #if defined(TEXTILE) if (u == uDot) { UnitItem = 0; ThickEdit->Text = IntToStr(MainImageForm->CanvasInfor.DotsPerInch);//"1 Inch" stRuler->AUnit = uDot; } else if (u == uInch) { UnitItem = 1; ThickEdit->Text = "1"; stRuler->AUnit = uInch; } else { UnitItem = 2; ThickEdit->Text = "2.54"; stRuler->AUnit = uCm; } Thick = MainImageForm->CanvasInfor.DotsPerInch; //"1 Inch" #elif defined(KNIT) UnitItem = 0; ThickEdit->Text = "15"; stRuler->AUnit = uDot; #endif StringGrid->RowCount = 151; store = new TList; ColIndex = PaletteForm->DIB256Palette->UseColor; sadd = false; sdel = false; stop = false; emode = false; InitialFunc(0); len = 0; Mdpi = MainImageForm->CanvasInfor.DotsPerInch; stRuler->DPI = Mdpi; c_size = 0; c_direct = 0; sbNew->Down = false; sbAdd->Down = false; sbDelete->Down = false; sbView->Down = false; MainImageForm->Palette->ToRGBQUAD(rgb, 256); rgb[255].rgbRed = 255; rgb[255].rgbBlue = 255; rgb[255].rgbGreen = 255; if (StripeImage->Bitmap->Create(StripeImage->Width, StripeImage->Height, 8, rgb) == false) goto fail; Left = 40; Top = 80; Width = 900; Height = 765; Visible = true; Init = true; enterfunc = true; Stripebmp2=new TTexpiaBitmap; ReadSTPIni(); ImageDrawing(); //StripeImage->Repaint(); Stripebmp = NULL; DEG = 0; return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::ExitForm() { PStripeData sd; if (store) { WriteSTPIni(); while (store->Count>0) { sd = (PStripeData) store->Last(); store->Remove(sd); delete sd; } delete store; store = NULL; } MainImageForm->iMainImage->SubVisible = false; MainImageForm->iMainImage->SubEnabled = false; if (Stripebmp) { delete Stripebmp; Stripebmp = NULL; } if (Stripebmp2) { delete Stripebmp2; Stripebmp2 = NULL; } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::ChangeUnit(TUnit CUnit) { if (stop) { MessageDlg(IDS_MESSAGE_INSERTCOLOR, mtConfirmation, TMsgDlgButtons()<AUnit = uDot; } else if (CUnit==uInch) { UnitItem = 1; ConvertValue(); stRuler->AUnit = uInch; } else if (CUnit==uCm) { UnitItem = 2; ConvertValue(); stRuler->AUnit = uCm; } ChangeLabel(); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::FGChange(int i) { ColIndex = i; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::iMainImageMouseDown(int X, int Y) { int i, k = MainImageForm->Palette->UseColor; PStripeData sd; if (Item==1) { MainImageForm->SubBitmapPosition(X, Y, false); for (i = 0; i < store->Count; i++) { sd = (PStripeData) store->Items[i]; if (k < sd->color) k = sd->color; } MainImageForm->Palette->UseColor = k; OpenImage(); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::iMainImageMouseMove(int X, int Y) { if (Item==1) { MainImageForm->SubBitmapPosition(X, Y, false); if (sbOneRepeat->Down) { MainImageForm->iMainImage->Cursor = crHandPoint; MergeSImage(X, Y); } } else { if(!MainImageForm->iMainImage->Cross)MainImageForm->iMainImage->Cursor = crPen; } } //---------------------------------------------------------------------------- void __fastcall TStripeForm::MergeSImage(int X, int Y) { int x, y, h, w; POINT p; Byte *sip, *mip, *sbp; COLORREF tcol; RECT r; TPItemImage *Image = MainImageForm->iMainImage; if (Stripebmp && Item == 1) { p.x = Image->SubRange.left; p.y = Image->SubRange.top; w = Image->SubBitmap->Width; h = Image->SubBitmap->Height; Stripebmp->StartScanLine(); Image->uBitmap->StartScanLine(); Image->SubBitmap->StartScanLine(); if (Image->uBitmap->BitsPerPixel == 8) { for (y = 0; y < h; y++) { mip = Image->uBitmap->GetScanLine(p.y + y); sip = Image->SubBitmap->GetScanLine(y); sbp = Stripebmp->GetScanLine(y); for (x = 0; x < w; x++) { if (sbp[x] == 0) sip[x] = mip[p.x + x]; } Image->SubBitmap->PutScanLine(y); } } else { for (y = 0; y < h; y++) { mip = Image->uBitmap->GetScanLine(p.y + y) + 3*p.x; sip = Image->SubBitmap->GetScanLine(y); sbp = Stripebmp->GetScanLine(y); for (x = 0; x < w; x++, sip += 3, mip += 3, sbp += 3 ) { GetPixel24(sbp, tcol); if (tcol == FillColor) CopyPixel24(sip, mip); } Image->SubBitmap->PutScanLine(y); } } Stripebmp->StopScanLine(); Image->SubMask->StopScanLine(); Image->SubBitmap->StopScanLine(); Image->uBitmap->StopScanLine(); Image->SubVisible = true; r.left = paintrect.left < Image->SubRange.left ? paintrect.left : Image->SubRange.left; r.top = paintrect.top < Image->SubRange.top ? paintrect.top : Image->SubRange.top; r.right = paintrect.right > Image->SubRange.right ? paintrect.right : Image->SubRange.right; r.bottom = paintrect.bottom > Image->SubRange.bottom ? paintrect.bottom : Image->SubRange.bottom; paintrect = Image->SubRange; Image->RectPaint(r); } } //--------------------------------------------------------------------------- TPException __fastcall TStripeForm::STPOnRead(TFMReadParameter rp, bool changeFileFormat) { TEXPIAFILEHEADER tpfh; int i, k, uc; short cnt; PStripeData sd; TPalette *TempPalette = NULL; TPException ec = EC_NONE; HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwRead; // InitData(); if ((hFile = CreateFile(FullPathName(rp.DirName, rp.FileName).c_str(),GENERIC_READ, 0, NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_MEMORY_LACK; goto fail; } if ((TempPalette = new TPalette) == NULL) {ec = EC_MEMORY_LACK; goto fail;} if ((ec = LoadFromTexpiaFile(hFile, TempPalette, tpfh, (TTexpiaBitmap *)NULL))!=EC_NONE) { ec = EC_MEMORY_LACK; goto fail; } // Union°úÀÇ Ambiguity Á¦°Å 2003-03-17 by celberus #ifndef ACADEMY UserColorLibForm->ThisFileHasUserColor(TempPalette); #endif uc = MainImageForm->Palette->UseColor; if (tpfh.Version.Texpia=='P' && tpfh.Version.Method=='T') { if (!ReadFile(hFile, &cnt, 2, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; goto fail; } if ((uc + cnt) > 251) { ec = EC_COLOR_OVERFLOW; goto fail; } InitData(); for (i = 0; i < cnt; i++) { sd = new TStripeData; if (!ReadFile(hFile, &sd->color, 1, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; goto fail; } if (!ReadFile(hFile, &sd->method, 1, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; goto fail; } if (!ReadFile(hFile, &sd->repetition, 2, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; goto fail; } if (!ReadFile(hFile, &sd->length, 2, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; goto fail; } sd->Ins = false; uc++; MainImageForm->Palette->ColorData[uc]->Copy(TempPalette->ColorData[sd->color]); sd->color = uc; store->Add(sd); } } else { if (!ReadFile(hFile, &cnt, 2, &dwRead, NULL) == -1) { ec = EC_FILE_NOT_READ; goto fail; } if ((uc + cnt) > 251) { ec = EC_COLOR_OVERFLOW; goto fail; } InitData(); for (i = 0; i < cnt; i++) { sd = new TStripeData; if (!ReadFile(hFile, &sd->color, 1, &dwRead, NULL) == -1) { ec = EC_FILE_NOT_READ; goto fail; } if (!ReadFile(hFile, &sd->method, 1, &dwRead, NULL) == -1) { ec = EC_FILE_NOT_READ; goto fail; } if (!ReadFile(hFile, &sd->repetition, 2, &dwRead, NULL) == -1) { ec = EC_FILE_NOT_READ; goto fail; } if (!ReadFile(hFile, &sd->length, 2, &dwRead, NULL) == -1) { ec = EC_FILE_NOT_READ; goto fail; } if (SetFilePointer(hFile, 2, NULL, FILE_CURRENT)==0xFFFFFFFF) { ec = EC_FILE_NOT_READ; goto fail; } uc++; MainImageForm->Palette->ColorData[uc]->Copy(TempPalette->ColorData[sd->color]); sd->color = uc; sd->Ins = false; store->Add(sd); } } delete TempPalette; CloseHandle(hFile); MainImageForm->Palette->UseColor = uc; Visible = true; StringGrid->Repaint(); ImageDrawing(); //2001.7.11 lhskys open ½Ã »öÀÌ ÀÌ»óÇϰԳª¿À´Â°ÍÀ» ó¸® ImageDrawing(); //µÎ¹øÀ» ÇØ¾ß Á¤»óÀûÀ¸·Î µÊ ÀÌÀ¯´Â ??? ¼öÁ¤¿äÇÔ..... StripeImage->Repaint(); ::RepaintColor(); if (store->Count>0) InitialFunc(1); return EC_NONE; fail: if (TempPalette) delete TempPalette; if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); return ec; } //--------------------------------------------------------------------------- TPException __fastcall TStripeForm::STPOnSave(AnsiString DirName, AnsiString FileName, TGraphicFileFormat ExtIndex, TCompressMethod cm) { TEXPIAFILEHEADER tpfh; int i, ec = EC_NONE; TTexpiaBitmap *tag = NULL; short cnt; PStripeData sd; TRect src; TCanvas *cv = NULL; HDC dcSrc = NULL; HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwWrite; // if (hasUndefinedData()) { // ShowMessage("undefined data exists!!");/* TODO : string table »ç¿ëÇØ¾ßÇÔ */ // return EC_NONE; // } if (stop) { MessageDlg(IDS_MESSAGE_INSERTCOLOR,mtConfirmation, TMsgDlgButtons()<CanvasInfor; tpfh.BitsPerPixel = MainImageForm->iMainImage->uBitmap->BitsPerPixel; tpfh.Compress = cm; src.Left = 0; src.Top = 0; src.Right = StripeImage->Bitmap->Width; src.Bottom = StripeImage->Bitmap->Height; if ((tag = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!tag->Create(80, 100, 8, rgb)) { ec = EC_MEMORY_LACK; goto fail; } if ((cv = tag->CreateCanvas())==NULL) { ec = EC_RESOURCE_LACK; goto fail; } cv->Brush->Color = clWhite; cv->FillRect(Rect(0, 0, 80, 100)); if ((dcSrc = StripeImage->Bitmap->CreateDC()) == NULL) { ec = EC_RESOURCE_LACK; goto fail; } SetStretchBltMode(cv->Handle,COLORONCOLOR); StretchBlt(cv->Handle, 0, 0, 80, 100, dcSrc, 0, 0, GetLength(), StripeImage->Bitmap->Height, SRCCOPY); StripeImage->Bitmap->DeleteDC(dcSrc); dcSrc = NULL; tag->DeleteCanvas(cv); cv = NULL; if (!SaveToTexpiaFile(hFile, MainImageForm->Palette, tpfh, tag, (TTexpiaBitmap *)NULL)) goto fail; // Union°úÀÇ Ambiguity Á¦°Å 2003-03-17 by celberus delete tag; tag = NULL; cnt = store->Count; if (!WriteFile(hFile, &cnt, 2, &dwWrite, NULL)) goto fail; for (i=0; iItems[i]; if (!WriteFile(hFile, &sd->color, 1, &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, &sd->method, 1, &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, &sd->repetition, 2, &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, &sd->length, 2, &dwWrite, NULL)) goto fail; } CloseHandle(hFile); return EC_NONE; fail: if (tag) delete tag; if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_WRITE; return ec; } //--------------------------------------------------------------------------- AnsiString __fastcall TStripeForm::STPOnFileName(AnsiString FileName, TGraphicFileFormat ExtIndex) { PChar s; int FileNameLength, last1, last2, last3, last4; char FileIndex1, FileIndex2, FileIndex3, FileIndex4; //=============================================================== FileNameLength = FileName.Length(); if(FileNameLength > 4){ last1 = FileNameLength-3; last2 = FileNameLength-2; last3 = FileNameLength-1; last4 = FileNameLength; FileIndex1 = '.'; FileIndex2 = 's'; FileIndex3 = 't'; FileIndex4 = 'p'; if((FileIndex1 == FileName[last1])&&(FileIndex2 == FileName[last2]) && (FileIndex3 == FileName[last3])&&(FileIndex4 == FileName[last4])){ s = "PASS"; }else s=NULL; }else s=NULL; //=============================================================== // s = AnsiStrScan(FileName.c_str(), '.'); if (s==NULL) { AnsiString fn = FileName+".stp"; return fn; } else { return FileName; } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::StringGridClick(TObject *Sender) { // } //--------------------------------------------------------------------------- void __fastcall TStripeForm::StringGridDblClick(TObject *Sender) { if ((StringGrid->Row > 0) && (StringGrid->Row <= store->Count)) { if ((StringGrid->Col > 2) && (StringGrid->Col <= 4)) { StringGrid->EditorMode = false; } } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::cbDegDblClick(TObject *Sender) { cbDeg->SetFocus(); cbDeg->SelectAll(); } //--------------------------------------------------------------------------- bool __fastcall TStripeForm::LengthWidth() { double yheght, xwidth, xyDeg, thickness, p, Len; AnsiString thickness1, len1; xyDeg = StrToFloat(cbDeg->Text)*M_PI/180; p = StrToFloat(ThickEdit->Text); switch (MainImageForm->CurrentUnit) { case uDot : thickness1 = p; len1 = len; break; case uInch: thickness1 = Format("%.2f", OPENARRAY(TVarRec, (p * MainImageForm->CanvasInfor.DotsPerInch))); len1 = Format("%.2f", OPENARRAY(TVarRec, (len * MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm : thickness1 = Format("%.2f", OPENARRAY(TVarRec, (p * MainImageForm->CanvasInfor.DotsPerInch / 2.54))); len1 = Format("%.2f", OPENARRAY(TVarRec, (len * MainImageForm->CanvasInfor.DotsPerInch / 2.54))); break; } thickness = StrToFloat(thickness1); Len = StrToFloat(len1); xwidth = abs(Len * cos(xyDeg)) + abs(thickness * sin(xyDeg)); yheght = abs(Len * sin(xyDeg)) + abs(thickness * cos(xyDeg)); if(yheght > MainImageForm->iMainImage->uBitmap->Height)return false; if(xwidth > MainImageForm->iMainImage->uBitmap->Width)return false; return true; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::StringGridMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { PStripeData sd = NULL; Byte m, i; if (StringGrid->Row && enterfunc) { if ((sadd) || (sdel)) { ///////////////////store->add or store->del///////////// if (StringGrid->Row<=store->Count) { if (sadd) { if ((sd = new TStripeData) == NULL) goto fail; store->Insert(StringGrid->Row-1, sd); sd->Ins = true; stop = true; sadd = false; sbAdd->Down = false; for(i=store->Count; i>=StringGrid->Row; i--) { StringGrid->Cells[3][i+1] = StringGrid->Cells[3][i]; StringGrid->Cells[4][i+1] = StringGrid->Cells[4][i]; } StringGrid->Cells[3][StringGrid->Row] = ""; StringGrid->Cells[4][StringGrid->Row] = ""; } else if (sdel) { for (i=StringGrid->Row; i<=store->Count; i++) { StringGrid->Cells[3][i] = StringGrid->Cells[3][i+1]; StringGrid->Cells[4][i] = StringGrid->Cells[4][i+1]; } sd = (PStripeData) store->Items[StringGrid->Row-1]; if (sd->Ins) stop = false; store->Remove(sd); delete sd; } sdel = false; sbDelete->Down = false; } else return; } else if (StringGrid->Col) { switch (StringGrid->Col) { case 1: StringGrid->EditorMode = false; if (StringGrid->Row<=store->Count) { sd = (PStripeData) store->Items[StringGrid->Row-1]; if (sd->Ins) { sd->color = ColIndex; sd->method = 0; sd->length = Mdpi / 2.54 + 0.5; // 1 cm sd->repetition = 1; sd->Ins = false; stop = false; } else { sd->color = ColIndex; } } else { sd = new TStripeData; sd->color = ColIndex; sd->method = 0; sd->length = Mdpi / 2.54 + 0.5; // 1 cm sd->repetition = 1; sd->Ins = false; store->Add(sd); } emode = true; break; case 2: if (StringGrid->Row<=store->Count) { StringGrid->EditorMode = false; if (StringGrid->Row>1) { //error ¹æÁö sd = (PStripeData) store->Items[StringGrid->Row-2]; //¹Ù·Î À§dataÀÇ Method m = sd->method; } else { m = 0; } sd = (PStripeData)store->Items[StringGrid->Row-1]; sd->method = sd->method+1; if (m==1) { if (sd->method>2) sd->method = 1; } else { if (sd->method>1) sd->method = 0; } } break; case 3: if (StringGrid->Row<=store->Count) StringGrid->EditorMode = true; break; case 4: if (StringGrid->Row<=store->Count) StringGrid->EditorMode = true; break; } } else StringGrid->EditorMode = false; } if (store->Count>0) InitialFunc(1); else InitialFunc(0); StringGrid->Repaint(); ImageDrawing(); StripeImage->Repaint(); if (emode) { // StringGrid->Col = 3; emode = false; } return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::ThickEditChange(TObject *Sender) { Thick = GetHeight(); } //--------------------------------------------------------------------------- bool __fastcall TStripeForm::hasUndefinedData() { PStripeData sd; int cnt = store->Count; for (int i=0; iItems[i]; if (sd->Ins) return true; } return false; } //---------------------------------------------------------------------------