Panner: Delphi Version


{*****************************************************************************
*                                                                            *
*  Panner.dpr                                                                *
*  PannerU.pas                                                               *
*                                                                            *
*  This program shows how to pan the contents of a virtual buffer through    *
*  a smaller window.                                                         *
*                                                                            *
*****************************************************************************}
unit PannerU;
interface
uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  Forms, Dialogs, Menus, FGWin;
type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    Left: TMenuItem;
    Right: TMenuItem;
    Up: TMenuItem;
    Down: TMenuItem;
    Reset: 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 LeftClick(Sender: TObject);
    procedure RightClick(Sender: TObject);
    procedure UpClick(Sender: TObject);
    procedure DownClick(Sender: TObject);
    procedure ResetClick(Sender: TObject);
    procedure ExitClick(Sender: TObject);
  end;
var
  Form1: TForm1;
implementation
{$R *.DFM}
const
  vbWidth  = 640;
  vbHeight = 480;
var
  dc   : hDC;
  hPal : hPalette;
  hVB  : integer;
  cxClient, cyClient : integer;
  x, y : integer;
  xLimit, yLimit : integer;
procedure TForm1.AppOnActivate(Sender: TObject);
begin
  fg_realize(hPal);
  Invalidate;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
  fg_realize(hPal);
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_showbmp('PORCH.BMP'+chr(0),0);
  x := 0;
  y := 0;
  Application.OnActivate := AppOnActivate;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
  fg_vbpaste(x,x+(vbWidth-1),y,y+(vbHeight-1),0,vbHeight-1);
end;
procedure TForm1.FormResize(Sender: TObject);
begin
  cxClient := ClientWidth;
  cyClient := ClientHeight;
  Invalidate;
  if (cxClient < vbWidth) then
  begin
    xLimit := vbWidth - cxClient;
    if (x > 0)      then Left.Enabled := True;
    if (x < xLimit) then Right.Enabled := True;
  end
  else
  begin
    xLimit := 0;
    Left.Enabled  := False;
    Right.Enabled := False;
  end;
  if (cyClient < vbHeight) then
  begin
    yLimit := vbHeight - cyClient;
    if (y > 0)      then Up.Enabled := True;
    if (y < yLimit) then Down.Enabled := True;
  end
  else
  begin
    yLimit := 0;
    Up.Enabled   := False;
    Down.Enabled := False;
  end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
  fg_vbclose;
  fg_vbfree(hVB);
  fg_vbfin;
  DeleteObject(hPal);
  ReleaseDC(Form1.Handle,dc);
end;
procedure TForm1.LeftClick(Sender: TObject);
begin
  if (x = xLimit) then Right.Enabled := True;
  dec(x);
  fg_vbpaste(x,x+(vbWidth-1),y,y+(vbHeight-1),0,vbHeight-1);
  if (x = 0) then Left.Enabled := False;
end;
procedure TForm1.RightClick(Sender: TObject);
begin
  if (x = 0) then Left.Enabled := True;
  inc(x);
  fg_vbpaste(x,x+(vbWidth-1),y,y+(vbHeight-1),0,vbHeight-1);
  if (x = xLimit) then Right.Enabled := False;
end;
procedure TForm1.UpClick(Sender: TObject);
begin
  if (y = yLimit) then Down.Enabled := True;
  dec(y);
  fg_vbpaste(x,x+(vbWidth-1),y,y+(vbHeight-1),0,vbHeight-1);
  if (y = 0) then Up.Enabled := False;
end;
procedure TForm1.DownClick(Sender: TObject);
begin
  if (y = 0) then Up.Enabled := True;
  inc(y);
  fg_vbpaste(x,x+(vbWidth-1),y,y+(vbHeight-1),0,vbHeight-1);
  if (y = yLimit) then Down.Enabled := False;
end;
procedure TForm1.ResetClick(Sender: TObject);
begin
  x := 0;
  y := 0;
  fg_vbpaste(0,vbWidth-1,0,vbHeight-1,0,vbHeight-1);
  if (xLimit > 0) then Right.Enabled := True;
  if (yLimit > 0) then Down.Enabled := True;
  Left.Enabled := False;
  Up.Enabled := False;
end;
procedure TForm1.ExitClick(Sender: TObject);
begin
  Close;
end;
end.

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.