Logo ROOT   6.08/07
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 #ifndef ROOT_Rtypes
31 #include "Rtypes.h"
32 #endif
33 
34 #ifndef ROOT_TColor
35 #include "TColor.h"
36 #endif
37 
38 
39 class TColorGradient : public TColor {
40 public:
41  typedef std::vector<Color_t>::size_type SizeType_t;
42 
43  //TODO: Replace with enum class as soon as we have C++11 enabled by default.
44  //CoordinateMode: both linear and radial gradients require some points - the
45  //start and end points.
46  //We can use either pad's rectangle as a coordinate system
47  //or an object's bounding rect.
49  kPadMode,//NDC, in a pad's rectangle (pad is 0,0 - 1,1).
50  kObjectBoundingMode //NDC in an object's bounding rect (this rect is 0,0 - 1, 1).
51  };
52 
53  struct Point {
56 
58  : fX(0.), fY(0.)
59  {
60  }
61 
63  : fX(x), fY(y)
64  {
65  }
66  };
67 
68 private:
69  //Positions of color nodes in a gradient, in NDC.
70  std::vector<Double_t> fColorPositions;
71  std::vector<Double_t> fColors;//RGBA values.
72 
73  //'default value' is kObjectBoundingMode.
75 
76 protected:
78 
79  TColorGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
80  const Color_t *colorIndices, ECoordinateMode mode = kObjectBoundingMode);
81  TColorGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
83 
84 public:
85  void ResetColor(UInt_t nPoints, const Double_t *points,
86  const Color_t *colorIndices);
87  void ResetColor(UInt_t nPoints, const Double_t *points,
88  const Double_t *colorIndices);
89 
92 
93  SizeType_t GetNumberOfSteps()const;
94  const Double_t *GetColorPositions()const;
95  const Double_t *GetColors()const;
96 
97 private:
98  void RegisterColor(Color_t colorIndex);
99 
100  ClassDef(TColorGradient, 0); //Gradient fill.
101 };
102 
104 public:
105  //With C++11 we'll use inherited constructors!!!
106  TLinearGradient();
107  TLinearGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
108  const Color_t *colorIndices, ECoordinateMode mode = kObjectBoundingMode);
109  TLinearGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
111 
112  //points are always in NDC (and also affected by fCoordinateMode).
113  void SetStartEnd(const Point &p1, const Point &p2);
114  const Point &GetStart()const;
115  const Point &GetEnd()const;
116 
117 private:
120 
121  ClassDef(TLinearGradient, 0); //Linear gradient fill.
122 };
123 
124 //
125 //Radial gradient. Can be either "simple": you specify a center
126 //and radius in NDC coordinates (see comments about linear gradient
127 //and coordinate modes above), or "extended": you have two centers
128 //(start,end) and two radiuses (R1, R2) and interpolation between them;
129 //still start/end and radiuses are in NDC.
130 //
131 
133 public:
136  kExtended
137  };
138 
139 
140  //With C++11 we'll use inherited constructors!!!
141  TRadialGradient();
142  TRadialGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
143  const Color_t *colorIndices, ECoordinateMode mode = kObjectBoundingMode);
144  TRadialGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
146 
147 
148  EGradientType GetGradientType()const;
149 
150 
151  //Extended gradient.
152  void SetStartEndR1R2(const Point &p1, Double_t r1,
153  const Point &p2, Double_t r2);
154  const Point &GetStart()const;
155  Double_t GetR1()const;
156  const Point &GetEnd()const;
157  Double_t GetR2()const;
158 
159  //Simple radial gradient: the same as extended with
160  //start == end, r1 = 0, r2 = radius.
161  void SetRadialGradient(const Point &center, Double_t radius);
162  const Point &GetCenter()const;
163  Double_t GetRadius()const;
164 
165 private:
167  Double_t fR1 = 0.;
169  Double_t fR2 = 0.;
170 
171  EGradientType fType = kSimple;
172 
173  ClassDef(TRadialGradient, 0); //Radial gradient fill.
174 };
175 
176 
177 #endif
const Double_t * GetColorPositions() const
Get color positions.
ECoordinateMode GetCoordinateMode() const
Get coordinate mode.
SizeType_t GetNumberOfSteps() const
Get number of steps.
std::vector< Double_t > fColorPositions
Define a radial color gradient.
TColorGradient()
Constructor.
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:254
static double p2(double t, double a, double b, double c)
void SetCoordinateMode(ECoordinateMode mode)
Set coordinate mode.
std::vector< Double_t > fColors
short Color_t
Definition: RtypesCore.h:79
void RegisterColor(Color_t colorIndex)
Register color.
std::vector< Color_t >::size_type SizeType_t
point * points
Definition: X3DBuffer.c:20
unsigned int r1[N_CITIES]
Definition: simanTSP.cxx:321
unsigned int UInt_t
Definition: RtypesCore.h:42
static double p1(double t, double a, double b)
PyObject * fType
Define a linear color gradient.
Color * colors
Definition: X3DBuffer.c:19
double Double_t
Definition: RtypesCore.h:55
Point(Double_t x, Double_t y)
Double_t y[n]
Definition: legend1.C:17
The color creation and management class.
Definition: TColor.h:23
void ResetColor(UInt_t nPoints, const Double_t *points, const Color_t *colorIndices)
Reset color.
const Double_t * GetColors() const
Get colors.
TColorGradient extends basic TColor.
unsigned int r2[N_CITIES]
Definition: simanTSP.cxx:322
ECoordinateMode fCoordinateMode