Logo ROOT  
Reference Guide
statusBar.C File Reference

Detailed Description

This macro gives an example of how to create a status bar related to an embedded canvas that shows the info of the selected object, exactly as the status bar of any canvas window. To run it do either:

.x statusBar.C
.x statusBar.C++
#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TFrame.h>
#include <TGStatusBar.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TRandom.h>
#include <TGraph.h>
#include <TAxis.h>
class MyMainFrame : public TGMainFrame {
private:
TGStatusBar *fStatusBar;
public:
MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
virtual ~MyMainFrame();
void DoExit();
void DoDraw();
void SetStatusText(const char *txt, Int_t pi);
void EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected);
ClassDef(MyMainFrame, 0)
};
void MyMainFrame::DoDraw()
{
// Draw something in the canvas
Printf("Slot DoDraw()");
TCanvas *c1 = fEcan->GetCanvas();
c1->SetFillColor(42);
c1->SetGrid();
const Int_t n = 20;
Double_t x[n], y[n];
for (Int_t i=0;i<n;i++) {
x[i] = i*0.1;
y[i] = 10*sin(x[i]+0.2);
printf(" i %i %f %f \n",i,x[i],y[i]);
}
TGraph *gr = new TGraph(n,x,y);
gr->SetLineColor(2);
gr->SetLineWidth(4);
gr->SetMarkerColor(4);
gr->SetMarkerStyle(21);
gr->SetTitle("a simple graph");
gr->GetXaxis()->SetTitle("X title");
gr->GetYaxis()->SetTitle("Y title");
gr->Draw("ACP");
// TCanvas::Update() draws the frame, after which it can be changed
c1->Update();
c1->GetFrame()->SetFillColor(21);
c1->GetFrame()->SetBorderSize(12);
c1->Modified();
c1->Update();
}
void MyMainFrame::DoExit()
{
printf("Exit application...");
}
void MyMainFrame::SetStatusText(const char *txt, Int_t pi)
{
// Set text in status bar.
fStatusBar->SetText(txt,pi);
}
void MyMainFrame::EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
{
// Writes the event status in the status bar parts
const char *text0, *text1, *text3;
char text2[50];
text0 = selected->GetTitle();
SetStatusText(text0,0);
text1 = selected->GetName();
SetStatusText(text1,1);
if (event == kKeyPress)
sprintf(text2, "%c", (char) px);
else
sprintf(text2, "%d,%d", px, py);
SetStatusText(text2,2);
text3 = selected->GetObjectInfo(px,py);
SetStatusText(text3,3);
}
MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) :
TGMainFrame(p, w, h)
{
// Create the embedded canvas
fEcan = new TRootEmbeddedCanvas(0,this,500,400);
Int_t wid = fEcan->GetCanvasWindowId();
TCanvas *myc = new TCanvas("MyCanvas", 10,10,wid);
fEcan->AdoptCanvas(myc);
myc->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)","MyMainFrame",this,
"EventInfo(Int_t,Int_t,Int_t,TObject*)");
AddFrame(fEcan, new TGLayoutHints(kLHintsTop | kLHintsLeft |
// status bar
Int_t parts[] = {45, 15, 10, 30};
fStatusBar = new TGStatusBar(this, 50, 10, kVerticalFrame);
fStatusBar->SetParts(parts, 4);
fStatusBar->Draw3DCorner(kFALSE);
AddFrame(fStatusBar, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
// Create a horizontal frame containing two buttons
TGHorizontalFrame *hframe = new TGHorizontalFrame(this, 200, 40);
TGTextButton *draw = new TGTextButton(hframe, "&Draw");
draw->Connect("Clicked()", "MyMainFrame", this, "DoDraw()");
hframe->AddFrame(draw, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
TGTextButton *exit = new TGTextButton(hframe, "&Exit ");
exit->Connect("Pressed()", "MyMainFrame", this, "DoExit()");
hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
AddFrame(hframe, new TGLayoutHints(kLHintsCenterX, 2, 2, 2, 2));
// Set a name to the main frame
SetWindowName("Embedded Canvas Status Info");
MapSubwindows();
// Initialize the layout algorithm via Resize()
Resize(GetDefaultSize());
// Map main frame
MapWindow();
}
MyMainFrame::~MyMainFrame()
{
// Clean up main frame...
Cleanup();
delete fEcan;
}
void statusBar()
{
// Popup the GUI...
new MyMainFrame(gClient->GetRoot(), 200, 200);
}
Author
Ilka Antcheva 1/12/2006

Definition in file statusBar.C.

n
const Int_t n
Definition: legend1.C:16
TGWindow
Definition: TGWindow.h:31
kLHintsCenterX
@ kLHintsCenterX
Definition: TGLayout.h:38
TGMainFrame
Definition: TGFrame.h:444
TGraph::SetTitle
virtual void SetTitle(const char *title="")
Change (i.e.
Definition: TGraph.cxx:2324
TGraph::Draw
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:760
kLHintsTop
@ kLHintsTop
Definition: TGLayout.h:40
kVerticalFrame
@ kVerticalFrame
Definition: GuiTypes.h:381
TGraph.h
TGStatusBar.h
kLHintsLeft
@ kLHintsLeft
Definition: TGLayout.h:37
TRandom.h
TObject::GetObjectInfo
virtual char * GetObjectInfo(Int_t px, Int_t py) const
Returns string containing info about the object at position (px,py).
Definition: TObject.cxx:388
TGTextButton
Definition: TGButton.h:142
Int_t
int Int_t
Definition: RtypesCore.h:45
sin
double sin(double)
x
Double_t x[n]
Definition: legend1.C:17
TGHorizontalFrame
Definition: TGFrame.h:423
TObject::GetTitle
virtual const char * GetTitle() const
Returns title of object.
Definition: TObject.cxx:403
TCanvas.h
TGraph::GetYaxis
TAxis * GetYaxis() const
Get y axis of the graph.
Definition: TGraph.cxx:1636
TGStatusBar
Definition: TGStatusBar.h:29
gClient
#define gClient
Definition: TGClient.h:166
TApplication.h
TObject::GetName
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:359
TGraph::GetXaxis
TAxis * GetXaxis() const
Get x axis of the graph.
Definition: TGraph.cxx:1626
h
#define h(i)
Definition: RSha256.hxx:124
gr
TGraphErrors * gr
Definition: legend1.C:25
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TGFrame.h
TGLayoutHints
Definition: TGLayout.h:57
gApplication
R__EXTERN TApplication * gApplication
Definition: TApplication.h:166
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
y
Double_t y[n]
Definition: legend1.C:17
TApplication::Terminate
virtual void Terminate(Int_t status=0)
kLHintsExpandY
@ kLHintsExpandY
Definition: TGLayout.h:44
TGClient.h
TNamed::SetTitle
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
TRootEmbeddedCanvas.h
Printf
void Printf(const char *fmt,...)
Double_t
double Double_t
Definition: RtypesCore.h:59
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
TGraph
Definition: TGraph.h:41
TF1.h
TCanvas
Definition: TCanvas.h:23
TGeant4Unit::pi
static constexpr double pi
Definition: TGeant4SystemOfUnits.h:73
TAxis.h
TObject
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGButton.h
TFrame.h
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:43
kKeyPress
@ kKeyPress
Definition: Buttons.h:26
TGCompositeFrame::AddFrame
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
Add frame to the composite frame using the specified layout hints.
Definition: TGFrame.cxx:1102
TRootEmbeddedCanvas
Definition: TRootEmbeddedCanvas.h:32
c1
return c1
Definition: legend1.C:41