Logo ROOT  
Reference Guide
transp_text.C File Reference

Detailed Description

This macro is based on labels1.C by Rene Brun. Updated by Timur Pocheptsov to use transparent text. The macro requires OpenGL - either enable by gStyle->SetCanvasPreferGL(kTRUE); or by setting OpenGL.CanvasPreferGL to 1 in $ROOTSYS/etc/system.rootrc.

//Includes for ACLiC (cling does not need them).
#include "TPaveText.h"
#include "TCanvas.h"
#include "TRandom.h"
#include "TError.h"
#include "TColor.h"
#include "TStyle.h"
#include "TH1F.h"
//Aux. functions for tutorials/gl.
#include "customcolorgl.h"
void transp_text()
{
//1. Try to 'allocate' free indices for our custom colors -
//we can use hard-coded indices like 1001, 1002, 1003 ... but
//I prefer to find free indices in a ROOT's color table
//to avoid possible conflicts with other tutorials.
Int_t indices[2] = {};
Error("transp_text", "failed to create new custom colors");
return;
}
//2. Create special transparent colors for both pavetext fill color and text color.
const Int_t grayColorIndex = indices[0], blackColorIndex = indices[1];
new TColor(grayColorIndex, 0.8, 0.8, 0.8, "transparent_gray", 0.85);
new TColor(blackColorIndex, 0., 0., 0., "transparent_black", 0.5);
//3. Create a TCanvas.
TCanvas * const c1 = new TCanvas("transparent text","transparent text demo", 10, 10, 900, 500);
if (!c1->UseGL())
::Warning("transp_text", "to use this macro you need OpenGL");
c1->SetGrid();
c1->SetBottomMargin(0.15);
const Int_t nx = 20;
const char *people[nx] = {"Jean","Pierre","Marie","Odile",
"Sebastien","Fons","Rene","Nicolas","Xavier","Greg",
"Bjarne","Anton","Otto","Eddy","Peter","Pasha",
"Philippe","Suzanne","Jeff","Valery"};
TH1F * const h = new TH1F("h4", "test", nx, 0, nx);
h->SetFillColor(38);
for (Int_t i = 0; i < 5000; ++i)
h->Fill(gRandom->Gaus(0.5 * nx, 0.2 * nx));
h->SetStats(0);
for (Int_t i = 1; i <= nx; ++i)
h->GetXaxis()->SetBinLabel(i, people[i - 1]);
h->Draw();
TPaveText * const pt = new TPaveText(0.3, 0.3, 0.98, 0.98, "brNDC");
//Transparent 'rectangle' with transparent text.
pt->SetFillColor(grayColorIndex);
pt->SetTextColor(blackColorIndex);
pt->SetTextSize(0.5);
pt->SetTextAlign(12);
pt->AddText("Hello");
pt->Draw();
}
Author
Timur Pocheptsov

Definition in file transp_text.C.

TStyle::SetCanvasPreferGL
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition: TStyle.h:325
TRandom::Gaus
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:263
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TH1F.h
Warning
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition: TError.cxx:231
ROOT::GLTutorials::FindFreeCustomColorIndices
unsigned FindFreeCustomColorIndices(T(&indices)[N])
Definition: customcolorgl.h:40
TRandom.h
TStyle.h
Int_t
int Int_t
Definition: RtypesCore.h:45
TColor.h
TCanvas.h
TPaveText.h
TPaveText::Draw
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:234
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
TColor
Definition: TColor.h:19
h
#define h(i)
Definition: RSha256.hxx:124
gRandom
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
TPaveText::AddText
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:183
TCanvas
Definition: TCanvas.h:23
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:572
TPaveText
Definition: TPaveText.h:21
pt
TPaveText * pt
Definition: entrylist_figure1.C:7
customcolorgl.h
Error
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition: TError.cxx:187
TError.h
c1
return c1
Definition: legend1.C:41