Fade: Delphi Version


{*****************************************************************************
*                                                                            *
*  Fade.dpr                                                                  *
*  FadeU.pas                                                                 *
*                                                                            *
*  This program shows how perform a palette fade.                            *
*                                                                            *
*****************************************************************************}
unit FadeU;
interface
uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, Menus, FGWin;
type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    FadeIn: TMenuItem;
    FadeOut: TMenuItem;
    Exit1: TMenuItem;
    procedure AppOnActivate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FadeInClick(Sender: TObject);
    procedure FadeOutClick(Sender: TObject);
    procedure ExitClick(Sender: TObject);
  end;
var
  Form1: TForm1;
implementation
{$R *.DFM}
const
  vbWidth  = 320;
  vbHeight = 200;
var
  dc   : hDC;
  hPal : hPalette;
  hVB  : integer;
  cxClient, cyClient : integer;
  Original : array [1..236*3] of byte;
  Current  : array [1..236*3] of byte;
procedure TForm1.FormActivate(Sender: TObject);
begin
  fg_realize(hPal);
  Invalidate;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
  dc := GetDC(Form1.Handle);
  fg_setdc(dc);
  hPal := fg_defpal;
  fg_realize(hPal);
  fg_vbinit;
  hVB := fg_vballoc(vbWidth,vbHeight);
  fg_vbopen(hVB);
  fg_vbcolors;
  fg_showpcx('MOUSE.PCX'+chr(0),FG_AT_XY);
  fg_getdacs(10,236,Original);
  Application.OnActivate := AppOnActivate;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
  fg_vbscale(0,vbWidth-1,0,vbHeight-1,0,cxClient-1,0,cyClient-1);
end;
procedure TForm1.FormResize(Sender: TObject);
begin
  cxClient := ClientWidth;
  cyClient := ClientHeight;
  Invalidate;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
  fg_vbclose;
  fg_vbfree(hVB);
  fg_vbfin;
  DeleteObject(hPal);
  ReleaseDC(Form1.Handle,dc);
end;
{*****************************************************************************
*                                                                            *
*  FadeInClick()                                                             *
*                                                                            *
*  Fade an image back to its original colors.                                *
*                                                                            *
*****************************************************************************}
procedure TForm1.FadeInClick(Sender: TObject);
var
  i : integer;
  Fading : boolean;
begin
  Cursor := crHourGlass;
  FillChar(Current,236*3,0);
  Fading := True;
  while Fading do
  begin
    Fading := False;
    for i := 1 to 236*3 do
    begin
      if (Current[i] <> Original[i]) then
      begin
        inc(Current[i]);
        Fading := True;
      end;
    end;
    fg_setdacs(10,236,Current);
    if (fg_colors > 8) then
      fg_vbscale(0,vbWidth-1,0,vbHeight-1,0,cxClient-1,0,cyClient-1);
  end;
  FadeIn.Enabled  := False;
  FadeOut.Enabled := True;
  Cursor := crDefault;
end;
{*****************************************************************************
*                                                                            *
*  FadeOutClick()                                                            *
*                                                                            *
*  Fade an image to black.                                                   *
*                                                                            *
*****************************************************************************}
procedure TForm1.FadeOutClick(Sender: TObject);
var
  i : integer;
  Fading : boolean;
begin
  Cursor := crHourGlass;
  Move(Original,Current,236*3);
  Fading := True;
  while Fading do
  begin
    Fading := False;
    for i := 1 to 236*3 do
    begin
      if (Current[i] <> 0) then
      begin
        dec(Current[i]);
        Fading := True;
      end;
    end;
    fg_setdacs(10,236,Current);
    if (fg_colors > 8) then
      fg_vbscale(0,vbWidth-1,0,vbHeight-1,0,cxClient-1,0,cyClient-1);
  end;
  FadeIn.Enabled  := True;
  FadeOut.Enabled := False;
  Cursor := crDefault;
end;
procedure TForm1.ExitClick(Sender: TObject);
begin
  Close;
end;
{****************************************************************************}
procedure TForm1.AppOnActivate(Sender: TObject);
begin
  fg_realize(hPal);
  Invalidate;
end;
end.

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.