I am trying to draw and drag polygon regions on an canvas using TCutG. I have implemented drawing polygon function by right click mouse, which is shown in the attachment. But I met with some difficulty when I create the drag function. I notice that Root automatically support dragging TCutG object. However, it can only work when you put your cursor on the edge of TCutG polygon. In fact, I want to drag TCutG polygon when the cursor is inside anywhere of the TCutG polygon and the cursor can automatically change to cross.
Any clue would be appreciated! Thank you very much in advance DragPolygon.cpp (2.83 KB)
TCutG is a TGraph. The Dragging is done in the method TGraph::ExecuteEvent.
We cannot change it the way you request because TGraphs are not always closed.
If you need a special dragging method you can overwrite the existing one or create your own class. To know if you are inside the polygon you should use TMath::IsInside(…)
Thank you very much for your prompt reply When I try to call TGraph::ExecuteEvent(kButton1Motion. px, py), the program crashes. But if I assign kButton1Down to event, ExecuteEvent does nothing. How can I use ExecuteEvent correctly?