// @(#)root/base:$Id$
// Author: Rene Brun   12/12/94

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "Riostream.h"
#include "TAttFill.h"
#include "TVirtualPad.h"
#include "TStyle.h"
#include "TVirtualX.h"
#include "TVirtualPadEditor.h"
#include "TColor.h"

ClassImp(TAttFill)


//______________________________________________________________________________
/* Begin_Html
<center><h2>Fill Area Attributes class</h2></center>

This class is used (in general by secondary inheritance)
by many other classes (graphics, histograms). It holds all the fill area
attributes.

<h3>Fill Area attributes</h3>
Fill Area attributes are:
<ul>
<li><a href="#F1">Fill Area color.</a></li>
<li><a href="#F2">Fill Area style.</a></li>
</ul>

<a name="F1"></a><h3>Fill Area color</h3>
The fill area color is a color index (integer) pointing in the ROOT
color table.
The fill area color of any class inheriting from <tt>TAttFill</tt> can
be changed using the method <tt>SetFillColor</tt> and retrieved using the
method <tt>GetFillColor</tt>.
The following table shows the first 50 default colors.
End_Html
Begin_Macro(source)
{
   TCanvas *c = new TCanvas("c","Fill Area colors",0,0,500,200);
   c->DrawColorTable();
   return c;
}
End_Macro

Begin_Html

<h4>Color transparency</h4>
<tt>SetFillColorAlpha()</tt>, allows to set a transparent color.
In the following example the fill color of the histogram <tt>histo</tt>
is set to blue with a transparency of 35%. The color <tt>kBlue</tt>
itself remains fully opaque.
<p>
<pre>
histo->SetFillColorAlpha(kBlue, 0.35);
</pre>
<p>
The transparency is available on all platforms when the <tt>flagOpenGL.CanvasPreferGL</tt> is set to <tt>1</tt>
in <tt>$ROOTSYS/etc/system.rootrc</tt>, or on Mac with the Cocoa backend. On the file output
it is visible with PDF, PNG, Gif, JPEG, SVG ... but not PostScript.

<h4>The ROOT Color Wheel.</h4>
The wheel contains the recommended 216 colors to be used in web applications.
The colors in the Color Wheel are created by TColor::CreateColorWheel.
<p>Using this color set for your text, background or graphics will give your
application a consistent appearance across different platforms and browsers.
<p>Colors are grouped by hue, the aspect most important in human perception
Touching color chips have the same hue, but with different brightness and vividness.
<p>Colors of slightly different hues <b>clash</b>. If you intend to display
colors of the same hue together, you should pick them from the same group.
<p>Each color chip is identified by a mnemonic (eg kYellow) and a number.
The keywords, kRed, kBlue, kYellow, kPink, etc are defined in the header file <b>Rtypes.h</b>
that is included in all ROOT other header files. We strongly recommend to use these keywords
in your code instead of hardcoded color numbers, eg:
<pre>
   myObject.SetFillColor(kRed);
   myObject.SetFillColor(kYellow-10);
   myLine.SetLineColor(kMagenta+2);
</pre>

End_Html
Begin_Macro(source)
{
   TColorWheel *w = new TColorWheel();
   w->Draw();
   return w->GetCanvas();
}
End_Macro

Begin_Html
<h4>Special case forcing black&white output.</h4>
If the current style fill area color is set to 0, then ROOT will force
a black&white output for all objects with a fill area defined and independently
of the object fill style.

<a name="F2"></a><h3>Fill Area style</h3>
The fill area style defines the pattern used to fill a polygon.
The fill area style of any class inheriting from <tt>TAttFill</tt> can
be changed using the method <tt>SetFillStyle</tt> and retrieved using the
method <tt>GetFillStyle</tt>.
<h4>Conventions for fill styles:</h4>
<ul>
<li>  0    : hollow                   </li>
<li>  1001 : Solid                    </li>
<li>  3000+pattern_number (see below) </li>
<li>  For TPad only:                  </li>
<ul>
   <li>  4000 :the window is transparent.                            </li>
   <li>  4000 to 4100 the window is 100% transparent to 100% opaque. </li>
</ul>
      The pad transparency is visible in binary outputs files like gif, jpg, png etc ..
      but not in vector graphics output files like PS, PDF and SVG. This convention
      (fill style > 4000) is kept for backward compatibility. It is better to use
      the color transparency instead.
</ul>

pattern_number can have any value from 1 to 25 (see table), or any
value from 100 to 999. For the latest the numbering convention is the following:
<pre>
      pattern_number = ijk      (FillStyle = 3ijk)

      i (1-9) : specify the space between each hatch
                1 = 1/2mm  9 = 6mm

      j (0-9) : specify angle between 0 and 90 degrees
                0 = 0
                1 = 10
                2 = 20
                3 = 30
                4 = 45
                5 = Not drawn
                6 = 60
                7 = 70
                8 = 80
                9 = 90

      k (0-9) : specify angle between 90 and 180 degrees
                0 = 180
                1 = 170
                2 = 160
                3 = 150
                4 = 135
                5 = Not drawn
                6 = 120
                7 = 110
                8 = 100
                9 = 90
</pre>
The following table shows the list of pattern styles.
The first table displays the 25 fixed patterns. They cannot be
customized unlike the hatches displayed in the second table which be
customized using:
<ul>
<li> <tt>gStyle->SetHatchesSpacing()</tt> to define the spacing between hatches.
<li> <tt>gStyle->SetHatchesLineWidth()</tt> to define the hatches line width.
</ul>
End_Html
Begin_Macro(source)
fillpatterns.C
End_Macro */


