00001
00002
00003
00004
00005 #include "TGButton.h"
00006 #include "TRootEmbeddedCanvas.h"
00007 #include "TGLayout.h"
00008 #include "TF1.h"
00009 #include "TMath.h"
00010 #include "TCanvas.h"
00011 #include "TGTextEntry.h"
00012 #include "TGTripleSlider.h"
00013
00014 enum ETestCommandIdentifiers {
00015 HId1,
00016 HId2,
00017 HId3,
00018 HCId1,
00019 HCId2,
00020
00021 HSId1
00022 };
00023
00024 class TTripleSliderDemo : public TGMainFrame {
00025
00026 private:
00027 TRootEmbeddedCanvas *fCanvas;
00028 TGLayoutHints *fLcan;
00029 TF1 *fFitFcn;
00030 TGHorizontalFrame *fHframe0, *fHframe1, *fHframe2;
00031 TGLayoutHints *fBly, *fBfly1, *fBfly2, *fBfly3;
00032 TGTripleHSlider *fHslider1;
00033 TGTextEntry *fTeh1, *fTeh2, *fTeh3;
00034 TGTextBuffer *fTbh1, *fTbh2, *fTbh3;
00035 TGCheckButton *fCheck1, *fCheck2;
00036
00037 public:
00038 TTripleSliderDemo();
00039 virtual ~TTripleSliderDemo();
00040
00041 void CloseWindow();
00042 void DoText(const char *text);
00043 void DoSlider();
00044 void HandleButtons();
00045
00046 ClassDef(TTripleSliderDemo, 0)
00047 };
00048
00049
00050 TTripleSliderDemo::TTripleSliderDemo() : TGMainFrame(gClient->GetRoot(), 100, 100)
00051 {
00052
00053 char buf[32];
00054 SetCleanup(kDeepCleanup);
00055
00056
00057 fCanvas = new TRootEmbeddedCanvas("Canvas", this, 600, 400);
00058 fLcan = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10, 10, 10, 10);
00059 AddFrame(fCanvas, fLcan);
00060 fCanvas->GetCanvas()->SetFillColor(33);
00061 fCanvas->GetCanvas()->SetFrameFillColor(41);
00062 fCanvas->GetCanvas()->SetBorderMode(0);
00063 fCanvas->GetCanvas()->SetGrid();
00064 fCanvas->GetCanvas()->SetLogy();
00065
00066 fHframe0 = new TGHorizontalFrame(this, 0, 0, 0);
00067
00068 fCheck1 = new TGCheckButton(fHframe0, "&Constrained", HCId1);
00069 fCheck2 = new TGCheckButton(fHframe0, "&Relative", HCId2);
00070 fCheck1->SetState(kButtonUp);
00071 fCheck2->SetState(kButtonUp);
00072 fCheck1->SetToolTipText("Pointer position constrained to slider sides");
00073 fCheck2->SetToolTipText("Pointer position relative to slider position");
00074
00075 fHframe0->Resize(200, 50);
00076
00077 fHframe1 = new TGHorizontalFrame(this, 0, 0, 0);
00078
00079 fHslider1 = new TGTripleHSlider(fHframe1, 190, kDoubleScaleBoth, HSId1,
00080 kHorizontalFrame,
00081 GetDefaultFrameBackground(),
00082 kFALSE, kFALSE, kFALSE, kFALSE);
00083 fHslider1->Connect("PointerPositionChanged()", "TTripleSliderDemo",
00084 this, "DoSlider()");
00085 fHslider1->Connect("PositionChanged()", "TTripleSliderDemo",
00086 this, "DoSlider()");
00087 fHslider1->SetRange(0.05,5.0);
00088
00089 fHframe1->Resize(200, 25);
00090
00091 fHframe2 = new TGHorizontalFrame(this, 0, 0, 0);
00092
00093 fTeh1 = new TGTextEntry(fHframe2, fTbh1 = new TGTextBuffer(5), HId1);
00094 fTeh2 = new TGTextEntry(fHframe2, fTbh2 = new TGTextBuffer(5), HId2);
00095 fTeh3 = new TGTextEntry(fHframe2, fTbh3 = new TGTextBuffer(5), HId3);
00096
00097 fTeh1->SetToolTipText("Minimum (left) Value of Slider");
00098 fTeh2->SetToolTipText("Pointer Position Value");
00099 fTeh3->SetToolTipText("Maximum (right) Value of Slider");
00100
00101 fTbh1->AddText(0, "0.0");
00102 fTbh2->AddText(0, "0.0");
00103 fTbh3->AddText(0, "0.0");
00104
00105 fTeh1->Connect("TextChanged(char*)", "TTripleSliderDemo", this,
00106 "DoText(char*)");
00107 fTeh2->Connect("TextChanged(char*)", "TTripleSliderDemo", this,
00108 "DoText(char*)");
00109 fTeh3->Connect("TextChanged(char*)", "TTripleSliderDemo", this,
00110 "DoText(char*)");
00111
00112 fCheck1->Connect("Clicked()", "TTripleSliderDemo", this,
00113 "HandleButtons()");
00114 fCheck2->Connect("Clicked()", "TTripleSliderDemo", this,
00115 "HandleButtons()");
00116
00117 fHframe2->Resize(100, 25);
00118
00119
00120 fBly = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5);
00121
00122
00123 fBfly1 = new TGLayoutHints(kLHintsTop | kLHintsCenterX, 5, 5, 5, 5);
00124 fBfly2 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
00125 fBfly3 = new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 5, 5);
00126
00127 fHframe0->AddFrame(fCheck1, fBfly2);
00128 fHframe0->AddFrame(fCheck2, fBfly2);
00129 fHframe1->AddFrame(fHslider1, fBly);
00130 fHframe2->AddFrame(fTeh1, fBfly2);
00131 fHframe2->AddFrame(fTeh2, fBfly1);
00132 fHframe2->AddFrame(fTeh3, fBfly3);
00133
00134 AddFrame(fHframe0, fBly);
00135 AddFrame(fHframe1, fBly);
00136 AddFrame(fHframe2, fBly);
00137
00138
00139
00140 SetWindowName("Triple Slider Demo");
00141 MapSubwindows();
00142 Resize(GetDefaultSize());
00143 MapWindow();
00144
00145 fFitFcn = new TF1("fFitFcn", "TMath::LogNormal(x, [0], [1], [2])", 0, 5);
00146 fFitFcn->SetRange(0.0, 2.5);
00147 fFitFcn->SetParameters(1.0, 0, 1);
00148 fFitFcn->SetMinimum(1.0e-3);
00149 fFitFcn->SetMaximum(10.0);
00150 fFitFcn->SetLineColor(kRed);
00151 fFitFcn->SetLineWidth(1);
00152 fFitFcn->Draw();
00153
00154 fHslider1->SetPosition(0.05,2.5);
00155 fHslider1->SetPointerPosition(1.0);
00156
00157 sprintf(buf, "%.3f", fHslider1->GetMinPosition());
00158 fTbh1->Clear();
00159 fTbh1->AddText(0, buf);
00160 sprintf(buf, "%.3f", fHslider1->GetPointerPosition());
00161 fTbh2->Clear();
00162 fTbh2->AddText(0, buf);
00163 sprintf(buf, "%.3f", fHslider1->GetMaxPosition());
00164 fTbh3->Clear();
00165 fTbh3->AddText(0, buf);
00166 }
00167
00168
00169 TTripleSliderDemo::~TTripleSliderDemo()
00170 {
00171
00172
00173 Cleanup();
00174 }
00175
00176
00177 void TTripleSliderDemo::CloseWindow()
00178 {
00179
00180
00181 delete this;
00182 }
00183
00184
00185 void TTripleSliderDemo::DoText(const char * )
00186 {
00187
00188
00189 TGTextEntry *te = (TGTextEntry *) gTQSender;
00190 Int_t id = te->WidgetId();
00191
00192 switch (id) {
00193 case HId1:
00194 fHslider1->SetPosition(atof(fTbh1->GetString()),
00195 fHslider1->GetMaxPosition());
00196 break;
00197 case HId2:
00198 fHslider1->SetPointerPosition(atof(fTbh2->GetString()));
00199 break;
00200 case HId3:
00201 fHslider1->SetPosition(fHslider1->GetMinPosition(),
00202 atof(fTbh1->GetString()));
00203 break;
00204 default:
00205 break;
00206 }
00207 fFitFcn->SetParameters(fHslider1->GetPointerPosition(), 0, 1);
00208 fFitFcn->SetRange(fHslider1->GetMinPosition()-0.05,
00209 fHslider1->GetMaxPosition());
00210 fFitFcn->Draw();
00211 fCanvas->GetCanvas()->Modified();
00212 fCanvas->GetCanvas()->Update();
00213 }
00214
00215
00216 void TTripleSliderDemo::DoSlider()
00217 {
00218
00219
00220 char buf[32];
00221
00222 sprintf(buf, "%.3f", fHslider1->GetMinPosition());
00223 fTbh1->Clear();
00224 fTbh1->AddText(0, buf);
00225 fTeh1->SetCursorPosition(fTeh1->GetCursorPosition());
00226 fTeh1->Deselect();
00227 gClient->NeedRedraw(fTeh1);
00228
00229 sprintf(buf, "%.3f", fHslider1->GetPointerPosition());
00230 fTbh2->Clear();
00231 fTbh2->AddText(0, buf);
00232 fTeh2->SetCursorPosition(fTeh2->GetCursorPosition());
00233 fTeh2->Deselect();
00234 gClient->NeedRedraw(fTeh2);
00235
00236 sprintf(buf, "%.3f", fHslider1->GetMaxPosition());
00237 fTbh3->Clear();
00238 fTbh3->AddText(0, buf);
00239 fTeh3->SetCursorPosition(fTeh3->GetCursorPosition());
00240 fTeh3->Deselect();
00241 gClient->NeedRedraw(fTeh3);
00242
00243 fFitFcn->SetParameters(fHslider1->GetPointerPosition(), 0, 1);
00244 fFitFcn->SetRange(fHslider1->GetMinPosition()-0.05,
00245 fHslider1->GetMaxPosition());
00246 fFitFcn->Draw();
00247 fCanvas->GetCanvas()->Modified();
00248 fCanvas->GetCanvas()->Update();
00249 }
00250
00251
00252 void TTripleSliderDemo::HandleButtons()
00253 {
00254
00255
00256 TGButton *btn = (TGButton *) gTQSender;
00257 Int_t id = btn->WidgetId();
00258
00259 switch (id) {
00260 case HCId1:
00261 fHslider1->SetConstrained(fCheck1->GetState());
00262 break;
00263 case HCId2:
00264 fHslider1->SetRelative(fCheck2->GetState());
00265 break;
00266 default:
00267 break;
00268 }
00269 }
00270
00271
00272 void Slider3Demo()
00273 {
00274 new TTripleSliderDemo();
00275 }
00276