mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-07 07:42:11 +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 DebugClipRect(const msg: string);
|
||||||
procedure setImage(AImage: TQtImage);
|
procedure setImage(AImage: TQtImage);
|
||||||
procedure CorrectCoordinates(var ARect: TRect);
|
procedure CorrectCoordinates(var ARect: TRect);
|
||||||
|
function GetLineLastPixelPos(PrevPos, NewPos: TPoint): TPoint;
|
||||||
public
|
public
|
||||||
{ Qt functions }
|
{ Qt functions }
|
||||||
|
|
||||||
@ -310,6 +311,7 @@ type
|
|||||||
procedure drawLine(x1: Integer; y1: Integer; x2: Integer; y2: Integer);
|
procedure drawLine(x1: Integer; y1: Integer; x2: Integer; y2: Integer);
|
||||||
procedure drawEllipse(x: Integer; y: Integer; w: Integer; h: Integer);
|
procedure drawEllipse(x: Integer; y: Integer; w: Integer; h: Integer);
|
||||||
procedure drawPixmap(p: PQtPoint; pm: QPixmapH; sr: PRect);
|
procedure drawPixmap(p: PQtPoint; pm: QPixmapH; sr: PRect);
|
||||||
|
procedure drawPolyLine(P: PPoint; NumPts: Integer);
|
||||||
procedure eraseRect(ARect: PRect);
|
procedure eraseRect(ARect: PRect);
|
||||||
procedure fillRect(ARect: PRect; ABrush: QBrushH); overload;
|
procedure fillRect(ARect: PRect; ABrush: QBrushH); overload;
|
||||||
procedure fillRect(x, y, w, h: Integer; 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;}
|
if ARect.Bottom > MaxBottom then ARect.Bottom := MaxBottom;}
|
||||||
end;
|
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;
|
procedure TQtDeviceContext.qDrawPlainRect(x, y, w, h: integer; AColor: PQColor = nil;
|
||||||
lineWidth: Integer = 1; FillBrush: QBrushH = nil);
|
lineWidth: Integer = 1; FillBrush: QBrushH = nil);
|
||||||
begin
|
begin
|
||||||
@ -2000,6 +2019,25 @@ begin
|
|||||||
QPainter_drawPixmap(Widget, p, pm, sr);
|
QPainter_drawPixmap(Widget, p, pm, sr);
|
||||||
end;
|
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);
|
procedure TQtDeviceContext.eraseRect(ARect: PRect);
|
||||||
begin
|
begin
|
||||||
QPainter_eraseRect(Widget, ARect);
|
QPainter_eraseRect(Widget, ARect);
|
||||||
|
@ -3506,9 +3506,7 @@ end;
|
|||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
function TQtWidgetSet.LineTo(DC: HDC; X, Y: Integer): Boolean;
|
function TQtWidgetSet.LineTo(DC: HDC; X, Y: Integer): Boolean;
|
||||||
var
|
var
|
||||||
PenPos: TPoint;
|
PenPos, LastPos: TPoint;
|
||||||
CX: Integer;
|
|
||||||
CY: Integer;
|
|
||||||
begin
|
begin
|
||||||
{$ifdef VerboseQtWinAPI}
|
{$ifdef VerboseQtWinAPI}
|
||||||
WriteLn('[WinAPI LineTo]');
|
WriteLn('[WinAPI LineTo]');
|
||||||
@ -3519,19 +3517,10 @@ begin
|
|||||||
if not IsValidDC(DC) then Exit;
|
if not IsValidDC(DC) then Exit;
|
||||||
|
|
||||||
TQtDeviceContext(DC).getPenPos(@PenPos);
|
TQtDeviceContext(DC).getPenPos(@PenPos);
|
||||||
|
LastPos := Point(X, Y);
|
||||||
CX := X;
|
LastPos := TQtDeviceContext(DC).GetLineLastPixelPos(PenPos, LastPos);
|
||||||
CY := Y;
|
TQtDeviceContext(DC).drawLine(PenPos.X, PenPos.Y, LastPos.X, LastPos.Y);
|
||||||
|
MoveToEx(DC, LastPos.X, LastPos.Y, nil);
|
||||||
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);
|
|
||||||
|
|
||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
@ -3633,9 +3622,9 @@ begin
|
|||||||
{$ifdef VerboseQtWinAPI}
|
{$ifdef VerboseQtWinAPI}
|
||||||
WriteLn('[WinAPI Polyline] DC: ', dbghex(DC));
|
WriteLn('[WinAPI Polyline] DC: ', dbghex(DC));
|
||||||
{$endif}
|
{$endif}
|
||||||
Result := IsValidDC(DC);
|
Result := IsValidDC(DC) and (NumPts > 0);
|
||||||
if Result then
|
if Result then
|
||||||
QPainter_drawPolyline(TQtDeviceContext(DC).Widget, PQtPoint(Points), NumPts);
|
TQtDeviceContext(DC).DrawPolyLine(Points, NumPts);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TQtWidgetSet.PostMessage(Handle: HWND; Msg: Cardinal; wParam: WParam; lParam: LParam): Boolean;
|
function TQtWidgetSet.PostMessage(Handle: HWND; Msg: Cardinal; wParam: WParam; lParam: LParam): Boolean;
|
||||||
|
Loading…
Reference in New Issue
Block a user