Skip to content

Commit

Permalink
TLEDDisplay can show numbers in hex
Browse files Browse the repository at this point in the history
  • Loading branch information
olivluca committed Jan 16, 2016
1 parent 995606f commit c913c39
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions RackCtls.pas
Original file line number Diff line number Diff line change
Expand Up @@ -356,14 +356,16 @@ TScrewPanel = class(TCustomPanel)
{$ENDIF}
end;

{ TLEDDisplay }

TLEDDisplay = class(TGraphicControl)
private
FBevelStyle : TPanelBevel;
FBorderStyle : TBorderStyle;
FColorBackGround,
FColorLED : TColor;
FDecSeparator : TDecSeparator;
FDigit : array [0..9] of TBitmap;
FDigit : array [0..15] of TBitmap;
FDigitHeight : integer;
FDigitShapeColor : TColor;
FDigitWidth : integer;
Expand All @@ -374,8 +376,9 @@ TLEDDisplay = class(TGraphicControl)
FLineWidth,
FNumDigits : integer;
FLeadingZeros : boolean;
FSegCl : array [0..9, 1..7] of TColor;
FSegCl : array [0..15, 1..7] of TColor;
FSegmentStyle : TSegmentStyle;
FHex : boolean;
FValue : extended;

FOnChange : TNotifyEvent;
Expand All @@ -395,6 +398,7 @@ TLEDDisplay = class(TGraphicControl)
procedure SetNumDigits (newValue: integer);
procedure SetSegmentStyle (newValue: TSegmentStyle);
procedure SetValue (newValue: extended);
procedure SetHex (newValue: boolean);

procedure CreateDigitBitmaps;
procedure AssignColors (seg: integer; s1,s2,s3,s4,s5,s6,s7: Boolean);
Expand Down Expand Up @@ -427,6 +431,7 @@ TLEDDisplay = class(TGraphicControl)
property LEDContrast: TContrast read FLEDContrast write SetLEDContrast;
property NumDigits: integer read FNumDigits write setNumDigits default 6;
property SegmentStyle: TSegmentStyle read FSegmentStyle write setSegmentStyle default ssBeveled;
property Hex: boolean read FHex write SetHex default false;
property Value: extended read FValue write setValue;
property Visible;
property Width default 168;
Expand Down Expand Up @@ -1872,7 +1877,7 @@ constructor TLEDDisplay.Create(AOwner: TComponent);
destructor TLEDDisplay.Destroy;
var c:integer;
begin
for c := 0 to 9 do
for c := 0 to 15 do
FDigit[c].free;
inherited destroy;
end;
Expand Down Expand Up @@ -1965,9 +1970,15 @@ procedure TLEDDisplay.CreateDigitBitmaps;
AssignColors (7,true,false,true,false,false,true,false);
AssignColors (8,true,true,true,true,true,true,true);
AssignColors (9,true,true,true,true,false,true,true);
AssignColors ($A,true,true,true,true,true,true,false);
AssignColors ($b,false,true,false,true,true,true,true);
AssignColors ($C,true,true,false,false,true,false,true);
AssignColors ($d,false,false,true,true,true,true,true);
AssignColors ($E,true,true,false,true,true,false,true);
AssignColors ($F,true,true,false,true,true,false,false);

{ Bitmap erstellen }
for c := 0 to 9 do begin
for c := 0 to 15 do begin
FDigit[c].free;
FDigit[c] := TBitmap.create;
FDigit[c].width := FDigitWidth;
Expand Down Expand Up @@ -2066,7 +2077,10 @@ procedure TLEDDisplay.Paint;
begin
Area := getClientRect;
try
outText:=FloatToStrF(FValue,ffFixed,18,FFractionDigits);
if Hex then
outText:=IntToHex(trunc(FValue),FNumDigits)
else
outText:=FloatToStrF(FValue,ffFixed,18,FFractionDigits);
except
outText:='';
end;
Expand All @@ -2090,8 +2104,8 @@ procedure TLEDDisplay.Paint;
{ Bitmaps und DecSeperator zeichnen }
for DigitNum:=1 to FNumDigits do begin
{ nachfolgende Nullen müssen gezeichnet werden! }
if FLeadingZeros or (StrToInt(outText[DigitNum])<>0) or ANZeroDigit then begin
Draw(DigitLeft, DigitTop, FDigit[StrToInt(outText[DigitNum])]);
if FLeadingZeros or (outText[DigitNum]<>'0') or ANZeroDigit then begin
Draw(DigitLeft, DigitTop, FDigit[StrToInt('$'+outText[DigitNum])]);
ANZeroDigit:=True; { spätestens jetzt isse da... }
end;
inc(DigitLeft, DigitSpace);
Expand Down Expand Up @@ -2290,6 +2304,14 @@ procedure TLEDDisplay.SetValue(newValue: extended);
end;
end;

procedure TLEDDisplay.SetHex(newValue: boolean);
begin
if FHex<>newValue then begin
FHex:=NewValue;
Invalidate;
end;
end;

{ Komponente TLEDMeter }

constructor TLEDMeter.Create(AOwner: TComponent);
Expand Down

0 comments on commit c913c39

Please sign in to comment.