Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
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
24
25////////////////////////////////////////////////////////////////////////////////
26/// Constructor.
27
29 UInt_t w, UInt_t h, Int_t widgetId) :
30 TGCompositeFrame(p, w, h), TGWidget(widgetId),
31
32 fLabelWidth (0),
35
36 fNELength (5),
37 fNEHeight (20),
38
39 fLabel (nullptr)
40{
42}
43
44/** \class TEveGValuator
45\ingroup TEve
46Composite GUI element for single value selection (supports label,
47number-entry and slider).
48*/
49
50
51////////////////////////////////////////////////////////////////////////////////
52/// Constructor.
53
54TEveGValuator::TEveGValuator(const TGWindow *p, const char* title,
55 UInt_t w, UInt_t h, Int_t widgetId) :
56 TEveGValuatorBase(p, title, w, h, widgetId),
57
58 fValue (0),
59 fMin (0),
60 fMax (0),
61
63 fSliderDivs (-1),
64 fEntry (nullptr),
65 fSlider (nullptr)
66{
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// Create sub-components (label, number entry, slider).
71
73{
74 TGCompositeFrame *hf1, *hfs;
77 hf1 = new TGHorizontalFrame(this);
79 AddFrame(hf1, new TGLayoutHints(kLHintsTop, 0,0,0,0));
80 hfs = new TGHorizontalFrame(this);
82 AddFrame(hfs, new TGLayoutHints(kLHintsTop, 0,0,0,0));
83 } else {
84 hf1 = this;
85 hfs = this;
87 }
88
89 // label
90 {
91 TGLayoutHints *labh, *labfrh;
92 if(fAlignRight) {
93 labh = new TGLayoutHints(kLHintsRight | kLHintsBottom, 0,0,0,0);
94 labfrh = new TGLayoutHints(kLHintsRight);
95 } else {
96 labh = new TGLayoutHints(kLHintsLeft | kLHintsBottom, 0,0,0,0);
97 labfrh = new TGLayoutHints(kLHintsLeft);
98 }
99 TGCompositeFrame *labfr =
102 fLabel = new TGLabel(labfr, fName);
103 labfr->AddFrame(fLabel, labh);
104 hf1->AddFrame(labfr, labfrh);
105 }
106
107 // number-entry
108 TGLayoutHints* elh = new TGLayoutHints(kLHintsLeft, 0,0,0,0);
109 fEntry = new TGNumberEntry(hf1, 0, fNELength);
110 fEntry->SetHeight(fNEHeight);
111 fEntry->GetNumberEntry()->SetToolTipText("Enter Slider Value");
112 hf1->AddFrame(fEntry, elh);
113
114 if (connect)
115 fEntry->Connect("ValueSet(Long_t)",
116 "TEveGValuator", this, "EntryCallback()");
117
118 // slider
119 if(fShowSlider) {
122
123 if (connect)
124 fSlider->Connect("PositionChanged(Int_t)",
125 "TEveGValuator", this, "SliderCallback()");
126 }
127}
128
129////////////////////////////////////////////////////////////////////////////////
130/// Set limits of the represented value.
131
134{
135 fMin = Float_t(min);
136 fMax = Float_t(max);
137 fEntry->SetFormat(nef);
138 fEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
139
140 if(fSlider) {
141 fSliderDivs = npos - 1;
142 fSlider->SetRange(0, fSliderDivs);
143 }
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// Set limits of the represented value for integer values.
148
150{
151 fMin = Float_t(min);
152 fMax = Float_t(max);
154 fEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
155
156 if(fSlider) {
157 fSliderDivs = max - min;
158 fSlider->SetRange(0, fSliderDivs);
159 }
160}
161
162////////////////////////////////////////////////////////////////////////////////
163/// Return slider position for given value.
164
169
170////////////////////////////////////////////////////////////////////////////////
171/// Callback for change in number-entry.
172
174{
175 fValue = fEntry->GetNumber();
176 if(fSlider) {
177 fSlider->SetPosition(CalcSliderPos(fValue));
178 }
180}
181
182////////////////////////////////////////////////////////////////////////////////
183/// Callback for change in slider position.
184
186{
187 fValue = fMin + fSlider->GetPosition()*(fMax-fMin)/fSliderDivs;
188 fEntry->SetNumber(fValue);
190}
191
192
193////////////////////////////////////////////////////////////////////////////////
194/// Emit "ValueSet(Double_t)" signal.
195
197{
198 Emit("ValueSet(Double_t)", val);
199}
200
201////////////////////////////////////////////////////////////////////////////////
202/// Set value, optionally emit signal.
203
205{
206 fValue = val;
207 fEntry->SetNumber(fValue);
208
209 if(fSlider){
210 fSlider->SetPosition(CalcSliderPos(fValue));
211 }
212 if(emit)
213 ValueSet(val);
214}
215
216////////////////////////////////////////////////////////////////////////////////
217/// Set the tooltip of the number-entry.
218
219void TEveGValuator::SetToolTip(const char* tip)
220{
221 fEntry->GetNumberEntry()->SetToolTipText(tip);
222}
223
224////////////////////////////////////////////////////////////////////////////////
225/// Set enabled state of the whole widget.
226
228{
229 fEntry->GetNumberEntry()->SetEnabled(state);
230 fEntry->GetButtonUp()->SetEnabled(state);
231 fEntry->GetButtonDown()->SetEnabled(state);
232 if(fSlider) {
233 if(state) fSlider->MapWindow();
234 else fSlider->UnmapWindow();
235 }
236}
237
238/** \class TEveGDoubleValuator
239\ingroup TEve
240Composite GUI element for selection of range (label, two
241number-entries and double-slider).
242*/
243
244
245////////////////////////////////////////////////////////////////////////////////
246/// Constructor.
247
249 UInt_t w, UInt_t h, Int_t widgetId) :
250 TEveGValuatorBase(p, title, w, h, widgetId),
251
252 fMinEntry(nullptr),
253 fMaxEntry(nullptr),
254 fSlider(nullptr)
255{
256}
257
258////////////////////////////////////////////////////////////////////////////////
259/// Create sub-components (label, number entries, double-slider).
260
262{
263 TGCompositeFrame *hf1, *hfs;
264 if(fShowSlider) {
266 hf1 = new TGHorizontalFrame(this);
269 hfs = new TGHorizontalFrame(this);
272 } else {
273 hf1 = this;
274 hfs = this;
276 }
277
278 // label
279 TGLayoutHints* lh;
280 if(fAlignRight)
281 lh = new TGLayoutHints(kLHintsRight | kLHintsBottom, 4,0,0,0);
282 else
283 lh = new TGLayoutHints(kLHintsLeft | kLHintsBottom, 0,4,0,0);
284
285 if(fLabelWidth > 0) {
287 fLabel = new TGLabel(lf, fName);
288 lf->AddFrame(fLabel, lh);
289 // add label frame to top horizontal frame
290 TGLayoutHints* lfh = new TGLayoutHints(kLHintsLeft, 0,0,0,0);
291 hf1->AddFrame(lf, lfh);
292 } else {
293 fLabel = new TGLabel(hf1, fName);
294 hf1->AddFrame(fLabel, lh);
295 }
296
297 // entries
298 fMinEntry = new TGNumberEntry(hf1, 0, fNELength);
299 fMinEntry->SetHeight(fNEHeight);
300 fMinEntry->GetNumberEntry()->SetToolTipText("Enter Slider Min Value");
301 hf1->AddFrame(fMinEntry, new TGLayoutHints(kLHintsLeft, 0,0,0,0));
302 if (connect)
303 fMinEntry->Connect("ValueSet(Long_t)",
304 "TEveGDoubleValuator", this, "MinEntryCallback()");
305
306 fMaxEntry = new TGNumberEntry(hf1, 0, fNELength);
307 fMaxEntry->SetHeight(fNEHeight);
308 fMaxEntry->GetNumberEntry()->SetToolTipText("Enter Slider Max Value");
309 hf1->AddFrame(fMaxEntry, new TGLayoutHints(kLHintsLeft, 2,0,0,0));
310 if (connect)
311 fMaxEntry->Connect("ValueSet(Long_t)",
312 "TEveGDoubleValuator", this, "MaxEntryCallback()");
313
314 // slider
315 if(fShowSlider) {
318 if (connect)
319 fSlider->Connect("PositionChanged()",
320 "TEveGDoubleValuator", this, "SliderCallback()");
321 }
322}
323
324////////////////////////////////////////////////////////////////////////////////
325/// Set limits of the represented range for integer values.
326
328{
329 fMinEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
331 fMaxEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
333
334 if(fSlider) {
335 fSlider->SetRange(min, max);
336 }
337}
338
339////////////////////////////////////////////////////////////////////////////////
340/// Set limits of the represented range.
341
344{
345 // printf("TEveGDoubleValuator::SetLimits(Float_t min, Float_t max, Int_ \n");
346 fMinEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
347 fMinEntry->SetFormat(nef);
348 fMaxEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
349 fMaxEntry->SetFormat(nef);
350
351 if(fSlider) fSlider->SetRange(min, max);
352}
353
354////////////////////////////////////////////////////////////////////////////////
355/// Callback for change in low number-entry.
356
358{
359 if(GetMin() > GetMax())
360 fMaxEntry->SetNumber(GetMin());
361 if(fSlider) fSlider->SetPosition(GetMin(), GetMax());
362 ValueSet();
363}
364
365////////////////////////////////////////////////////////////////////////////////
366/// Callback for change in high number-entry.
367
369{
370 if(GetMax() < GetMin())
371 fMinEntry->SetNumber(GetMax());
372 if(fSlider) fSlider->SetPosition(GetMin(), GetMax());
373 ValueSet();
374}
375
376////////////////////////////////////////////////////////////////////////////////
377/// Callback for change in slider position / width.
378
380{
381 Float_t minp, maxp;
382 fSlider->GetPosition(minp, maxp);
383 fMinEntry->SetNumber(minp);
384 fMaxEntry->SetNumber(maxp);
385 ValueSet();
386}
387
388////////////////////////////////////////////////////////////////////////////////
389/// Set min/max values, optionally emit signal.
390
392{
393 fMinEntry->SetNumber(min);
394 fMaxEntry->SetNumber(max);
395
396 if(fSlider) fSlider->SetPosition(min, max);
397 if(emit) ValueSet();
398}
399
400////////////////////////////////////////////////////////////////////////////////
401/// Emit "ValueSet()" signal.
402
404{
405 Emit("ValueSet()");
406}
407
408/** \class TEveGTriVecValuator
409\ingroup TEve
410Composite GUI element for setting three numerical values (label,
411three number-entries). All three values have the same number-format
412and value-range.
413*/
414
415
416////////////////////////////////////////////////////////////////////////////////
417/// Constructor.
418
420 UInt_t w, UInt_t h, Int_t widgetId) :
421 TGCompositeFrame(p, w, h), TGWidget(widgetId),
422
423 fLabelWidth (0),
424 fNELength (5),
425 fNEHeight (20)
426{
427 SetName(name);
428}
429
430////////////////////////////////////////////////////////////////////////////////
431/// Create sub-components (label, number entries).
432
433void TEveGTriVecValuator::Build(Bool_t vertical, const char* lab0, const char* lab1, const char* lab2)
434{
435 if (vertical) SetLayoutManager(new TGVerticalLayout(this));
436 else SetLayoutManager(new TGHorizontalLayout(this));
437
438 const char *labs[3] = { lab0, lab1, lab2 };
439 TGLayoutHints* lh;
440 for (Int_t i=0; i<3; ++i) {
441 fVal[i] = new TEveGValuator(this, labs[i], 10, 0);
442 fVal[i]->SetLabelWidth(fLabelWidth);
443 fVal[i]->SetShowSlider(kFALSE);
444 fVal[i]->SetNELength(fNELength);
445 fVal[i]->SetNEHeight(fNEHeight);
446 fVal[i]->Build();
447 fVal[i]->Connect
448 ("ValueSet(Double_t)", "TEveGTriVecValuator", this, "ValueSet()");
449 if (vertical) lh = new TGLayoutHints(kLHintsTop, 1, 1, 1, 1);
450 else lh = new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 1, 1);
451 AddFrame(fVal[i], lh);
452 }
453}
454
455////////////////////////////////////////////////////////////////////////////////
456/// Emit "ValueSet()" signal.
457
459{
460 Emit("ValueSet()");
461}
462
463////////////////////////////////////////////////////////////////////////////////
464/// Set limits for all three number-entries, integer values.
465
467{
468 for (Int_t i=0; i<3; ++i)
469 fVal[i]->SetLimits(min, max);
470}
471
472////////////////////////////////////////////////////////////////////////////////
473/// Set limits for all three number-entries.
474
477{
478 for (Int_t i=0; i<3; ++i)
479 fVal[i]->SetLimits(min, max, 0, nef);
480}
481
@ kFixedHeight
Definition GuiTypes.h:390
@ kFixedSize
Definition GuiTypes.h:391
#define h(i)
Definition RSha256.hxx:106
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
Definition RtypesCore.h:60
bool Bool_t
Boolean (0=false, 1=true) (bool).
Definition RtypesCore.h:77
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kDoubleScaleBoth
@ kLHintsRight
Definition TGLayout.h:26
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsBottom
Definition TGLayout.h:29
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
@ kScaleBoth
Definition TGSlider.h:36
@ kSlider1
Definition TGSlider.h:30
char name[80]
Definition TGX11.cxx:148
void MinEntryCallback()
Callback for change in low number-entry.
Float_t GetMin() const
TGNumberEntry * fMaxEntry
void Build(Bool_t connect=kTRUE) override
Create sub-components (label, number entries, double-slider).
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.
TGNumberEntry * fMinEntry
void SetValues(Float_t min, Float_t max, Bool_t emit=kFALSE)
Set min/max values, optionally emit signal.
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 &)
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 Build(Bool_t connect=kTRUE) override
Create sub-components (label, number entry, slider).
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
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 SetLayoutManager(TGLayoutManager *l)
Set the layout manager for the composite frame.
Definition TGFrame.cxx:992
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1109
TGCompositeFrame(const TGCompositeFrame &)=delete
Dragging the slider will generate the event:
UInt_t GetWidth() const
Definition TGFrame.h:226
Concrete class for horizontal slider.
Definition TGSlider.h:119
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:387
This class handles GUI labels.
Definition TGLabel.h:24
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
TGNumberEntry is a number entry input widget with up/down buttons.
@ kNESInteger
Style of number entry field.
@ kNELLimitMinMax
Both lower and upper limits.
TGWidget(const TGWidget &tgw)
Definition TGWidget.h:51
ROOT GUI Window base class.
Definition TGWindow.h:23
virtual void SetName(const char *name)
Definition TGWindow.h:121
TGWindow(Window_t id)
Definition TGWindow.h:34
TString fName
name of the window used in SavePrimitive()
Definition TGWindow.h:30
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition TQObject.h:164
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Definition TMath.h:704