Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TAttFill.cxx
Go to the documentation of this file.
1// @(#)root/base:$Id$
2// Author: Rene Brun 12/12/94
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include <iostream>
13#include "TAttFill.h"
14#include "TVirtualPad.h"
15#include "TStyle.h"
16#include "TVirtualX.h"
17#include "TVirtualPadEditor.h"
18#include "TColor.h"
19
21
22/** \class TAttFill
23\ingroup Base
24\ingroup GraphicsAtt
25
26Fill Area Attributes class.
27
28This class is used (in general by secondary inheritance)
29by many other classes (graphics, histograms). It holds all the fill area
30attributes.
31
32## Fill Area attributes
33Fill Area attributes are:
34
35 - [Fill Area color](\ref ATTFILL1)
36 - [Fill Area style](\ref ATTFILL2)
37
38\anchor ATTFILL1
39## Fill Area color
40The fill area color is a color index (integer) pointing in the ROOT
41color table.
42The fill area color of any class inheriting from `TAttFill` can
43be changed using the method `SetFillColor` and retrieved using the
44method `GetFillColor`.
45The following table shows the first 50 default colors.
46
47Begin_Macro
48{
49 TCanvas *c = new TCanvas("c","Fill Area colors",0,0,500,200);
50 c->DrawColorTable();
51 return c;
52}
53End_Macro
54
55### Color transparency
56`SetFillColorAlpha()`, allows to set a transparent color.
57In the following example the fill color of the histogram `histo`
58is set to blue with an opacity of 35% (i.e. a transparency of 65%).
59(The color `kBlue` itself is internally stored as fully opaque.)
60
61~~~ {.cpp}
62histo->SetFillColorAlpha(kBlue, 0.35);
63~~~
64
65The transparency is available on all platforms when the flag
66`OpenGL.CanvasPreferGL` is set to `1` in `$ROOTSYS/etc/system.rootrc`, or on Mac
67with the Cocoa backend.
68On the file output it is visible with PDF, PNG, Gif, JPEG, SVG, TeX... but not PostScript.
69
70Alternatively, you can call at the top of your script `gSytle->SetCanvasPreferGL();`.
71Or if you prefer to activate GL for a single canvas `c`, then use `c->SetSupportGL(true);`.
72
73### The ROOT Color Wheel.
74The wheel contains the recommended 216 colors to be used in web applications.
75The colors in the Color Wheel are created by TColor::CreateColorWheel.
76
77Using this color set for your text, background or graphics will give your
78application a consistent appearance across different platforms and browsers.
79
80Colors are grouped by hue, the aspect most important in human perception
81Touching color chips have the same hue, but with different brightness and vividness.
82
83Colors of slightly different hues _clash_. If you intend to display
84colors of the same hue together, you should pick them from the same group.
85
86Each color chip is identified by a mnemonic (eg kYellow) and a number.
87The keywords, kRed, kBlue, kYellow, kPink, etc are defined in the header file __Rtypes.h__
88that is included in all ROOT other header files. We strongly recommend to use these keywords
89in your code instead of hardcoded color numbers, eg:
90~~~ {.cpp}
91 myObject.SetFillColor(kRed);
92 myObject.SetFillColor(kYellow-10);
93 myLine.SetLineColor(kMagenta+2);
94~~~
95
96Begin_Macro
97{
98 TColorWheel *w = new TColorWheel();
99 auto cw = new TCanvas("cw","cw",0,0,400,400);
100 w->SetCanvas(cw);
101 w->Draw();
102}
103End_Macro
104
105### Special case forcing black&white output.
106If the current style fill area color is set to 0, then ROOT will force
107a black&white output for all objects with a fill area defined and independently
108of the object fill style.
109
110\anchor ATTFILL2
111## Fill Area style
112The fill area style defines the pattern used to fill a polygon.
113The fill area style of any class inheriting from `TAttFill` can
114be changed using the method `SetFillStyle` and retrieved using the
115method `GetFillStyle`.
116### Conventions for fill styles:
117
118 - 0 : hollow
119 - 1001 : Solid
120 - 3000+pattern_number (see below)
121 - For TPad only:
122
123 - 4000 :the window is transparent.
124 - 4000 to 4100 the window is 100% transparent to 100% opaque.
125
126 The pad transparency is visible in binary outputs files like gif, jpg, png etc ..
127 but not in vector graphics output files like PS, PDF and SVG. This convention
128 (fill style > 4000) is kept for backward compatibility. It is better to use
129 the color transparency instead.
130
131pattern_number can have any value from 1 to 25 (see table), or any
132value from 100 to 999. For the latest the numbering convention is the following:
133~~~ {.cpp}
134 pattern_number = ijk (FillStyle = 3ijk)
135
136 i (1-9) : specify the space between each hatch
137 1 = 1/2mm 9 = 6mm
138
139 j (0-9) : specify angle between 0 and 90 degrees
140 0 = 0
141 1 = 10
142 2 = 20
143 3 = 30
144 4 = 45
145 5 = Not drawn
146 6 = 60
147 7 = 70
148 8 = 80
149 9 = 90
150
151 k (0-9) : specify angle between 90 and 180 degrees
152 0 = 180
153 1 = 170
154 2 = 160
155 3 = 150
156 4 = 135
157 5 = Not drawn
158 6 = 120
159 7 = 110
160 8 = 100
161 9 = 90
162~~~
163The following table shows the list of pattern styles.
164The first table displays the 25 fixed patterns. They cannot be
165customized unlike the hatches displayed in the second table which be
166customized using:
167
168 - `gStyle->SetHatchesSpacing()` to define the spacing between hatches.
169 - `gStyle->SetHatchesLineWidth()` to define the hatches line width.
170
171Begin_Macro
172fillpatterns.C(500,700)
173End_Macro
174*/
175
176////////////////////////////////////////////////////////////////////////////////
177/// AttFill default constructor.
178/// Default fill attributes are taking from the current style
181{
182 if (!gStyle) {fFillColor=1; fFillStyle=0; return;}
185}
186
187////////////////////////////////////////////////////////////////////////////////
188/// AttFill normal constructor.
189/// - color Fill Color
190/// - style Fill Style
193{
194 fFillColor = color;
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// AttFill destructor.
202{
203}
204
205////////////////////////////////////////////////////////////////////////////////
206/// Copy this fill attributes to a new TAttFill.
208void TAttFill::Copy(TAttFill &attfill) const
209{
210 attfill.fFillColor = fFillColor;
211 attfill.fFillStyle = fFillStyle;
212}
213
214////////////////////////////////////////////////////////////////////////////////
215/// Change current fill area attributes if necessary.
217void TAttFill::Modify()
218{
219 if (!gPad) return;
220 if (!gPad->IsBatch()) {
221 gVirtualX->SetFillColor(fFillColor);
222 gVirtualX->SetFillStyle(fFillStyle);
223 }
224
225 gPad->SetAttFillPS(fFillColor,fFillStyle);
226}
227
228////////////////////////////////////////////////////////////////////////////////
229/// Reset this fill attributes to default values.
232{
233 fFillColor = 1;
234 fFillStyle = 0;
235}
236
237////////////////////////////////////////////////////////////////////////////////
238/// Save fill attributes as C++ statement(s) on output stream out
240void TAttFill::SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef, Int_t stydef)
241{
242 if (fFillColor != coldef) {
244 out<<" "<<name<<"->SetFillColor(ci);" << std::endl;
245 else
246 out<<" "<<name<<"->SetFillColor("<<fFillColor<<");"<<std::endl;
247 }
248 if (fFillStyle != stydef)
249 out<<" "<<name<<"->SetFillStyle("<<fFillStyle<<");"<<std::endl;
250}
251
252////////////////////////////////////////////////////////////////////////////////
253/// Invoke the DialogCanvas Fill attributes.
256{
258}
259
260////////////////////////////////////////////////////////////////////////////////
261/// Set a transparent fill color.
262/// \param fcolor defines the fill color
263/// \param falpha defines the percentage of opacity from 0. (fully transparent) to 1. (fully opaque).
264/// \note falpha is ignored (treated as 1) if the TCanvas has no GL support activated.
267{
268 fFillColor = TColor::GetColorTransparent(fcolor, falpha);
269}
short Style_t
Definition RtypesCore.h:82
short Color_t
Definition RtypesCore.h:85
float Float_t
Definition RtypesCore.h:57
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
Option_t Option_t style
char name[80]
Definition TGX11.cxx:110
R__EXTERN TStyle * gStyle
Definition TStyle.h:436
#define gPad
#define gVirtualX
Definition TVirtualX.h:337
Fill Area Attributes class.
Definition TAttFill.h:19
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:30
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition TAttFill.cxx:207
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:31
virtual void Modify()
Change current fill area attributes if necessary.
Definition TAttFill.cxx:216
Style_t fFillStyle
Fill area style.
Definition TAttFill.h:23
virtual ~TAttFill()
AttFill destructor.
Definition TAttFill.cxx:200
Color_t fFillColor
Fill area color.
Definition TAttFill.h:22
TAttFill()
AttFill default constructor.
Definition TAttFill.cxx:179
virtual void SetFillColorAlpha(Color_t fcolor, Float_t falpha)
Set a transparent fill color.
Definition TAttFill.cxx:265
virtual void SetFillAttributes()
Invoke the DialogCanvas Fill attributes.
Definition TAttFill.cxx:254
virtual void ResetAttFill(Option_t *option="")
Reset this fill attributes to default values.
Definition TAttFill.cxx:230
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
Save fill attributes as C++ statement(s) on output stream out.
Definition TAttFill.cxx:239
static Bool_t SaveColor(std::ostream &out, Int_t ci)
Save a color with index > 228 as a C++ statement(s) on output stream out.
Definition TColor.cxx:2543
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:2174
static void UpdateFillAttributes(Int_t col, Int_t sty)
Update fill attributes via the pad editor.