123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754 |
- {
- Free Pascal port of the OpenPTC C++ library.
- Copyright (C) 2001-2003 Nikolay Nikolov ([email protected])
- Original C++ version by Glenn Fiedler ([email protected])
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- This library 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. See the GNU
- Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- }
- Const
- {$IFDEF GO32V2}
- ConsoleTypesNumber = 4;
- {$ENDIF GO32V2}
- {$IFDEF Win32}
- ConsoleTypesNumber = 2;
- {$ENDIF Win32}
- {$IFDEF WinCE}
- ConsoleTypesNumber = 2;
- {$ENDIF WinCE}
- {$IFDEF UNIX}
- ConsoleTypesNumber = 1;
- {$ENDIF UNIX}
- ConsoleTypes : Array[0..ConsoleTypesNumber - 1] Of
- Record
- ConsoleClass : Class Of TPTCBaseConsole;
- Names : Array[1..2] Of String;
- End =
- (
- {$IFDEF GO32V2}
- (ConsoleClass : TVESAConsole; Names : ('VESA', '')),
- (ConsoleClass : TVGAConsole; Names : ('VGA', 'Fakemode')),
- (ConsoleClass : TCGAConsole; Names : ('CGA', '')),
- (ConsoleClass : TTEXTFX2Console; Names : ('TEXTFX2', 'Text'))
- {$ENDIF GO32V2}
- {$IFDEF Win32}
- (ConsoleClass : TDirectXConsole; Names : ('DirectX', '')),
- (ConsoleClass : TGDIConsole; Names : ('GDI', ''))
- {$ENDIF Win32}
- {$IFDEF WinCE}
- (ConsoleClass : TWinCEGAPIConsole; Names : ('GAPI', '')),
- (ConsoleClass : TWinCEGDIConsole; Names : ('GDI', ''))
- {$ENDIF WinCE}
- {$IFDEF UNIX}
- (ConsoleClass : TX11Console; Names : ('X11', ''))
- {$ENDIF UNIX}
- );
- Constructor TPTCConsole.Create;
- Var
- I : Integer;
- {$IFDEF UNIX}
- s : AnsiString;
- {$ENDIF UNIX}
- Begin
- Inherited Create;
- console := Nil;
- hacky_option_console_flag := False;
- FillChar(m_modes, SizeOf(m_modes), 0);
- For I := Low(m_modes) To High(m_modes) Do
- m_modes[I] := TPTCMode.Create;
- {$IFDEF UNIX}
- configure('/usr/share/ptcpas/ptcpas.conf');
- s := fpgetenv('HOME');
- If s = '' Then
- s := '/';
- If s[Length(s)] <> '/' Then
- s := s + '/';
- s := s + '.ptcpas.conf';
- configure(s);
- {$ENDIF UNIX}
- {$IFDEF Win32}
- configure('ptcpas.cfg');
- {$ENDIF Win32}
- {$IFDEF GO32V2}
- configure('ptcpas.cfg');
- {$ENDIF GO32V2}
- {$IFDEF WinCE}
- {todo: configure WinCE}
- {$ENDIF WinCE}
- End;
- Destructor TPTCConsole.Destroy;
- Var
- I : Integer;
- Begin
- close;
- console.Free;
- For I := Low(m_modes) To High(m_modes) Do
- m_modes[I].Free;
- Inherited Destroy;
- End;
- Procedure TPTCConsole.configure(Const _file : String);
- Var
- F : Text;
- S : String;
- Begin
- AssignFile(F, _file);
- {$I-}
- Reset(F);
- {$I+}
- If IOResult <> 0 Then
- Exit;
- While Not EoF(F) Do
- Begin
- {$I-}
- Readln(F, S);
- {$I+}
- If IOResult <> 0 Then
- Break;
- option(S);
- End;
- CloseFile(F);
- End;
- Function TPTCConsole.option(Const _option : String) : Boolean;
- Begin
- If _option = 'enable logging' Then
- Begin
- LOG_enabled := True;
- option := True;
- Exit;
- End;
- If _option = 'disable logging' Then
- Begin
- LOG_enabled := False;
- option := True;
- Exit;
- End;
- If Assigned(console) Then
- option := console.option(_option)
- Else
- Begin
- console := ConsoleCreate(_option);
- If Assigned(console) Then
- Begin
- hacky_option_console_flag := True;
- option := True;
- End
- Else
- option := False;
- End;
- End;
- Function TPTCConsole.modes : PPTCMode;
- Var
- _console : TPTCBaseConsole;
- index, mode : Integer;
- local : Integer;
- _modes : PPTCMode;
- tmp : TPTCMode;
- Begin
- If Assigned(console) Then
- modes := console.modes
- Else
- Begin
- _console := Nil;
- index := -1;
- mode := 0;
- Try
- Repeat
- Inc(index);
- Try
- _console := ConsoleCreate(index);
- Except
- On TPTCError Do Begin
- FreeAndNil(_console);
- Continue;
- End;
- End;
- If _console = Nil Then
- Break;
- _modes := _console.modes;
- local := 0;
- While _modes[local].valid Do
- Begin
- m_modes[mode].Assign(_modes[local]);
- Inc(local);
- Inc(mode);
- End;
- FreeAndNil(_console);
- Until False;
- Finally
- _console.Free;
- End;
- { todo: strip duplicate modes from list? }
- tmp := TPTCMode.Create;
- Try
- m_modes[mode].Assign(tmp);
- Finally
- tmp.Free;
- End;
- modes := m_modes;
- End;
- End;
- Procedure TPTCConsole.open(Const _title : String; _pages : Integer);{ Overload;}
- Var
- composite, tmp : TPTCError;
- index : Integer;
- success : Boolean;
- Begin
- If Assigned(console) Then
- Begin
- Try
- console.open(_title, _pages);
- Exit;
- Except
- On error : TPTCError Do Begin
- FreeAndNil(console);
- If hacky_option_console_flag Then
- Begin
- hacky_option_console_flag := False;
- Raise TPTCError.Create('could not open console', error);
- End;
- End;
- End;
- End;
- index := -1;
- composite := TPTCError.Create;
- success := False;
- Try
- Repeat
- Inc(index);
- Try
- console := ConsoleCreate(index);
- If console = Nil Then
- Break;
- console.open(_title, _pages);
- success := True;
- Exit;
- Except
- On error : TPTCError Do Begin
- tmp := TPTCError.Create(error.message, composite);
- Try
- composite.Assign(tmp);
- Finally
- tmp.Free;
- End;
- FreeAndNil(console);
- Continue;
- End;
- End;
- Until False;
- console := Nil;
- Raise TPTCError.Create(composite);
- Finally
- composite.Free;
- If Not success Then
- FreeAndNil(console);
- End;
- End;
- Procedure TPTCConsole.open(Const _title : String; Const _format : TPTCFormat;
- _pages : Integer);{ Overload;}
- Var
- composite, tmp : TPTCError;
- index : Integer;
- success : Boolean;
- Begin
- If Assigned(console) Then
- Begin
- Try
- console.open(_title, _format, _pages);
- Exit;
- Except
- On error : TPTCError Do Begin
- FreeAndNil(console);
- If hacky_option_console_flag Then
- Begin
- hacky_option_console_flag := False;
- Raise TPTCError.Create('could not open console', error);
- End;
- End;
- End;
- End;
- index := -1;
- composite := TPTCError.Create;
- success := False;
- Try
- Repeat
- Inc(index);
- Try
- console := ConsoleCreate(index);
- If console = Nil Then
- Break;
- console.open(_title, _format, _pages);
- success := True;
- Exit;
- Except
- On error : TPTCError Do Begin
- tmp := TPTCError.Create(error.message, composite);
- Try
- composite.Assign(tmp);
- Finally
- tmp.Free;
- End;
- FreeAndNil(console);
- Continue;
- End;
- End;
- Until False;
- console := Nil;
- Raise TPTCError.Create(composite);
- Finally
- composite.Free;
- If Not success Then
- FreeAndNil(console);
- End;
- End;
- Procedure TPTCConsole.open(Const _title : String; _width, _height : Integer;
- Const _format : TPTCFormat; _pages : Integer);{ Overload;}
- Var
- composite, tmp : TPTCError;
- index : Integer;
- success : Boolean;
- Begin
- If Assigned(console) Then
- Begin
- Try
- console.open(_title, _width, _height, _format, _pages);
- Exit;
- Except
- On error : TPTCError Do Begin
- FreeAndNil(console);
- If hacky_option_console_flag Then
- Begin
- hacky_option_console_flag := False;
- Raise TPTCError.Create('could not open console', error);
- End;
- End;
- End;
- End;
- index := -1;
- composite := TPTCError.Create;
- success := False;
- Try
- Repeat
- Inc(index);
- Try
- console := ConsoleCreate(index);
- If console = Nil Then
- Break;
- console.open(_title, _width, _height, _format, _pages);
- success := True;
- Exit;
- Except
- On error : TPTCError Do Begin
- tmp := TPTCError.Create(error.message, composite);
- Try
- composite.Assign(tmp);
- Finally
- tmp.Free;
- End;
- FreeAndNil(console);
- Continue;
- End;
- End;
- Until False;
- console := Nil;
- Raise TPTCError.Create(composite);
- Finally
- composite.Free;
- If Not success Then
- FreeAndNil(console);
- End;
- End;
- Procedure TPTCConsole.open(Const _title : String; Const _mode : TPTCMode;
- _pages : Integer);{ Overload;}
- Var
- composite, tmp : TPTCError;
- index : Integer;
- success : Boolean;
- Begin
- If Assigned(console) Then
- Begin
- Try
- console.open(_title, _mode, _pages);
- Exit;
- Except
- On error : TPTCError Do Begin
- FreeAndNil(console);
- If hacky_option_console_flag Then
- Begin
- hacky_option_console_flag := False;
- Raise TPTCError.Create('could not open console', error);
- End;
- End;
- End;
- End;
- index := -1;
- composite := TPTCError.Create;
- success := False;
- Try
- Repeat
- Inc(index);
- Try
- console := ConsoleCreate(index);
- If console = Nil Then
- Break;
- console.open(_title, _mode, _pages);
- success := True;
- Exit;
- Except
- On error : TPTCError Do Begin
- tmp := TPTCError.Create(error.message, composite);
- Try
- composite.Assign(tmp);
- Finally
- tmp.Free;
- End;
- FreeAndNil(console);
- Continue;
- End;
- End;
- Until False;
- console := Nil;
- Raise TPTCError.Create(composite);
- Finally
- composite.Free;
- If Not success Then
- FreeAndNil(console);
- End;
- End;
- Procedure TPTCConsole.close;
- Begin
- If Assigned(console) Then
- console.close;
- hacky_option_console_flag := False;
- End;
- Procedure TPTCConsole.flush;
- Begin
- check;
- console.flush;
- End;
- Procedure TPTCConsole.finish;
- Begin
- check;
- console.finish;
- End;
- Procedure TPTCConsole.update;
- Begin
- check;
- console.update;
- End;
- Procedure TPTCConsole.update(Const _area : TPTCArea);
- Begin
- check;
- console.update(_area);
- End;
- Procedure TPTCConsole.copy(Var surface : TPTCBaseSurface);
- Begin
- check;
- console.copy(surface);
- End;
- Procedure TPTCConsole.copy(Var surface : TPTCBaseSurface;
- Const source, destination : TPTCArea);
- Begin
- check;
- console.copy(surface, source, destination);
- End;
- Function TPTCConsole.lock : Pointer;
- Begin
- check;
- lock := console.lock;
- End;
- Procedure TPTCConsole.unlock;
- Begin
- check;
- console.unlock;
- End;
- Procedure TPTCConsole.load(Const pixels : Pointer;
- _width, _height, _pitch : Integer;
- Const _format : TPTCFormat;
- Const _palette : TPTCPalette);
- Begin
- check;
- console.load(pixels, _width, _height, _pitch, _format, _palette);
- End;
- Procedure TPTCConsole.load(Const pixels : Pointer;
- _width, _height, _pitch : Integer;
- Const _format : TPTCFormat;
- Const _palette : TPTCPalette;
- Const source, destination : TPTCArea);
- Begin
- check;
- console.load(pixels, _width, _height, _pitch, _format, _palette,
- source, destination);
- End;
- Procedure TPTCConsole.save(pixels : Pointer;
- _width, _height, _pitch : Integer;
- Const _format : TPTCFormat;
- Const _palette : TPTCPalette);
- Begin
- check;
- console.save(pixels, _width, _height, _pitch, _format, _palette);
- End;
- Procedure TPTCConsole.save(pixels : Pointer;
- _width, _height, _pitch : Integer;
- Const _format : TPTCFormat;
- Const _palette : TPTCPalette;
- Const source, destination : TPTCArea);
- Begin
- check;
- console.save(pixels, _width, _height, _pitch, _format, _palette,
- source, destination);
- End;
- Procedure TPTCConsole.clear;
- Begin
- check;
- console.clear;
- End;
- Procedure TPTCConsole.clear(Const color : TPTCColor);
- Begin
- check;
- console.clear(color);
- End;
- Procedure TPTCConsole.clear(Const color : TPTCColor;
- Const _area : TPTCArea);
- Begin
- check;
- console.clear(color, _area);
- End;
- Procedure TPTCConsole.palette(Const _palette : TPTCPalette);
- Begin
- check;
- console.palette(_palette);
- End;
- Function TPTCConsole.Palette : TPTCPalette;
- Begin
- check;
- Result := console.Palette;
- End;
- Procedure TPTCConsole.Clip(Const _area : TPTCArea);
- Begin
- check;
- console.clip(_area);
- End;
- Function TPTCConsole.GetWidth : Integer;
- Begin
- check;
- Result := console.GetWidth;
- End;
- Function TPTCConsole.GetHeight : Integer;
- Begin
- check;
- Result := console.GetHeight;
- End;
- Function TPTCConsole.GetPitch : Integer;
- Begin
- check;
- Result := console.GetPitch;
- End;
- Function TPTCConsole.GetPages : Integer;
- Begin
- check;
- Result := console.GetPages;
- End;
- Function TPTCConsole.GetArea : TPTCArea;
- Begin
- check;
- Result := console.GetArea;
- End;
- Function TPTCConsole.Clip : TPTCArea;
- Begin
- check;
- Result := console.Clip;
- End;
- Function TPTCConsole.GetFormat : TPTCFormat;
- Begin
- check;
- Result := console.GetFormat;
- End;
- Function TPTCConsole.GetName : String;
- Begin
- Result := '';
- If Assigned(console) Then
- Result := console.GetName
- Else
- {$IFDEF GO32V2}
- Result := 'DOS';
- {$ENDIF GO32V2}
- {$IFDEF WIN32}
- Result := 'Win32';
- {$ENDIF WIN32}
- {$IFDEF LINUX}
- Result := 'Linux';
- {$ENDIF LINUX}
- End;
- Function TPTCConsole.GetTitle : String;
- Begin
- check;
- Result := console.GetTitle;
- End;
- Function TPTCConsole.GetInformation : String;
- Begin
- check;
- Result := console.GetInformation;
- End;
- Function TPTCConsole.NextEvent(Var event : TPTCEvent; wait : Boolean; Const EventMask : TPTCEventMask) : Boolean;
- Begin
- check;
- Result := console.NextEvent(event, wait, EventMask);
- End;
- Function TPTCConsole.PeekEvent(wait : Boolean; Const EventMask : TPTCEventMask) : TPTCEvent;
- Begin
- check;
- Result := console.PeekEvent(wait, EventMask);
- End;
- Function TPTCConsole.ConsoleCreate(index : Integer) : TPTCBaseConsole;
- Begin
- Result := Nil;
- If (index >= Low(ConsoleTypes)) And (index <= High(ConsoleTypes)) Then
- Result := ConsoleTypes[index].ConsoleClass.Create;
- If Result <> Nil Then
- Result.KeyReleaseEnabled := KeyReleaseEnabled;
- End;
- Function TPTCConsole.ConsoleCreate(Const AName : String) : TPTCBaseConsole;
- Var
- I, J : Integer;
- Begin
- Result := Nil;
- If AName = '' Then
- Exit;
- For I := Low(ConsoleTypes) To High(ConsoleTypes) Do
- For J := Low(ConsoleTypes[I].Names) To High(ConsoleTypes[I].Names) Do
- If AName = ConsoleTypes[I].Names[J] Then
- Begin
- Result := ConsoleTypes[I].ConsoleClass.Create;
- If Result <> Nil Then
- Begin
- Result.KeyReleaseEnabled := KeyReleaseEnabled;
- Exit;
- End;
- End;
- End;
- Procedure TPTCConsole.check;
- Begin
- { $IFDEF DEBUG}
- If console = Nil Then
- Raise TPTCError.Create('console is not open (core)');
- { $ENDIF DEBUG}
- End;
|