// examplebb.C #include #include #include #include #include #include #include #include class MyMainFrame { RQ_OBJECT("MyMainFrame") private: TGMainFrame *fMain; TRootEmbeddedCanvas *fEcanvas; TGToolTip *fTip; public: MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h); virtual ~MyMainFrame(); void EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected); void DoClose(); void DoDraw(); }; //______________________________________________________________________ MyMainFrame::MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h) { // Create a main frame fMain = new TGMainFrame(p,w,h); fMain->SetCleanup(kDeepCleanup); fMain->Connect("CloseWindow()", "MyMainFrame", this, "DoClose()"); fMain->DontCallClose(); // to avoid double deletions. // Create canvas widget fEcanvas = new TRootEmbeddedCanvas("Ecanvas",fMain,200,200); fMain->AddFrame(fEcanvas, new TGLayoutHints(kLHintsExpandX| kLHintsExpandY, 10,10,10,1)); // create the tooltip with a timeout of 250 ms fTip = new TGToolTip(gClient->GetDefaultRoot(), fEcanvas, "", 250); // connect to the ProcessedEvent signal to fire up the tooltip fEcanvas->GetCanvas()->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "MyMainFrame",this, "EventInfo(Int_t,Int_t,Int_t,TObject*)"); // Create a horizontal frame widget with 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("Clicked()","MyMainFrame",this,"DoClose()"); 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"); // Map all subwindows of main frame fMain->MapSubwindows(); // Initialize the layout algorithm fMain->Resize(fMain->GetDefaultSize()); // Map main frame fMain->MapWindow(); } //______________________________________________________________________ MyMainFrame::~MyMainFrame() { // Clean up used widgets: frames, buttons, layouthints fMain->CloseWindow(); } //______________________________________________________________________ void MyMainFrame::DoClose() { // Close window slot: delete this and really close the window fTip->Hide(); delete fTip; delete this; } //______________________________________________________________________ void MyMainFrame::DoDraw() { // Draws function graphics in randomly choosen interval TCanvas *c1 = fEcanvas->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"); // TCanvas::Update() draws the frame, after which one can change it c1->Update(); c1->GetFrame()->SetFillColor(21); c1->GetFrame()->SetBorderSize(12); c1->Modified(); } //______________________________________________________________________ void MyMainFrame::EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected) { // Display a tooltip with several informations on the object // under the mouse pointer fTip->Hide(); if (event == kMouseLeave) return; if (selected && selected->InheritsFrom("TGraph")) { fTip->SetText(TString::Format("%s\n%s\n%s\n%s", selected->ClassName(), selected->GetName(), selected->GetTitle(), selected->GetObjectInfo(px, py))); fTip->SetPosition(px+15, py+15); fTip->Reset(); } } //______________________________________________________________________ void tooltip_info() { // Popup the GUI... new MyMainFrame(gClient->GetRoot(),200,200); }