Industrial/LCDDisplay: implement streaming of the character dot matrices.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8303 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-06-15 15:32:44 +00:00
parent 3d619ce25b
commit 68b436d9f9
5 changed files with 454 additions and 225 deletions

View File

@ -118,11 +118,6 @@
<ResourceBaseClass Value="Form"/>
<UnitName Value="untMain"/>
</Unit>
<Unit>
<Filename Value="..\..\..\..\..\svn\lazarus-ccr\components\industrialstuff\source\indlcldisplay.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="indLCLDisplay"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>

View File

@ -10,7 +10,7 @@ uses
athreads,
{$ENDIF}
Interfaces, // this includes the LCL widgetset
Forms, untMain, TLCDLines_unit;
Forms, untMain;
{$R *.res}

View File

@ -3,7 +3,7 @@ object frmMain: TfrmMain
Height = 531
Top = 217
Width = 921
Caption = 'LCDLines Demo'
Caption = 'LCDDisplay Demo'
ClientHeight = 531
ClientWidth = 921
OnCreate = FormCreate

View File

@ -63,7 +63,7 @@ type
procedure seDisplayLineCountChange(Sender: TObject);
procedure seWidthChange(Sender: TObject);
private
LCDLines1: TLCDLines;
LCDDisplay: TLCDDisplay;
public
@ -80,28 +80,28 @@ implementation
procedure TfrmMain.cbtFrameColorColorChanged(Sender: TObject);
begin
LCDLines1.FrameColor := cbtFrameColor.ButtonColor;
LCDDisplay.FrameColor := cbtFrameColor.ButtonColor;
end;
procedure TfrmMain.cbtBoardColorColorChanged(Sender: TObject);
begin
LCDLines1.BoardColor := cbtBoardColor.ButtonColor;
LCDDisplay.BoardColor := cbtBoardColor.ButtonColor;
end;
procedure TfrmMain.cbtDotONColorColorChanged(Sender: TObject);
begin
LCDLines1.DotColorON := cbtDotONColor.ButtonColor;
LCDDisplay.DotColorON := cbtDotONColor.ButtonColor;
end;
procedure TfrmMain.cbtDotOFFColorColorChanged(Sender: TObject);
begin
LCDLines1.DotColorOFF := cbtDotOFFColor.ButtonColor;
LCDDisplay.DotColorOFF := cbtDotOFFColor.ButtonColor;
end;
procedure TfrmMain.FormCreate(Sender: TObject);
begin
LCDLines1 := TLCDLines.Create(self);
with LCDLines1 do
LCDDisplay := TLCDDisplay.Create(self);
with LCDDisplay do
begin
Left := 24;
Height := 101;
@ -111,7 +111,7 @@ begin
DotColorOn := 5162664;
DotColorOff := 2900284;
DisplayCharCount := 0;
Lines.Add('TLCDLines');
Lines.Add('TLCDDisplay');
ColorScheme := csInvGreen;
Parent := self;
end
@ -119,111 +119,111 @@ end;
procedure TfrmMain.FormShow(Sender: TObject);
begin
mmText.Lines := LCDLines1.Lines;
seDisplayLineCount.Value := LCDLines1.DisplayLineCount;
seDisplayCharCount.Value := LCDLines1.DisplayCharCount;
seFrameSize.Value := LCDLines1.FrameSize;
seDotSize.Value := LCDLines1.DotSize;
seDotsSpace.Value := LCDLines1.DotsSpace;
seWidth.Value := LCDLines1.Width;
seHeigth.Value := LCDLines1.Height;
cbAutoSize.Checked := LCDLines1.AutoSize;
cbCharSpace.Checked := LCDLines1.CharSpace;
cbtFrameColor.ButtonColor := LCDLines1.FrameColor;
cbtBoardColor.ButtonColor := LCDLines1.BoardColor;
cbtDotONColor.ButtonColor := LCDLines1.DotColorOn;
cbtDotOFFColor.ButtonColor := LCDLines1.DotColorOff;
rgFrameStyle.ItemIndex := integer(LCDLines1.FrameStyle);
rgFrameColorStyle.ItemIndex := integer(LCDLines1.FrameColorStyle);
rgDotShape.ItemIndex := integer(LCDLines1.DotShape);
rgFrameHeight.ItemIndex := integer(LCDLines1.FrameHeight);
cbColorSchemes.ItemIndex:= integer(LCDLines1.ColorScheme);
mmText.Lines := LCDDisplay.Lines;
seDisplayLineCount.Value := LCDDisplay.DisplayLineCount;
seDisplayCharCount.Value := LCDDisplay.DisplayCharCount;
seFrameSize.Value := LCDDisplay.FrameSize;
seDotSize.Value := LCDDisplay.DotSize;
seDotsSpace.Value := LCDDisplay.DotsSpace;
seWidth.Value := LCDDisplay.Width;
seHeigth.Value := LCDDisplay.Height;
cbAutoSize.Checked := LCDDisplay.AutoSize;
cbCharSpace.Checked := LCDDisplay.CharSpace;
cbtFrameColor.ButtonColor := LCDDisplay.FrameColor;
cbtBoardColor.ButtonColor := LCDDisplay.BoardColor;
cbtDotONColor.ButtonColor := LCDDisplay.DotColorOn;
cbtDotOFFColor.ButtonColor := LCDDisplay.DotColorOff;
rgFrameStyle.ItemIndex := integer(LCDDisplay.FrameStyle);
rgFrameColorStyle.ItemIndex := integer(LCDDisplay.FrameColorStyle);
rgDotShape.ItemIndex := integer(LCDDisplay.DotShape);
rgFrameHeight.ItemIndex := integer(LCDDisplay.FrameHeight);
cbColorSchemes.ItemIndex:= integer(LCDDisplay.ColorScheme);
end;
procedure TfrmMain.cbAutoSizeChange(Sender: TObject);
begin
LCDLines1.AutoSize := cbAutoSize.Checked;
LCDDisplay.AutoSize := cbAutoSize.Checked;
if not cbAutoSize.Checked then
begin
LCDLines1.Width := seWidth.Value;
LCDLines1.Height := seHeigth.Value;
LCDDisplay.Width := seWidth.Value;
LCDDisplay.Height := seHeigth.Value;
end;
end;
procedure TfrmMain.cbCharSpaceChange(Sender: TObject);
begin
LCDLines1.CharSpace := cbCharSpace.Checked;
LCDDisplay.CharSpace := cbCharSpace.Checked;
end;
procedure TfrmMain.cbColorSchemesChange(Sender: TObject);
begin
LCDLines1.ColorScheme := TColorScheme(cbColorSchemes.ItemIndex);
LCDDisplay.ColorScheme := TColorScheme(cbColorSchemes.ItemIndex);
end;
procedure TfrmMain.mmTextChange(Sender: TObject);
begin
LCDLines1.Lines.Assign(mmText.Lines);
if LCDLines1.AutoSize then
LCDDisplay.Lines.Assign(mmText.Lines);
if LCDDisplay.AutoSize then
begin
LCDLines1.InvalidatePreferredSize;
LCDLines1.AdjustSize;
LCDDisplay.InvalidatePreferredSize;
LCDDisplay.AdjustSize;
end;
LCDLines1.Invalidate;
LCDDisplay.Invalidate;
end;
procedure TfrmMain.rgFrameStyleClick(Sender: TObject);
begin
LCDLines1.FrameStyle := TFrameStyle(rgFrameStyle.ItemIndex);
LCDDisplay.FrameStyle := TFrameStyle(rgFrameStyle.ItemIndex);
end;
procedure TfrmMain.rgFrameColorStyleClick(Sender: TObject);
begin
LCDLines1.FrameColorStyle := TFrameColorStyle(rgFrameColorStyle.ItemIndex);
LCDDisplay.FrameColorStyle := TFrameColorStyle(rgFrameColorStyle.ItemIndex);
end;
procedure TfrmMain.rgDotShapeClick(Sender: TObject);
begin
LCDLines1.DotShape := TDotShape(rgDotShape.ItemIndex);
LCDDisplay.DotShape := TDotShape(rgDotShape.ItemIndex);
end;
procedure TfrmMain.rgFrameHeightClick(Sender: TObject);
begin
LCDLines1.FrameHeight := TFrameHeight(rgFrameHeight.ItemIndex);
LCDDisplay.FrameHeight := TFrameHeight(rgFrameHeight.ItemIndex);
end;
procedure TfrmMain.seDisplayCharCountChange(Sender: TObject);
begin
LCDLines1.DisplayCharCount := seDisplayCharCount.Value;
LCDDisplay.DisplayCharCount := seDisplayCharCount.Value;
end;
procedure TfrmMain.seDotSizeChange(Sender: TObject);
begin
LCDLines1.DotSize := seDotSize.Value;
LCDDisplay.DotSize := seDotSize.Value;
end;
procedure TfrmMain.seDotsSpaceChange(Sender: TObject);
begin
LCDLines1.DotsSpace := seDotsSpace.Value;
LCDDisplay.DotsSpace := seDotsSpace.Value;
end;
procedure TfrmMain.seFrameSizeChange(Sender: TObject);
begin
LCDLines1.FrameSize := seFrameSize.Value;
LCDDisplay.FrameSize := seFrameSize.Value;
end;
procedure TfrmMain.seHeigthChange(Sender: TObject);
begin
LCDLines1.Height := seHeigth.Value;
LCDDisplay.Height := seHeigth.Value;
end;
procedure TfrmMain.seDisplayLineCountChange(Sender: TObject);
begin
LCDLines1.DisplayLineCount := seDisplayLineCount.Value;
LCDDisplay.DisplayLineCount := seDisplayLineCount.Value;
end;
procedure TfrmMain.seWidthChange(Sender: TObject);
begin
LCDLines1.Width := seWidth.Value;
LCDDisplay.Width := seWidth.Value;
end;
end.

