Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
26Fill Area Attributes class.
27
28This class is used (in general by secondary inheritance)
29by many other classes (graphics, histograms). It holds all the fill area
30attributes.
31
32## Fill Area attributes
33Fill Area attributes are:
34
35 - [Fill Area color](\ref ATTFILL1)
36 - [Fill Area style](\ref ATTFILL2)
37
38\anchor ATTFILL1
39## Fill Area color
40The fill area color is a color index (integer) pointing in the ROOT
41color table.
42The fill area color of any class inheriting from `TAttFill` can
43be changed using the method `SetFillColor` and retrieved using the
44method `GetFillColor`.
45The following table shows the first 50 default colors.
46
47Begin_Macro
48{
49 TCanvas *c = new TCanvas("c","Fill Area colors",0,0,500,200);
50 c->DrawColorTable();
51 return c;
52}
53End_Macro
54
55### Color transparency
56`SetFillColorAlpha()`, allows to set a transparent color.
57In the following example the fill color of the histogram `histo`
58is set to blue with a transparency of 35%. The color `kBlue`
59itself remains fully opaque.
60
61~~~ {.cpp}
62histo->SetFillColorAlpha(kBlue, 0.35);
63~~~
64
65The transparency is available on all platforms when the flag
66`OpenGL.CanvasPreferGL` is set to `1` in `$ROOTSYS/etc/system.rootrc`, or on Mac
67with the Cocoa backend.
68On the file output it is visible with PDF, PNG, Gif, JPEG, SVG, TeX... but not PostScript.
69
70### The ROOT Color Wheel.
71The wheel contains the recommended 216 colors to be used in web applications.
72The colors in the Color Wheel are created by TColor::CreateColorWheel.
73
74Using this color set for your text, background or graphics will give your
75application a consistent appearance across different platforms and browsers.
76
77Colors are grouped by hue, the aspect most important in human perception
78Touching color chips have the same hue, but with different brightness and vividness.
79
80Colors of slightly different hues _clash_. If you intend to display
81colors of the same hue together, you should pick them from the same group.
82
83Each color chip is identified by a mnemonic (eg kYellow) and a number.
84The keywords, kRed, kBlue, kYellow, kPink, etc are defined in the header file __Rtypes.h__
85that is included in all ROOT other header files. We strongly recommend to use these keywords
86in 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
93Begin_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}
100End_Macro
101
102### Special case forcing black&white output.
103If the current style fill area color is set to 0, then ROOT will force
104a black&white output for all objects with a fill area defined and independently
105of the object fill style.
106
107\anchor ATTFILL2
108## Fill Area style
109The fill area style defines the pattern used to fill a polygon.
110The fill area style of any class inheriting from `TAttFill` can
111be changed using the method `SetFillStyle` and retrieved using the
112method `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
128pattern_number can have any value from 1 to 25 (see table), or any
129value 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~~~
160The following table shows the list of pattern styles.
161The first table displays the 25 fixed patterns. They cannot be
162customized unlike the hatches displayed in the second table which be
163customized using:
164
165 - `gStyle->SetHatchesSpacing()` to define the spacing between hatches.
166 - `gStyle->SetHatchesLineWidth()` to define the hatches line width.
167
168Begin_Macro
169fillpatterns.C(500,700)
170End_Macro
171*/
172
173////////////////////////////////////////////////////////////////////////////////
174/// AttFill default constructor.
175/// Default fill attributes are taking from the current style
178{
179 if (!gStyle) {fFillColor=1; fFillStyle=0; return;}
182}
183
184////////////////////////////////////////////////////////////////////////////////
185/// AttFill normal constructor.
186/// - color Fill Color
187/// - style Fill Style
190{
191 fFillColor = color;
193}
194
195////////////////////////////////////////////////////////////////////////////////
196/// AttFill destructor.
199{
200}
201
202////////////////////////////////////////////////////////////////////////////////
203/// Copy this fill attributes to a new TAttFill.
205void 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.
214void 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.
229{
230 fFillColor = 1;
231 fFillStyle = 0;
232}
233
234////////////////////////////////////////////////////////////////////////////////
235/// Save fill attributes as C++ statement(s) on output stream out
237void TAttFill::SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef, Int_t stydef)
238{
239 if (fFillColor != coldef) {
241 out<<" "<<name<<"->SetFillColor(ci);" << std::endl;
242 else
243 out<<" "<<name<<"->SetFillColor("<<fFillColor<<");"<<std::endl;
244 }
245 if (fFillStyle != stydef)
246 out<<" "<<name<<"->SetFillStyle("<<fFillStyle<<");"<<std::endl;
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).
262{
263 fFillColor = TColor::GetColorTransparent(fcolor, falpha);
264}
short Style_t
Definition RtypesCore.h:89
short Color_t
Definition RtypesCore.h:92
float Float_t
Definition RtypesCore.h:57
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:377
Option_t Option_t style
char name[80]
Definition TGX11.cxx:110
R__EXTERN TStyle * gStyle
Definition TStyle.h:414
#define gPad
#define gVirtualX
Definition TVirtualX.h:338
Fill Area Attributes class.
Definition TAttFill.h:19
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:30
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition TAttFill.cxx:204
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:31
virtual void Modify()
Change current fill area attributes if necessary.
Definition TAttFill.cxx:213
Style_t fFillStyle
Fill area style.
Definition TAttFill.h:23
virtual ~TAttFill()
AttFill destructor.
Definition TAttFill.cxx:197
Color_t fFillColor
Fill area color.
Definition TAttFill.h:22
TAttFill()
AttFill default constructor.
Definition TAttFill.cxx:176
virtual void SetFillColorAlpha(Color_t fcolor, Float_t falpha)
Set a transparent fill color.
Definition TAttFill.cxx:260
virtual void SetFillAttributes()
Invoke the DialogCanvas Fill attributes.
Definition TAttFill.cxx:251
virtual void ResetAttFill(Option_t *option="")
Reset this fill attributes to default values.
Definition TAttFill.cxx:227
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
static Bool_t 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:2188
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:2034
static void UpdateFillAttributes(Int_t col, Int_t sty)
Update fill attributes via the pad editor.