void TestDialog::HandleEmbeddedCanvas(Int_t event, Int_t x, Int_t y, TObject *sel) { // Handle events in the left embedded canvas. bool DragMoveFlag = false; m_sel = sel; if(fHpxpy){ if (event == kButton3Down){ printf("event = %d, x = %d, y = %d, obj = %s::%s\n", event, x, y, sel->IsA()->GetName(), sel->GetName()); Region[ActRegion]->SetLineColor(kRed); Region[ActRegion]->SetMarkerColor(kRed); if(RegionSet(x, y)){ printf("Now we can update next plot!\n"); iPoints = 0; iReg++; } } if (event == kButton1Double){ if(iPoints>1){ CloseRegion(); printf("Draw Next region!\n"); iPoints = 0; iReg++; } else printf("No double click. Less than three points!"); } if (event == kButton1Down) {//Root can automatically handle dragging only when cursor is on the edge of Polygon DragMoveFlag = SelectRegion(0,x,y); printf("Current selected object is %s::%s\n", m_sel->IsA()->GetName(), m_sel->GetName()); } if (event == kButton1Up) { //Handle Drag and Move Region. if( CalDragDist(0, x, y)){ } } if (DragMoveFlag && event == kMouseMotion) { printf("Drag Move\n"); } } } bool TestDialog::CalDragDist(int iLoc, int x, int y){ double eX = 0, eY = 0; // End Point double dX = 0, dY = 0; double pX = 0, pY = 0; if(iReg > 0 && fMouseUp) { iCanvas = iLoc; fCanvas[iCanvas]->cd(); ParseXY(x, y, eX, eY); dX = DragPointX - eX; dY = DragPointY - eY; if(dX == 0.0 && dY ==0.0){ return false; } int N = Region[ActRegion]->GetN(); for(int i=0; iGetPoint(i, pX, pY); Region[ActRegion]->SetPoint(i, pX-dX, pY-dY); } Region[ActRegion]->Draw("LP"); fMouseUp = false; fCanvas[iCanvas]->Modified(); fCanvas[iCanvas]->Update(); return true; } return false; } bool TestDialog::SelectRegion(int iLoc, int x, int y){ bool InRegion = false; char CurObjName[20]; iCanvas = iLoc; fCanvas[iCanvas]->cd(); ParseXY(x, y, DragPointX, DragPointY); for(int i=0; i<=(iReg-1); i++){ InRegion = Region[i]->IsInside(DragPointX, DragPointY); if(InRegion) { if( ActRegion != i ) { Region[ActRegion]->SetLineColor(kRed); Region[ActRegion]->SetMarkerColor(kRed); ActRegion = i; //Current active region fCanvas[iCanvas]->Modified(); fCanvas[iCanvas]->Update(); } Region[ActRegion]->SetLineColor(kGreen); Region[ActRegion]->SetMarkerColor(kYellow); sprintf(CurObjName,"CUT%d",ActRegion+1); if(m_sel){ if(!strstr(m_sel->GetName(), CurObjName)){ m_sel->Clear(); m_sel = gPad->GetPrimitive(CurObjName); printf("Selected is %s\n", m_sel->GetName()); } } fMouseUp = true; break; } } if(!InRegion){ fMouseUp = false; Region[ActRegion]->SetLineColor(kRed); Region[ActRegion]->SetMarkerColor(kRed); } printf("Delete pointer\n"); return fMouseUp; }