diff options
author | sekelsenmat <sekelsenmat@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-07-11 12:50:12 +0000 |
---|---|---|
committer | sekelsenmat <sekelsenmat@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-07-11 12:50:12 +0000 |
commit | 3eed463f35acf61586e3928749fb8639280a9a65 (patch) | |
tree | c1a2bd5e6968de66a40d5bde457a32db9781adea | |
parent | 206939d343826dfbe7e39189dbcbfc61840aa6fe (diff) | |
download | fpGUI-3eed463f35acf61586e3928749fb8639280a9a65.tar.xz |
Implemented double buffering for Gfx
-rw-r--r-- | examples/gfx/subwindow/subwindow.pas | 8 | ||||
-rw-r--r-- | gfx/gdi/gfx_gdi.pas | 78 | ||||
-rw-r--r-- | gfx/gfxbase.pas | 3 |
3 files changed, 72 insertions, 17 deletions
diff --git a/examples/gfx/subwindow/subwindow.pas b/examples/gfx/subwindow/subwindow.pas index d7d46640..c4b6527e 100644 --- a/examples/gfx/subwindow/subwindow.pas +++ b/examples/gfx/subwindow/subwindow.pas @@ -31,7 +31,7 @@ type TBoxWindow = class(TFWindow) public constructor Create(AParent: TFCustomWindow); - procedure Paint(Sender: TObject; const Rect: TRect); + procedure Paint(Sender: TObject); procedure MouseReleased(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint); end; @@ -41,7 +41,7 @@ type public ABox: TBoxWindow; constructor Create; - procedure Paint(Sender: TObject; const Rect: TRect); + procedure Paint(Sender: TObject); procedure MouseReleased(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint); end; @@ -62,7 +62,7 @@ begin WriteLn('Mouse released on child window'); end; -procedure TBoxWindow.Paint(Sender: TObject; const Rect: TRect); +procedure TBoxWindow.Paint(Sender: TObject); var r: TRect; tw: integer; @@ -94,7 +94,7 @@ begin ABox.Show; end; -procedure TMainWindow.Paint(Sender: TObject; const Rect: TRect); +procedure TMainWindow.Paint(Sender: TObject); var r: TRect; tw: integer; diff --git a/gfx/gdi/gfx_gdi.pas b/gfx/gdi/gfx_gdi.pas index eeb1c34d..76b5fa53 100644 --- a/gfx/gdi/gfx_gdi.pas +++ b/gfx/gdi/gfx_gdi.pas @@ -101,8 +101,9 @@ type procedure DoMaskedCopyRect(ASource, AMask: TFCustomCanvas; const ASourceRect: TRect; const AMaskPos, ADestPos: TPoint); override; procedure DoDrawImageRect(AImage: TFCustomBitmap; ASourceRect: TRect; const ADestPos: TPoint); override; public - constructor Create(AHandle: HDC); + constructor Create; override; destructor Destroy; override; + procedure SetHandle(AHandle: PtrUInt); override; function MapColor(const AColor: TGfxColor): TGfxPixel; override; function FontCellHeight: Integer; override; function TextExtent(const AText: String): TSize; override; @@ -173,6 +174,8 @@ type { TGDIWindow } TGDIWindow = class(TFCustomWindow) + private + FPaintStruct: TPaintStruct; protected FHandle: PtrUInt; WindowClass: TWndClass; @@ -431,19 +434,13 @@ end; { TGDICanvas } -constructor TGDICanvas.Create(AHandle: HDC); +constructor TGDICanvas.Create; begin inherited Create; - FHandle := AHandle; - ASSERT(Handle <> 0); FDefaultFontHandle := Windows.GetStockObject(DEFAULT_GUI_FONT); FCurFontHandle := FDefaultFontHandle; - Windows.SelectObject(Handle, FDefaultFontHandle); - Windows.GetTextMetrics(Handle, @FFontMetrics); - Windows.SetBkMode(Handle, TRANSPARENT); end; - destructor TGDICanvas.Destroy; begin if FBrush <> 0 then @@ -459,6 +456,16 @@ begin inherited Destroy; end; +procedure TGDICanvas.SetHandle(AHandle: PtrUInt); +begin + FHandle := AHandle; + +// ASSERT(Handle <> 0); + + Windows.SelectObject(Handle, FDefaultFontHandle); + Windows.GetTextMetrics(Handle, @FFontMetrics); + Windows.SetBkMode(Handle, TRANSPARENT); +end; procedure TGDICanvas.SaveState; var @@ -874,7 +881,8 @@ end; constructor TGDIWindowCanvas.Create(AWnd: HWND); begin FWnd := AWnd; - inherited Create(Windows.GetDC(FWnd)); + inherited Create(); + SetHandle(Windows.GetDC(FWnd)); end; @@ -892,7 +900,8 @@ constructor TGDIBitmapCanvas.Create(ABitmap: HBITMAP; AWidth, AHeight: Integer); begin ASSERT(ABitmap <> 0); FBitmap := ABitmap; - inherited Create(Windows.CreateCompatibleDC(0)); + inherited Create(); + SetHandle(Windows.CreateCompatibleDC(0)); FWidth := AWidth; FHeight := AHeight; FOldBitmap := Windows.SelectObject(Handle, Bitmap); @@ -1147,6 +1156,7 @@ begin WM_Paint: begin Windows.BeginPaint(Window.Handle, @PaintStruct); + Window.FPaintStruct := PaintStruct; Window.EvPaint(); Windows.EndPaint(Window.Handle, @PaintStruct); end; @@ -1187,7 +1197,7 @@ begin Windows.GetClientRect(Window.Handle, @r); Window.FClientWidth := LoWord(lParam); Window.FClientHeight := HiWord(lParam); - TGDICanvas(Window.Canvas).Resized(Window.FWidth, Window.FHeight); +// TGDICanvas(Window.Canvas).Resized(Window.FWidth, Window.FHeight); Window.EvResize(); end; @@ -1379,7 +1389,9 @@ begin MainInstance, // handle to application instance Self); // window-creation data - FCanvas := TGDIWindowCanvas.Create(Handle); + { Creates the Canvas } + + FCanvas := TGDICanvas.Create(); end; @@ -1624,8 +1636,50 @@ begin end; procedure TGDIWindow.EvPaint; +var + rect: TRect; + OldBitmap, NewBitmap: HBITMAP; + hdcMem: HDC; begin + rect := FPaintStruct.rcPaint; + + hdcMem := CreateCompatibleDC(FPaintStruct.hdc); + + NewBitmap := Windows.CreateCompatibleBitmap(FPaintStruct.hdc, Width, Height); + + OldBitmap := HBITMAP(SelectObject(hdcMem, NewBitmap)); + + FCanvas.SetHandle(hdcMem); + if Assigned(OnPaint) then OnPaint(Self); + +{ Windows.BitBlt( + FPaintStruct.hdc, // handle to destination DC + rect.Left, // x-coord of destination upper-left corner + rect.Top, // y-coord of destination upper-left corner + rect.Left + rect.Right, // width of destination rectangle + rect.Top + rect.Bottom, // height of destination rectangle + FCanvas.Handle, // handle to source DC + rect.Left, // x-coordinate of source upper-left corner + rect.Top, // y-coordinate of source upper-left corner + SRCCOPY // raster operation code + ); } + + Windows.BitBlt( + FPaintStruct.hdc, // handle to destination DC + 0, // x-coord of destination upper-left corner + 0, // y-coord of destination upper-left corner + Width, // width of destination rectangle + Height, // height of destination rectangle + FCanvas.Handle, // handle to source DC + 0, // x-coordinate of source upper-left corner + 0, // y-coordinate of source upper-left corner + SRCCOPY // raster operation code + ); + + SelectObject(hdcMem, OldBitmap); + DeleteDC(hdcMem); + DeleteObject(NewBitmap); end; procedure TGDIWindow.EvMove; diff --git a/gfx/gfxbase.pas b/gfx/gfxbase.pas index 834dd0b6..45608a54 100644 --- a/gfx/gfxbase.pas +++ b/gfx/gfxbase.pas @@ -321,7 +321,8 @@ type procedure DoMaskedCopyRect(ASource, AMask: TFCustomCanvas; const ASourceRect: TRect; const AMaskPos, ADestPos: TPoint); virtual; abstract; procedure DoDrawImageRect(AImage: TFCustomBitmap; ASourceRect: TRect; const ADestPos: TPoint); virtual; abstract; public - constructor Create; + constructor Create; virtual; + procedure SetHandle(AHandle: PtrUInt); virtual; abstract; // Transformations function Transform(APoint: TPoint): TPoint; function Transform(ARect: TRect): TRect; |