#include "TCanvas.h" #include "TLine.h" #include "TMath.h" #include "TH2.h" void DrawLine(Int_t event, Int_t px, Int_t py, TObject *selected) { TCanvas *c = (TCanvas *) gTQSender; TPad *pad = (TPad *) c->GetSelectedPad(); if (! pad) return; static Double_t x0, y0, x1, y1; static Int_t pxold, pyold; static Int_t px0, py0; static Int_t linedrawn; static TLine *line = 0; switch (event) { case kButton1Down: gVirtualX->SetLineColor(-1); x0 = pad->AbsPixeltoX(px); y0 = pad->AbsPixeltoY(py); px0 = px; py0 = py; pxold = px; pyold = py; linedrawn = 0; break; case kButton1Motion: if (linedrawn) gVirtualX->DrawLine(px0, py0, pxold, pyold); pxold = px; pyold = py; linedrawn = 1; gVirtualX->DrawLine(px0, py0, pxold, pyold); break; case kButton1Up: if (px == px0 && py == py0) break; x1 = pad->AbsPixeltoX(px); y1 = pad->AbsPixeltoY(py); pad->Modified(kTRUE); if (pad->GetLogx()) { x0 = TMath::Power(10,x0); x1 = TMath::Power(10,x1); } if (pad->GetLogy()) { y0 = TMath::Power(10,y0); y1 = TMath::Power(10,y1); } if (! line) { line = new TLine(x0,y0,x1,y1); line->Draw(); } else { line->SetX1(x0); line->SetY1(y0); line->SetX2(x1); line->SetY2(y1); // line->Draw(); } // pad->Modified(); pad->Update(); break; } } void test(Option_t *option = "") { TCanvas *c1 = new TCanvas("c1"); TH2F *h0 = new TH2F("h0", "test", 1000, -4, 4, 1000, -4, 4); h0->FillRandom("gaus", 10000); h0->Draw(option); c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", 0, 0, "DrawLine(Int_t,Int_t,Int_t,TObject*)"); }