2005. május 24., kedd

How to create logical colour palettes


Can someone explain the palPalEntry? I don't understand what the array[0..0] does and how to use it.


You can use this for indicating the number of colours your palette is to contain. You should allocate memory for the palette dynamically, this way you can decide how much memory you want to put aside for the palette, i.e.

  LogPal: PLogPalette;
  Palette: HPalette;
  PalSize: LongInt;
  { ... }
  PalSize := 2 * SizeOf(Word) + n_Colors * SizeOf(TPaletteEntry));
{2 * SizeOf(Word) to get space for palVersion and palNumEntries,  n_Colors is the number
of colors in the palette}
GetMem(LogPal, PalSize);
LogPal^.palVersion := $0300;
LogPal^.palNumEntries := n_Colors;
LogPal^.palPalEntry[0] := {Some colour};
LogPal^.palPalEntry[1] := {Some other colour};
{ etc. }
FreeMem(LogPal, PalSize);
{ ... }

This has to be compiled with $R- (no range checking), otherwise you will get an error when you try using palPalEntry with an index higher than 0.

Nincsenek megjegyzések:

Megjegyzés küldése