3 #include "RGValuators.h"
7 #include <TGDoubleSlider.h>
11 /**************************************************************************/
13 /**************************************************************************/
15 ClassImp(RGValuatorBase)
17 RGValuatorBase::RGValuatorBase(const TGWindow *p, const char* name,
19 TGCompositeFrame(p, w, h),
33 /**************************************************************************/
35 /**************************************************************************/
39 RGValuator::RGValuator(const TGWindow *p, const char* title,
41 RGValuatorBase(p, title, w, h),
47 fSliderNewLine (kFALSE),
53 void RGValuator::Build()
55 TGCompositeFrame *hf1, *hfs;
56 if(fShowSlider && fSliderNewLine) {
57 SetLayoutManager(new TGVerticalLayout(this));
58 hf1 = new TGHorizontalFrame(this);
59 hf1->SetLayoutManager(new TGHorizontalLayout(hf1));
60 AddFrame(hf1, new TGLayoutHints(kLHintsTop, 0,0,0,0));
61 hfs = new TGHorizontalFrame(this);
62 hfs->SetLayoutManager(new TGHorizontalLayout(hfs));
63 AddFrame(hfs, new TGLayoutHints(kLHintsTop, 0,0,0,0));
67 SetLayoutManager(new TGHorizontalLayout(this));
73 lh = new TGLayoutHints(kLHintsRight | kLHintsBottom, 0,0,0,0);
75 lh = new TGLayoutHints(kLHintsLeft | kLHintsBottom, 0,0,0,0);
77 if (fLabelWidth > 0) {
78 // printf("fLabelWidth > 0 \n");
79 TGCompositeFrame *lf = new TGHorizontalFrame(hf1, fLabelWidth, fNEHeight, kFixedSize);
80 fLabel = new TGLabel(lf, GetName());
81 lf->AddFrame(fLabel, lh);
82 // add label frame to top horizontal frame
83 TGLayoutHints* lfh = new TGLayoutHints(kLHintsLeft, 0,0,0,0);
84 hf1->AddFrame(lf, lfh);
86 fLabel = new TGLabel(hf1, GetName());
87 hf1->AddFrame(fLabel, lh);
91 TGLayoutHints* elh = new TGLayoutHints(kLHintsLeft, 0,0,0,0);
92 fEntry = new TGNumberEntry(hf1, 0, fNELength);
93 fEntry->SetHeight(fNEHeight);
94 fEntry->GetNumberEntry()->SetToolTipText("Enter Slider Value");
95 hf1->AddFrame(fEntry, elh);
97 fEntry->Associate(this);
98 fEntry->Connect("ValueSet(Long_t)",
99 "Reve::RGValuator", this, "EntryCallback()");
104 fSlider = new TGHSlider(hfs, GetWidth(), kSlider1 | kScaleBoth);
105 hfs->AddFrame(fSlider, new TGLayoutHints(kLHintsLeft, 1,1,0,0));
107 fSlider->Associate(this);
108 fSlider->Connect("PositionChanged(Int_t)",
109 "Reve::RGValuator", this, "SliderCallback()");
113 void RGValuator::SetLimits(Float_t min, Float_t max, Int_t ndiv,
114 TGNumberFormat::EStyle nef)
119 fEntry->SetFormat(nef);
120 fEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
123 void RGValuator::SetLimits(Int_t min, Int_t max)
127 fEntry->SetFormat(TGNumberFormat::kNESInteger);
128 fEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
131 fSlider->SetRange(min, max);
132 fSliderSteps = max - min;
136 void RGValuator::EntryCallback()
138 fValue = fEntry->GetNumber();
141 if (fSliderSteps != -1) {
142 pos = Int_t( fSliderSteps*(fValue - fMin)/(fMax - fMin));
144 pos = Int_t(fValue - fMin);
147 fSlider->SetPosition(pos);
148 // printf( "RGValuator::EntryCallback() slider pos %d n", pos);
153 void RGValuator::SliderCallback()
156 if(fSliderSteps != -1)
157 val = fMin + fSlider->GetPosition()*Double_t((fMax-fMin))/fSliderSteps;
159 val = Double_t(fSlider->GetPosition());
162 fEntry->SetNumber(fValue);
167 void RGValuator::ValueSet(Double_t val)
169 Emit("ValueSet(Double_t)", val);
172 void RGValuator::SetValue(Float_t val, Bool_t emit)
175 fEntry->SetNumber(fValue);
178 fSlider->SetPosition(Int_t((val-fMin)*fSliderSteps/(fMax-fMin)));
179 // printf("RGValuator::ValueSet slider pos %d\n",fSlider->GetPosition() );
185 void RGValuator::SetToolTip(const Text_t* tip)
187 fEntry->GetNumberEntry()->SetToolTipText(tip);
190 void RGValuator::SetEnabled(Bool_t state)
192 fEntry->GetNumberEntry()->SetEnabled(state);
193 fEntry->GetButtonUp()->SetEnabled(state);
194 fEntry->GetButtonDown()->SetEnabled(state);
196 if(state) fSlider->MapWindow();
197 else fSlider->UnmapWindow();
201 /**************************************************************************/
203 /**************************************************************************/
205 ClassImp(RGDoubleValuator)
207 RGDoubleValuator::RGDoubleValuator(const TGWindow *p, const char* title,
208 UInt_t w, UInt_t h) :
209 RGValuatorBase(p, title, w, h),
216 void RGDoubleValuator::Build()
218 TGCompositeFrame *hf1, *hfs;
220 SetLayoutManager(new TGVerticalLayout(this));
221 hf1 = new TGHorizontalFrame(this);
222 hf1->SetLayoutManager(new TGHorizontalLayout(hf1));
223 AddFrame(hf1, new TGLayoutHints(kLHintsTop, 0,0,0,0));
224 hfs = new TGHorizontalFrame(this);
225 hfs->SetLayoutManager(new TGHorizontalLayout(hfs));
226 AddFrame(hfs, new TGLayoutHints(kLHintsTop, 0,0,0,0));
230 SetLayoutManager(new TGHorizontalLayout(this));
236 lh = new TGLayoutHints(kLHintsRight | kLHintsBottom, 0,2,0,0);
238 lh = new TGLayoutHints(kLHintsLeft | kLHintsBottom, 0,2,0,0);
240 if(fLabelWidth > 0) {
241 TGCompositeFrame *lf = new TGHorizontalFrame(hf1, fLabelWidth, fNEHeight, kFixedSize);
242 fLabel = new TGLabel(lf, GetName());
243 lf->AddFrame(fLabel, lh);
244 // add label frame to top horizontal frame
245 TGLayoutHints* lfh = new TGLayoutHints(kLHintsLeft, 0,0,0,0);
246 hf1->AddFrame(lf, lfh);
248 fLabel = new TGLabel(hf1, GetName());
249 hf1->AddFrame(fLabel);
253 fMinEntry = new TGNumberEntry(this, 0, fNELength);
254 fMinEntry->SetHeight(fNEHeight);
255 fMinEntry->GetNumberEntry()->SetToolTipText("Enter Slider Min Value");
256 hf1->AddFrame(fMinEntry, new TGLayoutHints(kLHintsLeft, 0,0,0,0));
257 fMinEntry->Connect("ValueSet(Long_t)",
258 "Reve::RGDoubleValuator", this, "MinEntryCallback()");
259 fMinEntry->Associate(this);
261 fMaxEntry = new TGNumberEntry(this, 0, fNELength);
262 fMaxEntry->SetHeight(fNEHeight);
263 fMaxEntry->GetNumberEntry()->SetToolTipText("Enter Slider Max Value");
264 hf1->AddFrame(fMaxEntry, new TGLayoutHints(kLHintsLeft, 2,0,0,0));
265 fMaxEntry->Connect("ValueSet(Long_t)",
266 "Reve::RGDoubleValuator", this, "MaxEntryCallback()");
267 fMaxEntry->Associate(this);
271 fSlider = new TGDoubleHSlider(hfs, GetWidth(), kDoubleScaleBoth);
272 hfs->AddFrame(fSlider, new TGLayoutHints(kLHintsTop|kLHintsLeft, 0,0,1,0));
273 fSlider->Associate(this);
274 fSlider->Connect("PositionChanged()",
275 "Reve::RGDoubleValuator", this, "SliderCallback()");
279 void RGDoubleValuator::SetLimits(Float_t min, Float_t max,
280 TGNumberFormat::EStyle nef)
282 // printf("RGDoubleValuator::SetLimits(Float_t min, Float_t max, Int_ \n");
283 fMinEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
284 fMinEntry->SetFormat(nef);
285 fMaxEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
286 fMaxEntry->SetFormat(nef);
288 if(fSlider) fSlider->SetRange(min, max);
291 void RGDoubleValuator::MinEntryCallback()
293 if(GetMin() > GetMax())
294 fMaxEntry->SetNumber(GetMin());
295 if(fSlider) fSlider->SetPosition(GetMin(), GetMax());
299 void RGDoubleValuator::MaxEntryCallback()
301 if(GetMax() < GetMin())
302 fMinEntry->SetNumber(GetMax());
303 if(fSlider) fSlider->SetPosition(GetMin(), GetMax());
307 void RGDoubleValuator::SliderCallback()
310 fSlider->GetPosition(minp, maxp);
311 //printf("RGDoubleValuator::SliderCallback %f %f\n", minp, maxp);
312 fMinEntry->SetNumber(minp);
313 fMaxEntry->SetNumber(maxp);
317 void RGDoubleValuator::SetValues(Float_t min, Float_t max, Bool_t emit)
319 fMinEntry->SetNumber(min);
320 fMaxEntry->SetNumber(max);
322 if(fSlider) fSlider->SetPosition(min, max);
326 void RGDoubleValuator::ValueSet()