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
175
177{
178 if (!gStyle) {fFillColor=1; fFillStyle=0; return;}
179 fFillColor = gStyle->GetFillColor();
180 fFillStyle = gStyle->GetFillStyle();
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// AttFill normal constructor.
185/// - color Fill Color
186/// - style Fill Style
187
189{
190 fFillColor = color;
192}
193
194////////////////////////////////////////////////////////////////////////////////
195/// AttFill destructor.
196
198{
199}
200
201////////////////////////////////////////////////////////////////////////////////
202/// Copy this fill attributes to a new TAttFill.
203
204void TAttFill::Copy(TAttFill &attfill) const
205{
206 attfill.fFillColor = fFillColor;
207 attfill.fFillStyle = fFillStyle;
208}
209
210////////////////////////////////////////////////////////////////////////////////
211/// Change current fill area attributes if necessary.
212
213void TAttFill::Modify()
214{
215 if (gPad)
216 ModifyOn(*gPad);
217}
218
219////////////////////////////////////////////////////////////////////////////////
220/// Change current fill area attributes on speicifed pad
221
223{
224 auto pp = pad.GetPainter();
225 if (pp)
226 pp->SetAttFill(*this);
227}
228
229////////////////////////////////////////////////////////////////////////////////
230/// Reset this fill attributes to default values.
231
233{
234 fFillColor = 1;
235 fFillStyle = 0;
236}
237
238////////////////////////////////////////////////////////////////////////////////
239/// Save fill attributes as C++ statement(s) on output stream out
240
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.
251
253{
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.
262
264{
265 fFillColor = TColor::GetColorTransparent(fcolor, falpha);
266}
267
268////////////////////////////////////////////////////////////////////////////////
269/// Set a fill color.
270
272{
273 SetFillColor(lcolor.number());
274}
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
short Color_t
Color number (short).
Definition RtypesCore.h:99
short Style_t
Style number (short).
Definition RtypesCore.h:96
float Float_t
Float 4 bytes (float).
Definition RtypesCore.h:71
const char Option_t
Option string (const char).
Definition RtypesCore.h:80
char name[80]
Definition TGX11.cxx:148
externTStyle * gStyle
Definition TStyle.h:442
#define gPad
void Copy(TAttFill &attfill) const
Style_t fFillStyle
Fill area style.
Definition TAttFill.h:25
Color_t fFillColor
Fill area color.
Definition TAttFill.h:24
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:40
virtual void ModifyOn(TVirtualPad &pad)
virtual ~TAttFill()
virtual void ResetAttFill(Option_t *option="")
virtual void Modify()
virtual void SetFillAttributes()
virtual void SetFillColorAlpha(Color_t fcolor, Float_t falpha)
virtual void SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef=1, Int_t stydef=1001)
Int_t number() const
Definition TColor.h:151
static Int_t GetColorTransparent(Int_t color, Float_t a)
static TString SavePrimitiveColor(Int_t ci)
static void UpdateFillAttributes(Int_t col, Int_t sty)
Update fill attributes via the pad editor.
virtual void SetAttFill(const TAttFill &att)
Set fill attributes.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition TVirtualPad.h:51
virtual TVirtualPadPainter * GetPainter()=0
TCanvas * style()
Definition style.C:1