BOSS 7.0.5
BESIII Offline Software System
Loading...
Searching...
No Matches
BesPaveText.cxx
Go to the documentation of this file.
1
2#include <TPad.h>
3#include "BesVisLib/BesPaveText.h"
4#include <iostream>
5
6using namespace std;
7
8#ifndef __CINT__
10#endif
11
12//______________________________________________________________________________
13BesPaveText::BesPaveText(): TPaveText()
14{
15}
16
17//______________________________________________________________________________
18BesPaveText::BesPaveText(Double_t x1, Double_t y1,Double_t x2, Double_t y2, Option_t *option)
19 :TPaveText(x1,y1,x2,y2,option)
20{
21 SetFillColor(1001);
22 SetBorderSize(1);
23 SetCornerRadius(0.2);
24
25 fTextSize = 0.025;
26}
27
28//______________________________________________________________________________
29BesPaveText::BesPaveText(const BesPaveText &pavetext) : TPaveText()
30{
31
32}
33
34//______________________________________________________________________________
35void BesPaveText::SetText(vector<TString> infoCon)
36{
37 Int_t n = infoCon.size();
38 Double_t margin = GetMargin();
39 Double_t dy = (1.0 - margin * 2) / n;
40
41 //Long Peixun's update: If the number of lines is 2, add an empty line to avoid text out of box.
42 if (n == 2) dy = (1.0 - margin * 2) / 3;
43
44 Double_t coordx = 0.0;
45 Double_t coordy = 0.0;
46 for (Int_t i = 0; i < n; i++) {
47 coordy = 1.0 - (i + 1) * dy;
48 if (n == 1) coordy = 1.0;
49
50 TText* tdata = AddText(coordx, coordy, infoCon[i].Data());
51 tdata->SetTextSize(fTextSize/1.2);
52 tdata->SetTextFont(42);
53 if (i == 0 && n > 4) {
54 tdata->SetTextSize(fTextSize);
55 tdata->SetTextFont(62);
56 }
57 tdata->SetTextColor(1);
58 tdata->SetTextAlign(12);
59
60 if (infoCon[i] == TString("Fired")) {
61 tdata->SetTextColor(kRed);
62 //tdata->SetTextSize(fTextSize);
63 tdata->SetTextFont(72);
64 }
65 }
66 //Long Peixun's update: If the number of lines is 2, add an empty line to avoid text out of box.
67 if (infoCon.size() == 2)
68 {
69 coordy = 1.0 - 3 * dy;
70 TText* tdata = AddText(0.0, coordy, "");
71 ++n;
72 }
73
74 fdxNDC = fTextSize * fLongest / 2.2;
75 fdyNDC = fTextSize * n * 1.2; //fLines->GetSize() * 1.2;
76
77 ConvertNDCtoPad();
78 // This is necessary, or when fTip was drawn the first time, it will in center, as its fX1 fX2 fY1 fY2 have not been changed.
79 SetX1NDC(0.0);
80 SetY1NDC(0.0);
81 SetX2NDC(fdxNDC);
82 SetY2NDC(fdyNDC);
83}
84
85//______________________________________________________________________________
86void BesPaveText::SetPos(Int_t px, Int_t py)
87{
88 if (!gPad) {
89 cout << "BesPaveText::SetPos, gPad does not exist" << endl;
90 return;
91 }
92
93 Double_t x = gPad->AbsPixeltoX(px+10);
94 Double_t y = gPad->AbsPixeltoY(py-10);
95 Double_t x1, y1, x2, y2, xNDC, yNDC;
96 gPad->GetRange(x1, y1, x2, y2);
97 xNDC = (x-x1)/(x2-x1);
98 yNDC = (y-y1)/(y2-y1);
99 //cout << xNDC << " " << yNDC << endl;
100
101 x1 = xNDC;
102 y1 = yNDC;
103 x2 = xNDC + fdxNDC;
104 y2 = yNDC + fdyNDC;
105
106 Double_t delta = 0.02;
107 if (x2 > 1.0 && y2 > 1.0) {
108 x1 -= (fdxNDC+delta);
109 x2 -= (fdxNDC+delta);
110 y1 -= (fdyNDC+delta);
111 y2 -= (fdyNDC+delta);
112 }
113 else if (x2 > 1.0) {
114 x1 -= fdxNDC;
115 x2 -= fdxNDC;
116 }
117 if (y2 > 1.0) {
118 y1 -= fdyNDC;
119 y2 -= fdyNDC;
120 }
121
122 SetX1NDC(x1);
123 SetY1NDC(y1);
124 SetX2NDC(x2);
125 SetY2NDC(y2);
126 ConvertNDCtoPad();
127}
ClassImp(BesPaveText) BesPaveText
Definition: BesPaveText.cxx:9
const double delta
const Int_t n
Double_t x[10]
virtual void SetText(std::vector< TString > infoCon)
virtual void SetPos(Int_t px, Int_t py)
Definition: BesPaveText.cxx:86
double y[1000]