ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
transp_text.C
Go to the documentation of this file.
1 //Author: Timur Pocheptsov, 19/03/2014.
2 //This macro is based on labels1.C by Rene Brun.
3 //Updated by Timur Pocheptsov to use transparent text.
4 //The macro requires OpenGL - either enable by
5 //gStyle->SetCanvasPreferGL(kTRUE); or by setting
6 //OpenGL.CanvasPreferGL to 1 in $ROOTSYS/etc/system.rootrc.
7 
8 //Includes for ACLiC (cling does not need them).
9 #include "TPaveText.h"
10 #include "TCanvas.h"
11 #include "TRandom.h"
12 #include "TError.h"
13 #include "TColor.h"
14 #include "TStyle.h"
15 #include "TH1F.h"
16 
17 //Aux. functions for tutorials/gl.
18 #include "customcolorgl.h"
19 
21 {
22  //1. Try to 'allocate' free indices for our custom colors -
23  //we can use hard-coded indices like 1001, 1002, 1003 ... but
24  //I prefer to find free indices in a ROOT's color table
25  //to avoid possible conflicts with other tutorials.
26  Int_t indices[2] = {};
28  Error("transp_text", "failed to create new custom colors");
29  return;
30  }
31 
32  //2. Create special transparent colors for both pavetext fill color and text color.
33  const Int_t grayColorIndex = indices[0], blackColorIndex = indices[1];
34  new TColor(grayColorIndex, 0.8, 0.8, 0.8, "transparent_gray", 0.85);
35  new TColor(blackColorIndex, 0., 0., 0., "transparent_black", 0.5);
36 
37  //3. Create a TCanvas.
39 
40  TCanvas * const c1 = new TCanvas("transparent text","transparent text demo", 10, 10, 900, 500);
41  if (!c1->UseGL())
42  ::Warning("transp_text", "to use this macro you need OpenGL");
43 
44  c1->SetGrid();
45  c1->SetBottomMargin(0.15);
46 
47  const Int_t nx = 20;
48  const char *people[nx] = {"Jean","Pierre","Marie","Odile",
49  "Sebastien","Fons","Rene","Nicolas","Xavier","Greg",
50  "Bjarne","Anton","Otto","Eddy","Peter","Pasha",
51  "Philippe","Suzanne","Jeff","Valery"};
52 
53  TH1F * const h = new TH1F("h4", "test", nx, 0, nx);
54 
55  h->SetFillColor(38);
56  for (Int_t i = 0; i < 5000; ++i)
57  h->Fill(gRandom->Gaus(0.5 * nx, 0.2 * nx));
58 
59  h->SetStats(0);
60  for (Int_t i = 1; i <= nx; ++i)
61  h->GetXaxis()->SetBinLabel(i, people[i - 1]);
62 
63  h->Draw();
64 
65  TPaveText * const pt = new TPaveText(0.3, 0.3, 0.98, 0.98, "brNDC");
66  //Transparent 'rectangle' with transparent text.
67  pt->SetFillColor(grayColorIndex);
68  pt->SetTextColor(blackColorIndex);
69 
70  pt->SetTextSize(0.5);
71  pt->SetTextAlign(12);
72 
73  pt->AddText("Hello");
74  pt->Draw();
75 }
const int nx
Definition: kalman.C:16
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3159
unsigned FindFreeCustomColorIndices(T(&indices)[N])
Definition: customcolorgl.h:44
void transp_text()
Definition: transp_text.C:18
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:211
Bool_t UseGL() const
Definition: TCanvas.h:242
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:235
TCanvas * c1
Definition: legend1.C:2
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
TH1 * h
Definition: legend2.C:5
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
Definition: TPaveText.cxx:160
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
int Int_t
Definition: RtypesCore.h:41
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:326
void Error(const char *location, const char *msgfmt,...)
virtual void SetTextAlign(Short_t align=11)
Definition: TAttText.h:55
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition: TStyle.h:337
virtual void SetBottomMargin(Float_t bottommargin)
Set Pad bottom margin in fraction of the pad height.
Definition: TAttPad.cxx:97
TPaveText * pt
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
virtual void SetFillColor(Color_t fcolor)
Definition: TAttFill.h:50
void Warning(const char *location, const char *msgfmt,...)
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
The Canvas class.
Definition: TCanvas.h:48
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:35
The color creation and management class.
Definition: TColor.h:47
virtual void SetBinLabel(Int_t bin, const char *label)
Set label for bin.
Definition: TAxis.cxx:793
virtual void SetTextColor(Color_t tcolor=1)
Definition: TAttText.h:57
virtual void SetTextSize(Float_t tsize=1)
Definition: TAttText.h:60
const Bool_t kTRUE
Definition: Rtypes.h:91
virtual void SetStats(Bool_t stats=kTRUE)
Set statistics option on/off.
Definition: TH1.cxx:8320
TAxis * GetXaxis()
Definition: TH1.h:319