From $ROOTSYS/tutorials/gui/Slider3Demo.C


// Simple macro showing capabilities of triple slider
//Authors: Bertrand Bellenot, Ilka Antcheva

#include "TGButton.h"
#include "TRootEmbeddedCanvas.h"
#include "TGLayout.h"
#include "TF1.h"
#include "TMath.h"
#include "TCanvas.h"
#include "TGTextEntry.h"
#include "TGTripleSlider.h"

enum ETestCommandIdentifiers {
   HId1,
   HId2,
   HId3,
   HCId1,
   HCId2,

   HSId1
};

class TTripleSliderDemo : public TGMainFrame {

private:
   TRootEmbeddedCanvas *fCanvas;
   TGLayoutHints       *fLcan;
   TF1                 *fFitFcn;
   TGHorizontalFrame   *fHframe0, *fHframe1, *fHframe2;
   TGLayoutHints       *fBly, *fBfly1, *fBfly2, *fBfly3;
   TGTripleHSlider     *fHslider1;
   TGTextEntry         *fTeh1, *fTeh2, *fTeh3;
   TGTextBuffer        *fTbh1, *fTbh2, *fTbh3;
   TGCheckButton       *fCheck1, *fCheck2;

public:
   TTripleSliderDemo();
   virtual ~TTripleSliderDemo();

   void CloseWindow();
   void DoText(const char *text);
   void DoSlider();
   void HandleButtons();

   ClassDef(TTripleSliderDemo, 0)
};

