mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-25 16:29:10 +02:00
TAChart: Add THistory and TChartExtentHistory utility classes
git-svn-id: trunk@38653 -
This commit is contained in:
parent
15016fc37f
commit
fcf539ce79
@ -233,6 +233,25 @@ type
|
|||||||
property IsSet[AIndex: Integer]: Boolean read GetIsSet write SetIsSet;
|
property IsSet[AIndex: Integer]: Boolean read GetIsSet write SetIsSet;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// A limited capacity stack desighed to store 'undo'-like history.
|
||||||
|
generic THistory<TElem> = class
|
||||||
|
strict private
|
||||||
|
FCount: Cardinal;
|
||||||
|
FData: array of TElem;
|
||||||
|
|
||||||
|
function GetCapacity: Cardinal; inline;
|
||||||
|
function GetItem(AIndex: Integer): TElem;
|
||||||
|
procedure SetCapacity(AValue: Cardinal);
|
||||||
|
procedure DeleteOld(ACount: Integer);
|
||||||
|
public
|
||||||
|
procedure Add(const AItem: TElem);
|
||||||
|
function Pop: TElem; inline;
|
||||||
|
|
||||||
|
property Capacity: Cardinal read GetCapacity write SetCapacity;
|
||||||
|
property Count: Cardinal read FCount;
|
||||||
|
property Item[AIndex: Integer]: TElem read GetItem; default;
|
||||||
|
end;
|
||||||
|
|
||||||
const
|
const
|
||||||
PUB_INT_SET_ALL = '';
|
PUB_INT_SET_ALL = '';
|
||||||
PUB_INT_SET_EMPTY = '-';
|
PUB_INT_SET_EMPTY = '-';
|
||||||
@ -493,6 +512,49 @@ begin
|
|||||||
Result := (A.Code = B.Code) and (A.Data = B.Data);
|
Result := (A.Code = B.Code) and (A.Data = B.Data);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ THistory }
|
||||||
|
|
||||||
|
procedure THistory.Add(const AItem: TElem);
|
||||||
|
begin
|
||||||
|
if Capacity = 0 then exit;
|
||||||
|
if FCount = Capacity then
|
||||||
|
DeleteOld(1);
|
||||||
|
FData[FCount] := AItem;
|
||||||
|
FCount += 1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure THistory.DeleteOld(ACount: Integer);
|
||||||
|
begin
|
||||||
|
FCount -= ACount;
|
||||||
|
Move(FData[ACount], FData[0], SizeOf(FData[0]) * FCount);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function THistory.GetCapacity: Cardinal;
|
||||||
|
begin
|
||||||
|
Result := Length(FData);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function THistory.GetItem(AIndex: Integer): TElem;
|
||||||
|
begin
|
||||||
|
if AIndex < 0 then
|
||||||
|
AIndex += Integer(FCount);
|
||||||
|
Result := FData[AIndex];
|
||||||
|
end;
|
||||||
|
|
||||||
|
function THistory.Pop: TElem;
|
||||||
|
begin
|
||||||
|
Result := GetItem(-1);
|
||||||
|
FCount -= 1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure THistory.SetCapacity(AValue: Cardinal);
|
||||||
|
begin
|
||||||
|
if Capacity = AValue then exit;
|
||||||
|
if AValue < FCount then
|
||||||
|
DeleteOld(FCount - AValue);
|
||||||
|
SetLength(FData, AValue);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TTypedFPListEnumerator }
|
{ TTypedFPListEnumerator }
|
||||||
|
|
||||||
function TTypedFPListEnumerator.GetCurrent: T;
|
function TTypedFPListEnumerator.GetCurrent: T;
|
||||||
|
@ -172,6 +172,8 @@ type
|
|||||||
property YMin: Double index 2 read GetBounds write SetBounds stored IsBoundsStored;
|
property YMin: Double index 2 read GetBounds write SetBounds stored IsBoundsStored;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TChartExtentHistory = specialize THistory<TDoubleRect>;
|
||||||
|
|
||||||
TRectArray = array [1..4] of Integer;
|
TRectArray = array [1..4] of Integer;
|
||||||
|
|
||||||
{ TChartMargins }
|
{ TChartMargins }
|
||||||
|
Loading…
Reference in New Issue
Block a user