Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
statusBar.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gui
3/// This macro gives an example of how to create a status bar related to an embedded canvas that shows the info of the
4/// selected object, exactly as the status bar of any canvas window. To run it do either:
5/// ~~~
6/// .x statusBar.C
7/// .x statusBar.C++
8/// ~~~
9///
10/// \macro_code
11///
12/// \author Ilka Antcheva 1/12/2006
13
14#include <TApplication.h>
15#include <TGClient.h>
16#include <TGButton.h>
17#include <TGFrame.h>
18#include <TFrame.h>
19#include <TRootEmbeddedCanvas.h>
20#include <TGStatusBar.h>
21#include <TCanvas.h>
22#include <TF1.h>
23#include <TRandom.h>
24#include <TGraph.h>
25#include <TAxis.h>
26
27class MyMainFrame : public TGMainFrame {
28
29private:
31 TGStatusBar *fStatusBar;
32
33public:
34 MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
35 ~MyMainFrame() override;
36 void DoExit();
37 void DoDraw();
38 void SetStatusText(const char *txt, Int_t pi);
39 void EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected);
40
41 ClassDefOverride(MyMainFrame, 0)
42};
43
44void MyMainFrame::DoDraw()
45{
46 // Draw something in the canvas
47
48 Printf("Slot DoDraw()");
49
50 TCanvas *c1 = fEcan->GetCanvas();
51 c1->SetFillColor(42);
52 c1->SetGrid();
53 const Int_t n = 20;
54 Double_t x[n], y[n];
55 for (Int_t i = 0; i < n; i++) {
56 x[i] = i * 0.1;
57 y[i] = 10 * sin(x[i] + 0.2);
58 printf(" i %i %f %f \n", i, x[i], y[i]);
59 }
60 TGraph *gr = new TGraph(n, x, y);
61 gr->SetLineColor(2);
62 gr->SetLineWidth(4);
64 gr->SetMarkerStyle(21);
65 gr->SetTitle("a simple graph");
66 gr->GetXaxis()->SetTitle("X title");
67 gr->GetYaxis()->SetTitle("Y title");
68 gr->Draw("ACP");
69
70 // TCanvas::Update() draws the frame, after which it can be changed
71 c1->Update();
72 c1->GetFrame()->SetFillColor(21);
73 c1->GetFrame()->SetBorderSize(12);
74 c1->Modified();
75 c1->Update();
76}
77
78void MyMainFrame::DoExit()
79{
80 printf("Exit application...");
82}
83
84void MyMainFrame::SetStatusText(const char *txt, Int_t pi)
85{
86 // Set text in status bar.
87 fStatusBar->SetText(txt, pi);
88}
89
90void MyMainFrame::EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
91{
92 // Writes the event status in the status bar parts
93
94 const char *text0, *text1, *text3;
95 char text2[50];
96 text0 = selected->GetTitle();
97 SetStatusText(text0, 0);
98 text1 = selected->GetName();
99 SetStatusText(text1, 1);
100 if (event == kKeyPress)
101 sprintf(text2, "%c", (char)px);
102 else
103 sprintf(text2, "%d,%d", px, py);
104 SetStatusText(text2, 2);
105 text3 = selected->GetObjectInfo(px, py);
106 SetStatusText(text3, 3);
107}
108
109MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) : TGMainFrame(p, w, h)
110{
111 // Create the embedded canvas
112 fEcan = new TRootEmbeddedCanvas(nullptr, this, 500, 400);
113 Int_t wid = fEcan->GetCanvasWindowId();
114 TCanvas *myc = new TCanvas("MyCanvas", 10, 10, wid);
115 fEcan->AdoptCanvas(myc);
116 myc->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "MyMainFrame", this,
117 "EventInfo(Int_t,Int_t,Int_t,TObject*)");
118
119 AddFrame(fEcan, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 0, 1, 1));
120 // status bar
121 Int_t parts[] = {45, 15, 10, 30};
122 fStatusBar = new TGStatusBar(this, 50, 10, kVerticalFrame);
123 fStatusBar->SetParts(parts, 4);
124 fStatusBar->Draw3DCorner(kFALSE);
125 AddFrame(fStatusBar, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
126
127 // Create a horizontal frame containing two buttons
128 TGHorizontalFrame *hframe = new TGHorizontalFrame(this, 200, 40);
129
130 TGTextButton *draw = new TGTextButton(hframe, "&Draw");
131 draw->Connect("Clicked()", "MyMainFrame", this, "DoDraw()");
132 hframe->AddFrame(draw, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
133 TGTextButton *exit = new TGTextButton(hframe, "&Exit ");
134 exit->Connect("Pressed()", "MyMainFrame", this, "DoExit()");
135 hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
136
137 AddFrame(hframe, new TGLayoutHints(kLHintsCenterX, 2, 2, 2, 2));
138
139 // Set a name to the main frame
140 SetWindowName("Embedded Canvas Status Info");
142
143 // Initialize the layout algorithm via Resize()
144 Resize(GetDefaultSize());
145
146 // Map main frame
147 MapWindow();
148}
149
150MyMainFrame::~MyMainFrame()
151{
152 // Clean up main frame...
153 Cleanup();
154 delete fEcan;
155}
156
157void statusBar()
158{
159 // Popup the GUI...
160 new MyMainFrame(gClient->GetRoot(), 200, 200);
161}
@ kKeyPress
Definition Buttons.h:20
@ kVerticalFrame
Definition GuiTypes.h:381
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
double Double_t
Definition RtypesCore.h:59
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
R__EXTERN TApplication * gApplication
#define gClient
Definition TGClient.h:157
@ 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
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize wid
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition TString.cxx:2503
virtual void Terminate(Int_t status=0)
Terminate the application by call TSystem::Exit() unless application has been told to return from Run...
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:38
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:40
The Canvas class.
Definition TCanvas.h:23
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=nullptr)
Add frame to the composite frame using the specified layout hints.
Definition TGFrame.cxx:1117
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
Provides a StatusBar widget.
Definition TGStatusBar.h:21
Yield an action as soon as it is clicked.
Definition TGButton.h:142
ROOT GUI Window base class.
Definition TGWindow.h:23
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
Definition TGraph.cxx:833
TAxis * GetXaxis() const
Get x axis of the graph.
Definition TGraph.cxx:1568
TAxis * GetYaxis() const
Get y axis of the graph.
Definition TGraph.cxx:1577
void SetTitle(const char *title="") override
Change (i.e.
Definition TGraph.cxx:2402
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
Mother of all ROOT objects.
Definition TObject.h:41
virtual const char * GetName() const
Returns name of object.
Definition TObject.cxx:456
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Returns string containing info about the object at position (px,py).
Definition TObject.cxx:485
virtual const char * GetTitle() const
Returns title of object.
Definition TObject.cxx:500
TCanvas * GetCanvas() const override
Definition TPad.h:262
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:869
This class creates a TGCanvas in which a TCanvas is created.
RVec< PromoteType< T > > sin(const RVec< T > &v)
Definition RVec.hxx:1851
Double_t y[n]
Definition legend1.C:17
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TGraphErrors * gr
Definition legend1.C:25