Dear all,
I am trying to do something when cliking a TMarker drawn on a canvas.
I wrote the following code based on
http://root.cern.ch/phpBB2/viewtopic.php?t=3527&highlight=mouse+click.
void MyClass::Draw()
{
if (! cm) cm = new TCanvas("cm", "MyClass", 600, 600);
cm->DrawFrame(-150, -150, 150, 150);
cm->SetGrid();
g->Draw("contzsame"); // g is a pointer to a TGraph2D object
for (int i = 0; i < g->GetN(); ++i) {
TMarker *m = new TMarker(g->GetX()[i], g->GetY()[i], 20);
m->SetUniqueID(i);
m->SetMarkerSize(0.8);
m->Draw();
}
cm->Update();
cm->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "MyClass", this,
"DrawProfile(Int_t,Int_t,Int_t,TObject*)");
cm->SetEditable(kFALSE);
}
void MyClass::DrawProfile(Int_t event, Int_t x, Int_t y, TObject *selected)
{
TCanvas *c = (TCanvas *) gTQSender;
if (event == kButton1Down) {
TString objName = selected->IsA()->GetName();
if (objName == "TMarker") {
TMarker *m = (TMarker *) selected;
int iDet = m->GetUniqueID(); // iDet
std::cout << "Marker #: " << iDet << std::endl;
// do something
...
}
}
}
But when another object such as a TLine is also drawn on the canvas overlapping with the markers,
the ProcessedEvent() always recognize a cllicked object as a line and not as a marker.
TMarker::Pop() did not fix this problem.
Is there any way to detect a click on a specific kind of object overlapping with other objects?
Thank you.