mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-25 14:28:15 +02:00
carbon: improve clipping operations: proper implementation of IntersectClipRect, ExcludeClipRect, SaveDC, RestoreDC functions
git-svn-id: trunk@21297 -
This commit is contained in:
parent
e363193148
commit
f1cea2e7e7
@ -84,7 +84,6 @@ type
|
|||||||
FSavedDCList: TFPObjectList;
|
FSavedDCList: TFPObjectList;
|
||||||
FTextFractional: Boolean;
|
FTextFractional: Boolean;
|
||||||
|
|
||||||
fLastClipRegion : TCarbonRegion;
|
|
||||||
isClipped : Boolean;
|
isClipped : Boolean;
|
||||||
|
|
||||||
procedure SetBkColor(AValue: TColor);
|
procedure SetBkColor(AValue: TColor);
|
||||||
@ -99,6 +98,7 @@ type
|
|||||||
function GetSize: TPoint; virtual; abstract;
|
function GetSize: TPoint; virtual; abstract;
|
||||||
function SaveDCData: TCarbonDCData; virtual;
|
function SaveDCData: TCarbonDCData; virtual;
|
||||||
procedure RestoreDCData(const AData: TCarbonDCData); virtual;
|
procedure RestoreDCData(const AData: TCarbonDCData); virtual;
|
||||||
|
procedure ExcludeClipRect(Left, Top, Right, Bottom: Integer);
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -119,7 +119,6 @@ type
|
|||||||
procedure DrawGrid(const ARect: TRect; DX, DY: Integer);
|
procedure DrawGrid(const ARect: TRect; DX, DY: Integer);
|
||||||
|
|
||||||
procedure Ellipse(X1, Y1, X2, Y2: Integer);
|
procedure Ellipse(X1, Y1, X2, Y2: Integer);
|
||||||
procedure ExcludeClipRect(Left, Top, Right, Bottom: Integer);
|
|
||||||
function ExtTextOut(X, Y: Integer; Options: Longint; Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean;
|
function ExtTextOut(X, Y: Integer; Options: Longint; Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean;
|
||||||
procedure FillRect(Rect: TRect; Brush: TCarbonBrush);
|
procedure FillRect(Rect: TRect; Brush: TCarbonBrush);
|
||||||
procedure Frame(X1, Y1, X2, Y2: Integer);
|
procedure Frame(X1, Y1, X2, Y2: Integer);
|
||||||
@ -144,8 +143,6 @@ type
|
|||||||
public
|
public
|
||||||
property Size: TPoint read GetSize;
|
property Size: TPoint read GetSize;
|
||||||
|
|
||||||
property LastClipRegion: TCarbonRegion read fLastClipRegion;
|
|
||||||
|
|
||||||
property CurrentFont: TCarbonFont read FCurrentFont write SetCurrentFont;
|
property CurrentFont: TCarbonFont read FCurrentFont write SetCurrentFont;
|
||||||
property CurrentBrush: TCarbonBrush read FCurrentBrush write SetCurrentBrush;
|
property CurrentBrush: TCarbonBrush read FCurrentBrush write SetCurrentBrush;
|
||||||
property CurrentPen: TCarbonPen read FCurrentPen write SetCurrentPen;
|
property CurrentPen: TCarbonPen read FCurrentPen write SetCurrentPen;
|
||||||
@ -492,6 +489,8 @@ end;
|
|||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
function TCarbonDeviceContext.SaveDC: Integer;
|
function TCarbonDeviceContext.SaveDC: Integer;
|
||||||
begin
|
begin
|
||||||
|
if isClipped then CGContextRestoreGState(CGContext); // clip rect is on top of the state stack!
|
||||||
|
|
||||||
Result := 0;
|
Result := 0;
|
||||||
if CGContext = nil then
|
if CGContext = nil then
|
||||||
begin
|
begin
|
||||||
@ -507,6 +506,13 @@ begin
|
|||||||
{$IFDEF VerboseCanvas}
|
{$IFDEF VerboseCanvas}
|
||||||
DebugLn('TCarbonDeviceContext.SaveDC Result: ', DbgS(Result));
|
DebugLn('TCarbonDeviceContext.SaveDC Result: ', DbgS(Result));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
|
if isClipped then
|
||||||
|
begin
|
||||||
|
// should clip rect be restored?
|
||||||
|
isClipped:=false;
|
||||||
|
FClipRegion.Shape := HIShapeCreateEmpty;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -518,6 +524,8 @@ end;
|
|||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
function TCarbonDeviceContext.RestoreDC(ASavedDC: Integer): Boolean;
|
function TCarbonDeviceContext.RestoreDC(ASavedDC: Integer): Boolean;
|
||||||
begin
|
begin
|
||||||
|
if isClipped then CGContextRestoreGState(CGContext);
|
||||||
|
|
||||||
Result := False;
|
Result := False;
|
||||||
if (FSavedDCList = nil) or (ASavedDC <= 0) or (ASavedDC > FSavedDCList.Count) then
|
if (FSavedDCList = nil) or (ASavedDC <= 0) or (ASavedDC > FSavedDCList.Count) then
|
||||||
begin
|
begin
|
||||||
@ -549,6 +557,14 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
if FSavedDCList.Count = 0 then FreeAndNil(FSavedDCList);
|
if FSavedDCList.Count = 0 then FreeAndNil(FSavedDCList);
|
||||||
|
|
||||||
|
|
||||||
|
if isClipped then
|
||||||
|
begin
|
||||||
|
// should clip be restored?
|
||||||
|
isClipped:=false;
|
||||||
|
FClipRegion.Shape := HIShapeCreateEmpty;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -1468,7 +1484,6 @@ begin
|
|||||||
isClipped := false;
|
isClipped := false;
|
||||||
CGContextRestoreGState(CGContext);
|
CGContextRestoreGState(CGContext);
|
||||||
end;
|
end;
|
||||||
fLastClipRegion := AClipRegion;
|
|
||||||
|
|
||||||
if not Assigned(AClipRegion) then
|
if not Assigned(AClipRegion) then
|
||||||
begin
|
begin
|
||||||
|
@ -801,6 +801,9 @@ begin
|
|||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
Result := LCLType.ComplexRegion;
|
Result := LCLType.ComplexRegion;
|
||||||
|
if (CombineMode in [RGN_AND, RGN_OR, RGN_XOR]) and HIShapeIsEmpty(FShape) then
|
||||||
|
CombineMode := RGN_COPY;
|
||||||
|
|
||||||
case CombineMode of
|
case CombineMode of
|
||||||
RGN_AND: Shape:=HIShapeCreateIntersection(FShape, ARegion.Shape);
|
RGN_AND: Shape:=HIShapeCreateIntersection(FShape, ARegion.Shape);
|
||||||
RGN_XOR:
|
RGN_XOR:
|
||||||
|
@ -102,6 +102,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
if AWidget.HasCaret then DrawCaret;
|
if AWidget.HasCaret then DrawCaret;
|
||||||
|
|
||||||
|
// resetting clip region for the next paint
|
||||||
|
TCarbonControlContext(AWidget.Context).SetClipRegion(nil, 0);
|
||||||
|
|
||||||
|
|
||||||
finally
|
finally
|
||||||
FreeAndNil(AWidget.Context);
|
FreeAndNil(AWidget.Context);
|
||||||
dec(IsDrawEvent);
|
dec(IsDrawEvent);
|
||||||
|
@ -904,18 +904,8 @@ end;
|
|||||||
function TCarbonWidgetSet.ExcludeClipRect(DC: HDC; Left, Top, Right,
|
function TCarbonWidgetSet.ExcludeClipRect(DC: HDC; Left, Top, Right,
|
||||||
Bottom: Integer): Integer;
|
Bottom: Integer): Integer;
|
||||||
begin
|
begin
|
||||||
Result := ERROR;
|
//todo: remove, as unused
|
||||||
|
Result := inherited ExcludeClipRect(DC, Left, Top, Right, Bottom);
|
||||||
{$IFDEF VerboseWinAPI}
|
|
||||||
DebugLn('TCarbonWidgetSet.ExcludeClipRect DC: ' + DbgS(DC) + ' R: ' +
|
|
||||||
DbgS(Classes.Rect(Left, Top, Right, Bottom)));
|
|
||||||
{$ENDIF}
|
|
||||||
|
|
||||||
if not CheckDC(DC, 'ExcludeClipRect') then Exit;
|
|
||||||
|
|
||||||
TCarbonDeviceContext(DC).ExcludeClipRect(Left, Top, Right, Bottom);
|
|
||||||
|
|
||||||
Result := COMPLEXREGION;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCarbonWidgetSet.ExtCreatePen(dwPenStyle, dwWidth: DWord;
|
function TCarbonWidgetSet.ExtCreatePen(dwPenStyle, dwWidth: DWord;
|
||||||
@ -2249,19 +2239,8 @@ end;
|
|||||||
function TCarbonWidgetSet.IntersectClipRect(DC: HDC; Left, Top, Right,
|
function TCarbonWidgetSet.IntersectClipRect(DC: HDC; Left, Top, Right,
|
||||||
Bottom: Integer): Integer;
|
Bottom: Integer): Integer;
|
||||||
begin
|
begin
|
||||||
Result := ERROR;
|
//todo: remove, as not used
|
||||||
|
Result := inherited IntersectClipRect(DC, Left, Top, Right, Bottom);
|
||||||
{$IFDEF VerboseWinAPI}
|
|
||||||
DebugLn('TCarbonWidgetSet.IntersectClipRect DC: ' + DbgS(DC) + ' R: ' +
|
|
||||||
DbgS(Classes.Rect(Left, Top, Right, Bottom)));
|
|
||||||
{$ENDIF}
|
|
||||||
|
|
||||||
if not CheckDC(DC, 'IntersectClipRect') then Exit;
|
|
||||||
|
|
||||||
CGContextClipToRect(TCarbonContext(DC).CGContext,
|
|
||||||
RectToCGRect(Classes.Rect(Left, Top, Right, Bottom)));
|
|
||||||
|
|
||||||
Result := COMPLEXREGION;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -2461,10 +2440,10 @@ function TCarbonWidgetSet.MoveWindowOrgEx(DC: HDC; dX, dY: Integer): Boolean;
|
|||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
|
|
||||||
{$IFDEF VerboseWinAPI}
|
{.$IFDEF VerboseWinAPI}
|
||||||
DebugLn('TCarbonWidgetSet.MoveWindowOrgEx DC: ' + DbgS(DC) + ' ' + DbgS(DX)
|
DebugLn('TCarbonWidgetSet.MoveWindowOrgEx DC: ' + DbgS(DC) + ' ' + DbgS(DX)
|
||||||
+ ', ' + DbgS(DY));
|
+ ', ' + DbgS(DY));
|
||||||
{$ENDIF}
|
{.$ENDIF}
|
||||||
|
|
||||||
if not CheckDC(DC, 'MoveWindowOrgEx') then Exit;
|
if not CheckDC(DC, 'MoveWindowOrgEx') then Exit;
|
||||||
|
|
||||||
@ -3447,7 +3426,6 @@ const
|
|||||||
SName = 'TCarbonWidgetSet.StretchMaskBlt';
|
SName = 'TCarbonWidgetSet.StretchMaskBlt';
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
|
|
||||||
{$IFDEF VerboseWinAPI}
|
{$IFDEF VerboseWinAPI}
|
||||||
DebugLn('TCarbonWidgetSet.StretchMaskBlt DestDC: ' + DbgS(DestDC) + ' SrcDC: ',
|
DebugLn('TCarbonWidgetSet.StretchMaskBlt DestDC: ' + DbgS(DestDC) + ' SrcDC: ',
|
||||||
DbgS(SrcDC) + ' X: ' + DbgS(X) + ' Y: ' + DbgS(Y),
|
DbgS(SrcDC) + ' X: ' + DbgS(X) + ' Y: ' + DbgS(Y),
|
||||||
|
Loading…
Reference in New Issue
Block a user