From f58d3707004107e3c6b624f5ac1ea0492c72fff5 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Fri, 30 Apr 2010 13:27:50 +0200 Subject: Fixed imgtest demo not working under Windows. * We called the image.UpdateImage to early. We are only supposed to do it after we populated the imagedata arrow with color values. * Also reduced the resource usage, by only creating the internal image once. --- examples/gui/imgtest/bitmaptest.lpi | 5 ++--- examples/gui/imgtest/bitmaptest.lpr | 29 +++++++++++++++-------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/examples/gui/imgtest/bitmaptest.lpi b/examples/gui/imgtest/bitmaptest.lpi index af74913a..24ccafc2 100644 --- a/examples/gui/imgtest/bitmaptest.lpi +++ b/examples/gui/imgtest/bitmaptest.lpi @@ -1,15 +1,14 @@ - - + + - </General> diff --git a/examples/gui/imgtest/bitmaptest.lpr b/examples/gui/imgtest/bitmaptest.lpr index 010ff886..898b7c61 100644 --- a/examples/gui/imgtest/bitmaptest.lpr +++ b/examples/gui/imgtest/bitmaptest.lpr @@ -19,8 +19,7 @@ type TMainForm = class(TfpgForm) private img: TfpgImage; - protected - procedure HandlePaint; override; + procedure FormPaint(Sender: TObject); public constructor Create(AOwner: TComponent); override; destructor Destroy; override; @@ -29,22 +28,21 @@ type { TMainForm } -procedure TMainForm.HandlePaint; +procedure TMainForm.FormPaint(Sender: TObject); var i, j: integer; begin - Canvas.BeginDraw; // activate double buffering in time. -// inherited HandlePaint; - img.Free; - img := TfpgImage.Create; - img.AllocateImage(32, 256, 256); - img.UpdateImage; - // populate the bitmap with pretty colors :-) - for j := 0 to 255 do - for i := 0 to 255 do - PLongWord(img.ImageData)[j * 256 + i] := (i shl 16) or (j shl 8); + if not Assigned(img) then // we only need to create the image once + begin + img := TfpgImage.Create; + img.AllocateImage(32, 256, 256); + // populate the bitmap with pretty colors :-) + for j := 0 to 255 do + for i := 0 to 255 do + PLongWord(img.ImageData)[j * 256 + i] := (i shl 16) or (j shl 8); + img.UpdateImage; // now only do we allocate OS resources + end; Canvas.DrawImage(0, 0, img); - Canvas.EndDraw; end; constructor TMainForm.Create(AOwner: TComponent); @@ -52,6 +50,9 @@ begin inherited Create(AOwner); SetPosition(100, 100, 256, 256); WindowTitle := 'fpGUI Bitmap Test'; + WindowPosition := wpOneThirdDown; + Sizeable := False; + OnPaint := @FormPaint; end; destructor TMainForm.Destroy; -- cgit v1.2.3-70-g09d2