On 24 Jul 98 at 11:44, Frederic FAURE wrote: > Hello, > In a C++ programm, i would like to know if a mouse button has been > pushed, and > what is the location (x,y) > of the mouse cursor. > I guess that virtual void TCanvas::HandleInput(const > EEventType button, > Int_t x, Int_t y) > could do that, but i don't succeed to make it work. > > i tried: > > EEventType event; > Int_t px; > Int_t py; > > c->HandleInput(event,px,py); > > cout<<"px="<<px<<endl; > cout<<"py="<<py<<endl; > cout<<"event="<<event<<endl; > > which gives nothing. > > Is there a possibility? Please have a look at http://root.cern.ch/root/HowtoPick.html This means if you create any "abstract" object derived from TObject and apply method Draw() somehow obj->Draw() the pointer to your object will be included into the list of the TPad objects and the method ExecuteMethod(Int_t px, Int_t py) of very your class will be called just the mouse will be moving within TPad. If your DistancetoPrimitive method will "return 0" always then TPad will ALWAYS call veryyourobject->ExecuteEvent(event,px,py) as well. Where the "event" is defined with TButton.h file, px, py are the current mouse position in pixels. (I'd like to mention the "veryyourobject" may have NO real graphical view on the screen at all. i.e. it could be "fantom" object. The last means you do not supply any Paint() method for your class). Just the class as follows will do job for you #include <TObject.h> class Picker: public TObject { public: Int_t DistancetoPrimitive(Int_t px, Int_t py){ return 0;) void ExecuteEvent(Int_t event, Int_t px, Int_t py){ printf( the event %d with px=%d, py=%d has been caught\n" ,event,px,py); } }; Hope this helps, Valery ================================================================= Dr. Valeri Faine (Fine) ------------------- Phone: +1 516 344 7806 Brookhaven National Laboratory FAX : +1 516 344 4206 Bldg. 510A /STAR mailto:fine@bnl.gov Upton, New York, 11973-5000 http://nicewww.cern.ch/~fine USA Dr. Valery Fine Telex : 911621 dubna su ----------- LCTA/Joint Inst.for Nuclear Res. Phone : +7 09621 6 40 80 141980 Dubna, Moscow region Fax : +7 09621 6 51 45 Russia mailto:fine@main1.jinr.dubna.su
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:35 MET