Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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-2023, 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 "TColor.h"
31
32class TColorGradient : public TColor {
33public:
34 typedef std::vector<Color_t>::size_type SizeType_t;
35
36 //TODO: Replace with enum class as soon as we have C++11 enabled by default.
37 //CoordinateMode: both linear and radial gradients require some points - the
38 //start and end points.
39 //We can use either pad's rectangle as a coordinate system
40 //or an object's bounding rect.
42 kPadMode, //NDC, in a pad's rectangle (pad is 0,0 - 1,1).
43 kObjectBoundingMode //NDC in an object's bounding rect (this rect is 0,0 - 1, 1).
44 };
45
46 struct Point {
49
51 : fX(0.), fY(0.)
52 {
53 }
54
56 : fX(x), fY(y)
57 {
58 }
59 };
60
61private:
62 //Positions of color nodes in a gradient, in NDC.
63 std::vector<Double_t> fColorPositions;
64 std::vector<Double_t> fColors;//RGBA values.
65
66 //'default value' is kObjectBoundingMode.
68
69public:
71 TColorGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
72 const Color_t *colorIndices, ECoordinateMode mode = kObjectBoundingMode);
73 TColorGradient(Color_t newColor, UInt_t nPoints, const Double_t *points,
75
76 void ResetColor(UInt_t nPoints, const Double_t *points,
77 const Color_t *colorIndices);
78 void ResetColor(UInt_t nPoints, const Double_t *points,
79 const Double_t *colorIndices);
80
81 void SetColorAlpha(UInt_t indx, Double_t alpha);
82 Double_t GetColorAlpha(UInt_t indx) const;
83
86
88 const Double_t *GetColorPositions() const;
89 const Double_t *GetColors() const;
90
91private:
92 void RegisterColor(Color_t colorIndex);
93
94 ClassDefOverride(TColorGradient, 1); //Gradient fill.
95};
96
98public:
99 //With C++11 we'll use inherited constructors!!!
101
103
104 //points are always in NDC (and also affected by fCoordinateMode).
105 void SetStartEnd(const Point &p1, const Point &p2);
106 const Point &GetStart() const;
107 const Point &GetEnd() const;
108
109private:
112
113 ClassDefOverride(TLinearGradient, 1); //Linear gradient fill.
114};
115
116//
117//Radial gradient. Can be either "simple": you specify a center
118//and radius in NDC coordinates (see comments about linear gradient
119//and coordinate modes above), or "extended": you have two centers
120//(start,end) and two radiuses (R1, R2) and interpolation between them;
121//still start/end and radiuses are in NDC.
122//
123
125public:
129 };
130
131 //With C++11 we'll use inherited constructors!!!
133
135
137
138 //Extended gradient.
139 void SetStartEndR1R2(const Point &p1, Double_t r1,
140 const Point &p2, Double_t r2);
141 const Point &GetStart() const;
142 Double_t GetR1() const;
143 const Point &GetEnd() const;
144 Double_t GetR2() const;
145
146 //Simple radial gradient: the same as extended with
147 //start == end, r1 = 0, r2 = radius.
148 void SetRadialGradient(const Point &center, Double_t radius);
149 const Point &GetCenter()const;
150 Double_t GetRadius()const;
151
152private:
157
159
160 ClassDefOverride(TRadialGradient, 1); //Radial gradient fill.
161};
162
163
164#endif
short Color_t
Definition RtypesCore.h:92
unsigned int UInt_t
Definition RtypesCore.h:46
double Double_t
Definition RtypesCore.h:59
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t points
Color * colors
Definition X3DBuffer.c:21
TColorGradient extends basic TColor.
void RegisterColor(Color_t colorIndex)
Register color.
const Double_t * GetColors() const
Get colors.
std::vector< Double_t > fColorPositions
std::vector< Color_t >::size_type SizeType_t
Double_t GetColorAlpha(UInt_t indx) const
Return alpha parameter of selected color.
void SetCoordinateMode(ECoordinateMode mode)
Set coordinate mode.
void ResetColor(UInt_t nPoints, const Double_t *points, const Color_t *colorIndices)
Reset color.
void SetColorAlpha(UInt_t indx, Double_t alpha)
Change alpha parameter of the color.
SizeType_t GetNumberOfSteps() const
Get number of steps.
ECoordinateMode fCoordinateMode
ECoordinateMode GetCoordinateMode() const
Get coordinate mode.
const Double_t * GetColorPositions() const
Get color positions.
std::vector< Double_t > fColors
The color creation and management class.
Definition TColor.h:21
void SetStartEnd(const Point &p1, const Point &p2)
Set end and start.
const Point & GetEnd() const
Get end.
const Point & GetStart() const
Get start.
Double_t GetR1() const
Double_t GetRadius() const
Get radius.
void SetStartEndR1R2(const Point &p1, Double_t r1, const Point &p2, Double_t r2)
Set start and end R1 and R2.
const Point & GetStart() const
Get start.
Double_t GetR2() const
Get R2.
const Point & GetCenter() const
Get center.
EGradientType fType
EGradientType GetGradientType() const
Get gradient type.
const Point & GetEnd() const
Get end.
void SetRadialGradient(const Point &center, Double_t radius)
Set radial gradient.
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Point(Double_t x, Double_t y)