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