Logo ROOT  
Reference Guide
TColorGradient.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 //Author: Timur Pocheptsov 20/03/2012
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2012, 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 #ifndef ROOT_TColorGradient
13 #define ROOT_TColorGradient
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TColorGradient //
19 // //
20 // TColorGradient extends basic TColor. //
21 // Actually, this is not a simple color, but linear or radial gradient //
22 // for a filled area. By inheriting from TColor, gradients can be //
23 // placed inside gROOT's list of colors and use it in all TAttXXX //
24 // descendants without modifying any existing code. //
25 // //
26 //////////////////////////////////////////////////////////////////////////
27 
28 #include <vector>
29 
30 #include "Rtypes.h"
31 
32 #include "TColor.h"
33 
34 
35 class TColorGradient : public TColor {
36 public:
37  typedef std::vector<Color_t>::size_type SizeType_t;
38 
39  //TODO: Replace with enum class as soon as we have C++11 enabled by default.
40  //CoordinateMode: both linear and radial gradients require some points - the
41  //start and end points.
42  //We can use either pad's rectangle as a coordinate system
43  //or an object's bounding rect.
44  enum ECoordinateMode {
45  kPadMode,//NDC, in a pad's rectangle (pad is 0,0 - 1,1).
46  kObjectBoundingMode //NDC in an object's bounding rect (this rect is 0,0 - 1, 1).
47  };
48 
49  struct Point {
52 
53  Point()
54  : fX(0.), fY(0.)
55  {
56  }
57 
59  : fX(x), fY(y)
60  {
61  }
62  };
63 
64 private:
65  //Positions of color nodes in a gradient, in NDC.
66  std::vector<Double_t> fColorPositions;
67  std::vector<Double_t> fColors;//RGBA values.
68 
69  //'default value' is kObjectBoundingMode.
71 
72 protected:
74 
75  TColorGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
76  const Color_t *colorIndices, ECoordinateMode mode = kObjectBoundingMode);
77  TColorGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
79 
80 public:
81  void ResetColor(UInt_t nPoints, const Double_t *points,
82  const Color_t *colorIndices);
83  void ResetColor(UInt_t nPoints, const Double_t *points,
84  const Double_t *colorIndices);
85 
88 
90  const Double_t *GetColorPositions()const;
91  const Double_t *GetColors()const;
92 
93 private:
94  void RegisterColor(Color_t colorIndex);
95 
96  ClassDef(TColorGradient, 0); //Gradient fill.
97 };
98 
100 public:
101  //With C++11 we'll use inherited constructors!!!
102  TLinearGradient();
103  TLinearGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
104  const Color_t *colorIndices, ECoordinateMode mode = kObjectBoundingMode);
105  TLinearGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
107 
108  //points are always in NDC (and also affected by fCoordinateMode).
109  void SetStartEnd(const Point &p1, const Point &p2);
110  const Point &GetStart()const;
111  const Point &GetEnd()const;
112 
113 private:
116 
117  ClassDef(TLinearGradient, 0); //Linear gradient fill.
118 };
119 
120 //
121 //Radial gradient. Can be either "simple": you specify a center
122 //and radius in NDC coordinates (see comments about linear gradient
123 //and coordinate modes above), or "extended": you have two centers
124 //(start,end) and two radiuses (R1, R2) and interpolation between them;
125 //still start/end and radiuses are in NDC.
126 //
127 
129 public:
133  };
134 
135 
136  //With C++11 we'll use inherited constructors!!!
137  TRadialGradient();
138  TRadialGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
139  const Color_t *colorIndices, ECoordinateMode mode = kObjectBoundingMode);
140  TRadialGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
142 
143 
145 
146 
147  //Extended gradient.
148  void SetStartEndR1R2(const Point &p1, Double_t r1,
149  const Point &p2, Double_t r2);
150  const Point &GetStart()const;
151  Double_t GetR1()const;
152  const Point &GetEnd()const;
153  Double_t GetR2()const;
154 
155  //Simple radial gradient: the same as extended with
156  //start == end, r1 = 0, r2 = radius.
157  void SetRadialGradient(const Point &center, Double_t radius);
158  const Point &GetCenter()const;
159  Double_t GetRadius()const;
160 
161 private:
162  Point fStart;
163  Double_t fR1 = 0.;
164  Point fEnd;
165  Double_t fR2 = 0.;
166 
168 
169  ClassDef(TRadialGradient, 0); //Radial gradient fill.
170 };
171 
172 
173 #endif
TColorGradient::Point::fY
Double_t fY
Definition: TColorGradient.h:57
TColorGradient::GetCoordinateMode
ECoordinateMode GetCoordinateMode() const
Get coordinate mode.
Definition: TColorGradient.cxx:135
TColorGradient::kPadMode
@ kPadMode
Definition: TColorGradient.h:51
TRadialGradient::GetCenter
const Point & GetCenter() const
Get center.
Definition: TColorGradient.cxx:335
TColorGradient::TColorGradient
TColorGradient()
Constructor.
Definition: TColorGradient.cxx:40
TColorGradient::RegisterColor
void RegisterColor(Color_t colorIndex)
Register color.
Definition: TColorGradient.cxx:167
TColorGradient::fCoordinateMode
ECoordinateMode fCoordinateMode
Definition: TColorGradient.h:76
colors
Color * colors
Definition: X3DBuffer.c:21
TColorGradient::ResetColor
void ResetColor(UInt_t nPoints, const Double_t *points, const Color_t *colorIndices)
Reset color.
Definition: TColorGradient.cxx:80
TRadialGradient::fEnd
Point fEnd
Definition: TColorGradient.h:164
TColorGradient::kObjectBoundingMode
@ kObjectBoundingMode
Definition: TColorGradient.h:52
x
Double_t x[n]
Definition: legend1.C:17
TRadialGradient
Definition: TColorGradient.h:128
TLinearGradient::GetStart
const Point & GetStart() const
Get start.
Definition: TColorGradient.cxx:227
TColor.h
TColorGradient::Point
Definition: TColorGradient.h:55
TRadialGradient::GetR2
Double_t GetR2() const
Get R2.
Definition: TColorGradient.cxx:316
Color_t
short Color_t
Definition: RtypesCore.h:83
TRadialGradient::SetStartEndR1R2
void SetStartEndR1R2(const Point &p1, Double_t r1, const Point &p2, Double_t r2)
Set start and end R1 and R2.
Definition: TColorGradient.cxx:279
TColorGradient
Definition: TColorGradient.h:35
TLinearGradient::TLinearGradient
TLinearGradient()
Definition: TColorGradient.cxx:193
TColorGradient::ECoordinateMode
ECoordinateMode
Definition: TColorGradient.h:50
TColorGradient::Point::Point
Point()
Definition: TColorGradient.h:59
TRadialGradient::fStart
Point fStart
Definition: TColorGradient.h:162
TColor
Definition: TColor.h:19
TRadialGradient::GetStart
const Point & GetStart() const
Get start.
Definition: TColorGradient.cxx:292
TColorGradient::Point::fX
Double_t fX
Definition: TColorGradient.h:56
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TColorGradient::GetColors
const Double_t * GetColors() const
Get colors.
Definition: TColorGradient.cxx:159
TLinearGradient
Definition: TColorGradient.h:99
y
Double_t y[n]
Definition: legend1.C:17
TColorGradient::fColorPositions
std::vector< Double_t > fColorPositions
Definition: TColorGradient.h:72
TColorGradient::GetColorPositions
const Double_t * GetColorPositions() const
Get color positions.
Definition: TColorGradient.cxx:151
TRadialGradient::fType
EGradientType fType
Definition: TColorGradient.h:167
TRadialGradient::kExtended
@ kExtended
Definition: TColorGradient.h:132
TColorGradient::GetNumberOfSteps
SizeType_t GetNumberOfSteps() const
Get number of steps.
Definition: TColorGradient.cxx:143
unsigned int
TRadialGradient::fR1
Double_t fR1
Definition: TColorGradient.h:163
TRadialGradient::kSimple
@ kSimple
Definition: TColorGradient.h:131
TLinearGradient::fStart
Point fStart
Definition: TColorGradient.h:114
TLinearGradient::SetStartEnd
void SetStartEnd(const Point &p1, const Point &p2)
Set end and start.
Definition: TColorGradient.cxx:218
Double_t
double Double_t
Definition: RtypesCore.h:59
TRadialGradient::SetRadialGradient
void SetRadialGradient(const Point &center, Double_t radius)
Set radial gradient.
Definition: TColorGradient.cxx:324
TLinearGradient::GetEnd
const Point & GetEnd() const
Get end.
Definition: TColorGradient.cxx:235
TRadialGradient::GetGradientType
EGradientType GetGradientType() const
Get gradient type.
Definition: TColorGradient.cxx:271
TColorGradient::SizeType_t
std::vector< Color_t >::size_type SizeType_t
Definition: TColorGradient.h:43
TColorGradient::fColors
std::vector< Double_t > fColors
Definition: TColorGradient.h:73
points
point * points
Definition: X3DBuffer.c:22
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TRadialGradient::TRadialGradient
TRadialGradient()
Definition: TColorGradient.cxx:246
TRadialGradient::fR2
Double_t fR2
Definition: TColorGradient.h:165
TRadialGradient::EGradientType
EGradientType
Definition: TColorGradient.h:130
TColorGradient::SetCoordinateMode
void SetCoordinateMode(ECoordinateMode mode)
Set coordinate mode.
Definition: TColorGradient.cxx:127
TRadialGradient::GetRadius
Double_t GetRadius() const
Get radius.
Definition: TColorGradient.cxx:343
Rtypes.h
TLinearGradient::fEnd
Point fEnd
Definition: TColorGradient.h:115
TRadialGradient::GetEnd
const Point & GetEnd() const
Get end.
Definition: TColorGradient.cxx:308
TRadialGradient::GetR1
Double_t GetR1() const
Definition: TColorGradient.cxx:300