ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
transparentpad.C
Go to the documentation of this file.
1 //Author: Timur Pocheptsov, 19/03/2014.
2 //This macro demonstrates semi-transparent pads.
3 //Requires OpenGL.
4 
5 //Includes for ACLiC (cling does not need them).
6 
7 #include "TCanvas.h"
8 #include "TStyle.h"
9 #include "TError.h"
10 #include "TColor.h"
11 #include "TH1F.h"
12 
13 //Aux. functions for tutorials/gl.
14 #include "customcolorgl.h"
15 
17 {
18  //1. Try to 'allocate' free indices for our custom colors -
19  //we can use hard-coded indices like 1001, 1002, 1003 ... but
20  //I prefer to find free indices in a ROOT's color table
21  //to avoid possible conflicts with other tutorials.
23 
24  Int_t indices[3] = {};
26  ::Error("transparentpad", "failed to create new custom colors");
27  return;
28  }
29 
30  //2. Create a TCanvas.
31  TCanvas * const c1 = new TCanvas("transparent pad","transparent pad demo", 10, 10, 900, 500);
32  //We can check gVirtualX (its type):
33  if (!c1->UseGL()) {
34  ::Warning("transparentpad", "You can see the transparency ONLY in a pdf or png output (\"File\"->\"Save As\" ->...)\n"
35  "To have transparency in a canvas graphics, you need OpenGL rendering enabled");
36  }
37 
38  //2. Create special transparent colors.
39  new TColor(indices[0], 1., 0.2, 0.2, "transparent_pink", 0.25);
40  new TColor(indices[1], 0.2, 1., 0.2, "transparent_green", 0.25);
41  new TColor(indices[2], 0.2, 2., 1., "transparent_blue", 0.15);
42 
43  //3. Some arbitrary histograms.
44  TH1F * const h1 = new TH1F("TH1F 1", "TH1F 1", 100, -1.5, 1.5);
45  h1->FillRandom("gaus");
46 
47  TH1F * const h2 = new TH1F("TH1F 2", "TH1F 2", 100, -1.5, 0.);
48  h2->FillRandom("gaus");
49 
50  TH1F * const h3 = new TH1F("TH1F 3", "TH1F 3", 100, 0.5, 2.);
51  h3->FillRandom("landau");
52 
53  //4. Now overlapping transparent pads.
54  TPad * const pad1 = new TPad("transparent pad 1", "transparent pad 1", 0.1, 0.1, 0.7, 0.7);
55  pad1->SetFillColor(indices[0]);//here's the magic!
56  pad1->cd();
57  h1->Draw("lego2");
58  c1->cd();
59  pad1->Draw();
60 
61  TPad * const pad2 = new TPad("transparent pad 2", "transparent pad 2", 0.2, 0.2, 0.8, 0.8);
62  pad2->SetFillColor(indices[1]);//here's the magic!
63  pad2->cd();
64  h2->Draw();
65  c1->cd();
66  pad2->Draw();
67 
68  TPad * const pad3 = new TPad("transparent pad 3", "transparent pad 3", 0.3, 0.3, 0.9, 0.9);
69  pad3->SetFillColor(indices[2]);//here's the magic!
70  pad3->cd();
71  h3->Draw();
72  c1->cd();
73  pad3->Draw();
74 }
75 
unsigned FindFreeCustomColorIndices(T(&indices)[N])
Definition: customcolorgl.h:44
Bool_t UseGL() const
Definition: TCanvas.h:242
TCanvas * c1
Definition: legend1.C:2
R__EXTERN TStyle * gStyle
Definition: TStyle.h:423
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:659
TPad * pad1
Definition: hcons.C:13
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
int Int_t
Definition: RtypesCore.h:41
TPad * pad3
Definition: hcons.C:13
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:514
void transparentpad()
TH2D * h2
Definition: fit2dHist.C:45
TH1F * h1
Definition: legend1.C:5
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1192
void Error(const char *location, const char *msgfmt,...)
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition: TStyle.h:337
virtual void FillRandom(const char *fname, Int_t ntimes=5000)
Fill histogram following distribution in function fname.
Definition: TH1.cxx:3330
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
The most important graphics class in the ROOT system.
Definition: TPad.h:46
void Warning(const char *location, const char *msgfmt,...)
The Canvas class.
Definition: TCanvas.h:48
The color creation and management class.
Definition: TColor.h:47
TPad * pad2
Definition: hcons.C:13
const Bool_t kTRUE
Definition: Rtypes.h:91