-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUDogFrame.pas
72 lines (59 loc) · 1.68 KB
/
UDogFrame.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
unit UDogFrame;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, UDoubleBufferedFrame, Vcl.ExtCtrls,
System.ImageList, Vcl.ImgList, UMinesweeperDataController;
type
TDogFrame = class(TDoubleBufferedFrame)
ImageList1: TImageList;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
fController: TMineSweeperDataController;
protected
procedure CanvasPaint(aCanvas: TCanvas); override;
public
{ Public declarations }
property Controller: TMineSweeperDataController read fController write fController;
end;
var
DogFrame: TDogFrame;
implementation
uses
System.Math;
{$R *.dfm}
procedure TDogFrame.CanvasPaint(aCanvas: TCanvas);
begin
inherited;
aCanvas.Brush.Color := $00B3CBFF;
aCanvas.FillRect(aCanvas.ClipRect);
if not Assigned(Controller) then
Exit();
case Controller.GameState of
mgsIdle:
begin
ImageList1.Draw(aCanvas, 0, 0, 0);
var mousePosScreen := Mouse.CursorPos;
var mousePosClient := ScreenToClient(mousePosScreen);
var leftEyeX := Min(18, Max(11, mousePosClient.X));
var rightEyeX := Min(28, Max(24, mousePosClient.X));
aCanvas.Brush.Color := $002A2B4D;
aCanvas.Ellipse(leftEyeX, 14, leftEyeX + 5, 18);
aCanvas.Ellipse(rightEyeX, 14, rightEyeX + 5, 18);
end;
mgsLeftClick:
ImageList1.Draw(aCanvas, 0, 0, 1);
mgsExploded:
ImageList1.Draw(aCanvas, 0, 0, 3);
mgsVictory:
ImageList1.Draw(aCanvas, 0, 0, 2);
end;
end;
procedure TDogFrame.Timer1Timer(Sender: TObject);
begin
inherited;
Redraw();
end;
end.