Re: [ROOT] Colours

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Mon Aug 19 2002 - 11:26:25 MEST


I Simon,

 I've simplified your life and implemented a correct conversion method
in the TColor class. Now in cvs and in the coming release later this
week.

The API is:
new method TColor::GetPixel() and static method TColor::Number2Pixel().
Use these methods to get the pixel value associated with the TColor.
This pixel value can be directly used in the TGxxx GUI classes. For
example:
   TCanvas *c = new TCanvas;
   widget->ChangeBackground(TColor::Number2Pixel(c->GetFillColor()));

Note that your solution only works for TrueColor X11 servers and for a
specific endianness of the RGB word.


Cheers, Fons.


On Fri, 2002-08-16 at 23:49, Simon Dean wrote:
> OK, I solved this one.
> 
> If you want to take a TColor and find the equivalent ULong_t for the
> argument of a TGFrame (which specifies the background colour) this is how
> to do it. You need to know the colour number identifier (select
> View->Colors from a TCanvas) which is referred to here as 'i':
> 
>     float red = gROOT->GetColor(i)->GetRed();
>     float blue = gROOT->GetColor(i)->GetBlue();
>     float green = gROOT->GetColor(i)->GetGreen();
> 
>     int redbit = (int)(red*31);
>     int greenbit = (int)(green*63);
>     int bluebit = (int)(blue*31);
> 
>     ULong_t colourindex = (redbit<<11)+(greenbit<<5)+bluebit;
> 
> Then just give colourindex as the TGFrame argument like:
> 
> 	new TGFrame(gClient->GetRoot(), 32, 32, 0, colourindex);
> 
> cheers,
> 
> Simon
> 
> On Fri, 9 Aug 2002, Simon Dean wrote:
> 
> > Hi Fons,
> > 
> > Thanks for the reply, although it did not solve the problem. You see, the
> > tutorial you quote deals with TCanvas and TPad, both classes which inherit
> > from TAttFill. This class uses the TColor system and is very user-friendly
> > and nice. My original problem, however, was that TGFrame does not inherit
> > from TAttFill and instead takes an ULong_t as an argument to specify the
> > background colour. 
> > 
> > I can't find a way of translating between a TColor and the equivalent
> > ULong_t pixel number. Is there such a system?
> > 
> > Thanks a lot,
> > 
> > Simon
> > 
> > On 9 Aug 2002, Fons Rademakers wrote:
> > 
> > > Yes it is possible, check $ROOTSYS/tutorials/greyscale.C.
> > > 
> > > Cheers, Fons.
> > > 
> > > 
> > > 
> > > On Thu, 2002-08-08 at 21:08, Simon Dean wrote:
> > > > Hello,
> > > > 
> > > > I would like to make a TH1F and a TGFrame the same colour. This seems to
> > > > be impossible because TH1s use the TColor scheme and TGFrames require a
> > > > pixel number. Is it possible?
> > > > 
> > > > cheers,
> > > > 
> > > > Simon
> > > 
> > 
-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7679480



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:05 MET