30 class MyMainFrame :
public TGMainFrame {
33 TRootEmbeddedCanvas *fEcan;
34 TGStatusBar *fStatusBar;
37 MyMainFrame(
const TGWindow *p, UInt_t w, UInt_t h);
38 virtual ~MyMainFrame();
41 void SetStatusText(
const char *txt, Int_t pi);
42 void EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected);
44 ClassDef(MyMainFrame, 0)
47 void MyMainFrame::DoDraw()
51 Printf(
"Slot DoDraw()");
53 TCanvas *c1 = fEcan->GetCanvas();
58 for (Int_t i=0;i<n;i++) {
60 y[i] = 10*sin(x[i]+0.2);
61 printf(
" i %i %f %f \n",i,x[i],y[i]);
63 TGraph *gr =
new TGraph(n,x,y);
66 gr->SetMarkerColor(4);
67 gr->SetMarkerStyle(21);
68 gr->SetTitle(
"a simple graph");
69 gr->GetXaxis()->SetTitle(
"X title");
70 gr->GetYaxis()->SetTitle(
"Y title");
75 c1->GetFrame()->SetFillColor(21);
76 c1->GetFrame()->SetBorderSize(12);
81 void MyMainFrame::DoExit()
83 printf(
"Exit application...");
84 gApplication->Terminate(0);
87 void MyMainFrame::SetStatusText(
const char *txt, Int_t pi)
90 fStatusBar->SetText(txt,pi);
93 void MyMainFrame::EventInfo(Int_t event, Int_t px, Int_t py, TObject *selected)
97 const char *text0, *text1, *text3;
99 text0 = selected->GetTitle();
100 SetStatusText(text0,0);
101 text1 = selected->GetName();
102 SetStatusText(text1,1);
103 if (event == kKeyPress)
104 sprintf(text2,
"%c", (
char) px);
106 sprintf(text2,
"%d,%d", px, py);
107 SetStatusText(text2,2);
108 text3 = selected->GetObjectInfo(px,py);
109 SetStatusText(text3,3);
112 MyMainFrame::MyMainFrame(
const TGWindow *p, UInt_t w, UInt_t h) :
116 fEcan =
new TRootEmbeddedCanvas(0,
this,500,400);
117 Int_t wid = fEcan->GetCanvasWindowId();
118 TCanvas *myc =
new TCanvas(
"MyCanvas", 10,10,wid);
119 fEcan->AdoptCanvas(myc);
120 myc->Connect(
"ProcessedEvent(Int_t,Int_t,Int_t,TObject*)",
"MyMainFrame",
this,
121 "EventInfo(Int_t,Int_t,Int_t,TObject*)");
123 AddFrame(fEcan,
new TGLayoutHints(kLHintsTop | kLHintsLeft |
124 kLHintsExpandX | kLHintsExpandY,0,0,1,1));
126 Int_t parts[] = {45, 15, 10, 30};
127 fStatusBar =
new TGStatusBar(
this, 50, 10, kVerticalFrame);
128 fStatusBar->SetParts(parts, 4);
129 fStatusBar->Draw3DCorner(kFALSE);
130 AddFrame(fStatusBar,
new TGLayoutHints(kLHintsExpandX, 0, 0, 10, 0));
133 TGHorizontalFrame *hframe =
new TGHorizontalFrame(
this, 200, 40);
135 TGTextButton *draw =
new TGTextButton(hframe,
"&Draw");
136 draw->Connect(
"Clicked()",
"MyMainFrame",
this,
"DoDraw()");
137 hframe->AddFrame(draw,
new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
138 TGTextButton *exit =
new TGTextButton(hframe,
"&Exit ");
139 exit->Connect(
"Pressed()",
"MyMainFrame",
this,
"DoExit()");
140 hframe->AddFrame(exit,
new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
142 AddFrame(hframe,
new TGLayoutHints(kLHintsCenterX, 2, 2, 2, 2));
145 SetWindowName(
"Embedded Canvas Status Info");
149 Resize(GetDefaultSize());
156 MyMainFrame::~MyMainFrame()
167 new MyMainFrame(gClient->GetRoot(), 200, 200);