mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-17 13:49:32 +02:00
Adds more region support for lazcanvas
git-svn-id: trunk@33743 -
This commit is contained in:
parent
50fa9db563
commit
cd917e380b
@ -56,7 +56,7 @@ type
|
||||
FAssignedBrush: TFPCustomBrush;
|
||||
FAssignedPen: TFPCustomPen;
|
||||
FBaseWindowOrg: TPoint;
|
||||
FUseSimpleRectClipping: Boolean;
|
||||
FUseRegionClipping: Boolean;
|
||||
FLazClipRegion: TLazRegion;
|
||||
FWindowOrg: TPoint; // already in absolute coords with BaseWindowOrg summed up
|
||||
function GetAssignedBrush: TFPCustomBrush;
|
||||
@ -78,7 +78,8 @@ type
|
||||
//
|
||||
// SetWindowOrg operations will be relative to BaseWindowOrg, useful for customdrawn wincontrols
|
||||
property BaseWindowOrg: TPoint read FBaseWindowOrg write FBaseWindowOrg;
|
||||
property UseSimpleRectClipping: Boolean read FUseSimpleRectClipping write FUseSimpleRectClipping;
|
||||
property ClipRegion: TLazRegion read FLazClipRegion write FLazClipRegion;
|
||||
property UseRegionClipping: Boolean read FUseRegionClipping write FUseRegionClipping; // when false ClipRect is used
|
||||
property WindowOrg: TPoint read GetWindowOrg write SetWindowOrg;
|
||||
end;
|
||||
|
||||
@ -119,13 +120,14 @@ var
|
||||
begin
|
||||
lx := x + FWindowOrg.X;
|
||||
ly := y + FWindowOrg.Y;
|
||||
if Clipping and FUseRegionClipping and (not FLazClipRegion.IsPointInRegion(lx, ly)) then
|
||||
Exit;
|
||||
inherited SetColor(lx, ly, AValue);
|
||||
end;
|
||||
|
||||
constructor TLazCanvas.create(AnImage: TFPCustomImage);
|
||||
begin
|
||||
inherited Create(AnImage);
|
||||
FUseSimpleRectClipping := True;
|
||||
end;
|
||||
|
||||
destructor TLazCanvas.destroy;
|
||||
|
@ -37,9 +37,11 @@ type
|
||||
// There is no z-order for the parts, they are all validly inside the region area
|
||||
Parts: TFPList; // of TLazRegionPart
|
||||
IsSimpleRectRegion: Boolean; // Indicates whether this region has only 1 rectangular part
|
||||
Rect: TRect; // Used for performance increase when IsSimpleRectRegion is on
|
||||
constructor Create; virtual;
|
||||
destructor Destroy; override;
|
||||
procedure AddRectangle(ARect: TRect);
|
||||
procedure SetAsSimpleRectRegion(ARect: TRect);
|
||||
function IsPointInRegion(AX, AY: Integer): Boolean; virtual;
|
||||
end;
|
||||
|
||||
@ -83,6 +85,7 @@ constructor TLazRegion.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
Parts := TFPList.Create;
|
||||
IsSimpleRectRegion := True;
|
||||
end;
|
||||
|
||||
destructor TLazRegion.Destroy;
|
||||
@ -100,6 +103,12 @@ begin
|
||||
Parts.Add(lNewRect);
|
||||
end;
|
||||
|
||||
procedure TLazRegion.SetAsSimpleRectRegion(ARect: TRect);
|
||||
begin
|
||||
IsSimpleRectRegion := True;
|
||||
Rect := ARect;
|
||||
end;
|
||||
|
||||
{
|
||||
Checks if a point is inside this region
|
||||
}
|
||||
@ -107,13 +116,22 @@ function TLazRegion.IsPointInRegion(AX, AY: Integer): Boolean;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
Result := False;
|
||||
for i := 0 to Parts.Count-1 do
|
||||
if IsSimpleRectRegion then
|
||||
begin
|
||||
if TLazRegionPart(Parts.Items[i]).IsPointInPart(AX, AY) then
|
||||
Result := (AX >= Rect.Left) and (AX < Rect.Right) and
|
||||
(AY >= Rect.Top) and (AY < Rect.Bottom);
|
||||
end
|
||||
else
|
||||
begin
|
||||
Result := False;
|
||||
for i := 0 to Parts.Count-1 do
|
||||
begin
|
||||
Result := True;
|
||||
Exit;
|
||||
// being inside 1 subpart is enough
|
||||
if TLazRegionPart(Parts.Items[i]).IsPointInPart(AX, AY) then
|
||||
begin
|
||||
Result := True;
|
||||
Exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user