00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TEveGValuators.h"
00013
00014 #include "TMath.h"
00015 #include "TGLabel.h"
00016 #include "TGSlider.h"
00017 #include "TGDoubleSlider.h"
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 ClassImp(TEveGValuatorBase);
00030
00031
00032 TEveGValuatorBase::TEveGValuatorBase(const TGWindow *p, const char* name,
00033 UInt_t w, UInt_t h, Int_t widgetId) :
00034 TGCompositeFrame(p, w, h), TGWidget(widgetId),
00035
00036 fLabelWidth (0),
00037 fAlignRight (kFALSE),
00038 fShowSlider (kTRUE),
00039
00040 fNELength (5),
00041 fNEHeight (20),
00042
00043 fLabel (0)
00044 {
00045
00046
00047 SetName(name);
00048 }
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 ClassImp(TEveGValuator);
00061
00062
00063 TEveGValuator::TEveGValuator(const TGWindow *p, const char* title,
00064 UInt_t w, UInt_t h, Int_t widgetId) :
00065 TEveGValuatorBase(p, title, w, h, widgetId),
00066
00067 fValue (0),
00068 fMin (0),
00069 fMax (0),
00070
00071 fSliderNewLine (kFALSE),
00072 fSliderDivs (-1),
00073 fEntry (0),
00074 fSlider (0)
00075 {
00076
00077 }
00078
00079
00080 void TEveGValuator::Build(Bool_t connect)
00081 {
00082
00083
00084 TGCompositeFrame *hf1, *hfs;
00085 if(fShowSlider && fSliderNewLine) {
00086 SetLayoutManager(new TGVerticalLayout(this));
00087 hf1 = new TGHorizontalFrame(this);
00088 hf1->SetLayoutManager(new TGHorizontalLayout(hf1));
00089 AddFrame(hf1, new TGLayoutHints(kLHintsTop, 0,0,0,0));
00090 hfs = new TGHorizontalFrame(this);
00091 hfs->SetLayoutManager(new TGHorizontalLayout(hfs));
00092 AddFrame(hfs, new TGLayoutHints(kLHintsTop, 0,0,0,0));
00093 } else {
00094 hf1 = this;
00095 hfs = this;
00096 SetLayoutManager(new TGHorizontalLayout(this));
00097 }
00098
00099
00100 {
00101 TGLayoutHints *labh, *labfrh;
00102 if(fAlignRight) {
00103 labh = new TGLayoutHints(kLHintsRight | kLHintsBottom, 0,0,0,0);
00104 labfrh = new TGLayoutHints(kLHintsRight);
00105 } else {
00106 labh = new TGLayoutHints(kLHintsLeft | kLHintsBottom, 0,0,0,0);
00107 labfrh = new TGLayoutHints(kLHintsLeft);
00108 }
00109 TGCompositeFrame *labfr =
00110 new TGHorizontalFrame(hf1, fLabelWidth, fNEHeight,
00111 fLabelWidth != 0 ? kFixedSize : kFixedHeight);
00112 fLabel = new TGLabel(labfr, fName);
00113 labfr->AddFrame(fLabel, labh);
00114 hf1->AddFrame(labfr, labfrh);
00115 }
00116
00117
00118 TGLayoutHints* elh = new TGLayoutHints(kLHintsLeft, 0,0,0,0);
00119 fEntry = new TGNumberEntry(hf1, 0, fNELength);
00120 fEntry->SetHeight(fNEHeight);
00121 fEntry->GetNumberEntry()->SetToolTipText("Enter Slider Value");
00122 hf1->AddFrame(fEntry, elh);
00123
00124 if (connect)
00125 fEntry->Connect("ValueSet(Long_t)",
00126 "TEveGValuator", this, "EntryCallback()");
00127
00128
00129 if(fShowSlider) {
00130 fSlider = new TGHSlider(hfs, GetWidth(), kSlider1 | kScaleBoth);
00131 hfs->AddFrame(fSlider, new TGLayoutHints(kLHintsLeft|kLHintsTop, 1,1,0,0));
00132
00133 if (connect)
00134 fSlider->Connect("PositionChanged(Int_t)",
00135 "TEveGValuator", this, "SliderCallback()");
00136 }
00137 }
00138
00139
00140 void TEveGValuator::SetLimits(Float_t min, Float_t max, Int_t npos,
00141 TGNumberFormat::EStyle nef)
00142 {
00143
00144
00145 fMin = Float_t(min);
00146 fMax = Float_t(max);
00147 fEntry->SetFormat(nef);
00148 fEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
00149
00150 if(fSlider) {
00151 fSliderDivs = npos - 1;
00152 fSlider->SetRange(0, fSliderDivs);
00153 }
00154 }
00155
00156
00157 void TEveGValuator::SetLimits(Int_t min, Int_t max)
00158 {
00159
00160
00161 fMin = Float_t(min);
00162 fMax = Float_t(max);
00163 fEntry->SetFormat(TGNumberFormat::kNESInteger);
00164 fEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
00165
00166 if(fSlider) {
00167 fSliderDivs = max - min;
00168 fSlider->SetRange(0, fSliderDivs);
00169 }
00170 }
00171
00172
00173 Int_t TEveGValuator::CalcSliderPos(Float_t v)
00174 {
00175
00176
00177 return (Int_t) TMath::Nint((v - fMin)*fSliderDivs/(fMax - fMin));
00178 }
00179
00180
00181 void TEveGValuator::EntryCallback()
00182 {
00183
00184
00185 fValue = fEntry->GetNumber();
00186 if(fSlider) {
00187 fSlider->SetPosition(CalcSliderPos(fValue));
00188 }
00189 ValueSet(fValue);
00190 }
00191
00192
00193 void TEveGValuator::SliderCallback()
00194 {
00195
00196
00197 fValue = fMin + fSlider->GetPosition()*(fMax-fMin)/fSliderDivs;
00198 fEntry->SetNumber(fValue);
00199 ValueSet(fValue);
00200 }
00201
00202
00203
00204 void TEveGValuator::ValueSet(Double_t val)
00205 {
00206
00207
00208 Emit("ValueSet(Double_t)", val);
00209 }
00210
00211
00212 void TEveGValuator::SetValue(Float_t val, Bool_t emit)
00213 {
00214
00215
00216 fValue = val;
00217 fEntry->SetNumber(fValue);
00218
00219 if(fSlider){
00220 fSlider->SetPosition(CalcSliderPos(fValue));
00221 }
00222 if(emit)
00223 ValueSet(val);
00224 }
00225
00226
00227 void TEveGValuator::SetToolTip(const char* tip)
00228 {
00229
00230
00231 fEntry->GetNumberEntry()->SetToolTipText(tip);
00232 }
00233
00234
00235 void TEveGValuator::SetEnabled(Bool_t state)
00236 {
00237
00238
00239 fEntry->GetNumberEntry()->SetEnabled(state);
00240 fEntry->GetButtonUp()->SetEnabled(state);
00241 fEntry->GetButtonDown()->SetEnabled(state);
00242 if(fSlider) {
00243 if(state) fSlider->MapWindow();
00244 else fSlider->UnmapWindow();
00245 }
00246 }
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 ClassImp(TEveGDoubleValuator);
00259
00260
00261 TEveGDoubleValuator::TEveGDoubleValuator(const TGWindow *p, const char* title,
00262 UInt_t w, UInt_t h, Int_t widgetId) :
00263 TEveGValuatorBase(p, title, w, h, widgetId),
00264
00265 fMinEntry(0),
00266 fMaxEntry(0),
00267 fSlider(0)
00268 {
00269
00270 }
00271
00272
00273 void TEveGDoubleValuator::Build(Bool_t connect)
00274 {
00275
00276
00277 TGCompositeFrame *hf1, *hfs;
00278 if(fShowSlider) {
00279 SetLayoutManager(new TGVerticalLayout(this));
00280 hf1 = new TGHorizontalFrame(this);
00281 hf1->SetLayoutManager(new TGHorizontalLayout(hf1));
00282 AddFrame(hf1, new TGLayoutHints(kLHintsTop));
00283 hfs = new TGHorizontalFrame(this);
00284 hfs->SetLayoutManager(new TGHorizontalLayout(hfs));
00285 AddFrame(hfs, new TGLayoutHints(kLHintsTop));
00286 } else {
00287 hf1 = this;
00288 hfs = this;
00289 SetLayoutManager(new TGHorizontalLayout(this));
00290 }
00291
00292
00293 TGLayoutHints* lh;
00294 if(fAlignRight)
00295 lh = new TGLayoutHints(kLHintsRight | kLHintsBottom, 4,0,0,0);
00296 else
00297 lh = new TGLayoutHints(kLHintsLeft | kLHintsBottom, 0,4,0,0);
00298
00299 if(fLabelWidth > 0) {
00300 TGCompositeFrame *lf = new TGHorizontalFrame(hf1, fLabelWidth, fNEHeight, kFixedSize);
00301 fLabel = new TGLabel(lf, fName);
00302 lf->AddFrame(fLabel, lh);
00303
00304 TGLayoutHints* lfh = new TGLayoutHints(kLHintsLeft, 0,0,0,0);
00305 hf1->AddFrame(lf, lfh);
00306 } else {
00307 fLabel = new TGLabel(hf1, fName);
00308 hf1->AddFrame(fLabel, lh);
00309 }
00310
00311
00312 fMinEntry = new TGNumberEntry(hf1, 0, fNELength);
00313 fMinEntry->SetHeight(fNEHeight);
00314 fMinEntry->GetNumberEntry()->SetToolTipText("Enter Slider Min Value");
00315 hf1->AddFrame(fMinEntry, new TGLayoutHints(kLHintsLeft, 0,0,0,0));
00316 if (connect)
00317 fMinEntry->Connect("ValueSet(Long_t)",
00318 "TEveGDoubleValuator", this, "MinEntryCallback()");
00319
00320 fMaxEntry = new TGNumberEntry(hf1, 0, fNELength);
00321 fMaxEntry->SetHeight(fNEHeight);
00322 fMaxEntry->GetNumberEntry()->SetToolTipText("Enter Slider Max Value");
00323 hf1->AddFrame(fMaxEntry, new TGLayoutHints(kLHintsLeft, 2,0,0,0));
00324 if (connect)
00325 fMaxEntry->Connect("ValueSet(Long_t)",
00326 "TEveGDoubleValuator", this, "MaxEntryCallback()");
00327
00328
00329 if(fShowSlider) {
00330 fSlider = new TGDoubleHSlider(hfs, GetWidth(), kDoubleScaleBoth);
00331 hfs->AddFrame(fSlider, new TGLayoutHints(kLHintsTop|kLHintsLeft, 0,0,1,0));
00332 if (connect)
00333 fSlider->Connect("PositionChanged()",
00334 "TEveGDoubleValuator", this, "SliderCallback()");
00335 }
00336 }
00337
00338
00339 void TEveGDoubleValuator::SetLimits(Int_t min, Int_t max)
00340 {
00341
00342
00343 fMinEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
00344 fMinEntry->SetFormat(TGNumberFormat::kNESInteger);
00345 fMaxEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
00346 fMaxEntry->SetFormat(TGNumberFormat::kNESInteger);
00347
00348 if(fSlider) {
00349 fSlider->SetRange(min, max);
00350 }
00351 }
00352
00353
00354 void TEveGDoubleValuator::SetLimits(Float_t min, Float_t max,
00355 TGNumberFormat::EStyle nef)
00356 {
00357
00358
00359
00360 fMinEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
00361 fMinEntry->SetFormat(nef);
00362 fMaxEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, min, max);
00363 fMaxEntry->SetFormat(nef);
00364
00365 if(fSlider) fSlider->SetRange(min, max);
00366 }
00367
00368
00369 void TEveGDoubleValuator::MinEntryCallback()
00370 {
00371
00372
00373 if(GetMin() > GetMax())
00374 fMaxEntry->SetNumber(GetMin());
00375 if(fSlider) fSlider->SetPosition(GetMin(), GetMax());
00376 ValueSet();
00377 }
00378
00379
00380 void TEveGDoubleValuator::MaxEntryCallback()
00381 {
00382
00383
00384 if(GetMax() < GetMin())
00385 fMinEntry->SetNumber(GetMax());
00386 if(fSlider) fSlider->SetPosition(GetMin(), GetMax());
00387 ValueSet();
00388 }
00389
00390
00391 void TEveGDoubleValuator::SliderCallback()
00392 {
00393
00394
00395 Float_t minp, maxp;
00396 fSlider->GetPosition(minp, maxp);
00397 fMinEntry->SetNumber(minp);
00398 fMaxEntry->SetNumber(maxp);
00399 ValueSet();
00400 }
00401
00402
00403 void TEveGDoubleValuator::SetValues(Float_t min, Float_t max, Bool_t emit)
00404 {
00405
00406
00407 fMinEntry->SetNumber(min);
00408 fMaxEntry->SetNumber(max);
00409
00410 if(fSlider) fSlider->SetPosition(min, max);
00411 if(emit) ValueSet();
00412 }
00413
00414
00415 void TEveGDoubleValuator::ValueSet()
00416 {
00417
00418
00419 Emit("ValueSet()");
00420 }
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433 ClassImp(TEveGTriVecValuator);
00434
00435
00436 TEveGTriVecValuator::TEveGTriVecValuator(const TGWindow *p, const char* name,
00437 UInt_t w, UInt_t h, Int_t widgetId) :
00438 TGCompositeFrame(p, w, h), TGWidget(widgetId),
00439
00440 fLabelWidth (0),
00441 fNELength (5),
00442 fNEHeight (20)
00443 {
00444
00445
00446 SetName(name);
00447 }
00448
00449
00450 void TEveGTriVecValuator::Build(Bool_t vertical, const char* lab0, const char* lab1, const char* lab2)
00451 {
00452
00453
00454 if (vertical) SetLayoutManager(new TGVerticalLayout(this));
00455 else SetLayoutManager(new TGHorizontalLayout(this));
00456
00457 const char *labs[3] = { lab0, lab1, lab2 };
00458 TGLayoutHints* lh;
00459 for (Int_t i=0; i<3; ++i) {
00460 fVal[i] = new TEveGValuator(this, labs[i], 10, 0);
00461 fVal[i]->SetLabelWidth(fLabelWidth);
00462 fVal[i]->SetShowSlider(kFALSE);
00463 fVal[i]->SetNELength(fNELength);
00464 fVal[i]->SetNEHeight(fNEHeight);
00465 fVal[i]->Build();
00466 fVal[i]->Connect
00467 ("ValueSet(Double_t)", "TEveGTriVecValuator", this, "ValueSet()");
00468 if (vertical) lh = new TGLayoutHints(kLHintsTop, 1, 1, 1, 1);
00469 else lh = new TGLayoutHints(kLHintsLeft|kLHintsExpandX, 1, 1, 1, 1);
00470 AddFrame(fVal[i], lh);
00471 }
00472 }
00473
00474
00475 void TEveGTriVecValuator::ValueSet()
00476 {
00477
00478
00479 Emit("ValueSet()");
00480 }
00481
00482
00483
00484
00485 void TEveGTriVecValuator::SetLimits(Int_t min, Int_t max)
00486 {
00487
00488
00489 for (Int_t i=0; i<3; ++i)
00490 fVal[i]->SetLimits(min, max);
00491 }
00492
00493
00494 void TEveGTriVecValuator::SetLimits(Float_t min, Float_t max,
00495 TGNumberFormat::EStyle nef)
00496 {
00497
00498
00499 for (Int_t i=0; i<3; ++i)
00500 fVal[i]->SetLimits(min, max, 0, nef);
00501 }
00502
00503