//______________________________________________________________________________
TTripleSliderDemo::TTripleSliderDemo() : TGMainFrame(gClient->GetRoot(), 100, 100)
{

   char buf[32];
   SetCleanup(kDeepCleanup);
   // Create an embedded canvas and add to the main frame, centered in x and y
   // and with 30 pixel margins all around
   fCanvas = new TRootEmbeddedCanvas("Canvas", this, 600, 400);
   fLcan = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10, 10, 10, 10);
   AddFrame(fCanvas, fLcan);
   fCanvas->GetCanvas()->SetFillColor(33);
   fCanvas->GetCanvas()->SetFrameFillColor(41);
   fCanvas->GetCanvas()->SetBorderMode(0);
   fCanvas->GetCanvas()->SetGrid();
   fCanvas->GetCanvas()->SetLogy();

   fHframe0 = new TGHorizontalFrame(this, 0, 0, 0);

   fCheck1 = new TGCheckButton(fHframe0, "&Constrained", HCId1);
   fCheck2 = new TGCheckButton(fHframe0, "&Relative", HCId2);
   fCheck1->SetState(kButtonUp);
   fCheck2->SetState(kButtonUp);
   fCheck1->SetToolTipText("Pointer position constrained to slider sides");
   fCheck2->SetToolTipText("Pointer position relative to slider position");

   fHframe0->Resize(200, 50);

   fHframe1 = new TGHorizontalFrame(this, 0, 0, 0);

   fHslider1 = new TGTripleHSlider(fHframe1, 190, kDoubleScaleBoth, HSId1,
                                   kHorizontalFrame,
                                   GetDefaultFrameBackground(),
                                   kFALSE, kFALSE, kFALSE, kFALSE);
   fHslider1->Connect("PointerPositionChanged()", "TTripleSliderDemo",
                      this, "DoSlider()");
   fHslider1->Connect("PositionChanged()", "TTripleSliderDemo",
                      this, "DoSlider()");
   fHslider1->SetRange(0.05,5.0);

   fHframe1->Resize(200, 25);

   fHframe2 = new TGHorizontalFrame(this, 0, 0, 0);

   fTeh1 = new TGTextEntry(fHframe2, fTbh1 = new TGTextBuffer(5), HId1);
   fTeh2 = new TGTextEntry(fHframe2, fTbh2 = new TGTextBuffer(5), HId2);
   fTeh3 = new TGTextEntry(fHframe2, fTbh3 = new TGTextBuffer(5), HId3);

   fTeh1->SetToolTipText("Minimum (left) Value of Slider");
   fTeh2->SetToolTipText("Pointer Position Value");
   fTeh3->SetToolTipText("Maximum (right) Value of Slider");

   fTbh1->AddText(0, "0.0");
   fTbh2->AddText(0, "0.0");
   fTbh3->AddText(0, "0.0");

   fTeh1->Connect("TextChanged(char*)", "TTripleSliderDemo", this,
                  "DoText(char*)");
   fTeh2->Connect("TextChanged(char*)", "TTripleSliderDemo", this,
                  "DoText(char*)");
   fTeh3->Connect("TextChanged(char*)", "TTripleSliderDemo", this,
                  "DoText(char*)");

   fCheck1->Connect("Clicked()", "TTripleSliderDemo", this,
                    "HandleButtons()");
   fCheck2->Connect("Clicked()", "TTripleSliderDemo", this,
                    "HandleButtons()");

   fHframe2->Resize(100, 25);

   //--- layout for buttons: top align, equally expand horizontally
   fBly = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5);

   //--- layout for the frame: place at bottom, right aligned
   fBfly1 = new TGLayoutHints(kLHintsTop | kLHintsCenterX, 5, 5, 5, 5);
   fBfly2 = new TGLayoutHints(kLHintsTop | kLHintsLeft,    5, 5, 5, 5);
   fBfly3 = new TGLayoutHints(kLHintsTop | kLHintsRight,   5, 5, 5, 5);

   fHframe0->AddFrame(fCheck1, fBfly2);
   fHframe0->AddFrame(fCheck2, fBfly2);
   fHframe1->AddFrame(fHslider1, fBly);
   fHframe2->AddFrame(fTeh1, fBfly2);
   fHframe2->AddFrame(fTeh2, fBfly1);
   fHframe2->AddFrame(fTeh3, fBfly3);

   AddFrame(fHframe0, fBly);
   AddFrame(fHframe1, fBly);
   AddFrame(fHframe2, fBly);

   // Set main frame name, map sub windows (buttons), initialize layout
   // algorithm via Resize() and map main frame
   SetWindowName("Triple Slider Demo");
   MapSubwindows();
   Resize(GetDefaultSize());
   MapWindow();

   fFitFcn = new TF1("fFitFcn", "TMath::LogNormal(x, [0], [1], [2])", 0, 5);
   fFitFcn->SetRange(0.0, 2.5);
   fFitFcn->SetParameters(1.0, 0, 1);
   fFitFcn->SetMinimum(1.0e-3);
   fFitFcn->SetMaximum(10.0);
   fFitFcn->SetLineColor(kRed);
   fFitFcn->SetLineWidth(1);
   fFitFcn->Draw();

   fHslider1->SetPosition(0.05,2.5);
   fHslider1->SetPointerPosition(1.0);

   sprintf(buf, "%.3f", fHslider1->GetMinPosition());
   fTbh1->Clear();
   fTbh1->AddText(0, buf);
   sprintf(buf, "%.3f", fHslider1->GetPointerPosition());
   fTbh2->Clear();
   fTbh2->AddText(0, buf);
   sprintf(buf, "%.3f", fHslider1->GetMaxPosition());
   fTbh3->Clear();
   fTbh3->AddText(0, buf);
}

//______________________________________________________________________________
TTripleSliderDemo::~TTripleSliderDemo()
{
   // Clean up

   Cleanup();
}

//______________________________________________________________________________
void TTripleSliderDemo::CloseWindow()
{
   // Called when window is closed via the window manager.

   delete this;
}

