1 | unit UFormMain;
|
---|
2 |
|
---|
3 | {$mode delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
|
---|
9 | ExtCtrls, UEngine, LCLType, types;
|
---|
10 |
|
---|
11 | type
|
---|
12 |
|
---|
13 | { TFormMain }
|
---|
14 |
|
---|
15 | TFormMain = class(TForm)
|
---|
16 | PaintBox1: TPaintBox;
|
---|
17 | Timer1: TTimer;
|
---|
18 | procedure FormCreate(Sender: TObject);
|
---|
19 | procedure FormDestroy(Sender: TObject);
|
---|
20 | procedure FormKeyPress(Sender: TObject; var Key: char);
|
---|
21 | procedure FormShow(Sender: TObject);
|
---|
22 | procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
|
---|
23 | Shift: TShiftState; X, Y: Integer);
|
---|
24 | procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
|
---|
25 | Y: Integer);
|
---|
26 | procedure PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
|
---|
27 | Shift: TShiftState; X, Y: Integer);
|
---|
28 | procedure PaintBox1MouseWheelDown(Sender: TObject; Shift: TShiftState;
|
---|
29 | MousePos: TPoint; var Handled: Boolean);
|
---|
30 | procedure PaintBox1MouseWheelUp(Sender: TObject; Shift: TShiftState;
|
---|
31 | MousePos: TPoint; var Handled: Boolean);
|
---|
32 | procedure PaintBox1Paint(Sender: TObject);
|
---|
33 | procedure PaintBox1Resize(Sender: TObject);
|
---|
34 | procedure Timer1Timer(Sender: TObject);
|
---|
35 | public
|
---|
36 | Engine: TEngine;
|
---|
37 | procedure EraseBackground(DC: HDC); override;
|
---|
38 | end;
|
---|
39 |
|
---|
40 | var
|
---|
41 | FormMain: TFormMain;
|
---|
42 |
|
---|
43 | implementation
|
---|
44 |
|
---|
45 | {$R *.lfm}
|
---|
46 |
|
---|
47 | uses
|
---|
48 | UFormImages;
|
---|
49 |
|
---|
50 | { TFormMain }
|
---|
51 |
|
---|
52 | procedure TFormMain.FormCreate(Sender: TObject);
|
---|
53 | begin
|
---|
54 | Engine := TEngine.Create;
|
---|
55 | //PaintBox1.ControlStyle := [csOpaque];
|
---|
56 | end;
|
---|
57 |
|
---|
58 | procedure TFormMain.FormDestroy(Sender: TObject);
|
---|
59 | begin
|
---|
60 | Engine.Free;
|
---|
61 | end;
|
---|
62 |
|
---|
63 | procedure TFormMain.FormKeyPress(Sender: TObject; var Key: char);
|
---|
64 | begin
|
---|
65 | if (Key = #32) then begin
|
---|
66 | if Engine.State = gsRunning then Engine.State := gsPaused
|
---|
67 | else if Engine.State = gsPaused then Engine.State := gsRunning;
|
---|
68 | end;
|
---|
69 | end;
|
---|
70 |
|
---|
71 | procedure TFormMain.FormShow(Sender: TObject);
|
---|
72 | begin
|
---|
73 | Randomize;
|
---|
74 | Engine.ImagePassenger.Picture.Assign(FormImages.ImagePassenger.Picture);
|
---|
75 | Engine.ImageLocomotive.Picture.Assign(FormImages.ImageLocomotive.Picture);
|
---|
76 | Engine.Map.Size := Point(PaintBox1.Width, PaintBox1.Height);
|
---|
77 | Engine.View.DestRect := Rect(0, 0, PaintBox1.Width, PaintBox1.Height);
|
---|
78 | Engine.Reset;
|
---|
79 | end;
|
---|
80 |
|
---|
81 | procedure TFormMain.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
|
---|
82 | Shift: TShiftState; X, Y: Integer);
|
---|
83 | begin
|
---|
84 | Engine.MouseDown(Button, Point(X, Y));
|
---|
85 | end;
|
---|
86 |
|
---|
87 | procedure TFormMain.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
|
---|
88 | Y: Integer);
|
---|
89 | begin
|
---|
90 | Engine.MouseMove(Point(X, Y));
|
---|
91 | end;
|
---|
92 |
|
---|
93 | procedure TFormMain.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;
|
---|
94 | Shift: TShiftState; X, Y: Integer);
|
---|
95 | begin
|
---|
96 | Engine.MouseUp(Button, Point(X, Y));
|
---|
97 | end;
|
---|
98 |
|
---|
99 | procedure TFormMain.PaintBox1MouseWheelDown(Sender: TObject;
|
---|
100 | Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
|
---|
101 | begin
|
---|
102 | Engine.View.Zoom := Engine.View.Zoom * 1.2;
|
---|
103 | end;
|
---|
104 |
|
---|
105 | procedure TFormMain.PaintBox1MouseWheelUp(Sender: TObject; Shift: TShiftState;
|
---|
106 | MousePos: TPoint; var Handled: Boolean);
|
---|
107 | begin
|
---|
108 | Engine.View.Zoom := Engine.View.Zoom / 1.2;
|
---|
109 | end;
|
---|
110 |
|
---|
111 | procedure TFormMain.PaintBox1Paint(Sender: TObject);
|
---|
112 | begin
|
---|
113 | Engine.View.DestRect := Rect(0, 0, PaintBox1.Width, PaintBox1.Height);
|
---|
114 | Engine.Paint(PaintBox1.Canvas);
|
---|
115 | end;
|
---|
116 |
|
---|
117 | procedure TFormMain.PaintBox1Resize(Sender: TObject);
|
---|
118 | begin
|
---|
119 | Engine.Redraw;
|
---|
120 | end;
|
---|
121 |
|
---|
122 | procedure TFormMain.Timer1Timer(Sender: TObject);
|
---|
123 | begin
|
---|
124 | Engine.Tick;
|
---|
125 | if Engine.RedrawPending then
|
---|
126 | PaintBox1.Repaint;
|
---|
127 | end;
|
---|
128 |
|
---|
129 | procedure TFormMain.EraseBackground(DC: HDC);
|
---|
130 | begin
|
---|
131 | // Do nothing, all background space covered by controls
|
---|
132 | end;
|
---|
133 |
|
---|
134 | end.
|
---|
135 |
|
---|