//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "capture.h" #include "Main_F.h" #include "Viewer.h" #include "Design.h" #include "Palette.h" #include "jpeg.hpp" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_CAPTURE StringTable[0] #define IDS_ZOOM StringTable[1] #define IDS_WHOLE_VIEWER StringTable[2] #define IDS_LOAD_IMAGE StringTable[3] #define IDS_SAVE_IMAGE StringTable[4] #define IDS_TYPE StringTable[5] #define IDS_POSITION StringTable[6] #define IDS_LENGTH StringTable[7] #define IDS_UNDO StringTable[8] #define IDS_MEASURE StringTable[9] #define IDS_GRID StringTable[10] #define IDS_SET StringTable[11] #define IDS_GRID_MOVE StringTable[12] #define IDS_PATH StringTable[13] //--------------------------------------------------------------------------- TCaptureForm *CaptureForm; //--------------------------------------------------------------------------- __fastcall TCaptureForm::TCaptureForm(TComponent* Owner) : TForm(Owner) { lpgrid=NULL; gridx=0; gridy=0; ImageGraphicObjectList= new TList; temp_path = new TList; view_path=false; } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::sbCaptureClick(TObject *Sender) { if(view_path){ show_path(); view_path=false; } if(hWndC==NULL){ pmLoadImage->Enabled=false; pmSaveImage->Enabled=false; pmViewer->Enabled=false; //ImageManagerForm->Visible=false; if(Image->Cursor==crCross) Image->Cursor = crDefault; try{ TCursor cursor = Screen->Cursor; Screen->Cursor = crHourGlass; CAPDRIVERCAPS CapDriverCaps; CAPSTATUS CapStatus; HANDLE hwndParent = this->Handle; hWndC = capCreateCaptureWindow ( (PROGRAM_NAME + " Capture Window").c_str(), WS_CHILD | WS_VISIBLE , ImageScrollBox->Left+2, ImageScrollBox->Top+2, ImageScrollBox->Width-4, ImageScrollBox->Height-4, hwndParent, 0); RECT r; GetWindowRect(hWndC,&r); Image->Width=(r.right-r.left); Image->Height=(r.bottom-r.top); Image->Picture->Bitmap->Width=Image->Width; Image->Picture->Bitmap->Height=Image->Height; Image->Picture->Bitmap->Canvas->Brush->Color = clGray; Image->Picture->Bitmap->Canvas->FillRect(Image->ClientRect); ResetObjectList(); UpdateLabel(); if(lpgrid){ VirtualUnlock(lpgrid,gridx*gridy*sizeof(POINT)); VirtualFree(lpgrid,gridx*gridy*sizeof(POINT),MEM_DECOMMIT); lpgrid=NULL; gridx=0; gridy=0; } rgObjectType->Enabled=false; gbObject->Enabled=false; sbUndo->Enabled=false; lbPosition->Enabled=false; lbLength->Enabled=false; gbGrid->Enabled=false; edWale->Enabled=false; edCourse->Enabled=false; sbSet->Enabled=false; sbGridMove->Enabled=false; sbPath->Enabled=false; spGridColor->Enabled=false; ImageScrollBox->VertScrollBar->Visible=false; ImageScrollBox->HorzScrollBar->Visible=false; capDriverConnect (hWndC, 0); capDriverGetCaps(hWndC, &CapDriverCaps, sizeof (CAPDRIVERCAPS)); Screen->Cursor = cursor; if (CapDriverCaps.fHasDlgVideoSource) capDlgVideoSource(hWndC); if (CapDriverCaps.fHasDlgVideoFormat) { capDlgVideoFormat(hWndC); //BITMAPINFO VideoFormat; //capGetVideoFormat(hWndC,&VideoFormat,sizeof(BITMAPINFO)); //VideoFormat.bmiHeader.biWidth=320; //VideoFormat.bmiHeader.biHeight=240; //capSetVideoFormat(hWndC,&VideoFormat,sizeof(BITMAPINFO)); //capGetStatus(hWndC, &CapStatus, sizeof (CAPSTATUS)); //SetWindowPos(hWndC, NULL, 0, 0, CapStatus.uiImageWidth, // CapStatus.uiImageHeight, SWP_NOZORDER | SWP_NOMOVE); } //capPreviewScale(hWndC,true); //TPoint pt = TPoint(0,0); //capSetScrollPos(hWndC,&pt); capOverlay(hWndC,false); capPreviewRate(hWndC, 66); // rate, in milliseconds capPreview(hWndC, TRUE); // starts preview } catch(...){ if(hWndC){ capPreview(hWndC, FALSE); capDriverDisconnect (hWndC); DestroyWindow(hWndC); hWndC=NULL; } } } else { capPreview(hWndC, FALSE); capDriverDisconnect (hWndC); RECT r; GetWindowRect(hWndC,&r); Image->Width=(r.right-r.left); Image->Height=(r.bottom-r.top); Image->Picture->Bitmap->Width=Image->Width; Image->Picture->Bitmap->Height=Image->Height; HDC hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL); BitBlt(Image->Canvas->Handle, 0,0, Image->Width, Image->Height, hdcScreen, r.left,r.top, SRCCOPY); DeleteDC(hdcScreen); DestroyWindow(hWndC); hWndC=NULL; pmLoadImage->Enabled=true; pmSaveImage->Enabled=true; pmViewer->Enabled=true; rgObjectType->Enabled=true; gbObject->Enabled=true; sbUndo->Enabled=true; lbPosition->Enabled=true; lbLength->Enabled=true; gbGrid->Enabled=true; edWale->Enabled=true; edCourse->Enabled=true; sbSet->Enabled=true; sbGridMove->Enabled=true; sbPath->Enabled=true; spGridColor->Enabled=true; if(sbMeasure->Down){ rgObjectType->Visible=true; gbObject->Visible=true; gbGrid->Visible=false; spGridColor->Visible=false; } else { rgObjectType->Visible=false; gbObject->Visible=false; gbGrid->Visible=true; spGridColor->Visible=true; } } ImageScrollBox->VertScrollBar->Visible=true; ImageScrollBox->HorzScrollBar->Visible=true; ImageScrollBox->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::pmViewerClick(TObject *Sender) { if(Image->Height==0||Image->Width==0)return; Viewer_F->Width = Image->Width+6; Viewer_F->Height = Image->Height+25; Viewer_F->Image->Width=Image->Width; Viewer_F->Image->Height=Image->Height; Viewer_F->Image->Picture->Bitmap->Width=Image->Width; Viewer_F->Image->Picture->Bitmap->Height=Image->Height; HDC hDC = Viewer_F->Image->Canvas->Handle; BitBlt(hDC,0,0,Viewer_F->Width,Viewer_F->Height,Image->Canvas->Handle,0,0,SRCCOPY); Viewer_F->Show(); Viewer_F->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::pmLoadImageClick(TObject *Sender) { if (OpenPictureDialog->Execute()) { if(OpenPictureDialog->FilterIndex==1){ Graphics::TBitmap *bm = new Graphics::TBitmap; bm->LoadFromFile(OpenPictureDialog->FileName); Image->Height = bm->Height; Image->Width = bm->Width; Image->Picture->Bitmap->Assign(bm); Image->Repaint(); if(bm) delete bm; } else if(OpenPictureDialog->FilterIndex==2){ TJPEGImage *jp = new TJPEGImage(); try { jp->LoadFromFile(OpenPictureDialog->FileName); Image->Height = jp->Height; Image->Width = jp->Width; Image->Picture->Bitmap->Assign(jp); Image->Repaint(); } __finally { delete jp; } } } ResetObjectList(); UpdateLabel(); if(lpgrid){ VirtualUnlock(lpgrid,gridx*gridy*sizeof(POINT)); VirtualFree(lpgrid,gridx*gridy*sizeof(POINT),MEM_DECOMMIT); lpgrid=NULL; gridx=0; gridy=0; } } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::pmSaveImageClick(TObject *Sender) { if (SavePictureDialog->Execute()) { if(SavePictureDialog->FilterIndex==1){ Image->Picture->Bitmap->SaveToFile(SavePictureDialog->FileName); } else if(SavePictureDialog->FilterIndex==2){ TJPEGImage *jp = new TJPEGImage(); try { jp->Assign(Image->Picture->Bitmap); jp->SaveToFile(SavePictureDialog->FileName); } __finally { delete jp; } } } } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::FormCreate(TObject *Sender) { hWndC=NULL; SetFont(); StringTable.Create(BaseDir, Language, "Capture"); Caption=IDS_CAPTURE; pmZoom->Caption=IDS_ZOOM; pmViewer->Caption=IDS_WHOLE_VIEWER; pmLoadImage->Caption=IDS_LOAD_IMAGE; pmSaveImage->Caption=IDS_SAVE_IMAGE; //rgObjectType->Caption=IDS_TYPE; rgObjectType->Items->Clear(); rgObjectType->Items->Add(IDS_POSITION); rgObjectType->Items->Add(IDS_LENGTH); rgObjectType->ItemIndex=0; sbUndo->Caption = IDS_UNDO; sbMeasure->Caption = IDS_MEASURE; sbGrid->Caption = IDS_GRID; //gbGrid->Caption = IDS_GRID; sbSet->Caption = IDS_SET; sbGridMove->Caption = IDS_GRID_MOVE; sbPath->Caption = IDS_PATH; grid_step=0; Image->Width=0; Image->Height=0; OpenPictureDialog->InitialDir=BaseDir+"\\bmp"; OpenPictureDialog->DefaultExt = "bmp"; OpenPictureDialog->FileName = "*.bmp"; OpenPictureDialog->Filter="Bitmaps (*.bmp)|*.bmp|JPEG Image File (*.jpg)|*.jpg"; SavePictureDialog->InitialDir=BaseDir+"\\bmp"; SavePictureDialog->DefaultExt = "bmp"; SavePictureDialog->FileName = "Noname1"; SavePictureDialog->Filter="Bitmaps (*.bmp)|*.bmp|JPEG Image File (*.jpg)|*.jpg"; } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::FormDestroy(TObject *Sender) { if(ImageGraphicObjectList){ while(ImageGraphicObjectList->Count){ delete (graphicobject *)ImageGraphicObjectList->Last(); ImageGraphicObjectList->Remove(ImageGraphicObjectList->Last()); } delete ImageGraphicObjectList; ImageGraphicObjectList=NULL; } if(hWndC){ capPreview(hWndC, FALSE); capDriverDisconnect (hWndC); DestroyWindow(hWndC); hWndC=NULL; } if(lpgrid){ VirtualUnlock(lpgrid,gridx*gridy*sizeof(POINT)); VirtualFree(lpgrid,gridx*gridy*sizeof(POINT),MEM_DECOMMIT); lpgrid=NULL; } while(temp_path->Count){ KO *ko=(KO *)temp_path->Last(); delete ko; temp_path->Remove(ko); } delete temp_path; } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::ImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if(sbCapture->Down){ return; } else if(sbMeasure->Down){ int default_point_size=5; int default_line_dot=1; int default_font_size=10; Image->Picture->Bitmap->Canvas->Font->Size=default_font_size; if(!Shift.Contains(ssLeft))return; if(!Image->Picture->Bitmap->Empty){ //if(ImageManagerForm->Visible){ TCanvas *canvas = Image->Picture->Bitmap->Canvas; switch(rgObjectType->ItemIndex) { case 0: { Draw_Add_Object(canvas, X-default_point_size, Y-default_point_size, X+default_point_size, Y+default_point_size, POINTTYPE, ""); UpdateLabel(); Image->Repaint(); break; } case 1: { graphicobject *go = NULL; if(ImageGraphicObjectList->Count) go = (graphicobject *)ImageGraphicObjectList->Items[ImageGraphicObjectList->Count-1]; if(ImageGraphicObjectList->Count&&go->got==STRINGTYPE){ DeleteLastObject(Image->Picture->Bitmap->Canvas); DeleteLastObject(Image->Picture->Bitmap->Canvas); } else { Draw_Add_Object(canvas, X, Y, X, Y, LINETYPE, ""); Draw_Add_Object(canvas, X, Y, X, Y, STRINGTYPE, "0"); } Image->Repaint(); break; } default: Image->Repaint(); break; } //} } } else { if(sbGridMove->Down){ pt=FindNearestPoint(X,Y); if(pt.x==-1) { grid_step=0; return; } if(grid_step==0)grid_step=1; else if(grid_step==1)grid_step=0; //POINT *p2=(POINT *)lpgrid+(gridx*j+i); } else { pt=FindNearestPoint(X,Y); if(pt.x==-1) return; Tex *tex=(Tex *)Main->texlayer->TexList->Items[Main->LayerNum]; KO *ko=(KO *)tex->Curve->Items[(gridy-1-pt.y)%tex->Curve->Count]; int x=gridx-1-pt.x; if(ko->via==x){ ko->in=x; ko->via=x+1; } else { ko->in=x+1; ko->via=x; } tex->Correction(); update_path(); DesignForm->DrawChart(); } } } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::ImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if(sbCapture->Down){ return; } else if(sbMeasure->Down){ int default_point_size=5; int default_line_dot=1; int default_font_size=10; Image->Picture->Bitmap->Canvas->Font->Size=default_font_size; if(Shift.Contains(ssLeft))return; if(!Image->Picture->Bitmap->Empty){ //if(ImageManagerForm->Visible){ TCanvas *canvas = Image->Picture->Bitmap->Canvas; switch(rgObjectType->ItemIndex) { case 0: { Image->Repaint(); break; } case 1: { graphicobject *go = NULL; if(ImageGraphicObjectList->Count) go = (graphicobject *)ImageGraphicObjectList->Items[ImageGraphicObjectList->Count-1]; if(ImageGraphicObjectList->Count&&go->got==STRINGTYPE){ go = (graphicobject *)ImageGraphicObjectList->Items[ImageGraphicObjectList->Count-2]; DrawObject(canvas, go->x, go->y, go->x2, go->y2, LINETYPE, ""); go->x2=X; go->y2=Y; DrawObject(canvas, go->x, go->y, go->x2, go->y2, LINETYPE, ""); go = (graphicobject *)ImageGraphicObjectList->Items[ImageGraphicObjectList->Count-1]; DrawObject(canvas, go->x, go->y, go->x2, go->y2, STRINGTYPE, go->string); go->x=X; go->y=Y; go->string=MyFloatToStr( sqrt((go->x2-go->x)*(go->x2-go->x)+(go->y2-go->y)*(go->y2-go->y)), 2 ); DrawObject(canvas, go->x, go->y, go->x2, go->y2, STRINGTYPE, go->string); lbLength->Caption=go->string; } else { } Image->Repaint(); break; } default: Image->Repaint(); break; } //} } } else { if(sbGridMove->Down){ if(grid_step==1){ POINT *p=(POINT *)lpgrid+(gridx*pt.y+pt.x); if(p){ TCanvas *canvas = Image->Picture->Bitmap->Canvas; if((pt.x==0&&pt.y==0)||(pt.x==0&&pt.y==gridy-1)||(pt.x==gridx-1&&pt.y==0)||(pt.x==gridx-1&&pt.y==gridy-1)){ for(int i=0;iPen->Mode = pmNot; canvas->Ellipse(p2->x-5,p2->y-5,p2->x+5,p2->y+5); } } p->x=X; p->y=Y; POINT *p11=(POINT *)lpgrid+(gridx*0+0); POINT *p21=(POINT *)lpgrid+(gridx*0+gridx-1); POINT *p12=(POINT *)lpgrid+(gridx*(gridy-1)+0); POINT *p22=(POINT *)lpgrid+(gridx*(gridy-1)+gridx-1); for(int i=0;ix*(gridx-1-i)+p21->x*(i))/(gridx-1); double x1222=(p12->x*(gridx-1-i)+p22->x*(i))/(gridx-1); double x=(x1121*(gridy-1-j)+x1222*(j))/(gridy-1); double y1121=(p11->y*(gridx-1-i)+p21->y*(i))/(gridx-1); double y1222=(p12->y*(gridx-1-i)+p22->y*(i))/(gridx-1); double y=(y1121*(gridy-1-j)+y1222*(j))/(gridy-1); POINT *p2=(POINT *)lpgrid+(gridx*j+i); p2->x=x; p2->y=y; } } for(int i=0;iPen->Mode = pmNot; canvas->Ellipse(p2->x-5,p2->y-5,p2->x+5,p2->y+5); } } } else { canvas->Pen->Mode = pmNot; canvas->Ellipse(p->x-5,p->y-5,p->x+5,p->y+5); p->x=X; p->y=Y; canvas->Pen->Mode = pmNot; canvas->Ellipse(p->x-5,p->y-5,p->x+5,p->y+5); } } } } else { } } } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::Draw_Add_Object(TCanvas *canvas, int X, int Y, int X2, int Y2, GRAPHICOBJECTTYPE type, AnsiString s){ DrawObject(canvas,X,Y,X2,Y2,type,s); AddObject(X,Y,X2,Y2,type,s); } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::DrawObject(TCanvas *canvas, int X, int Y, int X2, int Y2, GRAPHICOBJECTTYPE type, AnsiString s){ switch(type){ // ±×¸²À» ±×¸² case POINTTYPE: { canvas->Pen->Mode = pmNot; canvas->Ellipse(X,Y,X2,Y2); break; } case LINETYPE: { canvas->Pen->Mode = pmNot; canvas->MoveTo(X,Y); canvas->LineTo(X2,Y2); break; } case STRINGTYPE: { canvas->CopyMode = cmSrcInvert; Graphics::TBitmap *bm = new Graphics::TBitmap; bm->Assign(NULL); bm->Height = canvas->TextHeight(s); bm->Width = canvas->TextWidth(s); bm->Canvas->Brush->Color = clBlack; bm->Canvas->Font->Color = clWhite; bm->Canvas->Font->Size=canvas->Font->Size; bm->Canvas->TextOut(0,0,s); canvas->Draw(X,Y,bm); delete bm; break; } default: break; } } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::AddObject(int X, int Y, int X2, int Y2, GRAPHICOBJECTTYPE type, AnsiString s){ graphicobject *go = new graphicobject; // µ¥ÀÌÅ͸¦ ´õÇÔ go->x=X; go->y=Y; go->x2=X2; go->y2=Y2; go->got = type; go->string = s; ImageGraphicObjectList->Add(go); } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::DeleteAllObject(TCanvas *canvas){ // µ¥ÀÌÅÍ¿Í ±×¸²À» Áö¿ò if(ImageGraphicObjectList){ while(ImageGraphicObjectList->Count){ graphicobject *go = (graphicobject *)ImageGraphicObjectList->Last(); DrawObject(canvas, go->x, go->y, go->x2, go->y2, go->got, go->string); delete go; ImageGraphicObjectList->Remove(ImageGraphicObjectList->Last()); } } } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::DeleteLastObject(TCanvas *canvas){ // µ¥ÀÌÅÍ¿Í ±×¸²À» Áö¿ò if(ImageGraphicObjectList->Count){ graphicobject *go = (graphicobject *)ImageGraphicObjectList->Last(); DrawObject(canvas, go->x, go->y, go->x2, go->y2, go->got, go->string); delete go; ImageGraphicObjectList->Remove(ImageGraphicObjectList->Last()); } } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::ResetObjectList(){ // µ¥ÀÌÅ͸¦ Áö¿ò if(ImageGraphicObjectList){ while(ImageGraphicObjectList->Count){ graphicobject *go = (graphicobject *)ImageGraphicObjectList->Last(); delete go; ImageGraphicObjectList->Remove(ImageGraphicObjectList->Last()); } } } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::sbUndoClick(TObject *Sender) { DeleteLastObject(Image->Picture->Bitmap->Canvas); UpdateLabel(); } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::UpdateLabel(){ graphicobject *go; int count=0; for(int i=0;iCount;i++){ go = (graphicobject *)ImageGraphicObjectList->Items[i]; if(go->got==POINTTYPE) count++; } lbPosition->Caption = count; } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::OnChangeSize(){ int h=ClientHeight; int w=ClientWidth; int var=(w-4-366); gbGrid->Left=rgObjectType->Left; gbGrid->Top=rgObjectType->Top; gbGrid->Width=366+var; gbObject->Width=191+var; pnMode->Width=328+var; sbMeasure->Left=168+var; sbGrid->Left=248+var; sbUndo->Left=111+var; sbGridMove->Left=206+var; sbPath->Left=286+var; ImageScrollBox->Left=2; ImageScrollBox->Top=gbGrid->Top+gbGrid->Height+4; ImageScrollBox->Height=h-ImageScrollBox->Top-4; ImageScrollBox->Width=w-4; ImageScrollBox->HorzScrollBar->Position=0; ImageScrollBox->VertScrollBar->Position=0; Image->Top=0; Image->Left=0; } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::FormResize(TObject *Sender) { OnChangeSize(); } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::SetFont(){ SetSmallFont(Font); } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::sbSetClick(TObject *Sender) { reset_grid(true); } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::sbMeasureClick(TObject *Sender) { if(view_path){ show_path(); view_path=false; } if(sbCapture->Down){ sbCaptureClick(NULL); sbCapture->Down=false; } rgObjectType->Visible=true; gbObject->Visible=true; gbGrid->Visible=false; spGridColor->Visible=false; } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::sbGridClick(TObject *Sender) { if(sbCapture->Down){ sbCaptureClick(NULL); sbCapture->Down=false; } if(sbGridMove->Down){ if(view_path){ show_path(); view_path=false; } } else { if(view_path==false){ show_path(); view_path=true; } } if(ImageGraphicObjectList->Count){ graphicobject *go = (graphicobject *)ImageGraphicObjectList->Last(); if(go->got==STRINGTYPE){ DrawObject(Image->Picture->Bitmap->Canvas, go->x, go->y, go->x2, go->y2, go->got, go->string); delete go; ImageGraphicObjectList->Remove(ImageGraphicObjectList->Last()); } go = (graphicobject *)ImageGraphicObjectList->Last(); if(go->got==LINETYPE){ DrawObject(Image->Picture->Bitmap->Canvas, go->x, go->y, go->x2, go->y2, go->got, go->string); delete go; ImageGraphicObjectList->Remove(ImageGraphicObjectList->Last()); } } rgObjectType->Visible=false; gbObject->Visible=false; gbGrid->Visible=true; spGridColor->Visible=true; } //--------------------------------------------------------------------------- POINT __fastcall TCaptureForm::FindNearestPoint(int &X, int &Y){ POINT p=Point(-1,-1),*p2=NULL; if(lpgrid){ double r=-1,r2=0; for(int i=0;ix-X)*(p2->x-X)+(p2->y-Y)*(p2->y-Y); } else { r2=(p2->x-X)*(p2->x-X)+(p2->y-Y)*(p2->y-Y); if(r>r2){ r=r2; p=Point(i,j); } } } } } return p; } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::ImageMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if(sbCapture->Down){ return; } else if(sbMeasure->Down){ } else { if(sbGridMove->Down){ if(grid_step==1){ grid_step=0; } } else { } } } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::sbPathClick(TObject *Sender) { if(lpgrid&&view_path==false){ Tex *tex=(Tex *)Main->texlayer->TexList->Items[Main->LayerNum]; while(tex->Curve->Count>temp_path->Count){ KO *ko=new KO; *ko=*(KO *)tex->Curve->Items[temp_path->Count]; temp_path->Add(ko); } while(tex->Curve->CountCount){ KO *ko=(KO *)temp_path->Last(); delete ko; temp_path->Remove(ko); } for(int i=0;iCount;i++){ KO *ko1=(KO *)tex->Curve->Items[i]; KO *ko2=(KO *)temp_path->Items[i]; *ko2=*ko1; } show_path(); view_path=true; } } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::show_path(){ TCanvas *canvas = Image->Picture->Bitmap->Canvas; for(int j=0;jItems[j%temp_path->Count]; int x=min(ko->in,ko->via); if(x>=gridx||x<0)continue; POINT *p=(POINT *)lpgrid+gridx*((gridy-1-j)%gridy)+(gridx-1-x); //canvas->Pen->Mode = pmNot; //canvas->Ellipse(p->x-7,p->y-7,p->x+7,p->y+7); KO *ko2=(KO *)temp_path->Items[(j+1)%temp_path->Count]; int x2=min(ko2->in,ko2->via); if(x2>=gridx||x2<0)continue; POINT *p2=(POINT *)lpgrid+gridx*((gridy-1-(j+1))%gridy)+(gridx-1-x2); canvas->Pen->Mode = pmNot; canvas->Pen->Width=10; canvas->MoveTo(p->x,p->y); canvas->LineTo(p2->x,p2->y); canvas->Pen->Width=1; } } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::sbGridMoveClick(TObject *Sender) { if(view_path){ show_path(); view_path=false; } } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::update_path(){ if(view_path){ show_path(); Tex *tex=(Tex *)Main->texlayer->TexList->Items[Main->LayerNum]; while(tex->Curve->Count>temp_path->Count){ KO *ko=new KO; *ko=*(KO *)tex->Curve->Items[temp_path->Count]; temp_path->Add(ko); } while(tex->Curve->CountCount){ KO *ko=(KO *)temp_path->Last(); delete ko; temp_path->Remove(ko); } for(int i=0;iCount;i++){ KO *ko1=(KO *)tex->Curve->Items[i]; KO *ko2=(KO *)temp_path->Items[i]; *ko2=*ko1; } show_path(); } } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::edWaleKeyPress(TObject *Sender, char &Key) { if(Key!=VK_RETURN) return; reset_grid(false); edCourse->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::edCourseKeyPress(TObject *Sender, char &Key) { if(Key!=VK_RETURN) return; reset_grid(false); } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::reset_grid(bool init_pos){ if(view_path){ show_path(); } bool exist=false; POINT p11,p12,p21,p22; TCanvas *canvas = Image->Picture->Bitmap->Canvas; if(lpgrid){ exist=true; p11=*((POINT *)lpgrid+(gridx*0+0)); p21=*((POINT *)lpgrid+(gridx*0+gridx-1)); p12=*((POINT *)lpgrid+(gridx*(gridy-1)+0)); p22=*((POINT *)lpgrid+(gridx*(gridy-1)+gridx-1)); for(int i=0;iPen->Mode = pmNot; canvas->Ellipse(p->x-5,p->y-5,p->x+5,p->y+5); } } VirtualUnlock(lpgrid,gridx*gridy*sizeof(POINT)); VirtualFree(lpgrid,gridx*gridy*sizeof(POINT),MEM_DECOMMIT); lpgrid=NULL; } gridx=StrToInt(edWale->Text); gridy=StrToInt(edCourse->Text); if(gridx<2||gridy<2){ edWale->Text="2";edCourse->Text="2"; gridx=2;gridy=2; } lpgrid = VirtualAlloc(NULL,gridx*gridy*sizeof(POINT),MEM_COMMIT,PAGE_READWRITE); if(lpgrid) VirtualLock(lpgrid,gridx*gridy*sizeof(POINT)); if(init_pos||exist==false){ for(int i=0;ix=20+i*(ImageScrollBox->Width-40)/gridx; p->y=20+j*(ImageScrollBox->Height-40)/gridy; } } } else { for(int i=0;ix=x; p2->y=y; } } } for(int i=0;iPen->Mode = pmNot; canvas->Ellipse(p->x-5,p->y-5,p->x+5,p->y+5); } } if(view_path){ show_path(); } } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::FormShow(TObject *Sender) { static bool first=true; if(first){ POINT p=Main->ClientToScreen(Point(0,0)); Top=p.y+2; Height=(Main->ClientHeight-6)/2; Left=p.x+2; Width=(Main->ClientWidth-209-6)/2; } first=false; } //--------------------------------------------------------------------------- void __fastcall TCaptureForm::spGridColorMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if(!Shift.Contains(ssLeft))return; TColor c; PaletteForm->Visible=true; PaletteForm->InitForm(PaletteForm->Palette);//visible »óÅ¿¡¼­ ÃʱâÈ­ÇØ¾ß ½ºÅ©·Ñ¹Ù°¡ ¿òÁ÷¿©Áø´Ù PaletteForm->Visible=false; if(PaletteForm->ShowModal()==mrOk){ spGridColor->Brush->Color=PaletteForm->DIB256Palette->FGColor; } } //---------------------------------------------------------------------------