summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2010-03-17 14:13:26 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2010-03-18 16:13:54 +0200
commit05322ebae6280a855330f21d57bbfc7ac0001222 (patch)
tree54baa3418641672a087d01f36ffd0da49ebab072 /examples
parent063efc0e5831be63f4a1a2cfcf52c0bb634b08c4 (diff)
downloadfpGUI-05322ebae6280a855330f21d57bbfc7ac0001222.tar.xz
helloworld: Fixed memory leaks and new painting method
* This demo actually had 3 memory leaks which are now fixed. * I introduced new painting routines using GradientFill instead [now this works correctly on WinCE devices too] * Added an option for exiting the application cleanly.
Diffstat (limited to 'examples')
-rw-r--r--examples/corelib/helloworld/helloworld.pas53
1 files changed, 34 insertions, 19 deletions
diff --git a/examples/corelib/helloworld/helloworld.pas b/examples/corelib/helloworld/helloworld.pas
index e6ba7440..d7178c9d 100644
--- a/examples/corelib/helloworld/helloworld.pas
+++ b/examples/corelib/helloworld/helloworld.pas
@@ -26,6 +26,7 @@ uses
const
HelloWorldString: String = 'Hello, world!';
+ ClickToClose: String = 'click to close';
type
@@ -35,6 +36,7 @@ type
procedure MsgPaint(var msg: TfpgMessageRec); message FPGM_PAINT;
procedure MsgClose(var msg: TfpgMessageRec); message FPGM_CLOSE;
procedure MsgResize(var msg: TfpgMessageRec); message FPGM_RESIZE;
+ procedure MsgMouseUp(var msg: TfpgMessageRec); message FPGM_MOUSEUP;
public
constructor Create(AOwner: TComponent); override;
procedure Show;
@@ -55,36 +57,43 @@ begin
DoSetWindowVisible(True);
// We can't set a title if we don't have a window handle. So we do that here
// and not in the constructor.
- SetWindowTitle('fpGFX Hello World');
+ SetWindowTitle('fpGUI Hello World');
end;
procedure TMainWindow.MsgPaint(var msg: TfpgMessageRec);
var
- Color: TfpgColor;
r: TfpgRect;
i: Integer;
+ fnt: TfpgFont;
begin
Canvas.BeginDraw; // begin double buffering
- Color := 0;
- r.SetRect(0, 0, Width, 1);
- for i := 0 to FHeight-1 do
- begin
- Color := $ff - (i * $ff) div FHeight; // shades of Blue
- Canvas.SetColor(Color);
- r.Top := i;
- Canvas.DrawRectangle(r);
- end;
+ r.SetRect(0, 0, Width, Height);
+ Canvas.GradientFill(r, clBlue, clBlack, gdVertical);
+
+ fnt := fpgGetFont('Arial-20');
+ try
+ Canvas.Font := fnt;
- Canvas.Font := fpgGetFont('Arial-30');
+ Canvas.SetTextColor(clBlack);
+ Canvas.DrawString((Width - Canvas.Font.TextWidth(HelloWorldString)) div 2 + 1,
+ (Height - Canvas.Font.Height) div 2 + 1, HelloWorldString);
- Canvas.SetTextColor(clBlack);
- Canvas.DrawString((Width - Canvas.Font.TextWidth(HelloWorldString)) div 2 + 1,
- (Height - Canvas.Font.Height) div 2 + 1, HelloWorldString);
+ Canvas.SetTextColor(clWhite);
+ Canvas.DrawString((Width - Canvas.Font.TextWidth(HelloWorldString)) div 2 - 1,
+ (Height - Canvas.Font.Height) div 2 - 1, HelloWorldString);
+ finally
+ fnt.Free;
+ end;
- Canvas.SetTextColor(clWhite);
- Canvas.DrawString((Width - Canvas.Font.TextWidth(HelloWorldString)) div 2 - 1,
- (Height - Canvas.Font.Height) div 2 - 1, HelloWorldString);
+ fnt := fpgGetFont('Arial-10');
+ try
+ Canvas.Font := fnt;
+ Canvas.DrawString((Width - Canvas.Font.TextWidth(ClickToClose)) div 2 - 1,
+ Height - (Canvas.Font.Height*2), ClickToClose);
+ finally
+ fnt.Free;
+ end;
Canvas.EndDraw;
end;
@@ -92,7 +101,7 @@ end;
procedure TMainWindow.MsgClose(var msg: TfpgMessageRec);
begin
ReleaseWindowHandle;
- Halt(0);
+ fpgApplication.Terminate;
end;
procedure TMainWindow.MsgResize(var msg: TfpgMessageRec);
@@ -101,6 +110,11 @@ begin
FHeight := msg.Params.rect.Height;
end;
+procedure TMainWindow.MsgMouseUp(var msg: TfpgMessageRec);
+begin
+ MsgClose(msg);
+end;
+
var
@@ -108,6 +122,7 @@ var
begin
fpgApplication.Initialize;
MainWindow := TMainWindow.Create(nil);
+ fpgApplication.MainForm := MainWindow;
MainWindow.Show;
fpgApplication.Run;
MainWindow.Free;