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