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
|
type
TTambour = class
private
FWidth : Integer;
FHeight: Integer;
FImage : TImage;
FBitmap: TBitmap;
FTimer : TTimer;
FText : string;
FSize : TSize;
FDigits: array of Integer;
procedure SetText(const Value: string);
procedure OnTimer(Sender: TObject);
public
constructor Create(AImage: TImage; AText: string);
destructor Destroy;
property Text: string read FText write SetText;
end;
constructor TTambour.Create;
begin
inherited Create;
FWidth := 24;
FHeight := 48;
FImage := AImage;
FBitmap := TBitmap.Create;
with FBitmap.Canvas do
begin
Font.Name := 'Impact';
Font.Height := 32;
Font.Style := [fsBold];
Brush.Style := bsClear;
FSize := TextExtent('0');
FSize.cx := (FWidth - FSize.cx) div 2;
FSize.cy := (FHeight - FSize.cy) div 2;
end;
FTimer := TTimer.Create(nil);
FTimer.Interval := 60;
FTimer.OnTimer := OnTimer;
Text := AText;
OnTimer(Self);
end;
destructor TTambour.Destroy;
begin
FTimer.Free;
FBitmap.Free;
inherited;
end;
procedure TTambour.SetText(const Value: string);
begin
FText := Value;
SetLength(FDigits, Length(FText));
FBitmap.Width := Length(FText) * FWidth;
FBitmap.Height := FHeight;
FTimer.Enabled := True;
end;
procedure TTambour.OnTimer(Sender: TObject);
const
DIGITS = '0123456789,-+E';
var
Done: Boolean;
y, c, x: Integer;
Index : Integer;
begin
Done := True;
with FBitmap.Canvas do
begin
for y := 0 to FHeight div 2 do
begin
c := (255 * y) div (FHeight div 2);
c := c + c shl 8 + c shl 16;
Pen.Color := c;
MoveTo(0, y);
LineTo(FBitmap.Width, y);
MoveTo(0 , FHeight - 1 - y);
LineTo(FBitmap.Width, FHeight - 1 - y);
end;
Pen.Color := clBlack;
for x := 0 to Length(FText) - 1 do
begin
MoveTo(x * FWidth, 0);
LineTo(x * FWidth, FHeight);
Index := Pos(FText[x + 1], DIGITS) - 1;
if Index * FHeight <> FDigits[x] then
begin
Done := False;
FDigits[x] := (FDigits[x] + 6) mod (FHeight * Length(DIGITS));
end;
Index := FDigits[x] div FHeight + 1;
if Index > 10 then
Font.Color := clRed
else
Font.Color := clBlack;
y := FSize.cy - FDigits[x] mod FHeight;
TextOut(x * FWidth + FSize.cx, y, DIGITS[Index]);
Inc(y, FHeight);
MoveTo(x * FWidth, y);
LineTo((x + 1) * FWidth, y);
Inc(Index);
if Index = 11 then
Font.Color := clRed
else
if Index = 15 then
begin
Index := 0;
Font.Color := clBlack;
end;
TextOut(x * FWidth + FSize.cx, y, DIGITS[Index]);
Inc(y, FHeight);
MoveTo(x * FWidth, y);
LineTo((x + 1) * FWidth, y);
end;
end;
FImage.Picture.Assign(FBitmap);
FTimer.Enabled := Done = False;
end;
begin
Tambour := TTambour.Create(Image1, edNombre.Text);
end. |
Partager