//--------------------------------------------------------------------------- #include #include #include #pragma hdrstop #include "Stripe_F.h" #include "FileManager_F.h" #include "MainImage.h" #include "Palette.h" #include "Undo.h" #include "UserColor_F.h" //--------------------------------------------------------------------------- #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(DirectoryBin, 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-290;//230; MenuPanel->Left = StringGrid->Width+4; stRuler->Width = ClientWidth-3; bottomBevel->Width = ClientWidth-1; StripeImage->Width = ClientWidth-3; if (StripeImage->Bitmap->Create(StripeImage->Width, StripeImage->Height, 8, rgb)==false) PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); ScrollBar->Width = ClientWidth-4; bottomBevel->Height = ClientHeight-337; StripeImage->Height = ClientHeight-334; ScrollBar->Top = ClientHeight-24; 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()<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 = tpsDeg->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->Bitmap->Width, MainImageForm->iMainImage->Bitmap->Height); #ifdef TPDEBUG if (!MainImageForm->UndoSave(UK_ALL, r)) SHOWDEBUG; #else MainImageForm->UndoSave(UK_ALL, r); #endif } if (MainImageForm->iMainImage->Bitmap->BitsPerPixel == 8) TempBitmapDrawing(MainImageForm->iSelectImage->Bitmap); else TempBitmapDrawing24(MainImageForm->iSelectImage->Bitmap); MainImageForm->Center.x = MainImageForm->iSelectImage->Bitmap->Width / 2; MainImageForm->Center.y = MainImageForm->iSelectImage->Bitmap->Height / 2; MainImageForm->iSelectImageSize(); MainImageForm->iSelectImage->SetPosition(0, 0); MainImageForm->iSelectImage->Visible = true; MainImageForm->iSelectImage->Repaint(); ::RepaintColor(); Item = 1; Visible = false; if (sbWhole->Down) { PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::sbFileClick(TObject *Sender) { TFileManagerForm *Form = NULL; if ((Form = new TFileManagerForm(NULL)) == NULL) goto fail; Form->SpeedButtonRead->Down = true; Form->SpeedButtonReadClick(this); Form->Extension = 2; //Stripe¸¦ fileManager¿¡°Ô ¾Ë¸². Form->FilterComboBox->Filter = "Texpro Jacquard File (*.stp)|*.stp"; Form->OnRead = STPOnRead; Form->OnFileName = STPOnFileName; Form->OnSave = STPOnSave; Form->ShowModal(); delete Form; 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 = "Stitch"; break; //7.41 changed instead of Length 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::StringGridClick(TObject *Sender) { 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 = 63; sd->repetition = 1; sd->Ins = false; stop = false; } else { sd->color = ColIndex; } } else { sd = new TStripeData; sd->color = ColIndex; sd->method = 0; sd->length = 63; 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::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) { grid->Row = grid->Row+1; } } } } //--------------------------------------------------------------------------- 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; } /* if (CanSelect) { if (Row) { switch (Col) { case 0: case 1: case 2: StringGrid->Options>>goEditing; break; case 3: case 4: StringGrid->Options<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("Count", "cnt", 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 = false; store->Add(sd); count = count-1; } angle = STPIni->ReadInteger("Infor", "Angle", 0); tpsDeg->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; StringGrid->Repaint(); } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::WriteSTPIni() { int count, i; AnsiString str; PStripeData sd; TIniFile *STPIni = NULL; STPIni = new TIniFile(DirectoryItem+"\\Stripe.ini"); if (STPIni) { count = STPIni->ReadInteger("Count", "cnt", 0); if (store->CountCount; iEraseSection(str); } } STPIni->WriteInteger("Count", "cnt", store->Count); count = store->Count; while (count>0) { sd = (PStripeData) store->Items[count-1]; str = Format("%d", OPENARRAY (TVarRec, (count-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); 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; switch (UnitItem) { case 0: if (store->Count>0) { for (i=0; iCount; i++) { StringGrid->Cells[3][i+1] = Format("%.0f", OPENARRAY(TVarRec, (StrToFloat(StringGrid->Cells[3][i+1])*Mdpi / 2.54))); } } ThickEdit->Text = Format("%.0f", OPENARRAY(TVarRec, (StrToFloat(ThickEdit->Text)*Mdpi / 2.54))); break; case 1: if (store->Count>0) { for (i=0; iCount; i++) { StringGrid->Cells[3][i+1] = Format("%.2f", OPENARRAY(TVarRec, (StrToFloat(StringGrid->Cells[3][i+1])/Mdpi))); } } ThickEdit->Text = Format("%.2f", OPENARRAY(TVarRec,(StrToFloat(ThickEdit->Text)/Mdpi))); break; case 2: if (store->Count>0) { for (i=0; iCount; i++) { StringGrid->Cells[3][i+1] = Format("%.2f", OPENARRAY(TVarRec, (StrToFloat(StringGrid->Cells[3][i+1])*2.54))); } } ThickEdit->Text = Format("%.2f", OPENARRAY(TVarRec, (2.54*StrToFloat(ThickEdit->Text)))); 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() { int x, y, z, r, sp, ep, ctr, length, ht; PStripeData sd; RECT rect; Byte *b_col; length = GetLength(); if (StripeImage->Width>length) length = StripeImage->Width; if (StripeImage->Bitmap->Create(length, StripeImage->Height, 8) == NULL) goto fail; MainImageForm->Palette->ToRGBQUAD(rgb, 256); rgb[255].rgbRed = 255; rgb[255].rgbBlue = 255; rgb[255].rgbGreen = 255; StripeImage->Bitmap->PutColors(0, 256, rgb); rect = Rect(0, 0, StripeImage->Width, StripeImage->Height); StripeImage->Bitmap->FillRect(rect, PALETTEINDEX(255)); if (StripeImage->Bitmap->StartScanLine() == false) goto fail; b_col = (Byte *) StripeImage->Bitmap->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; htHeight; ht++) StripeImage->Bitmap->PutScanLine(ht); StripeImage->Bitmap->StopScanLine(); return; fail : StripeImage->Bitmap->Destroy(); StripeImage->Bitmap->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; } //--------------------------------------------------------------------------- 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->Bitmap->Height; } else { cmpL = MainImageForm->iMainImage->Bitmap->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::TempBitmapDrawing(TTexpiaBitmap *bmp) { int thick, x, y, w, www, hhh, deg, vx, px; int k = MainImageForm->Palette->UseColor; double theta, cosv, sinv; Byte *sl1, *sl2; PStripeData sd; TTexpiaBitmap *Mbmp = MainImageForm->iMainImage->Bitmap; deg = tpsDeg->Value; www = Mbmp->Width; hhh = Mbmp->Height; if (sbWhole->Down) { theta = deg*M_PI/180; cosv = cos(theta); sinv = sin(theta); w = sqrt(www*www + hhh*hhh); w = b_width*(w/b_width + 1); // Max. value for min. value(less than 0) if ((StripeImage->Bitmap->StartScanLine()) == false) goto fail; if ((Mbmp->StartScanLine()) == false) goto fail; sl1 = (Byte *) StripeImage->Bitmap->GetScanLine(0); for (y=0; yGetScanLine(y); for (x=0; x= 0) { cnt = vx/b_width; px = vx -cnt*b_width; } else { cnt = vx/b_width; px = vx - (cnt-1)*b_width; if(px == b_width) px--; } */ *(sl2+x) = *(sl1+px); } Mbmp->PutScanLine(y); } Mbmp->StopScanLine(); StripeImage->Bitmap->StopScanLine(); for (x = 0; x < store->Count; x++) { sd = (PStripeData) store->Items[x]; if (k < sd->color) k = sd->color; } MainImageForm->Palette->UseColor = k; } else if (sbOneRepeat->Down) { deg = deg*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 > www) b_width = www; if (thick > hhh) thick = hhh; if (bmp->Create(b_width, thick, 8, rgb) == false) goto fail; bmp->Copy(StripeImage->Bitmap, SRCCOPY); if (!bmp->Rotate(deg, true, 0)) goto fail; if ((Stripebmp = new TTexpiaBitmap) == NULL) goto fail; if ((Stripebmp->Create(bmp->Width, bmp->Height, 8, rgb)) == false) goto fail; Stripebmp->Copy(bmp, SRCCOPY); } return; fail: if (bmp) bmp->Destroy(); StripeImage->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::TempBitmapDrawing24(TTexpiaBitmap *bmp) { int thick, x, y, w, deg, www, hhh, px, vx; int k = MainImageForm->Palette->UseColor; double theta, cosv, sinv; Byte *ssl, *dsl; PStripeData sd; COLORREF crrf; TPalette *pPalette = PaletteForm->DIB256Palette->Palette; TTexpiaBitmap *Mbmp = MainImageForm->iMainImage->Bitmap; deg = tpsDeg->Value; www = Mbmp->Width; hhh = Mbmp->Height; if (sbWhole->Down) { theta = deg*M_PI/180; w = sqrt(www*www + hhh*hhh); w = b_width*(w/b_width + 1); //Max. value for min. value cosv = cos(theta); sinv = sin(theta); if ((StripeImage->Bitmap->StartScanLine()) == false) goto fail; if ((Mbmp->StartScanLine()) == false) goto fail; ssl = (Byte *) StripeImage->Bitmap->GetScanLine(0); for (y=0; yGetScanLine(y); for (x=0; x= 0) { px = vx - b_width*(vx/b_width); } else { px = vx - b_width*(vx/b_width - 1); if(px == b_width) px--; } */ crrf = pPalette->Color[*(ssl+px)]; SetPixel24(dsl, crrf); } Mbmp->PutScanLine(y); } Mbmp->StopScanLine(); StripeImage->Bitmap->StopScanLine(); for (x = 0; x < store->Count; x++) { sd = (PStripeData) store->Items[x]; if (k < sd->color) k = sd->color; } MainImageForm->Palette->UseColor = k; } else if (sbOneRepeat->Down) { deg = deg*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 > www) b_width = www; if (thick > hhh) thick = hhh; if ((bmp->Create(b_width, thick, 24)) == false) goto fail; bmp->Copy(StripeImage->Bitmap, SRCCOPY); FillColor = SearchFillColor(); if (!bmp->Rotate(deg, true, FillColor)) goto fail; if ((Stripebmp = new TTexpiaBitmap) == NULL) goto fail; if ((Stripebmp->Create(bmp->Width, bmp->Height, 24)) == false) goto fail; Stripebmp->Copy(bmp, SRCCOPY); } return; fail : if (bmp) bmp->Destroy(); StripeImage->Bitmap->StopScanLine(); 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; TTexpiaBitmap *sBitmap = MainImageForm->iSelectImage->Bitmap; 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 & 0x00000011; g = (crrf>>8) & 0x000011; b = (crrf>>16) & 0x0011; 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(TObject *Sender) { int x, y, t; Byte *sip, *mip; COLORREF tcol ; TPSelectImage *Image = (TPSelectImage *) Sender; TPoint p; RECT rc; if (Image->Width==MainImageForm->Panel->Width) { p.x = MainImageForm->iMainImage->PositionX-Image->PositionX; } else { p.x = MainImageForm->iMainImage->CanvasToBitmapX(Image->Left); } if (Image->Height==MainImageForm->Panel->Height) { p.y = MainImageForm->iMainImage->PositionY-Image->PositionY; } else { p.y = MainImageForm->iMainImage->CanvasToBitmapY(Image->Top); } rc = Rect(p.x, p.y, p.x+Image->Bitmap->Width, p.y+Image->Bitmap->Height); //========================================= if (sbOneRepeat->Down) { #ifdef TPDEBUG if (!MainImageForm->UndoSave(UK_ALL, rc)) SHOWDEBUG; #else // MainImageForm->UndoSave(UK_ALL, rc); MainImageForm->UndoSave(UK_ALL, rc, true); #endif if ((MainImageForm->iMainImage->Bitmap->StartScanLine()) == false) goto fail; if ((Image->Bitmap->StartScanLine()) == false) goto fail; if (MainImageForm->iMainImage->Bitmap->BitsPerPixel == 8) { for (y=0; yBitmap->Height; y++) { mip = MainImageForm->iMainImage->Bitmap->GetScanLine(p.y + y) + p.x; sip = Image->Bitmap->GetScanLine(y); for (x=0; xBitmap->Width; x++) { if (sip[x] != 0) mip[x] = sip[x]; } MainImageForm->iMainImage->Bitmap->PutScanLine(p.y + y); } } else { for (y=0; yBitmap->Height; y++) { mip = MainImageForm->iMainImage->Bitmap->GetScanLine(p.y + y) + 3*p.x; sip = Image->Bitmap->GetScanLine(y); for (x=0; xBitmap->Width; x++, mip += 3, sip += 3) { GetPixel24(sip, tcol); if (tcol != FillColor) CopyPixel24(mip, sip); } MainImageForm->iMainImage->Bitmap->PutScanLine(p.y + y); } } Image->Bitmap->StopScanLine(); MainImageForm->iMainImage->Bitmap->StopScanLine(); if (Stripebmp) { Stripebmp->Destroy(); Stripebmp = NULL; } } //========================================= MainImageForm->WorkArea->SetRectangle(rc); MainImageForm->WorkAreaChange(); PaletteForm->DIB256Palette->ChoiceIndex = 2; Image->Bitmap->Destroy(); Image->Visible = false; ::RepaintColor(); Item = 0; return; fail: MainImageForm->iMainImage->Bitmap->StopScanLine(); } //--------------------------------------------------------------------------- void __fastcall TStripeForm::Open24Image(RECT rc) { int x, y, col; Byte *ssl, *dsl; COLORREF crrf; TPalette *pPalette = PaletteForm->DIB256Palette->Palette; if (MainImageForm->iMainImage->Bitmap->StartScanLine() == false) goto fail; if (MainImageForm->iSelectImage->Bitmap->StartScanLine() == false) goto fail; for (y = rc.top; y < rc.bottom; y++) { dsl = MainImageForm->iMainImage->Bitmap->GetScanLine(y) + 3*rc.left; ssl = MainImageForm->iSelectImage->Bitmap->GetScanLine(y-rc.top); for (x = rc.left; x < rc.right; x++, dsl += 3) { col = ssl[x - rc.left]; if (col == 1) { crrf = pPalette->Color[col]; SetPixel24(dsl, crrf); } else if (col == 2) { crrf = pPalette->Color[col]; SetPixel24(dsl, crrf); } else if (col == 3) { crrf = pPalette->Color[col]; SetPixel24(dsl, crrf); } else { crrf = pPalette->Color[col]; SetPixel24(dsl, crrf); } } MainImageForm->iMainImage->Bitmap->PutScanLine(y); } MainImageForm->iSelectImage->Bitmap->StopScanLine(); MainImageForm->iMainImage->Bitmap->StopScanLine(); return; fail : MainImageForm->iSelectImage->Bitmap->StopScanLine(); MainImageForm->iMainImage->Bitmap->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 = "160"; 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; } #elif defined(KNIT) UnitItem = 0; ThickEdit->Text = "15"; stRuler->AUnit = uDot; #endif StringGrid->RowCount = 100; 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; ReadSTPIni(); ImageDrawing(); 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->iSelectImage->Visible = false; // MainImageForm->iSelectImage->Bitmap->Destroy(); //=================================================== if ( MainImageForm->iSelectImage->Bitmap) MainImageForm->iSelectImage->Bitmap->Destroy(); if (Stripebmp) {delete Stripebmp; Stripebmp = 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::iMainImageMouseMove(TObject *Sender, int X, int Y) { if (Item==1) { // MainImageForm->iMainImage->Cursor = crHandPoint; //============================================== By kjs for Merging sbRun Click if (sbOneRepeat->Down) { MainImageForm->iMainImage->Cursor = crHandPoint; MergeSImage(X, Y); } //=========================================================== MainImageForm->iSelectImageSize(); MainImageForm->IsMerge(MainImageForm->iSelectImagePosition( Point(X-MainImageForm->Center.x, Y-MainImageForm->Center.y))); } else { MainImageForm->iMainImage->Cursor = crPen; } } //---------------------------------------------------------------------------- void __fastcall TStripeForm::iSelectImageMouseDown(TObject *Sender, int X, int Y) { int i, k = MainImageForm->Palette->UseColor; PStripeData sd; if (Item==1) { MainImageForm->IsMerge(MainImageForm->iSelectImagePosition( MainImageForm->iSelectImageConvert(X, Y))); for (i = 0; i < store->Count; i++) { sd = (PStripeData) store->Items[i]; if (k < sd->color) k = sd->color; } MainImageForm->Palette->UseColor = k; OpenImage(Sender); MainImageForm->iMainImage->Repaint(); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::iSelectImageMouseMove(TObject *Sender, int X, int Y) { //==================================== /* int x, y; POINT p; Byte *sip, *mip, *sbp; COLORREF tcol; TPSelectImage *SImage = MainImageForm->iSelectImage; TPItemImage *MImage = MainImageForm->iMainImage; if (Stripebmp && Item == 1) { p = MainImageForm->iSelectImagePosition( MainImageForm->iSelectImageConvert(X, Y)); Stripebmp->StartScanLine(); MImage->Bitmap->StartScanLine(); SImage->Bitmap->StartScanLine(); if (MImage->Bitmap->BitsPerPixel == 8) { for (y=0; yBitmap->Height; y++) { mip = MImage->Bitmap->GetScanLine(p.y + y) + p.x; sip = SImage->Bitmap->GetScanLine(y); sbp = Stripebmp->GetScanLine(y); for (x=0; xBitmap->Width; x++) { if (sbp[x] == 0) sip[x] = mip[x]; } SImage->Bitmap->PutScanLine(y); } } else { for (y=0; yBitmap->Height; y++) { mip = MImage->Bitmap->GetScanLine(p.y + y) + 3*p.x; sip = SImage->Bitmap->GetScanLine(y); sbp = Stripebmp->GetScanLine(y); for (x=0; xBitmap->Width; x++, sip += 3, mip += 3, sbp += 3 ) { GetPixel24(sbp, tcol); if (tcol == FillColor) CopyPixel24(sip, mip); } SImage->Bitmap->PutScanLine(y); } } Stripebmp->StopScanLine(); SImage->Bitmap->StopScanLine(); MImage->Bitmap->StopScanLine(); SImage->Update(); } */ MergeSImage(X, Y); //==================================== /* if (Item==1) { MainImageForm->IsMerge(MaifnImageForm->iSelectImagePosition( MainImageForm->iSelectImageConvert(X, Y))); } */ } //--------------------------------------------------------------------------- void __fastcall TStripeForm::MergeSImage(int X, int Y) { int x, y; POINT p; Byte *sip, *mip, *sbp; COLORREF tcol; TPSelectImage *SImage = MainImageForm->iSelectImage; TPItemImage *MImage = MainImageForm->iMainImage; if (Stripebmp && Item == 1) { p = MainImageForm->iSelectImagePosition( MainImageForm->iSelectImageConvert(X, Y)); Stripebmp->StartScanLine(); MImage->Bitmap->StartScanLine(); SImage->Bitmap->StartScanLine(); if (MImage->Bitmap->BitsPerPixel == 8) { for (y=0; yBitmap->Height; y++) { mip = MImage->Bitmap->GetScanLine(p.y + y) + p.x; sip = SImage->Bitmap->GetScanLine(y); sbp = Stripebmp->GetScanLine(y); for (x=0; xBitmap->Width; x++) { if (sbp[x] == 0) sip[x] = mip[x]; } SImage->Bitmap->PutScanLine(y); } } else { for (y=0; yBitmap->Height; y++) { mip = MImage->Bitmap->GetScanLine(p.y + y) + 3*p.x; sip = SImage->Bitmap->GetScanLine(y); sbp = Stripebmp->GetScanLine(y); for (x=0; xBitmap->Width; x++, sip += 3, mip += 3, sbp += 3 ) { GetPixel24(sbp, tcol); if (tcol == FillColor) CopyPixel24(sip, mip); } SImage->Bitmap->PutScanLine(y); } } Stripebmp->StopScanLine(); SImage->Bitmap->StopScanLine(); MImage->Bitmap->StopScanLine(); SImage->Update(); } } //--------------------------------------------------------------------------- TPException __fastcall TStripeForm::STPOnRead(TFMReadParameter rp) { TEXPIAFILEHEADER tpfh; HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwRead; int i, j, k, m, max; short cnt; PStripeData sd; TPalette *TempPalette = NULL; TPException ec = EC_NONE; 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_FILE_NOT_OPEN; goto fail; } if ((TempPalette = new TPalette) == NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((ec = LoadFromTexpiaFile(hFile, TempPalette, tpfh, NULL)) != EC_NONE) goto fail; UserColorLibForm->ThisFileHasUserColor(TempPalette); j = MainImageForm->Palette->UseColor + 1; m = j + TempPalette->UseColor; if (m >= 252) { ec = EC_COLOR_OVERFLOW; goto fail; } max = 0; if (tpfh.Version.Texpia=='P' && tpfh.Version.Method=='T') { for (k=j; k<=m; k++) MainImageForm->Palette->ColorData[k]->Copy(TempPalette->ColorData[k-j]); if (!ReadFile(hFile, &cnt, 2, &dwRead, NULL)) goto fail; for (i= 0; icolor, 1, &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &sd->method, 1, &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &sd->repetition, 2, &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &sd->length, 2, &dwRead, NULL)) goto fail; sd->Ins = false; sd->color = sd->color+j; store->Add(sd); if (max < sd->color) max = sd->color; } } else { for (k=j; k<=m; k++) MainImageForm->Palette->ColorData[k]->Copy(TempPalette->ColorData[k-j+1]); if (!ReadFile(hFile, &cnt, 2, &dwRead, NULL)) goto fail; for (i=0; icolor, 1, &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &sd->method, 1, &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &sd->repetition, 2, &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &sd->length, 2, &dwRead, NULL)) goto fail; if (SetFilePointer(hFile, 2, NULL, FILE_CURRENT) == 0xFFFFFFFF) goto fail; sd->color = sd->color+j-1; sd->Ins = false; store->Add(sd); if (max < sd->color) max = sd->color; } } delete TempPalette; CloseHandle(hFile); if (j < max) MainImageForm->Palette->UseColor = max; Visible = true; StringGrid->Repaint(); ImageDrawing(); ::RepaintColor(); if (store->Count>0) InitialFunc(1); return EC_NONE; fail: if (TempPalette) delete TempPalette; if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_READ; return ec; } //--------------------------------------------------------------------------- TPException __fastcall TStripeForm::STPOnSave(AnsiString DirName, AnsiString FileName, TGraphicFileFormat ExtIndex, TCompressMethod cm) { TEXPIAFILEHEADER tpfh; HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwWrite; int i, ec = EC_NONE; TTexpiaBitmap *tag = NULL; short cnt; PStripeData sd; TRect src; if ((hFile = CreateFile((FullPathName(DirName, FileName)).c_str(), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_CREATE; goto fail; } tpfh.Version = TexVersion('P', 'T', 222); tpfh.CanvasInfor = MainImageForm->CanvasInfor; tpfh.BitsPerPixel = MainImageForm->iMainImage->Bitmap->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; } MakeTexpiaTag(tag, StripeImage->Bitmap, src, 0); if (!SaveToTexpiaFile(hFile, MainImageForm->Palette, tpfh, tag, NULL)) goto fail; 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 = AnsiStrScan(FileName.c_str(), '.'); if (s==NULL) { AnsiString fn = FileName+".stp"; return fn; } else { return FileName; } } //--------------------------------------------------------------------------- void __fastcall TStripeForm::tpsDegClick(TObject *Sender) { tpsDeg->SetFocus(); tpsDeg->SelectAll(); } //--------------------------------------------------------------------------- bool __fastcall TStripeForm::LengthWidth() { double yheght, xwidth, xyDeg, thickness, p, Len; AnsiString thickness1, len1; xyDeg = StrToFloat(tpsDeg->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->Bitmap->Height)return false; if(xwidth > MainImageForm->iMainImage->Bitmap->Width)return false; return true; } //--------------------------------------------------------------------------- void __fastcall TStripeForm::StringGridDblClick(TObject *Sender) { if ((StringGrid->Row > 0) && (StringGrid->Row <= store->Count)) { if ((StringGrid->Col > 2) && (StringGrid->Col <= 4)) { StringGrid->EditorMode = false; } } } //---------------------------------------------------------------------------