GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CollectOn.C
Go to the documentation of this file.
1 
2 
3 void CollectOn()
4 {
5  if ( TVirtualPad::Pad() ) {
6  TCanvas *c = TVirtualPad::Pad()->GetCanvas(); ClickCollector *thecollector = ClickCollector::TheCollector();
7  c->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)","ClickCollector",
8  thecollector,
9  "DoCollect(Int_t,Int_t,Int_t,TObject*)");
10  cout << " - Start collecting clicks in " << c->GetName() << endl ;
11 
12  thecollector->SetMode();
13  }
14  else
15  cout << " - Cannot collect clicks, there is no current pad !!! " << endl ;
16 
17 }
18 
19 #include <RQ_OBJECT.h>
20 
22 {
23 RQ_OBJECT("ClickCollector")
24 
25 private:
26  static ClickCollector *gfCollector; // the click collector
27 
28 private:
29  Int_t fLastPx, fLastPy; // to keep track of the last postion of the mouse in the pad
30  EEventType fCollectMode; // type of event needed to collect
31 
32  TMarker fMarker; // Marker attribute used to draw markers
33 
34  Bool_t fIsActive; // true if collect mode is on
35 
36 private:
38 
39 public:
41 
42  void SetMode(Bool_t mode = true) { fIsActive = mode; }
43  void SetMarker(TMarker m) { fMarker = m; }
44 
45  // the unique collector
46  static ClickCollector * TheCollector();
47 
48  // action to be performed for any events
49  void DoCollect(Int_t event, Int_t px, Int_t py, TObject *obj);
50 };
51 
52 // set statics
53 ClickCollector *ClickCollector::gfCollector = 0;
54 
55 ClickCollector::ClickCollector() : fLastPx(0), fLastPy(0), fCollectMode(kKeyPress), fMarker()
56 {
57  // set marker style for peaks
58  fMarker.SetMarkerStyle(20); fMarker.SetMarkerColor(2); gfCollector = this;
59 }
60 
61 
63 {
64  if ( gfCollector == NULL ) new ClickCollector(); return gfCollector;
65 }
66 
67 
68 void ClickCollector::DoCollect(Int_t event, Int_t px, Int_t py, TObject *obj)
69 {
70  // Collect event.
71  // if event = fCollectMode ( = double click by default ) it adds a "click"
72  // to the list of clicks and displays a TCross at that position.
73 
74  if ( event == kMouseMotion ) { fLastPx = px; fLastPy = py; return; } // keep memory of the last position
75 
76  if ( event == fCollectMode && fIsActive ) {
77  if ( gROOT->GetSelectedPad() ) {
78  fMarker.DrawMarker(gROOT->GetSelectedPad()->AbsPixeltoX(fLastPx),
79  gROOT->GetSelectedPad()->AbsPixeltoY(fLastPy));
80  gROOT->GetSelectedPad()->Update();
81  }
82  }
83 }
84 
85 
86 
87 
88 
void DoCollect(Int_t event, Int_t px, Int_t py, TObject *obj)
Definition: CollectOn.C:68
void SetMode(Bool_t mode=true)
Definition: CollectOn.C:42
static ClickCollector * TheCollector()
Definition: CollectOn.C:62
void SetMarker(TMarker m)
Definition: CollectOn.C:43
void CollectOn()
Definition: CollectOn.C:3
ADF::LogMessage & endl(ADF::LogMessage &log)