]>
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
)
80 m_refData
= new wxPaletteRefData
;
82 NPLOGPALETTE npPal
= (NPLOGPALETTE
)LocalAlloc(LMEM_FIXED
, sizeof(LOGPALETTE
) +
83 (WORD
)n
* sizeof(PALETTEENTRY
));
87 npPal
->palVersion
= 0x300;
88 npPal
->palNumEntries
= n
;
91 for (i
= 0; i
< n
; i
++)
93 npPal
->palPalEntry
[i
].peRed
= red
[i
];
94 npPal
->palPalEntry
[i
].peGreen
= green
[i
];
95 npPal
->palPalEntry
[i
].peBlue
= blue
[i
];
96 npPal
->palPalEntry
[i
].peFlags
= 0;
98 M_PALETTEDATA
->m_hPalette
= (WXHPALETTE
) CreatePalette((LPLOGPALETTE
)npPal
);
99 LocalFree((HANDLE
)npPal
);
103 int wxPalette::GetPixel(const unsigned char red
, const unsigned char green
, const unsigned char blue
) const
108 return ::GetNearestPaletteIndex((HPALETTE
) M_PALETTEDATA
->m_hPalette
, PALETTERGB(red
, green
, blue
));
111 bool wxPalette::GetRGB(int index
, unsigned char *red
, unsigned char *green
, unsigned char *blue
) const
116 if (index
< 0 || index
> 255)
120 if (::GetPaletteEntries((HPALETTE
) M_PALETTEDATA
->m_hPalette
, index
, 1, &entry
))
123 *green
= entry
.peGreen
;
124 *blue
= entry
.peBlue
;
130 void wxPalette::SetHPALETTE(WXHPALETTE pal
)
133 m_refData
= new wxPaletteRefData
;
135 M_PALETTEDATA
->m_hPalette
= pal
;