Logo ROOT  
Reference Guide
No Matches
transparentpad.C File Reference

Detailed Description

This macro demonstrates semi-transparent pads.

Requires OS X and ROOT configured with –enable-cocoa.

//Includes for ACLiC (cling does not need them).
#include "TCanvas.h"
#include "TStyle.h"
#include "TError.h"
#include "TColor.h"
#include "TH1F.h"
//Aux. functions for tutorials/gl.
#include "customcolorgl.h"
void transparentpad()
//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[3] = {};
::Error("transparentpad", "failed to create new custom colors");
//2. Create a TCanvas.
TCanvas * const c1 = new TCanvas("transparent pad","transparent pad demo", 10, 10, 900, 500);
//We can check gVirtualX (its type):
if (!c1->UseGL()) {
::Warning("transparentpad", "You can see the transparency ONLY in a pdf or png output (\"File\"->\"Save As\" ->...)\n"
"To have transparency in a canvas graphics, you need OpenGL rendering enabled");
//2. Create special transparent colors.
new TColor(indices[0], 1., 0.2, 0.2, "transparent_pink", 0.25);
new TColor(indices[1], 0.2, 1., 0.2, "transparent_green", 0.25);
new TColor(indices[2], 0.2, 2., 1., "transparent_blue", 0.15);
//3. Some arbitrary histograms.
TH1F * const h1 = new TH1F("TH1F 1", "TH1F 1", 100, -1.5, 1.5);
TH1F * const h2 = new TH1F("TH1F 2", "TH1F 2", 100, -1.5, 0.);
TH1F * const h3 = new TH1F("TH1F 3", "TH1F 3", 100, 0.5, 2.);
//4. Now overlapping transparent pads.
TPad * const pad1 = new TPad("transparent pad 1", "transparent pad 1", 0.1, 0.1, 0.7, 0.7);
pad1->SetFillColor(indices[0]);//here's the magic!
TPad * const pad2 = new TPad("transparent pad 2", "transparent pad 2", 0.2, 0.2, 0.8, 0.8);
pad2->SetFillColor(indices[1]);//here's the magic!
TPad * const pad3 = new TPad("transparent pad 3", "transparent pad 3", 0.3, 0.3, 0.9, 0.9);
pad3->SetFillColor(indices[2]);//here's the magic!
int Int_t
Definition RtypesCore.h:45
const Bool_t kTRUE
Definition RtypesCore.h:91
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
R__EXTERN TStyle * gStyle
Definition TStyle.h:412
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
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition TStyle.h:325
return c1
Definition legend1.C:41
TH1F * h1
Definition legend1.C:5
unsigned FindFreeCustomColorIndices(T(&indices)[N])
Timur Pocheptsov

Definition in file transparentpad.C.