summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/ptc/src/tinyptc/tinyptc.pp
blob: 1c0abaa4470fb9cc056c3afdaf650eb2cf0dbd4e (plain)
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
unit TinyPTC;

{$MODE objfpc}

interface

function ptc_open(const ATitle: string; AWidth, AHeight: Integer): Boolean;
function ptc_update(ABuffer: Pointer): Boolean;
procedure ptc_close;

implementation

uses
  SysUtils, ptc;

var
  Console: TPTCConsole = nil;
  Format: TPTCFormat = nil;
  Palette: TPTCPalette = nil;
  Width, Height: Integer;

function ptc_open(const ATitle: string; AWidth, AHeight: Integer): Boolean;
begin
  try
    if Console = nil then
      Console := TPTCConsole.Create;
    if Format = nil then
      Format := TPTCFormat.Create(32, $FF0000, $FF00, $FF);
    if Palette = nil then
      Palette := TPTCPalette.Create;
    Console.Open(ATitle, AWidth, AHeight, Format);
    Width := AWidth;
    Height := AHeight;
    Result := true;
  except
    on error: TPTCError do
      Result := false;
  end;
end;

function ptc_update(ABuffer: Pointer): Boolean;
begin
  try
    Console.Load(ABuffer, Width, Height, Width*4, Format, Palette);
    Result := true;
  except
    on error: TPTCError do
      Result := false;
  end;
end;

procedure ptc_close;
begin
  if Assigned(Console) then
    Console.Close;
  FreeAndNil(Console);
  FreeAndNil(Format);
  FreeAndNil(Palette);
end;

finalization
  ptc_close;
end.