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",
37 "You can see the transparency ONLY in a pdf or png output (\"File\"->\"Save As\" ->...)\n"
38 "To have transparency in a canvas graphics, you need OS X version with cocoa enabled");
39 }
40
41 // 2. Create special transparent colors.
42 new TColor(indices[0], 1., 0.2, 0.2, "transparent_pink", 0.25);
43 new TColor(indices[1], 0.2, 1., 0.2, "transparent_green", 0.25);
44 new TColor(indices[2], 0.2, 2., 1., "transparent_blue", 0.15);
45
46 // 3. Some arbitrary histograms.
47 TH1F *const h1 = new TH1F("TH1F 1", "TH1F 1", 100, -1.5, 1.5);
48 h1->FillRandom("gaus");
49
50 TH1F *const h2 = new TH1F("TH1F 2", "TH1F 2", 100, -1.5, 0.);
51 h2->FillRandom("gaus");
52
53 TH1F *const h3 = new TH1F("TH1F 3", "TH1F 3", 100, 0.5, 2.);
54 h3->FillRandom("landau");
55
56 // 4. Now overlapping transparent pads.
57 TPad *const pad1 = new TPad("transparent pad 1", "transparent pad 1", 0.1, 0.1, 0.7, 0.7);
58 pad1->SetFillColor(indices[0]); // here's the magic!
59 pad1->cd();
60 h1->Draw("lego2");
61 c1->cd();
62 pad1->Draw();
63
64 TPad *const pad2 = new TPad("transparent pad 2", "transparent pad 2", 0.2, 0.2, 0.8, 0.8);
65 pad2->SetFillColor(indices[1]); // here's the magic!
66 pad2->cd();
67 h2->Draw();
68 c1->cd();
69 pad2->Draw();
70
71 TPad *const pad3 = new TPad("transparent pad 3", "transparent pad 3", 0.3, 0.3, 0.9, 0.9);
72 pad3->SetFillColor(indices[2]); // here's the magic!
73 pad3->cd();
74 h3->Draw();
75 c1->cd();
76 pad3->Draw();
77}
short Color_t
Definition RtypesCore.h:85
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:229
#define gVirtualX
Definition TVirtualX.h:337
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:21
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:623
virtual void FillRandom(TF1 *f1, Int_t ntimes=5000, TRandom *rng=nullptr)
Definition TH1.cxx:3530
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3068
The most important graphics class in the ROOT system.
Definition TPad.h:28
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
Definition TPad.cxx:693
void Draw(Option_t *option="") override
Draw Pad in Current pad (re-parent pad if necessary).
Definition TPad.cxx:1364
return c1
Definition legend1.C:41
TH1F * h1
Definition legend1.C:5
unsigned FindFreeCustomColorIndices(Color_t(&indices)[N])
Definition customcolor.h:38