You've already forked lazarus-ccr
Industrial/LCDDisplay: Complete CharDefs editor, based on bobby100's design.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8315 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -54,6 +54,8 @@ type
|
||||
procedure Assign(ASource: TPersistent); override;
|
||||
procedure Clear;
|
||||
procedure Delete(AChar: String);
|
||||
function DotRowsToString(AChar: String): String;
|
||||
function Find(const AChar: String): Boolean;
|
||||
procedure LoadFromFile(const AFileName: String);
|
||||
function SameDotRows(const AChar: String; const ADotRows: TDotRows): Boolean;
|
||||
procedure SaveToFile(const AFileName: String);
|
||||
@ -103,6 +105,7 @@ type
|
||||
FDotShape: TDotShape;
|
||||
|
||||
FCharDefs: TCharDefs;
|
||||
FOnChange: TNotifyEvent;
|
||||
|
||||
function GetDotColCount: Integer;
|
||||
function GetDotRowCount: INteger;
|
||||
@ -132,6 +135,7 @@ type
|
||||
function CalcCharCount: integer;
|
||||
procedure InitCharDefs(ACharDefs: TCharDefs; AHorDots, AVertDots: integer);
|
||||
function IsCharDefsStored: Boolean;
|
||||
procedure LinesChanged(Sender: TObject);
|
||||
|
||||
//calculate widths and heights of the display matrix, background border and frame
|
||||
procedure Prepare();
|
||||
@ -157,6 +161,7 @@ type
|
||||
// Takes care of high-dpi scaling
|
||||
procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
|
||||
const AXProportion, AYProportion: double); override;
|
||||
procedure DoChange; virtual;
|
||||
// inherited painting routine
|
||||
procedure Paint; override;
|
||||
// Recalculates the geometry if a related property has been changed.
|
||||
@ -227,8 +232,12 @@ type
|
||||
property FrameColorStyle: TFrameColorStyle
|
||||
read FFrameColorStyle write SetFrameColorStyle default stWindows;
|
||||
property DotShape: TDotShape read FDotShape write SetDotShape default stSquare;
|
||||
|
||||
property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
||||
end;
|
||||
|
||||
function CopyDotRows(const ADotRows: TDotRows): TDotRows;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
@ -237,7 +246,19 @@ uses
|
||||
const
|
||||
DEFAULT_DOT_COL_COUNT = 5;
|
||||
DEFAULT_DOT_ROW_COUNT = 7;
|
||||
|
||||
|
||||
{ Create a "real" copy to avoid reference counter issues. }
|
||||
function CopyDotRows(const ADotRows: TDotRows): TDotRows;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
Result := nil;
|
||||
SetLength(Result, Length(ADotRows));
|
||||
for i := 0 to High(ADotRows) do
|
||||
Result[i] := ADotRows[i];
|
||||
end;
|
||||
|
||||
|
||||
{ TCharDefs }
|
||||
|
||||
constructor TCharDefs.Create(ADisplay: TLCDDisplay);
|
||||
@ -259,7 +280,8 @@ procedure TCharDefs.Add(AChar: String; ADotRows: TDotRows);
|
||||
begin
|
||||
if Length(ADotRows) <> FRowCount then
|
||||
raise Exception.Create('Incorrect number of rows.');
|
||||
FCharList.Add(AChar, ADotRows);
|
||||
// Make sure to reset the reference counter --> use a local copy of ADotRows!
|
||||
FCharList.Add(AChar, CopyDotRows(ADotRows));
|
||||
end;
|
||||
|
||||
procedure TCharDefs.Assign(ASource: TPersistent);
|
||||
@ -299,6 +321,18 @@ begin
|
||||
FCharList.Delete(idx);
|
||||
end;
|
||||
|
||||
{ Display the elements of the RowDots as a string. For debugging purposes. }
|
||||
function TCharDefs.DotRowsToString(AChar: String): String;
|
||||
var
|
||||
lDotRows: TDotRows;
|
||||
i: Integer;
|
||||
begin
|
||||
lDotRows := DotRows[AChar];
|
||||
Result := IntToStr(lDotRows[0]);
|
||||
for i := 1 to High(lDotRows) do
|
||||
Result := Result + ',' + IntToStr(lDotRows[i]);
|
||||
end;
|
||||
|
||||
{ Creates an empty row in which not dots are set. }
|
||||
function TCharDefs.EmptyRows: TDotRows;
|
||||
var
|
||||
@ -338,6 +372,13 @@ begin
|
||||
Result := FCharList.Data[AIndex];
|
||||
end;
|
||||
|
||||
function TCharDefs.Find(const AChar: String): Boolean;
|
||||
var
|
||||
idx: Integer;
|
||||
begin
|
||||
Result := FCharList.Find(AChar, idx);
|
||||
end;
|
||||
|
||||
{ Reads the list of character name and dot matrices from the LFM file. The data
|
||||
are stored in the LFM as a comma-separated list beginning with the character
|
||||
name. }
|
||||
@ -546,9 +587,8 @@ var
|
||||
idx: Integer;
|
||||
begin
|
||||
if FCharList.Find(AChar, idx) then
|
||||
FCharList.Data[idx] := AValue
|
||||
else
|
||||
Add(AChar, AValue);
|
||||
Delete(AChar);
|
||||
Add(AChar, AValue);
|
||||
end;
|
||||
|
||||
{ Returns the number of rows of the dot matrix. }
|
||||
@ -615,6 +655,7 @@ begin
|
||||
FCountOn := 255;
|
||||
|
||||
FLines := TStringList.Create;
|
||||
FLines.OnChange := @LinesChanged;
|
||||
AutoSize := true;
|
||||
end;
|
||||
|
||||
@ -674,6 +715,11 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TLCDDisplay.DoChange;
|
||||
begin
|
||||
if Assigned(FOnChange) then FOnChange(Self);
|
||||
end;
|
||||
|
||||
procedure TLCDDisplay.Prepare();
|
||||
var
|
||||
nDotCols: Integer;
|
||||
@ -1276,7 +1322,7 @@ begin
|
||||
else
|
||||
FLines.Add(' ');
|
||||
end;
|
||||
UpdateSize;
|
||||
LinesChanged(self);
|
||||
end;
|
||||
|
||||
function TLCDDisplay.GetCharCount: longint;
|
||||
@ -1317,6 +1363,12 @@ begin
|
||||
UpdateSize;
|
||||
end;
|
||||
|
||||
procedure TLCDDisplay.LinesChanged(Sender: TObject);
|
||||
begin
|
||||
UpdateSize;
|
||||
DoChange;
|
||||
end;
|
||||
|
||||
procedure TLCDDisplay.UpdateSize;
|
||||
begin
|
||||
if AutoSize then
|
||||
|
Reference in New Issue
Block a user