View File

@ -22,20 +22,47 @@ type
TColorScheme = (csCustom, csBlue, csGreen, csInvGreen);
type
TDotMatrix = array of integer;
TDotMatrixList = specialize TFPGMap<string, TDotMatrix>;
TDotRow = integer;
TDotRows = array of TDotRow;
TDotMatrixList = specialize TFPGMap<string, TDotRows>;
TCharDefs = class(TPersistent)
private
FCharList: TDotMatrixList;
FColCount: Integer;
FRowCount: Integer;
function GetCount: Integer;
function GetDotRows(AChar: String): TDotRows;
procedure SetColCount(AValue: Integer);
procedure SetDotRows(AChar: String; const AValue: TDotRows);
procedure SetRowCount(AValue: Integer);
function EmptyRows: TDotRows;
procedure ReadCharDefs(Reader: TReader);
procedure WriteCharDefs(Writer: TWriter);
protected
procedure DefineProperties(Filer: TFiler); override;
public
constructor Create;
destructor Destroy; override;
procedure Add(AChar: String; ADotRows: TDotRows);
procedure Delete(AChar: String);
procedure Clear;
property Count: Integer read GetCount;
property DotRows[AChar: String]: TDotRows read GetDotRows write SetDotRows;
published
property ColCount: Integer read FColCount write SetColCount;
property RowCount: Integer read FRowCount write SetRowCount;
end;
TLCDDisplay = class(TGraphicControl)
private
BitMap: TBitMap;
FBitmap: TBitMap;
{
one char consists of Col x Row of dots
dots have size and space between dots
}
FDotSize: integer; // dot size in pixels
FDotsSpace: integer; // inter-dots space in pixels
FDotColsCount: integer; // number of dot-cols in char matrix
FDotRowsCount: integer; // number of dot-rows in char matrix
FCharCount: integer;
FGlobalDotColsCount: integer;
FCharWidth: integer;
@ -63,7 +90,12 @@ type
FFrameColorStyle: TFrameColorStyle;
FDotShape: TDotShape;
FCharList: TDotMatrixList;
FCharDefs: TCharDefs;
function GetDotColCount: Integer;
function GetDotRowCount: INteger;
procedure SetDotColCount(AValue: Integer);
procedure SetDotRowCount(AValue: Integer);
procedure SetDotShape(const Value: TDotShape);
procedure SetFrameColorStyle(const Value: TFrameColorStyle);
@ -87,8 +119,9 @@ type
function CalcCharCount: integer;
procedure InitCharList(AHorDots, AVertDots: integer);
//calculate widths and heigths of the char matrix, background border and frame
procedure DrawCalc();
procedure Prepare();
//draw frame
procedure DrawBorder();
//background grid of dots that are off
@ -105,27 +138,29 @@ type
procedure DrawBitmapToCanvas();
protected
// Basic method of auto-size calculation
procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;
{%H-}WithThemeSpace: boolean); override;
// Takes care of high-dpi scaling
procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
const AXProportion, AYProportion: double); override;
// inherited painting routine
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure AddDotMatrix(AChar: string; const Dots: array of integer);
property DotColsCount: integer read FDotColsCount;
property DotRowsCount: integer read FDotRowsCount;
// Adds a user-defined character and its dot matrix.
procedure AddCharDef(AChar: string; const Dots: TDotRows);
property CharCount: longint read GetCharCount;
property DotColCount: integer read GetDotColCount;
property DotRowCount: integer read GetDotRowCount;
property GlobalDotColsCount: longint read GetGlobalDotColsCount;
published
property AutoSize;
property AutoSize default true;
property BorderSpacing;
property ShowHint;
property Visible;
@ -135,6 +170,8 @@ type
property OnMouseMove;
property OnMouseUp;
property CharDefs: TCharDefs read FCharDefs write FCharDefs;
property DotSize: integer read FDotSize write SetDotSize default 4;
property DotsSpace: integer read FDotsSpace write SetDotsSpace default 1;
property FrameSize: integer read FFrameSize write SetFrameSize default 8;
@ -182,6 +219,169 @@ implementation
uses
Dialogs, LazUTF8, LazUnicode;
{ TCharDefs }
constructor TCharDefs.Create;
begin
inherited;
FCharList := TDotMatrixList.Create;
FCharList.Sorted := True;
end;
destructor TCharDefs.Destroy;
begin
FCharList.Free;
inherited;
end;
{ Adds a new character dot matrix. }
procedure TCharDefs.Add(AChar: String; ADotRows: TDotRows);
begin
if Length(ADotRows) <> FRowCount then
raise Exception.Create('Incorrect number of rows.');
FCharList.Add(AChar, ADotRows);
end;
{ Clears all characters and their dot matrices. }
procedure TCharDefs.Clear;
begin
FCharList.Clear;
end;
{ Prepares streaming of the dot matrices }
procedure TCharDefs.DefineProperties(Filer: TFiler);
begin
inherited DefineProperties(Filer);
Filer.DefineProperty('CharDefs', @ReadCharDefs, @WriteCharDefs, true);
end;
{ Deletes the specified character and its dot matrix from the list. }
procedure TCharDefs.Delete(AChar: String);
var
idx: Integer;
begin
if FCharList.Find(AChar, idx) then
FCharList.Delete(idx);
end;
{ Creates an empty row in which not dots are set. }
function TCharDefs.EmptyRows: TDotRows;
var
row: Integer;
begin
Result := nil;
SetLength(Result, FRowCount);
for row := 0 to FRowCount-1 do
Result[row] := 0;
end;
{ Returns the number of characters contained. }
function TCharDefs.GetCount: Integer;
begin
Result := FCharList.Count;
end;
{ Returns the dot matrix rows for the specified character. Each row is an
integer in which each bit is interpreted as a dot. }
function TCharDefs.GetDotRows(AChar: String): TDotRows;
var
idx: Integer;
begin
if FCharList.Find(AChar, idx) then
Result := FCharList.Data[idx]
else
Result := EmptyRows;
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. }
procedure TCharDefs.ReadCharDefs(Reader: TReader);
var
i: Integer;
s: String;
ch: String;
sa: TStringArray;
rows: TDotRows = nil;
begin
Clear;
Reader.ReadListBegin;
while not Reader.EndOfList do
begin
s := Reader.ReadString;
if s[1] = ',' then
begin
ch := ',';
System.Delete(s, 1, 2);
end else
begin
i := pos(',', s);
ch := copy(s, 1, i-1);
System.Delete(s, 1, i);
end;
sa := s.Split(',');
SetLength(rows, Length(sa));
for i := 0 to High(sa) do
rows[i] := StrToInt(sa[i]);
Add(ch, rows);
end;
Reader.ReadListEnd;
end;
{ Returns the number of columns of the dot matrix. }
procedure TCharDefs.SetColCount(AValue: Integer);
begin
if FColCount = AValue then
exit;
FColCount := AValue;
FCharList.Clear;
end;
{ Sets the dot matrix for the specified character }
procedure TCharDefs.SetDotRows(AChar: String; const AValue: TDotRows);
var
idx: Integer;
begin
if FCharList.Find(AChar, idx) then
FCharList.Data[idx] := AValue
else
Add(AChar, AValue);
end;
{ Returns the number of rows of the dot matrix. }
procedure TCharDefs.SetRowCount(AValue: Integer);
begin
if FRowCount = AValue then
exit;
FRowCount := AValue;
FCharList.Clear;
end;
{ Write the character and its dot matrix to the LFM. Each character is stored
as a comma-separated list of character and dotrow values. }
procedure TCharDefs.WriteCharDefs(Writer: TWriter);
var
i, j: Integer;
ch: String;
rows: TDotRows;
s: String;
begin
Writer.WriteListBegin;
for i := 0 to Count-1 do
begin
ch := FCharList.Keys[i];
rows := DotRows[ch];
s := ch;
for j := 0 to FRowCount-1 do
s := s + ',' + IntToStr(rows[j]);
Writer.WriteString(s);
end;
Writer.WriteListEnd;
end;
{ TLCDDisplay}
constructor TLCDDisplay.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
@ -193,12 +393,10 @@ begin
FDisplayLineCount := 2;
FDisplayCharCount := 10;
FCharList := TDotMatrixList.Create;
FCharList.Sorted := True;
FDotColsCount := 5;
FDotRowsCount := 7;
InitCharList(FDotColsCount, FDotRowsCount);
FCharDefs := TCharDefs.Create;
FCharDefs.ColCount := 5;
FCharDefs.RowCount := 7;
InitCharList(DotColCount, DotRowCount);
FDotSize := 4;
FDotsSpace := 1;
@ -210,44 +408,43 @@ begin
FDotColorOn := clSkyBlue;
FDotColorOff := clTeal;
BitMap := TBitMap.Create;
FBitmap := TBitMap.Create;
FCountOn := 255;
FLines := TStringList.Create;
AutoSize := true;
end;
destructor TLCDDisplay.Destroy;
begin
BitMap.Free;
FCharList.Free;
FBitmap.Free;
FCharDefs.Free;
FLines.Free;
inherited Destroy;
end;
procedure TLCDDisplay.AddDotMatrix(AChar: string; const Dots: array of integer);
var
matrix: TDotMatrix = nil;
i: integer;
procedure TLCDDisplay.AddCharDef(AChar: string; const Dots: TDotRows);
begin
if Length(Dots) <> FDotRowsCount then
raise Exception.Create('AddDotMatrix: Incorrect number of rows.');
SetLength(matrix, FDotRowsCount);
for i := 0 to FDotRowsCount - 1 do
matrix[i] := Dots[i];
FCharList.Add(AChar, matrix);
FCharDefs.Add(AChar, Dots);
end;
procedure TLCDDisplay.CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;
WithThemeSpace: boolean);
var
nDotCols: Integer;
nDotRows: Integer;
begin
FCharWidth := (DotSize * FDotColsCount) + (DotsSpace * (FDotColsCount + 1)); //pixels
nDotCols := DotColCount;
nDotRows := DotRowCount;
FCharWidth := (DotSize * nDotCols) + (DotsSpace * (nDotCols + 1)); //pixels
FCharCount := CalcCharCount;
FGlobalDotColsCount := (FCharCount * FDotColsCount) + (FCharCount - 1); //dots
FGlobalDotColsCount := (FCharCount * nDotCols) + (FCharCount - 1); //dots
// total matrix width
FLEDWidth := (FGlobalDotColsCount * DotSize) + ((FGlobalDotColsCount - 1) * DotsSpace);
// total matrix height
FLEDHeight := (FDisplayLineCount * FDotRowsCount * (DotSize + DotsSpace)) +
FLEDHeight := (FDisplayLineCount * nDotRows * (DotSize + DotsSpace)) +
((FDisplayLineCount - 1) * (DotSize + DotsSpace));
if FCharSpace then
FLEDHeight := FLEDHeight + ((FDisplayLineCount - 1) * DotsSpace);
@ -274,16 +471,22 @@ begin
end;
end;
procedure TLCDDisplay.DrawCalc();
procedure TLCDDisplay.Prepare();
var
nDotCols: Integer;
nDotRows: Integer;
begin
FCharWidth := (DotSize * FDotColsCount) + (DotsSpace * (FDotColsCount + 1)); //pixels
nDotCols := DotColCount;
nDotRows := DotRowCount;
FCharWidth := (DotSize * nDotCols) + (DotsSpace * (nDotCols + 1)); //pixels
FCharCount := ((Width - (2 * FrameSize)) + DotSize) div (FCharWidth + DotSize);
FGlobalDotColsCount := (FCharCount * FDotColsCount) + (FCharCount - 1); //dots
FGlobalDotColsCount := (FCharCount * nDotCols) + (FCharCount - 1); //dots
// total matrix width
FLEDWidth := (FGlobalDotColsCount * DotSize) + ((FGlobalDotColsCount - 1) * DotsSpace);
// total matrix height
FLEDHeight := (FDisplayLineCount * FDotRowsCount * (DotSize + DotsSpace)) +
FLEDHeight := (FDisplayLineCount * nDotRows * (DotSize + DotsSpace)) +
((FDisplayLineCount - 1) * (DotSize + DotsSpace));
if FCharSpace then
FLEDHeight := FLEDHeight + ((FDisplayLineCount - 1) * DotsSpace);
@ -291,8 +494,8 @@ begin
FBoardWidth := (Width - 2 * FrameSize - FLEDWidth) div 2;
FBoardHeight := (Height - 2 * FrameSize - FLEDHeight) div 2;
BitMap.Width := Width;
BitMap.Height := Height;
FBitmap.Width := Width;
FBitmap.Height := Height;
end;
procedure TLCDDisplay.DrawBorder();
@ -314,11 +517,11 @@ begin
BEnd.X := Width - FrameSize;
BEnd.Y := Height - FrameSize;
with BitMap.Canvas do
with FBitmap.Canvas do
begin
Brush.Color := FrameColor;
Pen.Color := FrameColor;
Rectangle(0, 0, BitMap.Width, BitMap.Height);
Rectangle(0, 0, FBitmap.Width, FBitmap.Height);
Brush.Color := FBoardColor;
Pen.Color := FBoardColor;
Rectangle(BStart.X, BStart.Y, BEnd.X, BEnd.Y);
@ -389,7 +592,7 @@ end;
procedure TLCDDisplay.DrawShadow(StartP, EndP: TPoint; LineColor1, LineColor2: TColor);
begin
with BitMap.Canvas do
with FBitmap.Canvas do
begin
Pen.Color := LineColor1;
MoveTo(EndP.X, StartP.Y);
@ -409,8 +612,8 @@ var
NRow, NCol: integer;
begin
NRow := (FDotRowsCount + 1) * FDisplayLineCount - 1;
NCol := (FDotColsCount + 1) * FCharCount - 1;
NRow := (DotRowCount + 1) * FDisplayLineCount - 1;
NCol := (DotColCount + 1) * FCharCount - 1;
for y := 0 to NRow - 1 do
for x := 0 to NCol - 1 do
@ -428,8 +631,8 @@ begin
//j - horizontal spaces
for lc := 0 to FDisplayLineCount - 1 do
begin
NRow := FDotRowsCount + 1;
NCol := (FDotColsCount + 1) * FCharCount - 1;
NRow := DotRowCount + 1;
NCol := (DotColCount + 1) * FCharCount - 1;
j := 0;
for y := 0 to (NRow * (lc + 1)) do
@ -458,12 +661,12 @@ end;
procedure TLCDDisplay.DrawText();
var
x, y, c: integer;
DotRow: integer;
DotOn: boolean;
i, j: integer;
dots: TDotRows;
dotRow: TDotRow;
dotOn: boolean;
i: integer;
line: string;
ch: string;
matrix: TDotMatrix;
begin
for i := 0 to FDisplayLineCount - 1 do
begin
@ -476,12 +679,10 @@ begin
for ch in line do
begin
Inc(c);
if not FCharList.Find(ch, j) then
exit;
matrix := FCharList[ch];
for y := 0 to FDotRowsCount - 1 do
dots := FCharDefs.DotRows[ch];
for y := 0 to DotRowCount - 1 do
begin
DotRow := matrix[y];
DotRow := dots[y];
for x := 0 to 4 do
begin
DotOn := DotRow and (1 shl (5 - x - 1)) > 0;
@ -501,7 +702,7 @@ end;
procedure TLCDDisplay.DrawChar(Row, Col, NChar: integer);
begin
Col := Col + ((FDotColsCount + 1) * (NChar - 1));
Col := Col + ((DotColCount + 1) * (NChar - 1));
if Col > FGlobalDotColsCount - 1 then
Exit;
if Col < 0 then
@ -534,7 +735,7 @@ begin
exit;
end;
with BitMap.Canvas do
with FBitmap.Canvas do
begin
Pen.Color := DotColor;
Brush.Color := DotColor;
@ -548,7 +749,16 @@ end;
procedure TLCDDisplay.DrawBitmapToCanvas();
begin
Canvas.Draw(0, 0, BitMap);
Canvas.Draw(0, 0, FBitmap);
end;
procedure TLCDDisplay.Paint();
begin
Prepare();
DrawBorder();
DrawGrid();
DrawText();
DrawBitmapToCanvas();
end;
// Find the longest's line length
@ -578,118 +788,106 @@ procedure TLCDDisplay.InitCharList(AHorDots, AVertDots: integer);
var
i: integer;
begin
FCharList.Clear;
FCharDefs.Clear;
if (AHorDots = 5) and (AVertDots = 7) then
begin
for i := 0 to 32 do
AddDotMatrix(char(i), [0, 0, 0, 0, 0, 0, 0]);
AddDotMatrix('!', [4, 4, 4, 4, 4, 0, 4]); // #33
AddDotMatrix('"', [10, 10, 0, 0, 0, 0, 0]); // #34
AddDotMatrix('#', [0, 10, 31, 10, 31, 10, 0]); // #35
AddDotMatrix('$', [4, 15, 20, 14, 5, 30, 4]); // #36
AddDotMatrix('%', [25, 26, 2, 4, 8, 11, 19]); // #37
AddDotMatrix('&', [12, 18, 20, 8, 21, 18, 13]); // #38
AddDotMatrix('''', [4, 4, 0, 0, 0, 0, 0]); // #39
AddDotMatrix('(', [2, 4, 8, 8, 8, 4, 2]); // #40
AddDotMatrix(')', [8, 4, 2, 2, 2, 4, 8]); // #41
AddDotMatrix('*', [0, 4, 21, 14, 21, 4, 0]); // #42
AddDotMatrix('+', [0, 4, 4, 31, 4, 4, 0]); // #43
AddDotMatrix(',', [0, 0, 0, 0, 12, 4, 8]); // #44
AddDotMatrix('-', [0, 0, 0, 14, 0, 0, 0]); // #45
AddDotMatrix('.', [0, 0, 0, 0, 0, 12, 12]); // #46
AddDotMatrix('/', [1, 1, 2, 4, 8, 16, 16]); // #47
AddDotMatrix('0', [14, 17, 19, 21, 25, 17, 14]); // #48
AddDotMatrix('1', [4, 12, 4, 4, 4, 4, 14]); // #49
AddDotMatrix('2', [14, 17, 1, 2, 4, 8, 31]); // #50
AddDotMatrix('3', [14, 17, 1, 6, 1, 17, 14]); // #51
AddDotMatrix('4', [2, 6, 10, 18, 31, 2, 2]); // #52
AddDotMatrix('5', [31, 16, 30, 1, 1, 17, 14]); // #53
AddDotMatrix('6', [14, 17, 16, 30, 17, 17, 14]); // #54
AddDotMatrix('7', [31, 1, 1, 2, 4, 4, 4]); // #55
AddDotMatrix('8', [14, 17, 17, 14, 17, 17, 14]); // #56
AddDotMatrix('9', [14, 17, 17, 15, 1, 17, 14]); // #57
AddDotMatrix(':', [0, 12, 12, 0, 12, 12, 0]); // #58
AddDotMatrix(';', [0, 12, 12, 0, 12, 4, 8]); // #59
AddDotMatrix('<', [2, 4, 8, 16, 8, 4, 2]); // #60
AddDotMatrix('=', [0, 0, 31, 0, 31, 0, 0]); // #61
AddDotMatrix('>', [8, 4, 2, 1, 2, 4, 8]); // #62
AddDotMatrix('?', [14, 17, 1, 2, 4, 0, 4]); // #63
AddDotMatrix('@', [14, 17, 19, 21, 23, 16, 15]); // #64
AddDotMatrix('A', [14, 17, 17, 31, 17, 17, 17]); // #65
AddDotMatrix('B', [30, 17, 17, 30, 17, 17, 30]); // #66
AddDotMatrix('C', [14, 17, 16, 16, 16, 17, 14]); // #67
AddDotMatrix('D', [30, 17, 17, 17, 17, 17, 30]); // #68
AddDotMatrix('E', [31, 16, 16, 30, 16, 16, 31]); // #69
AddDotMatrix('F', [31, 16, 16, 30, 16, 16, 16]); // #70
AddDotMatrix('G', [14, 17, 16, 19, 17, 17, 14]); // #71
AddDotMatrix('H', [17, 17, 17, 31, 17, 17, 17]); // #72
AddDotMatrix('I', [14, 4, 4, 4, 4, 4, 14]); // #73
AddDotMatrix('J', [1, 1, 1, 1, 17, 17, 14]); // #74
AddDotMatrix('K', [17, 18, 20, 24, 20, 18, 17]); // #75
AddDotMatrix('L', [16, 16, 16, 16, 16, 16, 31]); // #76
AddDotMatrix('M', [17, 27, 21, 21, 17, 17, 17]); // #77
AddDotMatrix('N', [17, 25, 21, 19, 17, 17, 17]); // #78
AddDotMatrix('O', [14, 17, 17, 17, 17, 17, 14]); // #79
AddDotMatrix('P', [30, 17, 17, 30, 16, 16, 16]); // #80
AddDotMatrix('Q', [14, 17, 17, 17, 17, 14, 1]); // #81
AddDotMatrix('R', [30, 17, 17, 30, 17, 17, 17]); // #82
AddDotMatrix('S', [14, 17, 16, 14, 1, 17, 14]); // #83
AddDotMatrix('T', [31, 4, 4, 4, 4, 4, 4]); // #84
AddDotMatrix('U', [17, 17, 17, 17, 17, 17, 14]); // #85
AddDotMatrix('V', [17, 17, 17, 17, 17, 10, 4]); // #86
AddDotMatrix('W', [17, 17, 17, 17, 21, 27, 17]); // #87
AddDotMatrix('X', [17, 10, 4, 4, 4, 10, 17]); // #88
AddDotMatrix('Y', [17, 17, 17, 10, 4, 4, 4]); // #89
AddDotMatrix('Z', [31, 1, 2, 4, 8, 16, 31]); // #90
AddDotMatrix('[', [12, 8, 8, 8, 8, 8, 12]); // #91
AddDotMatrix('\', [0, 16, 8, 4, 2, 1, 0]); // #92
AddDotMatrix(']', [6, 2, 2, 2, 2, 2, 6]); // #93
AddDotMatrix('^', [4, 10, 17, 0, 0, 0, 0]); // #94
AddDotMatrix('_', [0, 0, 0, 0, 0, 0, 31]); // #95
AddDotMatrix('`', [6, 4, 2, 0, 0, 0, 0]); // #96
AddDotMatrix('a', [0, 0, 14, 1, 15, 17, 15]); // #97
AddDotMatrix('b', [16, 16, 30, 17, 17, 17, 30]); // #98
AddDotMatrix('c', [0, 0, 15, 16, 16, 16, 15]); // #99
AddDotMatrix('d', [1, 1, 15, 17, 17, 17, 15]); // #100
AddDotMatrix('e', [0, 0, 14, 17, 31, 16, 14]); // #101
AddDotMatrix('f', [3, 4, 31, 4, 4, 4, 4]); // #102
AddDotMatrix('g', [0, 0, 15, 17, 15, 1, 14]); // #103
AddDotMatrix('h', [16, 16, 22, 25, 17, 17, 17]);// #104
AddDotMatrix('i', [4, 0, 12, 4, 4, 4, 14]); // #105
AddDotMatrix('j', [2, 0, 6, 2, 2, 18, 12]); // #106
AddDotMatrix('k', [16, 16, 18, 20, 24, 20, 18]);// #107
AddDotMatrix('l', [12, 4, 4, 4, 4, 4, 14]); // #108
AddDotMatrix('m', [0, 0, 26, 21, 21, 21, 21]); // #109
AddDotMatrix('n', [0, 0, 22, 25, 17, 17, 17]); // #110
AddDotMatrix('o', [0, 0, 14, 17, 17, 17, 14]); // #111
AddDotMatrix('p', [0, 0, 30, 17, 30, 16, 16]); // #112
AddDotMatrix('q', [0, 0, 15, 17, 15, 1, 1]); // #113
AddDotMatrix('r', [0, 0, 11, 12, 8, 8, 8]); // #114
AddDotMatrix('s', [0, 0, 14, 16, 14, 1, 30]); // #115
AddDotMatrix('t', [4, 4, 31, 4, 4, 4, 3]); // #116
AddDotMatrix('u', [0, 0, 17, 17, 17, 19, 13]); // #117
AddDotMatrix('v', [0, 0, 17, 17, 17, 10, 4]); // #118
AddDotMatrix('w', [0, 0, 17, 17, 21, 21, 10]); // #119
AddDotMatrix('x', [0, 0, 17, 10, 4, 10, 17]); // #120
AddDotMatrix('y', [0, 0, 17, 17, 15, 1, 14]); // #121
AddDotMatrix('z', [0, 0, 31, 2, 4, 8, 31]); // #122
AddDotMatrix('{', [3, 4, 4, 8, 4, 4, 3]); // #123
AddDotMatrix('|', [4, 4, 4, 4, 4, 4, 4]); // #124
AddDotMatrix('}', [24, 4, 4, 2, 4, 4, 24]); // #125
AddDotMatrix('~', [8, 21, 2, 0, 0, 0, 0]); // #126
AddDotMatrix(#127, [0, 0, 0, 0, 0, 0, 0]); // #127
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
end;
end;
procedure TLCDDisplay.Paint();
begin
DrawCalc();
DrawBorder();
DrawGrid();
DrawText();
DrawBitmapToCanvas();
end;
procedure TLCDDisplay.SetBoardColor(const Value: TColor);
begin
if Value = FBoardColor then
@ -885,14 +1083,50 @@ end;
function TLCDDisplay.GetCharCount: longint;
begin
DrawCalc();
Prepare();
Result := FCharCount;
end;
function TLCDDisplay.GetGlobalDotColsCount: longint;
begin
DrawCalc();
Prepare();
Result := FGlobalDotColsCount;
end;
function TLCDDisplay.GetDotColCount: Integer;
begin
Result := FCharDefs.ColCount;
end;
function TLCDDisplay.GetDotRowCount: Integer;
begin
Result := FCharDefs.RowCount;
end;
procedure TLCDDisplay.SetDotColCount(AValue: Integer);
begin
if AValue = DotColCount then
exit;
FCharDefs.ColCount := AValue;
if AutoSize then
begin
InvalidatePreferredSize;
AdjustSize;
end;
Invalidate;
end;
procedure TLCDDisplay.SetDotRowCount(AValue: Integer);
begin
if AValue = DotRowCount then
exit;
FCharDefs.RowCount := AValue;
if AutoSize then
begin
InvalidatePreferredSize;
AdjustSize;
end;
Invalidate;
end;
end.