diff options
Diffstat (limited to 'examples/corelib/helloworld')
-rw-r--r-- | examples/corelib/helloworld/helloworld.pas | 53 |
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; |