SliceButtonBar.cxx
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // \file SliceButtonBar.cxx
3 // \brief Controls for navigating between slices
4 // \author Christopher Backhouse - bckhouse@caltech.edu
5 ////////////////////////////////////////////////////////////////////////
6 
8 
9 #include "TGButton.h"
10 #include "TGLabel.h"
11 #include "TGTextEntry.h"
12 #include "TTimer.h"
13 
14 
16 
18 
19 namespace evd
20 {
21  //---------------------------------------------------------------
23  : TGCompositeFrame(p, 60, 20, kSunkenFrame | kHorizontalFrame),
24  fTimer(0)
25  {
27 
28  TGLabel* label = new TGLabel(this, "Slices: ");
29  AddFrame(label, new TGLayoutHints(kLHintsCenterY | kLHintsLeft,
30  0, 0, 5, 1));
31 
32  // Previous slice button
33  fPrevButton = new TGTextButton(this, "<< Previous", 50);
34  fPrevButton->SetToolTipText("Go to previous slice");
35  fPrevButton->Connect("Clicked()",
36  "evd::SliceButtonBar", this, "Previous()");
37  AddFrame(fPrevButton, new TGLayoutHints(kLHintsTop | kLHintsLeft,
38  2, 0, 2, 2));
39 
40  // Next slice button
41  fNextButton = new TGTextButton(this, "Next >>", 50);
42  fNextButton->SetToolTipText("Go to next slice");
43  fNextButton->Connect("Clicked()", "evd::SliceButtonBar", this, "Next()");
44  AddFrame(fNextButton, new TGLayoutHints(kLHintsTop | kLHintsLeft,
45  2, 0, 2, 2));
46 
47  // Auto-advance button
48  fAutoAdvanceButton = new TGTextButton(this, ">", 50);
49  fAutoAdvanceButton->SetToolTipText("Start slice auto advance");
50  fAutoAdvanceButton->Connect("Clicked()", "evd::SliceButtonBar", this, "AutoAdvance()");
51  AddFrame(fAutoAdvanceButton, new TGLayoutHints(kLHintsTop | kLHintsLeft,
52  2, 0, 2, 2));
53 
54  // Slice-by-slice enable button
55  fEnableButton = new TGCheckButton(this, "Slice-by-slice", 0);
56  AddFrame(fEnableButton, new TGLayoutHints(kLHintsCenterY | kLHintsLeft,
57  2, 0, 2, 2));
58  fEnableButton->Connect("Clicked()",
59  "evd::SliceButtonBar", this, "Enable()");
60  fEnableButton->SetState(nav->FullEventMode() ? kButtonUp : kButtonDown);
61 
62  fNSlicesLabel = new TGLabel(this, " / 1 ");
63  AddFrame(fNSlicesLabel, new TGLayoutHints(kLHintsCenterY | kLHintsRight,
64  0, 0, 5, 1));
65 
66  fSliceTextEntry = new TGTextEntry(this, new TGTextBuffer(128));
67  fSliceTextEntry->Connect("ReturnPressed()", "evd::SliceButtonBar",
68  this, "GoTo()");
69  fSliceTextEntry->Resize(50, 20);
70  fSliceTextEntry->SetText(TString::Format("%d", nav->CurrentSlice()));
71  AddFrame(fSliceTextEntry,
72  new TGLayoutHints(kLHintsTop | kLHintsRight, 2, 0, 2, 2));
73 
74  TGLabel* sliceLabel = new TGLabel(this, "[Slice]=");
75  AddFrame(sliceLabel,
76  new TGLayoutHints(kLHintsCenterY | kLHintsRight, 2, 0, 2, 2));
77 
78  // Set everything to the appropriate enabled state
79  Enable();
80  }
81 
82  //---------------------------------------------------------------
84  {
85  delete fPrevButton;
86  delete fNextButton;
87  delete fEnableButton;
88  delete fSliceTextEntry;
89  delete fNSlicesLabel;
90  }
91 
92  //---------------------------------------------------------------
94  {
96  nav->SetFullEventMode(fEnableButton->GetState() == kButtonUp);
97 
98  Update();
99  }
100 
101  //---------------------------------------------------------------
103  {
105  nav->Previous();
106  }
107 
108  //---------------------------------------------------------------
110  {
112  nav->Next();
113  }
114 
115  //---------------------------------------------------------------
117  {
118  this->Next();
119 
121  t->SetTime(nav->fAutoAdvanceInterval);
122 
123  return kTRUE;
124  }
125 
126  //---------------------------------------------------------------
128  {
129  if (fTimer == 0) {
130  //
131  // Start the slice-level auto-advance feature
132  //
133  fAutoAdvanceButton->SetText("X");
134  fTimer = new TTimer;
135  fTimer->SetObject(this);
136 
138  fTimer->Start(nav->fAutoAdvanceInterval);
139  }
140  else {
141  //
142  // Stop the slice-level auto-advance feature
143  //
144  fAutoAdvanceButton->SetText(">");
145  fTimer->Stop();
146  delete fTimer;
147  fTimer = 0;
148  }
149  }
150 
151  //---------------------------------------------------------------
153  {
155  nav->SetCurrentSlice(atoi(fSliceTextEntry->GetText()));
156  }
157 
158  //---------------------------------------------------------------
160  {
162 
163  fSliceTextEntry->SetText(TString::Format("%d", nav->CurrentSlice()));
164  fNSlicesLabel->SetText(TString::Format(" / %d ", nav->MaxSlice()));
165 
166  const bool enable = fEnableButton->GetState() != kButtonUp;
167  fSliceTextEntry->SetEnabled(enable);
168  fPrevButton->SetEnabled(enable);
169  fNextButton->SetEnabled(enable);
170  fAutoAdvanceButton->SetEnabled(enable);
171 
172  if(!enable) fSliceTextEntry->SetText("N/A");
173  }
174 }
Bool_t HandleTimer(TTimer *t)
const char * p
Definition: xmltok.h:285
TTimer * fTimer
Timer to handle slice-level auto-advancing.
TGTextButton * fPrevButton
TGTextButton * fNextButton
const char * label
nova event display
SliceButtonBar(const TGWindow *p)
TGTextEntry * fSliceTextEntry
TGCheckButton * fEnableButton
int fAutoAdvanceInterval
Wait time in milliseconds.
void SetFullEventMode(bool mode)
TGTextButton * fAutoAdvanceButton
Start to auto advance.
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154