]>
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 #if !USE_SHARED_LIBRARIES
28 IMPLEMENT_DYNAMIC_CLASS(wxPalette
, wxGDIObject
)
36 wxPaletteRefData::wxPaletteRefData()
41 wxPaletteRefData::~wxPaletteRefData()
45 // TODO: ::DeleteObject((HPALETTE) m_hPalette);
48 wxPalette::wxPalette()
52 wxPalette::wxPalette(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
54 Create(n
, red
, green
, blue
);
57 wxPalette::~wxPalette()
61 bool wxPalette::FreeResource(bool force
)
63 if ( M_PALETTEDATA
&& M_PALETTEDATA
->m_hPalette
)
65 // TODO: DeleteObject((HPALETTE)M_PALETTEDATA->m_hPalette);
70 bool wxPalette::Create(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
74 m_refData
= new wxPaletteRefData
;
78 NPLOGPALETTE npPal = (NPLOGPALETTE)LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) +
79 (WORD)n * sizeof(PALETTEENTRY));
83 npPal->palVersion = 0x300;
84 npPal->palNumEntries = n;
87 for (i = 0; i < n; i ++)
89 npPal->palPalEntry[i].peRed = red[i];
90 npPal->palPalEntry[i].peGreen = green[i];
91 npPal->palPalEntry[i].peBlue = blue[i];
92 npPal->palPalEntry[i].peFlags = 0;
94 M_PALETTEDATA->m_hPalette = (WXHPALETTE) CreatePalette((LPLOGPALETTE)npPal);
95 LocalFree((HANDLE)npPal);
100 int wxPalette::GetPixel(const unsigned char red
, const unsigned char green
, const unsigned char blue
) const
109 bool wxPalette::GetRGB(int index
, unsigned char *red
, unsigned char *green
, unsigned char *blue
) const
114 if (index
< 0 || index
> 255)
119 if (::GetPaletteEntries((HPALETTE) M_PALETTEDATA->m_hPalette, index, 1, &entry))
122 *green = entry.peGreen;
123 *blue = entry.peBlue;
131 void wxPalette::SetHPALETTE(WXHPALETTE pal
)
134 m_refData
= new wxPaletteRefData
;
136 M_PALETTEDATA
->m_hPalette
= pal
;