1{
2Ported to FPC by Nikolay Nikolov (nickysn@users.sourceforge.net)
3}
4
5{
6 Clear example for OpenPTC 1.0 C++ implementation
7 Copyright (c) Glenn Fiedler (ptc@gaffer.org)
8 This source code is in the public domain
9}
10
11program ClearExample;
12
13{$MODE objfpc}
14
15uses
16  SysUtils, ptc;
17
18var
19  console: IPTCConsole;
20  format: IPTCFormat;
21  surface: IPTCSurface;
22  width, height: Integer;
23  x, y: Integer;
24  size: Integer;
25  area: IPTCArea;
26  color: IPTCColor;
27begin
28  try
29    { create console }
30    console := TPTCConsoleFactory.CreateNew;
31
32    { create format }
33    format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
34
35    { open the console }
36    console.open('Clear example', format);
37
38    { create surface matching console dimensions }
39    surface := TPTCSurfaceFactory.CreateNew(console.width, console.height, format);
40
41    { loop until a key is pressed }
42    while not console.KeyPressed do
43    begin
44      { get surface dimensions }
45      width := surface.width;
46      height := surface.height;
47
48      { get random position }
49      x := Random(width);
50      y := Random(height);
51
52      { get random area size }
53      size := Random(width div 8);
54
55      { setup clear area }
56      area := TPTCAreaFactory.CreateNew(x-size, y-size, x+size, y+size);
57
58      { create random color }
59      color := TPTCColorFactory.CreateNew(Random, Random, Random);
60
61      { clear surface area with color }
62      surface.clear(color, area);
63
64      { copy to console }
65      surface.copy(console);
66
67      { update console }
68      console.update;
69    end;
70    if Assigned(console) then
71      console.close;
72  except
73    on error: TPTCError do
74      { report error }
75      error.report;
76  end;
77end.
78