Logo ROOT  
Reference Guide
Slider3Demo.C File Reference

Detailed Description

Simple macro showing capabilities of triple slider

#include "TGButton.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:
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,
GetDefaultFrameBackground(),
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.
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->Deselect();
gClient->NeedRedraw(fTeh1);
sprintf(buf, "%.3f", fHslider1->GetPointerPosition());
fTbh2->Clear();
fTbh2->AddText(0, buf);
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.
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();
}
Author
Bertrand Bellenot, Ilka Antcheva

Definition in file Slider3Demo.C.

TGButton::SetToolTipText
virtual void SetToolTipText(const char *text, Long_t delayms=400)
Set tool tip text associated with this button.
Definition: TGButton.cxx:398
kLHintsCenterX
@ kLHintsCenterX
Definition: TGLayout.h:38
TGCheckButton::SetState
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
Set check button state.
Definition: TGButton.cxx:1203
e
#define e(i)
Definition: RSha256.hxx:121
TGMainFrame
Definition: TGFrame.h:444
TGSlider::GetMaxPosition
virtual Int_t GetMaxPosition() const
Definition: TGSlider.h:111
kLHintsTop
@ kLHintsTop
Definition: TGLayout.h:40
TGLayout.h
TGTextEntry::Deselect
void Deselect()
Deselects all text (i.e.
Definition: TGTextEntry.cxx:1052
kLHintsLeft
@ kLHintsLeft
Definition: TGLayout.h:37
TGTextEntry::SetToolTipText
virtual void SetToolTipText(const char *text, Long_t delayms=500)
Set tool tip text associated with this text entry.
Definition: TGTextEntry.cxx:1663
TGSlider::SetRange
virtual void SetRange(Int_t min, Int_t max)
Definition: TGSlider.h:101
TGSlider::GetMinPosition
virtual Int_t GetMinPosition() const
Definition: TGSlider.h:110
kButtonUp
@ kButtonUp
Definition: TGButton.h:59
gTQSender
R__EXTERN void * gTQSender
Definition: TQObject.h:44
Int_t
int Int_t
Definition: RtypesCore.h:45
TGTripleSlider.h
TGHorizontalFrame
Definition: TGFrame.h:423
TCanvas.h
TGSlider::SetPosition
virtual void SetPosition(Int_t pos)
Definition: TGSlider.h:105
text
TText * text
Definition: entrylist_figure1.C:10
TGTextBuffer
Definition: TGTextBuffer.h:30
gClient
#define gClient
Definition: TGClient.h:166
TGCheckButton
Definition: TGButton.h:264
TGWidget::WidgetId
Int_t WidgetId() const
Definition: TGWidget.h:80
TGTextEntry
Definition: TGTextEntry.h:39
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
kLHintsRight
@ kLHintsRight
Definition: TGLayout.h:39
TGLayoutHints
Definition: TGLayout.h:57
TGTripleHSlider
Definition: TGTripleSlider.h:101
kLHintsExpandY
@ kLHintsExpandY
Definition: TGLayout.h:44
TGMainFrame::CloseWindow
virtual void CloseWindow()
Close and delete main frame.
Definition: TGFrame.cxx:1731
kRed
@ kRed
Definition: Rtypes.h:66
TGTextBuffer::Clear
void Clear()
Definition: TGTextBuffer.h:58
TRootEmbeddedCanvas.h
kHorizontalFrame
@ kHorizontalFrame
Definition: GuiTypes.h:382
TQObject::Connect
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition: TQObject.cxx:864
TF1.h
TGButton::GetState
virtual EButtonState GetState() const
Definition: TGButton.h:112
TGTextEntry.h
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGButton.h
kDeepCleanup
@ kDeepCleanup
Definition: TGFrame.h:51
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:43
TGTextEntry::GetCursorPosition
Int_t GetCursorPosition() const
Definition: TGTextEntry.h:128
TGTextEntry::SetCursorPosition
virtual void SetCursorPosition(Int_t pos)
Set the cursor position to newPos.
Definition: TGTextEntry.cxx:730
kDoubleScaleBoth
@ kDoubleScaleBoth
Definition: TGDoubleSlider.h:68
TGButton
Definition: TGButton.h:68
TF1
1-Dim function class
Definition: TF1.h:212
TGTextBuffer::AddText
void AddText(Int_t pos, const char *text)
Definition: TGTextBuffer.h:55
TGTextBuffer::GetString
const char * GetString() const
Definition: TGTextBuffer.h:53
TMath.h
TRootEmbeddedCanvas
Definition: TRootEmbeddedCanvas.h:32