ROOT
v6-32
Reference Guide
Loading...
Searching...
No Matches
transp_text.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_gl
3
/// This macro is based on labels1.C by Rene Brun.
4
/// Updated by Timur Pocheptsov to use transparent text.
5
/// The macro requires OpenGL or Web-based canvas
6
///
7
/// \macro_image(nobatch)
8
/// \macro_code
9
///
10
/// \authors Timur Pocheptsov, Sergey Linev
11
12
//Includes for ACLiC (cling does not need them).
13
#include "
TPaveText.h
"
14
#include "
TCanvas.h
"
15
#include "
TRandom.h
"
16
#include "
TError.h
"
17
#include "
TColor.h
"
18
#include "
TStyle.h
"
19
#include "
TH1F.h
"
20
21
void
transp_text(
bool
gl =
true
)
22
{
23
// 1. Create special transparent colors for both pavetext fill color and text color.
24
auto
grayColorIndex =
TColor::GetColor
((
Float_t
) 0.8, 0.8, 0.8, 0.85);
25
auto
blackColorIndex =
TColor::GetColor
((
Float_t
) 0., 0., 0., 0.5);
26
27
// 2. Create a TCanvas.
28
gStyle
->SetCanvasPreferGL(gl);
29
30
auto
c1
=
new
TCanvas
(
"transp_text"
,
"transparent text demo"
, 10, 10, 900, 500);
31
if
(!
c1
->UseGL() && !
c1
->IsWeb())
32
::Warning
(
"transp_text"
,
"to use this macro you need either OpenGL or Web"
);
33
34
c1
->SetGrid();
35
c1
->SetBottomMargin(0.15);
36
37
const
Int_t
nx = 20;
38
const
char
*people[nx] = {
"Jean"
,
"Pierre"
,
"Marie"
,
"Odile"
,
39
"Sebastien"
,
"Fons"
,
"Rene"
,
"Nicolas"
,
"Xavier"
,
"Greg"
,
40
"Bjarne"
,
"Anton"
,
"Otto"
,
"Eddy"
,
"Peter"
,
"Pasha"
,
41
"Philippe"
,
"Suzanne"
,
"Jeff"
,
"Valery"
};
42
43
auto
h
=
new
TH1F
(
"h4"
,
"test"
, nx, 0, nx);
44
45
h
->SetFillColor(38);
46
for
(
Int_t
i
= 0;
i
< 5000; ++
i
)
47
h
->Fill(
gRandom
->Gaus(0.5 * nx, 0.2 * nx));
48
49
h
->SetStats(
false
);
50
for
(
Int_t
i
= 1;
i
<= nx; ++
i
)
51
h
->GetXaxis()->SetBinLabel(
i
, people[
i
- 1]);
52
53
h
->Draw();
54
55
auto
pt
=
new
TPaveText
(0.3, 0.3, 0.98, 0.98,
"brNDC"
);
56
//Transparent 'rectangle' with transparent text.
57
pt
->SetFillColor(grayColorIndex);
58
pt
->SetTextColor(blackColorIndex);
59
60
pt
->SetTextSize(0.5);
61
pt
->SetTextAlign(12);
62
63
pt
->AddText(
"Hello"
);
64
pt
->Draw();
65
}
h
#define h(i)
Definition
RSha256.hxx:106
Int_t
int Int_t
Definition
RtypesCore.h:45
Float_t
float Float_t
Definition
RtypesCore.h:57
TCanvas.h
TColor.h
TError.h
Warning
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition
TError.cxx:229
i
Int_t i
Definition
TGraphAsymmErrors.cxx:1306
TH1F.h
TPaveText.h
TRandom.h
gRandom
R__EXTERN TRandom * gRandom
Definition
TRandom.h:62
TStyle.h
gStyle
R__EXTERN TStyle * gStyle
Definition
TStyle.h:433
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TColor::GetColor
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
Definition
TColor.cxx:1839
TH1F
1-D histogram with a float per channel (see TH1 documentation)
Definition
TH1.h:621
TPaveText
A Pave (see TPave) with text, lines or/and boxes inside.
Definition
TPaveText.h:21
pt
TPaveText * pt
Definition
entrylist_figure1.C:7
c1
return c1
Definition
legend1.C:41
tutorials
gl
transp_text.C
ROOT v6-32 - Reference Guide Generated on Wed Jun 3 2026 02:38:16 (GVA Time) using Doxygen 1.13.2