Merged revision(s) 55060 #2f5b1ac81a from trunk:

gtk3: fixed device context offset. Patch by Anton Kavalenka. Issue #31780
........

git-svn-id: branches/fixes_1_8@55068 -
This commit is contained in:
maxim 2017-05-23 22:12:57 +00:00
parent 6e65bf148c
commit 4db7b3a8dd
2 changed files with 49 additions and 52 deletions

View File

@ -219,6 +219,7 @@ type
Parent: PGtkWidget;
Window: PGdkWindow;
ParentPixmap: PGdkPixbuf;
fncOrigin:TPoint; // non-client area offsets surface origin
constructor Create(AWidget: PGtkWidget; const APaintEvent: Boolean = False); virtual;
constructor Create(AWindow: PGdkWindow; const APaintEvent: Boolean); virtual;
constructor CreateFromCairo(AWidget: PGtkWidget; ACairo: PCairo_t); virtual;
@ -802,6 +803,7 @@ begin
FStyle := psSolid;
FEndCap := pecFlat;
FJoinStyle := pjsRound;
FPenMode := pmCopy; // default pen mode
end;
procedure TGtk3Pen.setCosmetic(b: Boolean);
@ -990,7 +992,6 @@ var
w: Double;
begin
SetSourceColor(FCurrentPen.Color);
case FCurrentPen.Mode of
pmBlack: begin
SetSourceColor(clBlack);
@ -1208,6 +1209,8 @@ begin
end;
procedure TGtk3DeviceContext.CreateObjects;
var
Matrix:cairo_matrix_t;
begin
FBkMode := TRANSPARENT;
FCurrentImage := nil;
@ -1225,6 +1228,10 @@ begin
FCurrentFont := FFont;
FvImage := TGtk3Image.Create(nil, 1, 1, 8, CAIRO_FORMAT_ARGB32);
FCurrentImage := FvImage;
cairo_get_matrix(Widget, @Matrix);
// widget with menu or other non-client exclusions have offset in trasform matrix
fncOrigin:=Point(round(Matrix.x0),round(Matrix.y0));
end;
procedure TGtk3DeviceContext.DeleteObjects;

View File

