Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Slider3Demo.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gui
3/// Simple macro showing capabilities of triple slider
4///
5/// \macro_code
6///
7/// \author Bertrand Bellenot, Ilka Antcheva
8
9#include "TGButton.h"
10#include "TRootEmbeddedCanvas.h"
11#include "TGLayout.h"
12#include "TF1.h"
13#include "TMath.h"
14#include "TCanvas.h"
15#include "TGTextEntry.h"
16#include "TGTripleSlider.h"
17
18enum ETestCommandIdentifiers {
19 HId1,
20 HId2,
21 HId3,
22 HCId1,
23 HCId2,
24
25 HSId1
26};
27
28class TTripleSliderDemo : public TGMainFrame {
29
30private:
31 TRootEmbeddedCanvas *fCanvas;
32 TGLayoutHints *fLcan;
33 TF1 *fFitFcn;
34 TGHorizontalFrame *fHframe0, *fHframe1, *fHframe2;
35 TGLayoutHints *fBly, *fBfly1, *fBfly2, *fBfly3;
36 TGTripleHSlider *fHslider1;
37 TGTextEntry *fTeh1, *fTeh2, *fTeh3;
38 TGTextBuffer *fTbh1, *fTbh2, *fTbh3;
39 TGCheckButton *fCheck1, *fCheck2;
40
41public:
42 TTripleSliderDemo();
43 ~TTripleSliderDemo() override;
44
45 void CloseWindow() override;
46 void DoText(const char *text);
47 void DoSlider();
48 void HandleButtons();
49
50 ClassDef(TTripleSliderDemo, 0)
51};
52
53//______________________________________________________________________________
54TTripleSliderDemo::TTripleSliderDemo() : TGMainFrame(gClient->GetRoot(), 100, 100)
55{
56
57 char buf[32];
58 SetCleanup(kDeepCleanup);
59 // Create an embedded canvas and add to the main frame, centered in x and y
60 // and with 30 pixel margins all around
61 fCanvas = new TRootEmbeddedCanvas("Canvas", this, 600, 400);
62 fLcan = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10, 10, 10, 10);
63 AddFrame(fCanvas, fLcan);
64 fCanvas->GetCanvas()->SetFillColor(33);
65 fCanvas->GetCanvas()->SetFrameFillColor(41);
66 fCanvas->GetCanvas()->SetBorderMode(0);
67 fCanvas->GetCanvas()->SetGrid();
68 fCanvas->GetCanvas()->SetLogy();
69
70 fHframe0 = new TGHorizontalFrame(this, 0, 0, 0);
71
72 fCheck1 = new TGCheckButton(fHframe0, "&Constrained", HCId1);
73 fCheck2 = new TGCheckButton(fHframe0, "&Relative", HCId2);
74 fCheck1->SetState(kButtonUp);
75 fCheck2->SetState(kButtonUp);
76 fCheck1->SetToolTipText("Pointer position constrained to slider sides");
77 fCheck2->SetToolTipText("Pointer position relative to slider position");
78
79 fHframe0->Resize(200, 50);
80
81 fHframe1 = new TGHorizontalFrame(this, 0, 0, 0);
82
83 fHslider1 = new TGTripleHSlider(fHframe1, 190, kDoubleScaleBoth, HSId1, kHorizontalFrame,
84 GetDefaultFrameBackground(), kFALSE, kFALSE, kFALSE, kFALSE);
85 fHslider1->Connect("PointerPositionChanged()", "TTripleSliderDemo", this, "DoSlider()");
86 fHslider1->Connect("PositionChanged()", "TTripleSliderDemo", this, "DoSlider()");
87 fHslider1->SetRange(0.05, 5.0);
88
89 fHframe1->Resize(200, 25);
90
91 fHframe2 = new TGHorizontalFrame(this, 0, 0, 0);
92
93 fTeh1 = new TGTextEntry(fHframe2, fTbh1 = new TGTextBuffer(5), HId1);
94 fTeh2 = new TGTextEntry(fHframe2, fTbh2 = new TGTextBuffer(5), HId2);
95 fTeh3 = new TGTextEntry(fHframe2, fTbh3 = new TGTextBuffer(5), HId3);
96
97 fTeh1->SetToolTipText("Minimum (left) Value of Slider");
98 fTeh2->SetToolTipText("Pointer Position Value");
99 fTeh3->SetToolTipText("Maximum (right) Value of Slider");
100
101 fTbh1->AddText(0, "0.0");
102 fTbh2->AddText(0, "0.0");
103 fTbh3->AddText(0, "0.0");
104
105 fTeh1->Connect("TextChanged(char*)", "TTripleSliderDemo", this, "DoText(char*)");
106 fTeh2->Connect("TextChanged(char*)", "TTripleSliderDemo", this, "DoText(char*)");
107 fTeh3->Connect("TextChanged(char*)", "TTripleSliderDemo", this, "DoText(char*)");
108
109 fCheck1->Connect("Clicked()", "TTripleSliderDemo", this, "HandleButtons()");
110 fCheck2->Connect("Clicked()", "TTripleSliderDemo", this, "HandleButtons()");
111
112 fHframe2->Resize(100, 25);
113
114 //--- layout for buttons: top align, equally expand horizontally
115 fBly = new TGLayoutHints(kLHintsTop | kLHintsExpandX, 5, 5, 5, 5);
116
117 //--- layout for the frame: place at bottom, right aligned
118 fBfly1 = new TGLayoutHints(kLHintsTop | kLHintsCenterX, 5, 5, 5, 5);
119 fBfly2 = new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5);
120 fBfly3 = new TGLayoutHints(kLHintsTop | kLHintsRight, 5, 5, 5, 5);
121
122 fHframe0->AddFrame(fCheck1, fBfly2);
123 fHframe0->AddFrame(fCheck2, fBfly2);
124 fHframe1->AddFrame(fHslider1, fBly);
125 fHframe2->AddFrame(fTeh1, fBfly2);
126 fHframe2->AddFrame(fTeh2, fBfly1);
127 fHframe2->AddFrame(fTeh3, fBfly3);
128
129 AddFrame(fHframe0, fBly);
130 AddFrame(fHframe1, fBly);
131 AddFrame(fHframe2, fBly);
132
133 // Set main frame name, map sub windows (buttons), initialize layout
134 // algorithm via Resize() and map main frame
135 SetWindowName("Triple Slider Demo");
137 Resize(GetDefaultSize());
138 MapWindow();
139
140 fFitFcn = new TF1("fFitFcn", "TMath::LogNormal(x, [0], [1], [2])", 0, 5);
141 fFitFcn->SetRange(0.0, 2.5);
142 fFitFcn->SetParameters(1.0, 0, 1);
143 fFitFcn->SetMinimum(1.0e-3);
144 fFitFcn->SetMaximum(10.0);
145 fFitFcn->SetLineColor(kRed);
146 fFitFcn->SetLineWidth(1);
147 fFitFcn->Draw();
148
149 fHslider1->SetPosition(0.05, 2.5);
150 fHslider1->SetPointerPosition(1.0);
151
152 sprintf(buf, "%.3f", fHslider1->GetMinPosition());
153 fTbh1->Clear();
154 fTbh1->AddText(0, buf);
155 sprintf(buf, "%.3f", fHslider1->GetPointerPosition());
156 fTbh2->Clear();
157 fTbh2->AddText(0, buf);
158 sprintf(buf, "%.3f", fHslider1->GetMaxPosition());
159 fTbh3->Clear();
160 fTbh3->AddText(0, buf);
161}
162
163//______________________________________________________________________________
164TTripleSliderDemo::~TTripleSliderDemo()
165{
166 // Clean up
167
168 Cleanup();
169}
170
171//______________________________________________________________________________
172void TTripleSliderDemo::CloseWindow()
173{
174 // Called when window is closed via the window manager.
175
176 delete this;
177}
178
179//______________________________________________________________________________
180void TTripleSliderDemo::DoText(const char * /*text*/)
181{
182 // Handle text entry widgets.
183
185 Int_t id = te->WidgetId();
186
187 switch (id) {
188 case HId1: fHslider1->SetPosition((Float_t)atof(fTbh1->GetString()), (Float_t)fHslider1->GetMaxPosition()); break;
189 case HId2: fHslider1->SetPointerPosition((Float_t)atof(fTbh2->GetString())); break;
190 case HId3: fHslider1->SetPosition((Float_t)fHslider1->GetMinPosition(), (Float_t)atof(fTbh1->GetString())); break;
191 default: break;
192 }
193 fFitFcn->SetParameters(fHslider1->GetPointerPosition(), 0, 1);
194 fFitFcn->SetRange(fHslider1->GetMinPosition() - 0.05, fHslider1->GetMaxPosition());
195 fFitFcn->Draw();
196 fCanvas->GetCanvas()->Modified();
197 fCanvas->GetCanvas()->Update();
198}
199
200//______________________________________________________________________________
201void TTripleSliderDemo::DoSlider()
202{
203 // Handle slider widgets.
204
205 char buf[32];
206
207 sprintf(buf, "%.3f", fHslider1->GetMinPosition());
208 fTbh1->Clear();
209 fTbh1->AddText(0, buf);
210 fTeh1->SetCursorPosition(fTeh1->GetCursorPosition());
211 fTeh1->Deselect();
212 gClient->NeedRedraw(fTeh1);
213
214 sprintf(buf, "%.3f", fHslider1->GetPointerPosition());
215 fTbh2->Clear();
216 fTbh2->AddText(0, buf);
217 fTeh2->SetCursorPosition(fTeh2->GetCursorPosition());
218 fTeh2->Deselect();
219 gClient->NeedRedraw(fTeh2);
220
221 sprintf(buf, "%.3f", fHslider1->GetMaxPosition());
222 fTbh3->Clear();
223 fTbh3->AddText(0, buf);
224 fTeh3->SetCursorPosition(fTeh3->GetCursorPosition());
225 fTeh3->Deselect();
226 gClient->NeedRedraw(fTeh3);
227
228 fFitFcn->SetParameters(fHslider1->GetPointerPosition(), 0, 1);
229 fFitFcn->SetRange(fHslider1->GetMinPosition() - 0.05, fHslider1->GetMaxPosition());
230 fFitFcn->Draw();
231 fCanvas->GetCanvas()->Modified();
232 fCanvas->GetCanvas()->Update();
233}
234
235//______________________________________________________________________________
236void TTripleSliderDemo::HandleButtons()
237{
238 // Handle different buttons.
239
240 TGButton *btn = (TGButton *)gTQSender;
241 Int_t id = btn->WidgetId();
242
243 switch (id) {
244 case HCId1: fHslider1->SetConstrained(fCheck1->GetState()); break;
245 case HCId2: fHslider1->SetRelative(fCheck2->GetState()); break;
246 default: break;
247 }
248}
249
250void Slider3Demo()
251{
252 new TTripleSliderDemo();
253}
@ kHorizontalFrame
Definition GuiTypes.h:382
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
#define ClassDef(name, id)
Definition Rtypes.h:342
@ kRed
Definition Rtypes.h:66
@ kButtonUp
Definition TGButton.h:53
#define gClient
Definition TGClient.h:157
@ kDoubleScaleBoth
@ kDeepCleanup
Definition TGFrame.h:42
@ kLHintsRight
Definition TGLayout.h:26
@ kLHintsExpandY
Definition TGLayout.h:31
@ kLHintsLeft
Definition TGLayout.h:24
@ kLHintsCenterX
Definition TGLayout.h:25
@ kLHintsTop
Definition TGLayout.h:27
@ kLHintsExpandX
Definition TGLayout.h:30
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
Option_t Option_t TPoint TPoint const char text
R__EXTERN void * gTQSender
Definition TQObject.h:46
1-Dim function class
Definition TF1.h:233
A button abstract base class.
Definition TGButton.h:68
Selects different options.
Definition TGButton.h:264
A composite frame that layout their children in horizontal way.
Definition TGFrame.h:385
This class describes layout hints used by the layout classes.
Definition TGLayout.h:50
Defines top level windows that interact with the system Window Manager.
Definition TGFrame.h:397
virtual void CloseWindow()
Close and delete main frame.
Definition TGFrame.cxx:1770
A text buffer is used in several widgets, like TGTextEntry, TGFileDialog, etc.
A TGTextEntry is a one line text input widget.
Definition TGTextEntry.h:24
TripleSlider inherit from DoubleSlider widgets and allow easy selection of a min, max and pointer val...
Int_t WidgetId() const
Definition TGWidget.h:68
This class creates a TGCanvas in which a TCanvas is created.