]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/palette.cpp
1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
18 #include "wx/palette.h"
27 IMPLEMENT_DYNAMIC_CLASS(wxPalette
, wxGDIObject
)
34 wxPaletteRefData::wxPaletteRefData()
39 wxPaletteRefData::~wxPaletteRefData()
43 // TODO: ::DeleteObject((HPALETTE) m_hPalette);
46 wxPalette::wxPalette()
50 wxPalette::wxPalette(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
52 Create(n
, red
, green
, blue
);
55 wxPalette::~wxPalette()
59 bool wxPalette::FreeResource(bool force
)
61 if ( M_PALETTEDATA
&& M_PALETTEDATA
->m_hPalette
)
63 // TODO: DeleteObject((HPALETTE)M_PALETTEDATA->m_hPalette);
68 bool wxPalette::Create(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
72 m_refData
= new wxPaletteRefData
;
76 NPLOGPALETTE npPal = (NPLOGPALETTE)LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) +
77 (WORD)n * sizeof(PALETTEENTRY));
81 npPal->palVersion = 0x300;
82 npPal->palNumEntries = n;
85 for (i = 0; i < n; i ++)
87 npPal->palPalEntry[i].peRed = red[i];
88 npPal->palPalEntry[i].peGreen = green[i];
89 npPal->palPalEntry[i].peBlue = blue[i];
90 npPal->palPalEntry[i].peFlags = 0;
92 M_PALETTEDATA->m_hPalette = (WXHPALETTE) CreatePalette((LPLOGPALETTE)npPal);
93 LocalFree((HANDLE)npPal);
98 int wxPalette::GetPixel(const unsigned char red
, const unsigned char green
, const unsigned char blue
) const
107 bool wxPalette::GetRGB(int index
, unsigned char *red
, unsigned char *green
, unsigned char *blue
) const
112 if (index
< 0 || index
> 255)
117 if (::GetPaletteEntries((HPALETTE) M_PALETTEDATA->m_hPalette, index, 1, &entry))
120 *green = entry.peGreen;
121 *blue = entry.peBlue;
129 void wxPalette::SetHPALETTE(WXHPALETTE pal
)
132 m_refData
= new wxPaletteRefData
;
134 M_PALETTEDATA
->m_hPalette
= pal
;