Industrial/indLCDDisplay: Store character dot matrices to lfm only when different from default.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8304 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-06-15 19:55:50 +00:00
parent 68b436d9f9
commit b5847cda91

View File

@ -31,8 +31,10 @@ type
FCharList: TDotMatrixList;
FColCount: Integer;
FRowCount: Integer;
function GetCharByIndex(AIndex: Integer): String;
function GetCount: Integer;
function GetDotRows(AChar: String): TDotRows;
function GetDotRowsByIndex(AIndex: Integer): TDotRows;
procedure SetColCount(AValue: Integer);
procedure SetDotRows(AChar: String; const AValue: TDotRows);
procedure SetRowCount(AValue: Integer);
@ -45,10 +47,13 @@ type
constructor Create;
destructor Destroy; override;
procedure Add(AChar: String; ADotRows: TDotRows);
procedure Delete(AChar: String);
procedure Clear;
procedure Delete(AChar: String);
function SameDotRows(const AChar: String; const ADotRows: TDotRows): Boolean;
property Count: Integer read GetCount;
property CharByIndex[AIndex: Integer]: String read GetCharByIndex;
property DotRows[AChar: String]: TDotRows read GetDotRows write SetDotRows;
property DotRowsByIndex[AIndex: Integer]: TDotRows read GetDotRowsByIndex;
published
property ColCount: Integer read FColCount write SetColCount;
property RowCount: Integer read FRowCount write SetRowCount;
@ -118,7 +123,8 @@ type
procedure SetDotsSpace(const Value: integer);
function CalcCharCount: integer;
procedure InitCharList(AHorDots, AVertDots: integer);
procedure InitCharDefs(ACharDefs: TCharDefs; AHorDots, AVertDots: integer);
function IsCharDefsStored: Boolean;
//calculate widths and heigths of the char matrix, background border and frame
procedure Prepare();
@ -170,7 +176,7 @@ type
property OnMouseMove;
property OnMouseUp;
property CharDefs: TCharDefs read FCharDefs write FCharDefs;
property CharDefs: TCharDefs read FCharDefs write FCharDefs stored IsCharDefsStored;
property DotSize: integer read FDotSize write SetDotSize default 4;
property DotsSpace: integer read FDotsSpace write SetDotsSpace default 1;
@ -219,6 +225,10 @@ implementation
uses
Dialogs, LazUTF8, LazUnicode;
const
DEFAULT_DOT_COL_COUNT = 5;
DEFAULT_DOT_ROW_COUNT = 7;
{ TCharDefs }
constructor TCharDefs.Create;
@ -275,6 +285,11 @@ begin
Result[row] := 0;
end;
function TCharDefs.GetCharByIndex(AIndex: Integer): String;
begin
Result := FCharList.Keys[AIndex];
end;
{ Returns the number of characters contained. }
function TCharDefs.GetCount: Integer;
begin
@ -293,6 +308,11 @@ begin
Result := EmptyRows;
end;
function TCharDefs.GetDotRowsByIndex(AIndex: Integer): TDotRows;
begin
Result := FCharList.Data[AIndex];
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. }
@ -328,6 +348,20 @@ begin
Reader.ReadListEnd;
end;
function TCharDefs.SameDotRows(const AChar: String; const ADotRows: TDotRows): Boolean;
var
i: Integer;
lDotRows: TDotRows;
begin
Result := false;
lDotRows := DotRows[AChar];
if (Length(lDotRows) <> Length(ADotRows)) then
exit;
for i := 0 to High(lDotRows) do
if lDotRows[i] <> ADotRows[i] then exit;
Result := true;
end;
{ Returns the number of columns of the dot matrix. }
procedure TCharDefs.SetColCount(AValue: Integer);
begin
@ -394,9 +428,9 @@ begin
FDisplayCharCount := 10;
FCharDefs := TCharDefs.Create;
FCharDefs.ColCount := 5;
FCharDefs.RowCount := 7;
InitCharList(DotColCount, DotRowCount);
FCharDefs.ColCount := DEFAULT_DOT_COL_COUNT;
FCharDefs.RowCount := DEFAULT_DOT_ROW_COUNT;
InitCharDefs(FCharDefs, DotColCount, DotRowCount);
FDotSize := 4;
FDotsSpace := 1;
@ -784,110 +818,145 @@ begin
end;
end;
procedure TLCDDisplay.InitCharList(AHorDots, AVertDots: integer);
procedure TLCDDisplay.InitCharDefs(ACharDefs: TCharDefs; AHorDots, AVertDots: integer);
var
i: integer;
begin
FCharDefs.Clear;
if (AHorDots = 5) and (AVertDots = 7) then
ACharDefs.Clear;
if (AHorDots = DEFAULT_DOT_COL_COUNT) and (AVertDots = DEFAULT_DOT_ROW_COUNT) then
begin
AddCharDef('!', [4, 4, 4, 4, 4, 0, 4]); // #33
AddCharDef('"', [10, 10, 0, 0, 0, 0, 0]); // #34
AddCharDef('#', [0, 10, 31, 10, 31, 10, 0]); // #35
AddCharDef('$', [4, 15, 20, 14, 5, 30, 4]); // #36
AddCharDef('%', [25, 26, 2, 4, 8, 11, 19]); // #37
AddCharDef('&', [12, 18, 20, 8, 21, 18, 13]); // #38
AddCharDef('''', [4, 4, 0, 0, 0, 0, 0]); // #39
AddCharDef('(', [2, 4, 8, 8, 8, 4, 2]); // #40
AddCharDef(')', [8, 4, 2, 2, 2, 4, 8]); // #41
AddCharDef('*', [0, 4, 21, 14, 21, 4, 0]); // #42
AddCharDef('+', [0, 4, 4, 31, 4, 4, 0]); // #43
AddCharDef(',', [0, 0, 0, 0, 12, 4, 8]); // #44
AddCharDef('-', [0, 0, 0, 14, 0, 0, 0]); // #45
AddCharDef('.', [0, 0, 0, 0, 0, 12, 12]); // #46
AddCharDef('/', [1, 1, 2, 4, 8, 16, 16]); // #47
AddCharDef('0', [14, 17, 19, 21, 25, 17, 14]); // #48
AddCharDef('1', [4, 12, 4, 4, 4, 4, 14]); // #49
AddCharDef('2', [14, 17, 1, 2, 4, 8, 31]); // #50
AddCharDef('3', [14, 17, 1, 6, 1, 17, 14]); // #51
AddCharDef('4', [2, 6, 10, 18, 31, 2, 2]); // #52
AddCharDef('5', [31, 16, 30, 1, 1, 17, 14]); // #53
AddCharDef('6', [14, 17, 16, 30, 17, 17, 14]); // #54
AddCharDef('7', [31, 1, 1, 2, 4, 4, 4]); // #55
AddCharDef('8', [14, 17, 17, 14, 17, 17, 14]); // #56
AddCharDef('9', [14, 17, 17, 15, 1, 17, 14]); // #57
AddCharDef(':', [0, 12, 12, 0, 12, 12, 0]); // #58
AddCharDef(';', [0, 12, 12, 0, 12, 4, 8]); // #59
AddCharDef('<', [2, 4, 8, 16, 8, 4, 2]); // #60
AddCharDef('=', [0, 0, 31, 0, 31, 0, 0]); // #61
AddCharDef('>', [8, 4, 2, 1, 2, 4, 8]); // #62
AddCharDef('?', [14, 17, 1, 2, 4, 0, 4]); // #63
AddCharDef('@', [14, 17, 19, 21, 23, 16, 15]); // #64
AddCharDef('A', [14, 17, 17, 31, 17, 17, 17]); // #65
AddCharDef('B', [30, 17, 17, 30, 17, 17, 30]); // #66
AddCharDef('C', [14, 17, 16, 16, 16, 17, 14]); // #67
AddCharDef('D', [30, 17, 17, 17, 17, 17, 30]); // #68
AddCharDef('E', [31, 16, 16, 30, 16, 16, 31]); // #69
AddCharDef('F', [31, 16, 16, 30, 16, 16, 16]); // #70
AddCharDef('G', [14, 17, 16, 19, 17, 17, 14]); // #71
AddCharDef('H', [17, 17, 17, 31, 17, 17, 17]); // #72
AddCharDef('I', [14, 4, 4, 4, 4, 4, 14]); // #73
AddCharDef('J', [1, 1, 1, 1, 17, 17, 14]); // #74
AddCharDef('K', [17, 18, 20, 24, 20, 18, 17]); // #75
AddCharDef('L', [16, 16, 16, 16, 16, 16, 31]); // #76
AddCharDef('M', [17, 27, 21, 21, 17, 17, 17]); // #77
AddCharDef('N', [17, 25, 21, 19, 17, 17, 17]); // #78
AddCharDef('O', [14, 17, 17, 17, 17, 17, 14]); // #79
AddCharDef('P', [30, 17, 17, 30, 16, 16, 16]); // #80
AddCharDef('Q', [14, 17, 17, 17, 17, 14, 1]); // #81
AddCharDef('R', [30, 17, 17, 30, 17, 17, 17]); // #82
AddCharDef('S', [14, 17, 16, 14, 1, 17, 14]); // #83
AddCharDef('T', [31, 4, 4, 4, 4, 4, 4]); // #84
AddCharDef('U', [17, 17, 17, 17, 17, 17, 14]); // #85
AddCharDef('V', [17, 17, 17, 17, 17, 10, 4]); // #86
AddCharDef('W', [17, 17, 17, 17, 21, 27, 17]); // #87
AddCharDef('X', [17, 10, 4, 4, 4, 10, 17]); // #88
AddCharDef('Y', [17, 17, 17, 10, 4, 4, 4]); // #89
AddCharDef('Z', [31, 1, 2, 4, 8, 16, 31]); // #90
AddCharDef('[', [12, 8, 8, 8, 8, 8, 12]); // #91
AddCharDef('\', [0, 16, 8, 4, 2, 1, 0]); // #92
AddCharDef(']', [6, 2, 2, 2, 2, 2, 6]); // #93
AddCharDef('^', [4, 10, 17, 0, 0, 0, 0]); // #94
AddCharDef('_', [0, 0, 0, 0, 0, 0, 31]); // #95
AddCharDef('`', [6, 4, 2, 0, 0, 0, 0]); // #96
AddCharDef('a', [0, 0, 14, 1, 15, 17, 15]); // #97
AddCharDef('b', [16, 16, 30, 17, 17, 17, 30]); // #98
AddCharDef('c', [0, 0, 15, 16, 16, 16, 15]); // #99
AddCharDef('d', [1, 1, 15, 17, 17, 17, 15]); // #100
AddCharDef('e', [0, 0, 14, 17, 31, 16, 14]); // #101
AddCharDef('f', [3, 4, 31, 4, 4, 4, 4]); // #102
AddCharDef('g', [0, 0, 15, 17, 15, 1, 14]); // #103
AddCharDef('h', [16, 16, 22, 25, 17, 17, 17]);// #104
AddCharDef('i', [4, 0, 12, 4, 4, 4, 14]); // #105
AddCharDef('j', [2, 0, 6, 2, 2, 18, 12]); // #106
AddCharDef('k', [16, 16, 18, 20, 24, 20, 18]);// #107
AddCharDef('l', [12, 4, 4, 4, 4, 4, 14]); // #108
AddCharDef('m', [0, 0, 26, 21, 21, 21, 21]); // #109
AddCharDef('n', [0, 0, 22, 25, 17, 17, 17]); // #110
AddCharDef('o', [0, 0, 14, 17, 17, 17, 14]); // #111
AddCharDef('p', [0, 0, 30, 17, 30, 16, 16]); // #112
AddCharDef('q', [0, 0, 15, 17, 15, 1, 1]); // #113
AddCharDef('r', [0, 0, 11, 12, 8, 8, 8]); // #114
AddCharDef('s', [0, 0, 14, 16, 14, 1, 30]); // #115
AddCharDef('t', [4, 4, 31, 4, 4, 4, 3]); // #116
AddCharDef('u', [0, 0, 17, 17, 17, 19, 13]); // #117
AddCharDef('v', [0, 0, 17, 17, 17, 10, 4]); // #118
AddCharDef('w', [0, 0, 17, 17, 21, 21, 10]); // #119
AddCharDef('x', [0, 0, 17, 10, 4, 10, 17]); // #120
AddCharDef('y', [0, 0, 17, 17, 15, 1, 14]); // #121
AddCharDef('z', [0, 0, 31, 2, 4, 8, 31]); // #122
AddCharDef('{', [3, 4, 4, 8, 4, 4, 3]); // #123
AddCharDef('|', [4, 4, 4, 4, 4, 4, 4]); // #124
AddCharDef('}', [24, 4, 4, 2, 4, 4, 24]); // #125
AddCharDef('~', [8, 21, 2, 0, 0, 0, 0]); // #126
ACharDefs.Add('!', [4, 4, 4, 4, 4, 0, 4]); // #33
ACharDefs.Add('"', [10, 10, 0, 0, 0, 0, 0]); // #34
ACharDefs.Add('#', [0, 10, 31, 10, 31, 10, 0]); // #35
ACharDefs.Add('$', [4, 15, 20, 14, 5, 30, 4]); // #36
ACharDefs.Add('%', [25, 26, 2, 4, 8, 11, 19]); // #37
ACharDefs.Add('&', [12, 18, 20, 8, 21, 18, 13]); // #38
ACharDefs.Add('''', [4, 4, 0, 0, 0, 0, 0]); // #39
ACharDefs.Add('(', [2, 4, 8, 8, 8, 4, 2]); // #40
ACharDefs.Add(')', [8, 4, 2, 2, 2, 4, 8]); // #41
ACharDefs.Add('*', [0, 4, 21, 14, 21, 4, 0]); // #42
ACharDefs.Add('+', [0, 4, 4, 31, 4, 4, 0]); // #43
ACharDefs.Add(',', [0, 0, 0, 0, 12, 4, 8]); // #44
ACharDefs.Add('-', [0, 0, 0, 14, 0, 0, 0]); // #45
ACharDefs.Add('.', [0, 0, 0, 0, 0, 12, 12]); // #46
ACharDefs.Add('/', [1, 1, 2, 4, 8, 16, 16]); // #47
ACharDefs.Add('0', [14, 17, 19, 21, 25, 17, 14]); // #48
ACharDefs.Add('1', [4, 12, 4, 4, 4, 4, 14]); // #49
ACharDefs.Add('2', [14, 17, 1, 2, 4, 8, 31]); // #50
ACharDefs.Add('3', [14, 17, 1, 6, 1, 17, 14]); // #51
ACharDefs.Add('4', [2, 6, 10, 18, 31, 2, 2]); // #52
ACharDefs.Add('5', [31, 16, 30, 1, 1, 17, 14]); // #53
ACharDefs.Add('6', [14, 17, 16, 30, 17, 17, 14]); // #54
ACharDefs.Add('7', [31, 1, 1, 2, 4, 4, 4]); // #55
ACharDefs.Add('8', [14, 17, 17, 14, 17, 17, 14]); // #56
ACharDefs.Add('9', [14, 17, 17, 15, 1, 17, 14]); // #57
ACharDefs.Add(':', [0, 12, 12, 0, 12, 12, 0]); // #58
ACharDefs.Add(';', [0, 12, 12, 0, 12, 4, 8]); // #59
ACharDefs.Add('<', [2, 4, 8, 16, 8, 4, 2]); // #60
ACharDefs.Add('=', [0, 0, 31, 0, 31, 0, 0]); // #61
ACharDefs.Add('>', [8, 4, 2, 1, 2, 4, 8]); // #62
ACharDefs.Add('?', [14, 17, 1, 2, 4, 0, 4]); // #63
ACharDefs.Add('@', [14, 17, 19, 21, 23, 16, 15]); // #64
ACharDefs.Add('A', [14, 17, 17, 31, 17, 17, 17]); // #65
ACharDefs.Add('B', [30, 17, 17, 30, 17, 17, 30]); // #66
ACharDefs.Add('C', [14, 17, 16, 16, 16, 17, 14]); // #67
ACharDefs.Add('D', [30, 17, 17, 17, 17, 17, 30]); // #68
ACharDefs.Add('E', [31, 16, 16, 30, 16, 16, 31]); // #69
ACharDefs.Add('F', [31, 16, 16, 30, 16, 16, 16]); // #70
ACharDefs.Add('G', [14, 17, 16, 19, 17, 17, 14]); // #71
ACharDefs.Add('H', [17, 17, 17, 31, 17, 17, 17]); // #72
ACharDefs.Add('I', [14, 4, 4, 4, 4, 4, 14]); // #73
ACharDefs.Add('J', [1, 1, 1, 1, 17, 17, 14]); // #74
ACharDefs.Add('K', [17, 18, 20, 24, 20, 18, 17]); // #75
ACharDefs.Add('L', [16, 16, 16, 16, 16, 16, 31]); // #76
ACharDefs.Add('M', [17, 27, 21, 21, 17, 17, 17]); // #77
ACharDefs.Add('N', [17, 25, 21, 19, 17, 17, 17]); // #78
ACharDefs.Add('O', [14, 17, 17, 17, 17, 17, 14]); // #79
ACharDefs.Add('P', [30, 17, 17, 30, 16, 16, 16]); // #80
ACharDefs.Add('Q', [14, 17, 17, 17, 17, 14, 1]); // #81
ACharDefs.Add('R', [30, 17, 17, 30, 17, 17, 17]); // #82
ACharDefs.Add('S', [14, 17, 16, 14, 1, 17, 14]); // #83
ACharDefs.Add('T', [31, 4, 4, 4, 4, 4, 4]); // #84
ACharDefs.Add('U', [17, 17, 17, 17, 17, 17, 14]); // #85
ACharDefs.Add('V', [17, 17, 17, 17, 17, 10, 4]); // #86
ACharDefs.Add('W', [17, 17, 17, 17, 21, 27, 17]); // #87
ACharDefs.Add('X', [17, 10, 4, 4, 4, 10, 17]); // #88
ACharDefs.Add('Y', [17, 17, 17, 10, 4, 4, 4]); // #89
ACharDefs.Add('Z', [31, 1, 2, 4, 8, 16, 31]); // #90
ACharDefs.Add('[', [12, 8, 8, 8, 8, 8, 12]); // #91
ACharDefs.Add('\', [0, 16, 8, 4, 2, 1, 0]); // #92
ACharDefs.Add(']', [6, 2, 2, 2, 2, 2, 6]); // #93
ACharDefs.Add('^', [4, 10, 17, 0, 0, 0, 0]); // #94
ACharDefs.Add('_', [0, 0, 0, 0, 0, 0, 31]); // #95
ACharDefs.Add('`', [6, 4, 2, 0, 0, 0, 0]); // #96
ACharDefs.Add('a', [0, 0, 14, 1, 15, 17, 15]); // #97
ACharDefs.Add('b', [16, 16, 30, 17, 17, 17, 30]); // #98
ACharDefs.Add('c', [0, 0, 15, 16, 16, 16, 15]); // #99
ACharDefs.Add('d', [1, 1, 15, 17, 17, 17, 15]); // #100
ACharDefs.Add('e', [0, 0, 14, 17, 31, 16, 14]); // #101
ACharDefs.Add('f', [3, 4, 31, 4, 4, 4, 4]); // #102
ACharDefs.Add('g', [0, 0, 15, 17, 15, 1, 14]); // #103
ACharDefs.Add('h', [16, 16, 22, 25, 17, 17, 17]);// #104
ACharDefs.Add('i', [4, 0, 12, 4, 4, 4, 14]); // #105
ACharDefs.Add('j', [2, 0, 6, 2, 2, 18, 12]); // #106
ACharDefs.Add('k', [16, 16, 18, 20, 24, 20, 18]);// #107
ACharDefs.Add('l', [12, 4, 4, 4, 4, 4, 14]); // #108
ACharDefs.Add('m', [0, 0, 26, 21, 21, 21, 21]); // #109
ACharDefs.Add('n', [0, 0, 22, 25, 17, 17, 17]); // #110
ACharDefs.Add('o', [0, 0, 14, 17, 17, 17, 14]); // #111
ACharDefs.Add('p', [0, 0, 30, 17, 30, 16, 16]); // #112
ACharDefs.Add('q', [0, 0, 15, 17, 15, 1, 1]); // #113
ACharDefs.Add('r', [0, 0, 11, 12, 8, 8, 8]); // #114
ACharDefs.Add('s', [0, 0, 14, 16, 14, 1, 30]); // #115
ACharDefs.Add('t', [4, 4, 31, 4, 4, 4, 3]); // #116
ACharDefs.Add('u', [0, 0, 17, 17, 17, 19, 13]); // #117
ACharDefs.Add('v', [0, 0, 17, 17, 17, 10, 4]); // #118
ACharDefs.Add('w', [0, 0, 17, 17, 21, 21, 10]); // #119
ACharDefs.Add('x', [0, 0, 17, 10, 4, 10, 17]); // #120
ACharDefs.Add('y', [0, 0, 17, 17, 15, 1, 14]); // #121
ACharDefs.Add('z', [0, 0, 31, 2, 4, 8, 31]); // #122
ACharDefs.Add('{', [3, 4, 4, 8, 4, 4, 3]); // #123
ACharDefs.Add('|', [4, 4, 4, 4, 4, 4, 4]); // #124
ACharDefs.Add('}', [24, 4, 4, 2, 4, 4, 24]); // #125
ACharDefs.Add('~', [8, 21, 2, 0, 0, 0, 0]); // #126
end;
end;
{ Determines whether the character definitons must be stored in the lfm file.
They are NOT stored when the currently used defs are exactly the same as those
generated by InitCharDefs. }
function TLCDDisplay.IsCharDefsStored: Boolean;
var
defs: TCharDefs;
i: Integer;
ch1, ch2: String;
dotRows1, dotRows2: TDotRows;
begin
Result := true;
if (DotRowCount <> DEFAULT_DOT_ROW_COUNT) or (DotColCount <> DEFAULT_DOT_COL_COUNT) then
exit;
defs := TCharDefs.Create;
try
defs.ColCount := DEFAULT_DOT_COL_COUNT;
defs.RowCount := DEFAULT_DOT_ROW_COUNT;
InitCharDefs(defs, defs.ColCount, defs.RowCount);
if defs.Count <> FCharDefs.Count then
exit;
for i := 0 to defs.Count-1 do
begin
ch1 := defs.CharByIndex[i];
ch2 := FCharDefs.CharByIndex[i];;
if (ch1 <> ch2) then
exit;
dotRows1 := defs.DotRowsByIndex[i];
if not FCharDefs.SameDotRows(ch1, dotRows1) then
exit;
end;
Result := false;
finally
defs.Free;
end;
end;
procedure TLCDDisplay.SetBoardColor(const Value: TColor);
begin
if Value = FBoardColor then