//______________________________________________________________________________
TAttFill::TAttFill()
{
   // AttFill default constructor.
   // Default fill attributes are taking from the current style

   if (!gStyle) {fFillColor=1; fFillStyle=0; return;}
   fFillColor = gStyle->GetFillColor();
   fFillStyle = gStyle->GetFillStyle();
}


//______________________________________________________________________________
TAttFill::TAttFill(Color_t color, Style_t style)
{
   // AttFill normal constructor.
   // color Fill Color
   // style Fill Style

   fFillColor = color;
   fFillStyle = style;
}


//______________________________________________________________________________
TAttFill::~TAttFill()
{
   // AttFill destructor.
}


//______________________________________________________________________________
void TAttFill::Copy(TAttFill &attfill) const
{
   // Copy this fill attributes to a new TAttFill.

   attfill.fFillColor  = fFillColor;
   attfill.fFillStyle  = fFillStyle;
}


//______________________________________________________________________________
void TAttFill::Modify()
{
   // Change current fill area attributes if necessary.

   if (!gPad) return;
   if (!gPad->IsBatch()) {
      gVirtualX->SetFillColor(fFillColor);
      gVirtualX->SetFillStyle(fFillStyle);
   }

   gPad->SetAttFillPS(fFillColor,fFillStyle);
}


//______________________________________________________________________________
void TAttFill::ResetAttFill(Option_t *)
{
   // Reset this fill attributes to default values.

   fFillColor = 1;
   fFillStyle = 0;
}


//______________________________________________________________________________
void TAttFill::SaveFillAttributes(std::ostream &out, const char *name, Int_t coldef, Int_t stydef)
{
    // Save fill attributes as C++ statement(s) on output stream out

   if (fFillColor != coldef) {
      if (fFillColor > 228) {
         TColor::SaveColor(out, fFillColor);
         out<<"   "<<name<<"->SetFillColor(ci);" << std::endl;
      } else
         out<<"   "<<name<<"->SetFillColor("<<fFillColor<<");"<<std::endl;
   }
   if (fFillStyle != stydef) {
      out<<"   "<<name<<"->SetFillStyle("<<fFillStyle<<");"<<std::endl;
   }
}


//______________________________________________________________________________
void TAttFill::SetFillAttributes()
{
   // Invoke the DialogCanvas Fill attributes.

   TVirtualPadEditor::UpdateFillAttributes(fFillColor,fFillStyle);
}


