using System;
using System.Runtime.InteropServices;
using Vanara.Extensions;
namespace Vanara.PInvoke
{
/// The alpha intensity value for the palette entry.
[PInvokeData("wingdi.h")]
[Flags]
public enum PC : byte
{
///
/// Specifies that the low-order word of the logical palette entry designates a hardware palette index. This flag allows the
/// application to show the contents of the display device palette.
///
PC_EXPLICIT = 0x2,
///
/// Specifies that the color be placed in an unused entry in the system palette instead of being matched to an existing color in
/// the system palette. If there are no unused entries in the system palette, the color is matched normally. Once this color is
/// in the system palette, colors in other logical palettes can be matched to this color.
///
PC_NOCOLLAPSE = 0x4,
///
/// Specifies that the logical palette entry be used for palette animation. This flag prevents other windows from matching colors
/// to the palette entry since the color frequently changes. If an unused system-palette entry is available, the color is placed
/// in that entry. Otherwise, the color is not available for animation.
///
PC_RESERVED = 0x1,
}
/// The LOGPALETTE structure defines a logical palette.
///
/// The colors in the palette-entry table should appear in order of importance because entries earlier in the logical palette are
/// most likely to be placed in the system palette.
///
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-taglogpalette typedef struct tagLOGPALETTE { WORD
// palVersion; WORD palNumEntries; PALETTEENTRY palPalEntry[1]; } LOGPALETTE, *PLOGPALETTE, *NPLOGPALETTE, *LPLOGPALETTE;
[PInvokeData("wingdi.h", MSDNShortId = "99d70a0e-ac61-4a88-a500-66443e7882ad")]
[StructLayout(LayoutKind.Sequential)]
public class LOGPALETTE : IDisposable
{
/// The version number of the system.
public ushort palVersion;
/// The number of entries in the logical palette.
public ushort palNumEntries;
private IntPtr _palPalEntry;
/// Specifies an array of PALETTEENTRY structures that define the color and usage of each entry in the logical palette.
public PALETTEENTRY[] palPalEntry
{
get => _palPalEntry.ToArray(palNumEntries);
set { Marshal.FreeHGlobal(_palPalEntry); value.MarshalToPtr(Marshal.AllocHGlobal, out _); }
}
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
void IDisposable.Dispose() => Marshal.FreeHGlobal(_palPalEntry);
}
/// Specifies the color and usage of an entry in a logical palette.
// https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-tagpaletteentry typedef struct tagPALETTEENTRY { BYTE peRed;
// BYTE peGreen; BYTE peBlue; BYTE peFlags; } PALETTEENTRY, *PPALETTEENTRY, *LPPALETTEENTRY;
[PInvokeData("wingdi.h")]
[StructLayout(LayoutKind.Sequential)]
public struct PALETTEENTRY
{
///
/// Type: BYTE
/// The red intensity value for the palette entry.
///
public byte peRed;
///
/// Type: BYTE
/// The green intensity value for the palette entry.
///
public byte peGreen;
///
/// Type: BYTE
/// The blue intensity value for the palette entry.
///
public byte peBlue;
///
/// Type: BYTE
///
/// The alpha intensity value for the palette entry. Note that as of DirectX 8, this member is treated differently than
/// documented for Windows.
///
///
public PC peFlags;
}
}