## How to make wxClolour use an index of wxPalette? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
waterj
Earned a small fee
Posts: 21
Joined: Mon Nov 07, 2005 8:39 am

### How to make wxClolour use an index of wxPalette?

Hi guys. I find no way to make a wxColour from the color index of a palette. Anyone have any idea?
Thanks.

Jamie
Filthy Rich wx Solver
Posts: 205
Joined: Wed Mar 30, 2005 10:56 pm

Code: Select all

unsigned char red, green, blue;
bitmap.GetPalette()->GetRGB(paletteIndex, &red, &green, &blue);
wxColour colour(red, green, blue);

waterj
Earned a small fee
Posts: 21
Joined: Mon Nov 07, 2005 8:39 am
Jamie wrote:

Code: Select all

unsigned char red, green, blue;
bitmap.GetPalette()->GetRGB(paletteIndex, &red, &green, &blue);
wxColour colour(red, green, blue);
Thanks for post.
Maybe I didn't make myself clear. I create a palette like these:

Code: Select all

wxClientDC dc(this);

BYTE r[]={255,0,0}
BYTE g[]={0,255,0}
BYTE b[]={0,0,255}
wxPalette pal;
pal.Create(3, r, g, b);

dc.SetPalette(pal);
Now the question is: how to use an index to present the color in palette?

In MFC, we can say :
COLORREF clr = PALETTEINDEX(0);
where PALETTEINDX was defined as:
#define PALETTEINDEX(i) ((COLORREF)(0x01000000 | (DWORD)(WORD)(i)))

Jamie
Filthy Rich wx Solver
Posts: 205
Joined: Wed Mar 30, 2005 10:56 pm
waterj wrote:Now the question is: how to use an index to present the color in palette?
Is this not what I've already explained? You want to know how to convert a palette index into colour, correct?

Since you already have the palette:

Code: Select all

unsigned char red, green, blue;
pal.GetRGB(paletteIndex /* this is your index */, &red, &green, &blue);
wxColour colour(red, green, blue); // this is the colour
Maybe as a function might help:

Code: Select all

inline wxColour ConvertPaletteIndexToColour(const wxPalette& pal, int index)
{
unsigned char red, green, blue;
pal.GetRGB(index, &red, &green, &blue);
return wxColour(red, green, blue);
}

waterj
Earned a small fee
Posts: 21
Joined: Mon Nov 07, 2005 8:39 am
Ok, I think it's the only way to make wx palette work.
Thanks fo help.