1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
{
fpGUI - Free Pascal GUI Library
HelloWorld - GFX Hello World application
Copyright (C) 2000 - 2006 See the file AUTHORS.txt, included in this
distribution, for details of the copyright.
See the file COPYING.modifiedLGPL, included in this distribution,
for details about redistributing fpGUI.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
}
program HelloWorld;
{$ifdef fpc}
{$mode objfpc}{$H+}
{$endif}
uses
Classes,
fpGFX, GFXBase;
const
HelloWorldString: String = 'Hello, world!';
type
{ TMainWindow }
TMainWindow = class(TFWindow)
public
Font: TFCustomFont;
TextSize: TSize;
procedure Paint(Sender: TObject);
constructor Create;
end;
procedure TMainWindow.Paint(Sender: TObject);
var
Color: TGfxColor;
r: TRect;
i: Integer;
begin
Color.Red := 0;
Color.Green := 0;
Color.Alpha := 0;
r.Left := 0;
r.Right := Width;
for i := 0 to Height - 1 do
begin
Color.Blue := $ffff - (i * $ffff) div ClientHeight;
Canvas.SetColor(Color);
r.Top := i;
r.Bottom := i + 1;
Canvas.FillRect(r);
end;
Canvas.SetColor(colBlack);
Canvas.SetFont(Font);
Canvas.TextOut(Point((ClientWidth - TextSize.cx) div 2 + 1,
(ClientHeight - TextSize.cy) div 2 + 1), HelloWorldString);
Canvas.SetColor(colWhite);
Canvas.TextOut(Point((ClientWidth - TextSize.cx) div 2 - 1,
(ClientHeight - TextSize.cy) div 2 - 1), HelloWorldString);
end;
constructor TMainWindow.Create;
begin
inherited Create(nil, [woWindow]);
{ Possible font classes:
fcSerif, fcSansSerif, fcTypewriter, fcDingbats }
Font := TFFont.Create('-*-'
+ TFFont.GetDefaultFontName(fcSerif)
+ '-*-r-*-*-34-*-*-*-*-*-*-*');
Title := 'fpGFX Hello World example';
OnPaint := @Paint;
Canvas.SetFont(Font);
TextSize.cx := Canvas.TextWidth(HelloWorldString);
TextSize.cy := Canvas.FontCellHeight;
SetClientSize(Size((TextSize.cx * 3) div 2, TextSize.cy * 2));
SetMinMaxClientSize(TextSize, Size(0, 0));
end;
var
MainWindow: TMainWindow;
begin
GFApplication.Initialize;
MainWindow := TMainWindow.Create;
GFApplication.AddWindow(MainWindow);
MainWindow.Show;
GFApplication.Run;
end.
|