// example.C #include #include #include #include #include #include #include #include #include class MyMainFrame : public TGMainFrame { private: Int_t fCounter; TRootEmbeddedCanvas *fEcanvas; TTimer *fTimer; TGraph *fGraph; TGTextButton *fDraw; public: MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h); virtual ~MyMainFrame(); void DoDraw(); Bool_t HandleTimer(TTimer *t); ClassDef(MyMainFrame, 0) }; MyMainFrame *gMyMainFrame; MyMainFrame::MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h) : TGMainFrame(p,w,h) { #ifdef __CINT__ fTimer = new TTimer(1000); fTimer->SetCommand("gMyMainFrame->HandleTimer(0)"); #else fTimer = new TTimer(this, 1000); #endif fGraph = new TGraph(); fCounter = 0; // Create canvas widget fEcanvas = new TRootEmbeddedCanvas("Ecanvas",this,200,200); AddFrame(fEcanvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10,10,10,1)); // Create a horizontal frame widget with buttons TGHorizontalFrame *hframe = new TGHorizontalFrame(this,200,40); fDraw = new TGTextButton(hframe, "&Start"); fDraw->Connect("Clicked()","MyMainFrame",this,"DoDraw()"); hframe->AddFrame(fDraw, new TGLayoutHints(kLHintsCenterX,5,5,3,4)); TGTextButton *exit = new TGTextButton(hframe,"&Exit","gApplication->Terminate(0)"); 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("Simple Example"); // Map all subwindows of main frame MapSubwindows(); // Initialize the layout algorithm Resize(GetDefaultSize()); // Map main frame MapWindow(); } //______________________________________________________________________________ Bool_t MyMainFrame::HandleTimer(TTimer *t) { // Handle timer event and draws function graphics TCanvas *fCanvas = fEcanvas->GetCanvas(); fGraph->SetPoint(fCounter, fCounter, fCounter*2); fCanvas->cd(); if (fCounter == 0) { fCanvas->Clear(); fGraph->Draw("al"); } fCanvas->Update(); fCounter++; fTimer->Reset(); if (fCounter >= 50) fTimer->TurnOff(); return kTRUE; } void MyMainFrame::DoDraw() { // Reset counter and graph, reset and start timer static Bool_t running = kFALSE; if (!running) { fDraw->SetText("&Stop"); fTimer->Reset(); fTimer->TurnOn(); running = kTRUE; } else { fDraw->SetText("&Start"); fTimer->Reset(); fTimer->TurnOff(); running = kFALSE; } } MyMainFrame::~MyMainFrame() { // Clean up used widgets: frames, buttons, layouthints Cleanup(); } void timer_example() { // Popup the GUI... gMyMainFrame = new MyMainFrame(gClient->GetRoot(),200,200); }