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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormPaint(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Timer1Timer(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Déclarations privées }
bmp,bmpFond : TBitmap;
clic : boolean;
pt : TPoint;
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
s,m,he : extended;
r,w,h : integer;
F : File of TPoint;
point2 : TPoint;
Present: TDateTime;
Year,Month,Day,Hour,Min,Sec,Msec : Word;
X,Y : Int64;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var R1,R2 : HRGN;
i : integer;
begin
AssignFile(F,'C:\point.pt');
{$I-}
Reset(F);
{$I+}
if IOresult = 0 then
begin
Read(F,point2);
Left:=point2.X;
Top:=point2.Y;
end;
pt:=point(ClientWidth div 2,ClientHeight div 2);
r:=round(ClientWidth*20/200);
w:=ClientWidth-r;
h:=ClientHeight-r;
bmp:=TBitmap.Create;
With bmp do
begin
Width:=ClientWidth;
Height:=ClientHeight;
end;
//dessin de fond
bmpFond:=TBitmap.Create;
With bmpFond do
begin
Width:=ClientWidth;
Height:=ClientHeight;
With Canvas do
begin
Pen.Width:=3;
Brush.Color:=clwhite;
For i:=0 to r do
begin
//Pen.Color:=rgb(i*155 div r +100,0,0);
//Pen.Color:=rgb(i*80 div r+30,i*80 div r+30,i*80 div r+30);
Pen.Color:=rgb(0,58,i*52 div r+60);
Ellipse(i,i,ClientWidth-i,ClientHeight-i);
end;
Font.Name:='Arial';
Font.Height:=15;
textout(r+31*w div 48-textWidth('1'),r+3*h div 24,'1'); //1
textout(r+36*w div 48-textWidth('2'),r+11*h div 48,'2'); //2
Textout(w-r-textWidth('3') div 2,h div 2,'3'); //3
textout(r+36*w div 48-textWidth('4'),r+27*h div 48,'4'); //4
textout(r+31*w div 48-textWidth('5'),r+32*h div 48,'5'); //5
textout(r+w div 2-TextWidth('6'),h-r-TextHeight('6') div 2,'6'); //6
textout(r+17*w div 48-textWidth('7'),r+32*h div 48,'7'); //7
textout(r+10*w div 48-textWidth('8'),r+27*h div 48,'8'); //8
Textout(r+textWidth('9'),h div 2,'9'); //9
Textout(round(r+textWidth('10')/1.5),r+12*h div 48,'10'); //10
Textout(r+17*w div 48-textWidth('11'),r+3*h div 24,'11'); //11
textout(r+w div 2-TextWidth('12'),r+textHeight('12') div 2,'12'); //12
end;
end;
//forme circulaire de TForm1
R2:=createRectRgn(0,0,ClientWidth,CLientHeight);
R1:=createEllipticRGN(0,0,ClientWidth,CLientHeight);
CombineRGN(R2,R2,R1,RGN_AND);
SetWindowRgn(handle,R2,true);
DeleteObject(R1);
FormPaint(nil);
Timer1Timer(nil);
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = VK_ESCAPE then Application.Terminate;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
With bmp.Canvas do
begin
Pen.Width:=2;
bmp.Assign(bmpFond);
//heures
Pen.Color:=clblack;
MoveTo(pt.X,pt.Y);
LineTo(round(pt.X+(ClientWidth div 2-r*2)*cos((he-90)*pi/180)),round(pt.Y+(ClientWidth div 2-r*2)*sin((he-90)*pi/180)));
//minutes
Pen.Color:=clgray;
MoveTo(pt.X,pt.Y);
LineTo(round(pt.X+(ClientWidth div 2-r*1.5)*cos((m-90)*pi/180)),round(pt.Y+(ClientWidth div 2-r*1.5)*sin((m-90)*pi/180)));
//secondes
Pen.Color:=clred;
MoveTo(pt.X,pt.Y);
LineTo(round(pt.X+(ClientWidth div 2-r-3)*cos((s-90)*pi/180)),round(pt.Y+(ClientWidth div 2-r-3)*sin((s-90)*pi/180)));
end;
Canvas.Draw(0,0,bmp);
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
clic:=true;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
clic:=false;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if clic then
begin
Left:=X+Left-Width div 2;
Top:=Y+Top-Height div 2 ;
point2:=point(Left,Top);
Rewrite(F);
Write(F,point2);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Present:=Now;
DecodeTime(Present,Hour, Min,Sec,MSec);
s:=sec*360 / 60;
m:=min*360 / 60;
he:=Hour*360 / 12;
FormPaint(nil);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
CloseFile(F);
bmp.Free;
bmpFond.Free;
end;
end. |
Partager