Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
transparentpad.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_cocoa
3/// This macro demonstrates semi-transparent pads.
4/// Requires OS X and ROOT configured with --enable-cocoa.
5///
6/// \macro_code
7///
8/// \author Timur Pocheptsov
9
10//Includes for ACLiC (cling does not need them).
11#include "TVirtualX.h"
12#include "TCanvas.h"
13#include "TError.h"
14#include "TColor.h"
15#include "TH1F.h"
16
17//Aux. functions for tutorials/cocoa.
18#include "customcolor.h"
19
20void transparentpad()
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 Color_t indices[3] = {};
28 ::Error("transparentpad", "failed to create new custom colors");
29 return;
30 }
31
32 //2. Create a TCanvas to force a gVirtualX initialization.
33 TCanvas * const c1 = new TCanvas("transparent pad","transparent pad demo", 10, 10, 900, 500);
34 //We can check gVirtualX (its type):
35 if (gVirtualX && !gVirtualX->InheritsFrom("TGCocoa")) {
36 ::Warning("transparentpad", "You can see the transparency ONLY in a pdf or png output (\"File\"->\"Save As\" ->...)\n"
37 "To have transparency in a canvas graphics, you need OS X version with cocoa enabled");
38 }
39
40 //2. Create special transparent colors.
41 new TColor(indices[0], 1., 0.2, 0.2, "transparent_pink", 0.25);
42 new TColor(indices[1], 0.2, 1., 0.2, "transparent_green", 0.25);
43 new TColor(indices[2], 0.2, 2., 1., "transparent_blue", 0.15);
44
45 //3. Some arbitrary histograms.
46 TH1F * const h1 = new TH1F("TH1F 1", "TH1F 1", 100, -1.5, 1.5);
47 h1->FillRandom("gaus");
48
49 TH1F * const h2 = new TH1F("TH1F 2", "TH1F 2", 100, -1.5, 0.);
50 h2->FillRandom("gaus");
51
52 TH1F * const h3 = new TH1F("TH1F 3", "TH1F 3", 100, 0.5, 2.);
53 h3->FillRandom("landau");
54
55 //4. Now overlapping transparent pads.
56 TPad * const pad1 = new TPad("transparent pad 1", "transparent pad 1", 0.1, 0.1, 0.7, 0.7);
57 pad1->SetFillColor(indices[0]);//here's the magic!
58 pad1->cd();
59 h1->Draw("lego2");
60 c1->cd();
61 pad1->Draw();
62
63 TPad * const pad2 = new TPad("transparent pad 2", "transparent pad 2", 0.2, 0.2, 0.8, 0.8);
64 pad2->SetFillColor(indices[1]);//here's the magic!
65 pad2->cd();
66 h2->Draw();
67 c1->cd();
68 pad2->Draw();
69
70 TPad * const pad3 = new TPad("transparent pad 3", "transparent pad 3", 0.3, 0.3, 0.9, 0.9);
71 pad3->SetFillColor(indices[2]);//here's the magic!
72 pad3->cd();
73 h3->Draw();
74 c1->cd();
75 pad3->Draw();
76}
77
short Color_t
Definition RtypesCore.h:83
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:187
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:231
#define gVirtualX
Definition TVirtualX.h:338
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:37
The Canvas class.
Definition TCanvas.h:23
The color creation and management class.
Definition TColor.h:19
1-D histogram with a float per channel (see TH1 documentation)}
Definition TH1.h:575
virtual void FillRandom(const char *fname, Int_t ntimes=5000, TRandom *rng=nullptr)
Fill histogram following distribution in function fname.
Definition TH1.cxx:3525
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition TH1.cxx:3073
The most important graphics class in the ROOT system.
Definition TPad.h:26
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
Definition TPad.cxx:603
void Draw(Option_t *option="") override
Draw Pad in Current pad (re-parent pad if necessary).
Definition TPad.cxx:1299
return c1
Definition legend1.C:41
TH1F * h1
Definition legend1.C:5
unsigned FindFreeCustomColorIndices(Color_t(&indices)[N])
Definition customcolor.h:38