Logo ROOT   6.19/01
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 flag
65 `OpenGL.CanvasPreferGL` is set to `1` in `$ROOTSYS/etc/system.rootrc`, or on Mac
66 with the Cocoa backend.
67 On the file output it is visible with PDF, PNG, Gif, JPEG, SVG, TeX... but not PostScript.
68 
69 ### The ROOT Color Wheel.
70 The wheel contains the recommended 216 colors to be used in web applications.
71 The colors in the Color Wheel are created by TColor::CreateColorWheel.
72 
73 Using this color set for your text, background or graphics will give your
74 application a consistent appearance across different platforms and browsers.
75 
76 Colors are grouped by hue, the aspect most important in human perception
77 Touching color chips have the same hue, but with different brightness and vividness.
78 
79 Colors of slightly different hues _clash_. If you intend to display
80 colors of the same hue together, you should pick them from the same group.
81 
82 Each color chip is identified by a mnemonic (eg kYellow) and a number.
83 The keywords, kRed, kBlue, kYellow, kPink, etc are defined in the header file __Rtypes.h__
84 that is included in all ROOT other header files. We strongly recommend to use these keywords
85 in 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 
92 Begin_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 }
99 End_Macro
100 
101 ### Special case forcing black&white output.
102 If the current style fill area color is set to 0, then ROOT will force
103 a black&white output for all objects with a fill area defined and independently
104 of the object fill style.
105 
106 ## <a name="F2"></a> Fill Area style
107 The fill area style defines the pattern used to fill a polygon.
108 The fill area style of any class inheriting from `TAttFill` can
109 be changed using the method `SetFillStyle` and retrieved using the
110 method `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 
126 pattern_number can have any value from 1 to 25 (see table), or any
127 value 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 ~~~
158 The following table shows the list of pattern styles.
159 The first table displays the 25 fixed patterns. They cannot be
160 customized unlike the hatches displayed in the second table which be
161 customized using:
162 
163  - `gStyle->SetHatchesSpacing()` to define the spacing between hatches.
164  - `gStyle->SetHatchesLineWidth()` to define the hatches line width.
165 
166 Begin_Macro
167 fillpatterns.C(500,700)
168 End_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;
190  fFillStyle = style;
191 }
192 
193 ////////////////////////////////////////////////////////////////////////////////
194 /// AttFill destructor.
197 {
198 }
199 
200 ////////////////////////////////////////////////////////////////////////////////
201 /// Copy this fill attributes to a new TAttFill.
203 void 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.
212 void 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
235 void 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).
261 void TAttFill::SetFillColorAlpha(Color_t fcolor, Float_t falpha)
262 {
263  fFillColor = TColor::GetColorTransparent(fcolor, falpha);
264 }
virtual void SetFillAttributes()
Invoke the DialogCanvas Fill attributes.
Definition: TAttFill.cxx:251
virtual ~TAttFill()
AttFill destructor.
Definition: TAttFill.cxx:195
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:407
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
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:225
virtual void Modify()
Change current fill area attributes if necessary.
Definition: TAttFill.cxx:211
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:234
#define gVirtualX
Definition: TVirtualX.h:345
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.
#define ClassImp(name)
Definition: Rtypes.h:365
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:174
Color_t fFillColor
Fill area color.
Definition: TAttFill.h:22
#define gPad
Definition: TVirtualPad.h:286
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:260
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:202