Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit MainForm;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, Vcl.StdCtrls, Vcl.ExtDlgs,
- Vcl.ExtCtrls;
- type
- TMainForm = class(TForm)
- MainMenu: TMainMenu;
- FileItem: TMenuItem;
- HelpItem: TMenuItem;
- ExitItem: TMenuItem;
- AboutItem: TMenuItem;
- MainPanel: TPanel;
- PaintBox: TPaintBox;
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- procedure ExitItemClick(Sender: TObject);
- procedure AboutItemClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormPaint(Sender: TObject);
- procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
- private
- Shift: ShortInt;
- SkyBmp, PlaneBmp, PlaneLeft, PlaneRight: TBitmap;
- procedure Right;
- procedure Up;
- procedure Down;
- procedure Left;
- end;
- resourcestring
- QuitMessage = 'Are you sure you want to exit?';
- AboutMessage = 'This program';
- InvalidExtensionMessage = 'Invalid file type. Text file expected';
- var
- _MainForm: TMainForm;
- implementation
- {$R *.dfm}
- procedure TMainForm.AboutItemClick(Sender: TObject);
- begin
- MessageDlg(AboutMessage, mtInformation, [mbOk], 0);
- end;
- procedure TMainForm.Down;
- var
- TempBmp: TBitmap;
- begin
- TempBmp := TBitmap.Create;
- TempBmp.Width := 640;
- TempBmp.Height := 480;
- TempBmp.Canvas.CopyRect(Rect(0, 0, 640, 480 - Shift), SkyBmp.Canvas, Rect(0, Shift, 640, 480));
- TempBmp.Canvas.CopyRect(Rect(0, 480 - Shift, 640, 480), SkyBmp.Canvas, Rect(0, 0, 640, Shift));
- SkyBmp.Canvas.Draw(0, 0, TempBmp);
- TempBmp.Canvas.Draw(0, 0, SkyBmp);
- TempBmp.Canvas.Draw(200, 200, PlaneBmp);
- PaintBox.Canvas.Draw(0, 0, TempBmp);
- TempBmp.Free;
- end;
- procedure TMainForm.ExitItemClick(Sender: TObject);
- begin
- Close;
- end;
- procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- begin
- if MessageDlg(QuitMessage, mtConfirmation, mbYesNo, 0) = mrNo then
- CanClose := False;
- end;
- procedure TMainForm.FormCreate(Sender: TObject);
- begin
- Shift := 10;
- SkyBmp := TBitmap.Create;
- SkyBmp.LoadFromResourceName(HInstance, 'sky');
- PlaneLeft := TBitmap.Create;
- PlaneLeft.LoadFromResourceName(HInstance, 'plane_left');
- PlaneLeft.Transparent := True;
- PlaneRight := TBitmap.Create;
- PlaneRight.LoadFromResourceName(HInstance, 'plane_right');
- PlaneRight.Transparent := True;
- PlaneBmp := PlaneRight;
- end;
- procedure TMainForm.FormKeyDown(Sender: TObject; var Key: Word;
- Shift: TShiftState);
- begin
- case Key of
- VK_RIGHT: Right;
- VK_UP: Up;
- VK_DOWN: Down;
- VK_LEFT: Left;
- end;
- end;
- procedure TMainForm.FormPaint(Sender: TObject);
- begin
- PaintBox.Canvas.Draw(0, 0, SkyBmp);
- PaintBox.Canvas.Draw(200, 200, PlaneBmp);
- end;
- procedure TMainForm.Left;
- var
- TempBmp: TBitmap;
- begin
- PlaneBmp := PlaneLeft;
- TempBmp := TBitmap.Create;
- TempBmp.Width := 640;
- TempBmp.Height := 480;
- TempBmp.Canvas.CopyRect(Rect(Shift, 0, 640, 480), SkyBmp.Canvas, Rect(0, 0, 640 - Shift, 480));
- TempBmp.Canvas.CopyRect(Rect(0, 0, Shift, 480), SkyBmp.Canvas, Rect(640 - Shift, 0, 640, 480));
- SkyBmp.Canvas.Draw(0, 0, TempBmp);
- TempBmp.Canvas.Draw(0, 0, SkyBmp);
- TempBmp.Canvas.Draw(200, 200, PlaneBmp);
- PaintBox.Canvas.Draw(0, 0, TempBmp);
- TempBmp.Free;
- end;
- procedure TMainForm.Up;
- var
- TempBmp: TBitmap;
- begin
- TempBmp := TBitmap.Create;
- TempBmp.Width := 640;
- TempBmp.Height := 480;
- TempBmp.Canvas.CopyRect(Rect(0, Shift, 640, 480), SkyBmp.Canvas, Rect(0, 0, 640, 480 - Shift));
- TempBmp.Canvas.CopyRect(Rect(0, 0, 640, Shift), SkyBmp.Canvas, Rect(0, 480 - Shift, 640, 480));
- SkyBmp.Canvas.Draw(0, 0, TempBmp);
- TempBmp.Canvas.Draw(0, 0, SkyBmp);
- TempBmp.Canvas.Draw(200, 200, PlaneBmp);
- PaintBox.Canvas.Draw(0, 0, TempBmp);
- TempBmp.Free;
- end;
- procedure TMainForm.Right;
- var
- TempBmp: TBitmap;
- begin
- PlaneBmp := PlaneRight;
- TempBmp := TBitmap.Create;
- TempBmp.Width := 640;
- TempBmp.Height := 480;
- TempBmp.Canvas.CopyRect(Rect(0, 0, 640 - Shift, 480), SkyBmp.Canvas, Rect(Shift, 0, 640, 480));
- TempBmp.Canvas.CopyRect(Rect(640 - Shift, 0, 640, 480), SkyBmp.Canvas, Rect(0, 0, Shift, 480));
- SkyBmp.Canvas.Draw(0, 0, TempBmp);
- TempBmp.Canvas.Draw(0, 0, SkyBmp);
- TempBmp.Canvas.Draw(200, 200, PlaneBmp);
- PaintBox.Canvas.Draw(0, 0, TempBmp);
- TempBmp.Free;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement