home *** CD-ROM | disk | FTP | other *** search
- { Project Pan.DPR Delphi 2.0 Demos
-
- Description:- Pan.Dpr Project:-
-
- Demonstrates the use of:
-
- 1) 'Pan'
- 2) 'ScrollBars'
- 3) 'Repos'
-
- Date of Origin: 18/04/96
- Original Author: Andrew Hutchison
- Modification History:
-
- Date Person Change
- ----------------------------------------------------
- 18/04/96 A Hutchison Created
-
- (c) Copyright Media Architects Inc. 1996.
- All rights reserved. No part of this program may be
- photocopied, reproduced, translated to another programming
- language or transported to any computer system without the
- prior written consent of Media Architects Inc.}
-
- unit UPan;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ExtCtrls, Menus, OleCtrls, ImageKnife32, StdCtrls;
-
- type
- TForm1 = class(TForm)
- OpenDialog: TOpenDialog;
- MainMenu1: TMainMenu;
- File1: TMenuItem;
- LoadImage1: TMenuItem;
- N1: TMenuItem;
- Exit1: TMenuItem;
- Bevel1: TBevel;
- Picbuf1: TPicbuf;
- ScrollBars: TCheckBox;
- procedure FormCreate(Sender: TObject);
- procedure LoadImage1Click(Sender: TObject);
- procedure Picbuf1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure Picbuf1MouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- procedure ScrollBarsClick(Sender: TObject);
- procedure Exit1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- {Used to find Demo Images}
- function GetImageLocation:String;
-
- {Globals required for Pan Operations}
- var
- Startx, Starty, Pixelx, Pixely, Imagestartx, Imagestarty : Integer;
-
-
- implementation
-
- {$R *.DFM}
-
- {--------------------------------------------------------------------------------}
- {Set Defaults}
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Application.HintPause:=10;
- Application.HintColor:=clAqua;
-
- {Set FileNames - uses GetImageLocation function - See Below}
- Picbuf1.filename := GetImageLocation + 'images\marybeth.tif';
-
- {Load Default Source Image if it exists}
- if FileExists(Picbuf1.filename) then{Delphi function call - True if file exists}
- Picbuf1.Load
- else
- MessageDlg('Cannot find Sample file [\images\squirrel.bmp].' +
- ' Users should manually load this Image into the Source Picture.', mtInformation,
- [mbOk], 0);
- end;
-
- {--------------------------------------------------------------------------------}
- {Load Image into Picbuf}
- procedure TForm1.LoadImage1Click(Sender: TObject);
- begin
- {Open File}
- if OpenDialog.execute then
- begin
- {Set Name}
- Picbuf1.Filename := OpenDialog.FileName;
- {Call Load}
- Picbuf1.Load;
- {Set Pointer}
- Picbuf1.MousePointer := 15;
- end;
- end;
-
- {--------------------------------------------------------------------------------}
- { When the user clicks the Image get the Mouse location. With Delphi no Conversions
- are Required as all units are in Pixels}
- procedure TForm1.Picbuf1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- if ssleft in Shift then {Left Mouse Button}
- begin
- ImagestartX := Picbuf1.ScreenToImageX(X);{Mouse Down X}
- ImagestartY := Picbuf1.ScreenToImageY(Y);{Mouse Down Y}
- end;
- end;
-
- {--------------------------------------------------------------------------------}
- {Reposition the Image, linked to the Mouse Pointer Position}
- procedure TForm1.Picbuf1MouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- begin
- if ssleft in Shift then {Left Mouse Button}
- begin
- Pixelx := X ; {Current Mouse Location}
- Pixely := Y ; {Current Mouse Location}
- {Make Sure Valid Location}
- If ((x > 0) And (y > 0) And (x < Picbuf1.Width) And (y < Picbuf1.Height)) Then
- Picbuf1.RePos(imagestartx, imagestarty, pixelx, pixely); {RePos Image}
- end;
- end;
-
- {--------------------------------------------------------------------------------}
- {Enable Disable Scroll Bars}
- procedure TForm1.ScrollBarsClick(Sender: TObject);
- begin
- if not ScrollBars.Checked then {If NOT checked then no Scroll Bars}
- begin
- Picbuf1.ScrollBars := 0;
- Picbuf1.MousePointer := 15; {Set Mouse Cursor}
- end
- else
- begin
- Picbuf1.ScrollBars := 3; {If Checked enable Scroll Bars}
- Picbuf1.MousePointer := 0; {Set Mouse Cursor}
- end;
- end;
-
- {-------------------------------------------------------------------------------)
- {Get Path of Default files:-
- Basically the functions gets the path name of the EXE location, strips of the last
- directory, ready for use - only applicable to this Demo. See Delphi on-line help}
- function GetImageLocation:String;
- Var
- Temp:String;
- DelphiLocation:Integer;
- begin
- Temp := ExtractFileDir(Application.exename); {Get full path of EXE}
- Temp := UpperCase(Temp); {Make Sure it is upper Case}
- DelphiLocation := Pos('\DELPHI2',Temp);
- Delete(Temp,DelphiLocation,length('\DELPHI2')); {Strip of last Directory}
- Result:=Temp + '\'; {Add the Missing '\'}
- end;
-
-
- {-------------------------------------------------------------------------------)
- {Exit Application}
- procedure TForm1.Exit1Click(Sender: TObject);
- begin
- Halt;
- end;
-
- end.
-