//______________________________________________________________________________
void TTripleSliderDemo::DoText(const char * /*text*/)
{
   // Handle text entry widgets.

   TGTextEntry *te = (TGTextEntry *) gTQSender;
   Int_t id = te->WidgetId();

   switch (id) {
      case HId1:
         fHslider1->SetPosition(atof(fTbh1->GetString()),
                                fHslider1->GetMaxPosition());
         break;
      case HId2:
         fHslider1->SetPointerPosition(atof(fTbh2->GetString()));
         break;
      case HId3:
         fHslider1->SetPosition(fHslider1->GetMinPosition(),
                                atof(fTbh1->GetString()));
         break;
      default:
         break;
   }
   fFitFcn->SetParameters(fHslider1->GetPointerPosition(), 0, 1);
   fFitFcn->SetRange(fHslider1->GetMinPosition()-0.05,
                     fHslider1->GetMaxPosition());
   fFitFcn->Draw();
   fCanvas->GetCanvas()->Modified();
   fCanvas->GetCanvas()->Update();
}

//______________________________________________________________________________
void TTripleSliderDemo::DoSlider()
{
   // Handle slider widgets.

   char buf[32];

   sprintf(buf, "%.3f", fHslider1->GetMinPosition());
   fTbh1->Clear();
   fTbh1->AddText(0, buf);
   fTeh1->SetCursorPosition(fTeh1->GetCursorPosition());
   fTeh1->Deselect();
   gClient->NeedRedraw(fTeh1);

   sprintf(buf, "%.3f", fHslider1->GetPointerPosition());
   fTbh2->Clear();
   fTbh2->AddText(0, buf);
   fTeh2->SetCursorPosition(fTeh2->GetCursorPosition());
   fTeh2->Deselect();
   gClient->NeedRedraw(fTeh2);

   sprintf(buf, "%.3f", fHslider1->GetMaxPosition());
   fTbh3->Clear();
   fTbh3->AddText(0, buf);
   fTeh3->SetCursorPosition(fTeh3->GetCursorPosition());
   fTeh3->Deselect();
   gClient->NeedRedraw(fTeh3);

   fFitFcn->SetParameters(fHslider1->GetPointerPosition(), 0, 1);
   fFitFcn->SetRange(fHslider1->GetMinPosition()-0.05,
                     fHslider1->GetMaxPosition());
   fFitFcn->Draw();
   fCanvas->GetCanvas()->Modified();
   fCanvas->GetCanvas()->Update();
}

//______________________________________________________________________________
void TTripleSliderDemo::HandleButtons()
{
   // Handle different buttons.

   TGButton *btn = (TGButton *) gTQSender;
   Int_t id = btn->WidgetId();

   switch (id) {
      case HCId1:
         fHslider1->SetConstrained(fCheck1->GetState());
         break;
      case HCId2:
         fHslider1->SetRelative(fCheck2->GetState());
         break;
      default:
         break;
   }
}


