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