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