| Class TPaletteDemo (unit PalDemo) |
TCustomControl
Demostration of palettes and animation in a Delphi component. Copyright © 1997 Tempest Software, Inc. The TPaletteDemo component displays a color gradient, with a user-specified starting and ending color, and number of color steps between them. The gradient works on all systems. The Animate procedure randomly shifts the starting and ending colors, and animates the palette to change the display of the gradient without repainting. Palette animation works only on displays that use a palette, namely, 256-color video adapters.
| Constructors |
constructor Create(Owner: TComponent);| Functions |
procedure Animate;
destructor Destroy;
procedure DestroyPalette;
function GetPalette: HPalette;
function MakePalette: HPalette;
procedure MutateColors;
procedure Paint;
procedure UseNewPalette;
procedure SetColorBottom(Value: TColor);
procedure SetColorTop(Value: TColor);Change the top color.
procedure SetNumSteps(Value: Byte);| Properties |
property Align :
property ColorBottom : TColor
property ColorTop : TColor
property Height :
property NumSteps : Byte
property Width :
property Canvas : | Events |
event OnClick :
event OnDblClick :
event OnEnter :
event OnExit :
event OnMouseDown :
event OnMouseMove :
event OnMouseUp : | Variables |
DeltaBottom : TColor;
DeltaTop : TColor;
fColBottom : TColor;
fColorBottom : TColor;
fColorTop : TColor;
fColTop : TColor;
fNumSteps : Byte;
LogPal : PLogPalette;
PalHandle : HPalette;
PalSize : Integer;| Constructors |
constructor Create(Owner: TComponent);Create and initialize the palette demo control. Initialize the color deltas to random values, but make sure they are at least 1, so the colors really animate. Zero would be boring. Start with 64 steps because most palette devices use 18 bits per pixel, which means 6 bits per color, or 64 distinct colors.
| Functions |
procedure Animate;Mutate the colors and animate the system palette for those new colors.
Animate the control by mutating the color and then telling Windows to use the new colors.
destructor Destroy;Destroy the control. Clean up by freeing the palette resource and memory.
procedure DestroyPalette;Destroy the palette after the control is done using it.
Destroy the palette and free the palette memory.
function GetPalette: HPalette;Delphi calls GetPalette for every control. Return the palette handle to let Delphi take care of selecting and realizing that palette when it paints this control.
Return the palette handle.
function MakePalette: HPalette;Create the gradient palette and return its handle.
Make a gradient palette and return the palette handle. Call this once when initializing the control. After that, just change the palette entries without making a new palette. If the user changes the number of steps, then recreate the palette with a new size.
procedure MutateColors;Randomly mutate the colors and change the palette entries.
Change the colors to animate the palette.
procedure Paint;Paint this control by drawing the gradient.
Paint the gradient. Tell Windows to use the palette when painting this control, even if the display does not use a system palette. To do this, we must explicitly select the palette and use PaletteIndex as the color. To paint the gradient, divide the canvas into NumSteps bands, and fill each band with a solid color, chosen from the palette.
procedure UseNewPalette;Change the colors in the new palette.
Update the palette and tell Windows to use that new palette in the control. You must select the palette before animating it. Note that AnimatePalette does nothing on systems that do not use a display palette (that is, <> 256 colors).
procedure SetColorBottom(Value: TColor);Change the bottom color.
procedure SetColorTop(Value: TColor);size of LogPal memory
Change the top color.
procedure SetNumSteps(Value: Byte);Change the number of steps in the gradient. Note that this requires rebuilding the palette with a new size.
| Properties |
property Align :
property ColorBottom : TColor
property ColorTop : TColor
property Height :
property NumSteps : Byte
property Width :
property Canvas : Return the control's canvas.
| Events |
event OnClick :
event OnDblClick :
event OnEnter :
event OnExit :
event OnMouseDown :
event OnMouseMove :
event OnMouseUp : | Variables |
DeltaBottom : TColor;
DeltaTop : TColor;Delta for changing the color each iteration
fColBottom : TColor;
fColorBottom : TColor;
fColorTop : TColor;Colors for the end pointersin the gradient
fColTop : TColor;The same colors after mutation.
fNumSteps : Byte;Number of steps in the gradient
LogPal : PLogPalette;handle to the palette
PalHandle : HPalette;Palette information
PalSize : Integer;pointer to logical palette