You've already forked lazarus-ccr
899 lines
26 KiB
ObjectPascal
899 lines
26 KiB
ObjectPascal
![]() |
{
|
||
|
*****************************************************************************
|
||
|
See the file COPYING.modifiedLGPL.txt, included in your Lazarus installation
|
||
|
for details about the license.
|
||
|
*****************************************************************************
|
||
|
Based on LCDLine by Yuriy Tereshchenko
|
||
|
Initial Lazarus port and multi-line extension: Boban Spasic (spasic@gmail.com)
|
||
|
Further optimizations and extensions: Werner Pamler
|
||
|
}
|
||
|
unit indLCDDisplay;
|
||
|
|
||
|
interface
|
||
|
|
||
|
uses
|
||
|
SysUtils, Classes, Controls, fgl, Graphics, LResources, LCLIntf;
|
||
|
|
||
|
type
|
||
|
TFrameStyle = (fsRelief, fsNone, fsLowered, fsRaised);
|
||
|
TFrameColorStyle = (stWindows, stColor);
|
||
|
TFrameHeight = (fhDouble, fhSingle);
|
||
|
TDotShape = (stSquare, stRound);
|
||
|
TColorScheme = (csCustom, csBlue, csGreen, csInvGreen);
|
||
|
|
||
|
type
|
||
|
TDotMatrix = array of integer;
|
||
|
TDotMatrixList = specialize TFPGMap<string, TDotMatrix>;
|
||
|
|
||
|
TLCDDisplay = class(TGraphicControl)
|
||
|
private
|
||
|
BitMap: 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;
|
||
|
|
||
|
FFrameSize: integer;
|
||
|
FBoardWidth: integer;
|
||
|
FBoardHeight: integer;
|
||
|
FLEDWidth: integer;
|
||
|
FLEDHeight: integer;
|
||
|
|
||
|
FFrameColor: TColor;
|
||
|
FBoardColor: TColor;
|
||
|
FDotColorOn: TColor;
|
||
|
FDotColorOff: TColor;
|
||
|
|
||
|
FLenText: integer;
|
||
|
FDisplayLineCount: integer;
|
||
|
FDisplayCharCount: integer;
|
||
|
FLines: TStringList;
|
||
|
FCharSpace: boolean;
|
||
|
FColorScheme: TColorScheme;
|
||
|
FCountOn: integer;
|
||
|
FFrameStyle: TFrameStyle;
|
||
|
FFrameHeight: TFrameHeight;
|
||
|
FFrameColorStyle: TFrameColorStyle;
|
||
|
FDotShape: TDotShape;
|
||
|
|
||
|
FCharList: TDotMatrixList;
|
||
|
|
||
|
procedure SetDotShape(const Value: TDotShape);
|
||
|
procedure SetFrameColorStyle(const Value: TFrameColorStyle);
|
||
|
procedure SetFrameHeight(const Value: TFrameHeight);
|
||
|
procedure SetFrameStyle(const Value: TFrameStyle);
|
||
|
procedure SetCharSpace(const Value: boolean);
|
||
|
procedure SetColorScheme(const Value: TColorScheme);
|
||
|
|
||
|
function GetCharCount: longint;
|
||
|
function GetGlobalDotColsCount: longint;
|
||
|
procedure SetDisplayLineCount(const Value: integer);
|
||
|
procedure SetDisplayCharCount(const Value: integer);
|
||
|
procedure SetLines(const Value: TStringList);
|
||
|
procedure SetDotColorOff(const Value: TColor);
|
||
|
procedure SetDotColorOn(const Value: TColor);
|
||
|
procedure SetBoardColor(const Value: TColor);
|
||
|
procedure SetFrameColor(const Value: TColor);
|
||
|
procedure SetFrameSize(const Value: integer);
|
||
|
procedure SetDotSize(const Value: integer);
|
||
|
procedure SetDotsSpace(const Value: integer);
|
||
|
|
||
|
function CalcCharCount: integer;
|
||
|
procedure InitCharList(AHorDots, AVertDots: integer);
|
||
|
//calculate widths and heigths of the char matrix, background border and frame
|
||
|
procedure DrawCalc();
|
||
|
//draw frame
|
||
|
procedure DrawBorder();
|
||
|
//background grid of dots that are off
|
||
|
procedure DrawGrid();
|
||
|
//space between chars
|
||
|
procedure DrawSpace();
|
||
|
//call DrawChar for every char
|
||
|
procedure DrawText();
|
||
|
//call DrawDot for every dot that is on
|
||
|
procedure DrawChar(Row, Col, NChar: integer);
|
||
|
procedure DrawDot(Row, Col: integer; DotColor: TColor);
|
||
|
//draw frame shadow
|
||
|
procedure DrawShadow(StartP, EndP: TPoint; LineColor1, LineColor2: TColor);
|
||
|
procedure DrawBitmapToCanvas();
|
||
|
|
||
|
protected
|
||
|
procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;
|
||
|
{%H-}WithThemeSpace: boolean); override;
|
||
|
procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
|
||
|
const AXProportion, AYProportion: double); override;
|
||
|
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;
|
||
|
|
||
|
property CharCount: longint read GetCharCount;
|
||
|
property GlobalDotColsCount: longint read GetGlobalDotColsCount;
|
||
|
|
||
|
|
||
|
published
|
||
|
property AutoSize;
|
||
|
property BorderSpacing;
|
||
|
property ShowHint;
|
||
|
property Visible;
|
||
|
property OnClick;
|
||
|
property OnDblClick;
|
||
|
property OnMouseDown;
|
||
|
property OnMouseMove;
|
||
|
property OnMouseUp;
|
||
|
|
||
|
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;
|
||
|
|
||
|
property FrameColor: TColor read FFrameColor write SetFrameColor default clBtnFace;
|
||
|
// To use BoardColor, ColorScheme must be set to csCustom
|
||
|
property BoardColor: TColor read FBoardColor write SetBoardColor default clBlack;
|
||
|
// To use DotColorOn, ColorScheme must be set to csCustom
|
||
|
property DotColorOn: TColor read FDotColorOn write SetDotColorOn default clSkyBlue;
|
||
|
// To use DotColorOff, ColorScheme must be set to csCustom
|
||
|
property DotColorOff: TColor read FDotColorOff write SetDotColorOff default clTeal;
|
||
|
// Vertical screen size in chars
|
||
|
// Without AutoSize, if the frame is too small
|
||
|
// a part off the text will not be visible
|
||
|
// e.g. frame is big enough for one line
|
||
|
// and the text contains 3 lines
|
||
|
// - just the middle line will be visible
|
||
|
property DisplayLineCount: integer read FDisplayLineCount write SetDisplayLineCount default 2;
|
||
|
// Horizontal screen size in chars
|
||
|
// Set to <=0 (zero) to have a real AutoSize
|
||
|
// Has no effect without AutoSize
|
||
|
property DisplayCharCount: integer read FDisplayCharCount write SetDisplayCharCount default 10;
|
||
|
// The text to display
|
||
|
// It will be truncated according
|
||
|
// to ScreenRowCount and ScreenColCount
|
||
|
property Lines: TStringList read FLines write SetLines;
|
||
|
// Insert one-dot space between chars
|
||
|
property CharSpace: boolean read FCharSpace write SetCharSpace default False;
|
||
|
// Pre-defined color schemes
|
||
|
// Set to csCustom in order to use
|
||
|
// the BoardColor, DotColorOn and DotColorOff
|
||
|
property ColorScheme: TColorScheme
|
||
|
read FColorScheme write SetColorScheme default csCustom;
|
||
|
property FrameStyle: TFrameStyle
|
||
|
read FFrameStyle write SetFrameStyle default fsRelief;
|
||
|
property FrameHeight: TFrameHeight
|
||
|
read FFrameHeight write SetFrameHeight default fhDouble;
|
||
|
property FrameColorStyle: TFrameColorStyle
|
||
|
read FFrameColorStyle write SetFrameColorStyle default stWindows;
|
||
|
property DotShape: TDotShape read FDotShape write SetDotShape default stSquare;
|
||
|
end;
|
||
|
|
||
|
implementation
|
||
|
|
||
|
uses
|
||
|
Dialogs, LazUTF8, LazUnicode;
|
||
|
|
||
|
constructor TLCDDisplay.Create(AOwner: TComponent);
|
||
|
begin
|
||
|
inherited Create(AOwner);
|
||
|
ControlStyle := ControlStyle + [csOpaque];
|
||
|
|
||
|
Width := 156;
|
||
|
Height := 76;
|
||
|
|
||
|
FDisplayLineCount := 2;
|
||
|
FDisplayCharCount := 10;
|
||
|
|
||
|
FCharList := TDotMatrixList.Create;
|
||
|
FCharList.Sorted := True;
|
||
|
|
||
|
FDotColsCount := 5;
|
||
|
FDotRowsCount := 7;
|
||
|
InitCharList(FDotColsCount, FDotRowsCount);
|
||
|
|
||
|
FDotSize := 4;
|
||
|
FDotsSpace := 1;
|
||
|
FFrameSize := 8;
|
||
|
FBoardWidth := 4;
|
||
|
|
||
|
FFrameColor := clBtnFace;
|
||
|
FBoardColor := clBlack;
|
||
|
FDotColorOn := clSkyBlue;
|
||
|
FDotColorOff := clTeal;
|
||
|
|
||
|
BitMap := TBitMap.Create;
|
||
|
FCountOn := 255;
|
||
|
|
||
|
FLines := TStringList.Create;
|
||
|
end;
|
||
|
|
||
|
destructor TLCDDisplay.Destroy;
|
||
|
begin
|
||
|
BitMap.Free;
|
||
|
FCharList.Free;
|
||
|
FLines.Free;
|
||
|
inherited Destroy;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.AddDotMatrix(AChar: string; const Dots: array of integer);
|
||
|
var
|
||
|
matrix: TDotMatrix = nil;
|
||
|
i: integer;
|
||
|
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);
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.CalculatePreferredSize(var PreferredWidth, PreferredHeight: integer;
|
||
|
WithThemeSpace: boolean);
|
||
|
begin
|
||
|
FCharWidth := (DotSize * FDotColsCount) + (DotsSpace * (FDotColsCount + 1)); //pixels
|
||
|
FCharCount := CalcCharCount;
|
||
|
FGlobalDotColsCount := (FCharCount * FDotColsCount) + (FCharCount - 1); //dots
|
||
|
|
||
|
// total matrix width
|
||
|
FLEDWidth := (FGlobalDotColsCount * DotSize) + ((FGlobalDotColsCount - 1) * DotsSpace);
|
||
|
// total matrix height
|
||
|
FLEDHeight := (FDisplayLineCount * FDotRowsCount * (DotSize + DotsSpace)) +
|
||
|
((FDisplayLineCount - 1) * (DotSize + DotsSpace));
|
||
|
if FCharSpace then
|
||
|
FLEDHeight := FLEDHeight + ((FDisplayLineCount - 1) * DotsSpace);
|
||
|
|
||
|
//background around text matrix - left/right pixels
|
||
|
FBoardWidth := DotSize + DotsSpace;
|
||
|
//background around text matrix - up/down pixels
|
||
|
FBoardHeight := DotSize + DotsSpace;
|
||
|
|
||
|
//Total size incl. frame
|
||
|
PreferredWidth := FLEDWidth + (2 * FrameSize) + (2 * FBoardWidth);
|
||
|
PreferredHeight := FLEDHeight + (2 * FrameSize) + (2 * FBoardWidth);
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
|
||
|
const AXProportion, AYProportion: double);
|
||
|
begin
|
||
|
inherited;
|
||
|
if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then
|
||
|
begin
|
||
|
FDotSize := round(FDotSize * AXProportion);
|
||
|
FDotsSpace := round(FDotsSpace * AXProportion);
|
||
|
FFrameSize := round(FFrameSize * AXProportion);
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.DrawCalc();
|
||
|
begin
|
||
|
FCharWidth := (DotSize * FDotColsCount) + (DotsSpace * (FDotColsCount + 1)); //pixels
|
||
|
FCharCount := ((Width - (2 * FrameSize)) + DotSize) div (FCharWidth + DotSize);
|
||
|
FGlobalDotColsCount := (FCharCount * FDotColsCount) + (FCharCount - 1); //dots
|
||
|
|
||
|
// total matrix width
|
||
|
FLEDWidth := (FGlobalDotColsCount * DotSize) + ((FGlobalDotColsCount - 1) * DotsSpace);
|
||
|
// total matrix height
|
||
|
FLEDHeight := (FDisplayLineCount * FDotRowsCount * (DotSize + DotsSpace)) +
|
||
|
((FDisplayLineCount - 1) * (DotSize + DotsSpace));
|
||
|
if FCharSpace then
|
||
|
FLEDHeight := FLEDHeight + ((FDisplayLineCount - 1) * DotsSpace);
|
||
|
|
||
|
FBoardWidth := (Width - 2 * FrameSize - FLEDWidth) div 2;
|
||
|
FBoardHeight := (Height - 2 * FrameSize - FLEDHeight) div 2;
|
||
|
|
||
|
BitMap.Width := Width;
|
||
|
BitMap.Height := Height;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.DrawBorder();
|
||
|
var
|
||
|
FStart, FEnd: TPoint;
|
||
|
BStart, BEnd: TPoint;
|
||
|
Color1, Color2, Color3, Color4: TColor;
|
||
|
C: longint;
|
||
|
R, G, B: integer;
|
||
|
const
|
||
|
K1 = 4.637;
|
||
|
K2 = 1.364;
|
||
|
K3 = 1.372093;
|
||
|
K4 = 2.088495;
|
||
|
begin
|
||
|
|
||
|
BStart.X := FrameSize;
|
||
|
BStart.Y := FrameSize;
|
||
|
BEnd.X := Width - FrameSize;
|
||
|
BEnd.Y := Height - FrameSize;
|
||
|
|
||
|
with BitMap.Canvas do
|
||
|
begin
|
||
|
Brush.Color := FrameColor;
|
||
|
Pen.Color := FrameColor;
|
||
|
Rectangle(0, 0, BitMap.Width, BitMap.Height);
|
||
|
Brush.Color := FBoardColor;
|
||
|
Pen.Color := FBoardColor;
|
||
|
Rectangle(BStart.X, BStart.Y, BEnd.X, BEnd.Y);
|
||
|
end;
|
||
|
|
||
|
if FrameStyle = fsNone then
|
||
|
Exit;
|
||
|
|
||
|
if FrameColorStyle = stWindows then
|
||
|
C := ColorToRGB(clBtnFace)
|
||
|
else
|
||
|
C := ColorToRGB(FrameColor);
|
||
|
|
||
|
R := RED(C);
|
||
|
G := GREEN(C);
|
||
|
B := BLUE(C);
|
||
|
|
||
|
if FrameColorStyle = stWindows then
|
||
|
Color1 := clWhite
|
||
|
else
|
||
|
Color1 := RGBToColor(Round(R / K1 + 200), Round(G / K1 + 200), Round(B / K1 + 200));
|
||
|
|
||
|
Color2 := RGBToColor(Round(R / K2 + 68), Round(G / K2 + 68), Round(B / K2 + 68));
|
||
|
Color3 := RGBToColor(Round(R / K3), Round(G / K3), Round(B / K3));
|
||
|
|
||
|
if FrameHeight = fhDouble then
|
||
|
Color4 := RGBToColor(Round(R / K4), Round(G / K4), Round(B / K4))
|
||
|
else
|
||
|
Color4 := Color3;
|
||
|
|
||
|
FStart.X := 0;
|
||
|
FStart.Y := 0;
|
||
|
FEnd.X := Width - 1;
|
||
|
FEnd.Y := Height - 1;
|
||
|
|
||
|
BStart.X := FrameSize;
|
||
|
BStart.Y := FrameSize;
|
||
|
BEnd.X := Width - FrameSize - 1;
|
||
|
BEnd.Y := Height - FrameSize - 1;
|
||
|
|
||
|
if (FrameStyle = fsRaised) or (FrameStyle = fsRelief) then
|
||
|
begin
|
||
|
DrawShadow(FStart, FEnd, Color1, Color4);
|
||
|
|
||
|
if FrameHeight = fhDouble then
|
||
|
begin
|
||
|
FStart.X := FStart.X + 1;
|
||
|
FStart.Y := FStart.Y + 1;
|
||
|
FEnd.X := FEnd.X - 1;
|
||
|
FEnd.Y := FEnd.Y - 1;
|
||
|
DrawShadow(FStart, FEnd, Color2, Color3);
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
if (FrameStyle = fsLowered) or (FrameStyle = fsRelief) then
|
||
|
begin
|
||
|
DrawShadow(BStart, BEnd, Color3, Color1);
|
||
|
if FrameHeight = fhDouble then
|
||
|
begin
|
||
|
BStart.X := BStart.X + 1;
|
||
|
BStart.Y := BStart.Y + 1;
|
||
|
BEnd.X := BEnd.X - 1;
|
||
|
BEnd.Y := BEnd.Y - 1;
|
||
|
DrawShadow(BStart, BEnd, Color4, Color2);
|
||
|
end;
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.DrawShadow(StartP, EndP: TPoint; LineColor1, LineColor2: TColor);
|
||
|
begin
|
||
|
with BitMap.Canvas do
|
||
|
begin
|
||
|
Pen.Color := LineColor1;
|
||
|
MoveTo(EndP.X, StartP.Y);
|
||
|
LineTo(StartP.X, StartP.Y);
|
||
|
LineTo(StartP.X, EndP.Y);
|
||
|
|
||
|
Pen.Color := LineColor2;
|
||
|
MoveTo(EndP.X, StartP.Y);
|
||
|
LineTo(EndP.X, EndP.Y);
|
||
|
LineTo(StartP.X - 1, EndP.Y);
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.DrawGrid();
|
||
|
var
|
||
|
y, x: integer;
|
||
|
NRow, NCol: integer;
|
||
|
begin
|
||
|
|
||
|
NRow := (FDotRowsCount + 1) * FDisplayLineCount - 1;
|
||
|
NCol := (FDotColsCount + 1) * FCharCount - 1;
|
||
|
|
||
|
for y := 0 to NRow - 1 do
|
||
|
for x := 0 to NCol - 1 do
|
||
|
DrawDot(y, x, FDotColorOff);
|
||
|
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.DrawSpace();
|
||
|
var
|
||
|
y, x: integer;
|
||
|
NRow, NCol: integer;
|
||
|
i, j, lc: integer;
|
||
|
begin
|
||
|
//i - vertical spaces
|
||
|
//j - horizontal spaces
|
||
|
for lc := 0 to FDisplayLineCount - 1 do
|
||
|
begin
|
||
|
NRow := FDotRowsCount + 1;
|
||
|
NCol := (FDotColsCount + 1) * FCharCount - 1;
|
||
|
|
||
|
j := 0;
|
||
|
for y := 0 to (NRow * (lc + 1)) do
|
||
|
begin
|
||
|
i := 0;
|
||
|
for x := 0 to NCol - 1 do
|
||
|
begin
|
||
|
if ((i = 5) or (j = 7)) and (y < (NRow * (lc + 1))) then
|
||
|
begin
|
||
|
DrawDot(y, x, FBoardColor);
|
||
|
i := 0;
|
||
|
end
|
||
|
else
|
||
|
i := i + 1;
|
||
|
end;
|
||
|
if j = 7 then
|
||
|
begin
|
||
|
j := 0;
|
||
|
end
|
||
|
else
|
||
|
j := j + 1;
|
||
|
end;
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.DrawText();
|
||
|
var
|
||
|
x, y, c: integer;
|
||
|
DotRow: integer;
|
||
|
DotOn: boolean;
|
||
|
i, j: integer;
|
||
|
line: string;
|
||
|
ch: string;
|
||
|
matrix: TDotMatrix;
|
||
|
begin
|
||
|
for i := 0 to FDisplayLineCount - 1 do
|
||
|
begin
|
||
|
if i < FLines.Count then
|
||
|
begin
|
||
|
line := FLines[i];
|
||
|
FLenText := UTF8Length(line);
|
||
|
|
||
|
c := 0;
|
||
|
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
|
||
|
begin
|
||
|
DotRow := matrix[y];
|
||
|
for x := 0 to 4 do
|
||
|
begin
|
||
|
DotOn := DotRow and (1 shl (5 - x - 1)) > 0;
|
||
|
if DotOn then
|
||
|
DrawChar(y + 8 * i, x, c);
|
||
|
end; // for x
|
||
|
end; // for y
|
||
|
end; // for ch
|
||
|
end;
|
||
|
|
||
|
if CharSpace then
|
||
|
DrawSpace();
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
|
||
|
procedure TLCDDisplay.DrawChar(Row, Col, NChar: integer);
|
||
|
begin
|
||
|
|
||
|
Col := Col + ((FDotColsCount + 1) * (NChar - 1));
|
||
|
if Col > FGlobalDotColsCount - 1 then
|
||
|
Exit;
|
||
|
if Col < 0 then
|
||
|
Exit;
|
||
|
DrawDot(Row, Col, FDotColorOn);
|
||
|
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.DrawDot(Row, Col: integer; DotColor: TColor);
|
||
|
var
|
||
|
DotR: TRect;
|
||
|
begin
|
||
|
DotR.Left := FrameSize + FBoardWidth + (DotSize + DotsSpace) * Col;
|
||
|
DotR.Top := FrameSize + FBoardHeight + (DotSize + DotsSpace) * Row;
|
||
|
DotR.Right := DotR.Left + DotSize;
|
||
|
DotR.Bottom := DotR.Top + DotSize;
|
||
|
|
||
|
if FFrameHeight = fhSingle then
|
||
|
begin
|
||
|
if (DotR.Top <= FFrameSize) or (DotR.Bottom >= Height - FFrameSize) then
|
||
|
exit;
|
||
|
if (DotR.Left <= FFrameSize) or (DotR.Right >= Width - FFrameSize) then
|
||
|
exit;
|
||
|
end
|
||
|
else
|
||
|
begin
|
||
|
if (DotR.Top <= FFrameSize + 1) or (DotR.Bottom >= Height - FFrameSize - 1) then
|
||
|
exit;
|
||
|
if (DotR.Left <= FFrameSize + 1) or (DotR.Right >= Width - FFrameSize - 1) then
|
||
|
exit;
|
||
|
end;
|
||
|
|
||
|
with BitMap.Canvas do
|
||
|
begin
|
||
|
Pen.Color := DotColor;
|
||
|
Brush.Color := DotColor;
|
||
|
|
||
|
if DotShape = stSquare then
|
||
|
FillRect(DotR)
|
||
|
else
|
||
|
Ellipse(DotR.Left, DotR.Top, DotR.Right, DotR.Bottom);
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.DrawBitmapToCanvas();
|
||
|
begin
|
||
|
Canvas.Draw(0, 0, BitMap);
|
||
|
end;
|
||
|
|
||
|
// Find the longest's line length
|
||
|
function TLCDDisplay.CalcCharCount: integer;
|
||
|
var
|
||
|
len: integer;
|
||
|
i, tmp: integer;
|
||
|
begin
|
||
|
len := 1;
|
||
|
if FDisplayCharCount > 0 then
|
||
|
Result := FDisplayCharCount
|
||
|
else
|
||
|
begin
|
||
|
for i := 0 to FDisplayLineCount - 1 do
|
||
|
begin
|
||
|
if i < Lines.Count then
|
||
|
begin
|
||
|
tmp := UTF8Length(Lines[i]);
|
||
|
if tmp > Len then Len := tmp;
|
||
|
end;
|
||
|
end;
|
||
|
Result := Len;
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.InitCharList(AHorDots, AVertDots: integer);
|
||
|
var
|
||
|
i: integer;
|
||
|
begin
|
||
|
FCharList.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
|
||
|
end;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.Paint();
|
||
|
begin
|
||
|
DrawCalc();
|
||
|
DrawBorder();
|
||
|
DrawGrid();
|
||
|
DrawText();
|
||
|
DrawBitmapToCanvas();
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.SetBoardColor(const Value: TColor);
|
||
|
begin
|
||
|
if Value = FBoardColor then
|
||
|
Exit;
|
||
|
FBoardColor := Value;
|
||
|
SetColorScheme(csCustom);
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.SetDotColorOff(const Value: TColor);
|
||
|
begin
|
||
|
if Value = FDotColorOff then
|
||
|
Exit;
|
||
|
FDotColorOff := Value;
|
||
|
SetColorScheme(csCustom);
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.SetDotColorOn(const Value: TColor);
|
||
|
begin
|
||
|
if Value = FDotColorOn then
|
||
|
Exit;
|
||
|
FDotColorOn := Value;
|
||
|
SetColorScheme(csCustom);
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.SetDotSize(const Value: integer);
|
||
|
begin
|
||
|
if Value = DotSize then
|
||
|
Exit;
|
||
|
FDotSize := Value;
|
||
|
if AutoSize then
|
||
|
begin
|
||
|
InvalidatePreferredSize;
|
||
|
AdjustSize;
|
||
|
end;
|
||
|
Invalidate;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.SetDotsSpace(const Value: integer);
|
||
|
begin
|
||
|
if Value = DotsSpace then
|
||
|
Exit;
|
||
|
FDotsSpace := Value;
|
||
|
if AutoSize then
|
||
|
begin
|
||
|
InvalidatePreferredSize;
|
||
|
AdjustSize;
|
||
|
end;
|
||
|
Invalidate;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.SetDotShape(const Value: TDotShape);
|
||
|
begin
|
||
|
if Value = DotShape then
|
||
|
Exit;
|
||
|
FDotShape := Value;
|
||
|
Invalidate;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.SetFrameColor(const Value: TColor);
|
||
|
begin
|
||
|
if Value = FrameColor then
|
||
|
Exit;
|
||
|
FFrameColor := Value;
|
||
|
Invalidate;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.SetFrameColorStyle(const Value: TFrameColorStyle);
|
||
|
begin
|
||
|
if Value = FrameColorStyle then
|
||
|
Exit;
|
||
|
FFrameColorStyle := Value;
|
||
|
Invalidate;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.SetFrameHeight(const Value: TFrameHeight);
|
||
|
begin
|
||
|
if Value = FrameHeight then
|
||
|
Exit;
|
||
|
FFrameHeight := Value;
|
||
|
if AutoSize then
|
||
|
begin
|
||
|
InvalidatePreferredSize;
|
||
|
AdjustSize;
|
||
|
end;
|
||
|
Invalidate;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.SetFrameSize(const Value: integer);
|
||
|
begin
|
||
|
if Value = FrameSize then
|
||
|
Exit;
|
||
|
FFrameSize := Value;
|
||
|
if AutoSize then
|
||
|
begin
|
||
|
InvalidatePreferredSize;
|
||
|
AdjustSize;
|
||
|
end;
|
||
|
Invalidate;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.SetFrameStyle(const Value: TFrameStyle);
|
||
|
begin
|
||
|
if Value = FrameStyle then
|
||
|
Exit;
|
||
|
FFrameStyle := Value;
|
||
|
if AutoSize then
|
||
|
begin
|
||
|
InvalidatePreferredSize;
|
||
|
AdjustSize;
|
||
|
end;
|
||
|
Invalidate;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.SetCharSpace(const Value: boolean);
|
||
|
begin
|
||
|
if Value = CharSpace then
|
||
|
Exit;
|
||
|
FCharSpace := Value;
|
||
|
Invalidate;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.SetColorScheme(const Value: TColorScheme);
|
||
|
begin
|
||
|
if Value = FColorScheme then Exit;
|
||
|
case Value of
|
||
|
csBlue: begin
|
||
|
FBoardColor := clBlack;
|
||
|
FDotColorOff := clTeal;
|
||
|
FDotColorOn := clSkyBlue;
|
||
|
end;
|
||
|
csGreen: begin
|
||
|
FBoardColor := 5162664;
|
||
|
FDotColorOff := 5162664;
|
||
|
FDotColorOn := 2900284;
|
||
|
end;
|
||
|
csInvGreen: begin
|
||
|
FBoardColor := clBlack;
|
||
|
FDotColorOff := 2900284;
|
||
|
FDotColorOn := 5162664;
|
||
|
end;
|
||
|
csCustom: begin
|
||
|
end;
|
||
|
end;
|
||
|
FColorScheme := Value;
|
||
|
Invalidate;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.SetDisplayLineCount(const Value: integer);
|
||
|
begin
|
||
|
if Value = FDisplayLineCount then
|
||
|
Exit;
|
||
|
FDisplayLineCount := Value;
|
||
|
if AutoSize then
|
||
|
begin
|
||
|
InvalidatePreferredSize;
|
||
|
AdjustSize;
|
||
|
end;
|
||
|
Invalidate;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.SetDisplayCharCount(const Value: integer);
|
||
|
begin
|
||
|
if Value = FDisplayCharCount then
|
||
|
Exit;
|
||
|
FDisplayCharCount := Value;
|
||
|
if AutoSize then
|
||
|
begin
|
||
|
InvalidatePreferredSize;
|
||
|
AdjustSize;
|
||
|
end;
|
||
|
Invalidate;
|
||
|
end;
|
||
|
|
||
|
procedure TLCDDisplay.SetLines(const Value: TStringList);
|
||
|
var
|
||
|
i: integer;
|
||
|
begin
|
||
|
FLines.Clear;
|
||
|
for i := 0 to FDisplayLineCount - 1 do
|
||
|
begin
|
||
|
if i < Value.Count then
|
||
|
FLines.Add(Value[i])
|
||
|
else
|
||
|
FLines.Add(' ');
|
||
|
end;
|
||
|
if AutoSize then
|
||
|
begin
|
||
|
InvalidatePreferredSize;
|
||
|
AdjustSize;
|
||
|
end;
|
||
|
Invalidate;
|
||
|
end;
|
||
|
|
||
|
function TLCDDisplay.GetCharCount: longint;
|
||
|
begin
|
||
|
DrawCalc();
|
||
|
Result := FCharCount;
|
||
|
end;
|
||
|
|
||
|
function TLCDDisplay.GetGlobalDotColsCount: longint;
|
||
|
begin
|
||
|
DrawCalc();
|
||
|
Result := FGlobalDotColsCount;
|
||
|
end;
|
||
|
|
||
|
end.
|