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 "TStyle.h"
15#include "TVirtualPad.h"
16#include "TVirtualPadPainter.h"
17#include "TVirtualPadEditor.h"
18#include "TColor.h"
19
20
21/** \class TAttFill
22\ingroup Base
23\ingroup GraphicsAtt
24
25Fill Area Attributes class.
26
27This class is used (in general by secondary inheritance)
28by many other classes (graphics, histograms). It holds all the fill area
29attributes.
30
31## Fill Area attributes
32Fill Area attributes are:
33
34 - [Fill Area color](\ref ATTFILL1)
35 - [Fill Area style](\ref ATTFILL2)
36
37\anchor ATTFILL1
38## Fill Area color
39The fill area color is a color index (integer) pointing in the ROOT
40color table.
41The fill area color of any class inheriting from `TAttFill` can
42be changed using the method `SetFillColor` and retrieved using the
43method `GetFillColor`.
44The following table shows the first 50 default colors.
45
46Begin_Macro
47{
48 TCanvas *c = new TCanvas("c","Fill Area colors",0,0,500,200);
49 c->DrawColorTable();
50 return c;
51}
52End_Macro
53
54### Color transparency
55`SetFillColorAlpha()`, allows to set a transparent color.
56In the following example the fill color of the histogram `histo`
57is set to blue with an opacity of 35% (i.e. a transparency of 65%).
58(The color `kBlue` itself is internally stored as fully opaque.)
59
60~~~ {.cpp}
61histo->SetFillColorAlpha(kBlue, 0.35);
62~~~
63
64The transparency is available on all platforms when the flag
65`OpenGL.CanvasPreferGL` is set to `1` in `$ROOTSYS/etc/system.rootrc`, or on Mac
66with the Cocoa backend.
67On the file output it is visible with PDF, PNG, Gif, JPEG, SVG, TeX... but not PostScript.
68
69Alternatively, you can call at the top of your script `gSytle->SetCanvasPreferGL();`.
70Or if you prefer to activate GL for a single canvas `c`, then use `c->SetSupportGL(true);`.
71
72### The ROOT Color Wheel.
73The wheel contains the recommended 216 colors to be used in web applications.
74The colors in the Color Wheel are created by TColor::CreateColorWheel.
75
76Using this color set for your text, background or graphics will give your
77application a consistent appearance across different platforms and browsers.
78
79Colors are grouped by hue, the aspect most important in human perception
80Touching color chips have the same hue, but with different brightness and vividness.
81
82Colors of slightly different hues _clash_. If you intend to display
83colors of the same hue together, you should pick them from the same group.
84
85Each color chip is identified by a mnemonic (eg kYellow) and a number.
86The keywords, kRed, kBlue, kYellow, kPink, etc are defined in the header file __Rtypes.h__
87that is included in all ROOT other header files. We strongly recommend to use these keywords
88in your code instead of hardcoded color numbers, eg:
89~~~ {.cpp}
90 myObject.SetFillColor(kRed);
91 myObject.SetFillColor(kYellow-10);
92 myLine.SetLineColor(kMagenta+2);
93~~~
94
95Begin_Macro
96{
97 TColorWheel *w = new TColorWheel();
98 auto cw = new TCanvas("cw","cw",0,0,400,400);
99 w->SetCanvas(cw);
100 w->Draw();
101}
102End_Macro
103
104### Special case forcing black&white output.
105If the current style fill area color is set to 0, then ROOT will force
106a black&white output for all objects with a fill area defined and independently
107of the object fill style.
108
109\anchor ATTFILL2
110## Fill Area style
111The fill area style defines the pattern used to fill a polygon.
112The fill area style of any class inheriting from `TAttFill` can
113be changed using the method `SetFillStyle` and retrieved using the
114method `GetFillStyle`.
115### Conventions for fill styles:
116
117 - 0 : hollow
118 - 1001 : Solid
119 - 3000 + pattern_number (see below)
120 - 4000..4100: 100% transparent .. 100% opaque
121
122Historically the styles between 4000 and 4100 were introduced to implement pad
123transparency on platforms like X11 which does not support alpha channel in color.
124Since ROOT 6.40 any objects can use such fill styles. On supported platforms like
125Cocoa or GL or PS/PDF/SVG output style will be automatically converted to transparent colors.
126
127pattern_number can have any value from 1 to 25 (see table), or any
128value from 100 to 999. For the latest the numbering convention is the following:
129~~~ {.cpp}
130 pattern_number = ijk (FillStyle = 3ijk)
131
132 i (1-9) : specify the space between each hatch
133 1 = 1/2mm 9 = 6mm
134
135 j (0-9) : specify angle between 0 and 90 degrees
136 0 = 0
137 1 = 10
138 2 = 20
139 3 = 30
140 4 = 45
141 5 = Not drawn
142 6 = 60
143 7 = 70
144 8 = 80
145 9 = 90
146
147 k (0-9) : specify angle between 90 and 180 degrees
148 0 = 180
149 1 = 170
150 2 = 160
151 3 = 150
152 4 = 135
153 5 = Not drawn
154 6 = 120
155 7 = 110
156 8 = 100
157 9 = 90
158~~~
159The following table shows the list of pattern styles.
160The first table displays the 25 fixed patterns. They cannot be
161customized unlike the hatches displayed in the second table which be
162customized using:
163
164 - `gStyle->SetHatchesSpacing()` to define the spacing between hatches.
165 - `gStyle->SetHatchesLineWidth()` to define the hatches line width.
166
167Begin_Macro
168fillpatterns.C(500,700)
169End_Macro
170*/
171
172////////////////////////////////////////////////////////////////////////////////
173/// AttFill default constructor.
174/// Default fill attributes are taking from the current style
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// AttFill normal constructor.
185/// - color Fill Color
186/// - style Fill Style
189{
190 fFillColor = color;
192}
193
194////////////////////////////////////////////////////////////////////////////////
195/// AttFill destructor.
199}
200
201////////////////////////////////////////////////////////////////////////////////
202/// Copy this fill attributes to a new TAttFill.
205{
206 attfill.fFillColor = fFillColor;
207 attfill.fFillStyle = fFillStyle;
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// Change current fill area attributes if necessary.
213void TAttFill::Modify()
214{
215 if (gPad)
216 ModifyOn(*gPad);
217}
218
219////////////////////////////////////////////////////////////////////////////////
220/// Change current fill area attributes on speicifed pad
223{
224 auto pp = pad.GetPainter();
225 if (pp)
226 pp->SetAttFill(*this);
227}
228
229////////////////////////////////////////////////////////////////////////////////
230/// Reset this fill attributes to default values.
233{
234 fFillColor = 1;
235 fFillStyle = 0;
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// Save fill attributes as C++ statement(s) on output stream out
241void TAttFill::SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef, Int_t stydef)
242{
243 if (fFillColor != coldef)
244 out << " " << name << "->SetFillColor(" << TColor::SavePrimitiveColor(fFillColor) << ");\n";
245 if (fFillStyle != stydef)
246 out << " " << name << "->SetFillStyle(" << fFillStyle << ");\n";
247}
248
249////////////////////////////////////////////////////////////////////////////////
250/// Invoke the DialogCanvas Fill attributes.
255}
256
257////////////////////////////////////////////////////////////////////////////////
258/// Set a transparent fill color.
259/// \param fcolor defines the fill color
260/// \param falpha defines the percentage of opacity from 0. (fully transparent) to 1. (fully opaque).
261/// \note falpha is ignored (treated as 1) if the TCanvas has no GL support activated.
266}
267
268////////////////////////////////////////////////////////////////////////////////
269/// Set a fill color.
274}
short Style_t
Style number (short)
Definition RtypesCore.h:96
short Color_t
Color number (short)
Definition RtypesCore.h:99
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:71
const char Option_t
Option string (const char)
Definition RtypesCore.h:80
Option_t Option_t SetFillColor
Option_t Option_t style
char name[80]
Definition TGX11.cxx:145
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
#define gPad
Fill Area Attributes class.
Definition TAttFill.h:21
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:32
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition TAttFill.cxx:203
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:33
virtual void Modify()
Change current fill area attributes if necessary.
Definition TAttFill.cxx:212
Style_t fFillStyle
Fill area style.
Definition TAttFill.h:25
virtual ~TAttFill()
AttFill destructor.
Definition TAttFill.cxx:196
Color_t fFillColor
Fill area color.
Definition TAttFill.h:24
TAttFill()
AttFill default constructor.
Definition TAttFill.cxx:175
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:40
virtual void SetFillColorAlpha(Color_t fcolor, Float_t falpha)
Set a transparent fill color.
Definition TAttFill.cxx:262
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:231
virtual void ModifyOn(TVirtualPad &pad)
Change current fill area attributes on speicifed pad.
Definition TAttFill.cxx:221
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:240
static TString SavePrimitiveColor(Int_t ci)
Convert color in C++ statement which can be used in SetColor directives Produced statement either inc...
Definition TColor.cxx:2556
static Int_t GetColorTransparent(Int_t color, Float_t a)
Static function: Returns the transparent color number corresponding to n.
Definition TColor.cxx:2182
static void UpdateFillAttributes(Int_t col, Int_t sty)
Update fill attributes via the pad editor.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51