Re: [ROOT] Colours

From: Simon Dean (sdean@hep.man.ac.uk)
Date: Fri Aug 16 2002 - 23:49:23 MEST


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
> > 
> 



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