Hi Thomas,
Please find an example in the attached macro embstat.C.
Just run the macro (.x embstat.C); click on the Draw button to have some
drowing in the canvas; click on Exit - to exit root.
Best regards, Ilka
Thomas Bretz wrote:
> Dear all,
>
> I have implemented my own display containing a TEmbeddedCanvas. Now I
> would like to implement a 'status line' like the one which is
> implemented in TCanvas into my display. This status line should
> display the GetObjectInfo from the object in the canvas like in
> TCanvas. How can I 'redirect' the GetObjectInfo to my own status line?
>
> Thanks in advance,
> Thomas.
>
/******************************************************************************
* File: embstat.C *
* Description: macro file to test embedded canvas and status bar widgets *
* This macro gives an example of how to collect the info of *
* the selected canvas object and show this info via the *
* status bar *
* Author: Ilka Antcheva (CERN/EP/SFT) *
*Site Contact: roottalk@cern.ch *
*ROOT Version: 3.05/10 *
* Last Change: 21/11/2003 *
******************************************************************************/
#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TRootEmbeddedCanvas.h>
#include <TGStatusBar.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TRandom.h>
#include <RQ_OBJECT.h>
class MyMainFrame {
RQ_OBJECT("MyMainFrame")
private:
TGMainFrame *fMain;
TRootEmbeddedCanvas *fEcan;
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);
};
void MyMainFrame::DoDraw()
{
// Draw a function
Printf("Slot DoDraw()");
static TF1 *f1 = 0;
if (f1) delete f1;
f1 = new TF1("f1", "sin(x)/x", 0, gRandom->Rndm()*10);
f1->SetFillColor(19);
f1->SetFillStyle(1);
f1->SetLineWidth(3);
f1->Draw();
TCanvas *fCanvas = fEcan->GetCanvas();
fCanvas->cd();
fCanvas->Update();
}
void MyMainFrame::DoExit()
{
Printf("Slot DoExit()");
gApplication->Terminate(0);
}
// Widget methods here...
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
//Printf("Slot EventInfo()");
TCanvas *c = (TCanvas *) gTQSender;
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)
{
// Create the main frame
fMain = new TGMainFrame(p,w,h);
// Create the embedded canvas
fEcan = new TRootEmbeddedCanvas(0,fMain,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*)");
fMain->AddFrame(fEcan, new TGLayoutHints(kLHintsTop | kLHintsLeft
| kLHintsExpandX | kLHintsExpandY,0,0,1,1));
// status bar
Int_t parts[] = {45, 15, 10, 30};
fStatusBar = new TGStatusBar(fMain, 50, 10, kVerticalFrame);
fStatusBar->SetParts(parts, 4);
fMain->AddFrame(fStatusBar, new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
// Create a horizontal frame containing two buttons
TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain, 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));
fMain->AddFrame(hframe, new TGLayoutHints(kLHintsCenterX, 2, 2, 2, 2));
// Set a name to the main frame
fMain->SetWindowName("Embedded Canvas Status Info");
fMain->MapSubwindows();
// Initialize the layout algorithm via Resize()
fMain->Resize(fMain->GetDefaultSize());
// Map main frame
fMain->MapWindow();
}
MyMainFrame::~MyMainFrame()
{
// Clean up main frame...
fMain->Cleanup();
delete fEcan;
delete fStatusBar;
delete fMain;
}
void embstat()
{
// Popup the GUI...
new MyMainFrame(gClient->GetRoot(), 200, 200);
}
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:05 MET