📄 qilcdmatrix.pas
字号:
Canvas.FillRect(ARect);
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.DrawCharacter(Canvas: TCanvas; Col, Row: Integer; CharacterIndex: Integer; Color: TColor);
var
CellColStart : Integer;
CellRowstart : Integer;
ACharacter : TiLCDCharacter;
CellRow : Integer;
CellCol : Integer;
CellRowData : Integer;
CellOn : Boolean;
begin
if (Col < 0) or (Col > (FCharactersHorz -1)) then Exit;
if (Row < 0) or (Row > (FCharactersVert -1)) then Exit;
CellColStart := Col *(FCharactersetWidth + FCharacterSpacingHorz);
CellRowStart := Row *(FCharactersetHeight + FCharacterSpacingVert);
Canvas.Brush.Color := Color;
Canvas.Pen.Color := Color;
ACharacter := CharacterObject[CharacterIndex];
for CellRow := 0 to FCharactersetHeight-1 do
begin
CellRowData := ACharacter.GetRowData(CellRow);
for CellCol := 0 to FCharactersetWidth -1 do
begin
CellOn := CellRowData and (1 shl (FCharactersetWidth - CellCol -1)) > 0;
if CellOn then DrawCell(Canvas, CellColStart + CellCol, CellRowstart + CellRow, CellOn);
end;
end;
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.DrawText(Canvas: TCanvas);
var
x : Integer;
Row, Col : Integer;
begin
for x := 0 to FElementList.Count-1 do
begin
if ElementObject[x].AChar = #0 then Continue;
Row := x div FCharactersHorz;
Col := x mod FCharactersHorz;
DrawCharacter(Canvas, Col, Row, ord(ElementObject[x].AChar), ElementObject[x].Color);
end;
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.iPaintTo(Canvas: TCanvas);
begin
DrawBackGround(Canvas, BackGroundColor);
Canvas.Brush.Style := bsSolid;
Canvas.Pen.Style := psSolid;
DrawCalc;
DrawGrid(Canvas);
DrawText(Canvas);
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.SetCharacterSpacingHorz(const Value: Integer);begin if Value < 0 then Exit; SetIntegerProperty(Value, FCharacterSpacingHorz, irtInvalidate);end;
procedure TiLCDMatrix.SetCharacterSpacingVert(const Value: Integer);begin if Value < 0 then Exit; SetIntegerProperty(Value, FCharacterSpacingVert, irtInvalidate);end;
procedure TiLCDMatrix.SetCharactersetWidth (const Value: Integer);begin if Value < 1 then Exit; SetIntegerProperty(Value, FCharactersetWidth, irtInvalidate);end;
procedure TiLCDMatrix.SetCellsWidth (const Value: Integer);begin if Value < 1 then Exit; SetIntegerProperty(Value, FCellsWidth, irtInvalidate);end;
procedure TiLCDMatrix.SetCellsSpacingHorz (const Value: Integer);begin if Value < 0 then Exit; SetIntegerProperty(Value, FCellsSpacingHorz, irtInvalidate);end;
procedure TiLCDMatrix.SetCellsSpacingVert (const Value: Integer);begin if Value < 0 then Exit; SetIntegerProperty(Value, FCellsSpacingVert, irtInvalidate);end;
procedure TiLCDMatrix.SetCellsColorOff (const Value: TColor );begin SetColorProperty (Value, FCellsColorOff, irtInvalidate);end;
procedure TiLCDMatrix.SetCellsShowOff (const Value: Boolean);begin SetBooleanProperty(Value, FCellsShowOff, irtInvalidate);end;
procedure TiLCDMatrix.SetOuterMarginBottom (const Value: Integer);begin if Value < 0 then Exit; SetIntegerProperty(Value, FOuterMarginBottom, irtInvalidate);end;
procedure TiLCDMatrix.SetOuterMarginLeft (const Value: Integer);begin if Value < 0 then Exit; SetIntegerProperty(Value, FOuterMarginLeft, irtInvalidate);end;
procedure TiLCDMatrix.SetOuterMarginRight (const Value: Integer);begin if Value < 0 then Exit; SetIntegerProperty(Value, FOuterMarginRight, irtInvalidate);end;
procedure TiLCDMatrix.SetOuterMarginTop (const Value: Integer);begin if Value < 0 then Exit; SetIntegerProperty(Value, FOuterMarginTop, irtInvalidate);end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.SetCellsColorOn(const Value: TColor);
var
x : Integer;
begin
if FCellsColorOn <> Value then
begin
FCellsColorOn := Value;
for x := 0 to FElementList.Count-1 do
ElementObject[x].Color := Value;
InvalidateChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.SetCharactersetHeight(const Value: Integer);
var
x : Integer;
begin
if Value < 1 then Exit;
if FCharactersetHeight <> Value then
begin
FCharactersetHeight := Value;
for x := 0 to 255 do
CharacterObject[x].RowCount := Value;
InvalidateChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.SetCharactorRowData(CharacterIndex, RowIndex, Value: Integer);
begin
CharacterObject[CharacterIndex].SetRowData(RowIndex, Value);
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.DefineProperties(Filer: TFiler);
begin
inherited;
Filer.DefineProperty('Characters', ReadFromStream, WriteToStream, True);
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.WriteToStream(Writer: TWriter);
var
x : Integer;
begin
TWriterAccess(Writer).WriteValue(vaCollection);
for x := 0 to 255 - 1 do
begin
Writer.WriteListBegin;
WriterWriteProperties(Writer, CharacterObject[x]);
Writer.WriteListEnd;
end;
Writer.WriteListEnd;
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.ReadFromStream(Reader: TReader);
var
CurrentIndex : Integer;
begin
CurrentIndex := 0;
if TReaderAccess(Reader).ReadValue <> vaCollection then exit;
while not Reader.EndOfList do
begin
Reader.ReadListBegin;
while not Reader.EndOfList do TReaderAccess(Reader).ReadProperty(CharacterObject[CurrentIndex]);
Reader.ReadListEnd;
Inc(CurrentIndex)
end;
Reader.ReadListEnd;
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.LoadCharactersetFromFile(FileName: String);
var
x : Integer;
Row : Integer;
StringList : TStringList;
NewWidth : Integer;
NewHeight : Integer;
CurrentIndex : Integer;
begin
StringList := TStringList.Create;
try
StringList.LoadFromFile(FileName);
CurrentIndex := 0;
NewWidth := StrToInt(StringList.Strings[CurrentIndex]); Inc(CurrentIndex);
NewHeight := StrToInt(StringList.Strings[CurrentIndex]); Inc(CurrentIndex);
if (NewHeight*256 + 2) <> StringList.Count then raise Exception.Create('Invalid Characterset File Format');
FCharactersetName := ExtractFileName(FileName);
CharactersetWidth := NewWidth;
CharactersetHeight := NewHeight;
for x := 0 to 255 do
for Row := 0 to NewHeight-1 do
begin
CharacterObject[x].SetRowData(Row, StrToInt(StringList.Strings[CurrentIndex]));
Inc(CurrentIndex);
end;
finally
StringList.Free;
end;
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.SaveCharactersetToFile(FileName: String);
var
x : Integer;
Row : Integer;
StringList : TStringList;
begin
StringList := TStringList.Create;
try
StringList.Add(IntToStr(CharactersetWidth));
StringList.Add(IntToStr(CharactersetHeight));
for x := 0 to 255 do
for Row := 0 to CharactersetHeight-1 do
StringList.Add(IntToStr(CharacterObject[x].GetRowData(Row)));
StringList.SaveToFile(FileName);
FCharactersetName := ExtractFileName(FileName);
finally
StringList.Free;
end;
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.AdjustElementList(RequiredElements: Integer);
var
Element : TiLCDElement;
begin
if FElementList.Count < RequiredElements then
begin
while FElementList.Count < RequiredElements do
begin
Element := TiLCDElement.Create;
Element.Color := FCellsColorOn;
Element.AChar := #0;
FElementList.AddObject('', Element);
end;
end;
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.SetText(const Value: String);
begin
FText := Value;
Clear;
PlaceText(FText, 0, 0, FCellsColorOn);
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.PlaceText(AText: String; Col, Row: Integer; AColor: TColor);
var
x : Integer;
StartIndex : Integer;
AShortString : ShortString;
begin
DrawCalc;
StartIndex := Row*FCharactersHorz + Col;
AdjustElementList(StartIndex + Length(AText));
for x := 0 to Length(AText)-1 do
begin
if (x + StartIndex) > FElementList.Count-1 then Break;
AShortString := Copy(AText, x + 1, 1);
ElementObject[StartIndex + x].AChar := AShortString[1];
ElementObject[StartIndex + x].Color := AColor;
end;
InvalidateChange;
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.Clear;
var
x : Integer;
begin
for x := 0 to FElementList.Count-1 do
begin
ElementObject[x].Color := FCellsColorOn;
ElementObject[x].AChar := #0;
end;
InvalidateChange;
end;
//****************************************************************************************************************************************************
function TiLCDMatrix.GetElementColor(Col, Row: Integer): TColor;
begin
DrawCalc;
Result := clBlack;
if Col < 0 then Exit;
if Row < 0 then Exit;
if Col > FCharactersHorz -1 then Exit;
if Row > FCharactersVert -1 then Exit;
Result := ElementObject[Row*FCharactersHorz + Col].Color;
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.SetElementColor(Col, Row: Integer; const Value: TColor);
begin
DrawCalc;
if Col < 0 then Exit;
if Row < 0 then Exit;
if Col > FCharactersHorz -1 then Exit;
if Row > FCharactersVert -1 then Exit;
ElementObject[Row*FCharactersHorz + Col].Color := Value;
InvalidateChange;
end;
//****************************************************************************************************************************************************
function TiLCDMatrix.GetElementChar(Col, Row: Integer): Char;
begin
DrawCalc;
Result := #0;
if Col < 0 then Exit;
if Row < 0 then Exit;
if Col > FCharactersHorz -1 then Exit;
if Row > FCharactersVert -1 then Exit;
Result := ElementObject[Row*FCharactersHorz + Col].AChar;
end;
//****************************************************************************************************************************************************
function TiLCDMatrix.GetElementCharCode(Col, Row: Integer): Integer;
begin
DrawCalc;
Result := 0;
if Col < 0 then Exit;
if Row < 0 then Exit;
if Col > FCharactersHorz -1 then Exit;
if Row > FCharactersVert -1 then Exit;
Result := ord(ElementObject[Row*FCharactersHorz + Col].AChar);
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.SetElementChar(Col, Row: Integer; const Value: Char);
begin
DrawCalc;
if Col < 0 then Exit;
if Row < 0 then Exit;
if Col > FCharactersHorz -1 then Exit;
if Row > FCharactersVert -1 then Exit;
ElementObject[Row*FCharactersHorz + Col].AChar := Value;
InvalidateChange;
end;
//****************************************************************************************************************************************************
procedure TiLCDMatrix.SetElementCode(Col, Row: Integer; const Value: Integer);
begin
DrawCalc;
if Col < 0 then Exit;
if Row < 0 then Exit;
if Col > FCharactersHorz -1 then Exit;
if Row > FCharactersVert -1 then Exit;
ElementObject[Row*FCharactersHorz + Col].AChar := chr(Value);
InvalidateChange;
end;
//****************************************************************************************************************************************************
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -