mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-09 23:08:05 +02:00
qt:
- improve LineTo - PolyLine must skip last pixel to be delphi/win32 compatible git-svn-id: trunk@16690 -
This commit is contained in:
parent
d0f9e88743
commit
7f06e41a7c
@ -292,6 +292,7 @@ type
|
||||
procedure DebugClipRect(const msg: string);
|
||||
procedure setImage(AImage: TQtImage);
|
||||
procedure CorrectCoordinates(var ARect: TRect);
|
||||
function GetLineLastPixelPos(PrevPos, NewPos: TPoint): TPoint;
|
||||
public
|
||||
{ Qt functions }
|
||||
|
||||
@ -310,6 +311,7 @@ type
|
||||
procedure drawLine(x1: Integer; y1: Integer; x2: Integer; y2: Integer);
|
||||
procedure drawEllipse(x: Integer; y: Integer; w: Integer; h: Integer);
|
||||
procedure drawPixmap(p: PQtPoint; pm: QPixmapH; sr: PRect);
|
||||
procedure drawPolyLine(P: PPoint; NumPts: Integer);
|
||||
procedure eraseRect(ARect: PRect);
|
||||
procedure fillRect(ARect: PRect; ABrush: QBrushH); overload;
|
||||
procedure fillRect(x, y, w, h: Integer; ABrush: QBrushH); overload;
|
||||
@ -1770,6 +1772,23 @@ begin
|
||||
if ARect.Bottom > MaxBottom then ARect.Bottom := MaxBottom;}
|
||||
end;
|
||||
|
||||
function TQtDeviceContext.GetLineLastPixelPos(PrevPos, NewPos: TPoint): TPoint;
|
||||
begin
|
||||
Result := NewPos;
|
||||
|
||||
if NewPos.X > PrevPos.X then
|
||||
dec(Result.X)
|
||||
else
|
||||
if NewPos.X < PrevPos.X then
|
||||
inc(Result.X);
|
||||
|
||||
if NewPos.Y > PrevPos.Y then
|
||||
dec(Result.Y)
|
||||
else
|
||||
if NewPos.Y < PrevPos.Y then
|
||||
inc(Result.Y);
|
||||
end;
|
||||
|
||||
procedure TQtDeviceContext.qDrawPlainRect(x, y, w, h: integer; AColor: PQColor = nil;
|
||||
lineWidth: Integer = 1; FillBrush: QBrushH = nil);
|
||||
begin
|
||||
@ -2000,6 +2019,25 @@ begin
|
||||
QPainter_drawPixmap(Widget, p, pm, sr);
|
||||
end;
|
||||
|
||||
procedure TQtDeviceContext.drawPolyLine(P: PPoint; NumPts: Integer);
|
||||
var
|
||||
QtPoints: PQtPoint;
|
||||
i: integer;
|
||||
LastPoint: TPoint;
|
||||
begin
|
||||
GetMem(QtPoints, NumPts * SizeOf(TQtPoint));
|
||||
for i := 0 to NumPts - 2 do
|
||||
QtPoints[i] := QtPoint(P[i].x, P[i].y);
|
||||
|
||||
LastPoint := P[NumPts - 1];
|
||||
if NumPts > 1 then
|
||||
LastPoint := GetLineLastPixelPos(P[NumPts - 2], LastPoint);
|
||||
QtPoints[NumPts - 1] := QtPoint(LastPoint.X, LastPoint.Y);
|
||||
|
||||
QPainter_drawPolyline(Widget, QtPoints, NumPts);
|
||||
FreeMem(QtPoints);
|
||||
end;
|
||||
|
||||
procedure TQtDeviceContext.eraseRect(ARect: PRect);
|
||||
begin
|
||||
QPainter_eraseRect(Widget, ARect);
|
||||
|
@ -3506,9 +3506,7 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
function TQtWidgetSet.LineTo(DC: HDC; X, Y: Integer): Boolean;
|
||||
var
|
||||
PenPos: TPoint;
|
||||
CX: Integer;
|
||||
CY: Integer;
|
||||
PenPos, LastPos: TPoint;
|
||||
begin
|
||||
{$ifdef VerboseQtWinAPI}
|
||||
WriteLn('[WinAPI LineTo]');
|
||||
@ -3519,19 +3517,10 @@ begin
|
||||
if not IsValidDC(DC) then Exit;
|
||||
|
||||
TQtDeviceContext(DC).getPenPos(@PenPos);
|
||||
|
||||
CX := X;
|
||||
CY := Y;
|
||||
|
||||
if (CX <> PenPos.X) and (CX > 0) and (CX > PenPos.X) then
|
||||
CX := CX - 1;
|
||||
|
||||
if (CY <> PenPos.Y) and (CY > 0) and (CY > PenPos.Y) then
|
||||
CY := CY - 1;
|
||||
|
||||
TQtDeviceContext(DC).drawLine(PenPos.X, PenPos.Y, CX, CY);
|
||||
|
||||
MoveToEx(DC, CX, CY, nil);
|
||||
LastPos := Point(X, Y);
|
||||
LastPos := TQtDeviceContext(DC).GetLineLastPixelPos(PenPos, LastPos);
|
||||
TQtDeviceContext(DC).drawLine(PenPos.X, PenPos.Y, LastPos.X, LastPos.Y);
|
||||
MoveToEx(DC, LastPos.X, LastPos.Y, nil);
|
||||
|
||||
Result := True;
|
||||
end;
|
||||
@ -3633,9 +3622,9 @@ begin
|
||||
{$ifdef VerboseQtWinAPI}
|
||||
WriteLn('[WinAPI Polyline] DC: ', dbghex(DC));
|
||||
{$endif}
|
||||
Result := IsValidDC(DC);
|
||||
Result := IsValidDC(DC) and (NumPts > 0);
|
||||
if Result then
|
||||
QPainter_drawPolyline(TQtDeviceContext(DC).Widget, PQtPoint(Points), NumPts);
|
||||
TQtDeviceContext(DC).DrawPolyLine(Points, NumPts);
|
||||
end;
|
||||
|
||||
function TQtWidgetSet.PostMessage(Handle: HWND; Msg: Cardinal; wParam: WParam; lParam: LParam): Boolean;
|
||||
|
Loading…
Reference in New Issue
Block a user