mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-17 04:29:25 +02:00
* Moved handle -> reference for TRegion
git-svn-id: trunk@13266 -
This commit is contained in:
parent
e74bc916d7
commit
f9054e88c2
@ -42,7 +42,7 @@ uses
|
||||
IntfGraphics,
|
||||
AvgLvlTree,
|
||||
LCLStrConsts, LCLType, LCLProc, LMessages, LCLIntf, LResources, LCLResCache,
|
||||
GraphType, GraphMath, InterfaceBase;
|
||||
GraphType, GraphMath, InterfaceBase, WSReferences;
|
||||
|
||||
type
|
||||
PColor = ^TColor;
|
||||
@ -614,29 +614,33 @@ type
|
||||
{ TRegion }
|
||||
|
||||
TRegionData = record
|
||||
Handle: HRgn;
|
||||
Reference: TWSRegionReference;
|
||||
Rect: TRect;
|
||||
{Polygon Region Info - not used yet}
|
||||
Polygon: PPoint;//Polygon Points
|
||||
NumPoints: Longint;//Number of Points
|
||||
Winding: Boolean;//Use Winding mode
|
||||
Polygon: PPoint; //Polygon Points
|
||||
NumPoints: Longint; //Number of Points
|
||||
Winding: Boolean; //Use Winding mode
|
||||
end;
|
||||
|
||||
TRegion = class(TGraphicsObject)
|
||||
private
|
||||
FRegionData: TRegionData;
|
||||
procedure FreeHandle;
|
||||
protected
|
||||
procedure FreeReference;
|
||||
function GetReference: TWSRegionReference;
|
||||
function GetHandle: HRGN;
|
||||
procedure ReferenceNeeded;
|
||||
procedure SetHandle(const Value: HRGN);
|
||||
protected
|
||||
procedure SetClipRect(value: TRect);
|
||||
Function GetClipRect: TRect;
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
procedure Assign(Source: TPersistent); override;
|
||||
property Handle: HRGN read GetHandle write SetHandle;
|
||||
|
||||
property ClipRect: TRect read GetClipRect write SetClipRect;
|
||||
property Handle: HRGN read GetHandle write SetHandle; deprecated;
|
||||
property Reference: TWSRegionReference read GetReference;
|
||||
end;
|
||||
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
constructor TRegion.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
FillChar(FRegionData,SizeOf(FRegionData), 0);
|
||||
FillChar(FRegionData, SizeOf(FRegionData), 0);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -40,7 +40,7 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
destructor TRegion.Destroy;
|
||||
begin
|
||||
FreeHandle;
|
||||
FreeReference;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
@ -57,6 +57,7 @@ begin
|
||||
then begin
|
||||
Self.ClipRect := TRegion(Source).ClipRect;
|
||||
//TODO : Get Polygon INFO
|
||||
Exit;
|
||||
end;
|
||||
|
||||
inherited Assign(Source);
|
||||
@ -71,14 +72,13 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TRegion.SetHandle(const Value: HRGN);
|
||||
begin
|
||||
if FRegionData.Handle <> Value
|
||||
then begin
|
||||
FreeHandle;
|
||||
FRegionData.Handle := Value;
|
||||
FRegionData.Rect := GetClipRect;
|
||||
//TODO: query polygon params
|
||||
Changed;
|
||||
end;
|
||||
if FRegionData.Reference.Handle = Value then Exit;
|
||||
|
||||
FreeReference;
|
||||
FRegionData.Reference._lclHandle := Value;
|
||||
FRegionData.Rect := GetClipRect;
|
||||
//TODO: query polygon params
|
||||
Changed;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -89,40 +89,58 @@ end;
|
||||
Creates a region if needed
|
||||
------------------------------------------------------------------------------}
|
||||
function TRegion.GetHandle: HRGN;
|
||||
begin
|
||||
Result := Reference.Handle;
|
||||
end;
|
||||
|
||||
function TRegion.GetReference: TWSRegionReference;
|
||||
begin
|
||||
ReferenceNeeded;
|
||||
Result := FRegionData.Reference;
|
||||
end;
|
||||
|
||||
procedure TRegion.ReferenceNeeded;
|
||||
var
|
||||
FillMode: integer;
|
||||
begin
|
||||
If FRegiondata.Handle = 0 then
|
||||
With FRegionData do
|
||||
if (Polygon <> nil) or (((Rect.Right - Rect.Left) <> 0) or ((Rect.Bottom - Rect.Top) <> 0))
|
||||
then
|
||||
If Polygon <> nil then begin
|
||||
if Winding then
|
||||
FillMode:=LCLType.Winding
|
||||
else
|
||||
FillMode:=Alternate;
|
||||
FRegionData.Handle := CreatePolygonRgn(Polygon, NumPoints, FillMode);
|
||||
end else
|
||||
With Rect do
|
||||
FRegionData.Handle := CreateRectRgn(Left, Top, Right, Bottom);
|
||||
if FRegionData.Reference.Allocated then Exit;
|
||||
|
||||
Result := FRegionData.Handle;
|
||||
if FRegionData.Polygon <> nil
|
||||
then begin
|
||||
if FRegionData.Winding
|
||||
then FillMode := Winding
|
||||
else FillMode := Alternate;
|
||||
|
||||
FRegionData.Reference._lclHandle := CreatePolygonRgn(
|
||||
FRegionData.Polygon, FRegionData.NumPoints, FillMode);
|
||||
Exit;
|
||||
end;
|
||||
|
||||
with FRegionData.Rect do
|
||||
begin
|
||||
if (Right - Left <> 0) or (Bottom - Top <> 0)
|
||||
then begin
|
||||
FRegionData.Reference._lclHandle := CreateRectRgn(Left, Top, Right, Bottom);
|
||||
Exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Method: TRegion.FreeHandle
|
||||
Method: TRegion.FreeReference
|
||||
Params: none
|
||||
Returns: Nothing
|
||||
|
||||
Frees a brushhandle if needed
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TRegion.FreeHandle;
|
||||
|
||||
procedure TRegion.FreeReference;
|
||||
begin
|
||||
if FRegionData.Handle <> 0
|
||||
then begin
|
||||
DeleteObject(FRegionData.Handle);
|
||||
FRegionData.Handle := 0;
|
||||
end;
|
||||
if not FRegionData.Reference.Allocated then Exit;
|
||||
|
||||
DeleteObject(FRegionData.Reference.Handle);
|
||||
FRegionData.Reference._lclHandle := 0;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -134,19 +152,18 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TRegion.SetClipRect(Value : TRect);
|
||||
begin
|
||||
if FRegionData.Rect <> Value
|
||||
then begin
|
||||
FreeHandle;
|
||||
FRegionData.Rect := Value;
|
||||
If FRegionData.Polygon <> nil then
|
||||
ReallocMem(FRegionData.Polygon, 0);
|
||||
if FRegionData.Rect = Value then Exit;
|
||||
|
||||
FRegionData.Polygon := nil;
|
||||
FRegionData.NumPoints := 0;
|
||||
FRegionData.Winding := False;
|
||||
FreeReference;
|
||||
FRegionData.Rect := Value;
|
||||
if FRegionData.Polygon <> nil then
|
||||
ReallocMem(FRegionData.Polygon, 0);
|
||||
|
||||
FRegionData.Polygon := nil;
|
||||
FRegionData.NumPoints := 0;
|
||||
FRegionData.Winding := False;
|
||||
|
||||
Changed;
|
||||
end;
|
||||
Changed;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -156,21 +173,24 @@ end;
|
||||
|
||||
Gets the regions current clip rect
|
||||
------------------------------------------------------------------------------}
|
||||
Function TRegion.GetClipRect : TRect;
|
||||
function TRegion.GetClipRect : TRect;
|
||||
begin
|
||||
If FRegionData.Handle <> 0 then
|
||||
GetRgnBox(FRegionData.Handle, @Result)
|
||||
else
|
||||
If FRegionData.Polygon <> nil then begin
|
||||
GetHandle;
|
||||
If FRegionData.Handle <> 0 then
|
||||
Result := GetClipRect
|
||||
else
|
||||
Result := FRegionData.Rect;
|
||||
FreeHandle;
|
||||
if FRegionData.Reference.Allocated
|
||||
then begin
|
||||
GetRgnBox(FRegionData.Reference.Handle, @Result)
|
||||
end
|
||||
else begin
|
||||
if FRegionData.Polygon <> nil
|
||||
then begin
|
||||
ReferenceNeeded;
|
||||
if FRegionData.Reference.Allocated
|
||||
then Result := GetClipRect
|
||||
else Result := FRegionData.Rect;
|
||||
//FreeReference; // ??? why free (mwe)
|
||||
end
|
||||
else
|
||||
Result := FRegionData.Rect;
|
||||
end;
|
||||
end;
|
||||
|
||||
// included by graphics.pp
|
||||
|
@ -48,11 +48,10 @@ type
|
||||
property WidgetSetClass: TWSLCLComponentClass read FWidgetSetClass;
|
||||
end;
|
||||
|
||||
{ TLCLHandleComponent }
|
||||
// A base class for all components having a handle
|
||||
|
||||
{ TLCLReferenceComponent }
|
||||
|
||||
// A base class for all components having a handle
|
||||
|
||||
TLCLReferenceComponent = class(TLCLComponent)
|
||||
private
|
||||
FReferencePtr: PWSReference;
|
||||
|
@ -60,10 +60,46 @@ type
|
||||
property Ptr: Pointer read FRef.Ptr;
|
||||
end;
|
||||
|
||||
// NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
|
||||
// NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
|
||||
// NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
|
||||
//
|
||||
// All properties with _ are temporary and for lcl use only.
|
||||
// They can be removed anytime, without notice
|
||||
//
|
||||
// (don't complain that I didn't warn you)
|
||||
|
||||
TWSCustomImageListReference = object(TWSReference)
|
||||
public
|
||||
property Handle: Thandle read FRef.Handle;
|
||||
property Handle: THandle read FRef.Handle;
|
||||
end;
|
||||
|
||||
TWSGDIObjReference = object(TWSReference)
|
||||
end;
|
||||
|
||||
TWSBitmapReference = object(TWSGDIObjReference)
|
||||
property Handle: THandle read FRef.Handle;
|
||||
end;
|
||||
|
||||
TWSBrushReference = object(TWSGDIObjReference)
|
||||
property Handle: THandle read FRef.Handle;
|
||||
end;
|
||||
|
||||
TWSPenReference = object(TWSGDIObjReference)
|
||||
property Handle: THandle read FRef.Handle;
|
||||
end;
|
||||
|
||||
TWSFontReference = object(TWSGDIObjReference)
|
||||
property Handle: THandle read FRef.Handle;
|
||||
end;
|
||||
|
||||
TWSRegionReference = object(TWSGDIObjReference)
|
||||
property _lclHandle: THandle write FRef.Handle;
|
||||
property Handle: THandle read FRef.Handle;
|
||||
end;
|
||||
|
||||
TWSDeviceContextReference = object(TWSReference)
|
||||
property Handle: THandle read FRef.Handle;
|
||||
end;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user