/****************************************************************************** * 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/PH/SFT) * *Site Contact: roottalk@cern.ch or http://root.cern.ch/phpBB2/ * *ROOT Version: 3.05/10 * * Last Change: 21/11/2003 * ******************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include 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()"); 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;iSetLineColor(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"); */ TF2 *f2 = new TF2("f2","xygaus + xygaus(5) + xylandau(10)",-4,4,-4,4); Double_t params[] = {130,-1.4,1.8,1.5,1, 150,2,0.5,-2,0.5, 3600,-2,0.7,-3,0.3}; f2->SetParameters(params); TH2F *h2 = new TH2F("h2","xygaus + xygaus(5) + xylandau(10)",20,-4,4,20,-4,4); h2->SetFillColor(46); h2->FillRandom("f2",40000); h2->Draw("surf1"); // 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(); c1->ToggleEditor(); c1->Selected(c1,h2,1); } 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()"); 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[] = {20, 10, 10, 60}; fStatusBar = new TGStatusBar(fMain, 50, 10, kVerticalFrame); fStatusBar->SetParts(parts, 4); fStatusBar->Draw3DCorner(kFALSE); 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 fMain; } void embstatTH2() { // Popup the GUI... new MyMainFrame(gClient->GetRoot(), 500, 700); }