@ -2731,7 +2731,7 @@ end;
function TGtk3WidgetSet.GetWindowOrgEx(dc: hdc; P: PPoint): Integer;
var
Matrix: Pcairo_matrix_t;
Matrix: cairo_matrix_t;
dx: Double;
dy: Double;
begin
@ -2746,22 +2746,17 @@ begin
{$endif}
exit;
end;
New(Matrix);
cairo_get_matrix(TGtk3DeviceContext(DC).Widget, Matrix);
if Matrix <> nil then
cairo_get_matrix(TGtk3DeviceContext(DC).Widget, @Matrix);
dx := 0;
dy := 0;
cairo_matrix_transform_point(@Matrix, @dx, @dy);
// DebugLn('GetWindowOrgEx POINT ',Format('dx %d dy %d',[-Trunc(Dx), -Trunc(Dy)]));
if P <> nil then
begin
dx := 0;
dy := 0;
cairo_matrix_transform_point(Matrix, @dx, @dy);
// DebugLn('GetWindowOrgEx POINT ',Format('dx %d dy %d',[-Trunc(Dx), -Trunc(Dy)]));
if P <> nil then
begin
P^.X := -Trunc(DX);
P^.Y := -Trunc(DY);
end;
Result := 1;
Dispose(Matrix);
P^.X := -Trunc(DX)+TGtk3DeviceContext(DC).fncOrigin.X;
P^.Y := -Trunc(DY)+TGtk3DeviceContext(DC).fncOrigin.Y;
end;
Result := 1;
end;
function TGtk3WidgetSet.GetWindowRect(Handle: hwnd; var ARect: TRect): Integer;
@ -2907,7 +2902,7 @@ end;
function TGtk3WidgetSet.LPtoDP(DC: HDC; var Points; Count: Integer): BOOL;
var
Matrix: Pcairo_matrix_t;
Matrix: cairo_matrix_t;
cr: PCairo_t;
P: PPoint;
dx, dy: Double;
@ -2921,26 +2916,23 @@ begin
if not IsValidDC(DC) then
exit;
cr := TGtk3DeviceContext(DC).Widget;
New(Matrix);
try
cairo_get_matrix(cr, Matrix);
P := @Points;
while Count > 0 do
begin
Dec(Count);
DX := P^.X;
DY := P^.Y;
// DebugLn('LPTODP INPUT ',Format('dx %2.2n dy %2.2n',[dx, dy]));
cairo_matrix_translate(Matrix, Dx, Dy);
cairo_matrix_transform_point(Matrix, @Dx, @Dy);
// DebugLn('LPTODP Output ',Format('dx %2.2n dy %2.2n',[dx, dy]));
P^.X := Round(DX);
P^.Y := Round(DY);
Inc(P);
end;
finally
Dispose(Matrix);
P := @Points;
while Count > 0 do
begin
Dec(Count);
DX := P^.X;
DY := P^.Y;
// DebugLn('LPTODP INPUT ',Format('dx %2.2n dy %2.2n',[dx, dy]));
//cairo_matrix_translate(@Matrix, Dx, Dy);
//cairo_matrix_transform_point(@Matrix, @Dx, @Dy);
cairo_user_to_device(cr,@dx,@dy);
// DebugLn('LPTODP Output ',Format('dx %2.2n dy %2.2n',[dx, dy]));
P^.X := Round(DX)-TGtk3DeviceContext(DC).fncOrigin.x;
P^.Y := Round(DY)-TGtk3DeviceContext(DC).fncOrigin.y;
Inc(P);
end;
Result:=true;
end;
function MessageButtonClicked(Widget : PGtkWidget; data: gPointer) : GBoolean; cdecl;
@ -3221,7 +3213,7 @@ begin
R := NormalizeRect(Rect(X1, Y1, X2, Y2));
if IsRectEmpty(R) then Exit(True);
with R do
TGtk3DeviceContext(DC).drawRect(Left, Top, Right - Left, Bottom - Top, True);
TGtk3DeviceContext(DC).drawRect(Left, Top, Right - Left, Bottom - Top, false);
Result := True;
end;
@ -3892,7 +3884,7 @@ end;
function TGtk3WidgetSet.SetWindowOrgEx(dc: hdc; NewX, NewY: Integer;
OldPoint: PPoint): Boolean;
var
Matrix: Pcairo_matrix_t;
Matrix: cairo_matrix_t;
dx: Double;
dy: Double;
begin
@ -3900,20 +3892,18 @@ begin
if IsValidDC(DC) then
begin
GetWindowOrgEx(dc, OldPoint);
New(Matrix);
cairo_get_matrix(TGtk3DeviceContext(DC).Widget, Matrix);
if Matrix <> nil then
begin
dx := 0;
dy := 0;
// cairo_matrix_init_translate(Matrix, -NewX, -NewY);
cairo_matrix_translate(Matrix, -NewX, -NewY);
cairo_transform(TGtk3DeviceContext(DC).Widget, Matrix);
// cairo_set_matrix(TGtk3DeviceContext(DC).Widget, Matrix);
// DebugLn('TGtk3WidgetSet.SetWindowOrgEx NewX=',dbgs(NewX),' NewY=',dbgs(NewY));
Result := True;
Dispose(Matrix);
end;
cairo_get_matrix(TGtk3DeviceContext(DC).Widget, @Matrix);
dx := 0;
dy := 0;
// cairo_matrix_init_translate(Matrix, -NewX, -NewY);
cairo_matrix_translate(@Matrix,
-NewX - TGtk3DeviceContext(DC).fncOrigin.x,
-NewY - TGtk3DeviceContext(DC).fncOrigin.Y);
cairo_transform(TGtk3DeviceContext(DC).Widget, @Matrix);
// cairo_set_matrix(TGtk3DeviceContext(DC).Widget, Matrix);
// DebugLn('TGtk3WidgetSet.SetWindowOrgEx NewX=',dbgs(NewX),' NewY=',dbgs(NewY));
Result := True;
end;
end;