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
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 - For TPad only:
121
122 - 4000 :the window is transparent.
123 - 4000 to 4100 the window is 100% transparent to 100% opaque.
124
125 The pad transparency is visible in binary outputs files like gif, jpg, png etc ..
126 but not in vector graphics output files like PS, PDF and SVG. This convention
127 (fill style > 4000) is kept for backward compatibility. It is better to use
128 the color transparency instead.
129
130pattern_number can have any value from 1 to 25 (see table), or any
131value from 100 to 999. For the latest the numbering convention is the following:
132~~~ {.cpp}
133 pattern_number = ijk (FillStyle = 3ijk)
134
135 i (1-9) : specify the space between each hatch
136 1 = 1/2mm 9 = 6mm
137
138 j (0-9) : specify angle between 0 and 90 degrees
139 0 = 0
140 1 = 10
141 2 = 20
142 3 = 30
143 4 = 45
144 5 = Not drawn
145 6 = 60
146 7 = 70
147 8 = 80
148 9 = 90
149
150 k (0-9) : specify angle between 90 and 180 degrees
151 0 = 180
152 1 = 170
153 2 = 160
154 3 = 150
155 4 = 135
156 5 = Not drawn
157 6 = 120
158 7 = 110
159 8 = 100
160 9 = 90
161~~~
162The following table shows the list of pattern styles.
163The first table displays the 25 fixed patterns. They cannot be
164customized unlike the hatches displayed in the second table which be
165customized using:
166
167 - `gStyle->SetHatchesSpacing()` to define the spacing between hatches.
168 - `gStyle->SetHatchesLineWidth()` to define the hatches line width.
169
170Begin_Macro
171fillpatterns.C(500,700)
172End_Macro
173*/
174
175////////////////////////////////////////////////////////////////////////////////
176/// AttFill default constructor.
177/// Default fill attributes are taking from the current style
184}
185
186////////////////////////////////////////////////////////////////////////////////
187/// AttFill normal constructor.
188/// - color Fill Color
189/// - style Fill Style
192{
193 fFillColor = color;
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// AttFill destructor.
202}
203
204////////////////////////////////////////////////////////////////////////////////
205/// Copy this fill attributes to a new TAttFill.
208{
209 attfill.fFillColor = fFillColor;
210 attfill.fFillStyle = fFillStyle;
211}
212
213////////////////////////////////////////////////////////////////////////////////
214/// Change current fill area attributes if necessary.
216void TAttFill::Modify()
217{
218 if (!gPad) return;
219 if (!gPad->IsBatch()) {
220 gVirtualX->SetFillColor(fFillColor);
221 gVirtualX->SetFillStyle(fFillStyle);
222 }
223
224 gPad->SetAttFillPS(fFillColor,fFillStyle);
225}
226
227////////////////////////////////////////////////////////////////////////////////
228/// Reset this fill attributes to default values.
231{
232 fFillColor = 1;
233 fFillStyle = 0;
234}
235
236////////////////////////////////////////////////////////////////////////////////
237/// Save fill attributes as C++ statement(s) on output stream out
239void TAttFill::SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef, Int_t stydef)
240{
241 if (fFillColor != coldef)
242 out << " " << name << "->SetFillColor(" << TColor::SavePrimitiveColor(fFillColor) << ");\n";
243 if (fFillStyle != stydef)
244 out << " " << name << "->SetFillStyle(" << fFillStyle << ");\n";
245}
246
247////////////////////////////////////////////////////////////////////////////////
248/// Invoke the DialogCanvas Fill attributes.
253}
254
255////////////////////////////////////////////////////////////////////////////////
256/// Set a transparent fill color.
257/// \param fcolor defines the fill color
258/// \param falpha defines the percentage of opacity from 0. (fully transparent) to 1. (fully opaque).
259/// \note falpha is ignored (treated as 1) if the TCanvas has no GL support activated.
264}
269}
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:110
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
#define gPad
#define gVirtualX
Definition TVirtualX.h:337
Fill Area Attributes class.
Definition TAttFill.h:20
virtual Color_t GetFillColor() const
Return the fill area color.
Definition TAttFill.h:31
void Copy(TAttFill &attfill) const
Copy this fill attributes to a new TAttFill.
Definition TAttFill.cxx:206
virtual Style_t GetFillStyle() const
Return the fill area style.
Definition TAttFill.h:32
virtual void Modify()
Change current fill area attributes if necessary.
Definition TAttFill.cxx:215
Style_t fFillStyle
Fill area style.
Definition TAttFill.h:24
virtual ~TAttFill()
AttFill destructor.
Definition TAttFill.cxx:199
Color_t fFillColor
Fill area color.
Definition TAttFill.h:23
TAttFill()
AttFill default constructor.
Definition TAttFill.cxx:178
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:38
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:249
virtual void ResetAttFill(Option_t *option="")
Reset this fill attributes to default values.
Definition TAttFill.cxx:229
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:238
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.