-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappframe.cxx
197 lines (152 loc) · 4.77 KB
/
appframe.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// example.C
#include <TGClient.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TRandom.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TRootEmbeddedCanvas.h>
#include <RQ_OBJECT.h>
#include <TROOT.h>
#include <TApplication.h>
#include <TMutex.h>
#include "appframe.h"
extern TMutex *g_mtx_disp;
AppFrame::AppFrame(const TGWindow *p, UInt_t w, UInt_t h) {
// Create a main frame
fMain = new TGMainFrame(p, w, h);
TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain, 480, 360);
fMain->AddFrame(hframe,
new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
// Create canvas widget
fEcanvas = new TRootEmbeddedCanvas("Ecanvas", hframe, 480, 360);
hframe->AddFrame(fEcanvas,
new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 4, 4, 4, 4));
// Create a horizontal frame widget with buttons
TGVerticalFrame *vframe = new TGVerticalFrame(hframe, 60, 300);
TGTextButton *bdraw = new TGTextButton(vframe, "&Run/Stop");
//bdraw->Connect("Clicked()", "AppFrame", this, "DoDraw()");
bdraw->Connect("Clicked()", "AppFrame", this, "ToggleRunState()");
vframe->AddFrame(bdraw,
new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 2, 4, 4, 4));
TGTextButton *btoggle = new TGTextButton(vframe, "&Y-Scale");
btoggle->Connect("Clicked()", "AppFrame", this, "ToggleScale()");
vframe->AddFrame(btoggle,
new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 2, 4, 4, 4));
TGTextButton *bxscale = new TGTextButton(vframe, "&X-scale");
bxscale->Connect("Clicked()", "AppFrame", this, "ToggleXScale()");
vframe->AddFrame(bxscale,
new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 2, 4, 4, 4));
TGCheckButton* bcheck[8];
for (int i = 0 ; i < 8 ; i++) {
char title[8];
title[0] = '0' + i;
title[1] = '\0';
bcheck[i] = new TGCheckButton(vframe, title, 70 + i);
vframe->AddFrame(bcheck[i],
new TGLayoutHints(kLHintsCenterX | kLHintsExpandX, 2, 4, 4, 4));
bcheck[i]->Connect("Toggled(Bool_t)", "AppFrame", this, "DoEnableCh()");
}
TGTextButton *bexit = new TGTextButton(vframe,"&Exit",
"gApplication->Terminate(0)");
vframe->AddFrame(bexit,
new TGLayoutHints(
//kLHintsCenterX | kLHintsExpandX | kLHintsBottom,
kLHintsExpandX | kLHintsBottom,
2, 4, 4, 4));
TGTextButton *bprint = new TGTextButton(vframe,"&Print");
bprint->Connect("Clicked()", "AppFrame", this, "PrintCanvas()");
vframe->AddFrame(bprint,
new TGLayoutHints(
//kLHintsCenterX | kLHintsExpandX | kLHintsBottom,
kLHintsExpandX | kLHintsBottom,
2, 4, 4, 4));
hframe->AddFrame(vframe,
new TGLayoutHints(kLHintsRight | kLHintsExpandY, 0, 0, 0, 0));
// Set a name to the main frame
hframe->SetWindowName("App Frame");
// Map all subwindows of main frame
fMain->MapSubwindows();
// Initialize the layout algorithm
fMain->Resize(fMain->GetDefaultSize());
// Map main frame
fMain->MapWindow();
}
AppFrame::~AppFrame() {
// Clean up used widgets: frames, buttons, layout hints
fMain->Cleanup();
delete fMain;
}
TCanvas* AppFrame::GetCanvas() {
return fEcanvas->GetCanvas();
}
ClassImp(AppFrame);
void AppFrame::DoDraw() {
// Draws function graphics in randomly chosen interval
TF1 *f1 = new TF1("f1","sin(x)/x",0,gRandom->Rndm()*10);
f1->SetLineWidth(3);
f1->Draw();
TCanvas *fCanvas = fEcanvas->GetCanvas();
fCanvas->cd();
fCanvas->Update();
}
bool AppFrame::ToggleRunState() {
m_run_state = (! m_run_state);
return m_run_state;
}
bool AppFrame::GetRunState() {
return m_run_state;
}
int AppFrame::ToggleScale() {
const int scale_factor[] = {512, 256, 128, 64, 32, 16};
static int sf_index = 0;
if (++sf_index > 5) sf_index = 0;
m_scale = scale_factor[sf_index];
//std::cout << "#D scale " << sf_index << " " << m_scale << std::endl;
return m_scale;
}
int AppFrame::GetScale() {
return m_scale;
}
int AppFrame::ToggleXScale() {
const int scale_factor[] = {512, 256, 128, 64, 32, 16};
static int sf_index = 0;
if (++sf_index > 5) sf_index = 0;
m_xscale = scale_factor[sf_index];
//std::cout << "#D xscale " << sf_index << " " << m_xscale << std::endl;
return m_xscale;
}
int AppFrame::GetXScale() {
return m_xscale;
}
bool* AppFrame::DoEnableCh() {
TGButton *btn = (TGButton *) gTQSender;
int id = btn->WidgetId();
//std::cout << "DoButton: id = " << id << std::endl;
int button = id - 70;
m_enable_ch[button] = ! m_enable_ch[button];
for (int i = 0 ; i < 8 ; i++) std::cout << " " << m_enable_ch[i] << " ";
for (int i = 0 ; i < 8 ; i++) {
if (m_enable_ch[i] == true) {
std::cout << "O";
} else {
std::cout << "-";
}
}
std::cout << std::endl;
return m_enable_ch;
}
bool* AppFrame::GetEnableCh() {
return m_enable_ch;
}
void AppFrame::PrintCanvas() {
TCanvas *c = fEcanvas->GetCanvas();
c->Print("display.png", "png");
c->Print("display.pdf", "pdf");
return;
}
void AppFrame::Exit() {
delete g_mtx_disp;
gApplication->Terminate(0);
return;
}