📄 lcd99.pas
字号:
begin
fOnColor := Val;
Invalidate;
end;
end;
procedure TLCD99.SetSegmentSize(Val: Integer);
begin
if fSegmentSize <> Val then
begin
fSegmentSize := Val;
Invalidate;
end;
end;
procedure TLCD99.SetPreview(Val: Boolean);
begin
if fPreview <> Val then
begin
fPreview := Val;
Invalidate;
end;
end;
{ Thanks to Mike Heydon for the OnChange event code }
procedure TLCD99.SetValue(Val: String);
var
Count: Integer;
Invalid: Boolean;
begin
if fValue <> Val then
begin
{ For this bit, we check the validity of the string }
Invalid := False;
if Val <> '' then
for Count := 1 to length(Val) do
begin
Val[Count] := Upcase(Val[Count]);
if not(((Val[Count] >= '0') and (Val[Count] <= '9')) or
(Val[Count] = '-') or (Val[Count] = ' ') or (Val[Count] = '.') or
((Val[Count] >= 'A') and (Val[Count] <= 'Z')) or
(Val[Count] = ':')) then
Invalid := True;
end;
if Invalid then Val := '';
{ We don't allow decimal points on the end of the value }
if (Val <> '') and (Val[length(Val)] = '.') then Delete(Val,length(Val),1);
fValue := Val;
{ Trigger on change event }
if Assigned(fOnChange) then fOnChange(Self, fValue, Val);
{ Turn on animation }
fIsChanging:=true;
Invalidate;
end;
end;
procedure TLCD99.ShowAbout(Val: TLCDAbout);
begin
if fAbout <> Val then
begin
if Val = abNone then fAbout := Val else
begin
fAbout := abNone;
MessageDlg(StrPas(CopyRightStr), mtInformation, [mbOk], 0);
end;
Invalidate;
end;
end;
procedure TLCD99.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
Message.Result := 1;
end;
{ Thanks to Alan Warriner for adding double buffering, animation
previews, and improved animation delays }
procedure TLCD99.Paint;
var
AnimationNo, SegmentNo: Byte;
tmp,tmp2,tmp3,tmp4: string;
PaintStart,FirstTickCount:{$IFDEF WIN32}DWord{$ELSE}Longint{$ENDIF};
AValue, HG, HH, HW, Spacing, tmpDelay, VG, VH, VW: Integer;
{ Draw a vertical segment - Thanks to Jean Pierre for his help }
procedure DrawVerticalSegment(StartX,StartY,XSpace,YSpace: Integer; SColor:TColor);
var
BeginAt,Count,HalfY,NextAt,TheSpace: Integer;
DotOk: Boolean;
Seg: Integer;
SegData: Array[0..7] of Integer;
begin
with fWorkCanvas do
begin
Brush.Color := SColor;
Pen.Color := SColor;
if fDotDisplay then
begin
{ Draw a dotted segment }
for Count := 0 to 7 do SegData[Count] := LCDDisplayData[AValue,Count];
Seg := SegData[SegmentNo];
TheSpace := fSegmentSize;
if YSpace < 0 then
TheSpace := -(TheSpace);
BeginAt := StartX;
while BeginAt < (StartX + XSpace) do
begin
{ Some dots may be shared by segments, so we shouldn't overwrite them
by accident }
DotOk := True;
NextAt := BeginAt + fSegmentSize + fDotSpacing;
if Seg = 0 then
case SegmentNo of
1: if ((BeginAt = StartX) and (SegData[2] = 1)) or
((NextAt >= StartX + XSpace) and (SegData[3] = 1))
then DotOk := False;
7: if ((BeginAt = StartX) and (SegData[5] = 1)) or
((NextAt >= StartX + XSpace) and (SegData[6] = 1))
then DotOk := False;
end;
{ Draw the dot }
if DotOk then Ellipse(BeginAt,StartY,BeginAt+fSegmentSize,StartY+TheSpace);
Inc(BeginAt,fSegmentSize + fDotSpacing);
end;
end
else
begin
{ Draw a normal segment }
HalfY := StartY + round(YSpace/4);
Polygon([Point(StartX,HalfY),
Point(StartX+(HW div 2),StartY),
Point((StartX+XSpace)-(HW div 2),StartY),
Point(StartX+XSpace,HalfY),
Point((StartX+XSpace)-HW,StartY+YSpace),
Point(StartX+HW,StartY+YSpace),
Point(StartX,HalfY)]);
end;
end;
end;
{ Draw the centre segment }
procedure DrawCenterSegment(StartX,StartY,XSpace,YSpace: Integer; SColor:TColor);
var
BeginAt,Count,HalfY,NextAt: Integer;
DotOk: Boolean;
Seg: Integer;
SegData: Array[0..7] of Integer;
begin
with fWorkCanvas do
begin
Brush.Color := SColor;
Pen.Color := SColor;
if fDotDisplay then
begin
{ Draw a dotted segment }
for Count := 0 to 7 do SegData[Count] := LCDDisplayData[AValue,Count];
Seg := SegData[SegmentNo];
BeginAt := StartX;
while BeginAt < (StartX + XSpace) do
begin
{ Some dots may be shared by segments, so we shouldn't overwrite them
by accident }
DotOk := True;
NextAt := BeginAt + fSegmentSize + fDotSpacing;
if (Seg = 0) and (((BeginAt = StartX) and ((SegData[2] = 1) or (SegData[5] = 1))) or
((NextAt >= StartX + XSpace) and ((SegData[3] = 1) or (SegData[6] = 1))))
then DotOk := False;
{ Draw the dot }
if DotOk then Ellipse(BeginAt,StartY,BeginAt+fSegmentSize,StartY+fSegmentSize);
Inc(BeginAt,fSegmentSize + fDotSpacing);
end;
end
else
begin
{ Draw a normal segment }
HalfY := StartY + round(YSpace/2);
Polygon([Point(StartX,HalfY),
Point(StartX+HW,StartY),
Point((StartX+XSpace)-HW,StartY),
Point(StartX+XSpace,HalfY),
Point((StartX+XSpace)-HW,StartY+YSpace),
Point(StartX+HW,StartY+YSpace),
Point(StartX,HalfY)]);
end;
end;
end;
{ Draw a horizontal segment - Thanks to Jean Pierre for his help }
procedure DrawHorizontalSegment(StartX,StartY,XSpace,YSpace: Integer; SColor:TColor);
var
BeginAt,Count,HalfX,NextAt,TheSpace: Integer;
DotOk: Boolean;
Seg: Integer;
SegData: Array[0..7] of Integer;
begin
with fWorkCanvas do
begin
Brush.Color := SColor;
Pen.Color := SColor;
if fDotDisplay then
begin
{ Draw a dotted segment }
for Count := 0 to 7 do SegData[Count] := LCDDisplayData[AValue,Count];
Seg := SegData[SegmentNo];
TheSpace := fSegmentSize;
if XSpace < 0 then
TheSpace := -(TheSpace);
BeginAt := StartY;
while BeginAt < (StartY + YSpace) do
begin
{ Some dots may be shared by segments, so we shouldn't overwrite them
by accident }
DotOk := True;
NextAt := BeginAt + fSegmentSize + fDotSpacing;
if Seg = 0 then
case SegmentNo of
2: if ((BeginAt = StartY) and (SegData[1] = 1)) or
((NextAt >= StartY + YSpace) and ((SegData[4] = 1) or (SegData[5] = 1)))
then DotOk := False;
3: if ((BeginAt = StartY) and (SegData[1] = 1)) or
((NextAt >= StartY + YSpace) and ((SegData[4] = 1) or (SegData[6] = 1)))
then DotOk := False;
5: if ((BeginAt = StartY) and ((SegData[2] = 1) or (SegData[4] = 1))) or
((NextAt >= StartY + YSpace) and (SegData[7] = 1))
then DotOk := False;
6: if ((BeginAt = StartY) and ((SegData[3] = 1) or (SegData[4] = 1))) or
((NextAt >= StartY + YSpace) and (SegData[7] = 1))
then DotOk := False;
end;
{ Draw the dot }
if DotOk then Ellipse(StartX,BeginAt,StartX+TheSpace,BeginAt+fSegmentSize);
Inc(BeginAt,fSegmentSize + fDotSpacing);
end;
end
else
begin
{ Draw a normal segment }
HalfX := StartX + round(XSpace/4);
Polygon([Point(HalfX,StartY),
Point(StartX,StartY+(VH div 2)),
Point(StartX,(StartY+YSpace)-(VH div 2)),
Point(HalfX,StartY+YSpace),
Point(StartX+XSpace,(StartY+YSpace)-VH),
Point(StartX+XSpace,StartY+VH),
Point(HalfX,StartY)]);
end;
end;
end;
{ Draw a colon - Thanks to Daniel Szasz for his help }
procedure DrawColon(StartX1,StartY1,StartX2,StartY2,XSpace,YSpace: Integer; SColor:TColor);
begin
with fWorkCanvas do
begin
Brush.Color := SColor;
Pen.Color := SColor;
Ellipse(StartX1,StartY1,StartX1+XSpace,StartY1+YSpace);
Ellipse(StartX2,StartY2,StartX2+XSpace,StartY2+YSpace);
end;
end;
{ And here's the clever procedure that draws the digits WITHOUT using
bitmaps! }
procedure DrawDigit(Animation, Speed: Integer;SkipSome:Boolean);
var
AnimationCount: Byte;
CH, CW, DelayCorrection, DigitNumber, DrawX, DrawY, SegmentSpaceX,
SegmentSpaceY, Temp: Integer;
SColor: TColor;
DigitOn: Boolean;
SegmentDelay,DelayTicks,FirstSegmentTickCount:{$IFDEF WIN32}DWord{$ELSE}Longint{$ENDIF};
begin
with fWorkCanvas do
begin
{ We start counting the whole delay here, as time can be wasted
drawing the display. A delay of 1000 MUST last around 1 second }
{ Work out segment sizes }
Spacing := fDigitSpacing + Integer(Not fDotDisplay);
{ Just to ensure that everything is drawn. The canvas doesn't always
draw along the edges, rather irritatingly. We also need to give an
extra space for the left decimal point }
CH := Height - 1;
CW := Width - 1 - Spacing;
{ Prepare to draw }
Brush.Style := bsSolid;
AnimationCount := 0;
if fDotDisplay then
begin
{ Each dotted segments must contain the same number of dots horizontally
and vertically as the other segments. So here we do some (very)
mind-boggling calculations - how I achieved this I will never know!!! }
Temp := (((CW + Spacing) div fDigitNum) - Spacing + fDotSpacing)
div (fSegmentSize + fDotSpacing);
SegmentSpaceX := Temp * (fSegmentSize + fDotSpacing) - fDotSpacing;
Temp := ((CH - fSegmentSize) div 2) div (fSegmentSize + fDotSpacing);
SegmentSpaceY := ((Temp * (fSegmentSize + fDotSpacing)) * 2) + fSegmentSize;
end
else
begin
{ Normal segments aren't dotted, so we do a simple divide }
SegmentSpaceX := (CW - (fDigitNum * Spacing)) div fDigitNum;
SegmentSpaceY := CH;
end;
{ Each segment needs a corner gap. We use this to work out the segment
height and width. These next variables are named as follows: -
H- = Horizontal Segment, V- = Vertical Segment
-G = Corner gap, -H = Height, -W = Width }
if fDotDisplay then
begin
{ Dotted segments don't use gaps }
HG := 0;
VG := 0;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -