From 315a021fbd5398c7720d0ce5d29436ca8fdc448c Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Sun, 28 Jan 2007 14:48:40 +0000 Subject: [PATCH] Small improvements on coordinate handling on Qt's StretchDraw. git-svn-id: trunk@10524 - --- lcl/interfaces/qt/qtobjects.pas | 25 +++++++++++++++++++++++++ lcl/interfaces/qt/qtwinapi.inc | 16 ++++++++++------ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/lcl/interfaces/qt/qtobjects.pas b/lcl/interfaces/qt/qtobjects.pas index e32f768a2a..022823fed4 100644 --- a/lcl/interfaces/qt/qtobjects.pas +++ b/lcl/interfaces/qt/qtobjects.pas @@ -203,6 +203,7 @@ type function RestoreDCData(DCData: PQtDCData): boolean; procedure DebugClipRect(const msg: string); procedure setImage(AImage: TQtImage); + procedure CorrectCoordinates(var ARect: TRect); public { Qt functions } procedure drawPoint(x1: Integer; y1: Integer); @@ -842,6 +843,30 @@ begin Widget := QPainter_Create(vImage); end; +{------------------------------------------------------------------------------ + Function: TQtDeviceContext.CorrectCoordinates + Params: None + Returns: Nothing + + If you draw an image with negative coordinates + (for example x: -50 y: -50 w: 100 h: 100), the result is not well + defined in Qt, and could well be: (x: 0 y: 0 w: 100 h: 100) + This method corrects the coordinates, cutting the result, so we draw: + (x: 0 y: 0 w: 50 h: 50) + ------------------------------------------------------------------------------} +procedure TQtDeviceContext.CorrectCoordinates(var ARect: TRect); +var + Buffer: Integer; +begin + if ARect.Left < 0 then ARect.Left := 0; + + if ARect.Top < 0 then ARect.Top := 0; + +{ if ARect.Right > MaxRight then ARect.Right := MaxRight; + + if ARect.Bottom > MaxBottom then ARect.Bottom := MaxBottom;} +end; + {------------------------------------------------------------------------------ Function: TQtDeviceContext.CreateDCData Params: None diff --git a/lcl/interfaces/qt/qtwinapi.inc b/lcl/interfaces/qt/qtwinapi.inc index 7238cdec32..57896d1a4b 100644 --- a/lcl/interfaces/qt/qtwinapi.inc +++ b/lcl/interfaces/qt/qtwinapi.inc @@ -2641,12 +2641,6 @@ var SrcRect, DstRect: TRect; Image: QImageH; begin - DstRect := Bounds(X, Y, Width, Height); - - SrcRect := Bounds(XSrc, YSrc, SrcWidth, SrcHeight); - - Image := TQtDeviceContext(SrcDC).vImage; - {$ifdef VerboseQtWinAPI} WriteLn('[WinAPI StretchMaskBlt]', ' DestDC:', dbghex(DestDC), @@ -2658,6 +2652,16 @@ begin ' WSrc:', dbgs(SrcWidth), ' HSrc:', dbgs(SrcHeight)); {$endif} + DstRect := Bounds(X, Y, Width, Height); + + SrcRect := Bounds(XSrc, YSrc, SrcWidth, SrcHeight); + + Image := TQtDeviceContext(SrcDC).vImage; + + TQtDeviceContext(DestDC).CorrectCoordinates(DstRect); + + TQtDeviceContext(DestDC).CorrectCoordinates(SrcRect); + TQtDeviceContext(DestDC).drawImage(@DstRect, Image, @SrcRect); Result := True;