Logo ROOT   6.18/05
Reference Guide
TEveGValuators.cxx
Go to the documentation of this file.
1// @(#)root/eve:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TEveGValuators.h"
13
14#include "TMath.h"
15#include "TGLabel.h"
16#include "TGSlider.h"
17#include "TGDoubleSlider.h"
18
19/** \class TEveGValuatorBase
20\ingroup TEve
21Base class for composite GUI elements for setting of numeric values.
22*/
23
25
26////////////////////////////////////////////////////////////////////////////////
27/// Constructor.
28
30 UInt_t w, UInt_t h, Int_t widgetId) :
31 TGCompositeFrame(p, w, h), TGWidget(widgetId),
32
33 fLabelWidth (0),
34 fAlignRight (kFALSE),
35 fShowSlider (kTRUE),
36
37 fNELength (5),
38 fNEHeight (20),
39
40 fLabel (0)
41{
43}
44
45/** \class TEveGValuator
46\ingroup TEve
47Composite GUI element for single value selection (supports label,
48number-entry and slider).
49*/
50
52
53////////////////////////////////////////////////////////////////////////////////
54/// Constructor.
55
56TEveGValuator::TEveGValuator(const TGWindow *p, const char* title,
57 UInt_t w, UInt_t h, Int_t widgetId) :
58 TEveGValuatorBase(p, title, w, h, widgetId),
59
60 fValue (0),
61 fMin (0),
62 fMax (0),
63
64 fSliderNewLine (kFALSE),
65 fSliderDivs (-1),
66 fEntry (0),
67 fSlider (0)
68{
69}
70
71////////////////////////////////////////////////////////////////////////////////
72/// Create sub-components (label, number entry, slider).
73
75{
76 TGCompositeFrame *hf1, *hfs;
79 hf1 = new TGHorizontalFrame(this);
81 AddFrame(hf1, new TGLayoutHints(kLHintsTop, 0,0,0,0));
82 hfs = new TGHorizontalFrame(this);
84 AddFrame(hfs, new TGLayoutHints(kLHintsTop, 0,0,0,0));
85 } else {
86 hf1 = this;
87 hfs = this;
89 }
90
91 // label
92 {
93 TGLayoutHints *labh, *labfrh;
94 if(fAlignRight) {
95 labh = new TGLayoutHints(kLHintsRight | kLHintsBottom, 0,0,0,0);
96 labfrh = new TGLayoutHints(kLHintsRight);
97 } else {
98 labh = new TGLayoutHints(kLHintsLeft | kLHintsBottom, 0,0,0,0);
99 labfrh = new TGLayoutHints(kLHintsLeft);
100 }
101 TGCompositeFrame *labfr =
104 fLabel = new TGLabel(labfr, fName);
105 labfr->AddFrame(fLabel, labh);
106 hf1->AddFrame(labfr, labfrh);
107 }
108
109 // number-entry
110 TGLayoutHints* elh = new TGLayoutHints(kLHintsLeft, 0,0,0,0);
111 fEntry = new TGNumberEntry(hf1, 0, fNELength);
113 fEntry->GetNumberEntry()->SetToolTipText("Enter Slider Value");
114 hf1->AddFrame(fEntry, elh);
115
116 if (connect)
117 fEntry->Connect("ValueSet(Long_t)",
118 "TEveGValuator", this, "EntryCallback()");
119
120 // slider
121 if(fShowSlider) {
124
125 if (connect)
126 fSlider->Connect("PositionChanged(Int_t)",
127 "TEveGValuator", this, "SliderCallback()");
128 }
129}
130
131////////////////////////////////////////////////////////////////////////////////
132/// Set limits of the represented value.
133
136{
137 fMin = Float_t(min);
138 fMax = Float_t(max);
139 fEntry->SetFormat(nef);
141
142 if(fSlider) {
143 fSliderDivs = npos - 1;
145 }
146}
147
148////////////////////////////////////////////////////////////////////////////////
149/// Set limits of the represented value for integer values.
150
152{
153 fMin = Float_t(min);
154 fMax = Float_t(max);
157
158 if(fSlider) {
159 fSliderDivs = max - min;
161 }
162}
163
164////////////////////////////////////////////////////////////////////////////////
165/// Return slider position for given value.
166
168{
169 return (Int_t) TMath::Nint((v - fMin)*fSliderDivs/(fMax - fMin));
170}
171
172////////////////////////////////////////////////////////////////////////////////
173/// Callback for change in number-entry.
174
176{
178 if(fSlider) {
180 }
182}
183
184////////////////////////////////////////////////////////////////////////////////
185/// Callback for change in slider position.
186
188{
192}
193
194
195////////////////////////////////////////////////////////////////////////////////
196/// Emit "ValueSet(Double_t)" signal.
197
199{
200 Emit("ValueSet(Double_t)", val);
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// Set value, optionally emit signal.
205
207{
208 fValue = val;
210
211 if(fSlider){
213 }
214 if(emit)
215 ValueSet(val);
216}
217
218////////////////////////////////////////////////////////////////////////////////
219/// Set the tooltip of the number-entry.
220
221void TEveGValuator::SetToolTip(const char* tip)
222{
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Set enabled state of the whole widget.
228
230{
232 fEntry->GetButtonUp()->SetEnabled(state);
234 if(fSlider) {
235 if(state) fSlider->MapWindow();
236 else fSlider->UnmapWindow();
237 }
238}
239
240/** \class TEveGDoubleValuator
241\ingroup TEve
242Composite GUI element for selection of range (label, two
243number-entries and double-slider).
244*/
245
247
248////////////////////////////////////////////////////////////////////////////////
249/// Constructor.
250
252 UInt_t w, UInt_t h, Int_t widgetId) :
253 TEveGValuatorBase(p, title, w, h, widgetId),
254
255 fMinEntry(0),
256 fMaxEntry(0),
257 fSlider(0)
258{
259}
260
261////////////////////////////////////////////////////////////////////////////////
262/// Create sub-components (label, number entries, double-slider).
263
265{
266 TGCompositeFrame *hf1, *hfs;
267 if(fShowSlider) {
269 hf1 = new TGHorizontalFrame(this);
272 hfs = new TGHorizontalFrame(this);
275 } else {
276 hf1 = this;
277 hfs = this;
279 }
280
281 // label
282 TGLayoutHints* lh;
283 if(fAlignRight)
284 lh = new TGLayoutHints(kLHintsRight | kLHintsBottom, 4,0,0,0);
285 else
286 lh = new TGLayoutHints(kLHintsLeft | kLHintsBottom, 0,4,0,0);
287
288 if(fLabelWidth > 0) {
290 fLabel = new TGLabel(lf, fName);
291 lf->AddFrame(fLabel, lh);
292 // add label frame to top horizontal frame
293 TGLayoutHints* lfh = new TGLayoutHints(kLHintsLeft, 0,0,0,0);
294 hf1->AddFrame(lf, lfh);
295 } else {
296 fLabel = new TGLabel(hf1, fName);
297 hf1->AddFrame(fLabel, lh);
298 }
299
300 // entries
301 fMinEntry = new TGNumberEntry(hf1, 0, fNELength);
303 fMinEntry->GetNumberEntry()->SetToolTipText("Enter Slider Min Value");
304 hf1->AddFrame(fMinEntry, new TGLayoutHints(kLHintsLeft, 0,0,0,0));
305 if (connect)
306 fMinEntry->Connect("ValueSet(Long_t)",
307 "TEveGDoubleValuator", this, "MinEntryCallback()");
308
309 fMaxEntry = new TGNumberEntry(hf1, 0, fNELength);
311 fMaxEntry->GetNumberEntry()->SetToolTipText("Enter Slider Max Value");
312 hf1->AddFrame(fMaxEntry, new TGLayoutHints(kLHintsLeft, 2,0,0,0));
313 if (connect)
314 fMaxEntry->Connect("ValueSet(Long_t)",
315 "TEveGDoubleValuator", this, "MaxEntryCallback()");
316
317 // slider
318 if(fShowSlider) {
321 if (connect)
322 fSlider->Connect("PositionChanged()",
323 "TEveGDoubleValuator", this, "SliderCallback()");
324 }
325}
326
327////////////////////////////////////////////////////////////////////////////////
328/// Set limits of the represented range for integer values.
329
331{
336
337 if(fSlider) {
338 fSlider->SetRange(min, max);
339 }
340}
341
342////////////////////////////////////////////////////////////////////////////////
343/// Set limits of the represented range.
344
347{
348 // printf("TEveGDoubleValuator::SetLimits(Float_t min, Float_t max, Int_ \n");
350 fMinEntry->SetFormat(nef);
352 fMaxEntry->SetFormat(nef);
353
354 if(fSlider) fSlider->SetRange(min, max);
355}
356
357////////////////////////////////////////////////////////////////////////////////
358/// Callback for change in low number-entry.
359
361{
362 if(GetMin() > GetMax())
365 ValueSet();
366}
367
368////////////////////////////////////////////////////////////////////////////////
369/// Callback for change in high number-entry.
370
372{
373 if(GetMax() < GetMin())
376 ValueSet();
377}
378
379////////////////////////////////////////////////////////////////////////////////
380/// Callback for change in slider position / width.
381
383{
384 Float_t minp, maxp;
385 fSlider->GetPosition(minp, maxp);
386 fMinEntry->SetNumber(minp);
387 fMaxEntry->SetNumber(maxp);
388 ValueSet();
389}
390
391////////////////////////////////////////////////////////////////////////////////
392/// Set min/max values, optionally emit signal.
393
395{
396 fMinEntry->SetNumber(min);
397 fMaxEntry->SetNumber(max);
398
399 if(fSlider) fSlider->SetPosition(min, max);
400 if(emit) ValueSet();
401}
402
403////////////////////////////////////////////////////////////////////////////////
404/// Emit "ValueSet()" signal.
405
407{
408 Emit("ValueSet()");
409}
410
411/** \class TEveGTriVecValuator
412\ingroup TEve
413Composite GUI element for setting three numerical values (label,
414three number-entries). All three values have the same number-format
415and value-range.
416*/
417
419
420////////////////////////////////////////////////////////////////////////////////
421/// Constructor.
422
424 UInt_t w, UInt_t h, Int_t widgetId) :
425 TGCompositeFrame(p, w, h), TGWidget(widgetId),
426
427 fLabelWidth (0),
428 fNELength (5),
429 fNEHeight (20)
430{
431 SetName(name);
432}
433
434////////////////////////////////////////////////////////////////////////////////
435/// Create sub-components (label, number entries).
436
437void TEveGTriVecValuator::Build(Bool_t vertical, const char* lab0, const char* lab1, const char* lab2)
438{
439 if (vertical) SetLayoutManager(new TGVerticalLayout(this));
440 else SetLayoutManager(new TGHorizontalLayout(this));
441
442 const char *labs[3] = { lab0, lab1, lab2 };
443 TGLayoutHints* lh;
444 for (Int_t i=0; i<3; ++i) {
445 fVal[i] = new TEveGValuator(this, labs[i], 10, 0);
450 fVal[i]->Build();
451 fVal[i]->Connect
452 ("ValueSet(Double_t)", "TEveGTriVecValuator", this, "ValueSet()");
453 if (vertical) lh = new TGLayoutHints(kLHintsTop, 1, 1, 1, 1);
454 else lh = new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 1, 1);
455 AddFrame(fVal[i], lh);
456 }
457}
458
459////////////////////////////////////////////////////////////////////////////////
460/// Emit "ValueSet()" signal.
461
463{
464 Emit("ValueSet()");
465}
466
467////////////////////////////////////////////////////////////////////////////////
468/// Set limits for all three number-entries, integer values.
469
471{
472 for (Int_t i=0; i<3; ++i)
473 fVal[i]->SetLimits(min, max);
474}
475
476////////////////////////////////////////////////////////////////////////////////
477/// Set limits for all three number-entries.
478
481{
482 for (Int_t i=0; i<3; ++i)
483 fVal[i]->SetLimits(min, max, 0, nef);
484}
485
SVector< double, 2 > v
Definition: Dict.h:5
PyObject * fValue
#define h(i)
Definition: RSha256.hxx:106
int Int_t
Definition: RtypesCore.h:41
unsigned int UInt_t
Definition: RtypesCore.h:42
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
float Float_t
Definition: RtypesCore.h:53
const Bool_t kTRUE
Definition: RtypesCore.h:87
#define ClassImp(name)
Definition: Rtypes.h:365
@ kDoubleScaleBoth
@ kFixedHeight
Definition: TGFrame.h:67
@ kFixedSize
Definition: TGFrame.h:68
@ kLHintsRight
Definition: TGLayout.h:33
@ kLHintsLeft
Definition: TGLayout.h:31
@ kLHintsBottom
Definition: TGLayout.h:36
@ kLHintsTop
Definition: TGLayout.h:34
@ kLHintsExpandX
Definition: TGLayout.h:37
@ kScaleBoth
Definition: TGSlider.h:62
@ kSlider1
Definition: TGSlider.h:56
char name[80]
Definition: TGX11.cxx:109
Composite GUI element for selection of range (label, two number-entries and double-slider).
void MinEntryCallback()
Callback for change in low number-entry.
Float_t GetMin() const
TGNumberEntry * fMaxEntry
TEveGDoubleValuator(const TEveGDoubleValuator &)
void SetLimits(Int_t min, Int_t max)
Set limits of the represented range for integer values.
void ValueSet()
Emit "ValueSet()" signal.
TGDoubleHSlider * fSlider
Float_t GetMax() const
void MaxEntryCallback()
Callback for change in high number-entry.
void SliderCallback()
Callback for change in slider position / width.
virtual void Build(Bool_t connect=kTRUE)
Create sub-components (label, number entries, double-slider).
TGNumberEntry * fMinEntry
void SetValues(Float_t min, Float_t max, Bool_t emit=kFALSE)
Set min/max values, optionally emit signal.
Composite GUI element for setting three numerical values (label, three number-entries).
TEveGValuator * fVal[3]
void ValueSet()
Emit "ValueSet()" signal.
void SetLimits(Int_t min, Int_t max)
Set limits for all three number-entries, integer values.
void Build(Bool_t vertical, const char *lab0, const char *lab1, const char *lab2)
Create sub-components (label, number entries).
TEveGTriVecValuator(const TEveGTriVecValuator &)
Base class for composite GUI elements for setting of numeric values.
void SetLabelWidth(Int_t w)
void SetNEHeight(Int_t h)
void SetShowSlider(Bool_t s=kTRUE)
void SetNELength(Int_t l)
TEveGValuatorBase(const TEveGValuatorBase &)
Composite GUI element for single value selection (supports label, number-entry and slider).
TGNumberEntry * fEntry
TEveGValuator(const TEveGValuator &)
void ValueSet(Double_t)
Emit "ValueSet(Double_t)" signal.
void SetEnabled(Bool_t state)
Set enabled state of the whole widget.
Int_t CalcSliderPos(Float_t v)
Return slider position for given value.
TGHSlider * fSlider
void SetToolTip(const char *tip)
Set the tooltip of the number-entry.
void SetLimits(Int_t min, Int_t max)
Set limits of the represented value for integer values.
Bool_t fSliderNewLine
virtual void Build(Bool_t connect=kTRUE)
Create sub-components (label, number entry, slider).
void SliderCallback()
Callback for change in slider position.
void EntryCallback()
Callback for change in number-entry.
virtual void SetValue(Float_t v, Bool_t emit=kFALSE)
Set value, optionally emit signal.
virtual void SetEnabled(Bool_t e=kTRUE)
Set enabled or disabled state of button.
Definition: TGButton.cxx:409
virtual void SetLayoutManager(TGLayoutManager *l)
Set the layout manager for the composite frame.
Definition: TGFrame.cxx:982
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1099
virtual void GetPosition(Float_t &min, Float_t &max) const
virtual void SetRange(Float_t min, Float_t max)
virtual void SetPosition(Float_t min, Float_t max)
virtual void MapWindow()
Definition: TGFrame.h:251
UInt_t GetWidth() const
Definition: TGFrame.h:271
virtual void SetHeight(UInt_t h)
Definition: TGFrame.h:294
virtual void UnmapWindow()
Definition: TGFrame.h:253
virtual void SetNumber(Double_t val)
TGNumberEntryField * GetNumberEntry() const
virtual void SetLimits(ELimit limits=TGNumberFormat::kNELNoLimits, Double_t min=0, Double_t max=1)
TGButton * GetButtonDown() const
virtual void SetFormat(EStyle style, EAttribute attr=TGNumberFormat::kNEAAnyNumber)
virtual Double_t GetNumber() const
TGButton * GetButtonUp() const
virtual Int_t GetPosition() const
Definition: TGSlider.h:109
virtual void SetPosition(Int_t pos)
Definition: TGSlider.h:105
virtual void SetRange(Int_t min, Int_t max)
Definition: TGSlider.h:101
void SetEnabled(Bool_t flag=kTRUE)
Definition: TGTextEntry.h:164
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
virtual void SetName(const char *name)
Definition: TGWindow.h:125
TString fName
Definition: TGWindow.h:39
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition: TQObject.h:164
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition: TQObject.cxx:867
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Definition: TMath.h:701