//--------------------------------------------------------------------------- #include #pragma hdrstop #include "ViewPattern_F.h" #include "Menu3D_F.h" //#include "MainImage.h" // for call function which erase grid..... #include "LogData.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "TPStretchImage" #pragma resource "*.dfm" TPatternForm *PatternForm; //--------------------------------------------------------------------------- __fastcall TPatternForm::TPatternForm(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TPatternForm::FormCreate(TObject *Sender) { shPoint->Brush->Color = MainImageForm->Data3D->PointColor; Bitmap = NULL; zoom = 1; } //--------------------------------------------------------------------------- void __fastcall TPatternForm::FormDestroy(TObject *Sender) { if (Bitmap) { delete Bitmap; Bitmap = NULL; } } //--------------------------------------------------------------------------- void __fastcall TPatternForm::ShowFabric(TPBitmap *pattern) { BEGIN_LOG(""); int ratio, ww = 0, hh = 0, rv = 0; String str; RGBQUAD rgb[256]; TTexpiaBitmap *tmp = NULL; HDC dhDC = NULL, shDC = NULL; // Image->Bitmap = NULL; if (!pattern) { if (Bitmap) { delete Bitmap; Bitmap = NULL; } Image->Bitmap = NULL; END_LOG; return; } if (Bitmap) {delete Bitmap; Bitmap = NULL;} if ((Bitmap = new TTexpiaBitmap) == NULL) goto fail; if ((tmp = new TTexpiaBitmap) == NULL) goto fail; tmp->ColorSpace = csHLS; if (pattern->BitsPerPixel == 8) { if (!tmp->Create(pattern->Width, pattern->Height, 8, rgb)) goto fail; } else { if (!tmp->Create(pattern->Width, pattern->Height, 24)) goto fail; } tmp->LoadFromMemory(pattern->ScanLine(), pattern->BytesPerLine); tmp->ConvertColorSpace(csRGB); switch (zoom) { case 1: ratio = 1; str = "1"; break; case 2: ratio = 2; str = "1/2"; break; case 3: ratio = 4; str = "1/4"; break; case 4: ratio = 8; str = "1/8"; break; case 5: ratio = 16; str = "1/16"; break; } stZoom->Caption = str; ww = tmp->Width/ratio; hh = tmp->Height/ratio; if ( ww == 0 || hh == 0) goto fail; if (pattern->BitsPerPixel == 8) { if (!Bitmap->Create(ww, hh, 8, rgb)) goto fail; } else { if (!Bitmap->Create(ww, hh, 24)) goto fail; } if ((dhDC = Bitmap->CreateDC()) == NULL) goto fail; if ((shDC = tmp->CreateDC()) == NULL) goto fail; if (ratio > 1) { SetStretchBltMode(dhDC, COLORONCOLOR); rv = StretchBlt(dhDC, 0, 0, ww, hh, shDC, 0, 0, tmp->Width, tmp->Height, SRCCOPY); if (rv == 0) ShowMessage("Pattern size is too small or large to zoom in or out!"); } else { BitBlt(dhDC, 0, 0, ww, hh, shDC, 0, 0, SRCCOPY); } tmp->DeleteDC(shDC); Bitmap->DeleteDC(dhDC); delete tmp; Image->Width = ww; Image->Height = hh; Image->Bitmap = Bitmap; Image->Repaint(); StatusBar1->Panels->Items[2]->Text = "Fabric Size :" + IntToStr((int)pattern->Width) + " X " + IntToStr((int)pattern->Height); END_LOG; return; fail: if (tmp) { if (shDC) tmp->DeleteDC(shDC); delete tmp; tmp = NULL; } if (Bitmap) { if (dhDC) Bitmap->DeleteDC(dhDC); delete Bitmap; Bitmap = NULL; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TPatternForm::sbGroupSelectClick(TObject *Sender) { BEGIN_LOG(""); TSpeedButton *sp = (TSpeedButton *)Sender; TData3D *dp = MainImageForm->Data3D; int gpindex; String str; gpindex = Menu3DForm->GetGroupIndex(); if (sp->Tag) { if (gpindex >= 7) gpindex = 0; else gpindex++; } else { if (gpindex <= 0) gpindex = 7; else gpindex--; } if ((dp->GroupList[gpindex].FIndex > 0) && (dp->fn[gpindex].cnt)) { Menu3DForm->SetGroupIndex(gpindex); Menu3DForm->SetGridIndex(dp->fn[gpindex].sn[0]); Menu3DForm->ViewGrid(dp->fn[gpindex].sn[0]); str = "(" + IntToStr((int)(dp->s_point.FP[dp->fn[gpindex].sn[0]].x)) + ", " + IntToStr((int)(dp->s_point.FP[dp->fn[gpindex].sn[0]].y)) + ")"; StatusBar1->Panels->Items[0]->Text = "Select Point : " + str; if (dp->fn[gpindex].cnt > 1) { sbGridNext->Enabled = true; sbGridPre->Enabled = true; } else { sbGridNext->Enabled = false; sbGridPre->Enabled = false; } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TPatternForm::FormCloseQuery(TObject *Sender, bool &CanClose) { BEGIN_LOG(""); if (MainImageForm->iMainImage->OnPaintZoom) { MainImageForm->iMainImage->OnPaintZoom = NULL; MainImageForm->iMainImage->Invalidate(); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TPatternForm::sbGridSelectClick(TObject *Sender) { BEGIN_LOG(""); int gd, gp, index, cnt, k, temp; TSpeedButton *sp = (TSpeedButton *)Sender; TData3D *dp = MainImageForm->Data3D; String str; gp = Menu3DForm->GetGroupIndex(); gd = Menu3DForm->GetGridIndex(); cnt = dp->fn[gp].cnt; if (cnt < 2) { END_LOG; return; } if (sp->Tag) { for (k=0; kfn[gp].sn[k]; if (temp == gd) { if ((k+1) == cnt) { END_LOG; return; } else gd = dp->fn[gp].sn[k+1]; goto next; } } } else { for (k=0; kfn[gp].sn[k]; if (temp == gd) { if (k == 0) { END_LOG; return; } else gd = dp->fn[gp].sn[k-1]; goto next; } } } next: Menu3DForm->SetGridIndex(gd); Menu3DForm->ViewGrid(gd); str = "(" + IntToStr((int)(dp->s_point.FP[dp->fn[gp].sn[gd]].x)) + ", " + IntToStr((int)(dp->s_point.FP[dp->fn[gp].sn[gd]].y)) + ")"; StatusBar1->Panels->Items[0]->Text = "Select Point : " + str; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TPatternForm::ImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { int ratio; switch (zoom) { case 1: ratio = 1; break; case 2: ratio = 2; break; case 3: ratio = 4; break; case 4: ratio = 8; break; case 5: ratio = 16; break; } StatusBar1->Panels->Items[1]->Text = "(" + IntToStr(X*ratio) + ", " + IntToStr(Y*ratio) + ")"; } //--------------------------------------------------------------------------- void __fastcall TPatternForm::ImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { BEGIN_LOG(""); int ratio,gpindex; switch (zoom) { case 1: ratio = 1; break; case 2: ratio = 2; break; case 3: ratio = 4; break; case 4: ratio = 8; break; case 5: ratio = 16; break; } StatusBar1->Panels->Items[0]->Text = "(" + IntToStr(X*ratio) + ", " + IntToStr(Y*ratio) + ")"; MainImageForm->Data3D->s_point.FP[Menu3DForm->GetGridIndex()] = Point(X*ratio, Y*ratio); Image->Repaint(); Draw_s_point(X, Y); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TPatternForm::sbZoomClick(TObject *Sender) { BEGIN_LOG(""); int bzoom, gpindex; TSpeedButton *sp = (TSpeedButton *)Sender; bzoom = zoom; if (sp->Tag) { if (zoom < 5) zoom++; } else { if (zoom > 1) zoom--; } if (bzoom != zoom) { gpindex = StrToInt(stGroupIndex->Caption); ShowFabric(MainImageForm->Data3D->GroupList[gpindex-1].FFabric); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TPatternForm::shPointMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (shPoint->Brush->Color == clRed) { shPoint->Brush->Color = clBlue; } else if (shPoint->Brush->Color == clBlue) { shPoint->Brush->Color = clYellow; } else if (shPoint->Brush->Color == clYellow) { shPoint->Brush->Color = clFuchsia; } else if (shPoint->Brush->Color == clFuchsia) { shPoint->Brush->Color = clGreen; } else if (shPoint->Brush->Color == clGreen) { shPoint->Brush->Color = clBlack; } else { shPoint->Brush->Color = clRed; } MainImageForm->Data3D->PointColor = shPoint->Brush->Color; MainImageForm->iMainImage->Invalidate(); } //--------------------------------------------------------------------------- void __fastcall TPatternForm::Draw_s_point(int X,int Y) { BEGIN_LOG(""); HDC DC=Image->Canvas->Handle; HPEN hOldPen = NULL, hPen = NULL; hPen = CreatePen(PS_SOLID, 2, shPoint->Brush->Color); hOldPen = (HPEN)SelectObject(DC, hPen); MoveToEx(DC, X, Y-5, NULL); LineTo(DC, X, Y+5); MoveToEx(DC, X-5, Y, NULL); LineTo(DC, X+5, Y); SelectObject(DC, hOldPen); DeleteObject(hPen); END_LOG; } //---------------------------------------------------------------------------