Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 (12/10/2012). Requires OS X and ROOT configured with –enable-cocoa.

//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"
void transp_text(bool gl = true)
{
// 1. Create special transparent colors for both pavetext fill color and text color.
auto grayColorIndex = TColor::GetColor((Float_t) 0.8, 0.8, 0.8, 0.85);
auto blackColorIndex = TColor::GetColor((Float_t) 0., 0., 0., 0.5);
// 2. Create a TCanvas.
gStyle->SetCanvasPreferGL(gl);
auto c1 = new TCanvas("transp_text","transparent text demo", 10, 10, 900, 500);
if (!c1->UseGL() && !c1->IsWeb())
::Warning("transp_text", "to use this macro you need either OpenGL or Web");
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"};
auto 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(false);
for (Int_t i = 1; i <= nx; ++i)
h->GetXaxis()->SetBinLabel(i, people[i - 1]);
h->Draw();
auto 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();
}
#define h(i)
Definition RSha256.hxx:106
int Int_t
Definition RtypesCore.h:45
float Float_t
Definition RtypesCore.h:57
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:229
Int_t i
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
R__EXTERN TStyle * gStyle
Definition TStyle.h:433
The Canvas class.
Definition TCanvas.h:23
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
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:621
A Pave (see TPave) with text, lines or/and boxes inside.
Definition TPaveText.h:21
TPaveText * pt
return c1
Definition legend1.C:41
Author
Timur Pocheptsov

Definition in file transp_text.C.