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