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.
Post Reply
waterj
Earned a small fee
Earned a small fee
Posts: 21
Joined: Mon Nov 07, 2005 8:39 am

How to make wxClolour use an index of wxPalette?

Post by waterj » Fri Jan 06, 2006 9:35 am

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
Filthy Rich wx Solver
Posts: 205
Joined: Wed Mar 30, 2005 10:56 pm

Post by Jamie » Fri Jan 06, 2006 11:41 am

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
Earned a small fee
Posts: 21
Joined: Mon Nov 07, 2005 8:39 am

Post by waterj » Sat Jan 07, 2006 3:43 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
Filthy Rich wx Solver
Posts: 205
Joined: Wed Mar 30, 2005 10:56 pm

Post by Jamie » Sat Jan 07, 2006 2:01 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
Earned a small fee
Posts: 21
Joined: Mon Nov 07, 2005 8:39 am

Post by waterj » Sun Jan 08, 2006 9:12 am

Ok, I think it's the only way to make wx palette work.
Thanks fo help.

Post Reply