]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/palette.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "palette.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/palette.h"
33 #if !USE_SHARED_LIBRARIES
34 IMPLEMENT_DYNAMIC_CLASS(wxPalette
, wxGDIObject
)
42 wxPaletteRefData::wxPaletteRefData(void)
47 wxPaletteRefData::~wxPaletteRefData(void)
50 ::DeleteObject((HPALETTE
) m_hPalette
);
53 wxPalette::wxPalette(void)
57 wxPalette::wxPalette(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
59 Create(n
, red
, green
, blue
);
62 wxPalette::~wxPalette(void)
64 // FreeResource(TRUE);
67 bool wxPalette::FreeResource(bool force
)
69 if ( M_PALETTEDATA
&& M_PALETTEDATA
->m_hPalette
)
71 DeleteObject((HPALETTE
)M_PALETTEDATA
->m_hPalette
);
76 bool wxPalette::Create(int n
, const unsigned char *red
, const unsigned char *green
, const unsigned char *blue
)
86 m_refData
= new wxPaletteRefData
;
88 NPLOGPALETTE npPal
= (NPLOGPALETTE
)LocalAlloc(LMEM_FIXED
, sizeof(LOGPALETTE
) +
89 (WORD
)n
* sizeof(PALETTEENTRY
));
93 npPal
->palVersion
= 0x300;
94 npPal
->palNumEntries
= n
;
97 for (i
= 0; i
< n
; i
++)
99 npPal
->palPalEntry
[i
].peRed
= red
[i
];
100 npPal
->palPalEntry
[i
].peGreen
= green
[i
];
101 npPal
->palPalEntry
[i
].peBlue
= blue
[i
];
102 npPal
->palPalEntry
[i
].peFlags
= 0;
104 M_PALETTEDATA
->m_hPalette
= (WXHPALETTE
) CreatePalette((LPLOGPALETTE
)npPal
);
105 LocalFree((HANDLE
)npPal
);
111 int wxPalette::GetPixel(const unsigned char red
, const unsigned char green
, const unsigned char blue
) const
116 return ::GetNearestPaletteIndex((HPALETTE
) M_PALETTEDATA
->m_hPalette
, PALETTERGB(red
, green
, blue
));
119 bool wxPalette::GetRGB(int index
, unsigned char *red
, unsigned char *green
, unsigned char *blue
) const
124 if (index
< 0 || index
> 255)
128 if (::GetPaletteEntries((HPALETTE
) M_PALETTEDATA
->m_hPalette
, index
, 1, &entry
))
131 *green
= entry
.peGreen
;
132 *blue
= entry
.peBlue
;
138 void wxPalette::SetHPALETTE(WXHPALETTE pal
)
141 m_refData
= new wxPaletteRefData
;
143 M_PALETTEDATA
->m_hPalette
= pal
;