133 lines
3.3 KiB
C++
133 lines
3.3 KiB
C++
#ifndef _COMMON_PUREPALETTE_HPP_
|
|
#define _COMMON_PUREPALETTE_HPP_
|
|
#include <string.h>
|
|
#ifndef _COMMON_WINDOWS_HPP_
|
|
#include <common/windows.hpp>
|
|
#endif
|
|
#ifndef _COMMON_PUREBITMAP_HPP_
|
|
#include <common/purebmp.hpp>
|
|
#endif
|
|
#ifndef _COMMON_PUREDEVICE_HPP_
|
|
#include <common/purehdc.hpp>
|
|
#endif
|
|
#ifndef _COMMON_RGBCOLOR_HPP_
|
|
#include <common/rgbcolor.hpp>
|
|
#endif
|
|
#ifndef _COMMON_PUREVECTOR_HPP_
|
|
#include <common/pvector.hpp>
|
|
#endif
|
|
#ifndef _COMMON_PVECTOR_TPP_
|
|
#include <common/pvector.tpp>
|
|
#endif
|
|
#ifndef _COMMON_PALETTEENTRY_HPP_
|
|
#include <common/palentry.hpp>
|
|
#endif
|
|
|
|
class BitmapInfo;
|
|
|
|
class PurePalette
|
|
{
|
|
public:
|
|
enum {MaxColors=256};
|
|
enum InitPal{InitSys,InitNone};
|
|
typedef int PaletteIndex;
|
|
PurePalette(InitPal initPal=InitNone);
|
|
PurePalette(HPALETTE hPalette);
|
|
PurePalette(const PurePalette &somePurePalette);
|
|
PurePalette(const BitmapInfo &someBitmapInfo);
|
|
virtual ~PurePalette();
|
|
PurePalette &operator=(const PurePalette &somePurePalette);
|
|
PurePalette &operator=(const BitmapInfo &someBitmapInfo);
|
|
PurePalette &operator=(HPALETTE hPalette);
|
|
PaletteEntry &operator[](PaletteIndex paletteIndex);
|
|
WORD operator==(const PurePalette &somePurePalette)const;
|
|
WORD identityPalette(void);
|
|
WORD systemPalette(void);
|
|
WORD isIdentityPalette(void)const;
|
|
void cyclePalette(void);
|
|
PaletteIndex paletteIndex(const RGBColor &someRGBColor)const;
|
|
void getPaletteColors(PureVector<RGBColor> &someRGBColors)const;
|
|
void setPaletteColors(PureVector<RGBColor> &someRGBColors,PaletteEntry::PaletteFlags paletteFlag=PaletteEntry::NullFlag);
|
|
WORD setPaletteColor(short paletteIndex,RGBColor &someRGBColor,PaletteEntry::PaletteFlags paletteFlag=PaletteEntry::NullFlag);
|
|
WORD getPaletteColor(short paletteIndex,RGBColor &someRGBColor)const;
|
|
void clearPalette(void);
|
|
void usePalette(const PureDevice &somePureDevice,short usage);
|
|
WORD paletteEntry(PaletteIndex paletteIndex,RGBColor &someRGBColor)const;
|
|
RGBColor paletteEntry(PaletteIndex paletteIndex)const;
|
|
WORD paletteEntries(void)const;
|
|
WORD isInUse(void)const;
|
|
operator HPALETTE(void)const;
|
|
private:
|
|
enum {SystemStaticColors=20};
|
|
WORD createPalette(void);
|
|
void clearPaletteEntries(void);
|
|
void setPaletteColors(void)const;
|
|
void destroyPalette(void);
|
|
|
|
HPALETTE mhPalette;
|
|
HPALETTE mhOldPalette;
|
|
PaletteEntry mPaletteData[MaxColors];
|
|
WORD mIsInUse;
|
|
};
|
|
|
|
inline
|
|
PurePalette::PurePalette(InitPal initPal)
|
|
: mhPalette(0), mhOldPalette(0), mIsInUse(FALSE)
|
|
{
|
|
if(InitSys==initPal)systemPalette();
|
|
else {clearPaletteEntries(),createPalette();}
|
|
return;
|
|
}
|
|
|
|
inline
|
|
PurePalette::~PurePalette()
|
|
{
|
|
destroyPalette();
|
|
return;
|
|
}
|
|
|
|
inline
|
|
WORD PurePalette::paletteEntries(void)const
|
|
{
|
|
return MaxColors;
|
|
}
|
|
|
|
inline
|
|
PurePalette::operator HPALETTE(void)const
|
|
{
|
|
return mhPalette;
|
|
}
|
|
|
|
inline
|
|
void PurePalette::clearPaletteEntries(void)
|
|
{
|
|
::memset((void*)&mPaletteData,0,sizeof(mPaletteData));
|
|
}
|
|
|
|
inline
|
|
void PurePalette::setPaletteColors(void)const
|
|
{
|
|
::SetPaletteEntries(mhPalette,0,MaxColors,(PALETTEENTRY FAR*)&mPaletteData);
|
|
}
|
|
|
|
inline
|
|
WORD PurePalette::isInUse(void)const
|
|
{
|
|
return mIsInUse;
|
|
}
|
|
|
|
inline
|
|
PurePalette::PaletteIndex PurePalette::paletteIndex(const RGBColor &someRGBColor)const
|
|
{
|
|
return ::GetNearestPaletteIndex(mhPalette,(COLORREF)someRGBColor);
|
|
}
|
|
|
|
inline
|
|
PaletteEntry &PurePalette::operator[](PaletteIndex paletteIndex)
|
|
{
|
|
assert(paletteIndex<MaxColors);
|
|
return mPaletteData[paletteIndex];
|
|
}
|
|
#endif
|
|
|