void Slider3Demo()
{
   new TTripleSliderDemo();
}

 Slider3Demo.C:1
 Slider3Demo.C:2
 Slider3Demo.C:3
 Slider3Demo.C:4
 Slider3Demo.C:5
 Slider3Demo.C:6
 Slider3Demo.C:7
 Slider3Demo.C:8
 Slider3Demo.C:9
 Slider3Demo.C:10
 Slider3Demo.C:11
 Slider3Demo.C:12
 Slider3Demo.C:13
 Slider3Demo.C:14
 Slider3Demo.C:15
 Slider3Demo.C:16
 Slider3Demo.C:17
 Slider3Demo.C:18
 Slider3Demo.C:19
 Slider3Demo.C:20
 Slider3Demo.C:21
 Slider3Demo.C:22
 Slider3Demo.C:23
 Slider3Demo.C:24
 Slider3Demo.C:25
 Slider3Demo.C:26
 Slider3Demo.C:27
 Slider3Demo.C:28
 Slider3Demo.C:29
 Slider3Demo.C:30
 Slider3Demo.C:31
 Slider3Demo.C:32
 Slider3Demo.C:33
 Slider3Demo.C:34
 Slider3Demo.C:35
 Slider3Demo.C:36
 Slider3Demo.C:37
 Slider3Demo.C:38
 Slider3Demo.C:39
 Slider3Demo.C:40
 Slider3Demo.C:41
 Slider3Demo.C:42
 Slider3Demo.C:43
 Slider3Demo.C:44
 Slider3Demo.C:45
 Slider3Demo.C:46
 Slider3Demo.C:47
 Slider3Demo.C:48
 Slider3Demo.C:49
 Slider3Demo.C:50
 Slider3Demo.C:51
 Slider3Demo.C:52
 Slider3Demo.C:53
 Slider3Demo.C:54
 Slider3Demo.C:55
 Slider3Demo.C:56
 Slider3Demo.C:57
 Slider3Demo.C:58
 Slider3Demo.C:59
 Slider3Demo.C:60
 Slider3Demo.C:61
 Slider3Demo.C:62
 Slider3Demo.C:63
 Slider3Demo.C:64
 Slider3Demo.C:65
 Slider3Demo.C:66
 Slider3Demo.C:67
 Slider3Demo.C:68
 Slider3Demo.C:69
 Slider3Demo.C:70
 Slider3Demo.C:71
 Slider3Demo.C:72
 Slider3Demo.C:73
 Slider3Demo.C:74
 Slider3Demo.C:75
 Slider3Demo.C:76
 Slider3Demo.C:77
 Slider3Demo.C:78
 Slider3Demo.C:79
 Slider3Demo.C:80
 Slider3Demo.C:81
 Slider3Demo.C:82
 Slider3Demo.C:83
 Slider3Demo.C:84
 Slider3Demo.C:85
 Slider3Demo.C:86
 Slider3Demo.C:87
 Slider3Demo.C:88
 Slider3Demo.C:89
 Slider3Demo.C:90
 Slider3Demo.C:91
 Slider3Demo.C:92
 Slider3Demo.C:93
 Slider3Demo.C:94
 Slider3Demo.C:95
 Slider3Demo.C:96
 Slider3Demo.C:97
 Slider3Demo.C:98
 Slider3Demo.C:99
 Slider3Demo.C:100
 Slider3Demo.C:101
 Slider3Demo.C:102
 Slider3Demo.C:103
 Slider3Demo.C:104
 Slider3Demo.C:105
 Slider3Demo.C:106
 Slider3Demo.C:107
 Slider3Demo.C:108
 Slider3Demo.C:109
 Slider3Demo.C:110
 Slider3Demo.C:111
 Slider3Demo.C:112
 Slider3Demo.C:113
 Slider3Demo.C:114
 Slider3Demo.C:115
 Slider3Demo.C:116
 Slider3Demo.C:117
 Slider3Demo.C:118
 Slider3Demo.C:119
 Slider3Demo.C:120
 Slider3Demo.C:121
 Slider3Demo.C:122
 Slider3Demo.C:123
 Slider3Demo.C:124
 Slider3Demo.C:125
 Slider3Demo.C:126
 Slider3Demo.C:127
 Slider3Demo.C:128
 Slider3Demo.C:129
 Slider3Demo.C:130
 Slider3Demo.C:131
 Slider3Demo.C:132
 Slider3Demo.C:133
 Slider3Demo.C:134
 Slider3Demo.C:135
 Slider3Demo.C:136
 Slider3Demo.C:137
 Slider3Demo.C:138
 Slider3Demo.C:139
 Slider3Demo.C:140
 Slider3Demo.C:141
 Slider3Demo.C:142
 Slider3Demo.C:143
 Slider3Demo.C:144
 Slider3Demo.C:145
 Slider3Demo.C:146
 Slider3Demo.C:147
 Slider3Demo.C:148
 Slider3Demo.C:149
 Slider3Demo.C:150
 Slider3Demo.C:151
 Slider3Demo.C:152
 Slider3Demo.C:153
 Slider3Demo.C:154
 Slider3Demo.C:155
 Slider3Demo.C:156
 Slider3Demo.C:157
 Slider3Demo.C:158
 Slider3Demo.C:159
 Slider3Demo.C:160
 Slider3Demo.C:161
 Slider3Demo.C:162
 Slider3Demo.C:163
 Slider3Demo.C:164
 Slider3Demo.C:165
 Slider3Demo.C:166
 Slider3Demo.C:167
 Slider3Demo.C:168
 Slider3Demo.C:169
 Slider3Demo.C:170
 Slider3Demo.C:171
 Slider3Demo.C:172
 Slider3Demo.C:173
 Slider3Demo.C:174
 Slider3Demo.C:175
 Slider3Demo.C:176
 Slider3Demo.C:177
 Slider3Demo.C:178
 Slider3Demo.C:179
 Slider3Demo.C:180
 Slider3Demo.C:181
 Slider3Demo.C:182
 Slider3Demo.C:183
 Slider3Demo.C:184
 Slider3Demo.C:185
 Slider3Demo.C:186
 Slider3Demo.C:187
 Slider3Demo.C:188
 Slider3Demo.C:189
 Slider3Demo.C:190
 Slider3Demo.C:191
 Slider3Demo.C:192
 Slider3Demo.C:193
 Slider3Demo.C:194
 Slider3Demo.C:195
 Slider3Demo.C:196
 Slider3Demo.C:197
 Slider3Demo.C:198
 Slider3Demo.C:199
 Slider3Demo.C:200
 Slider3Demo.C:201
 Slider3Demo.C:202
 Slider3Demo.C:203
 Slider3Demo.C:204
 Slider3Demo.C:205
 Slider3Demo.C:206
 Slider3Demo.C:207
 Slider3Demo.C:208
 Slider3Demo.C:209
 Slider3Demo.C:210
 Slider3Demo.C:211
 Slider3Demo.C:212
 Slider3Demo.C:213
 Slider3Demo.C:214
 Slider3Demo.C:215
 Slider3Demo.C:216
 Slider3Demo.C:217
 Slider3Demo.C:218
 Slider3Demo.C:219
 Slider3Demo.C:220
 Slider3Demo.C:221
 Slider3Demo.C:222
 Slider3Demo.C:223
 Slider3Demo.C:224
 Slider3Demo.C:225
 Slider3Demo.C:226
 Slider3Demo.C:227
 Slider3Demo.C:228
 Slider3Demo.C:229
 Slider3Demo.C:230
 Slider3Demo.C:231
 Slider3Demo.C:232
 Slider3Demo.C:233
 Slider3Demo.C:234
 Slider3Demo.C:235
 Slider3Demo.C:236
 Slider3Demo.C:237
 Slider3Demo.C:238
 Slider3Demo.C:239
 Slider3Demo.C:240
 Slider3Demo.C:241
 Slider3Demo.C:242
 Slider3Demo.C:243
 Slider3Demo.C:244
 Slider3Demo.C:245
 Slider3Demo.C:246
 Slider3Demo.C:247
 Slider3Demo.C:248
 Slider3Demo.C:249
 Slider3Demo.C:250
 Slider3Demo.C:251
 Slider3Demo.C:252
 Slider3Demo.C:253
 Slider3Demo.C:254
 Slider3Demo.C:255
 Slider3Demo.C:256
 Slider3Demo.C:257
 Slider3Demo.C:258
 Slider3Demo.C:259
 Slider3Demo.C:260
 Slider3Demo.C:261
 Slider3Demo.C:262
 Slider3Demo.C:263
 Slider3Demo.C:264
 Slider3Demo.C:265
 Slider3Demo.C:266
 Slider3Demo.C:267
 Slider3Demo.C:268
 Slider3Demo.C:269
 Slider3Demo.C:270
 Slider3Demo.C:271
 Slider3Demo.C:272
 Slider3Demo.C:273
 Slider3Demo.C:274
 Slider3Demo.C:275
 Slider3Demo.C:276
 Slider3Demo.C:277