]>
Commit | Line | Data |
---|---|---|
5987168b | 1 | // $Header$ |
2 | ||
3 | #include "RGValuators.h" | |
4 | ||
5 | #include <TGLabel.h> | |
6 | #include <TGSlider.h> | |
7 | #include <TGDoubleSlider.h> | |
8 | ||
9 | using namespace Reve; | |
10 | ||
11 | /**************************************************************************/ | |
12 | // RGValuatorBase | |
13 | /**************************************************************************/ | |
14 | ||
15 | ClassImp(RGValuatorBase) | |
16 | ||
17 | RGValuatorBase::RGValuatorBase(const TGWindow *p, const char* name, | |
18 | UInt_t w, UInt_t h) : | |
19 | TGCompositeFrame(p, w, h), | |
20 | ||
21 | fLabelWidth (0), | |
22 | fAlignRight (kFALSE), | |
23 | fShowSlider (kTRUE), | |
24 | ||
25 | fNELength (5), | |
26 | fNEHeight (20), | |
27 | ||
28 | fLabel (0) | |
29 | { | |
30 | SetName(name); | |
31 | } | |
32 | ||
33 | /**************************************************************************/ | |
34 | // RGValuator | |
35 | /**************************************************************************/ | |
36 | ||
37 | ClassImp(RGValuator) | |
38 | ||
39 | RGValuator::RGValuator(const TGWindow *p, const char* title, | |
40 | UInt_t w, UInt_t h) : | |
41 | RGValuatorBase(p, title, w, h), | |
42 | ||
43 | fValue (0), | |
44 | fMin (0), | |
45 | fMax (0), | |
46 | ||
47 | fSliderNewLine (kFALSE), | |
20d5c75e | 48 | fSliderDivs (-1), |
5987168b | 49 | fEntry (0), |
50 | fSlider (0) | |
51 | {} | |
52 | ||
65b5c50a | 53 | void RGValuator::Build(Bool_t connect) |
5987168b | 54 | { |
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)); | |
64 | } else { | |
65 | hf1 = this; | |
66 | hfs = this; | |
67 | SetLayoutManager(new TGHorizontalLayout(this)); | |
68 | } | |
69 | ||
70 | // label | |
20d5c75e | 71 | { |
72 | TGLayoutHints *labh, *labfrh; | |
73 | if(fAlignRight) { | |
74 | labh = new TGLayoutHints(kLHintsRight | kLHintsBottom, 4,0,0,0); | |
75 | labfrh = new TGLayoutHints(kLHintsRight); | |
76 | } else { | |
77 | labh = new TGLayoutHints(kLHintsLeft | kLHintsBottom, 0,4,0,0); | |
78 | labfrh = new TGLayoutHints(kLHintsLeft); | |
79 | } | |
80 | TGCompositeFrame *labfr = | |
81 | new TGHorizontalFrame(hf1, fLabelWidth, fNEHeight, | |
82 | fLabelWidth != 0 ? kFixedSize : kFixedHeight); | |
83 | fLabel = new TGLabel(labfr, GetName()); | |
84 | labfr->AddFrame(fLabel, labh); | |
85 | hf1->AddFrame(labfr, labfrh); | |
5987168b | 86 | } |
87 | ||
65b5c50a | 88 | // number-entry |
78cd2dc1 | 89 | TGLayoutHints* elh = new TGLayoutHints(kLHintsLeft, 0,0,0,0); |
5987168b | 90 | fEntry = new TGNumberEntry(hf1, 0, fNELength); |
91 | fEntry->SetHeight(fNEHeight); | |
92 | fEntry->GetNumberEntry()->SetToolTipText("Enter Slider Value"); | |
93 | hf1->AddFrame(fEntry, elh); | |
94 | ||
65b5c50a | 95 | fEntry->Associate(this); |
96 | if (connect) | |
97 | fEntry->Connect("ValueSet(Long_t)", | |
98 | "Reve::RGValuator", this, "EntryCallback()"); | |
5987168b | 99 | |
5987168b | 100 | // slider |
101 | if(fShowSlider) { | |
102 | fSlider = new TGHSlider(hfs, GetWidth(), kSlider1 | kScaleBoth); | |
20d5c75e | 103 | hfs->AddFrame(fSlider, new TGLayoutHints(kLHintsLeft|kLHintsTop, 1,1,0,0)); |
5987168b | 104 | |
105 | fSlider->Associate(this); | |
65b5c50a | 106 | if (connect) |
107 | fSlider->Connect("PositionChanged(Int_t)", | |
108 | "Reve::RGValuator", this, "SliderCallback()"); | |
5987168b | 109 | } |
110 | } | |
111 | ||
20d5c75e | 112 | void RGValuator::SetLimits(Float_t min, Float_t max, Int_t npos, |
5987168b | 113 | TGNumberFormat::EStyle nef) |
114 | { | |
115 | fMin = Float_t(min); | |
116 | fMax = Float_t(max); | |
5987168b | 117 | fEntry->SetFormat(nef); |
118 | fEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max); | |
20d5c75e | 119 | |
120 | if(fSlider) { | |
121 | fSliderDivs = npos - 1; | |
122 | fSlider->SetRange(0, fSliderDivs); | |
123 | } | |
5987168b | 124 | } |
125 | ||
126 | void RGValuator::SetLimits(Int_t min, Int_t max) | |
127 | { | |
128 | fMin = Float_t(min); | |
129 | fMax = Float_t(max); | |
130 | fEntry->SetFormat(TGNumberFormat::kNESInteger); | |
131 | fEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max); | |
132 | ||
20d5c75e | 133 | if(fSlider) { |
134 | fSliderDivs = max - min; | |
135 | fSlider->SetRange(0, fSliderDivs); | |
5987168b | 136 | } |
137 | } | |
138 | ||
20d5c75e | 139 | Int_t RGValuator::CalcSliderPos(Float_t v) |
140 | { | |
141 | return (Int_t) TMath::Nint((v - fMin)*fSliderDivs/(fMax - fMin)); | |
142 | } | |
143 | ||
5987168b | 144 | void RGValuator::EntryCallback() |
145 | { | |
146 | fValue = fEntry->GetNumber(); | |
147 | if(fSlider) { | |
20d5c75e | 148 | fSlider->SetPosition(CalcSliderPos(fValue)); |
5987168b | 149 | } |
150 | ValueSet(fValue); | |
151 | } | |
152 | ||
153 | void RGValuator::SliderCallback() | |
154 | { | |
20d5c75e | 155 | fValue = fMin + fSlider->GetPosition()*(fMax-fMin)/fSliderDivs; |
5987168b | 156 | fEntry->SetNumber(fValue); |
157 | ValueSet(fValue); | |
158 | } | |
159 | ||
160 | ||
161 | void RGValuator::ValueSet(Double_t val) | |
162 | { | |
163 | Emit("ValueSet(Double_t)", val); | |
164 | } | |
165 | ||
166 | void RGValuator::SetValue(Float_t val, Bool_t emit) | |
167 | { | |
168 | fValue = val; | |
169 | fEntry->SetNumber(fValue); | |
170 | ||
171 | if(fSlider){ | |
20d5c75e | 172 | fSlider->SetPosition(CalcSliderPos(fValue)); |
5987168b | 173 | } |
174 | if(emit) | |
175 | ValueSet(val); | |
176 | } | |
177 | ||
178 | void RGValuator::SetToolTip(const Text_t* tip) | |
179 | { | |
180 | fEntry->GetNumberEntry()->SetToolTipText(tip); | |
181 | } | |
182 | ||
78cd2dc1 | 183 | void RGValuator::SetEnabled(Bool_t state) |
184 | { | |
185 | fEntry->GetNumberEntry()->SetEnabled(state); | |
186 | fEntry->GetButtonUp()->SetEnabled(state); | |
187 | fEntry->GetButtonDown()->SetEnabled(state); | |
188 | if(fSlider) { | |
189 | if(state) fSlider->MapWindow(); | |
190 | else fSlider->UnmapWindow(); | |
191 | } | |
192 | } | |
193 | ||
5987168b | 194 | /**************************************************************************/ |
195 | // RGDoubleValuator | |
196 | /**************************************************************************/ | |
197 | ||
198 | ClassImp(RGDoubleValuator) | |
199 | ||
200 | RGDoubleValuator::RGDoubleValuator(const TGWindow *p, const char* title, | |
201 | UInt_t w, UInt_t h) : | |
202 | RGValuatorBase(p, title, w, h), | |
203 | ||
204 | fMinEntry(0), | |
205 | fMaxEntry(0), | |
206 | fSlider(0) | |
207 | {} | |
208 | ||
65b5c50a | 209 | void RGDoubleValuator::Build(Bool_t connect) |
5987168b | 210 | { |
211 | TGCompositeFrame *hf1, *hfs; | |
212 | if(fShowSlider) { | |
213 | SetLayoutManager(new TGVerticalLayout(this)); | |
214 | hf1 = new TGHorizontalFrame(this); | |
215 | hf1->SetLayoutManager(new TGHorizontalLayout(hf1)); | |
216 | AddFrame(hf1, new TGLayoutHints(kLHintsTop, 0,0,0,0)); | |
217 | hfs = new TGHorizontalFrame(this); | |
218 | hfs->SetLayoutManager(new TGHorizontalLayout(hfs)); | |
219 | AddFrame(hfs, new TGLayoutHints(kLHintsTop, 0,0,0,0)); | |
220 | } else { | |
221 | hf1 = this; | |
222 | hfs = this; | |
223 | SetLayoutManager(new TGHorizontalLayout(this)); | |
224 | } | |
225 | ||
226 | // label | |
227 | TGLayoutHints* lh; | |
228 | if(fAlignRight) | |
3b7a1af7 | 229 | lh = new TGLayoutHints(kLHintsRight | kLHintsBottom, 4,0,0,0); |
5987168b | 230 | else |
3b7a1af7 | 231 | lh = new TGLayoutHints(kLHintsLeft | kLHintsBottom, 0,4,0,0); |
5987168b | 232 | |
233 | if(fLabelWidth > 0) { | |
234 | TGCompositeFrame *lf = new TGHorizontalFrame(hf1, fLabelWidth, fNEHeight, kFixedSize); | |
235 | fLabel = new TGLabel(lf, GetName()); | |
236 | lf->AddFrame(fLabel, lh); | |
237 | // add label frame to top horizontal frame | |
238 | TGLayoutHints* lfh = new TGLayoutHints(kLHintsLeft, 0,0,0,0); | |
239 | hf1->AddFrame(lf, lfh); | |
240 | } else { | |
241 | fLabel = new TGLabel(hf1, GetName()); | |
3b7a1af7 | 242 | hf1->AddFrame(fLabel, lh); |
5987168b | 243 | } |
244 | ||
245 | // entries | |
246 | fMinEntry = new TGNumberEntry(this, 0, fNELength); | |
247 | fMinEntry->SetHeight(fNEHeight); | |
248 | fMinEntry->GetNumberEntry()->SetToolTipText("Enter Slider Min Value"); | |
78cd2dc1 | 249 | hf1->AddFrame(fMinEntry, new TGLayoutHints(kLHintsLeft, 0,0,0,0)); |
65b5c50a | 250 | if (connect) |
251 | fMinEntry->Connect("ValueSet(Long_t)", | |
252 | "Reve::RGDoubleValuator", this, "MinEntryCallback()"); | |
5987168b | 253 | fMinEntry->Associate(this); |
254 | ||
255 | fMaxEntry = new TGNumberEntry(this, 0, fNELength); | |
256 | fMaxEntry->SetHeight(fNEHeight); | |
257 | fMaxEntry->GetNumberEntry()->SetToolTipText("Enter Slider Max Value"); | |
258 | hf1->AddFrame(fMaxEntry, new TGLayoutHints(kLHintsLeft, 2,0,0,0)); | |
65b5c50a | 259 | if (connect) |
260 | fMaxEntry->Connect("ValueSet(Long_t)", | |
261 | "Reve::RGDoubleValuator", this, "MaxEntryCallback()"); | |
5987168b | 262 | fMaxEntry->Associate(this); |
263 | ||
264 | // slider | |
265 | if(fShowSlider) { | |
266 | fSlider = new TGDoubleHSlider(hfs, GetWidth(), kDoubleScaleBoth); | |
267 | hfs->AddFrame(fSlider, new TGLayoutHints(kLHintsTop|kLHintsLeft, 0,0,1,0)); | |
268 | fSlider->Associate(this); | |
65b5c50a | 269 | if (connect) |
270 | fSlider->Connect("PositionChanged()", | |
271 | "Reve::RGDoubleValuator", this, "SliderCallback()"); | |
5987168b | 272 | } |
273 | } | |
274 | ||
275 | void RGDoubleValuator::SetLimits(Float_t min, Float_t max, | |
276 | TGNumberFormat::EStyle nef) | |
277 | { | |
278 | // printf("RGDoubleValuator::SetLimits(Float_t min, Float_t max, Int_ \n"); | |
279 | fMinEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max); | |
280 | fMinEntry->SetFormat(nef); | |
281 | fMaxEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max); | |
282 | fMaxEntry->SetFormat(nef); | |
283 | ||
284 | if(fSlider) fSlider->SetRange(min, max); | |
285 | } | |
286 | ||
287 | void RGDoubleValuator::MinEntryCallback() | |
288 | { | |
289 | if(GetMin() > GetMax()) | |
290 | fMaxEntry->SetNumber(GetMin()); | |
291 | if(fSlider) fSlider->SetPosition(GetMin(), GetMax()); | |
292 | ValueSet(); | |
293 | } | |
294 | ||
295 | void RGDoubleValuator::MaxEntryCallback() | |
296 | { | |
297 | if(GetMax() < GetMin()) | |
298 | fMinEntry->SetNumber(GetMax()); | |
299 | if(fSlider) fSlider->SetPosition(GetMin(), GetMax()); | |
300 | ValueSet(); | |
301 | } | |
302 | ||
303 | void RGDoubleValuator::SliderCallback() | |
304 | { | |
305 | Float_t minp, maxp; | |
306 | fSlider->GetPosition(minp, maxp); | |
307 | //printf("RGDoubleValuator::SliderCallback %f %f\n", minp, maxp); | |
308 | fMinEntry->SetNumber(minp); | |
309 | fMaxEntry->SetNumber(maxp); | |
310 | ValueSet(); | |
311 | } | |
312 | ||
313 | void RGDoubleValuator::SetValues(Float_t min, Float_t max, Bool_t emit) | |
314 | { | |
315 | fMinEntry->SetNumber(min); | |
316 | fMaxEntry->SetNumber(max); | |
317 | ||
318 | if(fSlider) fSlider->SetPosition(min, max); | |
319 | if(emit) ValueSet(); | |
320 | } | |
321 | ||
322 | void RGDoubleValuator::ValueSet() | |
323 | { | |
324 | Emit("ValueSet()"); | |
325 | } | |
65b5c50a | 326 | |
327 | ||
328 | /**************************************************************************/ | |
329 | // RGTriVecValuator | |
330 | /**************************************************************************/ | |
331 | ||
332 | RGTriVecValuator::RGTriVecValuator(const TGWindow *p, const char* name, | |
333 | UInt_t w, UInt_t h) : | |
334 | TGCompositeFrame(p, w, h), | |
335 | ||
336 | fLabelWidth (0), | |
337 | fNELength (5), | |
338 | fNEHeight (20) | |
339 | { | |
340 | SetName(name); | |
341 | } | |
342 | ||
343 | RGTriVecValuator::~RGTriVecValuator() | |
344 | {} | |
345 | ||
346 | void RGTriVecValuator::Build(Bool_t vertical, const char* lab0, const char* lab1, const char* lab2) | |
347 | { | |
348 | if (vertical) SetLayoutManager(new TGVerticalLayout(this)); | |
349 | else SetLayoutManager(new TGHorizontalLayout(this)); | |
350 | ||
351 | const char *labs[3] = { lab0, lab1, lab2 }; | |
352 | TGLayoutHints* lh; | |
353 | for (Int_t i=0; i<3; ++i) { | |
354 | fVal[i] = new RGValuator(this, labs[i], 10, 0); | |
355 | fVal[i]->SetLabelWidth(fLabelWidth); | |
356 | fVal[i]->SetShowSlider(kFALSE); | |
357 | fVal[i]->SetNELength(fNELength); | |
358 | fVal[i]->SetNEHeight(fNEHeight); | |
359 | fVal[i]->Build(); | |
360 | fVal[i]->Connect | |
361 | ("ValueSet(Double_t)", "Reve::RGTriVecValuator", this, "ValueSet()"); | |
362 | if (vertical) lh = new TGLayoutHints(kLHintsTop, 1, 1, 1, 1); | |
363 | else lh = new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 1, 1); | |
364 | AddFrame(fVal[i], lh); | |
365 | } | |
366 | } | |
367 | ||
368 | void RGTriVecValuator::ValueSet() | |
369 | { | |
370 | Emit("ValueSet()"); | |
371 | } | |
372 | ||
373 | /**************************************************************************/ | |
374 | ||
375 | void RGTriVecValuator::SetLimits(Int_t min, Int_t max) | |
376 | { | |
377 | for (Int_t i=0; i<3; ++i) | |
378 | fVal[i]->SetLimits(min, max); | |
379 | } | |
380 | ||
381 | void RGTriVecValuator::SetLimits(Float_t min, Float_t max, | |
382 | TGNumberFormat::EStyle nef) | |
383 | { | |
384 | for (Int_t i=0; i<3; ++i) | |
385 | fVal[i]->SetLimits(min, max, 0, nef); | |
386 | } | |
387 | ||
388 |