From 508e764abaed838c440db59638ffa3bad924595d Mon Sep 17 00:00:00 2001 From: Olivier Couet <olivier.couet@cern.ch> Date: Tue, 31 May 2016 15:26:52 +0200 Subject: [PATCH] TColor::GetFreeColorIndex() allows to make sure the new color is created with an unused color index: --- README/ReleaseNotes/v608/index.md | 2 ++ core/base/inc/TColor.h | 1 + core/base/src/TColor.cxx | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/README/ReleaseNotes/v608/index.md b/README/ReleaseNotes/v608/index.md index db2370466ec..a01d70bad15 100644 --- a/README/ReleaseNotes/v608/index.md +++ b/README/ReleaseNotes/v608/index.md @@ -213,6 +213,8 @@ We added a cache specifically for the fast option of the TTreeCloner to signific * Fix two issues with the fill patterns in `TTextDump` (reported [here](https://sft.its.cern.ch/jira/browse/ROOT-8206)): - The pattern number 3 was not implemented. - Filled area drawn with pattern where surrounded by a solid line. +* `TColor::GetFreeColorIndex()` allows to make sure the new color is created with an + unused color index: ## 3D Graphics Libraries diff --git a/core/base/inc/TColor.h b/core/base/inc/TColor.h index 0f8fa67bf7c..b304059bb9c 100644 --- a/core/base/inc/TColor.h +++ b/core/base/inc/TColor.h @@ -88,6 +88,7 @@ public: static Int_t GetColorBright(Int_t color); static Int_t GetColorDark(Int_t color); static Int_t GetColorTransparent(Int_t color, Float_t a); + static Int_t GetFreeColorIndex(); static ULong_t Number2Pixel(Int_t ci); static ULong_t RGB2Pixel(Int_t r, Int_t g, Int_t b); static ULong_t RGB2Pixel(Float_t r, Float_t g, Float_t b); diff --git a/core/base/src/TColor.cxx b/core/base/src/TColor.cxx index b59a6d6f272..8d78a8c8756 100644 --- a/core/base/src/TColor.cxx +++ b/core/base/src/TColor.cxx @@ -89,6 +89,15 @@ A new color can be created the following way: TColor *color = new TColor(ci, 0.1, 0.2, 0.3); ~~~ +\since **6.07/07:** +TColor::GetFreeColorIndex() allows to make sure the new color is created with an +unused color index: + +~~~ {.cpp} + Int_t ci = TColor::GetFreeColorIndex(); + TColor *color = new TColor(ci, 0.1, 0.2, 0.3); +~~~ + Two sets of colors are initialized; - The basic colors: colors with index from 0 to 50. @@ -1863,6 +1872,20 @@ Int_t TColor::GetColorTransparent(Int_t n, Float_t a) } } +//////////////////////////////////////////////////////////////////////////////// +/// Static function: Returns a free color index which can be used to define +/// a user custom color. +/// +/// ~~~ {.cpp} +/// Int_t ci = TColor::GetFreeColorIndex(); +/// TColor *color = new TColor(ci, 0.1, 0.2, 0.3); +/// ~~~ + +Int_t TColor::GetFreeColorIndex() +{ + return gHighestColorIndex+1; +} + //////////////////////////////////////////////////////////////////////////////// /// Static method that given a color index number, returns the corresponding /// pixel value. This pixel value can be used in the GUI classes. This call -- GitLab