//______________________________________________________________________________
void TAttFill::SetFillColorAlpha(Color_t fcolor, Float_t falpha)
{
   // Set a transparent fill color. falpha defines the percentage of
   // the color opacity from 0. (fully transparent) to 1. (fully opaque).

   fFillColor = TColor::GetColorTransparent(fcolor, falpha);
}
 TAttFill.cxx:1
 TAttFill.cxx:2
 TAttFill.cxx:3
 TAttFill.cxx:4
 TAttFill.cxx:5
 TAttFill.cxx:6
 TAttFill.cxx:7
 TAttFill.cxx:8
 TAttFill.cxx:9
 TAttFill.cxx:10
 TAttFill.cxx:11
 TAttFill.cxx:12
 TAttFill.cxx:13
 TAttFill.cxx:14
 TAttFill.cxx:15
 TAttFill.cxx:16
 TAttFill.cxx:17
 TAttFill.cxx:18
 TAttFill.cxx:19
 TAttFill.cxx:20
 TAttFill.cxx:21
 TAttFill.cxx:22
 TAttFill.cxx:23
 TAttFill.cxx:24
 TAttFill.cxx:25
 TAttFill.cxx:26
 TAttFill.cxx:27
 TAttFill.cxx:28
 TAttFill.cxx:29
 TAttFill.cxx:30
 TAttFill.cxx:31
 TAttFill.cxx:32
 TAttFill.cxx:33
 TAttFill.cxx:34
 TAttFill.cxx:35
 TAttFill.cxx:36
 TAttFill.cxx:37
 TAttFill.cxx:38
 TAttFill.cxx:39
 TAttFill.cxx:40
 TAttFill.cxx:41
 TAttFill.cxx:42
 TAttFill.cxx:43
 TAttFill.cxx:44
 TAttFill.cxx:45
 TAttFill.cxx:46
 TAttFill.cxx:47
 TAttFill.cxx:48
 TAttFill.cxx:49
 TAttFill.cxx:50
 TAttFill.cxx:51
 TAttFill.cxx:52
 TAttFill.cxx:53
 TAttFill.cxx:54
 TAttFill.cxx:55
 TAttFill.cxx:56
 TAttFill.cxx:57
 TAttFill.cxx:58
 TAttFill.cxx:59
 TAttFill.cxx:60
 TAttFill.cxx:61
 TAttFill.cxx:62
 TAttFill.cxx:63
 TAttFill.cxx:64
 TAttFill.cxx:65
 TAttFill.cxx:66
 TAttFill.cxx:67
 TAttFill.cxx:68
 TAttFill.cxx:69
 TAttFill.cxx:70
 TAttFill.cxx:71
 TAttFill.cxx:72
 TAttFill.cxx:73
 TAttFill.cxx:74
 TAttFill.cxx:75
 TAttFill.cxx:76
 TAttFill.cxx:77
 TAttFill.cxx:78
 TAttFill.cxx:79
 TAttFill.cxx:80
 TAttFill.cxx:81
 TAttFill.cxx:82
 TAttFill.cxx:83
 TAttFill.cxx:84
 TAttFill.cxx:85
 TAttFill.cxx:86
 TAttFill.cxx:87
 TAttFill.cxx:88
 TAttFill.cxx:89
 TAttFill.cxx:90
 TAttFill.cxx:91
 TAttFill.cxx:92
 TAttFill.cxx:93
 TAttFill.cxx:94
 TAttFill.cxx:95
 TAttFill.cxx:96
 TAttFill.cxx:97
 TAttFill.cxx:98
 TAttFill.cxx:99
 TAttFill.cxx:100
 TAttFill.cxx:101
 TAttFill.cxx:102
 TAttFill.cxx:103
 TAttFill.cxx:104
 TAttFill.cxx:105
 TAttFill.cxx:106
 TAttFill.cxx:107
 TAttFill.cxx:108
 TAttFill.cxx:109
 TAttFill.cxx:110
 TAttFill.cxx:111
 TAttFill.cxx:112
 TAttFill.cxx:113
 TAttFill.cxx:114
 TAttFill.cxx:115
 TAttFill.cxx:116
 TAttFill.cxx:117
 TAttFill.cxx:118
 TAttFill.cxx:119
 TAttFill.cxx:120
 TAttFill.cxx:121
 TAttFill.cxx:122
 TAttFill.cxx:123
 TAttFill.cxx:124
 TAttFill.cxx:125
 TAttFill.cxx:126
 TAttFill.cxx:127
 TAttFill.cxx:128
 TAttFill.cxx:129
 TAttFill.cxx:130
 TAttFill.cxx:131
 TAttFill.cxx:132
 TAttFill.cxx:133
 TAttFill.cxx:134
 TAttFill.cxx:135
 TAttFill.cxx:136
 TAttFill.cxx:137
 TAttFill.cxx:138
 TAttFill.cxx:139
 TAttFill.cxx:140
 TAttFill.cxx:141
 TAttFill.cxx:142
 TAttFill.cxx:143
 TAttFill.cxx:144
 TAttFill.cxx:145
 TAttFill.cxx:146
 TAttFill.cxx:147
 TAttFill.cxx:148
 TAttFill.cxx:149
 TAttFill.cxx:150
 TAttFill.cxx:151
 TAttFill.cxx:152
 TAttFill.cxx:153
 TAttFill.cxx:154
 TAttFill.cxx:155
 TAttFill.cxx:156
 TAttFill.cxx:157
 TAttFill.cxx:158
 TAttFill.cxx:159
 TAttFill.cxx:160
 TAttFill.cxx:161
 TAttFill.cxx:162
 TAttFill.cxx:163
 TAttFill.cxx:164
 TAttFill.cxx:165
 TAttFill.cxx:166
 TAttFill.cxx:167
 TAttFill.cxx:168
 TAttFill.cxx:169
 TAttFill.cxx:170
 TAttFill.cxx:171
 TAttFill.cxx:172
 TAttFill.cxx:173
 TAttFill.cxx:174
 TAttFill.cxx:175
 TAttFill.cxx:176
 TAttFill.cxx:177
 TAttFill.cxx:178
 TAttFill.cxx:179
 TAttFill.cxx:180
 TAttFill.cxx:181
 TAttFill.cxx:182
 TAttFill.cxx:183
 TAttFill.cxx:184
 TAttFill.cxx:185
 TAttFill.cxx:186
 TAttFill.cxx:187
 TAttFill.cxx:188
 TAttFill.cxx:189
 TAttFill.cxx:190
 TAttFill.cxx:191
 TAttFill.cxx:192
 TAttFill.cxx:193
 TAttFill.cxx:194
 TAttFill.cxx:195
 TAttFill.cxx:196
 TAttFill.cxx:197
 TAttFill.cxx:198
 TAttFill.cxx:199
 TAttFill.cxx:200
 TAttFill.cxx:201
 TAttFill.cxx:202
 TAttFill.cxx:203
 TAttFill.cxx:204
 TAttFill.cxx:205
 TAttFill.cxx:206
 TAttFill.cxx:207
 TAttFill.cxx:208
 TAttFill.cxx:209
 TAttFill.cxx:210
 TAttFill.cxx:211
 TAttFill.cxx:212
 TAttFill.cxx:213
 TAttFill.cxx:214
 TAttFill.cxx:215
 TAttFill.cxx:216
 TAttFill.cxx:217
 TAttFill.cxx:218
 TAttFill.cxx:219
 TAttFill.cxx:220
 TAttFill.cxx:221
 TAttFill.cxx:222
 TAttFill.cxx:223
 TAttFill.cxx:224
 TAttFill.cxx:225
 TAttFill.cxx:226
 TAttFill.cxx:227
 TAttFill.cxx:228
 TAttFill.cxx:229
 TAttFill.cxx:230
 TAttFill.cxx:231
 TAttFill.cxx:232
 TAttFill.cxx:233
 TAttFill.cxx:234
 TAttFill.cxx:235
 TAttFill.cxx:236
 TAttFill.cxx:237
 TAttFill.cxx:238
 TAttFill.cxx:239
 TAttFill.cxx:240
 TAttFill.cxx:241
 TAttFill.cxx:242
 TAttFill.cxx:243
 TAttFill.cxx:244
 TAttFill.cxx:245
 TAttFill.cxx:246
 TAttFill.cxx:247
 TAttFill.cxx:248
 TAttFill.cxx:249
 TAttFill.cxx:250
 TAttFill.cxx:251
 TAttFill.cxx:252
 TAttFill.cxx:253
 TAttFill.cxx:254
 TAttFill.cxx:255
 TAttFill.cxx:256
 TAttFill.cxx:257
 TAttFill.cxx:258
 TAttFill.cxx:259
 TAttFill.cxx:260
 TAttFill.cxx:261
 TAttFill.cxx:262
 TAttFill.cxx:263
 TAttFill.cxx:264
 TAttFill.cxx:265
 TAttFill.cxx:266
 TAttFill.cxx:267
 TAttFill.cxx:268
 TAttFill.cxx:269
 TAttFill.cxx:270
 TAttFill.cxx:271