📄 iledmatrix.pas
字号:
end;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.iMouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Index : Integer;
Row : Integer;
Col : Integer;
begin
inherited;
Index := GetLedAtXY(X, Y);
if Index <> -1 then if FIndicatorList^[Index].MouseDown then
begin
Row := Index div ColCount;
Col := Index mod ColCount;
FClickRow := Row;
FClickCol := Col;
if Assigned(FOnMouseUpIndicator) then FOnMouseUpIndicator(Row, Col);
if Assigned(FOnClickIndicator) then FOnClickIndicator (Row, Col);
BackGroundChange;
end
else
begin
FClickRow := -1;
FClickCol := -1
end;
ClearMouseDown;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.DblClick;
begin
inherited;
if (FClickRow <> - 1) and (FClickCol <> -1) then
begin
if Assigned(FOnDblClickIndicator) then FOnDblClickIndicator(FClickRow, FClickCol);
end;
end;
//****************************************************************************************************************************************************
function TiLedMatrix.GetLedAtXY(X, Y: Integer): Integer;
var
i : Integer;
begin
Result := -1;
for i := 0 to (ColCount*RowCount)-1 do
begin
if PtInRect(FIndicatorList^[i].ARect, Point(X, Y)) then
begin
Result := i;
Exit;
end;
end;
end;
//****************************************************************************************************************************************************
function TiLedMatrix.GetIndicatorActive(Row, Col: Integer): Boolean;
begin
if (Row < 0) or (Row >= FRowCount) or (Col < 0) or (Col >= FColCount) then raise Exception.Create('Index out of bounds');
Result := FIndicatorList^[Col + Row*ColCount].Active;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.SetIndicatorActive(Row, Col: Integer; const Value: Boolean);
begin
if (Row < 0) or (Row >= FRowCount) or (Col < 0) or (Col >= FColCount) then raise Exception.Create('Index out of bounds');
FIndicatorList^[Col + Row*ColCount].Active := Value;
FIndicatorList^[Col + Row*ColCount].Dirty := True;
BackGroundChange;
end;
//****************************************************************************************************************************************************
function TiLedMatrix.GetIndicatorColor(Row, Col: Integer): TColor;
begin
if (Row < 0) or (Row >= FRowCount) or (Col < 0) or (Col >= FColCount) then raise Exception.Create('Index out of bounds');
Result := FIndicatorList^[Col + Row*ColCount].Color;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.SetIndicatorColor(Row, Col: Integer; const Value: TColor);
begin
if (Row < 0) or (Row >= FRowCount) or (Col < 0) or (Col >= FColCount) then raise Exception.Create('Index out of bounds');
FIndicatorList^[Col + Row*ColCount].Color := Value;
FIndicatorList^[Col + Row*ColCount].Dirty := True;
BackGroundChange;
end;
//****************************************************************************************************************************************************
function TiLedMatrix.GetIndicatorCaption(Row, Col: Integer): String;
begin
if (Row < 0) or (Row >= FRowCount) or (Col < 0) or (Col >= FColCount) then raise Exception.Create('Index out of bounds');
Result := FIndicatorList^[Col + Row*ColCount].Caption;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.SetIndicatorCaption(Row, Col: Integer; const Value: String);
begin
if Length(Value) > 50 then raise Exception.Create('Caption must be 50 or less characters');
if (Row < 0) or (Row >= FRowCount) or (Col < 0) or (Col >= FColCount) then raise Exception.Create('Index out of bounds');
FIndicatorList^[Col + Row*ColCount].Caption := Value;
FIndicatorList^[Col + Row*ColCount].Dirty := True;
BackGroundChange;
end;
//****************************************************************************************************************************************************
function TiLedMatrix.GetAutoSize: TPoint;
begin
Result.x := 2*FOuterMargin + FColCount*(FIndicatorWidth + FSpacingHorizontal);
Result.y := 2*FOuterMargin + FRowCount*(FIndicatorHeight + FSpacingVertical);
if Result.X > 3600 then Result.X := 3600;
if Result.Y > 2880 then Result.Y := 2880;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.DoAutoSize;
var
NewSize : TPoint;
begin
if FDoingAutoSize then exit;
if FAutoSize then
begin
FDoingAutoSize := True;
try
NewSize := GetAutoSize;
Width := NewSize.x;
Height := NewSize.y;
if Assigned(FOnAutoSize) then FOnAutoSize(Self);
finally
FDoingAutoSize := False;
end;
end;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.SetTransparent(const Value: Boolean);
begin
inherited;
RedoAll;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.iSetAutoSize(const Value: Boolean);
begin
if FAutoSize <> Value then
begin
FAutoSize := Value;
DoAutoSize;
BackGroundChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.SetColCount(const Value: Integer);
begin
if Value < 1 then exit;
if FColCount <> Value then
begin
FColCount := Value;
SetCapacity;
RedoAll;
DoAutoSize;
BackGroundChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.SetRowCount(const Value: Integer);
begin
if Value < 1 then exit;
if FRowCount <> Value then
begin
FRowCount := Value;
SetCapacity;
RedoAll;
DoAutoSize;
BackGroundChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.SetIndicatorStyle(const Value: TiLedMatrixIndiatorStyle);
begin
if FIndicatorStyle <> Value then
begin
FIndicatorStyle := Value;
if FIndicatorHeight <> FIndicatorWidth then FIndicatorHeight := FIndicatorWidth;
RedoAll;
BackGroundChange;
DoAutoSize;
end;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.SetIndicatorBevelStyle(const Value: TiBevelStyle);
begin
if FIndicatorBevelStyle <> Value then
begin
FIndicatorBevelStyle := Value;
RedoAll;
BackGroundChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.SetIndicatorHeight(const Value: Integer);
begin
if FIndicatorHeight <> Value then
begin
FIndicatorHeight := Value;
if FIndicatorStyle = ilmisRound then FIndicatorWidth := Value;
RedoAll;
BackGroundChange;
DoAutoSize;
end;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.SetIndicatorWidth(const Value: Integer);
begin
if FIndicatorWidth <> Value then
begin
FIndicatorWidth := Value;
if FIndicatorStyle = ilmisRound then FIndicatorHeight := Value;
RedoAll;
BackGroundChange;
DoAutoSize;
end;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.SetIndicatorShowReflection(const Value: Boolean);
begin
if FIndicatorShowReflection <> Value then
begin
FIndicatorShowReflection := Value;
RedoAll;
BackGroundChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.SetIndicatorActiveColor(const Value: TColor);
var
Row, Col : Integer;
begin
if FIndicatorActiveColor <> Value then
begin
FIndicatorActiveColor := Value;
for Row := 0 to FRowCount -1 do
for Col := 0 to FColCount - 1 do
FIndicatorList^[Col + Row*ColCount].Color := Value;
RedoAll;
BackGroundChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.SetOuterMargin(const Value: Integer);
begin
if FOuterMargin <> Value then
begin
FOuterMargin := Value;
RedoAll;
DoAutoSize;
BackGroundChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.SetSpacingHorizontal(const Value: Integer);
begin
if FSpacingHorizontal <> Value then
begin
FSpacingHorizontal := Value;
RedoAll;
DoAutoSize;
BackGroundChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.SetSpacingVertical(const Value: Integer);
begin
if FSpacingVertical <> Value then
begin
FSpacingVertical := Value;
RedoAll;
DoAutoSize;
BackGroundChange;
end;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.SetCachedDrawing(const Value: Boolean);
begin
inherited;
RedoAll;
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.iPaintTo(Canvas: TCanvas);
begin
if (FIndicatorWidth < 1) or (FIndicatorHeight < 1) then Exit;
if CachedDrawing then iPaintCached(Canvas) else iPaintNonCached(Canvas);
end;
//****************************************************************************************************************************************************
procedure TiLedMatrix.iPaintCached(Canvas: TCanvas);
var
Row, Col : Integer;
CurrentLeft : Integer;
CurrentTop : Integer;
ARect : TRect;
TempRect : TRect;
LedCacheObject : TLedCacheObject;
IndicatorData : TIndicatorData;
CenterY : Integer;
ATextHeight : Integer;
begin
if BackGroundChanged then
begin
CreateBackGroundBitmap;
with BackGroundBitmap, BackGroundBitmap.Canvas do
begin
if FFillBackGround then
begin
DrawBackGround(BackGroundBitmap.Canvas, BackGroundColor);
FFillBackGround := False;
end;
CurrentLeft := (Width - (FIndicatorWidth + FSpacingHorizontal)*FColCount) div 2 + 1;
for Col := 0 to FColCount - 1 do
begin
CurrentTop := (Height - (FIndicatorHeight + FSpacingVertical)*FRowCount) div 2 + 1;
for Row := 0 to FRowCount - 1 do
begin
ARect := Rect(CurrentLeft, CurrentTop, CurrentLeft + FIndicatorWidth, CurrentTop + FIndicatorHeight);
FIndicatorList^[Col + Row*ColCount].ARect := ARect;
IndicatorData := FIndicatorList^[Col + Row*ColCount];
if IndicatorData.Dirty then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -