//************ File MakeEx2a ***************************** rootcint -f ex2aDict.cxx -c example2a.h ex2aLinkDef.h g++ `root-config --cflags --glibs` -o example2a example2a.cxx ex2aDict.cxx //************ File ex2aLinkDef.h ************************ #pragma link C++ class MyMainFrame; //************ File example2a.h ************************** #include #include class TGWindow; class TGMainFrame; class TRootEmbeddedCanvas; class MyMainFrame { RQ_OBJECT("MyMainFrame") private: TGMainFrame *fMain; TRootEmbeddedCanvas *fEcanvas; public: MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h); virtual ~MyMainFrame(); void DoDraw(); }; //************ File example2a.cxx ************************ #include #include #include #include #include #include #include #include #include #include "example2a.h" MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) { // Create a main frame fMain = new TGMainFrame(p, w, h); // Create an embedded canvas and add it to the main frame fEcanvas = new TRootEmbeddedCanvas ("Ecanvas", fMain, 200, 200); fMain->AddFrame(fEcanvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10, 10, 10, 1)); // 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 ","gApplication->Terminate()"); 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("Simple Example"); fMain->MapSubwindows(); // Initialize the layout algorithm via Resize() fMain->Resize(fMain->GetDefaultSize()); // Map main frame fMain->MapWindow(); } MyMainFrame::~MyMainFrame() { // Clean up all widgets, frames and layouthints that were used fMain->Cleanup(); delete fMain; } void MyMainFrame::DoDraw() { // Draw a function 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 *canvas = fEcanvas->GetCanvas(); canvas->cd(); canvas->Update(); } void example() { // Popup the GUI... new MyMainFrame(gClient->GetRoot(), 400, 500); } int main(int argc, char **argv) { // Main program. Initialize application environment. TApplication theApp("App", &argc, argv); example(); theApp.Run(); return 0; }