summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsekelsenmat <sekelsenmat@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-07-11 12:53:53 +0000
committersekelsenmat <sekelsenmat@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-07-11 12:53:53 +0000
commitfd7ac4c68a0e307440aecc609cbf2855b347e020 (patch)
tree6ee93f8eb8b2d4165eca9a5b570740e8ca91af53
parent3eed463f35acf61586e3928749fb8639280a9a65 (diff)
downloadfpGUI-fd7ac4c68a0e307440aecc609cbf2855b347e020.tar.xz
Improved double buffering and implemented partial painting
-rw-r--r--gfx/gdi/gfx_gdi.pas25
1 files changed, 20 insertions, 5 deletions
diff --git a/gfx/gdi/gfx_gdi.pas b/gfx/gdi/gfx_gdi.pas
index 76b5fa53..a691f319 100644
--- a/gfx/gdi/gfx_gdi.pas
+++ b/gfx/gdi/gfx_gdi.pas
@@ -460,7 +460,10 @@ procedure TGDICanvas.SetHandle(AHandle: PtrUInt);
begin
FHandle := AHandle;
-// ASSERT(Handle <> 0);
+ { It's possible to set the Handle to zero
+ In this case we effectively disallowing new painting
+ until a new handle is set }
+ if AHandle = 0 then Exit;
Windows.SelectObject(Handle, FDefaultFontHandle);
Windows.GetTextMetrics(Handle, @FFontMetrics);
@@ -1643,6 +1646,10 @@ var
begin
rect := FPaintStruct.rcPaint;
+ { It is necessary to create a bitmap and select it to implement
+ double buffering. If we just create a DC and don't select a bitmap,
+ there is no memory where to store the painting }
+
hdcMem := CreateCompatibleDC(FPaintStruct.hdc);
NewBitmap := Windows.CreateCompatibleBitmap(FPaintStruct.hdc, Width, Height);
@@ -1651,9 +1658,13 @@ begin
FCanvas.SetHandle(hdcMem);
+ { Execution of user paint code }
+
if Assigned(OnPaint) then OnPaint(Self);
-{ Windows.BitBlt(
+ { Flushes the result to the screen }
+
+ 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
@@ -1663,9 +1674,9 @@ begin
rect.Left, // x-coordinate of source upper-left corner
rect.Top, // y-coordinate of source upper-left corner
SRCCOPY // raster operation code
- ); }
+ );
- Windows.BitBlt(
+{ Windows.BitBlt(
FPaintStruct.hdc, // handle to destination DC
0, // x-coord of destination upper-left corner
0, // y-coord of destination upper-left corner
@@ -1675,11 +1686,15 @@ begin
0, // x-coordinate of source upper-left corner
0, // y-coordinate of source upper-left corner
SRCCOPY // raster operation code
- );
+ ); }
+
+ { Clean up }
SelectObject(hdcMem, OldBitmap);
DeleteDC(hdcMem);
DeleteObject(NewBitmap);
+
+ FCanvas.SetHandle(0);
end;
procedure TGDIWindow.EvMove;