瀏覽代碼

* Updated PTCPas to version 0.99.12

git-svn-id: trunk@19633 -
nickysn 13 年之前
父節點
當前提交
6a0078e38a
共有 100 個文件被更改,包括 3048 次插入3449 次删除
  1. 2 0
      .gitattributes
  2. 40 45
      packages/graph/src/ptcgraph/ptccrt.pp
  3. 12 23
      packages/graph/src/ptcgraph/ptcgraph.pp
  4. 10 0
      packages/ptc/docs/CHANGES.txt
  5. 3 3
      packages/ptc/docs/INSTALL.txt
  6. 29 0
      packages/ptc/docs/INTF-CHANGES-0.99.12.txt
  7. 77 0
      packages/ptc/docs/INTF-CHANGES-FAQ-0.99.12.txt
  8. 41 25
      packages/ptc/docs/INTRO.txt
  9. 8 8
      packages/ptc/docs/README.txt
  10. 10 13
      packages/ptc/examples/area.pp
  11. 11 15
      packages/ptc/examples/buffer.pp
  12. 20 27
      packages/ptc/examples/clear.pp
  13. 10 19
      packages/ptc/examples/clip.pp
  14. 5 5
      packages/ptc/examples/con_info.pp
  15. 12 13
      packages/ptc/examples/console.pp
  16. 15 18
      packages/ptc/examples/fire.pp
  17. 16 22
      packages/ptc/examples/flower.pp
  18. 8 10
      packages/ptc/examples/hicolor.pp
  19. 13 21
      packages/ptc/examples/image.pp
  20. 13 27
      packages/ptc/examples/keyboard.pp
  21. 15 30
      packages/ptc/examples/keyboard2.pp
  22. 11 16
      packages/ptc/examples/land.pp
  23. 12 15
      packages/ptc/examples/lights.pp
  24. 21 31
      packages/ptc/examples/modes.pp
  25. 9 11
      packages/ptc/examples/mojo.pp
  26. 16 19
      packages/ptc/examples/mouse.pp
  27. 13 16
      packages/ptc/examples/palette.pp
  28. 9 11
      packages/ptc/examples/pixel.pp
  29. 8 10
      packages/ptc/examples/random.pp
  30. 19 29
      packages/ptc/examples/save.pp
  31. 29 49
      packages/ptc/examples/stretch.pp
  32. 12 15
      packages/ptc/examples/texwarp.pp
  33. 10 13
      packages/ptc/examples/timer.pp
  34. 8 10
      packages/ptc/examples/tunnel.pp
  35. 20 22
      packages/ptc/examples/tunnel3d.pp
  36. 19 13
      packages/ptc/src/core/aread.inc
  37. 59 15
      packages/ptc/src/core/areai.inc
  38. 27 27
      packages/ptc/src/core/baseconsoled.inc
  39. 120 32
      packages/ptc/src/core/baseconsolei.inc
  40. 33 34
      packages/ptc/src/core/basesurfaced.inc
  41. 3 3
      packages/ptc/src/core/cleard.inc
  42. 4 6
      packages/ptc/src/core/cleari.inc
  43. 5 4
      packages/ptc/src/core/clipperd.inc
  44. 110 121
      packages/ptc/src/core/clipperi.inc
  45. 25 19
      packages/ptc/src/core/colord.inc
  46. 88 27
      packages/ptc/src/core/colori.inc
  47. 2 74
      packages/ptc/src/core/consoled.inc
  48. 140 74
      packages/ptc/src/core/consolei.inc
  49. 2 2
      packages/ptc/src/core/copyd.inc
  50. 7 7
      packages/ptc/src/core/copyi.inc
  51. 4 11
      packages/ptc/src/core/eventd.inc
  52. 20 8
      packages/ptc/src/core/eventi.inc
  53. 28 19
      packages/ptc/src/core/formatd.inc
  54. 95 5
      packages/ptc/src/core/formati.inc
  55. 32 31
      packages/ptc/src/core/keyeventd.inc
  56. 121 3
      packages/ptc/src/core/keyeventi.inc
  57. 1 1
      packages/ptc/src/core/log.inc
  58. 21 17
      packages/ptc/src/core/moded.inc
  59. 67 18
      packages/ptc/src/core/modei.inc
  60. 30 23
      packages/ptc/src/core/mouseeventd.inc
  61. 81 1
      packages/ptc/src/core/mouseeventi.inc
  62. 9 11
      packages/ptc/src/core/paletted.inc
  63. 46 4
      packages/ptc/src/core/palettei.inc
  64. 2 53
      packages/ptc/src/core/surfaced.inc
  65. 129 111
      packages/ptc/src/core/surfacei.inc
  66. 7 19
      packages/ptc/src/core/timerd.inc
  67. 48 5
      packages/ptc/src/core/timeri.inc
  68. 36 36
      packages/ptc/src/dos/cga/cgaconsoled.inc
  69. 52 199
      packages/ptc/src/dos/cga/cgaconsolei.inc
  70. 2 2
      packages/ptc/src/dos/textfx2/textfx2.pp
  71. 46 46
      packages/ptc/src/dos/textfx2/textfx2consoled.inc
  72. 138 285
      packages/ptc/src/dos/textfx2/textfx2consolei.inc
  73. 38 38
      packages/ptc/src/dos/vesa/vesaconsoled.inc
  74. 95 201
      packages/ptc/src/dos/vesa/vesaconsolei.inc
  75. 38 38
      packages/ptc/src/dos/vga/vgaconsoled.inc
  76. 60 234
      packages/ptc/src/dos/vga/vgaconsolei.inc
  77. 1 1
      packages/ptc/src/ptc.pp
  78. 9 8
      packages/ptc/src/ptcwrapper/ptceventqueue.pp
  79. 28 35
      packages/ptc/src/ptcwrapper/ptcwrapper.pp
  80. 2 5
      packages/ptc/src/win32/base/kbd.inc
  81. 16 0
      packages/ptc/src/win32/base/window.inc
  82. 40 40
      packages/ptc/src/win32/directx/directxconsoled.inc
  83. 81 151
      packages/ptc/src/win32/directx/directxconsolei.inc
  84. 89 143
      packages/ptc/src/win32/directx/display.inc
  85. 10 10
      packages/ptc/src/win32/directx/displayd.inc
  86. 1 1
      packages/ptc/src/win32/directx/hook.inc
  87. 30 83
      packages/ptc/src/win32/directx/primary.inc
  88. 12 12
      packages/ptc/src/win32/directx/primaryd.inc
  89. 1 1
      packages/ptc/src/win32/directx/translate.inc
  90. 34 34
      packages/ptc/src/win32/gdi/gdiconsoled.inc
  91. 39 76
      packages/ptc/src/win32/gdi/gdiconsolei.inc
  92. 2 2
      packages/ptc/src/win32/gdi/win32dibd.inc
  93. 0 1
      packages/ptc/src/win32/gdi/win32dibi.inc
  94. 38 38
      packages/ptc/src/wince/gapi/wincegapiconsoled.inc
  95. 41 130
      packages/ptc/src/wince/gapi/wincegapiconsolei.inc
  96. 3 3
      packages/ptc/src/wince/gdi/wincebitmapinfod.inc
  97. 0 3
      packages/ptc/src/wince/gdi/wincebitmapinfoi.inc
  98. 38 38
      packages/ptc/src/wince/gdi/wincegdiconsoled.inc
  99. 46 136
      packages/ptc/src/wince/gdi/wincegdiconsolei.inc
  100. 30 30
      packages/ptc/src/x11/x11consoled.inc

+ 2 - 0
.gitattributes

@@ -5589,6 +5589,8 @@ packages/ptc/Makefile.fpc svneol=native#text/plain
 packages/ptc/docs/AUTHORS.txt svneol=native#text/plain
 packages/ptc/docs/AUTHORS.txt svneol=native#text/plain
 packages/ptc/docs/CHANGES.txt svneol=native#text/plain
 packages/ptc/docs/CHANGES.txt svneol=native#text/plain
 packages/ptc/docs/INSTALL.txt svneol=native#text/plain
 packages/ptc/docs/INSTALL.txt svneol=native#text/plain
+packages/ptc/docs/INTF-CHANGES-0.99.12.txt svneol=native#text/plain
+packages/ptc/docs/INTF-CHANGES-FAQ-0.99.12.txt svneol=native#text/plain
 packages/ptc/docs/INTRO.txt svneol=native#text/plain
 packages/ptc/docs/INTRO.txt svneol=native#text/plain
 packages/ptc/docs/README.txt svneol=native#text/plain
 packages/ptc/docs/README.txt svneol=native#text/plain
 packages/ptc/docs/TODO.txt svneol=native#text/plain
 packages/ptc/docs/TODO.txt svneol=native#text/plain

+ 40 - 45
packages/graph/src/ptcgraph/ptccrt.pp

@@ -110,56 +110,51 @@ end;
 
 
 procedure GetKeyEvents;
 procedure GetKeyEvents;
 var
 var
-  ev: TPTCEvent;
-  KeyEv: TPTCKeyEvent;
+  ev: IPTCEvent;
+  KeyEv: IPTCKeyEvent;
 begin
 begin
-  ev := nil;
-  try
-    repeat
-      PTCWrapperObject.NextEvent(ev, False, [PTCKeyEvent]);
-      if ev <> nil then
+  repeat
+    PTCWrapperObject.NextEvent(ev, False, [PTCKeyEvent]);
+    if ev <> nil then
+    begin
+      KeyEv := ev as IPTCKeyEvent;
+      if KeyEv.Press then
       begin
       begin
-        KeyEv := TPTCKeyEvent(ev);
-        if KeyEv.Press then
-        begin
-          case KeyEv.Code of
-            PTCKEY_BACKSPACE:
-              if KeyEv.Control then
-                KeyBufAdd(#127)
-              else
-                KeyBufAdd(#8);
-            PTCKEY_ENTER:  KeyBufAdd(#13);
-            PTCKEY_ESCAPE: KeyBufAdd(#27);
-            PTCKEY_INSERT: KeyBufAdd(#0#82);
-            PTCKEY_DELETE: KeyBufAdd(#0#83);
-            PTCKEY_LEFT:   KeyBufAdd(#0#75);
-            PTCKEY_UP:     KeyBufAdd(#0#72);
-            PTCKEY_RIGHT:  KeyBufAdd(#0#77);
-            PTCKEY_DOWN:   KeyBufAdd(#0#80);
-            PTCKEY_HOME:     KeyBufAdd(#0#71);
-            PTCKEY_END:      KeyBufAdd(#0#79);
-            PTCKEY_PAGEUP:   KeyBufAdd(#0#73);
-            PTCKEY_PAGEDOWN: KeyBufAdd(#0#81);
-            PTCKEY_F1:     KeyBufAdd(#0#59);
-            PTCKEY_F2:     KeyBufAdd(#0#60);
-            PTCKEY_F3:     KeyBufAdd(#0#61);
-            PTCKEY_F4:     KeyBufAdd(#0#62);
-            PTCKEY_F5:     KeyBufAdd(#0#63);
-            PTCKEY_F6:     KeyBufAdd(#0#64);
-            PTCKEY_F7:     KeyBufAdd(#0#65);
-            PTCKEY_F8:     KeyBufAdd(#0#66);
-            PTCKEY_F9:     KeyBufAdd(#0#67);
-            PTCKEY_F10:    KeyBufAdd(#0#68);
+        case KeyEv.Code of
+          PTCKEY_BACKSPACE:
+            if KeyEv.Control then
+              KeyBufAdd(#127)
             else
             else
-              if (KeyEv.Unicode >= 32) and (KeyEv.Unicode <= 127) then
-                KeyBufAdd(Chr(KeyEv.Unicode));
-          end;
+              KeyBufAdd(#8);
+          PTCKEY_ENTER:  KeyBufAdd(#13);
+          PTCKEY_ESCAPE: KeyBufAdd(#27);
+          PTCKEY_INSERT: KeyBufAdd(#0#82);
+          PTCKEY_DELETE: KeyBufAdd(#0#83);
+          PTCKEY_LEFT:   KeyBufAdd(#0#75);
+          PTCKEY_UP:     KeyBufAdd(#0#72);
+          PTCKEY_RIGHT:  KeyBufAdd(#0#77);
+          PTCKEY_DOWN:   KeyBufAdd(#0#80);
+          PTCKEY_HOME:     KeyBufAdd(#0#71);
+          PTCKEY_END:      KeyBufAdd(#0#79);
+          PTCKEY_PAGEUP:   KeyBufAdd(#0#73);
+          PTCKEY_PAGEDOWN: KeyBufAdd(#0#81);
+          PTCKEY_F1:     KeyBufAdd(#0#59);
+          PTCKEY_F2:     KeyBufAdd(#0#60);
+          PTCKEY_F3:     KeyBufAdd(#0#61);
+          PTCKEY_F4:     KeyBufAdd(#0#62);
+          PTCKEY_F5:     KeyBufAdd(#0#63);
+          PTCKEY_F6:     KeyBufAdd(#0#64);
+          PTCKEY_F7:     KeyBufAdd(#0#65);
+          PTCKEY_F8:     KeyBufAdd(#0#66);
+          PTCKEY_F9:     KeyBufAdd(#0#67);
+          PTCKEY_F10:    KeyBufAdd(#0#68);
+          else
+            if (KeyEv.Unicode >= 32) and (KeyEv.Unicode <= 127) then
+              KeyBufAdd(Chr(KeyEv.Unicode));
         end;
         end;
       end;
       end;
-    until ev = nil;
-  finally
-    ev.Free;
-  end;
+    end;
+  until ev = nil;
 end;
 end;
 
 
 function KeyPressed: Boolean;
 function KeyPressed: Boolean;

+ 12 - 23
packages/graph/src/ptcgraph/ptcgraph.pp

@@ -293,9 +293,9 @@ var
   ptcformat: TPTCFormat = nil;}
   ptcformat: TPTCFormat = nil;}
   PTCWidth: Integer;
   PTCWidth: Integer;
   PTCHeight: Integer;
   PTCHeight: Integer;
-  PTCFormat8: TPTCFormat;
-  PTCFormat15: TPTCFormat;
-  PTCFormat16: TPTCFormat;
+  PTCFormat8: IPTCFormat;
+  PTCFormat15: IPTCFormat;
+  PTCFormat16: IPTCFormat;
 
 
   EGAPaletteEnabled: Boolean;
   EGAPaletteEnabled: Boolean;
   EGAPalette: TEGAPalette;
   EGAPalette: TEGAPalette;
@@ -416,7 +416,7 @@ begin
 //  writeln('Initializing mode');
 //  writeln('Initializing mode');
   { create format }
   { create format }
 {  FreeAndNil(PTCFormat);
 {  FreeAndNil(PTCFormat);
-  PTCFormat:=TPTCFormat.Create(16,$f800,$07e0,$001f);}
+  PTCFormat:=TPTCFormatFactory.CreateNew(16,$f800,$07e0,$001f);}
   { open the console }
   { open the console }
 {  ptcconsole.open(paramstr(0),ptcformat);}
 {  ptcconsole.open(paramstr(0),ptcformat);}
   { create surface matching console dimensions }
   { create surface matching console dimensions }
@@ -640,7 +640,7 @@ begin
   CurrentCGABkColor := 0;
   CurrentCGABkColor := 0;
 end;
 end;
 
 
-procedure ptc_InternalOpen(const ATitle: string; AWidth, AHeight: Integer; AFormat: TPTCFormat; AVirtualPages: Integer);
+procedure ptc_InternalOpen(const ATitle: string; AWidth, AHeight: Integer; AFormat: IPTCFormat; AVirtualPages: Integer);
 var
 var
   ConsoleWidth, ConsoleHeight: Integer;
   ConsoleWidth, ConsoleHeight: Integer;
 begin
 begin
@@ -1503,11 +1503,11 @@ end;
   { Returns nil if no graphics mode supported.        }
   { Returns nil if no graphics mode supported.        }
   { This list is READ ONLY!                           }
   { This list is READ ONLY!                           }
   var
   var
-    PTCModeList: PPTCMode;
+    PTCModeList: TPTCModeList;
 
 
     function ModeListEmpty: Boolean;
     function ModeListEmpty: Boolean;
     begin
     begin
-      ModeListEmpty := (PTCModeList = nil) or (not PTCModeList[0].Valid);
+      ModeListEmpty := Length(PTCModeList) = 0;
     end;
     end;
 
 
     function ContainsExactResolution(AWidth, AHeight: Integer): Boolean;
     function ContainsExactResolution(AWidth, AHeight: Integer): Boolean;
@@ -1520,9 +1520,7 @@ end;
         exit;
         exit;
       end;
       end;
 
 
-      I := 0;
-      while (PTCModeList[I].Valid) do
-      begin
+      for I := Low(PTCModeList) to High(PTCModeList) do
         with PTCModeList[I] do
         with PTCModeList[I] do
           if (Width = AWidth) and
           if (Width = AWidth) and
              (Height = AHeight) then
              (Height = AHeight) then
@@ -1530,8 +1528,6 @@ end;
             ContainsExactResolution := True;
             ContainsExactResolution := True;
             exit;
             exit;
           end;
           end;
-        Inc(I);
-      end;
       ContainsExactResolution := False;
       ContainsExactResolution := False;
     end;
     end;
 
 
@@ -1545,9 +1541,7 @@ end;
         exit;
         exit;
       end;
       end;
 
 
-      I := 0;
-      while (PTCModeList[I].Valid) do
-      begin
+      for I := Low(PTCModeList) to High(PTCModeList) do
         with PTCModeList[I] do
         with PTCModeList[I] do
           if (Width >= AWidth) and
           if (Width >= AWidth) and
              (Height >= AHeight) then
              (Height >= AHeight) then
@@ -1555,8 +1549,6 @@ end;
             ContainsAtLeast := True;
             ContainsAtLeast := True;
             exit;
             exit;
           end;
           end;
-        Inc(I);
-      end;
       ContainsAtLeast := False;
       ContainsAtLeast := False;
     end;
     end;
 
 
@@ -2828,16 +2820,13 @@ end;
   end;
   end;
 
 
 initialization
 initialization
-  PTCFormat8 := TPTCFormat.Create(8);
-  PTCFormat15 := TPTCFormat.Create(16, $7C00, $03E0, $001F);
-  PTCFormat16 := TPTCFormat.Create(16, $F800, $07E0, $001F);
+  PTCFormat8 := TPTCFormatFactory.CreateNew(8);
+  PTCFormat15 := TPTCFormatFactory.CreateNew(16, $7C00, $03E0, $001F);
+  PTCFormat16 := TPTCFormatFactory.CreateNew(16, $F800, $07E0, $001F);
   PTCWrapperObject := TPTCWrapperThread.Create;
   PTCWrapperObject := TPTCWrapperThread.Create;
   InitializeGraph;
   InitializeGraph;
 finalization
 finalization
   PTCWrapperObject.Terminate;
   PTCWrapperObject.Terminate;
   PTCWrapperObject.WaitFor;
   PTCWrapperObject.WaitFor;
   PTCWrapperObject.Free;
   PTCWrapperObject.Free;
-  PTCFormat16.Free;
-  PTCFormat15.Free;
-  PTCFormat8.Free;
 end.
 end.

+ 10 - 0
packages/ptc/docs/CHANGES.txt

@@ -1,3 +1,13 @@
+0.99.12
+ - pressing Alt or F10 under Windows no longer pauses the application.
+ - API changes:
+    - PTC classes have been made descendants of TInterfacedObject and are now
+      accessed via interfaces. This simplifies memory management, because
+      objects are now reference counted and automatically freed when they are
+      no longer used. Unfortunately, this breaks existing code. However it's
+      relatively easy to fix. See the files INTF-CHANGES-0.99.12.txt and
+      INTF-CHANGES-FAQ-0.99.12.txt for details.
+
 0.99.11
 0.99.11
  - added ptcgraph - an implementation of FPC's BGI-compatible graph unit on top
  - added ptcgraph - an implementation of FPC's BGI-compatible graph unit on top
    of PTCPas. It should work on all platforms, supported by PTCPas,  except for
    of PTCPas. It should work on all platforms, supported by PTCPas,  except for

+ 3 - 3
packages/ptc/docs/INSTALL.txt

@@ -1,13 +1,13 @@
 The supported platforms are Linux, FreeBSD, Windows, Windows Mobile and DOS.
 The supported platforms are Linux, FreeBSD, Windows, Windows Mobile and DOS.
 
 
 Generally you need the latest stable version of the Free Pascal Compiler, which
 Generally you need the latest stable version of the Free Pascal Compiler, which
-currently means version 2.4.0. Generally FPC 2.2.4 should also work fine.
+currently means version 2.4.2. Generally FPC 2.2.4 should also work fine.
 
 
  - Compiling the library:
  - Compiling the library:
 Before starting make sure the FPCDIR environment variable is set correctly.
 Before starting make sure the FPCDIR environment variable is set correctly.
-For example: (windows, fpc version 2.4.0, default install dir)
+For example: (windows, fpc version 2.4.2, default install dir)
 
 
-  set FPCDIR=c:\fpc\2.4.0
+  set FPCDIR=c:\fpc\2.4.2
 
 
 To compile the library type:
 To compile the library type:
 
 

+ 29 - 0
packages/ptc/docs/INTF-CHANGES-0.99.12.txt

@@ -0,0 +1,29 @@
+This document describes the API changes introduced in version 0.99.12 of PTCPas
+
+Since version 0.99.12, most PTCPas classes have been made descendants of
+TInterfacedObject and are now only accessible via interfaces. The reason for
+this change is to provide automatic memory management via reference counting for
+the PTC core objects, so that they are freed automatically, once they're no
+longer in use, without causing any memory leaks.
+
+Unfortunately, this breaks existing code. However, it's relatively easy to fix
+it and the purpose of this document is to explain how. Here's a basic summary
+of the changes that need to be made:
+
+1) in your source code, replace "TPTCSomething.Create" with
+"TPTCSomethingFactory.CreateNew" (where 'Something' will correspond to one of
+those, depending on which objects are used in your program: Area, Color,
+Console, Event, Format, KeyEvent, Mode, MouseButtonEvent, MouseEvent, Palette,
+Surface and Timer)
+2) replace "TPTCSomething" with "IPTCSomething" (where 'Something' = an object
+from point #1)
+3) try compiling your code and you'll probably get some errors. Remove every
+call to .Free that fails with a compilation error, since it's no longer needed -
+PTC core objects are freed automatically when their reference count reaches
+zero.
+4) if you are using FreeAndNil, be extra careful! Since it accepts an untyped
+var parameter (bad design coming from Delphi), it will not cause a compilation
+error, if you are using it on an interface, but you will instead get a crash at
+runtime. Sadly, there's not much you can do, besides checking every call to
+FreeAndNil and replacing it with ":= nil" when you're using it on a PTC core
+object.

+ 77 - 0
packages/ptc/docs/INTF-CHANGES-FAQ-0.99.12.txt

@@ -0,0 +1,77 @@
+Frequently Asked Questions about the changes, introduced in version 0.99.12 of
+PTCPas
+
+Q: My code uses only the ptcgraph and ptccrt (TP7 compatibility) units. Is it
+affected by the changes?
+A: No. Only code that uses the ptc unit is affected.
+
+Q: Were the changes necessary?
+A: Yes, I believe so. Using certain objects like events, areas, and formats was
+tedious because of the need to manually manage and free them. You had to be
+aware of their lifecycle, e.g. when getting an event from the console you had
+to free it once you were done with it, but, when getting the format of the
+console, you had to know that you must not free it and that you must not change
+it with .Assign (otherwise things would break in the console, etc.) With the new
+interfaces, suddenly you don't have to worry about all that. The original C++
+library OpenPTC was much easier to work with, thanks to C++'s automatic
+destructors, copy constructors and operator overloading. However, when PTC was
+ported to Pascal for the first time, FPC was still at version 1.0.x and didn't
+support interfaces, so it wasn't possible to do at the time. I was planning this
+change for a long time but I kept postponing it until now :)
+
+Q: Are you planning any more changes that break backward compatibility?
+A: No. I promise :)
+
+Q: Was it possible to introduce the changes, without breaking backward
+compatibility with existing code?
+A: Basically, it was hard to do without having to maintain a full set of wrapper
+classes with the old interface for compatibility and that is a lot of extra work
+I wouldn't like to do. I'd rather help people migrate their code to the new
+version. :)
+I documented the necessary changes, most of them can be done with just a series
+of search & replace and you can also email me your code if you have any
+trouble - I'll do my best to help.
+
+Q: How about keeping the old methods around and adding new overloaded ones?
+A: I considered doing that for a while, but I figured it wasn't an option,
+because it would make a huge mess out of PTCPas' interface. Also mixing
+reference counted interfaces and ordinary classes is dangerous and prone to
+errors (see next question for details). If you really cannot justify the effort
+needed to upgrade your code, old PTCPas versions are available on sourceforge
+forever. :)
+
+Q: Why were constructors replaced with factory methods?
+A: I wanted to hide the old classes completely and force the use of interfaces
+everywhere. One of the reason for this was that if I kept the old classes, in
+certain cases, that would make old code compile without errors, but crash at
+runtime. Here's an example:
+
+var
+  format: TPTCFormat;  // bug: this should be changed to IPTCFormat
+  ...
+begin
+  format := TPTCFormat.Create(8);  // object created, ref count = 0
+
+  surface := TPTCSurface.Create(320, 200, format);  // the reference count of
+  // 'format' is increased (i.e. becomes 1) before the constructor call and
+  // decreased afterwards back to 0 and then the object is freed.
+  // If format was declared of type IPTCFormat, it would keep the reference
+  // count one higher until the variable goes out of scope.
+
+  console := TPTCConsole.Create;
+  console.Open(320, 200, format);  // here we try to use format for the second
+  // time, but it has been freed and we get a crash at runtime :(
+  ...
+end.
+
+The problem occurs when mixing direct references to the object with access to it
+via interfaces. To prevent this type of error, I made the TPTCFormat type
+private (i.e. hidden in the implementation part of the ptc unit) and only
+IPTCFormat public. This way, when trying to compile this code, you'll get a
+compile error in the declaration of 'format: TPTCFormat;' and you'll know that
+you need to fix it (by changing the type to IPTCFormat). However, this has the
+side effect of making the call to TPTCFormat.Create impossible (because
+TPTCFormat isn't public). IPTCFormat.Create sounds like the logical alternative,
+but it's also not possible, as IPTCFormat is an interface and interfaces cannot
+have constructors. That's why I introduced factory class methods (in this case:
+TPTCFormatFactory.CreateNew)

+ 41 - 25
packages/ptc/docs/INTRO.txt

@@ -1,40 +1,56 @@
-For more complete documentation please see the API reference found in the
+For more detailed documentation please see the API reference found in the
 'api-reference' directory (as well as online on the official PTCPas website).
 'api-reference' directory (as well as online on the official PTCPas website).
 
 
 This will explain the basics of creating a simple graphics application using
 This will explain the basics of creating a simple graphics application using
 PTC for FPC. :)
 PTC for FPC. :)
 
 
-(If you aren't familiar with Delphi classes, please refer to the Free Pascal
-Reference guide, Chapter 5 - Classes.)
+(If you aren't familiar with Delphi classes and interfaces, please refer to the
+Free Pascal Reference guide, Chapter 6 - Classes and Chapter 7 - Interfaces.)
 
 
-There are 3 classes you should get familiar with: TPTCFormat, TPTCSurface and
-TPTCConsole.
+There are 3 interfaces you should get familiar with: IPTCFormat, IPTCSurface
+and IPTCConsole.
 
 
-Ok, what is TPTCFormat? It basically describes a pixel format. To create a
+Ok, what is IPTCFormat? It basically describes a pixel format. To create a
 pixel format for 32 bpp use:
 pixel format for 32 bpp use:
-  Format := TPTCFormat.Create(32, $FF0000, $FF00, $FF);
+
+var
+  Format: IPTCFormat;
+begin
+  Format := TPTCFormatFactory.CreateNew(32, $FF0000, $FF00, $FF);
 
 
 32 is the number of bits per pixel. (Only formats with 8, 16, 24 and 32 bits
 32 is the number of bits per pixel. (Only formats with 8, 16, 24 and 32 bits
 per pixel are supported). $FF0000, $FF00 and $FF are the red, green and blue
 per pixel are supported). $FF0000, $FF00 and $FF are the red, green and blue
 masks.
 masks.
 
 
+Note that you no longer need to call Format.Free. The object is reference
+counted and will be freed automatically when it's no longer needed. This also
+applies to all the other PTC objects created by their TPTC*Factory.CreateNew
+methods.
+
 
 
 Now, when you have created your favourite pixel format, you should create a
 Now, when you have created your favourite pixel format, you should create a
 surface:
 surface:
-  Surface := TPTCSurface.Create(320, 200, Format);
+var
+  Surface: IPTCSurface;
+begin
+  Surface := TPTCSurfaceFactory.CreateNew(320, 200, Format);
 
 
 This will create a buffer in RAM to hold a single 320x200 frame in the given
 This will create a buffer in RAM to hold a single 320x200 frame in the given
-format. Note that TPTCSurface is always created in normal RAM, not video RAM,
-so it's not a problem if your video card doesn't have enough memory for it,
-or doesn't support e.g. 320x200x32bpp. You just create a TPTCConsole and open
-it in whatever mode is supported by the hardware and then PTC will blit the
-image stored in TPTCSurface to the console, doing any conversions that are
-necessary (i.e. converting to another pixel format, stretching the image to
-another resolution, etc...).
-
-
-How to use this TPTCConsole? Easy! First create it:
-  Console := TPTCConsole.Create;
+format. Note that surfaces, created by TPTCSurfaceFactory.CreateNew are always
+created in normal RAM, not video RAM, so it's not a problem if your video card
+doesn't have enough memory for it, or doesn't support the exact resolution that
+you requested. You just create a IPTCConsole and open it in whatever mode is
+supported by the hardware and then PTC will blit the image stored in
+IPTCSurface to the console, doing any conversions that are necessary (i.e.
+converting to another pixel format, stretch the image to another resolution,
+etc...).
+
+
+How to use this IPTCConsole? Easy! First create it:
+var
+  Console: IPTCConsole;
+begin
+  Console := TPTCConsoleFactory.CreateNew;
 
 
 This still doesn't do anything, just allocates memory and initializes stuff.
 This still doesn't do anything, just allocates memory and initializes stuff.
 Then you switch to the desired mode:
 Then you switch to the desired mode:
@@ -46,9 +62,9 @@ to switch to the best mode. If (for example) your card doesn't support
 To see the actual mode that PTC has set use these properties:
 To see the actual mode that PTC has set use these properties:
   Console.Width Console.Height and Console.Format
   Console.Width Console.Height and Console.Format
 
 
-Ok, now that you have created a TPTCSurface and opened a TPTCConsole, what to
-do next? Draw stuff... The lock function of TPTCSurface will give you a pointer
-to the internal buffer.
+Ok, now that you have created an IPTCSurface and opened an IPTCConsole, what to
+do next? Draw stuff... The lock function of IPTCSurface will give you a pointer
+to its internal buffer.
   ptr := Surface.Lock;
   ptr := Surface.Lock;
 
 
 Now you can draw your frame in the buffer, pointed by ptr. Note that this buffer
 Now you can draw your frame in the buffer, pointed by ptr. Note that this buffer
@@ -61,10 +77,10 @@ When you're done you have to unlock the surface and copy it to the console:
 
 
 The Surface.Copy(Console) will do the conversion (if necessary) to the actual
 The Surface.Copy(Console) will do the conversion (if necessary) to the actual
 mode. Console.Update will actually show the new frame (if the console driver
 mode. Console.Update will actually show the new frame (if the console driver
-supports multiple pages and you have enough video RAM for that, etc... :) ).
+supports multiple video pages and you have enough video RAM for that, etc... :) ).
 
 
-See the example programs for additional details. (keyboard input, high
-resolution timers - they're pretty much straightforward)
+See the example programs for additional details. (keyboard and mouse input,
+high resolution timers - they're pretty much straightforward)
 
 
 Enjoy!
 Enjoy!
 
 

+ 8 - 8
packages/ptc/docs/README.txt

@@ -1,4 +1,4 @@
-PTCPas 0.99.11
+PTCPas 0.99.12
 Nikolay Nikolov ([email protected])
 Nikolay Nikolov ([email protected])
 
 
 PTCPas is a free, portable framebuffer library, written in Free Pascal. It is
 PTCPas is a free, portable framebuffer library, written in Free Pascal. It is
@@ -18,13 +18,13 @@ OpenPTC C++ library. Since then, OpenPTC development has stalled and PTCPas
 lives on as a fully independent Object Pascal project.
 lives on as a fully independent Object Pascal project.
 
 
 Supported consoles:
 Supported consoles:
-  DirectX 3+ (should work on all x86 Windows versions since Windows 95, except
-              Windows CE. This currently means 95/98/ME/NT4/2000/XP/2003/Vista.
-              It is compatible with the x64 editions of XP and 2003 (although
-              only as a 32-bit application, no native win64 yet). On NT4 you
-              need SP3 or later. Also some very ancient versions of Windows 95
-              do not have any DirectX preinstalled, so it has to be installed
-              separately.)
+  DirectX 3+ (should work on all x86 and x64 Windows versions since Windows 95,
+              except Windows CE. This currently means 95/98/ME/NT4/2000/XP/2003/
+              Vista/2008/7. It is compatible with the x64 editions of XP, 2003,
+              Vista, 2008 and 7 (both as a 32-bit application and native win64).
+              On NT4 you need SP3 or later. Ancient versions of Windows 95 come
+              without any DirectX version by default, so you may have to install
+              it.)
   Win32 GDI (no fullscreen support. Slower than DirectX, but maybe more
   Win32 GDI (no fullscreen support. Slower than DirectX, but maybe more
              compatible.)
              compatible.)
   X11 (on linux and other unix-like OSes, supports XRandR, XF86VidMode, XShm
   X11 (on linux and other unix-like OSes, supports XRandR, XF86VidMode, XShm

+ 10 - 13
packages/ptc/examples/area.pp

@@ -16,33 +16,33 @@ uses
   ptc;
   ptc;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  format: TPTCFormat = nil;
-  surface: TPTCSurface = nil;
+  console: IPTCConsole;
+  format: IPTCFormat;
+  surface: IPTCSurface;
   pixels: PDWord;
   pixels: PDWord;
   width, height: Integer;
   width, height: Integer;
   i: Integer;
   i: Integer;
   x, y, r, g, b: Integer;
   x, y, r, g, b: Integer;
-  area: TPTCArea = nil;
+  area: IPTCArea;
 begin
 begin
   try
   try
     try
     try
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { create format }
       { create format }
-      format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+      format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
 
 
       { create console }
       { create console }
       console.open('Area example', format);
       console.open('Area example', format);
 
 
       { create surface half the size of the console }
       { create surface half the size of the console }
-      surface := TPTCSurface.Create(console.width div 2, console.height div 2, format);
+      surface := TPTCSurfaceFactory.CreateNew(console.width div 2, console.height div 2, format);
 
 
       { setup destination area }
       { setup destination area }
       x := console.width div 4;
       x := console.width div 4;
       y := console.height div 4;
       y := console.height div 4;
-      area := TPTCArea.Create(x, y, x + surface.width, y + surface.height);
+      area := TPTCAreaFactory.CreateNew(x, y, x + surface.width, y + surface.height);
 
 
       { loop until a key is pressed }
       { loop until a key is pressed }
       while not console.KeyPressed do
       while not console.KeyPressed do
@@ -81,11 +81,8 @@ begin
         console.update;
         console.update;
       end;
       end;
     finally
     finally
-      console.close;
-      console.Free;
-      surface.Free;
-      format.Free;
-      area.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 11 - 15
packages/ptc/examples/buffer.pp

@@ -16,9 +16,8 @@ uses
   ptc;
   ptc;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  format: TPTCFormat = nil;
-  palette: TPTCPalette = nil;
+  console: IPTCConsole;
+  format: IPTCFormat;
   width, height: Integer;
   width, height: Integer;
   pixels: PUint32 = nil;
   pixels: PUint32 = nil;
   x, y, r, g, b: Integer;
   x, y, r, g, b: Integer;
@@ -27,22 +26,21 @@ begin
   try
   try
     try
     try
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { create format }
       { create format }
-      format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+      format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
 
 
       { open the console }
       { open the console }
-      console.open('Buffer example', format);
+      console.Open('Buffer example', format);
 
 
       { get console dimensions }
       { get console dimensions }
-      width := console.width;
-      height := console.height;
+      width := console.Width;
+      height := console.Height;
 
 
       { allocate a buffer of pixels }
       { allocate a buffer of pixels }
       pixels := GetMem(width * height * SizeOf(Uint32));
       pixels := GetMem(width * height * SizeOf(Uint32));
       FillChar(pixels^, width * height * SizeOf(Uint32), 0);
       FillChar(pixels^, width * height * SizeOf(Uint32), 0);
-      palette := TPTCPalette.Create;
 
 
       { loop until a key is pressed }
       { loop until a key is pressed }
       while not console.KeyPressed do
       while not console.KeyPressed do
@@ -64,18 +62,16 @@ begin
         end;
         end;
 
 
         { load pixels to console }
         { load pixels to console }
-        console.load(pixels, width, height, width * 4, format, palette);
+        console.Load(pixels, width, height, width * 4, format, TPTCPaletteFactory.CreateNew);
 
 
         { update console }
         { update console }
-        console.update;
+        console.Update;
       end;
       end;
     finally
     finally
       { free pixels buffer }
       { free pixels buffer }
       FreeMem(pixels);
       FreeMem(pixels);
-      console.close;
-      palette.Free;
-      format.Free;
-      console.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 20 - 27
packages/ptc/examples/clear.pp

@@ -16,27 +16,27 @@ uses
   SysUtils, ptc;
   SysUtils, ptc;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  format: TPTCFormat = nil;
-  surface: TPTCSurface = nil;
+  console: IPTCConsole;
+  format: IPTCFormat;
+  surface: IPTCSurface;
   width, height: Integer;
   width, height: Integer;
   x, y: Integer;
   x, y: Integer;
   size: Integer;
   size: Integer;
-  area: TPTCArea = nil;
-  color: TPTCColor = nil;
+  area: IPTCArea;
+  color: IPTCColor;
 begin
 begin
   try
   try
     { create console }
     { create console }
-    console := TPTCConsole.Create;
+    console := TPTCConsoleFactory.CreateNew;
 
 
     { create format }
     { create format }
-    format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+    format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
 
 
     { open the console }
     { open the console }
     console.open('Clear example', format);
     console.open('Clear example', format);
 
 
     { create surface matching console dimensions }
     { create surface matching console dimensions }
-    surface := TPTCSurface.Create(console.width, console.height, format);
+    surface := TPTCSurfaceFactory.CreateNew(console.width, console.height, format);
 
 
     { loop until a key is pressed }
     { loop until a key is pressed }
     while not console.KeyPressed do
     while not console.KeyPressed do
@@ -52,30 +52,23 @@ begin
       { get random area size }
       { get random area size }
       size := Random(width div 8);
       size := Random(width div 8);
 
 
-      try
-        { setup clear area }
-        area := TPTCArea.Create(x-size, y-size, x+size, y+size);
+      { setup clear area }
+      area := TPTCAreaFactory.CreateNew(x-size, y-size, x+size, y+size);
 
 
-        { create random color }
-        color := TPTCColor.Create(Random, Random, Random);
+      { create random color }
+      color := TPTCColorFactory.CreateNew(Random, Random, Random);
 
 
-        { clear surface area with color }
-        surface.clear(color, area);
+      { clear surface area with color }
+      surface.clear(color, area);
 
 
-        { copy to console }
-        surface.copy(console);
+      { copy to console }
+      surface.copy(console);
 
 
-        { update console }
-        console.update;
-      finally
-        FreeAndNil(area);
-        FreeAndNil(color);
-      end;
+      { update console }
+      console.update;
     end;
     end;
-    console.close;
-    console.Free;
-    surface.Free;
-    format.Free;
+    if Assigned(console) then
+      console.close;
   except
   except
     on error: TPTCError do
     on error: TPTCError do
       { report error }
       { report error }

+ 10 - 19
packages/ptc/examples/clip.pp

@@ -16,10 +16,9 @@ uses
   ptc;
   ptc;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  surface: TPTCSurface = nil;
-  format: TPTCFormat = nil;
-  area: TPTCArea;
+  console: IPTCConsole;
+  surface: IPTCSurface;
+  format: IPTCFormat;
   x1, y1, x2, y2: Integer;
   x1, y1, x2, y2: Integer;
   pixels: PUint32;
   pixels: PUint32;
   width, height: Integer;
   width, height: Integer;
@@ -29,16 +28,16 @@ begin
   try
   try
     try
     try
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { create format }
       { create format }
-      format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+      format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
 
 
       { open the console }
       { open the console }
       console.open('Clip example', format);
       console.open('Clip example', format);
 
 
       { create surface matching console dimensions }
       { create surface matching console dimensions }
-      surface := TPTCSurface.Create(console.width, console.height, format);
+      surface := TPTCSurfaceFactory.CreateNew(console.width, console.height, format);
 
 
       { calculate clip coordinates }
       { calculate clip coordinates }
       x1 := console.width div 4;
       x1 := console.width div 4;
@@ -46,14 +45,8 @@ begin
       x2 := console.width - x1;
       x2 := console.width - x1;
       y2 := console.height - y1;
       y2 := console.height - y1;
 
 
-      { setup clip area }
-      area := TPTCArea.Create(x1, y1, x2, y2);
-      try
-        { set clip area }
-        console.clip(area);
-      finally
-        area.Free;
-      end;
+      { set clip area }
+      console.clip(TPTCAreaFactory.CreateNew(x1, y1, x2, y2));
 
 
       { loop until a key is pressed }
       { loop until a key is pressed }
       while not console.KeyPressed do
       while not console.KeyPressed do
@@ -92,10 +85,8 @@ begin
         console.update;
         console.update;
       end;
       end;
     finally
     finally
-      console.close;
-      console.Free;
-      surface.Free;
-      format.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 5 - 5
packages/ptc/examples/con_info.pp

@@ -15,7 +15,7 @@ program InfoExample;
 uses
 uses
   ptc;
   ptc;
 
 
-procedure print(const format: TPTCFormat);
+procedure print(format: IPTCFormat);
 begin
 begin
   { check format type }
   { check format type }
   if format.direct then
   if format.direct then
@@ -32,7 +32,7 @@ begin
 end;
 end;
 
 
 var
 var
-  console: TPTCConsole = nil;
+  console: IPTCConsole;
 begin
 begin
   try
   try
     try
     try
@@ -42,7 +42,7 @@ begin
       Writeln;
       Writeln;
 
 
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { open the console }
       { open the console }
       console.open('Info example');
       console.open('Info example');
@@ -64,8 +64,8 @@ begin
       Writeln('[console information]');
       Writeln('[console information]');
       Writeln(console.information);
       Writeln(console.information);
     finally
     finally
-      console.close;
-      console.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 12 - 13
packages/ptc/examples/console.pp

@@ -16,13 +16,13 @@ uses
   ptc;
   ptc;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  palette: TPTCPalette = nil;
+  console: IPTCConsole;
+  palette: IPTCPalette;
   data: array [0..255] of DWord;
   data: array [0..255] of DWord;
   i: Integer;
   i: Integer;
   pixels: PByte;
   pixels: PByte;
   width, height, pitch: Integer;
   width, height, pitch: Integer;
-  format: TPTCFormat;
+  format: IPTCFormat;
   bits, bytes: Integer;
   bits, bytes: Integer;
   x, y: Integer;
   x, y: Integer;
   color: DWord;
   color: DWord;
@@ -32,29 +32,29 @@ begin
   try
   try
     try
     try
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { open the console with one page }
       { open the console with one page }
       console.open('Console example', 1);
       console.open('Console example', 1);
 
 
       { create palette }
       { create palette }
-      palette := TPTCPalette.Create;
+      palette := TPTCPaletteFactory.CreateNew;
 
 
       { generate palette }
       { generate palette }
       for i := 0 to 255 do
       for i := 0 to 255 do
         data[i] := i;
         data[i] := i;
 
 
       { load palette data }
       { load palette data }
-      palette.load(data);
+      palette.Load(data);
 
 
       { set console palette }
       { set console palette }
-      console.palette(palette);
+      console.Palette(palette);
 
 
       { loop until a key is pressed }
       { loop until a key is pressed }
       while not console.KeyPressed do
       while not console.KeyPressed do
       begin
       begin
         { lock console }
         { lock console }
-        pixels := console.lock;
+        pixels := console.Lock;
 
 
         try
         try
           { get console dimensions }
           { get console dimensions }
@@ -104,16 +104,15 @@ begin
           end;
           end;
         finally
         finally
           { unlock console }
           { unlock console }
-          console.unlock;
+          console.Unlock;
         end;
         end;
 
 
         { update console }
         { update console }
-        console.update;
+        console.Update;
       end;
       end;
     finally
     finally
-      palette.Free;
-      console.close;
-      console.Free;
+      if Assigned(console) then
+        console.Close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 15 - 18
packages/ptc/examples/fire.pp

@@ -21,13 +21,13 @@ begin
   pack := (r shl 16) or (g shl 8) or b;
   pack := (r shl 16) or (g shl 8) or b;
 end;
 end;
 
 
-procedure generate(palette: TPTCPalette);
+procedure generate(palette: IPTCPalette);
 var
 var
   data: PUint32;
   data: PUint32;
   i, c: Integer;
   i, c: Integer;
 begin
 begin
   { lock palette data }
   { lock palette data }
-  data := palette.lock;
+  data := palette.Lock;
 
 
   try
   try
     { black to red }
     { black to red }
@@ -67,15 +67,15 @@ begin
 
 
   finally
   finally
     { unlock palette }
     { unlock palette }
-    palette.unlock;
+    palette.Unlock;
   end;
   end;
 end;
 end;
 
 
 var
 var
-  format: TPTCFormat = nil;
-  console: TPTCConsole = nil;
-  surface: TPTCSurface = nil;
-  palette: TPTCPalette = nil;
+  format: IPTCFormat;
+  console: IPTCConsole;
+  surface: IPTCSurface;
+  palette: IPTCPalette;
   state: Integer;
   state: Integer;
   intensity: Single;
   intensity: Single;
   pixels, pixel, p: PUint8;
   pixels, pixel, p: PUint8;
@@ -84,24 +84,24 @@ var
   top, bottom, c1, c2: Uint32;
   top, bottom, c1, c2: Uint32;
   generator: PUint8;
   generator: PUint8;
   color: Integer;
   color: Integer;
-  area: TPTCArea = nil;
+  area: IPTCArea;
 begin
 begin
   try
   try
     try
     try
       { create format }
       { create format }
-      format := TPTCFormat.Create(8);
+      format := TPTCFormatFactory.CreateNew(8);
 
 
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { open console }
       { open console }
       console.open('Fire demo', 320, 200, format);
       console.open('Fire demo', 320, 200, format);
 
 
       { create surface }
       { create surface }
-      surface := TPTCSurface.Create(320, 208, format);
+      surface := TPTCSurfaceFactory.CreateNew(320, 208, format);
 
 
       { create palette }
       { create palette }
-      palette := TPTCPalette.Create;
+      palette := TPTCPaletteFactory.CreateNew;
 
 
       { generate palette }
       { generate palette }
       generate(palette);
       generate(palette);
@@ -117,7 +117,7 @@ begin
       intensity := 0;
       intensity := 0;
 
 
       { setup copy area }
       { setup copy area }
-      area := TPTCArea.Create(0, 0, 320, 200);
+      area := TPTCAreaFactory.CreateNew(0, 0, 320, 200);
 
 
       { main loop }
       { main loop }
       repeat
       repeat
@@ -242,11 +242,8 @@ begin
       until False;
       until False;
 
 
     finally
     finally
-      console.Free;
-      surface.Free;
-      format.Free;
-      palette.Free;
-      area.Free;
+      if Assigned(console) then
+        console.Close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 16 - 22
packages/ptc/examples/flower.pp

@@ -21,7 +21,7 @@ begin
   pack := (r shl 16) or (g shl 8) or b;
   pack := (r shl 16) or (g shl 8) or b;
 end;
 end;
 
 
-procedure generate_flower(flower: TPTCSurface);
+procedure generate_flower(flower: IPTCSurface);
 var
 var
   data: PUint8;
   data: PUint8;
   x, y, fx, fy, fx2, fy2: Integer;
   x, y, fx, fy, fx2, fy2: Integer;
@@ -56,13 +56,13 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure generate(palette: TPTCPalette);
+procedure generate(palette: IPTCPalette);
 var
 var
   data: PUint32;
   data: PUint32;
   i, c: Integer;
   i, c: Integer;
 begin
 begin
   { lock palette data }
   { lock palette data }
-  data := palette.lock;
+  data := palette.Lock;
 
 
   try
   try
     { black to yellow }
     { black to yellow }
@@ -103,17 +103,17 @@ begin
     end;
     end;
   finally
   finally
     { unlock palette }
     { unlock palette }
-    palette.unlock;
+    palette.Unlock;
   end;
   end;
 end;
 end;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  format: TPTCFormat = nil;
-  flower_surface: TPTCSurface = nil;
-  surface: TPTCSurface = nil;
-  palette: TPTCPalette = nil;
-  area: TPTCArea = nil;
+  console: IPTCConsole;
+  format: IPTCFormat;
+  flower_surface: IPTCSurface;
+  surface: IPTCSurface;
+  palette: IPTCPalette;
+  area: IPTCArea;
   time, delta: Single;
   time, delta: Single;
   scr, map: PUint8;
   scr, map: PUint8;
   width, height, mapWidth: Integer;
   width, height, mapWidth: Integer;
@@ -124,13 +124,13 @@ begin
   try
   try
     try
     try
       { create format }
       { create format }
-      format := TPTCFormat.Create(8);
+      format := TPTCFormatFactory.CreateNew(8);
 
 
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { create flower surface }
       { create flower surface }
-      flower_surface := TPTCSurface.Create(640, 400, format);
+      flower_surface := TPTCSurfaceFactory.CreateNew(640, 400, format);
 
 
       { generate flower }
       { generate flower }
       generate_flower(flower_surface);
       generate_flower(flower_surface);
@@ -139,10 +139,10 @@ begin
       console.open('Flower demo', 320, 200, format);
       console.open('Flower demo', 320, 200, format);
 
 
       { create surface }
       { create surface }
-      surface := TPTCSurface.Create(320, 200, format);
+      surface := TPTCSurfaceFactory.CreateNew(320, 200, format);
 
 
       { create palette }
       { create palette }
-      palette := TPTCPalette.Create;
+      palette := TPTCPaletteFactory.CreateNew;
 
 
       { generate palette }
       { generate palette }
       generate(palette);
       generate(palette);
@@ -154,7 +154,7 @@ begin
       surface.palette(palette);
       surface.palette(palette);
 
 
       { setup copy area }
       { setup copy area }
-      area := TPTCArea.Create(0, 0, 320, 200);
+      area := TPTCAreaFactory.CreateNew(0, 0, 320, 200);
 
 
       { time data }
       { time data }
       time := 0;
       time := 0;
@@ -213,12 +213,6 @@ begin
     finally
     finally
       if Assigned(console) then
       if Assigned(console) then
         console.close;
         console.close;
-      area.Free;
-      format.Free;
-      palette.Free;
-      surface.Free;
-      flower_surface.Free;
-      console.Free;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 8 - 10
packages/ptc/examples/hicolor.pp

@@ -16,9 +16,9 @@ uses
   ptc;
   ptc;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  surface: TPTCSurface = nil;
-  format: TPTCFormat = nil;
+  console: IPTCConsole;
+  surface: IPTCSurface;
+  format: IPTCFormat;
   pixels: PUint16;
   pixels: PUint16;
   width, height: Integer;
   width, height: Integer;
   i: Integer;
   i: Integer;
@@ -27,16 +27,16 @@ begin
   try
   try
     try
     try
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { create format }
       { create format }
-      format := TPTCFormat.Create(16, $F800, $07E0, $001F);
+      format := TPTCFormatFactory.CreateNew(16, $F800, $07E0, $001F);
 
 
       { open the console }
       { open the console }
       console.open('HiColor example', format);
       console.open('HiColor example', format);
 
 
       { create surface matching console dimensions }
       { create surface matching console dimensions }
-      surface := TPTCSurface.Create(console.width, console.height, format);
+      surface := TPTCSurfaceFactory.CreateNew(console.width, console.height, format);
 
 
       { loop until a key is pressed }
       { loop until a key is pressed }
       while not console.KeyPressed do
       while not console.KeyPressed do
@@ -77,10 +77,8 @@ begin
         console.update;
         console.update;
       end;
       end;
     finally
     finally
-      console.close;
-      console.Free;
-      surface.Free;
-      format.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 13 - 21
packages/ptc/examples/image.pp

@@ -15,14 +15,13 @@ program ImageExample;
 uses
 uses
   SysUtils, ptc;
   SysUtils, ptc;
 
 
-procedure load(surface: TPTCSurface; filename: String);
+procedure load(surface: IPTCSurface; filename: String);
 var
 var
   F: File;
   F: File;
   width, height: Integer;
   width, height: Integer;
   pixels: PByte = nil;
   pixels: PByte = nil;
   y: Integer;
   y: Integer;
-  img_format: TPTCFormat = nil;
-  img_palette: TPTCPalette = nil;
+  img_format: IPTCFormat;
 begin
 begin
   { open image file }
   { open image file }
   AssignFile(F, filename);
   AssignFile(F, filename);
@@ -45,36 +44,32 @@ begin
 
 
     { load pixels to surface }
     { load pixels to surface }
     {$IFDEF FPC_LITTLE_ENDIAN}
     {$IFDEF FPC_LITTLE_ENDIAN}
-    img_format := TPTCFormat.Create(24, $00FF0000, $0000FF00, $000000FF);
+    img_format := TPTCFormatFactory.CreateNew(24, $00FF0000, $0000FF00, $000000FF);
     {$ELSE FPC_LITTLE_ENDIAN}
     {$ELSE FPC_LITTLE_ENDIAN}
-    img_format := TPTCFormat.Create(24, $000000FF, $0000FF00, $00FF0000);
+    img_format := TPTCFormatFactory.CreateNew(24, $000000FF, $0000FF00, $00FF0000);
     {$ENDIF FPC_LITTLE_ENDIAN}
     {$ENDIF FPC_LITTLE_ENDIAN}
-    img_palette := TPTCPalette.Create;
-    surface.load(pixels, width, height, width * 3, img_format, img_palette);
+    surface.Load(pixels, width, height, width * 3, img_format, TPTCPaletteFactory.CreateNew);
 
 
   finally
   finally
     CloseFile(F);
     CloseFile(F);
 
 
     { free image pixels }
     { free image pixels }
     FreeMem(pixels);
     FreeMem(pixels);
-
-    img_palette.Free;
-    img_format.Free;
   end;
   end;
 end;
 end;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  format: TPTCFormat = nil;
-  surface: TPTCSurface = nil;
+  console: IPTCConsole;
+  format: IPTCFormat;
+  surface: IPTCSurface;
 begin
 begin
   try
   try
     try
     try
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { create format }
       { create format }
-      format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+      format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
 
 
       try
       try
         { try to open the console matching the image resolution }
         { try to open the console matching the image resolution }
@@ -86,7 +81,7 @@ begin
       end;
       end;
 
 
       { create surface }
       { create surface }
-      surface := TPTCSurface.Create(320, 200, format);
+      surface := TPTCSurfaceFactory.CreateNew(320, 200, format);
 
 
       { load image to surface }
       { load image to surface }
       load(surface, 'image.tga');
       load(surface, 'image.tga');
@@ -102,11 +97,8 @@ begin
 
 
     finally
     finally
       { close console }
       { close console }
-      console.close;
-
-      console.Free;
-      surface.Free;
-      format.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 13 - 27
packages/ptc/examples/keyboard.pp

@@ -16,38 +16,34 @@ uses
   ptc;
   ptc;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  surface: TPTCSurface = nil;
-  format: TPTCFormat = nil;
-  color: TPTCColor = nil;
-  key: TPTCKeyEvent = nil;
-  area: TPTCArea;
+  console: IPTCConsole;
+  surface: IPTCSurface;
+  format: IPTCFormat;
+  color: IPTCColor;
+  key: IPTCKeyEvent;
   x, y: Integer;
   x, y: Integer;
   size: Integer;
   size: Integer;
   delta: Integer;
   delta: Integer;
 begin
 begin
   try
   try
     try
     try
-      { create key }
-      key := TPTCKeyEvent.Create;
-
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { create format }
       { create format }
-      format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+      format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
 
 
       { open the console }
       { open the console }
       console.open('Keyboard example', format);
       console.open('Keyboard example', format);
 
 
       { create surface matching console dimensions }
       { create surface matching console dimensions }
-      surface := TPTCSurface.Create(console.width, console.height, format);
+      surface := TPTCSurfaceFactory.CreateNew(console.width, console.height, format);
 
 
       { setup cursor data }
       { setup cursor data }
       x := surface.width div 2;
       x := surface.width div 2;
       y := surface.height div 2;
       y := surface.height div 2;
       size := surface.width div 10;
       size := surface.width div 10;
-      color := TPTCColor.Create(1, 1, 1);
+      color := TPTCColorFactory.CreateNew(1, 1, 1);
 
 
       { main loop }
       { main loop }
       repeat
       repeat
@@ -79,14 +75,8 @@ begin
         { clear surface }
         { clear surface }
         surface.clear;
         surface.clear;
 
 
-        { setup cursor area }
-        area := TPTCArea.Create(x - size, y - size, x + size, y + size);
-        try
-          { draw cursor as a quad }
-          surface.clear(color, area);
-        finally
-          area.Free;
-        end;
+        { draw cursor as a quad }
+        surface.clear(color, TPTCAreaFactory.CreateNew(x - size, y - size, x + size, y + size));
 
 
         { copy to console }
         { copy to console }
         surface.copy(console);
         surface.copy(console);
@@ -95,12 +85,8 @@ begin
         console.update;
         console.update;
       until False;
       until False;
     finally
     finally
-      color.Free;
-      console.close;
-      console.Free;
-      surface.Free;
-      key.Free;
-      format.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 15 - 30
packages/ptc/examples/keyboard2.pp

@@ -11,13 +11,12 @@ uses
   ptc;
   ptc;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  surface: TPTCSurface = nil;
-  format: TPTCFormat = nil;
-  color: TPTCColor = nil;
-  timer: TPTCTimer = nil;
-  key: TPTCKeyEvent = nil;
-  area: TPTCArea;
+  console: IPTCConsole;
+  surface: IPTCSurface;
+  format: IPTCFormat;
+  color: IPTCColor;
+  timer: IPTCTimer;
+  key: IPTCKeyEvent;
   x, y, delta: Real;
   x, y, delta: Real;
   left, right, up, down: Boolean;
   left, right, up, down: Boolean;
   size: Integer;
   size: Integer;
@@ -29,32 +28,29 @@ begin
   down := False;
   down := False;
   try
   try
     try
     try
-      { create key }
-      key := TPTCKeyEvent.Create;
-
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { enable key release events }
       { enable key release events }
       console.KeyReleaseEnabled := True;
       console.KeyReleaseEnabled := True;
 
 
       { create format }
       { create format }
-      format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+      format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
 
 
       { open the console }
       { open the console }
       console.open('Keyboard example 2', format);
       console.open('Keyboard example 2', format);
 
 
       { create timer }
       { create timer }
-      timer := TPTCTimer.Create;
+      timer := TPTCTimerFactory.CreateNew;
 
 
       { create surface matching console dimensions }
       { create surface matching console dimensions }
-      surface := TPTCSurface.Create(console.width, console.height, format);
+      surface := TPTCSurfaceFactory.CreateNew(console.width, console.height, format);
 
 
       { setup cursor data }
       { setup cursor data }
       x := surface.width div 2;
       x := surface.width div 2;
       y := surface.height div 2;
       y := surface.height div 2;
       size := surface.width div 10;
       size := surface.width div 10;
-      color := TPTCColor.Create(1, 1, 1);
+      color := TPTCColorFactory.CreateNew(1, 1, 1);
 
 
       { start timer }
       { start timer }
       timer.start;
       timer.start;
@@ -92,14 +88,8 @@ begin
         { clear surface }
         { clear surface }
         surface.clear;
         surface.clear;
 
 
-        { setup cursor area }
-        area := TPTCArea.Create(Trunc(x) - size, Trunc(y) - size, Trunc(x) + size, Trunc(y) + size);
-        try
-          { draw cursor as a quad }
-          surface.clear(color, area);
-        finally
-          area.Free;
-        end;
+        { draw cursor as a quad }
+        surface.clear(color, TPTCAreaFactory.CreateNew(Trunc(x) - size, Trunc(y) - size, Trunc(x) + size, Trunc(y) + size));
 
 
         { copy to console }
         { copy to console }
         surface.copy(console);
         surface.copy(console);
@@ -108,13 +98,8 @@ begin
         console.update;
         console.update;
       until Done;
       until Done;
     finally
     finally
-      color.Free;
-      console.close;
-      console.Free;
-      surface.Free;
-      key.Free;
-      timer.Free;
-      format.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 11 - 16
packages/ptc/examples/land.pp

@@ -270,11 +270,11 @@ begin
 end;
 end;
 
 
 var
 var
-  format: TPTCFormat = nil;
-  console: TPTCConsole = nil;
-  surface: TPTCSurface = nil;
-  timer: TPTCTimer = nil;
-  key: TPTCKeyEvent = nil;
+  format: IPTCFormat;
+  console: IPTCConsole;
+  surface: IPTCSurface;
+  timer: IPTCTimer;
+  key: IPTCKeyEvent;
   pixels: PUint32;
   pixels: PUint32;
   Done: Boolean;
   Done: Boolean;
 
 
@@ -286,11 +286,10 @@ begin
   Done := False;
   Done := False;
   try
   try
     try
     try
-      key := TPTCKeyEvent.Create;
-      format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
-      console := TPTCConsole.Create;
+      format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
+      console := TPTCConsoleFactory.CreateNew;
       console.open('Land demo', SCREENWIDTH, SCREENHEIGHT, format);
       console.open('Land demo', SCREENWIDTH, SCREENHEIGHT, format);
-      surface := TPTCSurface.Create(SCREENWIDTH, SCREENHEIGHT, format);
+      surface := TPTCSurfaceFactory.CreateNew(SCREENWIDTH, SCREENHEIGHT, format);
 
 
       { Compute the height map }
       { Compute the height map }
       ComputeMap;
       ComputeMap;
@@ -309,7 +308,7 @@ begin
       scale := 20;
       scale := 20;
 
 
       { create timer }
       { create timer }
-      timer := TPTCTimer.Create;
+      timer := TPTCTimerFactory.CreateNew;
 
 
       { start timer }
       { start timer }
       timer.start;
       timer.start;
@@ -372,12 +371,8 @@ begin
         Inc(y0, Trunc(CurrentSpeed * SinT[index]) div 256);
         Inc(y0, Trunc(CurrentSpeed * SinT[index]) div 256);
       until Done;
       until Done;
     finally
     finally
-      console.close;
-      console.Free;
-      surface.Free;
-      timer.Free;
-      format.Free;
-      key.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 12 - 15
packages/ptc/examples/lights.pp

@@ -28,10 +28,10 @@ begin
 end;
 end;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  surface: TPTCSurface = nil;
-  format: TPTCFormat = nil;
-  palette: TPTCPalette = nil;
+  console: IPTCConsole;
+  surface: IPTCSurface;
+  format: IPTCFormat;
+  palette: IPTCPalette;
   dx, dy: Integer;
   dx, dy: Integer;
   divisor: Single;
   divisor: Single;
   data: PUint32;
   data: PUint32;
@@ -54,15 +54,15 @@ begin
   try
   try
     try
     try
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
-      format := TPTCFormat.Create(8);
+      format := TPTCFormatFactory.CreateNew(8);
 
 
       { open console }
       { open console }
       console.open('Lights demo', 320, 200, format);
       console.open('Lights demo', 320, 200, format);
 
 
       { create surface }
       { create surface }
-      surface := TPTCSurface.Create(320, 200, format);
+      surface := TPTCSurfaceFactory.CreateNew(320, 200, format);
 
 
       { setup intensity table }
       { setup intensity table }
       for dy := 0 to 199 do
       for dy := 0 to 199 do
@@ -75,15 +75,15 @@ begin
         end;
         end;
 
 
       { create palette }
       { create palette }
-      palette := TPTCPalette.Create;
+      palette := TPTCPaletteFactory.CreateNew;
 
 
       { generate greyscale palette }
       { generate greyscale palette }
-      data := palette.lock;
+      data := palette.Lock;
       try
       try
         for i := 0 to 255 do
         for i := 0 to 255 do
           data[i] := (i shl 16) or (i shl 8) or i;
           data[i] := (i shl 16) or (i shl 8) or i;
       finally
       finally
-        palette.unlock;
+        palette.Unlock;
       end;
       end;
 
 
       { set console palette }
       { set console palette }
@@ -271,11 +271,8 @@ begin
         console.update;
         console.update;
       end;
       end;
     finally
     finally
-      console.close;
-      surface.Free;
-      console.Free;
-      palette.Free;
-      format.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 21 - 31
packages/ptc/examples/modes.pp

@@ -15,7 +15,7 @@ program ModesExample;
 uses
 uses
   ptc;
   ptc;
 
 
-procedure print(const format: TPTCFormat);
+procedure print(format: IPTCFormat);
 begin
 begin
   { check format type }
   { check format type }
   if format.direct then
   if format.direct then
@@ -31,7 +31,7 @@ begin
     Write('Format(', format.bits:2, ')');
     Write('Format(', format.bits:2, ')');
 end;
 end;
 
 
-procedure print(const mode: TPTCMode);
+procedure print(mode: IPTCMode);
 begin
 begin
   { print mode width and height }
   { print mode width and height }
   Write(' ', mode.width:4, ' x ', mode.height);
   Write(' ', mode.width:4, ' x ', mode.height);
@@ -51,42 +51,32 @@ begin
 end;
 end;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  modes: PPTCMode;
+  console: IPTCConsole;
+  modes: TPTCModeList;
   index: Integer;
   index: Integer;
 begin
 begin
   try
   try
-    try
-      { create console }
-      console := TPTCConsole.Create;
+    { create console }
+    console := TPTCConsoleFactory.CreateNew;
 
 
-      { get list of console modes }
-      modes := console.modes;
+    { get list of console modes }
+    modes := console.modes;
 
 
-      { check for empty list }
-      if not modes[0].valid then
-        { the console mode list was empty }
-        Writeln('[console mode list is not available]')
-      else
-      begin
-        { print mode list header }
-        Writeln('[console modes]');
-
-        { mode index }
-        index := 0;
-
-        { iterate through all modes }
-        while modes[index].valid do
-        begin
-          { print mode }
-          print(modes[index]);
+    { check for empty list }
+    if Length(modes) = 0 then
+      { the console mode list was empty }
+      Writeln('[console mode list is not available]')
+    else
+    begin
+      { print mode list header }
+      Writeln('[console modes]');
 
 
-          { next mode }
-          Inc(index);
-        end;
+      { iterate through all modes }
+      for index := Low(modes) to High(modes) do
+      begin
+        { print mode }
+        print(modes[index]);
       end;
       end;
-    finally
-      console.Free;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 9 - 11
packages/ptc/examples/mojo.pp

@@ -520,7 +520,7 @@ begin
   frandtab_seed := (frandtab_seed + 1) and $FFFF;
   frandtab_seed := (frandtab_seed + 1) and $FFFF;
 end;
 end;
 
 
-procedure VLightPart(console: TPTCConsole; surface: TPTCSurface);
+procedure VLightPart(console: IPTCConsole; surface: IPTCSurface);
 var
 var
   vl: VLight = nil;
   vl: VLight = nil;
   vl2: VLight = nil;
   vl2: VLight = nil;
@@ -705,33 +705,31 @@ begin
 end;
 end;
 
 
 var
 var
-  format: TPTCFormat = nil;
-  console: TPTCConsole = nil;
-  surface: TPTCSurface = nil;
+  format: IPTCFormat;
+  console: IPTCConsole;
+  surface: IPTCSurface;
 begin
 begin
   try
   try
     try
     try
       { create format }
       { create format }
-      format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+      format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
 
 
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { open console }
       { open console }
       console.open('mojo by statix', 320, 200, format);
       console.open('mojo by statix', 320, 200, format);
 
 
       { create main drawing surface }
       { create main drawing surface }
-      surface := TPTCSurface.Create(320, 200, format);
+      surface := TPTCSurfaceFactory.CreateNew(320, 200, format);
 
 
       { do the light effect }
       { do the light effect }
       VLightPart(console, surface);
       VLightPart(console, surface);
 
 
     finally
     finally
       { close console }
       { close console }
-      console.close;
-      console.Free;
-      surface.Free;
-      format.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
 
 
     { print message to stdout }
     { print message to stdout }

+ 16 - 19
packages/ptc/examples/mouse.pp

@@ -8,13 +8,13 @@ program MouseExample;
 {$MODE objfpc}
 {$MODE objfpc}
 
 
 uses
 uses
-  ptc;
+  ptc, SysUtils;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  surface: TPTCSurface = nil;
-  format: TPTCFormat = nil;
-  event: TPTCEvent = nil;
+  console: IPTCConsole;
+  surface: IPTCSurface;
+  format: IPTCFormat;
+  event: IPTCEvent;
   pixels: PUint32;
   pixels: PUint32;
   color: Uint32;
   color: Uint32;
   width, height: Integer;
   width, height: Integer;
@@ -26,10 +26,10 @@ begin
   try
   try
     try
     try
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { create format }
       { create format }
-      format := TPTCFormat.Create(32, $FF0000, $FF00, $FF);
+      format := TPTCFormatFactory.CreateNew(32, $FF0000, $FF00, $FF);
 
 
       { open the console }
       { open the console }
       console.open('Mouse example', format);
       console.open('Mouse example', format);
@@ -38,7 +38,7 @@ begin
       console.option('hide cursor');
       console.option('hide cursor');
 
 
       { create surface matching console dimensions }
       { create surface matching console dimensions }
-      surface := TPTCSurface.Create(console.width, console.height, format);
+      surface := TPTCSurfaceFactory.CreateNew(console.width, console.height, format);
 
 
       { initialization }
       { initialization }
       X := 0;
       X := 0;
@@ -49,20 +49,20 @@ begin
         console.NextEvent(event, True, PTCAnyEvent);
         console.NextEvent(event, True, PTCAnyEvent);
 
 
         { handle mouse events }
         { handle mouse events }
-        if event is TPTCMouseEvent then
+        if Supports(event, IPTCMouseEvent) then
         begin
         begin
           { if there's more than one mouse event, process them all... }
           { if there's more than one mouse event, process them all... }
           repeat
           repeat
-            X := (event as TPTCMouseEvent).X;
-            Y := (event as TPTCMouseEvent).Y;
-            button := PTCMouseButton1 in (event as TPTCMouseEvent).ButtonState;
+            X := (event as IPTCMouseEvent).X;
+            Y := (event as IPTCMouseEvent).Y;
+            button := PTCMouseButton1 in (event as IPTCMouseEvent).ButtonState;
           until not console.NextEvent(event, False, [PTCMouseEvent]);
           until not console.NextEvent(event, False, [PTCMouseEvent]);
         end;
         end;
 
 
         { handle keyboard events }
         { handle keyboard events }
-        if (event is TPTCKeyEvent) and (event as TPTCKeyEvent).Press then
+        if Supports(event, IPTCKeyEvent) and (event as IPTCKeyEvent).Press then
         begin
         begin
-          case (event as TPTCKeyEvent).Code of
+          case (event as IPTCKeyEvent).Code of
             PTCKEY_G: console.Option('grab mouse');
             PTCKEY_G: console.Option('grab mouse');
             PTCKEY_U: console.Option('ungrab mouse');
             PTCKEY_U: console.Option('ungrab mouse');
             PTCKEY_ESCAPE: Done := True;
             PTCKEY_ESCAPE: Done := True;
@@ -114,11 +114,8 @@ begin
 
 
       until Done;
       until Done;
     finally
     finally
-      console.close;
-      console.Free;
-      surface.Free;
-      format.Free;
-      event.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 13 - 16
packages/ptc/examples/palette.pp

@@ -16,10 +16,10 @@ uses
   ptc;
   ptc;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  surface: TPTCSurface = nil;
-  format: TPTCFormat = nil;
-  palette: TPTCPalette = nil;
+  console: IPTCConsole;
+  surface: IPTCSurface;
+  format: IPTCFormat;
+  palette: IPTCPalette;
   data: array [0..255] of Uint32;
   data: array [0..255] of Uint32;
   pixels: PUint8;
   pixels: PUint8;
   width, height: Integer;
   width, height: Integer;
@@ -29,32 +29,32 @@ begin
   try
   try
     try
     try
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { create format }
       { create format }
-      format := TPTCFormat.Create(8);
+      format := TPTCFormatFactory.CreateNew(8);
 
 
       { open console }
       { open console }
       console.open('Palette example', format);
       console.open('Palette example', format);
 
 
       { create surface }
       { create surface }
-      surface := TPTCSurface.Create(console.width, console.height, format);
+      surface := TPTCSurfaceFactory.CreateNew(console.width, console.height, format);
 
 
       { create palette }
       { create palette }
-      palette := TPTCPalette.Create;
+      palette := TPTCPaletteFactory.CreateNew;
 
 
       { generate palette }
       { generate palette }
       for i := 0 to 255 do
       for i := 0 to 255 do
         data[i] := i;
         data[i] := i;
 
 
       { load palette data }
       { load palette data }
-      palette.load(data);
+      palette.Load(data);
 
 
       { set console palette }
       { set console palette }
-      console.palette(palette);
+      console.Palette(palette);
 
 
       { set surface palette }
       { set surface palette }
-      surface.palette(palette);
+      surface.Palette(palette);
 
 
       { loop until a key is pressed }
       { loop until a key is pressed }
       while not console.KeyPressed do
       while not console.KeyPressed do
@@ -92,11 +92,8 @@ begin
         console.update;
         console.update;
       end;
       end;
     finally
     finally
-      console.close;
-      console.Free;
-      surface.Free;
-      palette.Free;
-      format.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 9 - 11
packages/ptc/examples/pixel.pp

@@ -15,7 +15,7 @@ program PixelExample;
 uses
 uses
   ptc;
   ptc;
 
 
-procedure putpixel(surface: TPTCSurface; x, y: Integer; r, g, b: Uint8);
+procedure putpixel(surface: IPTCSurface; x, y: Integer; r, g, b: Uint8);
 var
 var
   pixels: PUint32;
   pixels: PUint32;
   color: Uint32;
   color: Uint32;
@@ -35,23 +35,23 @@ begin
 end;
 end;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  surface: TPTCSurface = nil;
-  format: TPTCFormat = nil;
+  console: IPTCConsole;
+  surface: IPTCSurface;
+  format: IPTCFormat;
 begin
 begin
   try
   try
     try
     try
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { create format }
       { create format }
-      format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+      format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
 
 
       { open the console }
       { open the console }
       console.open('Pixel example', format);
       console.open('Pixel example', format);
 
 
       { create surface matching console dimensions }
       { create surface matching console dimensions }
-      surface := TPTCSurface.Create(console.width, console.height, format);
+      surface := TPTCSurfaceFactory.CreateNew(console.width, console.height, format);
 
 
       { plot a white pixel in the middle of the surface }
       { plot a white pixel in the middle of the surface }
       putpixel(surface, surface.width div 2, surface.height div 2, 255, 255, 255);
       putpixel(surface, surface.width div 2, surface.height div 2, 255, 255, 255);
@@ -65,10 +65,8 @@ begin
       { read key }
       { read key }
       console.ReadKey;
       console.ReadKey;
     finally
     finally
-      console.close;
-      console.Free;
-      surface.Free;
-      format.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 8 - 10
packages/ptc/examples/random.pp

@@ -16,9 +16,9 @@ uses
   ptc;
   ptc;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  surface: TPTCSurface = nil;
-  format: TPTCFormat = nil;
+  console: IPTCConsole;
+  surface: IPTCSurface;
+  format: IPTCFormat;
   pixels: PUint32;
   pixels: PUint32;
   width, height: Integer;
   width, height: Integer;
   i: Integer;
   i: Integer;
@@ -27,16 +27,16 @@ begin
   try
   try
     try
     try
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { create format }
       { create format }
-      format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+      format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
 
 
       { open the console }
       { open the console }
       console.open('Random example', format);
       console.open('Random example', format);
 
 
       { create surface matching console dimensions }
       { create surface matching console dimensions }
-      surface := TPTCSurface.Create(console.width, console.height, format);
+      surface := TPTCSurfaceFactory.CreateNew(console.width, console.height, format);
 
 
       { loop until a key is pressed }
       { loop until a key is pressed }
       while not console.KeyPressed do
       while not console.KeyPressed do
@@ -75,10 +75,8 @@ begin
         console.update;
         console.update;
       end;
       end;
     finally
     finally
-      console.close;
-      console.Free;
-      surface.Free;
-      format.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 19 - 29
packages/ptc/examples/save.pp

@@ -15,15 +15,14 @@ program SaveExample;
 uses
 uses
   ptc, Math;
   ptc, Math;
 
 
-procedure save(surface: TPTCSurface; filename: string);
+procedure save(surface: IPTCSurface; filename: string);
 var
 var
   F: File;
   F: File;
   width, height: Integer;
   width, height: Integer;
   size: Integer;
   size: Integer;
   y: Integer;
   y: Integer;
   pixels: PUint8 = nil;
   pixels: PUint8 = nil;
-  format: TPTCFormat = nil;
-  palette: TPTCPalette = nil;
+  format: IPTCFormat;
   { generate the header for a true color targa image }
   { generate the header for a true color targa image }
   header: array [0..17] of Uint8 =
   header: array [0..17] of Uint8 =
     (0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
     (0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
@@ -58,14 +57,13 @@ begin
     pixels := GetMem(size);
     pixels := GetMem(size);
 
 
     {$IFDEF FPC_LITTLE_ENDIAN}
     {$IFDEF FPC_LITTLE_ENDIAN}
-    format := TPTCFormat.Create(24, $00FF0000, $0000FF00, $000000FF);
+    format := TPTCFormatFactory.CreateNew(24, $00FF0000, $0000FF00, $000000FF);
     {$ELSE FPC_LITTLE_ENDIAN}
     {$ELSE FPC_LITTLE_ENDIAN}
-    format := TPTCFormat.Create(24, $000000FF, $0000FF00, $00FF0000);
+    format := TPTCFormatFactory.CreateNew(24, $000000FF, $0000FF00, $00FF0000);
     {$ENDIF FPC_LITTLE_ENDIAN}
     {$ENDIF FPC_LITTLE_ENDIAN}
-    palette := TPTCPalette.Create;
 
 
     { save surface to image pixels }
     { save surface to image pixels }
-    surface.save(pixels, width, height, width * 3, format, palette);
+    surface.save(pixels, width, height, width * 3, format, TPTCPaletteFactory.CreateNew);
 
 
     { write image pixels one line at a time }
     { write image pixels one line at a time }
     for y := height - 1 DownTo 0 do
     for y := height - 1 DownTo 0 do
@@ -75,9 +73,6 @@ begin
     { free image pixels }
     { free image pixels }
     FreeMem(pixels);
     FreeMem(pixels);
 
 
-    palette.Free;
-    format.Free;
-
     CloseFile(F);
     CloseFile(F);
   end;
   end;
 end;
 end;
@@ -128,7 +123,7 @@ begin
   calculate := 0;
   calculate := 0;
 end;
 end;
 
 
-procedure mandelbrot(console: TPTCConsole; surface: TPTCSurface;
+procedure mandelbrot(console: IPTCConsole; surface: IPTCSurface;
                      x1, y1, x2, y2: Single);
                      x1, y1, x2, y2: Single);
 const
 const
   { constant values }
   { constant values }
@@ -149,7 +144,7 @@ var
   count: Integer;
   count: Integer;
   index: Integer;
   index: Integer;
   color: Uint32;
   color: Uint32;
-  area: TPTCArea;
+  area: IPTCArea;
 begin
 begin
   { generate fractal color table }
   { generate fractal color table }
   for i := 0 to entries - 1 do
   for i := 0 to entries - 1 do
@@ -219,13 +214,10 @@ begin
       imaginary := imaginary + dy;
       imaginary := imaginary + dy;
 
 
       { setup line area }
       { setup line area }
-      area := TPTCArea.Create(0, y, width, y + 1);
-      try
-        { copy surface area to console }
-        surface.copy(console, area, area);
-      finally
-        area.Free;
-      end;
+      area := TPTCAreaFactory.CreateNew(0, y, width, y + 1);
+
+      { copy surface area to console }
+      surface.copy(console, area, area);
 
 
       { update console area }
       { update console area }
       console.update;
       console.update;
@@ -237,24 +229,24 @@ begin
 end;
 end;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  surface: TPTCSurface = nil;
-  format: TPTCFormat = nil;
+  console: IPTCConsole;
+  surface: IPTCSurface;
+  format: IPTCFormat;
   x1, y1, x2, y2: Single;
   x1, y1, x2, y2: Single;
 begin
 begin
   try
   try
     try
     try
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { create format }
       { create format }
-      format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+      format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
 
 
       { open the console with a single page }
       { open the console with a single page }
       console.open('Save example', format, 1);
       console.open('Save example', format, 1);
 
 
       { create surface matching console dimensions }
       { create surface matching console dimensions }
-      surface := TPTCSurface.Create(console.width, console.height, format);
+      surface := TPTCSurfaceFactory.CreateNew(console.width, console.height, format);
 
 
       { setup viewing area }
       { setup viewing area }
       x1 := -2.00;
       x1 := -2.00;
@@ -271,10 +263,8 @@ begin
       { read key }
       { read key }
       console.ReadKey;
       console.ReadKey;
     finally
     finally
-      console.close;
-      console.Free;
-      surface.Free;
-      format.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 29 - 49
packages/ptc/examples/stretch.pp

@@ -15,14 +15,13 @@ program StretchExample;
 uses
 uses
   ptc;
   ptc;
 
 
-procedure load(surface: TPTCSurface; filename: String);
+procedure load(surface: IPTCSurface; filename: string);
 var
 var
   F: File;
   F: File;
   width, height: Integer;
   width, height: Integer;
   pixels: PByte = nil;
   pixels: PByte = nil;
   y: Integer;
   y: Integer;
-  tmp: TPTCFormat;
-  tmp2: TPTCPalette;
+  format: IPTCFormat;
 begin
 begin
   { open image file }
   { open image file }
   AssignFile(F, filename);
   AssignFile(F, filename);
@@ -45,20 +44,11 @@ begin
 
 
     { load pixels to surface }
     { load pixels to surface }
     {$IFDEF FPC_LITTLE_ENDIAN}
     {$IFDEF FPC_LITTLE_ENDIAN}
-    tmp := TPTCFormat.Create(24, $00FF0000, $0000FF00, $000000FF);
+    format := TPTCFormatFactory.CreateNew(24, $00FF0000, $0000FF00, $000000FF);
     {$ELSE FPC_LITTLE_ENDIAN}
     {$ELSE FPC_LITTLE_ENDIAN}
-    tmp := TPTCFormat.Create(24, $000000FF, $0000FF00, $00FF0000);
+    format := TPTCFormatFactory.CreateNew(24, $000000FF, $0000FF00, $00FF0000);
     {$ENDIF FPC_LITTLE_ENDIAN}
     {$ENDIF FPC_LITTLE_ENDIAN}
-    try
-      tmp2 := TPTCPalette.Create;
-      try
-        surface.load(pixels, width, height, width * 3, tmp, tmp2);
-      finally
-        tmp2.Free;
-      end;
-    finally
-      tmp.Free;
-    end;
+    surface.Load(pixels, width, height, width * 3, format, TPTCPaletteFactory.CreateNew);
   finally
   finally
     { free image pixels }
     { free image pixels }
     FreeMem(pixels);
     FreeMem(pixels);
@@ -69,13 +59,12 @@ begin
 end;
 end;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  surface: TPTCSurface = nil;
-  image: TPTCSurface = nil;
-  format: TPTCFormat = nil;
-  timer: TPTCTimer = nil;
-  area: TPTCArea = nil;
-  color: TPTCColor = nil;
+  console: IPTCConsole;
+  surface: IPTCSurface;
+  image: IPTCSurface;
+  format: IPTCFormat;
+  timer: IPTCTimer;
+  area: IPTCArea;
   time: Double;
   time: Double;
   zoom: Single;
   zoom: Single;
   x, y, x1, y1, x2, y2, dx, dy: Integer;
   x, y, x1, y1, x2, y2, dx, dy: Integer;
@@ -83,19 +72,19 @@ begin
   try
   try
     try
     try
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { create format }
       { create format }
-      format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+      format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
 
 
       { open the console }
       { open the console }
       console.open('Stretch example', format);
       console.open('Stretch example', format);
 
 
       { create surface matching console dimensions }
       { create surface matching console dimensions }
-      surface := TPTCSurface.Create(console.width, console.height, format);
+      surface := TPTCSurfaceFactory.CreateNew(console.width, console.height, format);
 
 
       { create image surface }
       { create image surface }
-      image := TPTCSurface.Create(320, 140, format);
+      image := TPTCSurfaceFactory.CreateNew(320, 140, format);
 
 
       { load image to surface }
       { load image to surface }
       load(image, 'stretch.tga');
       load(image, 'stretch.tga');
@@ -107,11 +96,10 @@ begin
       dy := surface.height div 3;
       dy := surface.height div 3;
 
 
       { create timer }
       { create timer }
-      timer := TPTCTimer.Create;
+      timer := TPTCTimerFactory.CreateNew;
 
 
       { start timer }
       { start timer }
       timer.start;
       timer.start;
-      color := TPTCColor.Create(1, 1, 1);
 
 
       { loop until a key is pressed }
       { loop until a key is pressed }
       while not console.KeyPressed do
       while not console.KeyPressed do
@@ -120,7 +108,7 @@ begin
         time := timer.time;
         time := timer.time;
 
 
         { clear surface to white background }
         { clear surface to white background }
-        surface.clear(color);
+        surface.clear(TPTCColorFactory.CreateNew(1, 1, 1));
 
 
         { calculate zoom factor at current time }
         { calculate zoom factor at current time }
         zoom := 2.5 * (1 - cos(time));
         zoom := 2.5 * (1 - cos(time));
@@ -132,28 +120,20 @@ begin
         y2 := Trunc(y + zoom * dy);
         y2 := Trunc(y + zoom * dy);
 
 
         { setup image copy area }
         { setup image copy area }
-        area := TPTCArea.Create(x1, y1, x2, y2);
-        try
-          { copy and stretch image to surface }
-          image.copy(surface, image.area, area);
-
-          { copy surface to console }
-          surface.copy(console);
-
-          { update console }
-          console.update;
-        finally
-          area.Free;
-        end;
+        area := TPTCAreaFactory.CreateNew(x1, y1, x2, y2);
+
+        { copy and stretch image to surface }
+        image.copy(surface, image.area, area);
+
+        { copy surface to console }
+        surface.copy(console);
+
+        { update console }
+        console.update;
       end;
       end;
     finally
     finally
-      console.close;
-      console.Free;
-      surface.Free;
-      format.Free;
-      image.Free;
-      color.Free;
-      timer.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 12 - 15
packages/ptc/examples/texwarp.pp

@@ -22,7 +22,7 @@ const
   green_balance: Uint32 = 3;
   green_balance: Uint32 = 3;
   blue_balance: Uint32 = 1;
   blue_balance: Uint32 = 1;
 
 
-procedure blur(s: TPTCSurface);
+procedure blur(s: IPTCSurface);
 var
 var
   d: PUint8;
   d: PUint8;
   pitch: Integer;
   pitch: Integer;
@@ -60,7 +60,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure generate(surface: TPTCSurface);
+procedure generate(surface: IPTCSurface);
 var
 var
   dest: PUint32;
   dest: PUint32;
   i: Integer;
   i: Integer;
@@ -256,10 +256,10 @@ begin
 end;
 end;
 
 
 var
 var
-  format: TPTCFormat = nil;
-  texture: TPTCSurface = nil;
-  surface: TPTCSurface = nil;
-  console: TPTCConsole = nil;
+  format: IPTCFormat;
+  texture: IPTCSurface;
+  surface: IPTCSurface;
+  console: IPTCConsole;
   lighttable: PUint8 = nil;
   lighttable: PUint8 = nil;
   { texture grid }
   { texture grid }
   grid: array [0..41*26*3-1] of Uint32;
   grid: array [0..41*26*3-1] of Uint32;
@@ -270,10 +270,10 @@ begin
   try
   try
     try
     try
       { create format }
       { create format }
-      format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+      format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
 
 
       { create texture surface }
       { create texture surface }
-      texture := TPTCSurface.Create(256, 256, format);
+      texture := TPTCSurfaceFactory.CreateNew(256, 256, format);
 
 
       { create texture }
       { create texture }
       generate(texture);
       generate(texture);
@@ -283,13 +283,13 @@ begin
       make_light_table(lighttable);
       make_light_table(lighttable);
 
 
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { open console }
       { open console }
       console.open('Warp demo', 320, 200, format);
       console.open('Warp demo', 320, 200, format);
 
 
       { create drawing surface }
       { create drawing surface }
-      surface := TPTCSurface.Create(320, 200, format);
+      surface := TPTCSurfaceFactory.CreateNew(320, 200, format);
 
 
       { control values }
       { control values }
       xbase := 0;
       xbase := 0;
@@ -365,11 +365,8 @@ begin
         end;
         end;
       end;
       end;
     finally
     finally
-      console.close;
-      console.Free;
-      surface.Free;
-      texture.Free;
-      format.Free;
+      if Assigned(console) then
+        console.close;
       FreeMem(lighttable);
       FreeMem(lighttable);
     end;
     end;
   except
   except

+ 10 - 13
packages/ptc/examples/timer.pp

@@ -16,10 +16,10 @@ uses
   ptc;
   ptc;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  format: TPTCFormat = nil;
-  surface: TPTCSurface = nil;
-  timer: TPTCTimer = nil;
+  console: IPTCConsole;
+  format: IPTCFormat;
+  surface: IPTCSurface;
+  timer: IPTCTimer;
   time, t: Double;
   time, t: Double;
   pixels: PDWord;
   pixels: PDWord;
   width, height: Integer;
   width, height: Integer;
@@ -29,19 +29,19 @@ begin
   try
   try
     try
     try
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { create format }
       { create format }
-      format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+      format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
 
 
       { open the console }
       { open the console }
       console.open('Timer example', format);
       console.open('Timer example', format);
 
 
       { create surface matching console dimensions }
       { create surface matching console dimensions }
-      surface := TPTCSurface.Create(console.width, console.height, format);
+      surface := TPTCSurfaceFactory.CreateNew(console.width, console.height, format);
 
 
       { create timer }
       { create timer }
-      timer := TPTCTimer.Create;
+      timer := TPTCTimerFactory.CreateNew;
 
 
       { start timer }
       { start timer }
       timer.start;
       timer.start;
@@ -97,11 +97,8 @@ begin
         console.update;
         console.update;
       end;
       end;
     finally
     finally
-      timer.Free;
-      surface.Free;
-      console.close;
-      console.Free;
-      format.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 8 - 10
packages/ptc/examples/tunnel.pp

@@ -117,9 +117,9 @@ begin
 end;
 end;
 
 
 var
 var
-  format: TPTCFormat = nil;
-  console: TPTCConsole = nil;
-  surface: TPTCSurface = nil;
+  format: IPTCFormat;
+  console: IPTCConsole;
+  surface: IPTCSurface;
   TheTunnel: TTunnel = nil;
   TheTunnel: TTunnel = nil;
   time, delta: Single;
   time, delta: Single;
   buffer: PUint32;
   buffer: PUint32;
@@ -127,16 +127,16 @@ begin
   try
   try
     try
     try
       { create format }
       { create format }
-      format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+      format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
 
 
       { create console }
       { create console }
-      console := TPTCConsole.Create;
+      console := TPTCConsoleFactory.CreateNew;
 
 
       { open console }
       { open console }
       console.open('Tunnel demo', 320, 200, format);
       console.open('Tunnel demo', 320, 200, format);
 
 
       { create surface }
       { create surface }
-      surface := TPTCSurface.Create(320, 200, format);
+      surface := TPTCSurfaceFactory.CreateNew(320, 200, format);
 
 
       { create tunnel }
       { create tunnel }
       TheTunnel := TTunnel.Create;
       TheTunnel := TTunnel.Create;
@@ -169,10 +169,8 @@ begin
       end;
       end;
     finally
     finally
       TheTunnel.Free;
       TheTunnel.Free;
-      surface.Free;
-      console.close;
-      console.Free;
-      format.Free;
+      if Assigned(console) then
+        console.close;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 20 - 22
packages/ptc/examples/tunnel3d.pp

@@ -343,7 +343,7 @@ begin
 
 
         { Calculate texture index at intersection point (cylindrical mapping) }
         { Calculate texture index at intersection point (cylindrical mapping) }
         { try and adjust the 0.2 to stretch/shrink the texture }
         { try and adjust the 0.2 to stretch/shrink the texture }
-        u_array[(j shl 6) + i] := Trunc(intsc[2] * 0.2) shl 16;
+        u_array[(j shl 6) + i] := Integer(Trunc(intsc[2] * 0.2) shl 16);
         v_array[(j shl 6) + i] := Trunc(abs(arctan2(intsc[1], intsc[0]) * 256 / pi)) shl 16;
         v_array[(j shl 6) + i] := Trunc(abs(arctan2(intsc[1], intsc[0]) * 256 / pi)) shl 16;
 
 
         { Calculate the dotproduct between the normal vector and the vector }
         { Calculate the dotproduct between the normal vector and the vector }
@@ -396,23 +396,23 @@ begin
 
 
       { Set up gradients }
       { Set up gradients }
       lu := u_array[iadr]; ru := u_array[iadr + 1];
       lu := u_array[iadr]; ru := u_array[iadr + 1];
-      liu := (u_array[iadr + 64] - lu) shr 3;
-      riu := (u_array[iadr + 65] - ru) shr 3;
+      liu := (u_array[iadr + 64] - lu) div 8;
+      riu := (u_array[iadr + 65] - ru) div 8;
 
 
       lv := v_array[iadr]; rv := v_array[iadr + 1];
       lv := v_array[iadr]; rv := v_array[iadr + 1];
-      liv := (v_array[iadr + 64] - lv) shr 3;
-      riv := (v_array[iadr + 65] - rv) shr 3;
+      liv := (v_array[iadr + 64] - lv) div 8;
+      riv := (v_array[iadr + 65] - rv) div 8;
 
 
       ll := l_array[iadr]; rl := l_array[iadr + 1];
       ll := l_array[iadr]; rl := l_array[iadr + 1];
-      lil := (l_array[iadr + 64] - ll) shr 3;
-      ril := (l_array[iadr + 65] - rl) shr 3;
+      lil := (l_array[iadr + 64] - ll) div 8;
+      ril := (l_array[iadr + 65] - rl) div 8;
 
 
       for y := 0 to 7 do
       for y := 0 to 7 do
       begin
       begin
-        iu := (ru - lu) shr 3;
-        iv := (rv - lv) shr 3;
+        iu := (ru - lu) div 8;
+        iv := (rv - lv) div 8;
         l := ll;
         l := ll;
-        il := (rl - ll) shr 3;
+        il := (rl - ll) div 8;
 
 
         { Mess up everything for the sake of cache optimised mapping :) }
         { Mess up everything for the sake of cache optimised mapping :) }
         til_u := DWord(((lu shl 8) and $F8000000) or ((lu shr 1) and $00007FFF) or (lu and $00070000));
         til_u := DWord(((lu shl 8) and $F8000000) or ((lu shr 1) and $00007FFF) or (lu and $00070000));
@@ -426,8 +426,8 @@ begin
         for x := 0 to 7 do
         for x := 0 to 7 do
         begin
         begin
           { Interpolate texture u,v and light }
           { Interpolate texture u,v and light }
-          Inc(til_u, til_iu);
-          Inc(til_v, til_iv);
+          til_u := DWord(til_u + til_iu);
+          til_v := DWord(til_v + til_iv);
           Inc(l, il);
           Inc(l, il);
 
 
           adr := adr shr 16;
           adr := adr shr 16;
@@ -502,9 +502,9 @@ begin
 end;
 end;
 
 
 var
 var
-  console: TPTCConsole = nil;
-  surface: TPTCSurface = nil;
-  format: TPTCFormat = nil;
+  console: IPTCConsole;
+  surface: IPTCSurface;
+  format: IPTCFormat;
   tunnel: TRayTunnel = nil;
   tunnel: TRayTunnel = nil;
   posz, phase_x, phase_y: Single;
   posz, phase_x, phase_y: Single;
   angle_x, angle_y: Integer;
   angle_x, angle_y: Integer;
@@ -512,12 +512,12 @@ var
 begin
 begin
   try
   try
     try
     try
-      format := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+      format := TPTCFormatFactory.CreateNew(32, $00FF0000, $0000FF00, $000000FF);
 
 
-      console := TPTCConsole.create;
+      console := TPTCConsoleFactory.CreateNew;
       console.open('Tunnel3D demo', 320, 200, format);
       console.open('Tunnel3D demo', 320, 200, format);
 
 
-      surface := TPTCSurface.create(320, 200, format);
+      surface := TPTCSurfaceFactory.CreateNew(320, 200, format);
 
 
       { Create a tunnel, radius=700 }
       { Create a tunnel, radius=700 }
       tunnel := TRayTunnel.Create(700);
       tunnel := TRayTunnel.Create(700);
@@ -554,11 +554,9 @@ begin
         phase_y := phase_y + 0.1;
         phase_y := phase_y + 0.1;
       end;
       end;
     finally
     finally
-      console.close;
-      console.Free;
-      surface.Free;
+      if Assigned(console) then
+        console.close;
       tunnel.Free;
       tunnel.Free;
-      format.Free;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do

+ 19 - 13
packages/ptc/src/core/aread.inc

@@ -31,21 +31,27 @@
 }
 }
 
 
 type
 type
-  TPTCArea = class
-  private
-    FLeft, FTop, FRight, FBottom: Integer;
+  IPTCArea = interface
+    function GetLeft: Integer;
+    function GetTop: Integer;
+    function GetRight: Integer;
+    function GetBottom: Integer;
     function GetWidth: Integer;
     function GetWidth: Integer;
     function GetHeight: Integer;
     function GetHeight: Integer;
-  public
-    constructor Create;
-    constructor Create(ALeft, ATop, ARight, ABottom: Integer);
-    constructor Create(const AArea: TPTCArea);
-    procedure Assign(const AArea: TPTCArea);
-    function Equals(const AArea: TPTCArea): Boolean;
-    property Left: Integer read FLeft;
-    property Top: Integer read FTop;
-    property Right: Integer read FRight;
-    property Bottom: Integer read FBottom;
+
+    function Equals(AArea: IPTCArea): Boolean;
+
+    property Left: Integer read GetLeft;
+    property Top: Integer read GetTop;
+    property Right: Integer read GetRight;
+    property Bottom: Integer read GetBottom;
     property Width: Integer read GetWidth;
     property Width: Integer read GetWidth;
     property Height: Integer read GetHeight;
     property Height: Integer read GetHeight;
   end;
   end;
+
+  TPTCAreaFactory = class
+  public
+    class function CreateNew: IPTCArea;
+    class function CreateNew(ALeft, ATop, ARight, ABottom: Integer): IPTCArea;
+    class function CreateNew(AArea: IPTCArea): IPTCArea;
+  end;

+ 59 - 15
packages/ptc/src/core/areai.inc

@@ -30,6 +30,38 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 }
 }
 
 
+type
+  TPTCArea = class(TInterfacedObject, IPTCArea)
+  private
+    FLeft, FTop, FRight, FBottom: Integer;
+    function GetLeft: Integer;
+    function GetTop: Integer;
+    function GetRight: Integer;
+    function GetBottom: Integer;
+    function GetWidth: Integer;
+    function GetHeight: Integer;
+    function Equals(AArea: IPTCArea): Boolean;
+  public
+    constructor Create;
+    constructor Create(ALeft, ATop, ARight, ABottom: Integer);
+    constructor Create(AArea: IPTCArea);
+  end;
+
+class function TPTCAreaFactory.CreateNew: IPTCArea;
+begin
+  Result := TPTCArea.Create;
+end;
+
+class function TPTCAreaFactory.CreateNew(ALeft, ATop, ARight, ABottom: Integer): IPTCArea;
+begin
+  Result := TPTCArea.Create(ALeft, ATop, ARight, ABottom);
+end;
+
+class function TPTCAreaFactory.CreateNew(AArea: IPTCArea): IPTCArea;
+begin
+  Result := TPTCArea.Create(AArea);
+end;
+
 constructor TPTCArea.Create(ALeft, ATop, ARight, ABottom: Integer);
 constructor TPTCArea.Create(ALeft, ATop, ARight, ABottom: Integer);
 begin
 begin
   if ALeft < ARight then
   if ALeft < ARight then
@@ -62,28 +94,40 @@ begin
   FBottom := 0;
   FBottom := 0;
 end;
 end;
 
 
-constructor TPTCArea.Create(const AArea: TPTCArea);
+constructor TPTCArea.Create(AArea: IPTCArea);
+begin
+  FLeft   := AArea.Left;
+  FTop    := AArea.Top;
+  FRight  := AArea.Right;
+  FBottom := AArea.Bottom;
+end;
+
+function TPTCArea.Equals(AArea: IPTCArea): Boolean;
+begin
+  Result := (FLeft   = AArea.Left) and
+            (FTop    = AArea.Top) and
+            (FRight  = AArea.Right) and
+            (FBottom = AArea.Bottom);
+end;
+
+function TPTCArea.GetLeft: Integer;
+begin
+  Result := FLeft;
+end;
+
+function TPTCArea.GetTop: Integer;
 begin
 begin
-  FLeft   := AArea.FLeft;
-  FTop    := AArea.FTop;
-  FRight  := AArea.FRight;
-  FBottom := AArea.FBottom;
+  Result := FTop;
 end;
 end;
 
 
-procedure TPTCArea.Assign(const AArea: TPTCArea);
+function TPTCArea.GetRight: Integer;
 begin
 begin
-  FLeft   := AArea.FLeft;
-  FTop    := AArea.FTop;
-  FRight  := AArea.FRight;
-  FBottom := AArea.FBottom;
+  Result := FRight;
 end;
 end;
 
 
-function TPTCArea.Equals(const AArea: TPTCArea): Boolean;
+function TPTCArea.GetBottom: Integer;
 begin
 begin
-  Result := (FLeft   = AArea.FLeft) and
-            (FTop    = AArea.FTop) and
-            (FRight  = AArea.FRight) and
-            (FBottom = AArea.FBottom);
+  Result := FBottom;
 end;
 end;
 
 
 function TPTCArea.GetWidth: Integer;
 function TPTCArea.GetWidth: Integer;

+ 27 - 27
packages/ptc/src/core/baseconsoled.inc

@@ -31,43 +31,43 @@
 }
 }
 
 
 type
 type
-  TPTCBaseConsole = class(TPTCBaseSurface)
-  private
-    FReleaseEnabled: Boolean;
-    function GetPages: Integer; virtual; abstract;
-    function GetName: string; virtual; abstract;
-    function GetTitle: string; virtual; abstract;
-    function GetInformation: string; virtual; abstract;
-  public
-    constructor Create; virtual;
-    procedure Configure(const AFileName: String); virtual; abstract;
-    function Modes: PPTCMode; virtual; abstract;
-    procedure Open(const ATitle: string; APages: Integer = 0); overload; virtual; abstract;
-    procedure Open(const ATitle: string; const AFormat: TPTCFormat;
-                   APages: Integer = 0); overload; virtual; abstract;
+  IPTCConsole = interface(IPTCSurface)
+    function GetPages: Integer;
+    function GetName: string;
+    function GetTitle: string;
+    function GetInformation: string;
+
+    procedure Configure(const AFileName: string);
+    function Modes: TPTCModeList;
+    procedure Open(const ATitle: string; APages: Integer = 0); overload;
+    procedure Open(const ATitle: string; AFormat: IPTCFormat;
+                   APages: Integer = 0); overload;
     procedure Open(const ATitle: string; AWidth, AHeight: Integer;
     procedure Open(const ATitle: string; AWidth, AHeight: Integer;
-                   const AFormat: TPTCFormat; APages: Integer = 0); overload; virtual; abstract;
-    procedure Open(const ATitle: string; const AMode: TPTCMode;
-                   APages: Integer = 0); overload; virtual; abstract;
-    procedure Close; virtual; abstract;
-    procedure Flush; virtual; abstract;
-    procedure Finish; virtual; abstract;
-    procedure Update; virtual; abstract;
-    procedure Update(const AArea: TPTCArea); virtual; abstract;
+                   AFormat: IPTCFormat; APages: Integer = 0); overload;
+    procedure Open(const ATitle: string; AMode: IPTCMode;
+                   APages: Integer = 0); overload;
+    procedure Close;
+    procedure Flush;
+    procedure Finish;
+    procedure Update;
+    procedure Update(AArea: IPTCArea);
 
 
     { event handling }
     { event handling }
-    function NextEvent(var AEvent: TPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; virtual; abstract;
-    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): TPTCEvent; virtual; abstract;
+    function NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
+    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent;
 
 
     { key handling }
     { key handling }
     function KeyPressed: Boolean;
     function KeyPressed: Boolean;
-    function PeekKey(var AKey: TPTCKeyEvent): Boolean;
-    procedure ReadKey(var AKey: TPTCKeyEvent);
+    function PeekKey(out AKey: IPTCKeyEvent): Boolean;
+    procedure ReadKey(out AKey: IPTCKeyEvent);
     procedure ReadKey;
     procedure ReadKey;
-    property KeyReleaseEnabled: Boolean read FReleaseEnabled write FReleaseEnabled;
+    procedure SetKeyReleaseEnabled(AValue: Boolean);
+    function GetKeyReleaseEnabled: Boolean;
+    property KeyReleaseEnabled: Boolean read GetKeyReleaseEnabled write SetKeyReleaseEnabled;
 
 
     property Pages: Integer read GetPages;
     property Pages: Integer read GetPages;
     property Name: string read GetName;
     property Name: string read GetName;
     property Title: string read GetTitle;
     property Title: string read GetTitle;
     property Information: string read GetInformation;
     property Information: string read GetInformation;
   end;
   end;
+

+ 120 - 32
packages/ptc/src/core/baseconsolei.inc

@@ -30,6 +30,98 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 }
 }
 
 
+type
+  TPTCBaseConsole = class(TInterfacedObject, IPTCConsole, IPTCSurface)
+  private
+    FReleaseEnabled: Boolean;
+
+    procedure SetKeyReleaseEnabled(AValue: Boolean);
+    function GetKeyReleaseEnabled: Boolean;
+
+    function GetWidth: Integer; virtual; abstract;
+    function GetHeight: Integer; virtual; abstract;
+    function GetPitch: Integer; virtual; abstract;
+    function GetArea: IPTCArea; virtual; abstract;
+    function GetFormat: IPTCFormat; virtual; abstract;
+
+    function GetPages: Integer; virtual; abstract;
+    function GetName: string; virtual; abstract;
+    function GetTitle: string; virtual; abstract;
+    function GetInformation: string; virtual; abstract;
+  public
+    constructor Create; virtual;
+
+    procedure Copy(ASurface: IPTCSurface); virtual; abstract;
+    procedure Copy(ASurface: IPTCSurface;
+                   ASource, ADestination: IPTCArea); virtual; abstract;
+    function Lock: Pointer; virtual; abstract;
+    procedure Unlock; virtual; abstract;
+    procedure Load(const APixels: Pointer;
+                   AWidth, AHeight, APitch: Integer;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette); virtual; abstract;
+    procedure Load(const APixels: Pointer;
+                   AWidth, AHeight, APitch: Integer;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea); virtual; abstract;
+    procedure Save(APixels: Pointer;
+                   AWidth, AHeight, APitch: Integer;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette); virtual; abstract;
+    procedure Save(APixels: Pointer;
+                   AWidth, AHeight, APitch: Integer;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea); virtual; abstract;
+    procedure Clear; virtual; abstract;
+    procedure Clear(AColor: IPTCColor); virtual; abstract;
+    procedure Clear(AColor: IPTCColor;
+                    AArea: IPTCArea); virtual; abstract;
+    procedure Palette(APalette: IPTCPalette); virtual; abstract;
+    procedure Clip(AArea: IPTCArea); virtual; abstract;
+    function Option(const AOption: String): Boolean; virtual; abstract;
+    function Clip: IPTCArea; virtual; abstract;
+    function Palette: IPTCPalette; virtual; abstract;
+
+    procedure Configure(const AFileName: String); virtual; abstract;
+    function Modes: TPTCModeList; virtual; abstract;
+    procedure Open(const ATitle: string; APages: Integer = 0); overload; virtual; abstract;
+    procedure Open(const ATitle: string; AFormat: IPTCFormat;
+                   APages: Integer = 0); overload; virtual; abstract;
+    procedure Open(const ATitle: string; AWidth, AHeight: Integer;
+                   AFormat: IPTCFormat; APages: Integer = 0); overload; virtual; abstract;
+    procedure Open(const ATitle: string; AMode: IPTCMode;
+                   APages: Integer = 0); overload; virtual; abstract;
+    procedure Close; virtual; abstract;
+    procedure Flush; virtual; abstract;
+    procedure Finish; virtual; abstract;
+    procedure Update; virtual; abstract;
+    procedure Update(AArea: IPTCArea); virtual; abstract;
+
+    { event handling }
+    function NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; virtual; abstract;
+    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent; virtual; abstract;
+
+    { key handling }
+    function KeyPressed: Boolean;
+    function PeekKey(out AKey: IPTCKeyEvent): Boolean;
+    procedure ReadKey(out AKey: IPTCKeyEvent);
+    procedure ReadKey;
+    property KeyReleaseEnabled: Boolean read GetKeyReleaseEnabled write SetKeyReleaseEnabled;
+
+    property Pages: Integer read GetPages;
+    property Name: string read GetName;
+    property Title: string read GetTitle;
+    property Information: string read GetInformation;
+
+    property Width: Integer read GetWidth;
+    property Height: Integer read GetHeight;
+    property Pitch: Integer read GetPitch;
+    property Area: IPTCArea read GetArea;
+    property Format: IPTCFormat read GetFormat;
+  end;
+
 constructor TPTCBaseConsole.Create;
 constructor TPTCBaseConsole.Create;
 begin
 begin
   FReleaseEnabled := False;
   FReleaseEnabled := False;
@@ -37,38 +129,29 @@ end;
 
 
 function TPTCBaseConsole.KeyPressed: Boolean;
 function TPTCBaseConsole.KeyPressed: Boolean;
 var
 var
-  k, kpeek: TPTCEvent;
+  k, kpeek: IPTCEvent;
 begin
 begin
-  k := nil;
-  try
-    repeat
-      kpeek := PeekEvent(False, [PTCKeyEvent]);
-      if kpeek = nil then
-        exit(False);
-      if FReleaseEnabled or (kpeek As TPTCKeyEvent).Press then
-        exit(True);
-      NextEvent(k, False, [PTCKeyEvent]);
-    until False;
-  finally
-    k.Free;
-  end;
+  repeat
+    kpeek := PeekEvent(False, [PTCKeyEvent]);
+    if kpeek = nil then
+      exit(False);
+    if FReleaseEnabled or (kpeek as IPTCKeyEvent).Press then
+      exit(True);
+    NextEvent(k, False, [PTCKeyEvent]);
+  until False;
 end;
 end;
 
 
-procedure TPTCBaseConsole.ReadKey(var AKey: TPTCKeyEvent);
+procedure TPTCBaseConsole.ReadKey(out AKey: IPTCKeyEvent);
 var
 var
-  ev: TPTCEvent;
+  ev: IPTCEvent;
 begin
 begin
-  ev := AKey;
-  try
-    repeat
-      NextEvent(ev, True, [PTCKeyEvent]);
-    until FReleaseEnabled or (ev As TPTCKeyEvent).Press;
-  finally
-    AKey := ev As TPTCKeyEvent;
-  end;
+  repeat
+    NextEvent(ev, True, [PTCKeyEvent]);
+  until FReleaseEnabled or (ev as IPTCKeyEvent).Press;
+  AKey := ev as IPTCKeyEvent;
 end;
 end;
 
 
-function TPTCBaseConsole.PeekKey(var AKey: TPTCKeyEvent): Boolean;
+function TPTCBaseConsole.PeekKey(out AKey: IPTCKeyEvent): Boolean;
 begin
 begin
   if KeyPressed then
   if KeyPressed then
   begin
   begin
@@ -81,12 +164,17 @@ end;
 
 
 procedure TPTCBaseConsole.ReadKey;
 procedure TPTCBaseConsole.ReadKey;
 var
 var
-  k: TPTCKeyEvent;
+  k: IPTCKeyEvent;
 begin
 begin
-  k := TPTCKeyEvent.Create;
-  try
-    ReadKey(k);
-  finally
-    k.Free;
-  end;
+  ReadKey(k);
+end;
+
+procedure TPTCBaseConsole.SetKeyReleaseEnabled(AValue: Boolean);
+begin
+  FReleaseEnabled := AValue;
+end;
+
+function TPTCBaseConsole.GetKeyReleaseEnabled: Boolean;
+begin
+  Result := FReleaseEnabled;
 end;
 end;

+ 33 - 34
packages/ptc/src/core/basesurfaced.inc

@@ -31,49 +31,48 @@
 }
 }
 
 
 type
 type
-  TPTCBaseSurface = class
-  private
-    function GetWidth: Integer; virtual; abstract;
-    function GetHeight: Integer; virtual; abstract;
-    function GetPitch: Integer; virtual; abstract;
-    function GetArea: TPTCArea; virtual; abstract;
-    function GetFormat: TPTCFormat; virtual; abstract;
-  public
-    procedure Copy(ASurface: TPTCBaseSurface); virtual; abstract;
-    procedure Copy(ASurface: TPTCBaseSurface;
-                   const ASource, ADestination: TPTCArea); virtual; abstract;
-    function Lock: Pointer; virtual; abstract;
-    procedure Unlock; virtual; abstract;
+  IPTCSurface = interface
+    function GetWidth: Integer;
+    function GetHeight: Integer;
+    function GetPitch: Integer;
+    function GetArea: IPTCArea;
+    function GetFormat: IPTCFormat;
+
+    procedure Copy(ASurface: IPTCSurface);
+    procedure Copy(ASurface: IPTCSurface;
+                   ASource, ADestination: IPTCArea);
+    function Lock: Pointer;
+    procedure Unlock;
     procedure Load(const APixels: Pointer;
     procedure Load(const APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); virtual; abstract;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette);
     procedure Load(const APixels: Pointer;
     procedure Load(const APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); virtual; abstract;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea);
     procedure Save(APixels: Pointer;
     procedure Save(APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); virtual; abstract;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette);
     procedure Save(APixels: Pointer;
     procedure Save(APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); virtual; abstract;
-    procedure Clear; virtual; abstract;
-    procedure Clear(const AColor: TPTCColor); virtual; abstract;
-    procedure Clear(const AColor: TPTCColor;
-                    const AArea: TPTCArea); virtual; abstract;
-    procedure Palette(const APalette: TPTCPalette); virtual; abstract;
-    procedure Clip(const AArea: TPTCArea); virtual; abstract;
-    function Option(const AOption: String): Boolean; virtual; abstract;
-    function Clip: TPTCArea; virtual; abstract;
-    function Palette: TPTCPalette; virtual; abstract;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea);
+    procedure Clear;
+    procedure Clear(AColor: IPTCColor);
+    procedure Clear(AColor: IPTCColor;
+                    AArea: IPTCArea);
+    procedure Palette(APalette: IPTCPalette);
+    procedure Clip(AArea: IPTCArea);
+    function Option(const AOption: String): Boolean;
+    function Clip: IPTCArea;
+    function Palette: IPTCPalette;
     property Width: Integer read GetWidth;
     property Width: Integer read GetWidth;
     property Height: Integer read GetHeight;
     property Height: Integer read GetHeight;
     property Pitch: Integer read GetPitch;
     property Pitch: Integer read GetPitch;
-    property Area: TPTCArea read GetArea;
-    property Format: TPTCFormat read GetFormat;
+    property Area: IPTCArea read GetArea;
+    property Format: IPTCFormat read GetFormat;
   end;
   end;

+ 3 - 3
packages/ptc/src/core/cleard.inc

@@ -34,12 +34,12 @@ type
   TPTCClear = class
   TPTCClear = class
   private
   private
     FHandle: THermesClearerHandle;
     FHandle: THermesClearerHandle;
-    FFormat: TPTCFormat;
+    FFormat: IPTCFormat;
   public
   public
     constructor Create;
     constructor Create;
     destructor Destroy; override;
     destructor Destroy; override;
-    procedure Request(const AFormat: TPTCFormat);
+    procedure Request(AFormat: IPTCFormat);
     procedure Clear(APixels: Pointer;
     procedure Clear(APixels: Pointer;
                     AX, AY, AWidth, AHeight, APitch: Integer;
                     AX, AY, AWidth, AHeight, APitch: Integer;
-                    const AColor: TPTCColor);
+                    AColor: IPTCColor);
   end;
   end;

+ 4 - 6
packages/ptc/src/core/cleari.inc

@@ -32,7 +32,6 @@
 
 
 constructor TPTCClear.Create;
 constructor TPTCClear.Create;
 begin
 begin
-  FFormat := nil;
   { initialize hermes }
   { initialize hermes }
   if not Hermes_Init then
   if not Hermes_Init then
     raise TPTCError.Create('could not initialize hermes');
     raise TPTCError.Create('could not initialize hermes');
@@ -50,7 +49,6 @@ destructor TPTCClear.Destroy;
 begin
 begin
   { return the clearer instance }
   { return the clearer instance }
   Hermes_ClearerReturn(FHandle);
   Hermes_ClearerReturn(FHandle);
-  FFormat.Free;
 
 
   { free hermes }
   { free hermes }
   Hermes_Done;
   Hermes_Done;
@@ -58,20 +56,20 @@ begin
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
-procedure TPTCClear.Request(const AFormat: TPTCFormat);
+procedure TPTCClear.Request(AFormat: IPTCFormat);
 var
 var
   hermes_format: PHermesFormat;
   hermes_format: PHermesFormat;
 begin
 begin
-  hermes_format := @AFormat.FFormat;
+  hermes_format := AFormat.GetHermesFormat;
   { request surface clear for this format }
   { request surface clear for this format }
   if not Hermes_ClearerRequest(FHandle, hermes_format) then
   if not Hermes_ClearerRequest(FHandle, hermes_format) then
     raise TPTCError.Create('unsupported clear format');
     raise TPTCError.Create('unsupported clear format');
 
 
   { update current format }
   { update current format }
-  FFormat.Assign(AFormat);
+  FFormat := AFormat;
 end;
 end;
 
 
-procedure TPTCClear.Clear(APixels: Pointer; AX, AY, AWidth, AHeight, APitch: Integer; const AColor: TPTCColor);
+procedure TPTCClear.Clear(APixels: Pointer; AX, AY, AWidth, AHeight, APitch: Integer; AColor: IPTCColor);
 var
 var
   r, g, b, a: LongInt;
   r, g, b, a: LongInt;
   index: LongInt;
   index: LongInt;

+ 5 - 4
packages/ptc/src/core/clipperd.inc

@@ -34,9 +34,10 @@ type
   TPTCClipper = class
   TPTCClipper = class
   public
   public
     { clip a single area against clip area }
     { clip a single area against clip area }
-    class function Clip(const AArea, AClip: TPTCArea): TPTCArea;
+    class function Clip(AArea, AClip: IPTCArea): IPTCArea;
     { clip source and destination areas against source and destination clip areas }
     { clip source and destination areas against source and destination clip areas }
-    class procedure Clip(const ASource, AClipSource, AClippedSource,
-                         ADestination, AClipDestination,
-                         AClippedDestination: TPTCArea);
+    class procedure Clip(ASource, AClipSource: IPTCArea;
+                         out AClippedSource: IPTCArea;
+                         ADestination, AClipDestination: IPTCArea;
+                         out AClippedDestination: IPTCArea);
   end;
   end;

+ 110 - 121
packages/ptc/src/core/clipperi.inc

@@ -32,7 +32,7 @@
 
 
 {$INLINE ON}
 {$INLINE ON}
 
 
-class function TPTCClipper.Clip(const AArea, AClip: TPTCArea): TPTCArea;
+class function TPTCClipper.Clip(AArea, AClip: IPTCArea): IPTCArea;
 var
 var
   left, top, right, bottom: Integer;
   left, top, right, bottom: Integer;
   clip_left, clip_top, clip_right, clip_bottom: Integer;
   clip_left, clip_top, clip_right, clip_bottom: Integer;
@@ -103,7 +103,7 @@ begin
 end;
 end;
 
 
 { clip floating point area against clip area }
 { clip floating point area against clip area }
-procedure TPTCClipper_clip(var left, top, right, bottom: Real; const _clip: TPTCArea); Inline;
+procedure TPTCClipper_clip(var left, top, right, bottom: Real; const _clip: IPTCArea); Inline;
 var
 var
   clip_left, clip_top, clip_right, clip_bottom: Real;
   clip_left, clip_top, clip_right, clip_bottom: Real;
 begin
 begin
@@ -125,11 +125,11 @@ begin
   bottom := Round(bottom);
   bottom := Round(bottom);
 end;
 end;
 
 
-class procedure TPTCClipper.Clip(const ASource, AClipSource, AClippedSource,
-                                 ADestination, AClipDestination,
-                                 AClippedDestination: TPTCArea);
+class procedure TPTCClipper.Clip(ASource, AClipSource: IPTCArea;
+                                 out AClippedSource: IPTCArea;
+                                 ADestination, AClipDestination: IPTCArea;
+                                 out AClippedDestination: IPTCArea);
 var
 var
-  tmp1, tmp2: TPTCArea;
   source_left, source_top, source_right, source_bottom: Real;
   source_left, source_top, source_right, source_bottom: Real;
   clipped_source_left, clipped_source_top, clipped_source_right,
   clipped_source_left, clipped_source_top, clipped_source_right,
   clipped_source_bottom: Real;
   clipped_source_bottom: Real;
@@ -148,120 +148,109 @@ var
   adjusted_source_left, adjusted_source_top, adjusted_source_right,
   adjusted_source_left, adjusted_source_top, adjusted_source_right,
   adjusted_source_bottom: Real;
   adjusted_source_bottom: Real;
 begin
 begin
-  tmp1 := nil;
-  tmp2 := nil;
-  try
-    { expand source area to floating point }
-    source_left   := ASource.Left;
-    source_top    := ASource.Top;
-    source_right  := ASource.Right;
-    source_bottom := ASource.Bottom;
-
-    { setup clipped source area }
-    clipped_source_left := source_left;
-    clipped_source_top := source_top;
-    clipped_source_right := source_right;
-    clipped_source_bottom := source_bottom;
-
-    { perform clipping on floating point source area }
-    TPTCClipper_clip(clipped_source_left, clipped_source_top, clipped_source_right,
-                     clipped_source_bottom, AClipSource);
-
-    { check for early source area clipping exit }
-    if (clipped_source_left = clipped_source_right) or
-       (clipped_source_top = clipped_source_bottom) then
-    begin
-      { clipped area is zero }
-      tmp1 := TPTCArea.Create(0, 0, 0, 0);
-      AClippedSource.Assign(tmp1);
-      AClippedDestination.Assign(tmp1);
-      exit;
-    end;
-
-    { calculate deltas in source clip }
-    source_delta_left := clipped_source_left - source_left;
-    source_delta_top := clipped_source_top - source_top;
-    source_delta_right := clipped_source_right - source_right;
-    source_delta_bottom := clipped_source_bottom - source_bottom;
-
-    { calculate ratio of source area to destination area }
-    source_to_destination_x := ADestination.Width / ASource.Width;
-    source_to_destination_y := ADestination.Height / ASource.Height;
-
-    { expand destination area to floating point }
-    destination_left   := ADestination.Left;
-    destination_top    := ADestination.Top;
-    destination_right  := ADestination.Right;
-    destination_bottom := ADestination.Bottom;
-
-    { calculate adjusted destination area }
-    adjusted_destination_left := destination_left + source_delta_left * source_to_destination_x;
-    adjusted_destination_top := destination_top + source_delta_top * source_to_destination_y;
-    adjusted_destination_right := destination_right + source_delta_right * source_to_destination_x;
-    adjusted_destination_bottom := destination_bottom + source_delta_bottom * source_to_destination_y;
-
-    { setup clipped destination area }
-    clipped_destination_left := adjusted_destination_left;
-    clipped_destination_top := adjusted_destination_top;
-    clipped_destination_right := adjusted_destination_right;
-    clipped_destination_bottom := adjusted_destination_bottom;
-
-    { perform clipping on floating point destination area }
-    TPTCClipper_clip(clipped_destination_left, clipped_destination_top,
-                     clipped_destination_right, clipped_destination_bottom, AClipDestination);
-
-    { check for early destination area clipping exit }
-    if (clipped_destination_left = clipped_destination_right) or
-       (clipped_destination_top = clipped_destination_bottom) then
-    begin
-      { clipped area is zero }
-      tmp1 := TPTCArea.Create(0, 0, 0, 0);
-      AClippedSource.Assign(tmp1);
-      AClippedDestination.Assign(tmp1);
-      exit;
-    end;
-
-    { calculate deltas in destination clip }
-    destination_delta_left := clipped_destination_left - adjusted_destination_left;
-    destination_delta_top := clipped_destination_top - adjusted_destination_top;
-    destination_delta_right := clipped_destination_right - adjusted_destination_right;
-    destination_delta_bottom := clipped_destination_bottom - adjusted_destination_bottom;
-
-    { calculate ratio of destination area to source area }
-    destination_to_source_x := 1 / source_to_destination_x;
-    destination_to_source_y := 1 / source_to_destination_y;
-
-    { calculate adjusted source area }
-    adjusted_source_left := clipped_source_left + destination_delta_left * destination_to_source_x;
-    adjusted_source_top := clipped_source_top + destination_delta_top * destination_to_source_y;
-    adjusted_source_right := clipped_source_right + destination_delta_right * destination_to_source_x;
-    adjusted_source_bottom := clipped_source_bottom + destination_delta_bottom * destination_to_source_y;
-
-    { assign adjusted source to clipped source }
-    clipped_source_left := adjusted_source_left;
-    clipped_source_top := adjusted_source_top;
-    clipped_source_right := adjusted_source_right;
-    clipped_source_bottom := adjusted_source_bottom;
-
-    { round clipped areas to integer coordinates }
-    TPTCClipper_round(clipped_source_left, clipped_source_top,
-                      clipped_source_right, clipped_source_bottom);
-    TPTCClipper_round(clipped_destination_left, clipped_destination_top,
-                      clipped_destination_right, clipped_destination_bottom);
-
-    { construct clipped area rectangles from rounded floating point areas }
-    tmp1 := TPTCArea.Create(Trunc(clipped_source_left),
-                            Trunc(clipped_source_top),
-                            Trunc(clipped_source_right),
-                            Trunc(clipped_source_bottom));
-    tmp2 := TPTCArea.Create(Trunc(clipped_destination_left),
-                            Trunc(clipped_destination_top),
-                            Trunc(clipped_destination_right),
-                            Trunc(clipped_destination_bottom));
-    AClippedSource.Assign(tmp1);
-    AClippedDestination.Assign(tmp2);
-  finally
-    tmp1.Free;
-    tmp2.Free;
+  { expand source area to floating point }
+  source_left   := ASource.Left;
+  source_top    := ASource.Top;
+  source_right  := ASource.Right;
+  source_bottom := ASource.Bottom;
+
+  { setup clipped source area }
+  clipped_source_left := source_left;
+  clipped_source_top := source_top;
+  clipped_source_right := source_right;
+  clipped_source_bottom := source_bottom;
+
+  { perform clipping on floating point source area }
+  TPTCClipper_clip(clipped_source_left, clipped_source_top, clipped_source_right,
+                   clipped_source_bottom, AClipSource);
+
+  { check for early source area clipping exit }
+  if (clipped_source_left = clipped_source_right) or
+     (clipped_source_top = clipped_source_bottom) then
+  begin
+    { clipped area is zero }
+    AClippedSource := TPTCArea.Create(0, 0, 0, 0);
+    AClippedDestination := AClippedSource;
+    exit;
   end;
   end;
+
+  { calculate deltas in source clip }
+  source_delta_left := clipped_source_left - source_left;
+  source_delta_top := clipped_source_top - source_top;
+  source_delta_right := clipped_source_right - source_right;
+  source_delta_bottom := clipped_source_bottom - source_bottom;
+
+  { calculate ratio of source area to destination area }
+  source_to_destination_x := ADestination.Width / ASource.Width;
+  source_to_destination_y := ADestination.Height / ASource.Height;
+
+  { expand destination area to floating point }
+  destination_left   := ADestination.Left;
+  destination_top    := ADestination.Top;
+  destination_right  := ADestination.Right;
+  destination_bottom := ADestination.Bottom;
+
+  { calculate adjusted destination area }
+  adjusted_destination_left := destination_left + source_delta_left * source_to_destination_x;
+  adjusted_destination_top := destination_top + source_delta_top * source_to_destination_y;
+  adjusted_destination_right := destination_right + source_delta_right * source_to_destination_x;
+  adjusted_destination_bottom := destination_bottom + source_delta_bottom * source_to_destination_y;
+
+  { setup clipped destination area }
+  clipped_destination_left := adjusted_destination_left;
+  clipped_destination_top := adjusted_destination_top;
+  clipped_destination_right := adjusted_destination_right;
+  clipped_destination_bottom := adjusted_destination_bottom;
+
+  { perform clipping on floating point destination area }
+  TPTCClipper_clip(clipped_destination_left, clipped_destination_top,
+                   clipped_destination_right, clipped_destination_bottom, AClipDestination);
+
+  { check for early destination area clipping exit }
+  if (clipped_destination_left = clipped_destination_right) or
+     (clipped_destination_top = clipped_destination_bottom) then
+  begin
+    { clipped area is zero }
+    AClippedSource := TPTCArea.Create(0, 0, 0, 0);
+    AClippedDestination := AClippedSource;
+    exit;
+  end;
+
+  { calculate deltas in destination clip }
+  destination_delta_left := clipped_destination_left - adjusted_destination_left;
+  destination_delta_top := clipped_destination_top - adjusted_destination_top;
+  destination_delta_right := clipped_destination_right - adjusted_destination_right;
+  destination_delta_bottom := clipped_destination_bottom - adjusted_destination_bottom;
+
+  { calculate ratio of destination area to source area }
+  destination_to_source_x := 1 / source_to_destination_x;
+  destination_to_source_y := 1 / source_to_destination_y;
+
+  { calculate adjusted source area }
+  adjusted_source_left := clipped_source_left + destination_delta_left * destination_to_source_x;
+  adjusted_source_top := clipped_source_top + destination_delta_top * destination_to_source_y;
+  adjusted_source_right := clipped_source_right + destination_delta_right * destination_to_source_x;
+  adjusted_source_bottom := clipped_source_bottom + destination_delta_bottom * destination_to_source_y;
+
+  { assign adjusted source to clipped source }
+  clipped_source_left := adjusted_source_left;
+  clipped_source_top := adjusted_source_top;
+  clipped_source_right := adjusted_source_right;
+  clipped_source_bottom := adjusted_source_bottom;
+
+  { round clipped areas to integer coordinates }
+  TPTCClipper_round(clipped_source_left, clipped_source_top,
+                    clipped_source_right, clipped_source_bottom);
+  TPTCClipper_round(clipped_destination_left, clipped_destination_top,
+                    clipped_destination_right, clipped_destination_bottom);
+
+  { construct clipped area rectangles from rounded floating point areas }
+  AClippedSource := TPTCArea.Create(Trunc(clipped_source_left),
+                                    Trunc(clipped_source_top),
+                                    Trunc(clipped_source_right),
+                                    Trunc(clipped_source_bottom));
+  AClippedDestination := TPTCArea.Create(Trunc(clipped_destination_left),
+                                         Trunc(clipped_destination_top),
+                                         Trunc(clipped_destination_right),
+                                         Trunc(clipped_destination_bottom));
 end;
 end;

+ 25 - 19
packages/ptc/src/core/colord.inc

@@ -31,24 +31,30 @@
 }
 }
 
 
 type
 type
-  TPTCColor = class
-  private
-    FIndex: Integer;
-    FRed, FGreen, FBlue, FAlpha: Single;
-    FDirect: Boolean;
-    FIndexed: Boolean;
+  IPTCColor = interface
+    function GetIndex: Integer;
+    function GetR: Single;
+    function GetG: Single;
+    function GetB: Single;
+    function GetA: Single;
+    function GetDirect: Boolean;
+    function GetIndexed: Boolean;
+
+    function Equals(AColor: IPTCColor): Boolean;
+
+    property Index: Integer read GetIndex;
+    property R: Single read GetR;
+    property G: Single read GetG;
+    property B: Single read GetB;
+    property A: Single read GetA;
+    property Direct: Boolean read GetDirect;
+    property Indexed: Boolean read GetIndexed;
+  end;
+
+  TPTCColorFactory = class
   public
   public
-    constructor Create;
-    constructor Create(AIndex: Integer);
-    constructor Create(ARed, AGreen, ABlue: Single; AAlpha: Single = 1);
-    constructor Create(const AColor: TPTCColor);
-    procedure Assign(const AColor: TPTCColor);
-    function Equals(const AColor: TPTCColor): Boolean;
-    property Index: Integer read FIndex;
-    property R: Single read FRed;
-    property G: Single read FGreen;
-    property B: Single read FBlue;
-    property A: Single read FAlpha;
-    property Direct: Boolean read FDirect;
-    property Indexed: Boolean read FIndexed;
+    class function CreateNew: IPTCColor;
+    class function CreateNew(AIndex: Integer): IPTCColor;
+    class function CreateNew(ARed, AGreen, ABlue: Single; AAlpha: Single = 1): IPTCColor;
+    class function CreateNew(AColor: IPTCColor): IPTCColor;
   end;
   end;

+ 88 - 27
packages/ptc/src/core/colori.inc

@@ -30,10 +30,51 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 }
 }
 
 
+type
+  TPTCColor = class(TInterfacedObject, IPTCColor)
+  private
+    FIndex: Integer;
+    FRed, FGreen, FBlue, FAlpha: Single;
+    FIndexed: Boolean;
+
+    function GetIndex: Integer;
+    function GetR: Single;
+    function GetG: Single;
+    function GetB: Single;
+    function GetA: Single;
+    function GetDirect: Boolean;
+    function GetIndexed: Boolean;
+    function Equals(AColor: IPTCColor): Boolean;
+  public
+    constructor Create;
+    constructor Create(AIndex: Integer);
+    constructor Create(ARed, AGreen, ABlue: Single; AAlpha: Single = 1);
+    constructor Create(AColor: IPTCColor);
+  end;
+
+class function TPTCColorFactory.CreateNew: IPTCColor;
+begin
+  Result := TPTCColor.Create;
+end;
+
+class function TPTCColorFactory.CreateNew(AIndex: Integer): IPTCColor;
+begin
+  Result := TPTCColor.Create(AIndex);
+end;
+
+class function TPTCColorFactory.CreateNew(ARed, AGreen, ABlue: Single; AAlpha: Single = 1): IPTCColor;
+begin
+  Result := TPTCColor.Create(ARed, AGreen, ABlue, AAlpha);
+end;
+
+class function TPTCColorFactory.CreateNew(AColor: IPTCColor): IPTCColor;
+begin
+  Result := TPTCColor.Create(AColor);
+end;
+
 constructor TPTCColor.Create;
 constructor TPTCColor.Create;
 begin
 begin
   FIndexed := False;
   FIndexed := False;
-  FDirect  := False;
   FIndex   := 0;
   FIndex   := 0;
   FRed     := 0;
   FRed     := 0;
   FGreen   := 0;
   FGreen   := 0;
@@ -44,7 +85,6 @@ end;
 constructor TPTCColor.Create(AIndex: Integer);
 constructor TPTCColor.Create(AIndex: Integer);
 begin
 begin
   FIndexed := True;
   FIndexed := True;
-  FDirect  := False;
   FIndex   := AIndex;
   FIndex   := AIndex;
   FRed     := 0;
   FRed     := 0;
   FGreen   := 0;
   FGreen   := 0;
@@ -55,7 +95,6 @@ end;
 constructor TPTCColor.Create(ARed, AGreen, ABlue: Single; AAlpha: Single = 1);
 constructor TPTCColor.Create(ARed, AGreen, ABlue: Single; AAlpha: Single = 1);
 begin
 begin
   FIndexed := False;
   FIndexed := False;
-  FDirect  := True;
   FIndex   := 0;
   FIndex   := 0;
   FRed     := ARed;
   FRed     := ARed;
   FGreen   := AGreen;
   FGreen   := AGreen;
@@ -63,35 +102,57 @@ begin
   FAlpha   := AAlpha;
   FAlpha   := AAlpha;
 end;
 end;
 
 
-constructor TPTCColor.Create(const AColor: TPTCColor);
+constructor TPTCColor.Create(AColor: IPTCColor);
+begin
+  FIndex   := AColor.Index;
+  FRed     := AColor.R;
+  FGreen   := AColor.G;
+  FBlue    := AColor.B;
+  FAlpha   := AColor.A;
+  FIndexed := AColor.Indexed;
+end;
+
+function TPTCColor.Equals(AColor: IPTCColor): Boolean;
+begin
+  Result := (FIndexed = AColor.Indexed) and
+            (FIndex   = AColor.Index) and
+            (FRed     = AColor.R) and
+            (FGreen   = AColor.G) and
+            (FBlue    = AColor.B) and
+            (FAlpha   = AColor.A);
+end;
+
+function TPTCColor.GetIndex: Integer;
+begin
+  Result := FIndex;
+end;
+
+function TPTCColor.GetR: Single;
+begin
+  Result := FRed;
+end;
+
+function TPTCColor.GetG: Single;
+begin
+  Result := FGreen;
+end;
+
+function TPTCColor.GetB: Single;
+begin
+  Result := FBlue;
+end;
+
+function TPTCColor.GetA: Single;
 begin
 begin
-  FIndex   := AColor.FIndex;
-  FRed     := AColor.FRed;
-  FGreen   := AColor.FGreen;
-  FBlue    := AColor.FBlue;
-  FAlpha   := AColor.FAlpha;
-  FDirect  := AColor.FDirect;
-  FIndexed := AColor.FIndexed;
+  Result := FAlpha;
 end;
 end;
 
 
-procedure TPTCColor.Assign(const AColor: TPTCColor);
+function TPTCColor.GetDirect: Boolean;
 begin
 begin
-  FIndex   := AColor.FIndex;
-  FRed     := AColor.FRed;
-  FGreen   := AColor.FGreen;
-  FBlue    := AColor.FBlue;
-  FAlpha   := AColor.FAlpha;
-  FDirect  := AColor.FDirect;
-  FIndexed := AColor.FIndexed;
+  Result := not FIndexed;
 end;
 end;
 
 
-function TPTCColor.Equals(const AColor: TPTCColor): Boolean;
+function TPTCColor.GetIndexed: Boolean;
 begin
 begin
-  Result := (FIndexed = AColor.FIndexed) and
-            (FDirect  = AColor.FDirect) and
-            (FIndex   = AColor.FIndex) and
-            (FRed     = AColor.FRed) and
-            (FGreen   = AColor.FGreen) and
-            (FBlue    = AColor.FBlue) and
-            (FAlpha   = AColor.FAlpha);
+  Result := FIndexed;
 end;
 end;

+ 2 - 74
packages/ptc/src/core/consoled.inc

@@ -31,79 +31,7 @@
 }
 }
 
 
 type
 type
-  TPTCConsole = class(TPTCBaseConsole)
-  private
-    FConsole: TPTCBaseConsole;
-    FModes: array [0..1023] of TPTCMode;
-    FOptionsQueue: array of string;
-    FHackyOptionConsoleFlag: Boolean;
-
-    function ConsoleCreate(AIndex: Integer): TPTCBaseConsole;
-    function ConsoleCreate(const AName: string): TPTCBaseConsole;
-    procedure Check;
-
-    procedure AddOptionToOptionsQueue(const AOption: string);
-    procedure ExecuteOptionsFromOptionsQueue;
-    procedure ClearOptionsQueue;
+  TPTCConsoleFactory = class
   public
   public
-    constructor Create; override;
-    destructor Destroy; override;
-    procedure Configure(const AFile: string); override;
-    function Option(const AOption: string): Boolean; override;
-    function Modes: PPTCMode; override;
-    procedure Open(const ATitle: string; APages: Integer = 0); overload; override;
-    procedure Open(const ATitle: string; const AFormat: TPTCFormat;
-                   APages: Integer = 0); overload; override;
-    procedure Open(const ATitle: string; AWidth, AHeight: Integer;
-                   const AFormat: TPTCFormat; APages: Integer = 0); overload; override;
-    procedure Open(const ATitle: string; const AMode: TPTCMode;
-                   APages: Integer = 0); overload; override;
-
-    procedure Close; override;
-    procedure Flush; override;
-    procedure Finish; override;
-    procedure Update; override;
-    procedure Update(const AArea: TPTCArea); override;
-    procedure Copy(ASurface: TPTCBaseSurface); override;
-    procedure Copy(ASurface: TPTCBaseSurface;
-                   const ASource, ADestination: TPTCArea); override;
-    function Lock: Pointer; override;
-    procedure Unlock; override;
-    procedure Load(const APixels: Pointer;
-                   AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); override;
-    procedure Load(const APixels: Pointer;
-                   AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); override;
-    procedure Save(APixels: Pointer;
-                   AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); override;
-    procedure Save(APixels: Pointer;
-                   AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); override;
-    procedure Clear; override;
-    procedure Clear(const AColor: TPTCColor); override;
-    procedure Clear(const AColor: TPTCColor;
-                    const AArea: TPTCArea); override;
-    procedure Palette(const APalette: TPTCPalette); override;
-    function Palette: TPTCPalette; override;
-    procedure Clip(const AArea: TPTCArea); override;
-    function GetWidth: Integer; override;
-    function GetHeight: Integer; override;
-    function GetPitch: Integer; override;
-    function GetPages: Integer; override;
-    function GetArea: TPTCArea; override;
-    function Clip: TPTCArea; override;
-    function GetFormat: TPTCFormat; override;
-    function GetName: string; override;
-    function GetTitle: string; override;
-    function GetInformation: string; override;
-    function NextEvent(var AEvent: TPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; override;
-    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): TPTCEvent; override;
+    class function CreateNew: IPTCConsole;
   end;
   end;

+ 140 - 74
packages/ptc/src/core/consolei.inc

@@ -30,6 +30,89 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 }
 }
 
 
+type
+  TPTCConsole = class(TPTCBaseConsole)
+  private
+    FConsole: IPTCConsole;
+    FModes: array of IPTCMode;
+    FOptionsQueue: array of string;
+    FHackyOptionConsoleFlag: Boolean;
+
+    function ConsoleCreate(AIndex: Integer): IPTCConsole;
+    function ConsoleCreate(const AName: string): IPTCConsole;
+    procedure Check;
+
+    procedure AddOptionToOptionsQueue(const AOption: string);
+    procedure ExecuteOptionsFromOptionsQueue;
+    procedure ClearOptionsQueue;
+  public
+    constructor Create; override;
+    destructor Destroy; override;
+    procedure Configure(const AFile: string); override;
+    function Option(const AOption: string): Boolean; override;
+    function Modes: TPTCModeList; override;
+    procedure Open(const ATitle: string; APages: Integer = 0); overload; override;
+    procedure Open(const ATitle: string; AFormat: IPTCFormat;
+                   APages: Integer = 0); overload; override;
+    procedure Open(const ATitle: string; AWidth, AHeight: Integer;
+                   AFormat: IPTCFormat; APages: Integer = 0); overload; override;
+    procedure Open(const ATitle: string; AMode: IPTCMode;
+                   APages: Integer = 0); overload; override;
+
+    procedure Close; override;
+    procedure Flush; override;
+    procedure Finish; override;
+    procedure Update; override;
+    procedure Update(AArea: IPTCArea); override;
+    procedure Copy(ASurface: IPTCSurface); override;
+    procedure Copy(ASurface: IPTCSurface;
+                   ASource, ADestination: IPTCArea); override;
+    function Lock: Pointer; override;
+    procedure Unlock; override;
+    procedure Load(const APixels: Pointer;
+                   AWidth, AHeight, APitch: Integer;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette); override;
+    procedure Load(const APixels: Pointer;
+                   AWidth, AHeight, APitch: Integer;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea); override;
+    procedure Save(APixels: Pointer;
+                   AWidth, AHeight, APitch: Integer;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette); override;
+    procedure Save(APixels: Pointer;
+                   AWidth, AHeight, APitch: Integer;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea); override;
+    procedure Clear; override;
+    procedure Clear(AColor: IPTCColor); override;
+    procedure Clear(AColor: IPTCColor;
+                    AArea: IPTCArea); override;
+    procedure Palette(APalette: IPTCPalette); override;
+    function Palette: IPTCPalette; override;
+    procedure Clip(AArea: IPTCArea); override;
+    function GetWidth: Integer; override;
+    function GetHeight: Integer; override;
+    function GetPitch: Integer; override;
+    function GetPages: Integer; override;
+    function GetArea: IPTCArea; override;
+    function Clip: IPTCArea; override;
+    function GetFormat: IPTCFormat; override;
+    function GetName: string; override;
+    function GetTitle: string; override;
+    function GetInformation: string; override;
+    function NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; override;
+    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent; override;
+  end;
+
+class function TPTCConsoleFactory.CreateNew: IPTCConsole;
+begin
+  Result := TPTCConsole.Create;
+end;
+
 const
 const
  {$IFDEF GO32V2}
  {$IFDEF GO32V2}
   ConsoleTypesNumber = 4;
   ConsoleTypesNumber = 4;
@@ -81,9 +164,6 @@ begin
   inherited Create;
   inherited Create;
   FConsole := nil;
   FConsole := nil;
   FHackyOptionConsoleFlag := False;
   FHackyOptionConsoleFlag := False;
-  FillChar(FModes, SizeOf(FModes), 0);
-  for I := Low(FModes) to High(FModes) do
-    FModes[I] := TPTCMode.Create;
 
 
   {$IFDEF UNIX}
   {$IFDEF UNIX}
     Configure('/usr/share/ptcpas/ptcpas.conf');
     Configure('/usr/share/ptcpas/ptcpas.conf');
@@ -114,9 +194,7 @@ var
   I: Integer;
   I: Integer;
 begin
 begin
   close;
   close;
-  FConsole.Free;
-  for I := Low(FModes) to High(FModes) do
-    FModes[I].Free;
+  FConsole := nil;
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
@@ -203,54 +281,42 @@ begin
   end;
   end;
 end;
 end;
 
 
-function TPTCConsole.Modes: PPTCMode;
+function TPTCConsole.Modes: TPTCModeList;
 var
 var
-  _console: TPTCBaseConsole;
+  _console: IPTCConsole;
   index, mode: Integer;
   index, mode: Integer;
   local: Integer;
   local: Integer;
-  _modes: PPTCMode;
-  tmp: TPTCMode;
+  _modes: TPTCModeList;
 begin
 begin
   if Assigned(FConsole) then
   if Assigned(FConsole) then
     Result := FConsole.Modes
     Result := FConsole.Modes
   else
   else
   begin
   begin
     _console := nil;
     _console := nil;
+    SetLength(FModes, 0);
     index := -1;
     index := -1;
     mode := 0;
     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
-          FModes[mode].Assign(_modes[local]);
-          Inc(local);
-          Inc(mode);
+    repeat
+      Inc(index);
+      try
+        _console := ConsoleCreate(index);
+      except
+        on TPTCError do begin
+          _console := nil;
+          continue;
         end;
         end;
-        FreeAndNil(_console);
-      until False;
-    finally
-      _console.Free;
-    end;
+      end;
+      if _console = nil then
+        break;
+      _modes := _console.modes;
+      SetLength(FModes, Length(FModes) + Length(_modes));
+      for local := Low(_modes) to High(_modes) do
+      begin
+        FModes[mode] := _modes[local];
+        Inc(mode);
+      end;
+    until False;
     { todo: strip duplicate modes from list? }
     { todo: strip duplicate modes from list? }
-    tmp := TPTCMode.Create;
-    try
-      FModes[mode].Assign(tmp);
-    finally
-      tmp.Free;
-    end;
     Result := FModes;
     Result := FModes;
   end;
   end;
 end;
 end;
@@ -314,7 +380,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure TPTCConsole.Open(const ATitle: string; const AFormat: TPTCFormat;
+procedure TPTCConsole.Open(const ATitle: string; AFormat: IPTCFormat;
                            APages: Integer);
                            APages: Integer);
 var
 var
   composite, tmp: TPTCError;
   composite, tmp: TPTCError;
@@ -375,7 +441,7 @@ begin
 end;
 end;
 
 
 procedure TPTCConsole.Open(const ATitle: string; AWidth, AHeight: Integer;
 procedure TPTCConsole.Open(const ATitle: string; AWidth, AHeight: Integer;
-                           const AFormat: TPTCFormat; APages: Integer);
+                           AFormat: IPTCFormat; APages: Integer);
 var
 var
   composite, tmp: TPTCError;
   composite, tmp: TPTCError;
   index: Integer;
   index: Integer;
@@ -434,7 +500,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure TPTCConsole.Open(const ATitle: string; const AMode: TPTCMode;
+procedure TPTCConsole.Open(const ATitle: string; AMode: IPTCMode;
                            APages: Integer);
                            APages: Integer);
 var
 var
   composite, tmp: TPTCError;
   composite, tmp: TPTCError;
@@ -519,20 +585,20 @@ begin
   FConsole.Update;
   FConsole.Update;
 end;
 end;
 
 
-procedure TPTCConsole.Update(const AArea: TPTCArea);
+procedure TPTCConsole.Update(AArea: IPTCArea);
 begin
 begin
   Check;
   Check;
   FConsole.Update(AArea);
   FConsole.Update(AArea);
 end;
 end;
 
 
-procedure TPTCConsole.Copy(ASurface: TPTCBaseSurface);
+procedure TPTCConsole.Copy(ASurface: IPTCSurface);
 begin
 begin
   Check;
   Check;
   FConsole.Copy(ASurface);
   FConsole.Copy(ASurface);
 end;
 end;
 
 
-procedure TPTCConsole.Copy(ASurface: TPTCBaseSurface;
-                           const ASource, ADestination: TPTCArea);
+procedure TPTCConsole.Copy(ASurface: IPTCSurface;
+                           ASource, ADestination: IPTCArea);
 begin
 begin
   Check;
   Check;
   FConsole.Copy(ASurface, ASource, ADestination);
   FConsole.Copy(ASurface, ASource, ADestination);
@@ -552,8 +618,8 @@ end;
 
 
 procedure TPTCConsole.Load(const APixels: Pointer;
 procedure TPTCConsole.Load(const APixels: Pointer;
                            AWidth, AHeight, APitch: Integer;
                            AWidth, AHeight, APitch: Integer;
-                           const AFormat: TPTCFormat;
-                           const APalette: TPTCPalette);
+                           AFormat: IPTCFormat;
+                           APalette: IPTCPalette);
 begin
 begin
   Check;
   Check;
   FConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette);
   FConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette);
@@ -561,9 +627,9 @@ end;
 
 
 procedure TPTCConsole.Load(const APixels: Pointer;
 procedure TPTCConsole.Load(const APixels: Pointer;
                            AWidth, AHeight, APitch: Integer;
                            AWidth, AHeight, APitch: Integer;
-                           const AFormat: TPTCFormat;
-                           const APalette: TPTCPalette;
-                           const ASource, ADestination: TPTCArea);
+                           AFormat: IPTCFormat;
+                           APalette: IPTCPalette;
+                           ASource, ADestination: IPTCArea);
 begin
 begin
   Check;
   Check;
   FConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette,
   FConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette,
@@ -572,8 +638,8 @@ end;
 
 
 procedure TPTCConsole.Save(Apixels: Pointer;
 procedure TPTCConsole.Save(Apixels: Pointer;
                            AWidth, AHeight, APitch: Integer;
                            AWidth, AHeight, APitch: Integer;
-                           const AFormat: TPTCFormat;
-                           const APalette: TPTCPalette);
+                           AFormat: IPTCFormat;
+                           APalette: IPTCPalette);
 begin
 begin
   Check;
   Check;
   FConsole.Save(APixels, AWidth, AHeight, APitch, AFormat, APalette);
   FConsole.Save(APixels, AWidth, AHeight, APitch, AFormat, APalette);
@@ -581,9 +647,9 @@ end;
 
 
 procedure TPTCConsole.Save(APixels: Pointer;
 procedure TPTCConsole.Save(APixels: Pointer;
                            AWidth, AHeight, APitch: Integer;
                            AWidth, AHeight, APitch: Integer;
-                           const AFormat: TPTCFormat;
-                           const APalette: TPTCPalette;
-                           const ASource, ADestination: TPTCArea);
+                           AFormat: IPTCFormat;
+                           APalette: IPTCPalette;
+                           ASource, ADestination: IPTCArea);
 begin
 begin
   Check;
   Check;
   FConsole.Save(APixels, AWidth, AHeight, APitch, AFormat, APalette,
   FConsole.Save(APixels, AWidth, AHeight, APitch, AFormat, APalette,
@@ -593,35 +659,35 @@ end;
 procedure TPTCConsole.Clear;
 procedure TPTCConsole.Clear;
 begin
 begin
   Check;
   Check;
-  FConsole.clear;
+  FConsole.Clear;
 end;
 end;
 
 
-procedure TPTCConsole.Clear(const AColor: TPTCColor);
+procedure TPTCConsole.Clear(AColor: IPTCColor);
 begin
 begin
   Check;
   Check;
-  FConsole.clear(AColor);
+  FConsole.Clear(AColor);
 end;
 end;
 
 
-procedure TPTCConsole.Clear(const AColor: TPTCColor;
-                           const AArea: TPTCArea);
+procedure TPTCConsole.Clear(AColor: IPTCColor;
+                            AArea: IPTCArea);
 begin
 begin
   Check;
   Check;
-  FConsole.clear(AColor, AArea);
+  FConsole.Clear(AColor, AArea);
 end;
 end;
 
 
-procedure TPTCConsole.Palette(const APalette: TPTCPalette);
+procedure TPTCConsole.Palette(APalette: IPTCPalette);
 begin
 begin
   Check;
   Check;
   FConsole.Palette(APalette);
   FConsole.Palette(APalette);
 end;
 end;
 
 
-function TPTCConsole.Palette: TPTCPalette;
+function TPTCConsole.Palette: IPTCPalette;
 begin
 begin
   Check;
   Check;
   Result := FConsole.Palette;
   Result := FConsole.Palette;
 end;
 end;
 
 
-procedure TPTCConsole.Clip(const AArea: TPTCArea);
+procedure TPTCConsole.Clip(AArea: IPTCArea);
 begin
 begin
   Check;
   Check;
   FConsole.Clip(AArea);
   FConsole.Clip(AArea);
@@ -651,19 +717,19 @@ begin
   Result := FConsole.GetPages;
   Result := FConsole.GetPages;
 end;
 end;
 
 
-function TPTCConsole.GetArea: TPTCArea;
+function TPTCConsole.GetArea: IPTCArea;
 begin
 begin
   Check;
   Check;
   Result := FConsole.GetArea;
   Result := FConsole.GetArea;
 end;
 end;
 
 
-function TPTCConsole.Clip: TPTCArea;
+function TPTCConsole.Clip: IPTCArea;
 begin
 begin
   Check;
   Check;
   Result := FConsole.Clip;
   Result := FConsole.Clip;
 end;
 end;
 
 
-function TPTCConsole.GetFormat: TPTCFormat;
+function TPTCConsole.GetFormat: IPTCFormat;
 begin
 begin
   Check;
   Check;
   Result := FConsole.GetFormat;
   Result := FConsole.GetFormat;
@@ -701,19 +767,19 @@ begin
   Result := FConsole.GetInformation;
   Result := FConsole.GetInformation;
 end;
 end;
 
 
-function TPTCConsole.NextEvent(var AEvent: TPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
+function TPTCConsole.NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
 begin
 begin
   Check;
   Check;
   Result := FConsole.NextEvent(AEvent, AWait, AEventMask);
   Result := FConsole.NextEvent(AEvent, AWait, AEventMask);
 end;
 end;
 
 
-function TPTCConsole.PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): TPTCEvent;
+function TPTCConsole.PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent;
 begin
 begin
   Check;
   Check;
   Result := FConsole.PeekEvent(AWait, AEventMask);
   Result := FConsole.PeekEvent(AWait, AEventMask);
 end;
 end;
 
 
-function TPTCConsole.ConsoleCreate(AIndex: Integer): TPTCBaseConsole;
+function TPTCConsole.ConsoleCreate(AIndex: Integer): IPTCConsole;
 begin
 begin
   Result := nil;
   Result := nil;
   if (AIndex >= Low(ConsoleTypes)) and (AIndex <= High(ConsoleTypes)) then
   if (AIndex >= Low(ConsoleTypes)) and (AIndex <= High(ConsoleTypes)) then
@@ -723,7 +789,7 @@ begin
     Result.KeyReleaseEnabled := KeyReleaseEnabled;
     Result.KeyReleaseEnabled := KeyReleaseEnabled;
 end;
 end;
 
 
-function TPTCConsole.ConsoleCreate(const AName: string): TPTCBaseConsole;
+function TPTCConsole.ConsoleCreate(const AName: string): IPTCConsole;
 var
 var
   I, J: Integer;
   I, J: Integer;
 begin
 begin

+ 2 - 2
packages/ptc/src/core/copyd.inc

@@ -40,8 +40,8 @@ type
   public
   public
     constructor Create;
     constructor Create;
     destructor Destroy; override;
     destructor Destroy; override;
-    procedure Request(const ASource, ADestination: TPTCFormat);
-    procedure Palette(const ASource, ADestination: TPTCPalette);
+    procedure Request(ASource, ADestination: IPTCFormat);
+    procedure Palette(ASource, ADestination: IPTCPalette);
     procedure Copy(const ASourcePixels: Pointer; ASourceX, ASourceY,
     procedure Copy(const ASourcePixels: Pointer; ASourceX, ASourceY,
                    ASourceWidth, ASourceHeight, ASourcePitch: Integer;
                    ASourceWidth, ASourceHeight, ASourcePitch: Integer;
                    ADestinationPixels: Pointer; ADestinationX, ADestinationY,
                    ADestinationPixels: Pointer; ADestinationX, ADestinationY,

+ 7 - 7
packages/ptc/src/core/copyi.inc

@@ -47,25 +47,25 @@ begin
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
-procedure TPTCCopy.Request(const ASource, ADestination: TPTCFormat);
+procedure TPTCCopy.Request(ASource, ADestination: IPTCFormat);
 var
 var
   hermes_source_format, hermes_destination_format: PHermesFormat;
   hermes_source_format, hermes_destination_format: PHermesFormat;
 begin
 begin
-  hermes_source_format := @ASource.FFormat;
-  hermes_destination_format := @ADestination.FFormat;
+  hermes_source_format := ASource.GetHermesFormat;
+  hermes_destination_format := ADestination.GetHermesFormat;
   if not Hermes_ConverterRequest(FHandle, hermes_source_format,
   if not Hermes_ConverterRequest(FHandle, hermes_source_format,
      hermes_destination_format) then
      hermes_destination_format) then
     raise TPTCError.Create('unsupported hermes pixel format conversion');
     raise TPTCError.Create('unsupported hermes pixel format conversion');
 end;
 end;
 
 
-procedure TPTCCopy.Palette(const ASource, ADestination: TPTCPalette);
+procedure TPTCCopy.Palette(ASource, ADestination: IPTCPalette);
 begin
 begin
-  if not Hermes_ConverterPalette(FHandle, ASource.FHandle,
-         ADestination.FHandle) then
+  if not Hermes_ConverterPalette(FHandle, ASource.GetHermesPaletteHandle,
+         ADestination.GetHermesPaletteHandle) then
     raise TPTCError.Create('could not set hermes conversion palettes');
     raise TPTCError.Create('could not set hermes conversion palettes');
 end;
 end;
 
 
-procedure TPTCCopy.copy(const ASourcePixels: Pointer; ASourceX, ASourceY,
+procedure TPTCCopy.Copy(const ASourcePixels: Pointer; ASourceX, ASourceY,
                    ASourceWidth, ASourceHeight, ASourcePitch: Integer;
                    ASourceWidth, ASourceHeight, ASourcePitch: Integer;
                    ADestinationPixels: Pointer; ADestinationX, ADestinationY,
                    ADestinationPixels: Pointer; ADestinationX, ADestinationY,
                    ADestinationWidth, ADestinationHeight, ADestinationPitch: Integer);
                    ADestinationWidth, ADestinationHeight, ADestinationPitch: Integer);

+ 4 - 11
packages/ptc/src/core/eventd.inc

@@ -33,18 +33,11 @@
 type
 type
   TPTCEventType = (PTCKeyEvent, PTCMouseEvent{, PTCExposeEvent});
   TPTCEventType = (PTCKeyEvent, PTCMouseEvent{, PTCExposeEvent});
   TPTCEventMask = set of TPTCEventType;
   TPTCEventMask = set of TPTCEventType;
-  TPTCEvent = class
-  protected
-    function GetType: TPTCEventType; virtual; abstract;
-  public
-    property EventType: TPTCEventType read GetType;
+  IPTCEvent = interface
+    ['{1D5A6831-6648-47B6-83D5-10E65FDB72AD}']
+    function GetEventType: TPTCEventType;
+    property EventType: TPTCEventType read GetEventType;
   end;
   end;
 
 
 const
 const
   PTCAnyEvent: TPTCEventMask = [PTCKeyEvent, PTCMouseEvent{, PTCExposeEvent}];
   PTCAnyEvent: TPTCEventMask = [PTCKeyEvent, PTCMouseEvent{, PTCExposeEvent}];
-
-{type
-  TPTCExposeEvent = Class(TPTCEvent)
-  protected
-    function GetType: TPTCEventType; override;
-  End;}

+ 20 - 8
packages/ptc/src/core/eventi.inc

@@ -36,9 +36,20 @@ begin
 end;}
 end;}
 
 
 type
 type
+  TPTCEvent = class(TInterfacedObject, IPTCEvent)
+  protected
+    function GetEventType: TPTCEventType; virtual; abstract;
+  public
+    property EventType: TPTCEventType read GetEventType;
+  end;
+{  TPTCExposeEvent = Class(TPTCEvent)
+  protected
+    function GetType: TPTCEventType; override;
+  End;}
+
   PEventLinkedList = ^TEventLinkedList;
   PEventLinkedList = ^TEventLinkedList;
   TEventLinkedList = record
   TEventLinkedList = record
-    Event: TPTCEvent;
+    Event: IPTCEvent;
     Next: PEventLinkedList;
     Next: PEventLinkedList;
   end;
   end;
   TEventQueue = class
   TEventQueue = class
@@ -47,9 +58,9 @@ type
   public
   public
     constructor Create;
     constructor Create;
     destructor Destroy; override;
     destructor Destroy; override;
-    procedure AddEvent(event: TPTCEvent);
-    function PeekEvent(const EventMask: TPTCEventMask): TPTCEvent;
-    function NextEvent(const EventMask: TPTCEventMask): TPTCEvent;
+    procedure AddEvent(const event: IPTCEvent);
+    function PeekEvent(const EventMask: TPTCEventMask): IPTCEvent;
+    function NextEvent(const EventMask: TPTCEventMask): IPTCEvent;
   end;
   end;
 
 
 constructor TEventQueue.Create;
 constructor TEventQueue.Create;
@@ -65,7 +76,7 @@ begin
   p := FHead;
   p := FHead;
   while p <> nil do
   while p <> nil do
   begin
   begin
-    FreeAndNil(p^.Event);
+    p^.Event := nil;
     pnext := p^.Next;
     pnext := p^.Next;
     Dispose(p);
     Dispose(p);
     p := pnext;
     p := pnext;
@@ -73,7 +84,7 @@ begin
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
-procedure TEventQueue.AddEvent(event: TPTCEvent);
+procedure TEventQueue.AddEvent(const event: IPTCEvent);
 var
 var
   tmp: PEventLinkedList;
   tmp: PEventLinkedList;
 begin
 begin
@@ -94,7 +105,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-function TEventQueue.PeekEvent(const EventMask: TPTCEventMask): TPTCEvent;
+function TEventQueue.PeekEvent(const EventMask: TPTCEventMask): IPTCEvent;
 var
 var
   p: PEventLinkedList;
   p: PEventLinkedList;
 begin
 begin
@@ -112,7 +123,7 @@ begin
   Result := nil;
   Result := nil;
 end;
 end;
 
 
-function TEventQueue.NextEvent(const EventMask: TPTCEventMask): TPTCEvent;
+function TEventQueue.NextEvent(const EventMask: TPTCEventMask): IPTCEvent;
 var
 var
   prev, p: PEventLinkedList;
   prev, p: PEventLinkedList;
 begin
 begin
@@ -123,6 +134,7 @@ begin
     if p^.Event.EventType In EventMask then
     if p^.Event.EventType In EventMask then
     begin
     begin
       Result := p^.Event;
       Result := p^.Event;
+      p^.Event := nil;
 
 
       { delete the element from the linked list }
       { delete the element from the linked list }
       if prev <> nil then
       if prev <> nil then

+ 28 - 19
packages/ptc/src/core/formatd.inc

@@ -31,27 +31,36 @@
 }
 }
 
 
 type
 type
-  TPTCFormat = class
-  private
-    FFormat: THermesFormat;
+  IPTCFormat = interface
+    function GetHermesFormat: PHermesFormat;
+
+    function Equals(AFormat: IPTCFormat): Boolean;
+
+    function GetR: Uint32;
+    function GetG: Uint32;
+    function GetB: Uint32;
+    function GetA: Uint32;
+    function GetBits: Integer;
+    function GetIndexed: Boolean;
     function GetDirect: Boolean;
     function GetDirect: Boolean;
     function GetBytes: Integer;
     function GetBytes: Integer;
-  public
-    constructor Create;
-    constructor Create(ABits: Integer);
-    constructor Create(ABits: Integer;
-                       ARedMask, AGreenMask, ABlueMask: Uint32;
-                       AAlphaMask: Uint32 = 0);
-    constructor Create(const format: TPTCFormat);
-    destructor Destroy; override;
-    procedure Assign(const format: TPTCFormat);
-    function Equals(const format: TPTCFormat): Boolean;
-    property R: Uint32 read FFormat.r;
-    property G: Uint32 read FFormat.g;
-    property B: Uint32 read FFormat.b;
-    property A: Uint32 read FFormat.a;
-    property Bits: Integer read FFormat.bits;
-    property Indexed: Boolean read FFormat.indexed;
+
+    property R: Uint32 read GetR;
+    property G: Uint32 read GetG;
+    property B: Uint32 read GetB;
+    property A: Uint32 read GetA;
+    property Bits: Integer read GetBits;
+    property Indexed: Boolean read GetIndexed;
     property Direct: Boolean read GetDirect;
     property Direct: Boolean read GetDirect;
     property Bytes: Integer read GetBytes;
     property Bytes: Integer read GetBytes;
   end;
   end;
+
+  TPTCFormatFactory = class
+  public
+    class function CreateNew: IPTCFormat;
+    class function CreateNew(ABits: Integer): IPTCFormat;
+    class function CreateNew(ABits: Integer;
+                             ARedMask, AGreenMask, ABlueMask: Uint32;
+                             AAlphaMask: Uint32 = 0): IPTCFormat;
+    class function CreateNew(AFormat: IPTCFormat): IPTCFormat;
+  end;

+ 95 - 5
packages/ptc/src/core/formati.inc

@@ -30,6 +30,61 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 }
 }
 
 
+type
+  TPTCFormat = class(TInterfacedObject, IPTCFormat)
+  private
+    FFormat: THermesFormat;
+    function GetHermesFormat: PHermesFormat;
+    function Equals(AFormat: IPTCFormat): Boolean;
+    function GetR: Uint32;
+    function GetG: Uint32;
+    function GetB: Uint32;
+    function GetA: Uint32;
+    function GetBits: Integer;
+    function GetIndexed: Boolean;
+    function GetDirect: Boolean;
+    function GetBytes: Integer;
+  public
+    constructor Create;
+    constructor Create(ABits: Integer);
+    constructor Create(ABits: Integer;
+                       ARedMask, AGreenMask, ABlueMask: Uint32;
+                       AAlphaMask: Uint32 = 0);
+    constructor Create(AFormat: IPTCFormat);
+    destructor Destroy; override;
+//    procedure Assign(const format: TPTCFormat);
+{    property R: Uint32 read GetR;
+    property G: Uint32 read GetG;
+    property B: Uint32 read GetB;
+    property A: Uint32 read GetA;
+    property Bits: Integer read GetBits;
+    property Indexed: Boolean read GetIndexed;
+    property Direct: Boolean read GetDirect;
+    property Bytes: Integer read GetBytes;}
+  end;
+
+class function TPTCFormatFactory.CreateNew: IPTCFormat;
+begin
+  Result := TPTCFormat.Create;
+end;
+
+class function TPTCFormatFactory.CreateNew(ABits: Integer): IPTCFormat;
+begin
+  Result := TPTCFormat.Create(ABits);
+end;
+
+class function TPTCFormatFactory.CreateNew(ABits: Integer;
+                                           ARedMask, AGreenMask, ABlueMask: Uint32;
+                                           AAlphaMask: Uint32 = 0): IPTCFormat;
+begin
+  Result := TPTCFormat.Create(ABits, ARedMask, AGreenMask, ABlueMask, AAlphaMask);
+end;
+
+class function TPTCFormatFactory.CreateNew(AFormat: IPTCFormat): IPTCFormat;
+begin
+  Result := TPTCFormat.Create(AFormat);
+end;
+
 constructor TPTCFormat.Create;
 constructor TPTCFormat.Create;
 begin
 begin
   { defaults }
   { defaults }
@@ -85,13 +140,13 @@ begin
     raise TPTCError.Create('could not initialize hermes');
     raise TPTCError.Create('could not initialize hermes');
 end;
 end;
 
 
-constructor TPTCFormat.Create(const format: TPTCFormat);
+constructor TPTCFormat.Create(AFormat: IPTCFormat);
 begin
 begin
   { initialize hermes }
   { initialize hermes }
   if not Hermes_Init then
   if not Hermes_Init then
     raise TPTCError.Create('could not initialize hermes');
     raise TPTCError.Create('could not initialize hermes');
 
 
-  Hermes_FormatCopy(@format.FFormat, @FFormat)
+  Hermes_FormatCopy(AFormat.GetHermesFormat, @FFormat)
 end;
 end;
 
 
 {$INFO TODO: check what happens if Hermes_Init blows up in the constructor...}
 {$INFO TODO: check what happens if Hermes_Init blows up in the constructor...}
@@ -102,16 +157,51 @@ begin
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
-procedure TPTCFormat.Assign(const format: TPTCFormat);
+function TPTCFormat.GetHermesFormat: PHermesFormat;
+begin
+  Result := @Fformat;
+end;
+
+{procedure TPTCFormat.Assign(const format: TPTCFormat);
 begin
 begin
   if Self = format then
   if Self = format then
     exit;
     exit;
   Hermes_FormatCopy(@format.Fformat, @Fformat);
   Hermes_FormatCopy(@format.Fformat, @Fformat);
+end;}
+
+function TPTCFormat.Equals(AFormat: IPTCFormat): Boolean;
+begin
+  Result := Hermes_FormatEquals(AFormat.GetHermesFormat, @FFormat);
+end;
+
+function TPTCFormat.GetR: Uint32;
+begin
+  Result := FFormat.r;
+end;
+
+function TPTCFormat.GetG: Uint32;
+begin
+  Result := FFormat.g;
+end;
+
+function TPTCFormat.GetB: Uint32;
+begin
+  Result := FFormat.b;
+end;
+
+function TPTCFormat.GetA: Uint32;
+begin
+  Result := FFormat.a;
+end;
+
+function TPTCFormat.GetBits: Integer;
+begin
+  Result := FFormat.bits;
 end;
 end;
 
 
-function TPTCFormat.Equals(const format: TPTCFormat): Boolean;
+function TPTCFormat.GetIndexed: Boolean;
 begin
 begin
-  Result := Hermes_FormatEquals(@format.FFormat, @FFormat);
+  Result := FFormat.indexed;
 end;
 end;
 
 
 function TPTCFormat.GetDirect: Boolean;
 function TPTCFormat.GetDirect: Boolean;

+ 32 - 31
packages/ptc/src/core/keyeventd.inc

@@ -31,41 +31,42 @@
 }
 }
 
 
 type
 type
-  TPTCKeyEvent = class(TPTCEvent)
-  private
-    FCode: Integer;
-    FUnicode: Integer;
-    FAlt: Boolean;
-    FShift: Boolean;
-    FControl: Boolean;
-    FPress: Boolean;
-
+  IPTCKeyEvent = interface(IPTCEvent)
+    ['{9BD1CD41-1DF6-4392-99DC-885EADB6D85A}']
+    function GetCode: Integer;
+    function GetUnicode: Integer;
+    function GetAlt: Boolean;
+    function GetShift: Boolean;
+    function GetControl: Boolean;
+    function GetPress: Boolean;
     function GetRelease: Boolean;
     function GetRelease: Boolean;
-  protected
-    function GetType: TPTCEventType; override;
-  public
-    constructor Create;
-    constructor Create(ACode: Integer);
-    constructor Create(ACode, AUnicode: Integer);
-    constructor Create(ACode, AUnicode: Integer; APress: Boolean);
-    constructor Create(ACode: Integer; AAlt, AShift, AControl: Boolean);
-    constructor Create(ACode: Integer; AAlt, AShift, AControl, APress: Boolean);
-    constructor Create(ACode, AUnicode: Integer;
-                       AAlt, AShift, AControl: Boolean);
-    constructor Create(ACode, AUnicode: Integer;
-                       AAlt, AShift, AControl, APress: Boolean);
-    constructor Create(const AKey: TPTCKeyEvent);
-    procedure Assign(const AKey: TPTCKeyEvent);
-    function Equals(const AKey: TPTCKeyEvent): Boolean;
-    property Code: Integer read FCode;
-    property Unicode: Integer read FUnicode;
-    property Alt: Boolean read FAlt;
-    property Shift: Boolean read FShift;
-    property Control: Boolean read FControl;
-    property Press: Boolean read FPress;
+
+//    function Equals(AKey: IPTCKeyEvent): Boolean;
+
+    property Code: Integer read GetCode;
+    property Unicode: Integer read GetUnicode;
+    property Alt: Boolean read GetAlt;
+    property Shift: Boolean read GetShift;
+    property Control: Boolean read GetControl;
+    property Press: Boolean read GetPress;
     property Release: Boolean read GetRelease;
     property Release: Boolean read GetRelease;
   end;
   end;
 
 
+  TPTCKeyEventFactory = class
+  public
+    class function CreateNew: IPTCKeyEvent;
+    class function CreateNew(ACode: Integer): IPTCKeyEvent;
+    class function CreateNew(ACode, AUnicode: Integer): IPTCKeyEvent;
+    class function CreateNew(ACode, AUnicode: Integer; APress: Boolean): IPTCKeyEvent;
+    class function CreateNew(ACode: Integer; AAlt, AShift, AControl: Boolean): IPTCKeyEvent;
+    class function CreateNew(ACode: Integer; AAlt, AShift, AControl, APress: Boolean): IPTCKeyEvent;
+    class function CreateNew(ACode, AUnicode: Integer;
+                             AAlt, AShift, AControl: Boolean): IPTCKeyEvent;
+    class function CreateNew(ACode, AUnicode: Integer;
+                             AAlt, AShift, AControl, APress: Boolean): IPTCKeyEvent;
+    class function CreateNew(AKey: IPTCKeyEvent): IPTCKeyEvent;
+  end;
+
 const
 const
   PTCKEY_UNDEFINED    = $00;
   PTCKEY_UNDEFINED    = $00;
   PTCKEY_CANCEL       = $03;
   PTCKEY_CANCEL       = $03;

+ 121 - 3
packages/ptc/src/core/keyeventi.inc

@@ -29,8 +29,96 @@
     License along with this library; if not, write to the Free Software
     License along with this library; if not, write to the Free Software
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 }
 }
+type
+  TPTCKeyEvent = class(TPTCEvent, IPTCKeyEvent)
+  private
+    FCode: Integer;
+    FUnicode: Integer;
+    FAlt: Boolean;
+    FShift: Boolean;
+    FControl: Boolean;
+    FPress: Boolean;
 
 
-function TPTCKeyEvent.GetType: TPTCEventType;
+    function GetCode: Integer;
+    function GetUnicode: Integer;
+    function GetAlt: Boolean;
+    function GetShift: Boolean;
+    function GetControl: Boolean;
+    function GetPress: Boolean;
+    function GetRelease: Boolean;
+  protected
+    function GetEventType: TPTCEventType; override;
+  public
+    constructor Create;
+    constructor Create(ACode: Integer);
+    constructor Create(ACode, AUnicode: Integer);
+    constructor Create(ACode, AUnicode: Integer; APress: Boolean);
+    constructor Create(ACode: Integer; AAlt, AShift, AControl: Boolean);
+    constructor Create(ACode: Integer; AAlt, AShift, AControl, APress: Boolean);
+    constructor Create(ACode, AUnicode: Integer;
+                       AAlt, AShift, AControl: Boolean);
+    constructor Create(ACode, AUnicode: Integer;
+                       AAlt, AShift, AControl, APress: Boolean);
+    constructor Create(AKey: IPTCKeyEvent);
+{    procedure Assign(const AKey: TPTCKeyEvent);
+    function Equals(const AKey: TPTCKeyEvent): Boolean;
+    property Code: Integer read GetCode;
+    property Unicode: Integer read GetUnicode;
+    property Alt: Boolean read GetAlt;
+    property Shift: Boolean read GetShift;
+    property Control: Boolean read GetControl;
+    property Press: Boolean read GetPress;
+    property Release: Boolean read GetRelease;}
+  end;
+
+class function TPTCKeyEventFactory.CreateNew: IPTCKeyEvent;
+begin
+  Result := TPTCKeyEvent.Create;
+end;
+
+class function TPTCKeyEventFactory.CreateNew(ACode: Integer): IPTCKeyEvent;
+begin
+  Result := TPTCKeyEvent.Create(ACode);
+end;
+
+class function TPTCKeyEventFactory.CreateNew(ACode, AUnicode: Integer): IPTCKeyEvent;
+begin
+  Result := TPTCKeyEvent.Create(ACode, AUnicode);
+end;
+
+class function TPTCKeyEventFactory.CreateNew(ACode, AUnicode: Integer; APress: Boolean): IPTCKeyEvent;
+begin
+  Result := TPTCKeyEvent.Create(ACode, AUnicode, APress);
+end;
+
+class function TPTCKeyEventFactory.CreateNew(ACode: Integer; AAlt, AShift, AControl: Boolean): IPTCKeyEvent;
+begin
+  Result := TPTCKeyEvent.Create(ACode, AAlt, AShift, AControl);
+end;
+
+class function TPTCKeyEventFactory.CreateNew(ACode: Integer; AAlt, AShift, AControl, APress: Boolean): IPTCKeyEvent;
+begin
+  Result := TPTCKeyEvent.Create(ACode, AAlt, AShift, AControl, APress);
+end;
+
+class function TPTCKeyEventFactory.CreateNew(ACode, AUnicode: Integer;
+                                             AAlt, AShift, AControl: Boolean): IPTCKeyEvent;
+begin
+  Result := TPTCKeyEvent.Create(ACode, AUnicode, AAlt, AShift, AControl);
+end;
+
+class function TPTCKeyEventFactory.CreateNew(ACode, AUnicode: Integer;
+                                             AAlt, AShift, AControl, APress: Boolean): IPTCKeyEvent;
+begin
+  Result := TPTCKeyEvent.Create(ACode, AUnicode, AAlt, AShift, AControl, APress);
+end;
+
+class function TPTCKeyEventFactory.CreateNew(AKey: IPTCKeyEvent): IPTCKeyEvent;
+begin
+  Result := TPTCKeyEvent.Create(AKey);
+end;
+
+function TPTCKeyEvent.GetEventType: TPTCEventType;
 begin
 begin
   Result := PTCKeyEvent;
   Result := PTCKeyEvent;
 end;
 end;
@@ -116,7 +204,7 @@ begin
   FPress   := APress;
   FPress   := APress;
 end;
 end;
 
 
-constructor TPTCKeyEvent.Create(const AKey: TPTCKeyEvent);
+constructor TPTCKeyEvent.Create(AKey: IPTCKeyEvent);
 begin
 begin
   FCode    := AKey.Code;
   FCode    := AKey.Code;
   FUnicode := AKey.Unicode;
   FUnicode := AKey.Unicode;
@@ -126,7 +214,7 @@ begin
   FPress   := AKey.Press;
   FPress   := AKey.Press;
 end;
 end;
 
 
-procedure TPTCKeyEvent.Assign(const AKey: TPTCKeyEvent);
+{procedure TPTCKeyEvent.Assign(const AKey: TPTCKeyEvent);
 begin
 begin
   FCode    := AKey.Code;
   FCode    := AKey.Code;
   FUnicode := AKey.Unicode;
   FUnicode := AKey.Unicode;
@@ -144,6 +232,36 @@ begin
             (FShift   = AKey.FShift) and
             (FShift   = AKey.FShift) and
             (FControl = AKey.FControl) and
             (FControl = AKey.FControl) and
             (FPress   = AKey.FPress);
             (FPress   = AKey.FPress);
+end;}
+
+function TPTCKeyEvent.GetCode: Integer;
+begin
+  Result := FCode;
+end;
+
+function TPTCKeyEvent.GetUnicode: Integer;
+begin
+  Result := FUnicode;
+end;
+
+function TPTCKeyEvent.GetAlt: Boolean;
+begin
+  Result := FAlt;
+end;
+
+function TPTCKeyEvent.GetShift: Boolean;
+begin
+  Result := FShift;
+end;
+
+function TPTCKeyEvent.GetControl: Boolean;
+begin
+  Result := FControl;
+end;
+
+function TPTCKeyEvent.GetPress: Boolean;
+begin
+  Result := FPress;
 end;
 end;
 
 
 function TPTCKeyEvent.GetRelease: Boolean;
 function TPTCKeyEvent.GetRelease: Boolean;

+ 1 - 1
packages/ptc/src/core/log.inc

@@ -174,7 +174,7 @@ begin
   LOG_close;
   LOG_close;
 end;
 end;
 
 
-procedure LOG(const message: string; data: TPTCFormat);
+procedure LOG(const message: string; data: IPTCFormat);
 begin
 begin
   if not LOG_enabled then
   if not LOG_enabled then
     exit;
     exit;

+ 21 - 17
packages/ptc/src/core/moded.inc

@@ -31,22 +31,26 @@
 }
 }
 
 
 type
 type
-  PPTCMode=^TPTCMode;
-  TPTCMode = class
-  private
-    FValid: Boolean;
-    FWidth: Integer;
-    FHeight: Integer;
-    FFormat: TPTCFormat;
+  IPTCMode = interface
+    function GetValid: Boolean;
+    function GetWidth: Integer;
+    function GetHeight: Integer;
+    function GetFormat: IPTCFormat;
+
+    function Equals(AMode: IPTCMode): Boolean;
+
+    property Valid: Boolean read GetValid;
+    property Width: Integer read GetWidth;
+    property Height: Integer read GetHeight;
+    property Format: IPTCFormat read GetFormat;
+  end;
+
+  TPTCModeList = array of IPTCMode;
+
+  TPTCModeFactory = class
   public
   public
-    constructor Create;
-    constructor Create(AWidth, AHeight: Integer; const AFormat: TPTCFormat);
-    constructor Create(const mode: TPTCMode);
-    destructor Destroy; override;
-    procedure Assign(const mode: TPTCMode);
-    function Equals(const mode: TPTCMode): Boolean;
-    property Valid: Boolean read FValid;
-    property Width: Integer read FWidth;
-    property Height: Integer read FHeight;
-    property Format: TPTCFormat read FFormat;
+    class function CreateNew: IPTCMode;
+    class function CreateNew(AWidth, AHeight: Integer; AFormat: IPTCFormat): IPTCMode;
+    class function CreateNew(AMode: IPTCMode): IPTCMode;
   end;
   end;
+

+ 67 - 18
packages/ptc/src/core/modei.inc

@@ -31,7 +31,42 @@
 }
 }
 
 
 type
 type
-  TPTCModeDynArray = array of TPTCMode;
+  TPTCMode = class(TInterfacedObject, IPTCMode)
+  private
+    FValid: Boolean;
+    FWidth: Integer;
+    FHeight: Integer;
+    FFormat: IPTCFormat;
+    function GetValid: Boolean;
+    function GetWidth: Integer;
+    function GetHeight: Integer;
+    function GetFormat: IPTCFormat;
+  public
+    constructor Create;
+    constructor Create(AWidth, AHeight: Integer; AFormat: IPTCFormat);
+    constructor Create(AMode: IPTCMode);
+{    procedure Assign(const mode: TPTCMode);}
+    function Equals(AMode: IPTCMode): Boolean;
+{    property Valid: Boolean read GetValid;
+    property Width: Integer read GetWidth;
+    property Height: Integer read GetHeight;
+    property Format: IPTCFormat read GetFormat;}
+  end;
+
+class function TPTCModeFactory.CreateNew: IPTCMode;
+begin
+  Result := TPTCMode.Create;
+end;
+
+class function TPTCModeFactory.CreateNew(AWidth, AHeight: Integer; AFormat: IPTCFormat): IPTCMode;
+begin
+  Result := TPTCMode.Create(AWidth, AHeight, AFormat);
+end;
+
+class function TPTCModeFactory.CreateNew(AMode: IPTCMode): IPTCMode;
+begin
+  Result := TPTCMode.Create(AMode);
+end;
 
 
 constructor TPTCMode.Create;
 constructor TPTCMode.Create;
 begin
 begin
@@ -41,40 +76,54 @@ begin
   FValid := False;
   FValid := False;
 end;
 end;
 
 
-constructor TPTCMode.Create(AWidth, AHeight: Integer; const AFormat: TPTCFormat);
+constructor TPTCMode.Create(AWidth, AHeight: Integer; AFormat: IPTCFormat);
 begin
 begin
-  FFormat := TPTCFormat.Create(AFormat);
+  FFormat := AFormat;
   FWidth := AWidth;
   FWidth := AWidth;
   FHeight := AHeight;
   FHeight := AHeight;
   FValid := True;
   FValid := True;
 end;
 end;
 
 
-constructor TPTCMode.Create(const mode: TPTCMode);
+constructor TPTCMode.Create(AMode: IPTCMode);
 begin
 begin
-  FFormat := TPTCFormat.Create(mode.FFormat);
+  FFormat := AMode.Format;
+  FWidth := AMode.Width;
+  FHeight := AMode.Height;
+  FValid := AMode.Valid;
+end;
+
+{procedure TPTCMode.Assign(const mode: TPTCMode);
+begin
+  FFormat := mode.FFormat;
   FWidth := mode.FWidth;
   FWidth := mode.FWidth;
   FHeight := mode.FHeight;
   FHeight := mode.FHeight;
   FValid := mode.FValid;
   FValid := mode.FValid;
 end;
 end;
+}
+function TPTCMode.Equals(AMode: IPTCMode): Boolean;
+begin
+  Result := (FValid = AMode.Valid) and
+            (FWidth = AMode.Width) and
+            (FHeight = AMode.Height) and
+             FFormat.Equals(AMode.Format);
+end;
 
 
-destructor TPTCMode.Destroy;
+function TPTCMode.GetValid: Boolean;
 begin
 begin
-  FFormat.Free;
-  inherited Destroy;
+  Result := FValid;
 end;
 end;
 
 
-procedure TPTCMode.Assign(const mode: TPTCMode);
+function TPTCMode.GetWidth: Integer;
 begin
 begin
-  FFormat.Assign(mode.FFormat);
-  FWidth := mode.FWidth;
-  FHeight := mode.FHeight;
-  FValid := mode.FValid;
+  Result := FWidth;
+end;
+
+function TPTCMode.GetHeight: Integer;
+begin
+  Result := FHeight;
 end;
 end;
 
 
-function TPTCMode.Equals(const mode: TPTCMode): Boolean;
+function TPTCMode.GetFormat: IPTCFormat;
 begin
 begin
-  Result := (FValid = mode.FValid) and
-            (FWidth = mode.FWidth) and
-            (FHeight = mode.FHeight) and
-             FFormat.Equals(mode.FFormat);
+  Result := FFormat;
 end;
 end;

+ 30 - 23
packages/ptc/src/core/mouseeventd.inc

@@ -39,30 +39,37 @@ type
                      PTCMouseButton3, { middle mouse button }
                      PTCMouseButton3, { middle mouse button }
                      PTCMouseButton4,
                      PTCMouseButton4,
                      PTCMouseButton5);
                      PTCMouseButton5);
-  TPTCMouseButtonState = Set of TPTCMouseButton;
-  TPTCMouseEvent = Class(TPTCEvent)
-  private
-    FX, FY: Integer;
-    FDeltaX, FDeltaY: Integer;
-    FButtonState: TPTCMouseButtonState;
-  protected
-    function GetType: TPTCEventType; override;
-  public
-    constructor Create(AX, AY, ADeltaX, ADeltaY: Integer; AButtonState: TPTCMouseButtonState);
-    property X: Integer read FX;
-    property Y: Integer read FY;
-    property DeltaX: Integer read FDeltaX;
-    property DeltaY: Integer read FDeltaY;
-    property ButtonState: TPTCMouseButtonState read FButtonState;
+  TPTCMouseButtonState = set of TPTCMouseButton;
+  IPTCMouseEvent = interface(IPTCEvent)
+    ['{4D093608-6F27-4578-B41E-3492A4C7FEED}']
+    function GetX: Integer;
+    function GetY: Integer;
+    function GetDeltaX: Integer;
+    function GetDeltaY: Integer;
+    function GetButtonState: TPTCMouseButtonState;
+
+    property X: Integer read GetX;
+    property Y: Integer read GetY;
+    property DeltaX: Integer read GetDeltaX;
+    property DeltaY: Integer read GetDeltaY;
+    property ButtonState: TPTCMouseButtonState read GetButtonState;
   end;
   end;
-  TPTCMouseButtonEvent = Class(TPTCMouseEvent)
-  private
-    FPress: Boolean;
-    FButton: TPTCMouseButton;
+  IPTCMouseButtonEvent = interface(IPTCMouseEvent)
+    ['{363B9ACC-4DEB-4031-8BD9-0B6788C6CFA7}']
+    function GetPress: Boolean;
     function GetRelease: Boolean;
     function GetRelease: Boolean;
-  public
-    constructor Create(AX, AY, ADeltaX, ADeltaY: Integer; AButtonState: TPTCMouseButtonState; APress: Boolean; AButton: TPTCMouseButton);
-    property Press: Boolean read FPress;
+    function GetButton: TPTCMouseButton;
+
+    property Press: Boolean read GetPress;
     property Release: Boolean read GetRelease;
     property Release: Boolean read GetRelease;
-    property Button: TPTCMouseButton read FButton;
+    property Button: TPTCMouseButton read GetButton;
+  end;
+
+  TPTCMouseEventFactory = class
+  public
+    class function CreateNew(AX, AY, ADeltaX, ADeltaY: Integer; AButtonState: TPTCMouseButtonState): IPTCMouseEvent;
+  end;
+  TPTCMouseButtonEventFactory = class
+  public
+    class function CreateNew(AX, AY, ADeltaX, ADeltaY: Integer; AButtonState: TPTCMouseButtonState; APress: Boolean; AButton: TPTCMouseButton): IPTCMouseButtonEvent;
   end;
   end;

+ 81 - 1
packages/ptc/src/core/mouseeventi.inc

@@ -30,7 +30,52 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 }
 }
 
 
-function TPTCMouseEvent.GetType: TPTCEventType;
+type
+  TPTCMouseEvent = class(TPTCEvent, IPTCMouseEvent)
+  private
+    FX, FY: Integer;
+    FDeltaX, FDeltaY: Integer;
+    FButtonState: TPTCMouseButtonState;
+    function GetX: Integer;
+    function GetY: Integer;
+    function GetDeltaX: Integer;
+    function GetDeltaY: Integer;
+    function GetButtonState: TPTCMouseButtonState;
+  protected
+    function GetEventType: TPTCEventType; override;
+  public
+    constructor Create(AX, AY, ADeltaX, ADeltaY: Integer; AButtonState: TPTCMouseButtonState);
+{    property X: Integer read GetX;
+    property Y: Integer read GetY;
+    property DeltaX: Integer read GetDeltaX;
+    property DeltaY: Integer read GetDeltaY;
+    property ButtonState: TPTCMouseButtonState read GetButtonState;}
+  end;
+  TPTCMouseButtonEvent = class(TPTCMouseEvent, IPTCMouseButtonEvent)
+  private
+    FPress: Boolean;
+    FButton: TPTCMouseButton;
+    function GetPress: Boolean;
+    function GetRelease: Boolean;
+    function GetButton: TPTCMouseButton;
+  public
+    constructor Create(AX, AY, ADeltaX, ADeltaY: Integer; AButtonState: TPTCMouseButtonState; APress: Boolean; AButton: TPTCMouseButton);
+{    property Press: Boolean read GetPress;
+    property Release: Boolean read GetRelease;
+    property Button: TPTCMouseButton read GetButton;}
+  end;
+
+class function TPTCMouseEventFactory.CreateNew(AX, AY, ADeltaX, ADeltaY: Integer; AButtonState: TPTCMouseButtonState): IPTCMouseEvent;
+begin
+  Result := TPTCMouseEvent.Create(AX, AY, ADeltaX, ADeltaY, AButtonState);
+end;
+
+class function TPTCMouseButtonEventFactory.CreateNew(AX, AY, ADeltaX, ADeltaY: Integer; AButtonState: TPTCMouseButtonState; APress: Boolean; AButton: TPTCMouseButton): IPTCMouseButtonEvent;
+begin
+  Result := TPTCMouseButtonEvent.Create(AX, AY, ADeltaX, ADeltaY, AButtonState, APress, AButton);
+end;
+
+function TPTCMouseEvent.GetEventType: TPTCEventType;
 begin
 begin
   Result := PTCMouseEvent;
   Result := PTCMouseEvent;
 end;
 end;
@@ -44,6 +89,31 @@ begin
   FButtonState := AButtonState;
   FButtonState := AButtonState;
 end;
 end;
 
 
+function TPTCMouseEvent.GetX: Integer;
+begin
+  Result := FX;
+end;
+
+function TPTCMouseEvent.GetY: Integer;
+begin
+  Result := FY;
+end;
+
+function TPTCMouseEvent.GetDeltaX: Integer;
+begin
+  Result := FDeltaX;
+end;
+
+function TPTCMouseEvent.GetDeltaY: Integer;
+begin
+  Result := FDeltaY;
+end;
+
+function TPTCMouseEvent.GetButtonState: TPTCMouseButtonState;
+begin
+  Result := FButtonState;
+end;
+
 constructor TPTCMouseButtonEvent.Create(AX, AY, ADeltaX, ADeltaY: Integer; AButtonState: TPTCMouseButtonState; APress: Boolean; AButton: TPTCMouseButton);
 constructor TPTCMouseButtonEvent.Create(AX, AY, ADeltaX, ADeltaY: Integer; AButtonState: TPTCMouseButtonState; APress: Boolean; AButton: TPTCMouseButton);
 begin
 begin
   if APress xor (AButton In AButtonState) then
   if APress xor (AButton In AButtonState) then
@@ -55,7 +125,17 @@ begin
   FButton := AButton;
   FButton := AButton;
 end;
 end;
 
 
+function TPTCMouseButtonEvent.GetPress: Boolean;
+begin
+  Result := FPress;
+end;
+
 function TPTCMouseButtonEvent.GetRelease: Boolean;
 function TPTCMouseButtonEvent.GetRelease: Boolean;
 begin
 begin
   Result := not FPress;
   Result := not FPress;
 end;
 end;
+
+function TPTCMouseButtonEvent.GetButton: TPTCMouseButton;
+begin
+  Result := FButton;
+end;

+ 9 - 11
packages/ptc/src/core/paletted.inc

@@ -31,17 +31,7 @@
 }
 }
 
 
 type
 type
-  TPTCPalette = class
-  private
-    FLocked: Boolean;
-    FHandle: THermesPaletteHandle;
-  public
-    constructor Create;
-    constructor Create(const AData: array of Uint32);
-    constructor Create(const APalette: TPTCPalette);
-    destructor Destroy; override;
-    procedure Assign(const APalette: TPTCPalette);
-    function Equals(const APalette: TPTCPalette): Boolean;
+  IPTCPalette = interface
     function Lock: PUint32;
     function Lock: PUint32;
     procedure Unlock;
     procedure Unlock;
     procedure Load(const AData: array of Uint32);
     procedure Load(const AData: array of Uint32);
@@ -49,4 +39,12 @@ type
     procedure Save(var AData: array of Uint32);
     procedure Save(var AData: array of Uint32);
     procedure Save(AData: Pointer);
     procedure Save(AData: Pointer);
     function Data: PUint32;
     function Data: PUint32;
+    function GetHermesPaletteHandle: THermesPaletteHandle;
+  end;
+
+  TPTCPaletteFactory = class
+  public
+    class function CreateNew: IPTCPalette;
+    class function CreateNew(const AData: array of Uint32): IPTCPalette;
+    class function CreateNew(APalette: IPTCPalette): IPTCPalette;
   end;
   end;

+ 46 - 4
packages/ptc/src/core/palettei.inc

@@ -30,6 +30,43 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 }
 }
 
 
+type
+  TPTCPalette = class(TInterfacedObject, IPTCPalette)
+  private
+    FLocked: Boolean;
+    FHandle: THermesPaletteHandle;
+  public
+    constructor Create;
+    constructor Create(const AData: array of Uint32);
+    constructor Create(APalette: IPTCPalette);
+    destructor Destroy; override;
+//    procedure Assign(const APalette: TPTCPalette);
+//    function Equals(const APalette: TPTCPalette): Boolean;
+    function Lock: PUint32;
+    procedure Unlock;
+    procedure Load(const AData: array of Uint32);
+    procedure Load(AData: Pointer);
+    procedure Save(var AData: array of Uint32);
+    procedure Save(AData: Pointer);
+    function Data: PUint32;
+    function GetHermesPaletteHandle: THermesPaletteHandle;
+  end;
+
+class function TPTCPaletteFactory.CreateNew: IPTCPalette;
+begin
+  Result := TPTCPalette.Create;
+end;
+
+class function TPTCPaletteFactory.CreateNew(const AData: array of Uint32): IPTCPalette;
+begin
+  Result := TPTCPalette.Create(AData);
+end;
+
+class function TPTCPaletteFactory.CreateNew(APalette: IPTCPalette): IPTCPalette;
+begin
+  Result := TPTCPalette.Create(APalette);
+end;
+
 constructor TPTCPalette.Create;
 constructor TPTCPalette.Create;
 var
 var
   zero: array [0..255] of Uint32;
   zero: array [0..255] of Uint32;
@@ -55,7 +92,7 @@ begin
   Load(AData);
   Load(AData);
 end;
 end;
 
 
-constructor TPTCPalette.Create(const APalette: TPTCPalette);
+constructor TPTCPalette.Create(APalette: IPTCPalette);
 begin
 begin
   FLocked := False;
   FLocked := False;
   if not Hermes_Init then
   if not Hermes_Init then
@@ -63,7 +100,7 @@ begin
   FHandle := Hermes_PaletteInstance;
   FHandle := Hermes_PaletteInstance;
   if FHandle = nil then
   if FHandle = nil then
     raise TPTCError.Create('could not create hermes palette instance');
     raise TPTCError.Create('could not create hermes palette instance');
-  Assign(APalette);
+  Hermes_PaletteSet(FHandle, Hermes_PaletteGet(APalette.GetHermesPaletteHandle));
 end;
 end;
 
 
 destructor TPTCPalette.Destroy;
 destructor TPTCPalette.Destroy;
@@ -75,7 +112,7 @@ begin
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
-procedure TPTCPalette.Assign(const APalette: TPTCPalette);
+{procedure TPTCPalette.Assign(const APalette: TPTCPalette);
 begin
 begin
   if Self = APalette then
   if Self = APalette then
     exit;
     exit;
@@ -87,7 +124,7 @@ function TPTCPalette.Equals(const APalette: TPTCPalette): Boolean;
 begin
 begin
   Equals := CompareDWord(Hermes_PaletteGet(FHandle)^, Hermes_PaletteGet(APalette.FHandle)^, 1024 div 4) = 0;
   Equals := CompareDWord(Hermes_PaletteGet(FHandle)^, Hermes_PaletteGet(APalette.FHandle)^, 1024 div 4) = 0;
 end;
 end;
-
+}
 function TPTCPalette.Lock: PUint32;
 function TPTCPalette.Lock: PUint32;
 begin
 begin
   if FLocked then
   if FLocked then
@@ -127,3 +164,8 @@ function TPTCPalette.Data: PUint32;
 begin
 begin
   Result := Hermes_PaletteGet(FHandle);
   Result := Hermes_PaletteGet(FHandle);
 end;
 end;
+
+function TPTCPalette.GetHermesPaletteHandle: THermesPaletteHandle;
+begin
+  Result := FHandle;
+end;

+ 2 - 53
packages/ptc/src/core/surfaced.inc

@@ -31,58 +31,7 @@
 }
 }
 
 
 type
 type
-  TPTCSurface = class(TPTCBaseSurface)
-  private
-    {data}
-    FWidth: Integer;
-    FHeight: Integer;
-    FPitch: Integer;
-    FArea: TPTCArea;
-    FClip: TPTCArea;
-    FFormat: TPTCFormat;
-    FLocked: Boolean;
-    FPixels: Pointer;
-    {objects}
-    FCopy: TPTCCopy;
-    FClear: TPTCClear;
-    FPalette: TPTCPalette;
+  TPTCSurfaceFactory = class
   public
   public
-    constructor Create(AWidth, AHeight: Integer; const AFormat: TPTCFormat);
-    destructor Destroy; override;
-    procedure Copy(ASurface: TPTCBaseSurface); override;
-    procedure Copy(ASurface: TPTCBaseSurface;
-                   const ASource, ADestination: TPTCArea); override;
-    function Lock: Pointer; override;
-    procedure Unlock; override;
-    procedure Load(const APixels: Pointer;
-                   AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); override;
-    procedure Load(const APixels: Pointer;
-                   AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); override;
-    procedure Save(APixels: Pointer;
-                   AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); override;
-    procedure Save(APixels: Pointer;
-                   AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); override;
-    procedure Clear; override;
-    procedure Clear(const AColor: TPTCColor); override;
-    procedure Clear(const AColor: TPTCColor; const AArea: TPTCArea); override;
-    procedure Palette(const APalette: TPTCPalette); override;
-    function Palette: TPTCPalette; override;
-    procedure Clip(const AArea: TPTCArea); override;
-    function GetWidth: Integer; override;
-    function GetHeight: Integer; override;
-    function GetPitch: Integer; override;
-    function GetArea: TPTCArea; override;
-    function Clip: TPTCArea; override;
-    function GetFormat: TPTCFormat; override;
-    function Option(const AOption: string): Boolean; override;
+    class function CreateNew(AWidth, AHeight: Integer; AFormat: IPTCFormat): IPTCSurface;
   end;
   end;

+ 129 - 111
packages/ptc/src/core/surfacei.inc

@@ -30,7 +30,75 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 }
 }
 
 
-constructor TPTCSurface.Create(AWidth, AHeight: Integer; const AFormat: TPTCFormat);
+type
+  TPTCSurface = class(TInterfacedObject, IPTCSurface)
+  private
+    {data}
+    FWidth: Integer;
+    FHeight: Integer;
+    FPitch: Integer;
+    FArea: IPTCArea;
+    FClip: IPTCArea;
+    FFormat: IPTCFormat;
+    FLocked: Boolean;
+    FPixels: Pointer;
+    {objects}
+    FCopy: TPTCCopy;
+    FClear: TPTCClear;
+    FPalette: IPTCPalette;
+  public
+    constructor Create(AWidth, AHeight: Integer; AFormat: IPTCFormat);
+    destructor Destroy; override;
+    procedure Copy(ASurface: IPTCSurface);
+    procedure Copy(ASurface: IPTCSurface;
+                   ASource, ADestination: IPTCArea);
+    function Lock: Pointer;
+    procedure Unlock;
+    procedure Load(const APixels: Pointer;
+                   AWidth, AHeight, APitch: Integer;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette);
+    procedure Load(const APixels: Pointer;
+                   AWidth, AHeight, APitch: Integer;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea);
+    procedure Save(APixels: Pointer;
+                   AWidth, AHeight, APitch: Integer;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette);
+    procedure Save(APixels: Pointer;
+                   AWidth, AHeight, APitch: Integer;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea);
+    procedure Clear;
+    procedure Clear(AColor: IPTCColor);
+    procedure Clear(AColor: IPTCColor; AArea: IPTCArea);
+    procedure Palette(APalette: IPTCPalette);
+    function Palette: IPTCPalette;
+    procedure Clip(AArea: IPTCArea);
+    function GetWidth: Integer;
+    function GetHeight: Integer;
+    function GetPitch: Integer;
+    function GetArea: IPTCArea;
+    function Clip: IPTCArea;
+    function GetFormat: IPTCFormat;
+    function Option(const AOption: string): Boolean;
+
+    property Width: Integer read GetWidth;
+    property Height: Integer read GetHeight;
+    property Pitch: Integer read GetPitch;
+    property Area: IPTCArea read GetArea;
+    property Format: IPTCFormat read GetFormat;
+  end;
+
+class function TPTCSurfaceFactory.CreateNew(AWidth, AHeight: Integer; AFormat: IPTCFormat): IPTCSurface;
+begin
+  Result := TPTCSurface.Create(AWidth, AHeight, AFormat);
+end;
+
+constructor TPTCSurface.Create(AWidth, AHeight: Integer; AFormat: IPTCFormat);
 var
 var
   size: Integer;
   size: Integer;
 begin
 begin
@@ -41,7 +109,7 @@ begin
   LOG('format', AFormat);
   LOG('format', AFormat);
   FWidth := AWidth;
   FWidth := AWidth;
   FHeight := AHeight;
   FHeight := AHeight;
-  FFormat := TPTCFormat.Create(AFormat);
+  FFormat := AFormat;
   FArea := TPTCArea.Create(0, 0, AWidth, AHeight);
   FArea := TPTCArea.Create(0, 0, AWidth, AHeight);
   FClip := TPTCArea.Create(FArea);
   FClip := TPTCArea.Create(FArea);
   FPitch := AWidth * AFormat.Bytes;
   FPitch := AWidth * AFormat.Bytes;
@@ -63,21 +131,17 @@ begin
   end;
   end;
   FCopy.Free;
   FCopy.Free;
   FClear.Free;
   FClear.Free;
-  FPalette.Free;
-  FClip.Free;
-  FArea.Free;
-  FFormat.Free;
   FreeMem(FPixels);
   FreeMem(FPixels);
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
-procedure TPTCSurface.Copy(ASurface: TPTCBaseSurface);
+procedure TPTCSurface.Copy(ASurface: IPTCSurface);
 begin
 begin
   ASurface.Load(FPixels, FWidth, FHeight, FPitch, FFormat, FPalette);
   ASurface.Load(FPixels, FWidth, FHeight, FPitch, FFormat, FPalette);
 end;
 end;
 
 
-procedure TPTCSurface.Copy(ASurface: TPTCBaseSurface;
-                           const ASource, ADestination: TPTCArea);
+procedure TPTCSurface.Copy(ASurface: IPTCSurface;
+                           ASource, ADestination: IPTCArea);
 begin
 begin
   ASurface.Load(FPixels, FWidth, FHeight, FPitch, FFormat, FPalette,
   ASurface.Load(FPixels, FWidth, FHeight, FPitch, FFormat, FPalette,
                 ASource, ADestination);
                 ASource, ADestination);
@@ -100,10 +164,8 @@ end;
 
 
 procedure TPTCSurface.Load(const APixels: Pointer;
 procedure TPTCSurface.Load(const APixels: Pointer;
                            AWidth, AHeight, APitch: Integer;
                            AWidth, AHeight, APitch: Integer;
-                           const AFormat: TPTCFormat;
-                           const APalette: TPTCPalette);
-var
-  Area_: TPTCArea;
+                           AFormat: IPTCFormat;
+                           APalette: IPTCPalette);
 begin
 begin
   if FClip.Equals(FArea) then
   if FClip.Equals(FArea) then
   begin
   begin
@@ -113,51 +175,35 @@ begin
                FWidth, FHeight, FPitch);
                FWidth, FHeight, FPitch);
   end
   end
   else
   else
-  begin
-    Area_ := TPTCArea.Create(0, 0, AWidth, AHeight);
-    try
-      Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, Area_, FArea);
-    finally
-      Area_.Free;
-    end;
-  end;
+    Load(APixels, AWidth, AHeight, APitch, AFormat, APalette,
+         TPTCArea.Create(0, 0, AWidth, AHeight), FArea);
 end;
 end;
 
 
 procedure TPTCSurface.Load(const APixels: Pointer;
 procedure TPTCSurface.Load(const APixels: Pointer;
                            AWidth, AHeight, APitch: Integer;
                            AWidth, AHeight, APitch: Integer;
-                           const AFormat: TPTCFormat;
-                           const APalette: TPTCPalette;
-                           const ASource, ADestination: TPTCArea);
+                           AFormat: IPTCFormat;
+                           APalette: IPTCPalette;
+                           ASource, ADestination: IPTCArea);
 var
 var
-  clipped_source: TPTCArea = nil;
-  clipped_destination: TPTCArea = nil;
-  area_: TPTCArea = nil;
+  clipped_source: IPTCArea;
+  clipped_destination: IPTCArea;
 begin
 begin
-  try
-    clipped_source := TPTCArea.Create;
-    clipped_destination := TPTCArea.Create;
-    area_ := TPTCArea.Create(0, 0, AWidth, AHeight);
-    TPTCClipper.Clip(ASource, area_, clipped_source, ADestination, FClip,
-                     clipped_destination);
-    FCopy.Request(AFormat, FFormat);
-    FCopy.Palette(APalette, FPalette);
-    FCopy.Copy(APixels, clipped_source.left, clipped_source.top,
-               clipped_source.width, clipped_source.height, APitch,
-               FPixels, clipped_destination.left, clipped_destination.top,
-               clipped_destination.width, clipped_destination.height, FPitch);
-  finally
-    clipped_source.Free;
-    clipped_destination.Free;
-    area_.Free;
-  end;
+  TPTCClipper.Clip(ASource, TPTCArea.Create(0, 0, AWidth, AHeight),
+                   clipped_source,
+                   ADestination, FClip,
+                   clipped_destination);
+  FCopy.Request(AFormat, FFormat);
+  FCopy.Palette(APalette, FPalette);
+  FCopy.Copy(APixels, clipped_source.left, clipped_source.top,
+             clipped_source.width, clipped_source.height, APitch,
+             FPixels, clipped_destination.left, clipped_destination.top,
+             clipped_destination.width, clipped_destination.height, FPitch);
 end;
 end;
 
 
 procedure TPTCSurface.Save(APixels: Pointer;
 procedure TPTCSurface.Save(APixels: Pointer;
                            AWidth, AHeight, APitch: Integer;
                            AWidth, AHeight, APitch: Integer;
-                           const AFormat: TPTCFormat;
-                           const APalette: TPTCPalette);
-var
-  area_: TPTCArea;
+                           AFormat: IPTCFormat;
+                           APalette: IPTCPalette);
 begin
 begin
   if FClip.Equals(FArea) then
   if FClip.Equals(FArea) then
   begin
   begin
@@ -167,99 +213,71 @@ begin
                AWidth, AHeight, APitch);
                AWidth, AHeight, APitch);
   end
   end
   else
   else
-  begin
-    area_ := TPTCArea.Create(0, 0, width, height);
-    try
-      Save(APixels, AWidth, AHeight, APitch, AFormat, APalette, FArea, area_);
-    finally
-      area_.Free;
-    end;
-  end;
+    Save(APixels, AWidth, AHeight, APitch, AFormat, APalette,
+         FArea, TPTCArea.Create(0, 0, width, height));
 end;
 end;
 
 
 procedure TPTCSurface.Save(APixels: Pointer;
 procedure TPTCSurface.Save(APixels: Pointer;
                            AWidth, AHeight, APitch: Integer;
                            AWidth, AHeight, APitch: Integer;
-                           const AFormat: TPTCFormat;
-                           const APalette: TPTCPalette;
-                           const ASource, ADestination: TPTCArea);
+                           AFormat: IPTCFormat;
+                           APalette: IPTCPalette;
+                           ASource, ADestination: IPTCArea);
 var
 var
-  clipped_source: TPTCArea = nil;
-  clipped_destination: TPTCArea = nil;
-  area_: TPTCArea = nil;
+  clipped_source: IPTCArea;
+  clipped_destination: IPTCArea;
 begin
 begin
-  try
-    clipped_source := TPTCArea.Create;
-    clipped_destination := TPTCArea.Create;
-    area_ := TPTCArea.Create(0, 0, AWidth, AHeight);
-    TPTCClipper.Clip(ASource, FClip, clipped_source, ADestination, area_,
-                     clipped_destination);
-    FCopy.Request(FFormat, AFormat);
-    FCopy.Palette(FPalette, APalette);
-    FCopy.Copy(FPixels, clipped_source.left, clipped_source.top,
-               clipped_source.width, clipped_source.height, FPitch,
-               APixels, clipped_destination.left, clipped_destination.top,
-               clipped_destination.width, clipped_destination.height, APitch);
-  finally
-    clipped_source.Free;
-    clipped_destination.Free;
-    area_.Free;
-  end;
+  TPTCClipper.Clip(ASource, FClip,
+                   clipped_source,
+                   ADestination, TPTCArea.Create(0, 0, AWidth, AHeight),
+                   clipped_destination);
+  FCopy.Request(FFormat, AFormat);
+  FCopy.Palette(FPalette, APalette);
+  FCopy.Copy(FPixels, clipped_source.left, clipped_source.top,
+             clipped_source.width, clipped_source.height, FPitch,
+             APixels, clipped_destination.left, clipped_destination.top,
+             clipped_destination.width, clipped_destination.height, APitch);
 end;
 end;
 
 
 procedure TPTCSurface.Clear;
 procedure TPTCSurface.Clear;
 var
 var
-  Color: TPTCColor;
+  Color: IPTCColor;
 begin
 begin
   if Format.Direct then
   if Format.Direct then
     Color := TPTCColor.Create(0, 0, 0, 0)
     Color := TPTCColor.Create(0, 0, 0, 0)
   else
   else
     Color := TPTCColor.Create(0);
     Color := TPTCColor.Create(0);
-  try
-    Clear(Color);
-  finally
-    Color.Free;
-  end;
+
+  Clear(Color);
 end;
 end;
 
 
-procedure TPTCSurface.Clear(const AColor: TPTCColor);
+procedure TPTCSurface.Clear(AColor: IPTCColor);
 begin
 begin
   Clear(AColor, FArea);
   Clear(AColor, FArea);
 end;
 end;
 
 
-procedure TPTCSurface.Clear(const AColor: TPTCColor; const AArea: TPTCArea);
+procedure TPTCSurface.Clear(AColor: IPTCColor; AArea: IPTCArea);
 var
 var
-  clipped_area: TPTCArea;
+  clipped_area: IPTCArea;
 begin
 begin
-  clipped_area := TPTCClipper.clip(AArea, FClip);
-  try
-    FClear.Request(FFormat);
-    FClear.Clear(FPixels, clipped_area.left, clipped_area.top,
-                 clipped_area.width, clipped_area.height, FPitch, AColor);
-  finally
-    clipped_area.Free;
-  end;
+  clipped_area := TPTCClipper.Clip(AArea, FClip);
+  FClear.Request(FFormat);
+  FClear.Clear(FPixels, clipped_area.left, clipped_area.top,
+               clipped_area.width, clipped_area.height, FPitch, AColor);
 end;
 end;
 
 
-procedure TPTCSurface.Palette(const APalette: TPTCPalette);
+procedure TPTCSurface.Palette(APalette: IPTCPalette);
 begin
 begin
-  FPalette.Load(APalette.data^);
+  FPalette.Load(APalette.Data^);
 end;
 end;
 
 
-function TPTCSurface.Palette: TPTCPalette;
+function TPTCSurface.Palette: IPTCPalette;
 begin
 begin
   Result := FPalette;
   Result := FPalette;
 end;
 end;
 
 
-procedure TPTCSurface.Clip(const AArea: TPTCArea);
-var
-  tmp: TPTCArea;
+procedure TPTCSurface.Clip(AArea: IPTCArea);
 begin
 begin
-  tmp := TPTCClipper.Clip(AArea, FArea);
-  try
-    FClip.Assign(tmp);
-  finally
-    tmp.Free;
-  end;
+  FClip := TPTCClipper.Clip(AArea, FArea);
 end;
 end;
 
 
 function TPTCSurface.GetWidth: Integer;
 function TPTCSurface.GetWidth: Integer;
@@ -277,17 +295,17 @@ begin
   Result := FPitch;
   Result := FPitch;
 end;
 end;
 
 
-function TPTCSurface.GetArea: TPTCArea;
+function TPTCSurface.GetArea: IPTCArea;
 begin
 begin
   Result := FArea;
   Result := FArea;
 end;
 end;
 
 
-function TPTCSurface.Clip: TPTCArea;
+function TPTCSurface.Clip: IPTCArea;
 begin
 begin
   Result := FClip;
   Result := FClip;
 end;
 end;
 
 
-function TPTCSurface.GetFormat: TPTCFormat;
+function TPTCSurface.GetFormat: IPTCFormat;
 begin
 begin
   Result := FFormat;
   Result := FFormat;
 end;
 end;

+ 7 - 19
packages/ptc/src/core/timerd.inc

@@ -31,25 +31,7 @@
 }
 }
 
 
 type
 type
-  TPTCTimer = class
-  private
-    FOld: Double;
-    FTime: Double;
-    FStart: Double;
-    FCurrent: Double;
-    FRunning: Boolean;
-    {$IF defined(WIN32) OR defined(WIN64)}
-    FFrequency: QWord;
-    {$ENDIF defined(WIN32) OR defined(WIN64)}
-    function Clock: Double;
-    procedure internal_init_timer;
-  public
-    constructor Create;
-    constructor Create(ATime: Double);
-    constructor Create(const ATimer: TPTCTimer);
-    destructor Destroy; override;
-    procedure Assign(const ATimer: TPTCTimer);
-    function Equals(const ATimer: TPTCTimer): Boolean;
+  IPTCTimer = interface
     procedure SetTime(ATime: Double); {was 'set' in the C++ version}
     procedure SetTime(ATime: Double); {was 'set' in the C++ version}
     procedure Start;
     procedure Start;
     procedure Stop;
     procedure Stop;
@@ -57,3 +39,9 @@ type
     function Delta: Double;
     function Delta: Double;
     function Resolution: Double;
     function Resolution: Double;
   end;
   end;
+
+  TPTCTimerFactory = class
+  public
+    class function CreateNew: IPTCTimer;
+    class function CreateNew(ATime: Double): IPTCTimer;
+  end;

+ 48 - 5
packages/ptc/src/core/timeri.inc

@@ -30,6 +30,44 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 }
 }
 
 
+type
+  TPTCTimer = class(TInterfacedObject, IPTCTimer)
+  private
+    FOld: Double;
+    FTime: Double;
+    FStart: Double;
+    FCurrent: Double;
+    FRunning: Boolean;
+    {$IF defined(WIN32) OR defined(WIN64)}
+    FFrequency: QWord;
+    {$ENDIF defined(WIN32) OR defined(WIN64)}
+    function Clock: Double;
+    procedure internal_init_timer;
+  public
+    constructor Create;
+    constructor Create(ATime: Double);
+//    constructor Create(ATimer: IPTCTimer);
+    destructor Destroy; override;
+{    procedure Assign(const ATimer: TPTCTimer);
+    function Equals(const ATimer: TPTCTimer): Boolean;}
+    procedure SetTime(ATime: Double); {was 'set' in the C++ version}
+    procedure Start;
+    procedure Stop;
+    function Time: Double;
+    function Delta: Double;
+    function Resolution: Double;
+  end;
+
+class function TPTCTimerFactory.CreateNew: IPTCTimer;
+begin
+  Result := TPTCTimer.Create;
+end;
+
+class function TPTCTimerFactory.CreateNew(ATime: Double): IPTCTimer;
+begin
+  Result := TPTCTimer.Create(ATime);
+end;
+
 {Function timeGetTime: DWord; StdCall; external 'WINMM' name 'timeGetTime';}
 {Function timeGetTime: DWord; StdCall; external 'WINMM' name 'timeGetTime';}
 
 
 constructor TPTCTimer.Create;
 constructor TPTCTimer.Create;
@@ -53,19 +91,24 @@ begin
   SetTime(ATime);
   SetTime(ATime);
 end;
 end;
 
 
-constructor TPTCTimer.Create(const ATimer: TPTCTimer);
+{constructor TPTCTimer.Create(ATimer: IPTCTimer);
 begin
 begin
   internal_init_timer;
   internal_init_timer;
-  Assign(ATimer);
-end;
 
 
+  FOld := ATimer.FOld;
+  FTime := ATimer.FTime;
+  FStart := ATimer.FStart;
+  FCurrent := ATimer.FCurrent;
+  FRunning := ATimer.FRunning;
+end;
+}
 destructor TPTCTimer.Destroy;
 destructor TPTCTimer.Destroy;
 begin
 begin
   Stop;
   Stop;
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
-procedure TPTCTimer.Assign(const ATimer: TPTCTimer);
+{procedure TPTCTimer.Assign(const ATimer: TPTCTimer);
 begin
 begin
   if Self = ATimer then
   if Self = ATimer then
     exit;
     exit;
@@ -83,7 +126,7 @@ begin
             (FStart = ATimer.FStart) and (FCurrent = ATimer.FCurrent) and
             (FStart = ATimer.FStart) and (FCurrent = ATimer.FCurrent) and
             (FRunning = ATimer.FRunning);
             (FRunning = ATimer.FRunning);
 end;
 end;
-
+}
 procedure TPTCTimer.SetTime(ATime: Double);
 procedure TPTCTimer.SetTime(ATime: Double);
 begin
 begin
   FCurrent := ATime;
   FCurrent := ATime;

+ 36 - 36
packages/ptc/src/dos/cga/cgaconsoled.inc

@@ -30,10 +30,10 @@
 }
 }
 
 
 type
 type
-  TCGAConsole = Class(TPTCBaseConsole)
+  TCGAConsole = class(TPTCBaseConsole)
   private
   private
     { data }
     { data }
-    m_modes: array [0..255] of TPTCMode;
+    m_modes: array of IPTCMode;
     m_title: string;
     m_title: string;
     m_information: string;
     m_information: string;
 
 
@@ -44,7 +44,7 @@ type
     { option data }
     { option data }
     m_default_width: Integer;
     m_default_width: Integer;
     m_default_height: Integer;
     m_default_height: Integer;
-    m_default_format: TPTCFormat;
+    m_default_format: IPTCFormat;
 
 
     { objects }
     { objects }
     m_copy: TPTCCopy;
     m_copy: TPTCCopy;
@@ -58,9 +58,9 @@ type
     m_primary: TPTCSurface;
     m_primary: TPTCSurface;
 
 
     { internal console management routines }
     { internal console management routines }
-    procedure internal_pre_open_setup(const _title: String);
+    procedure internal_pre_open_setup(const _title: string);
     procedure internal_open_fullscreen_start;
     procedure internal_open_fullscreen_start;
-    procedure internal_open_fullscreen(_width, _height: Integer; const _format: TPTCFormat);
+    procedure internal_open_fullscreen(_width, _height: Integer; const _format: IPTCFormat);
     procedure internal_open_fullscreen_finish(_pages: Integer);
     procedure internal_open_fullscreen_finish(_pages: Integer);
     procedure internal_post_open_setup;
     procedure internal_post_open_setup;
     procedure internal_reset;
     procedure internal_reset;
@@ -74,61 +74,61 @@ type
   public
   public
     constructor Create; override;
     constructor Create; override;
     destructor Destroy; override;
     destructor Destroy; override;
-    procedure Configure(const AFileName: String); override;
-    function option(const _option: String): Boolean; override;
-    function modes: PPTCMode; override;
+    procedure Configure(const AFileName: string); override;
+    function option(const _option: string): Boolean; override;
+    function modes: TPTCModeList; override;
     procedure open(const _title: string; _pages: Integer); overload; override;
     procedure open(const _title: string; _pages: Integer); overload; override;
-    procedure open(const _title: string; const _format: TPTCFormat;
+    procedure open(const _title: string; _format: IPTCFormat;
                    _pages: Integer); overload; override;
                    _pages: Integer); overload; override;
     procedure open(const _title: string; _width, _height: Integer;
     procedure open(const _title: string; _width, _height: Integer;
-                   const _format: TPTCFormat; _pages: Integer); overload; override;
-    procedure open(const _title: string; const _mode: TPTCMode;
+                   _format: IPTCFormat; _pages: Integer); overload; override;
+    procedure open(const _title: string; _mode: IPTCMode;
                    _pages: Integer); overload; override;
                    _pages: Integer); overload; override;
     procedure close; override;
     procedure close; override;
     procedure flush; override;
     procedure flush; override;
     procedure finish; override;
     procedure finish; override;
     procedure update; override;
     procedure update; override;
-    procedure update(const _area: TPTCArea); override;
-    procedure copy(surface: TPTCBaseSurface); override;
-    procedure copy(surface: TPTCBaseSurface;
-                   const source, destination: TPTCArea); override;
+    procedure update(_area: IPTCArea); override;
+    procedure copy(surface: IPTCSurface); override;
+    procedure copy(surface: IPTCSurface;
+                   source, destination: IPTCArea); override;
     function lock: Pointer; override;
     function lock: Pointer; override;
     procedure unlock; override;
     procedure unlock; override;
     procedure load(const pixels: Pointer;
     procedure load(const pixels: Pointer;
                    _width, _height, _pitch: Integer;
                    _width, _height, _pitch: Integer;
-                   const _format: TPTCFormat;
-                   const _palette: TPTCPalette); override;
+                   _format: IPTCFormat;
+                   _palette: IPTCPalette); override;
     procedure load(const pixels: Pointer;
     procedure load(const pixels: Pointer;
                    _width, _height, _pitch: Integer;
                    _width, _height, _pitch: Integer;
-                   const _format: TPTCFormat;
-                   const _palette: TPTCPalette;
-                   const source, destination: TPTCArea); override;
+                   _format: IPTCFormat;
+                   _palette: IPTCPalette;
+                   source, destination: IPTCArea); override;
     procedure save(pixels: Pointer;
     procedure save(pixels: Pointer;
                    _width, _height, _pitch: Integer;
                    _width, _height, _pitch: Integer;
-                   const _format: TPTCFormat;
-                   const _palette: TPTCPalette); override;
+                   _format: IPTCFormat;
+                   _palette: IPTCPalette); override;
     procedure save(pixels: Pointer;
     procedure save(pixels: Pointer;
                    _width, _height, _pitch: Integer;
                    _width, _height, _pitch: Integer;
-                   const _format: TPTCFormat;
-                   const _palette: TPTCPalette;
-                   const source, destination: TPTCArea); override;
+                   _format: IPTCFormat;
+                   _palette: IPTCPalette;
+                   source, destination: IPTCArea); override;
     procedure clear; override;
     procedure clear; override;
-    procedure clear(const color: TPTCColor); override;
-    procedure clear(const color: TPTCColor;
-                    const _area: TPTCArea); override;
-    procedure Palette(const _palette: TPTCPalette); override;
-    function Palette: TPTCPalette; override;
-    procedure Clip(const _area: TPTCArea); override;
+    procedure clear(color: IPTCColor); override;
+    procedure clear(color: IPTCColor;
+                    _area: IPTCArea); override;
+    procedure Palette(_palette: IPTCPalette); override;
+    function Palette: IPTCPalette; override;
+    procedure Clip(_area: IPTCArea); override;
     function GetWidth: Integer; override;
     function GetWidth: Integer; override;
     function GetHeight: Integer; override;
     function GetHeight: Integer; override;
     function GetPitch: Integer; override;
     function GetPitch: Integer; override;
     function GetPages: Integer; override;
     function GetPages: Integer; override;
-    function GetArea: TPTCArea; override;
-    function Clip: TPTCArea; override;
-    function GetFormat: TPTCFormat; override;
+    function GetArea: IPTCArea; override;
+    function Clip: IPTCArea; override;
+    function GetFormat: IPTCFormat; override;
     function GetName: string; override;
     function GetName: string; override;
     function GetTitle: string; override;
     function GetTitle: string; override;
     function GetInformation: string; override;
     function GetInformation: string; override;
-    function NextEvent(var event: TPTCEvent; wait: Boolean; const EventMask: TPTCEventMask): Boolean; override;
-    function PeekEvent(wait: Boolean; const EventMask: TPTCEventMask): TPTCEvent; override;
+    function NextEvent(out event: IPTCEvent; wait: Boolean; const EventMask: TPTCEventMask): Boolean; override;
+    function PeekEvent(wait: Boolean; const EventMask: TPTCEventMask): IPTCEvent; override;
   end;
   end;

+ 52 - 199
packages/ptc/src/dos/cga/cgaconsolei.inc

@@ -36,54 +36,37 @@
 {$DEFINE DEFAULT_FORMAT:=TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF)}
 {$DEFINE DEFAULT_FORMAT:=TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF)}
 
 
 constructor TCGAConsole.Create;
 constructor TCGAConsole.Create;
-
-var
-  I: Integer;
-
 begin
 begin
   inherited Create;
   inherited Create;
 
 
   m_open := False;
   m_open := False;
   m_locked := False;
   m_locked := False;
-  FillChar(m_modes, SizeOf(m_modes), 0);
   m_title := '';
   m_title := '';
   m_information := '';
   m_information := '';
   m_default_width := DEFAULT_WIDTH;
   m_default_width := DEFAULT_WIDTH;
   m_default_height := DEFAULT_HEIGHT;
   m_default_height := DEFAULT_HEIGHT;
   m_default_format := DEFAULT_FORMAT;
   m_default_format := DEFAULT_FORMAT;
 
 
-  for I := 0 to 255 do
-    m_modes[I] := TPTCMode.Create;
-
   m_copy := TPTCCopy.Create;
   m_copy := TPTCCopy.Create;
   m_clear := TPTCClear.Create;
   m_clear := TPTCClear.Create;
   Configure('ptcpas.cfg');
   Configure('ptcpas.cfg');
 end;
 end;
 
 
 destructor TCGAConsole.Destroy;
 destructor TCGAConsole.Destroy;
-
-var
-  I: Integer;
-
 begin
 begin
   close;
   close;
-  for I := 0 to 255 do
-    m_modes[I].Free;
   m_keyboard.Free;
   m_keyboard.Free;
   FMouse.Free;
   FMouse.Free;
   FEventQueue.Free;
   FEventQueue.Free;
   m_copy.Free;
   m_copy.Free;
   m_clear.Free;
   m_clear.Free;
-  m_default_format.Free;
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
-procedure TCGAConsole.Configure(const AFileName: String);
-
+procedure TCGAConsole.Configure(const AFileName: string);
 var
 var
-  F: Text;
+  F: TextFile;
   S: string;
   S: string;
-
 begin
 begin
   AssignFile(F, AFileName);
   AssignFile(F, AFileName);
   {$push}{$I-}
   {$push}{$I-}
@@ -103,8 +86,7 @@ begin
   CloseFile(F);
   CloseFile(F);
 end;
 end;
 
 
-function TCGAConsole.option(const _option: String): Boolean;
-
+function TCGAConsole.option(const _option: string): Boolean;
 begin
 begin
   {...}
   {...}
   if _option = 'enable logging' then
   if _option = 'enable logging' then
@@ -123,47 +105,33 @@ begin
   Result := m_copy.option(_option);
   Result := m_copy.option(_option);
 end;
 end;
 
 
-function TCGAConsole.modes: PPTCMode;
-
+function TCGAConsole.modes: TPTCModeList;
 begin
 begin
-  Result := @m_modes;
+  Result := m_modes;
 end;
 end;
 
 
-procedure TCGAConsole.open(const _title: string; _pages: Integer); overload;
-
+procedure TCGAConsole.Open(const _title: string; _pages: Integer); overload;
 begin
 begin
   open(_title, m_default_format, _pages);
   open(_title, m_default_format, _pages);
 end;
 end;
 
 
-procedure TCGAConsole.open(const _title: string; const _format: TPTCFormat;
+procedure TCGAConsole.open(const _title: string; _format: IPTCFormat;
                            _pages: Integer); overload;
                            _pages: Integer); overload;
-
 begin
 begin
   open(_title, m_default_width, m_default_height, _format, _pages);
   open(_title, m_default_width, m_default_height, _format, _pages);
 end;
 end;
 
 
 procedure TCGAConsole.open(const _title: string; _width, _height: Integer;
 procedure TCGAConsole.open(const _title: string; _width, _height: Integer;
-                           const _format: TPTCFormat; _pages: Integer); overload;
-
-var
-  m: TPTCMode;
-
+                           _format: IPTCFormat; _pages: Integer); overload;
 begin
 begin
-  m := TPTCMode.Create(_width, _height, _format);
-  try
-    open(_title, m, _pages);
-  finally
-    m.Free;
-  end;
+  open(_title, TPTCMode.Create(_width, _height, _format), _pages);
 end;
 end;
 
 
-procedure TCGAConsole.open(const _title: string; const _mode: TPTCMode;
+procedure TCGAConsole.open(const _title: string; _mode: IPTCMode;
                            _pages: Integer); overload;
                            _pages: Integer); overload;
-
 var
 var
   _width, _height: Integer;
   _width, _height: Integer;
-  _format: TPTCFormat;
-
+  _format: IPTCFormat;
 begin
 begin
   if not _mode.valid then
   if not _mode.valid then
     raise TPTCError.Create('invalid mode');
     raise TPTCError.Create('invalid mode');
@@ -180,7 +148,6 @@ begin
 end;
 end;
 
 
 procedure TCGAConsole.close;
 procedure TCGAConsole.close;
-
 begin
 begin
   if m_open then
   if m_open then
   begin
   begin
@@ -194,24 +161,20 @@ begin
 end;
 end;
 
 
 procedure TCGAConsole.flush;
 procedure TCGAConsole.flush;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
 end;
 end;
 
 
 procedure TCGAConsole.finish;
 procedure TCGAConsole.finish;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
 end;
 end;
 
 
 procedure TCGAConsole.update;
 procedure TCGAConsole.update;
-
 var
 var
   framebuffer: PByte;
   framebuffer: PByte;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
@@ -224,17 +187,14 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure TCGAConsole.update(const _area: TPTCArea);
-
+procedure TCGAConsole.update(_area: IPTCArea);
 begin
 begin
   update;
   update;
 end;
 end;
 
 
-procedure TCGAConsole.copy(surface: TPTCBaseSurface);
-
+procedure TCGAConsole.Copy(surface: IPTCSurface);
 var
 var
   pixels: Pointer;
   pixels: Pointer;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
@@ -248,16 +208,13 @@ begin
   except
   except
     on error: TPTCError do
     on error: TPTCError do
       raise TPTCError.Create('failed to copy console to surface', error);
       raise TPTCError.Create('failed to copy console to surface', error);
-
   end;
   end;
 end;
 end;
 
 
-procedure TCGAConsole.copy(surface: TPTCBaseSurface;
-                           const source, destination: TPTCArea);
-
+procedure TCGAConsole.Copy(surface: IPTCSurface;
+                           source, destination: IPTCArea);
 var
 var
   pixels: Pointer;
   pixels: Pointer;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
@@ -276,10 +233,8 @@ begin
 end;
 end;
 
 
 function TCGAConsole.lock: Pointer;
 function TCGAConsole.lock: Pointer;
-
 var
 var
   pixels: Pointer;
   pixels: Pointer;
-
 begin
 begin
   check_open;
   check_open;
   if m_locked then
   if m_locked then
@@ -291,7 +246,6 @@ begin
 end;
 end;
 
 
 procedure TCGAConsole.unlock;
 procedure TCGAConsole.unlock;
-
 begin
 begin
   check_open;
   check_open;
   if not m_locked then
   if not m_locked then
@@ -303,12 +257,10 @@ end;
 
 
 procedure TCGAConsole.load(const pixels: Pointer;
 procedure TCGAConsole.load(const pixels: Pointer;
                            _width, _height, _pitch: Integer;
                            _width, _height, _pitch: Integer;
-                           const _format: TPTCFormat;
-                           const _palette: TPTCPalette);
+                           _format: IPTCFormat;
+                           _palette: IPTCPalette);
 var
 var
-  Area_: TPTCArea;
   console_pixels: Pointer;
   console_pixels: Pointer;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
@@ -327,70 +279,46 @@ begin
     except
     except
       on error: TPTCError do
       on error: TPTCError do
         raise TPTCError.Create('failed to load pixels to console', error);
         raise TPTCError.Create('failed to load pixels to console', error);
-
     end;
     end;
   end
   end
   else
   else
-  begin
-    Area_ := TPTCArea.Create(0, 0, width, height);
-    try
-      load(pixels, _width, _height, _pitch, _format, _palette, Area_, area);
-    finally
-      Area_.Free;
-    end;
-  end;
+    Load(pixels, _width, _height, _pitch, _format, _palette, TPTCArea.Create(0, 0, width, height), area);
 end;
 end;
 
 
 procedure TCGAConsole.load(const pixels: Pointer;
 procedure TCGAConsole.load(const pixels: Pointer;
                            _width, _height, _pitch: Integer;
                            _width, _height, _pitch: Integer;
-                           const _format: TPTCFormat;
-                           const _palette: TPTCPalette;
-                           const source, destination: TPTCArea);
+                           _format: IPTCFormat;
+                           _palette: IPTCPalette;
+                           source, destination: IPTCArea);
 var
 var
   console_pixels: Pointer;
   console_pixels: Pointer;
-  clipped_source, clipped_destination: TPTCArea;
-  tmp: TPTCArea;
-
+  clipped_source, clipped_destination: IPTCArea;
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
-  clipped_source := nil;
-  clipped_destination := nil;
   try
   try
     console_pixels := lock;
     console_pixels := lock;
     try
     try
-      clipped_source := TPTCArea.Create;
-      clipped_destination := TPTCArea.Create;
-      tmp := TPTCArea.Create(0, 0, _width, _height);
-      try
-        TPTCClipper.clip(source, tmp, clipped_source, destination, clip, clipped_destination);
-      finally
-        tmp.Free;
-      end;
+      TPTCClipper.clip(source, TPTCArea.Create(0, 0, _width, _height), clipped_source, destination, clip, clipped_destination);
       m_copy.request(_format, format);
       m_copy.request(_format, format);
       m_copy.palette(_palette, palette);
       m_copy.palette(_palette, palette);
       m_copy.copy(pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, _pitch,
       m_copy.copy(pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, _pitch,
                   console_pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, pitch);
                   console_pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, pitch);
     finally
     finally
       unlock;
       unlock;
-      clipped_source.Free;
-      clipped_destination.Free;
     end;
     end;
   except
   except
     on error:TPTCError do
     on error:TPTCError do
       raise TPTCError.Create('failed to load pixels to console area', error);
       raise TPTCError.Create('failed to load pixels to console area', error);
-
   end;
   end;
 end;
 end;
 
 
 procedure TCGAConsole.save(pixels: Pointer;
 procedure TCGAConsole.save(pixels: Pointer;
                            _width, _height, _pitch: Integer;
                            _width, _height, _pitch: Integer;
-                           const _format: TPTCFormat;
-                           const _palette: TPTCPalette);
+                           _format: IPTCFormat;
+                           _palette: IPTCPalette);
 var
 var
-  Area_: TPTCArea;
   console_pixels: Pointer;
   console_pixels: Pointer;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
@@ -413,105 +341,66 @@ begin
     end;
     end;
   end
   end
   else
   else
-  begin
-    Area_ := TPTCArea.Create(0, 0, width, height);
-    try
-      save(pixels, _width, _height, _pitch, _format, _palette, area, Area_);
-    finally
-      Area_.Free;
-    end;
-  end;
+    Save(pixels, _width, _height, _pitch, _format, _palette, area, TPTCArea.Create(0, 0, width, height));
 end;
 end;
 
 
 procedure TCGAConsole.save(pixels: Pointer;
 procedure TCGAConsole.save(pixels: Pointer;
                            _width, _height, _pitch: Integer;
                            _width, _height, _pitch: Integer;
-                           const _format: TPTCFormat;
-                           const _palette: TPTCPalette;
-                           const source, destination: TPTCArea);
+                           _format: IPTCFormat;
+                           _palette: IPTCPalette;
+                           source, destination: IPTCArea);
 var
 var
   console_pixels: Pointer;
   console_pixels: Pointer;
-  clipped_source, clipped_destination: TPTCArea;
-  tmp: TPTCArea;
-
+  clipped_source, clipped_destination: IPTCArea;
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
-  clipped_source := nil;
-  clipped_destination := nil;
   try
   try
     console_pixels := lock;
     console_pixels := lock;
     try
     try
-      clipped_source := TPTCArea.Create;
-      clipped_destination := TPTCArea.Create;
-      tmp := TPTCArea.Create(0, 0, _width, _height);
-      try
-        TPTCClipper.clip(source, clip, clipped_source, destination, tmp, clipped_destination);
-      finally
-        tmp.Free;
-      end;
+      TPTCClipper.clip(source, clip, clipped_source, destination, TPTCArea.Create(0, 0, _width, _height), clipped_destination);
       m_copy.request(format, _format);
       m_copy.request(format, _format);
       m_copy.palette(palette, _palette);
       m_copy.palette(palette, _palette);
       m_copy.copy(console_pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, pitch,
       m_copy.copy(console_pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, pitch,
                   pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, _pitch);
                   pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, _pitch);
     finally
     finally
       unlock;
       unlock;
-      clipped_source.Free;
-      clipped_destination.Free;
     end;
     end;
   except
   except
     on error:TPTCError do
     on error:TPTCError do
       raise TPTCError.Create('failed to save console area pixels', error);
       raise TPTCError.Create('failed to save console area pixels', error);
-
   end;
   end;
 end;
 end;
 
 
-procedure TCGAConsole.clear;
-
+procedure TCGAConsole.Clear;
 var
 var
-  tmp: TPTCColor;
-
+  Color: IPTCColor;
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
   if format.direct then
   if format.direct then
-    tmp := TPTCColor.Create(0, 0, 0, 0)
+    Color := TPTCColor.Create(0, 0, 0, 0)
   else
   else
-    tmp := TPTCColor.Create(0);
-  try
-    clear(tmp);
-  finally
-    tmp.Free;
-  end;
+    Color := TPTCColor.Create(0);
+  Clear(Color);
 end;
 end;
 
 
-procedure TCGAConsole.clear(const color: TPTCColor);
-
-var
-  tmp: TPTCArea;
-
+procedure TCGAConsole.Clear(color: IPTCColor);
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
-  tmp := TPTCArea.Create;
-  try
-    clear(color, tmp);
-  finally
-    tmp.Free;
-  end;
+  Clear(color, TPTCArea.Create);
 end;
 end;
 
 
-procedure TCGAConsole.clear(const color: TPTCColor;
-                            const _area: TPTCArea);
-
+procedure TCGAConsole.clear(color: IPTCColor;
+                            _area: IPTCArea);
 var
 var
   pixels: Pointer;
   pixels: Pointer;
-  clipped_area: TPTCArea;
-
+  clipped_area: IPTCArea;
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
   try
   try
-    clipped_area := nil;
     pixels := lock;
     pixels := lock;
     try
     try
       clipped_area := TPTCClipper.clip(_area, clip);
       clipped_area := TPTCClipper.clip(_area, clip);
@@ -519,139 +408,111 @@ begin
       m_clear.clear(pixels, clipped_area.left, clipped_area.right, clipped_area.width, clipped_area.height, pitch, color);
       m_clear.clear(pixels, clipped_area.left, clipped_area.right, clipped_area.width, clipped_area.height, pitch, color);
     finally
     finally
       unlock;
       unlock;
-      clipped_area.Free;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do
       raise TPTCError.Create('failed to clear console area', error);
       raise TPTCError.Create('failed to clear console area', error);
-
   end;
   end;
 end;
 end;
 
 
-procedure TCGAConsole.Palette(const _palette: TPTCPalette);
-
+procedure TCGAConsole.Palette(_palette: IPTCPalette);
 begin
 begin
   check_open;
   check_open;
   m_primary.palette(_palette);
   m_primary.palette(_palette);
 end;
 end;
 
 
-function TCGAConsole.Palette: TPTCPalette;
-
+function TCGAConsole.Palette: IPTCPalette;
 begin
 begin
   check_open;
   check_open;
   Result := m_primary.palette;
   Result := m_primary.palette;
 end;
 end;
 
 
-procedure TCGAConsole.Clip(const _area: TPTCArea);
-
+procedure TCGAConsole.Clip(_area: IPTCArea);
 begin
 begin
   check_open;
   check_open;
   m_primary.clip(_area);
   m_primary.clip(_area);
 end;
 end;
 
 
 function TCGAConsole.GetWidth: Integer;
 function TCGAConsole.GetWidth: Integer;
-
 begin
 begin
   check_open;
   check_open;
   Result := m_primary.width;
   Result := m_primary.width;
 end;
 end;
 
 
 function TCGAConsole.GetHeight: Integer;
 function TCGAConsole.GetHeight: Integer;
-
 begin
 begin
   check_open;
   check_open;
   Result := m_primary.height;
   Result := m_primary.height;
 end;
 end;
 
 
 function TCGAConsole.GetPitch: Integer;
 function TCGAConsole.GetPitch: Integer;
-
 begin
 begin
   check_open;
   check_open;
   Result := m_primary.pitch;
   Result := m_primary.pitch;
 end;
 end;
 
 
 function TCGAConsole.GetPages: Integer;
 function TCGAConsole.GetPages: Integer;
-
 begin
 begin
   check_open;
   check_open;
   Result := 2;
   Result := 2;
 end;
 end;
 
 
-function TCGAConsole.GetArea: TPTCArea;
-
+function TCGAConsole.GetArea: IPTCArea;
 begin
 begin
   check_open;
   check_open;
   Result := m_primary.area;
   Result := m_primary.area;
 end;
 end;
 
 
-function TCGAConsole.Clip: TPTCArea;
-
+function TCGAConsole.Clip: IPTCArea;
 begin
 begin
   check_open;
   check_open;
   Result := m_primary.clip;
   Result := m_primary.clip;
 end;
 end;
 
 
-function TCGAConsole.GetFormat: TPTCFormat;
-
+function TCGAConsole.GetFormat: IPTCFormat;
 begin
 begin
   check_open;
   check_open;
   Result := m_primary.format;
   Result := m_primary.format;
 end;
 end;
 
 
 function TCGAConsole.GetName: string;
 function TCGAConsole.GetName: string;
-
 begin
 begin
   Result := 'CGA';
   Result := 'CGA';
 end;
 end;
 
 
 function TCGAConsole.GetTitle: string;
 function TCGAConsole.GetTitle: string;
-
 begin
 begin
   Result := m_title;
   Result := m_title;
 end;
 end;
 
 
 function TCGAConsole.GetInformation: string;
 function TCGAConsole.GetInformation: string;
-
 begin
 begin
   Result := m_information;
   Result := m_information;
 end;
 end;
 
 
-procedure TCGAConsole.internal_pre_open_setup(const _title: String);
-
+procedure TCGAConsole.internal_pre_open_setup(const _title: string);
 begin
 begin
   m_title := _title;
   m_title := _title;
 end;
 end;
 
 
 procedure TCGAConsole.internal_open_fullscreen_start;
 procedure TCGAConsole.internal_open_fullscreen_start;
-
-var
-  f: TPTCFormat;
-
 begin
 begin
   CGAPrecalc;
   CGAPrecalc;
 
 
-  f := TPTCFormat.Create(32, $FF0000, $00FF00, $0000FF);
-  try
-    m_primary := TPTCSurface.Create(320, 200, f);
-  finally
-    f.Free;
-  end;
+  m_primary := TPTCSurface.Create(320, 200, TPTCFormat.Create(32, $FF0000, $00FF00, $0000FF));
 
 
   CGA320;
   CGA320;
 end;
 end;
 
 
-procedure TCGAConsole.internal_open_fullscreen(_width, _height: Integer; const _format: TPTCFormat);
-
+procedure TCGAConsole.internal_open_fullscreen(_width, _height: Integer; const _format: IPTCFormat);
 begin
 begin
 end;
 end;
 
 
 procedure TCGAConsole.internal_open_fullscreen_finish(_pages: Integer);
 procedure TCGAConsole.internal_open_fullscreen_finish(_pages: Integer);
-
 begin
 begin
 end;
 end;
 
 
 procedure TCGAConsole.internal_post_open_setup;
 procedure TCGAConsole.internal_post_open_setup;
-
 begin
 begin
   FreeAndNil(m_keyboard);
   FreeAndNil(m_keyboard);
   FreeAndNil(FMouse);
   FreeAndNil(FMouse);
@@ -668,7 +529,6 @@ begin
 end;
 end;
 
 
 procedure TCGAConsole.internal_reset;
 procedure TCGAConsole.internal_reset;
-
 begin
 begin
   FreeAndNil(m_primary);
   FreeAndNil(m_primary);
   FreeAndNil(m_keyboard);
   FreeAndNil(m_keyboard);
@@ -677,7 +537,6 @@ begin
 end;
 end;
 
 
 procedure TCGAConsole.internal_close;
 procedure TCGAConsole.internal_close;
-
 begin
 begin
   FreeAndNil(m_primary);
   FreeAndNil(m_primary);
   FreeAndNil(m_keyboard);
   FreeAndNil(m_keyboard);
@@ -688,18 +547,15 @@ begin
 end;
 end;
 
 
 procedure TCGAConsole.HandleEvents;
 procedure TCGAConsole.HandleEvents;
-
 begin
 begin
   m_keyboard.GetPendingEvents(FEventQueue);
   m_keyboard.GetPendingEvents(FEventQueue);
   FMouse.GetPendingEvents(FEventQueue);
   FMouse.GetPendingEvents(FEventQueue);
 end;
 end;
 
 
-function TCGAConsole.NextEvent(var event: TPTCEvent; wait: Boolean; const EventMask: TPTCEventMask): Boolean;
-
+function TCGAConsole.NextEvent(out event: IPTCEvent; wait: Boolean; const EventMask: TPTCEventMask): Boolean;
 begin
 begin
   check_open;
   check_open;
 
 
-  FreeAndNil(event);
   repeat
   repeat
     { get events }
     { get events }
     HandleEvents;
     HandleEvents;
@@ -710,8 +566,7 @@ begin
   Result := event <> nil;
   Result := event <> nil;
 end;
 end;
 
 
-function TCGAConsole.PeekEvent(wait: Boolean; const EventMask: TPTCEventMask): TPTCEvent;
-
+function TCGAConsole.PeekEvent(wait: Boolean; const EventMask: TPTCEventMask): IPTCEvent;
 begin
 begin
   check_open;
   check_open;
 
 
@@ -725,14 +580,12 @@ begin
 end;
 end;
 
 
 procedure TCGAConsole.check_open;
 procedure TCGAConsole.check_open;
-
 begin
 begin
   if not m_open then
   if not m_open then
     raise TPTCError.Create('console is not open');
     raise TPTCError.Create('console is not open');
 end;
 end;
 
 
 procedure TCGAConsole.check_unlocked;
 procedure TCGAConsole.check_unlocked;
-
 begin
 begin
   if m_locked then
   if m_locked then
     raise TPTCError.Create('console is not unlocked');
     raise TPTCError.Create('console is not unlocked');

+ 2 - 2
packages/ptc/src/dos/textfx2/textfx2.pp

@@ -69,7 +69,7 @@ const
   use_charset: Pbyte = @charset_b7asc;
   use_charset: Pbyte = @charset_b7asc;
   { Character set to use. Can be changed run-time. }
   { Character set to use. Can be changed run-time. }
 
 
-  colmap: PSmallInt = nil;
+  colmap: PWord = nil;
 
 
 procedure set80x43; { Sets up 80x43, no blink, no cursor. }
 procedure set80x43; { Sets up 80x43, no blink, no cursor. }
 procedure set80x50; { Sets up 80x50, no blink, no cursor. }
 procedure set80x50; { Sets up 80x50, no blink, no cursor. }
@@ -447,7 +447,7 @@ begin
   if colmap <> nil then
   if colmap <> nil then
     FreeMem(colmap);
     FreeMem(colmap);
   f := 64.0 / COLMAPDIM;
   f := 64.0 / COLMAPDIM;
-  colmap := GetMem(SizeOf(SmallInt) * COLMAPDIM * COLMAPDIM * COLMAPDIM);
+  colmap := GetMem(SizeOf(Word) * COLMAPDIM * COLMAPDIM * COLMAPDIM);
   for r := 0 to COLMAPDIM - 1 do
   for r := 0 to COLMAPDIM - 1 do
   begin
   begin
     for g := 0 to COLMAPDIM - 1 do
     for g := 0 to COLMAPDIM - 1 do

+ 46 - 46
packages/ptc/src/dos/textfx2/textfx2consoled.inc

@@ -30,38 +30,38 @@
 }
 }
 
 
 type
 type
-  TTextFX2Console = Class(TPTCBaseConsole)
+  TTextFX2Console = class(TPTCBaseConsole)
   private
   private
     { data }
     { data }
-    m_modes: array [0..255] of TPTCMode;
-    m_title: string;
-    m_information: string;
+    FModes: array of IPTCMode;
+    FTitle: string;
+    FInformation: string;
 
 
     { flags }
     { flags }
-    m_open: Boolean;
-    m_locked: Boolean;
+    FOpen: Boolean;
+    FLocked: Boolean;
 
 
     { option data }
     { option data }
-    m_default_width: Integer;
-    m_default_height: Integer;
-    m_default_format: TPTCFormat;
+    FDefaultWidth: Integer;
+    FDefaultHeight: Integer;
+    FDefaultFormat: IPTCFormat;
 
 
     { objects }
     { objects }
-    m_copy: TPTCCopy;
-    m_clear: TPTCClear;
+    FCopy: TPTCCopy;
+    FClear: TPTCClear;
 
 
     FEventQueue: TEventQueue;
     FEventQueue: TEventQueue;
 
 
     { Dos objects }
     { Dos objects }
-    m_keyboard: TDosKeyboard;
+    FKeyboard: TDosKeyboard;
     FMouse: TDosMouse;
     FMouse: TDosMouse;
-    m_primary: TPTCSurface;
-    m_160x100buffer: TPTCSurface;
+    FPrimary: TPTCSurface;
+    F160x100buffer: TPTCSurface;
 
 
     { internal console management routines }
     { internal console management routines }
     procedure internal_pre_open_setup(const _title: String);
     procedure internal_pre_open_setup(const _title: String);
     procedure internal_open_fullscreen_start;
     procedure internal_open_fullscreen_start;
-    procedure internal_open_fullscreen(_width, _height: Integer; const _format: TPTCFormat);
+    procedure internal_open_fullscreen(_width, _height: Integer; _format: IPTCFormat);
     procedure internal_open_fullscreen_finish(_pages: Integer);
     procedure internal_open_fullscreen_finish(_pages: Integer);
     procedure internal_post_open_setup;
     procedure internal_post_open_setup;
     procedure internal_reset;
     procedure internal_reset;
@@ -75,61 +75,61 @@ type
   public
   public
     constructor Create; override;
     constructor Create; override;
     destructor Destroy; override;
     destructor Destroy; override;
-    procedure Configure(const AFileName: String); override;
-    function option(const _option: String): Boolean; override;
-    function modes: PPTCMode; override;
+    procedure Configure(const AFileName: string); override;
+    function Option(const AOption: string): Boolean; override;
+    function Modes: TPTCModeList; override;
     procedure open(const _title: string; _pages: Integer); overload; override;
     procedure open(const _title: string; _pages: Integer); overload; override;
-    procedure open(const _title: string; const _format: TPTCFormat;
+    procedure open(const _title: string; _format: IPTCFormat;
                    _pages: Integer); overload; override;
                    _pages: Integer); overload; override;
     procedure open(const _title: string; _width, _height: Integer;
     procedure open(const _title: string; _width, _height: Integer;
-                   const _format: TPTCFormat; _pages: Integer); overload; override;
-    procedure open(const _title: string; const _mode: TPTCMode;
+                   _format: IPTCFormat; _pages: Integer); overload; override;
+    procedure open(const _title: string; _mode: IPTCMode;
                    _pages: Integer); overload; override;
                    _pages: Integer); overload; override;
     procedure close; override;
     procedure close; override;
     procedure flush; override;
     procedure flush; override;
     procedure finish; override;
     procedure finish; override;
     procedure update; override;
     procedure update; override;
-    procedure update(const _area: TPTCArea); override;
-    procedure copy(surface: TPTCBaseSurface); override;
-    procedure copy(surface: TPTCBaseSurface;
-                   const source, destination: TPTCArea); override;
+    procedure update(_area: IPTCArea); override;
+    procedure copy(surface: IPTCSurface); override;
+    procedure copy(surface: IPTCSurface;
+                   source, destination: IPTCArea); override;
     function lock: Pointer; override;
     function lock: Pointer; override;
     procedure unlock; override;
     procedure unlock; override;
     procedure load(const pixels: Pointer;
     procedure load(const pixels: Pointer;
                    _width, _height, _pitch: Integer;
                    _width, _height, _pitch: Integer;
-                   const _format: TPTCFormat;
-                   const _palette: TPTCPalette); override;
+                   _format: IPTCFormat;
+                   _palette: IPTCPalette); override;
     procedure load(const pixels: Pointer;
     procedure load(const pixels: Pointer;
                    _width, _height, _pitch: Integer;
                    _width, _height, _pitch: Integer;
-                   const _format: TPTCFormat;
-                   const _palette: TPTCPalette;
-                   const source, destination: TPTCArea); override;
+                   _format: IPTCFormat;
+                   _palette: IPTCPalette;
+                   source, destination: IPTCArea); override;
     procedure save(pixels: Pointer;
     procedure save(pixels: Pointer;
                    _width, _height, _pitch: Integer;
                    _width, _height, _pitch: Integer;
-                   const _format: TPTCFormat;
-                   const _palette: TPTCPalette); override;
+                   _format: IPTCFormat;
+                   _palette: IPTCPalette); override;
     procedure save(pixels: Pointer;
     procedure save(pixels: Pointer;
                    _width, _height, _pitch: Integer;
                    _width, _height, _pitch: Integer;
-                   const _format: TPTCFormat;
-                   const _palette: TPTCPalette;
-                   const source, destination: TPTCArea); override;
+                   _format: IPTCFormat;
+                   _palette: IPTCPalette;
+                   source, destination: IPTCArea); override;
     procedure clear; override;
     procedure clear; override;
-    procedure clear(const color: TPTCColor); override;
-    procedure clear(const color: TPTCColor;
-                    const _area: TPTCArea); override;
-    procedure Palette(const _palette: TPTCPalette); override;
-    function Palette: TPTCPalette; override;
-    procedure Clip(const _area: TPTCArea); override;
+    procedure Clear(AColor: IPTCColor); override;
+    procedure clear(color: IPTCColor;
+                    _area: IPTCArea); override;
+    procedure Palette(_palette: IPTCPalette); override;
+    function Palette: IPTCPalette; override;
+    procedure Clip(_area: IPTCArea); override;
     function GetWidth: Integer; override;
     function GetWidth: Integer; override;
     function GetHeight: Integer; override;
     function GetHeight: Integer; override;
     function GetPitch: Integer; override;
     function GetPitch: Integer; override;
     function GetPages: Integer; override;
     function GetPages: Integer; override;
-    function GetArea: TPTCArea; override;
-    function Clip: TPTCArea; override;
-    function GetFormat: TPTCFormat; override;
+    function GetArea: IPTCArea; override;
+    function Clip: IPTCArea; override;
+    function GetFormat: IPTCFormat; override;
     function GetName: string; override;
     function GetName: string; override;
     function GetTitle: string; override;
     function GetTitle: string; override;
     function GetInformation: string; override;
     function GetInformation: string; override;
-    function NextEvent(var event: TPTCEvent; wait: Boolean; const EventMask: TPTCEventMask): Boolean; override;
-    function PeekEvent(wait: Boolean; const EventMask: TPTCEventMask): TPTCEvent; override;
+    function NextEvent(out event: IPTCEvent; wait: Boolean; const EventMask: TPTCEventMask): Boolean; override;
+    function PeekEvent(wait: Boolean; const EventMask: TPTCEventMask): IPTCEvent; override;
   end;
   end;

+ 138 - 285
packages/ptc/src/dos/textfx2/textfx2consolei.inc

@@ -36,61 +36,44 @@
 {$DEFINE DEFAULT_FORMAT:=TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF)}
 {$DEFINE DEFAULT_FORMAT:=TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF)}
 
 
 constructor TTextFX2Console.Create;
 constructor TTextFX2Console.Create;
-
-var
-  I: Integer;
-
 begin
 begin
   inherited Create;
   inherited Create;
 
 
-  m_open := False;
-  m_locked := False;
-  FillChar(m_modes, SizeOf(m_modes), 0);
-  m_title := '';
-  m_information := '';
-  m_default_width := DEFAULT_WIDTH;
-  m_default_height := DEFAULT_HEIGHT;
-  m_default_format := DEFAULT_FORMAT;
-
-  for I := Low(m_modes) to High(m_modes) do
-    m_modes[I] := TPTCMode.Create;
+  FOpen := False;
+  FLocked := False;
+  FTitle := '';
+  FInformation := '';
+  FDefaultWidth := DEFAULT_WIDTH;
+  FDefaultHeight := DEFAULT_HEIGHT;
+  FDefaultFormat := DEFAULT_FORMAT;
 
 
   calcpal := @calcpal_colorbase;
   calcpal := @calcpal_colorbase;
   use_charset := @charset_b7asc;
   use_charset := @charset_b7asc;
   build_colormap(0);
   build_colormap(0);
-  m_copy := TPTCCopy.Create;
-  m_clear := TPTCClear.Create;
-  configure('ptcpas.cfg');
+  FCopy := TPTCCopy.Create;
+  FClear := TPTCClear.Create;
+  Configure('ptcpas.cfg');
 end;
 end;
 
 
 destructor TTextFX2Console.Destroy;
 destructor TTextFX2Console.Destroy;
-
-var
-  I: Integer;
-
 begin
 begin
-  close;
-  m_160x100buffer.Free;
-  m_primary.Free;
+  Close;
+  F160x100buffer.Free;
+  FPrimary.Free;
 
 
-  for I := Low(m_modes) to High(m_modes) do
-    m_modes[I].Free;
-  m_keyboard.Free;
+  FKeyboard.Free;
   FMouse.Free;
   FMouse.Free;
   FEventQueue.Free;
   FEventQueue.Free;
-  m_copy.Free;
-  m_clear.Free;
-  m_default_format.Free;
+  FCopy.Free;
+  FClear.Free;
   dispose_colormap;
   dispose_colormap;
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
-procedure TTextFX2Console.Configure(const AFileName: String);
-
+procedure TTextFX2Console.Configure(const AFileName: string);
 var
 var
-  F: Text;
+  F: TextFile;
   S: string;
   S: string;
-
 begin
 begin
   AssignFile(F, AFileName);
   AssignFile(F, AFileName);
   {$push}{$I-}
   {$push}{$I-}
@@ -110,111 +93,96 @@ begin
   CloseFile(F);
   CloseFile(F);
 end;
 end;
 
 
-function TTextFX2Console.option(const _option: String): Boolean;
-
+function TTextFX2Console.Option(const AOption: string): Boolean;
 begin
 begin
   {...}
   {...}
   Result := True;
   Result := True;
-  if _option = 'charset_b8ibm' then
+  if AOption = 'charset_b8ibm' then
   begin
   begin
     use_charset := @charset_b8ibm;
     use_charset := @charset_b8ibm;
     exit;
     exit;
   end;
   end;
-  if _option = 'charset_b7asc' then
+  if AOption = 'charset_b7asc' then
   begin
   begin
     use_charset := @charset_b7asc;
     use_charset := @charset_b7asc;
     exit;
     exit;
   end;
   end;
-  if _option = 'charset_b7sml' then
+  if AOption = 'charset_b7sml' then
   begin
   begin
     use_charset := @charset_b7sml;
     use_charset := @charset_b7sml;
     exit;
     exit;
   end;
   end;
-  if _option = 'charset_b8gry' then
+  if AOption = 'charset_b8gry' then
   begin
   begin
     use_charset := @charset_b8gry;
     use_charset := @charset_b8gry;
     exit;
     exit;
   end;
   end;
-  if _option = 'charset_b7nws' then
+  if AOption = 'charset_b7nws' then
   begin
   begin
     use_charset := @charset_b7nws;
     use_charset := @charset_b7nws;
     exit;
     exit;
   end;
   end;
-  if _option = 'calcpal_colorbase' then
+  if AOption = 'calcpal_colorbase' then
   begin
   begin
     calcpal := @calcpal_colorbase;
     calcpal := @calcpal_colorbase;
     build_colormap(0);
     build_colormap(0);
     exit;
     exit;
   end;
   end;
-  if _option = 'calcpal_lightbase' then
+  if AOption = 'calcpal_lightbase' then
   begin
   begin
     calcpal := @calcpal_lightbase;
     calcpal := @calcpal_lightbase;
     build_colormap(0);
     build_colormap(0);
     exit;
     exit;
   end;
   end;
-  if _option = 'calcpal_lightbase_g' then
+  if AOption = 'calcpal_lightbase_g' then
   begin
   begin
     calcpal := @calcpal_lightbase_g;
     calcpal := @calcpal_lightbase_g;
     build_colormap(0);
     build_colormap(0);
     exit;
     exit;
   end;
   end;
-  if _option = 'enable logging' then
+  if AOption = 'enable logging' then
   begin
   begin
     LOG_enabled := True;
     LOG_enabled := True;
     Result := True;
     Result := True;
     exit;
     exit;
   end;
   end;
-  if _option = 'disable logging' then
+  if AOption = 'disable logging' then
   begin
   begin
     LOG_enabled := False;
     LOG_enabled := False;
     Result := True;
     Result := True;
     exit;
     exit;
   end;
   end;
 
 
-  Result := m_copy.option(_option);
+  Result := FCopy.Option(AOption);
 end;
 end;
 
 
-function TTextFX2Console.modes: PPTCMode;
-
+function TTextFX2Console.Modes: TPTCModeList;
 begin
 begin
-  Result := @m_modes;
+  Result := FModes;
 end;
 end;
 
 
-procedure TTextFX2Console.open(const _title: string; _pages: Integer); overload;
-
+procedure TTextFX2Console.Open(const _title: string; _pages: Integer); overload;
 begin
 begin
-  open(_title, m_default_format, _pages);
+  Open(_title, FDefaultFormat, _pages);
 end;
 end;
 
 
-procedure TTextFX2Console.open(const _title: string; const _format: TPTCFormat;
+procedure TTextFX2Console.open(const _title: string; _format: IPTCFormat;
                                _pages: Integer); overload;
                                _pages: Integer); overload;
-
 begin
 begin
-  open(_title, m_default_width, m_default_height, _format, _pages);
+  open(_title, FDefaultWidth, FDefaultHeight, _format, _pages);
 end;
 end;
 
 
 procedure TTextFX2Console.open(const _title: string; _width, _height: Integer;
 procedure TTextFX2Console.open(const _title: string; _width, _height: Integer;
-                               const _format: TPTCFormat; _pages: Integer); overload;
-
-var
-  m: TPTCMode;
-
+                               _format: IPTCFormat; _pages: Integer); overload;
 begin
 begin
-  m := TPTCMode.Create(_width, _height, _format);
-  try
-    open(_title, m, _pages);
-  finally
-    m.Free;
-  end;
+  open(_title, TPTCMode.Create(_width, _height, _format), _pages);
 end;
 end;
 
 
-procedure TTextFX2Console.open(const _title: string; const _mode: TPTCMode;
+procedure TTextFX2Console.open(const _title: string; _mode: IPTCMode;
                                _pages: Integer); overload;
                                _pages: Integer); overload;
-
 var
 var
   _width, _height: Integer;
   _width, _height: Integer;
-  _format: TPTCFormat;
-
+  _format: IPTCFormat;
 begin
 begin
   if not _mode.valid then
   if not _mode.valid then
     raise TPTCError.Create('invalid mode');
     raise TPTCError.Create('invalid mode');
@@ -228,61 +196,53 @@ begin
   internal_post_open_setup;
   internal_post_open_setup;
 end;
 end;
 
 
-procedure TTextFX2Console.close;
-
+procedure TTextFX2Console.Close;
 begin
 begin
-  if m_open then
+  if FOpen then
   begin
   begin
-    if m_locked then
+    if FLocked then
       raise TPTCError.Create('console is still locked');
       raise TPTCError.Create('console is still locked');
     {flush all key presses}
     {flush all key presses}
     while KeyPressed do ReadKey;
     while KeyPressed do ReadKey;
     internal_close;
     internal_close;
-    m_open := False;
+    FOpen := False;
   end;
   end;
 end;
 end;
 
 
 procedure TTextFX2Console.flush;
 procedure TTextFX2Console.flush;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
 end;
 end;
 
 
 procedure TTextFX2Console.finish;
 procedure TTextFX2Console.finish;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
 end;
 end;
 
 
 procedure TTextFX2Console.update;
 procedure TTextFX2Console.update;
-
 var
 var
   framebuffer: PInteger;
   framebuffer: PInteger;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
 
 
-  m_primary.copy(m_160x100buffer);
-  framebuffer := m_160x100buffer.lock;
+  FPrimary.copy(F160x100buffer);
+  framebuffer := F160x100buffer.Lock;
   vrc;
   vrc;
   dump_160x(0, 50, framebuffer);
   dump_160x(0, 50, framebuffer);
-  m_160x100buffer.unlock;
+  F160x100buffer.Unlock;
 end;
 end;
 
 
-procedure TTextFX2Console.update(const _area: TPTCArea);
-
+procedure TTextFX2Console.update(_area: IPTCArea);
 begin
 begin
   update;
   update;
 end;
 end;
 
 
-procedure TTextFX2Console.copy(surface: TPTCBaseSurface);
-
+procedure TTextFX2Console.copy(surface: IPTCSurface);
 var
 var
   pixels: Pointer;
   pixels: Pointer;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
@@ -296,16 +256,13 @@ begin
   except
   except
     on error: TPTCError do
     on error: TPTCError do
       raise TPTCError.Create('failed to copy console to surface', error);
       raise TPTCError.Create('failed to copy console to surface', error);
-
   end;
   end;
 end;
 end;
 
 
-procedure TTextFX2Console.copy(surface: TPTCBaseSurface;
-                               const source, destination: TPTCArea);
-
+procedure TTextFX2Console.copy(surface: IPTCSurface;
+                               source, destination: IPTCArea);
 var
 var
   pixels: Pointer;
   pixels: Pointer;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
@@ -319,43 +276,37 @@ begin
   except
   except
     on error: TPTCError do
     on error: TPTCError do
       raise TPTCError.Create('failed to copy console to surface', error);
       raise TPTCError.Create('failed to copy console to surface', error);
-
   end;
   end;
 end;
 end;
 
 
-function TTextFX2Console.lock: Pointer;
-
+function TTextFX2Console.Lock: Pointer;
 var
 var
   pixels: Pointer;
   pixels: Pointer;
-
 begin
 begin
   check_open;
   check_open;
-  if m_locked then
+  if FLocked then
     raise TPTCError.Create('console is already locked');
     raise TPTCError.Create('console is already locked');
-  pixels := m_primary.lock;
-  m_locked := True;
+  pixels := FPrimary.lock;
+  FLocked := True;
   Result := pixels;
   Result := pixels;
 end;
 end;
 
 
-procedure TTextFX2Console.unlock;
-
+procedure TTextFX2Console.Unlock;
 begin
 begin
   check_open;
   check_open;
-  if not m_locked then
+  if not FLocked then
     raise TPTCError.Create('console is not locked');
     raise TPTCError.Create('console is not locked');
 
 
-  m_primary.unlock;
-  m_locked := False;
+  FPrimary.unlock;
+  FLocked := False;
 end;
 end;
 
 
-procedure TTextFX2Console.load(const pixels: Pointer;
+procedure TTextFX2Console.Load(const pixels: Pointer;
                                _width, _height, _pitch: Integer;
                                _width, _height, _pitch: Integer;
-                               const _format: TPTCFormat;
-                               const _palette: TPTCPalette);
+                               _format: IPTCFormat;
+                               _palette: IPTCPalette);
 var
 var
-  Area_: TPTCArea;
   console_pixels: Pointer;
   console_pixels: Pointer;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
@@ -364,9 +315,9 @@ begin
     try
     try
       console_pixels := lock;
       console_pixels := lock;
       try
       try
-        m_copy.request(_format, format);
-        m_copy.palette(_palette, palette);
-        m_copy.copy(pixels, 0, 0, _width, _height, _pitch, console_pixels, 0, 0,
+        FCopy.request(_format, format);
+        FCopy.palette(_palette, palette);
+        FCopy.copy(pixels, 0, 0, _width, _height, _pitch, console_pixels, 0, 0,
                     width, height, pitch);
                     width, height, pitch);
       finally
       finally
         unlock;
         unlock;
@@ -374,54 +325,33 @@ begin
     except
     except
       on error: TPTCError do
       on error: TPTCError do
         raise TPTCError.Create('failed to load pixels to console', error);
         raise TPTCError.Create('failed to load pixels to console', error);
-
     end;
     end;
   end
   end
   else
   else
-  begin
-    Area_ := TPTCArea.Create(0, 0, width, height);
-    try
-      load(pixels, _width, _height, _pitch, _format, _palette, Area_, area);
-    finally
-      Area_.Free;
-    end;
-  end;
+    Load(pixels, _width, _height, _pitch, _format, _palette, TPTCArea.Create(0, 0, width, height), area);
 end;
 end;
 
 
 procedure TTextFX2Console.load(const pixels: Pointer;
 procedure TTextFX2Console.load(const pixels: Pointer;
                                _width, _height, _pitch: Integer;
                                _width, _height, _pitch: Integer;
-                               const _format: TPTCFormat;
-                               const _palette: TPTCPalette;
-                               const source, destination: TPTCArea);
+                               _format: IPTCFormat;
+                               _palette: IPTCPalette;
+                               source, destination: IPTCArea);
 var
 var
   console_pixels: Pointer;
   console_pixels: Pointer;
-  clipped_source, clipped_destination: TPTCArea;
-  tmp: TPTCArea;
-
+  clipped_source, clipped_destination: IPTCArea;
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
-  clipped_source := nil;
-  clipped_destination := nil;
   try
   try
     console_pixels := lock;
     console_pixels := lock;
     try
     try
-      clipped_source := TPTCArea.Create;
-      clipped_destination := TPTCArea.Create;
-      tmp := TPTCArea.Create(0, 0, _width, _height);
-      try
-        TPTCClipper.clip(source, tmp, clipped_source, destination, clip, clipped_destination);
-      finally
-        tmp.Free;
-      end;
-      m_copy.request(_format, format);
-      m_copy.palette(_palette, palette);
-      m_copy.copy(pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, _pitch,
+      TPTCClipper.clip(source, TPTCArea.Create(0, 0, _width, _height), clipped_source, destination, clip, clipped_destination);
+      FCopy.request(_format, format);
+      FCopy.palette(_palette, palette);
+      FCopy.copy(pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, _pitch,
                   console_pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, pitch);
                   console_pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, pitch);
     finally
     finally
       unlock;
       unlock;
-      clipped_source.Free;
-      clipped_destination.Free;
     end;
     end;
   except
   except
     on error:TPTCError do
     on error:TPTCError do
@@ -432,12 +362,10 @@ end;
 
 
 procedure TTextFX2Console.save(pixels: Pointer;
 procedure TTextFX2Console.save(pixels: Pointer;
                                _width, _height, _pitch: Integer;
                                _width, _height, _pitch: Integer;
-                               const _format: TPTCFormat;
-                               const _palette: TPTCPalette);
+                               _format: IPTCFormat;
+                               _palette: IPTCPalette);
 var
 var
-  Area_: TPTCArea;
   console_pixels: Pointer;
   console_pixels: Pointer;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
@@ -446,9 +374,9 @@ begin
     try
     try
       console_pixels := lock;
       console_pixels := lock;
       try
       try
-        m_copy.request(format, _format);
-        m_copy.palette(palette, _palette);
-        m_copy.copy(console_pixels, 0, 0, width, height, pitch, pixels, 0, 0,
+        FCopy.request(format, _format);
+        FCopy.palette(palette, _palette);
+        FCopy.copy(console_pixels, 0, 0, width, height, pitch, pixels, 0, 0,
                     _width, _height, _pitch);
                     _width, _height, _pitch);
       finally
       finally
         unlock;
         unlock;
@@ -456,117 +384,76 @@ begin
     except
     except
       on error: TPTCError do
       on error: TPTCError do
         raise TPTCError.Create('failed to save console pixels', error);
         raise TPTCError.Create('failed to save console pixels', error);
-
     end;
     end;
   end
   end
   else
   else
-  begin
-    Area_ := TPTCArea.Create(0, 0, width, height);
-    try
-      save(pixels, _width, _height, _pitch, _format, _palette, area, Area_);
-    finally
-      Area_.Free;
-    end;
-  end;
+    Save(pixels, _width, _height, _pitch, _format, _palette, area, TPTCArea.Create(0, 0, width, height));
 end;
 end;
 
 
 procedure TTextFX2Console.save(pixels: Pointer;
 procedure TTextFX2Console.save(pixels: Pointer;
                                _width, _height, _pitch: Integer;
                                _width, _height, _pitch: Integer;
-                               const _format: TPTCFormat;
-                               const _palette: TPTCPalette;
-                               const source, destination: TPTCArea);
+                               _format: IPTCFormat;
+                               _palette: IPTCPalette;
+                               source, destination: IPTCArea);
 var
 var
   console_pixels: Pointer;
   console_pixels: Pointer;
-  clipped_source, clipped_destination: TPTCArea;
-  tmp: TPTCArea;
-
+  clipped_source, clipped_destination: IPTCArea;
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
-  clipped_source := nil;
-  clipped_destination := nil;
   try
   try
     console_pixels := lock;
     console_pixels := lock;
     try
     try
-      clipped_source := TPTCArea.Create;
-      clipped_destination := TPTCArea.Create;
-      tmp := TPTCArea.Create(0, 0, _width, _height);
-      try
-        TPTCClipper.clip(source, clip, clipped_source, destination, tmp, clipped_destination);
-      finally
-        tmp.Free;
-      end;
-      m_copy.request(format, _format);
-      m_copy.palette(palette, _palette);
-      m_copy.copy(console_pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, pitch,
-                  pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, _pitch);
+      TPTCClipper.clip(source, clip, clipped_source, destination, TPTCArea.Create(0, 0, _width, _height), clipped_destination);
+      FCopy.request(format, _format);
+      FCopy.palette(palette, _palette);
+      FCopy.copy(console_pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, pitch,
+                 pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, _pitch);
     finally
     finally
       unlock;
       unlock;
-      clipped_source.Free;
-      clipped_destination.Free;
     end;
     end;
   except
   except
     on error:TPTCError do
     on error:TPTCError do
       raise TPTCError.Create('failed to save console area pixels', error);
       raise TPTCError.Create('failed to save console area pixels', error);
-
   end;
   end;
 end;
 end;
 
 
 procedure TTextFX2Console.clear;
 procedure TTextFX2Console.clear;
-
 var
 var
-  tmp: TPTCColor;
-
+  Color: IPTCColor;
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
   if format.direct then
   if format.direct then
-    tmp := TPTCColor.Create(0, 0, 0, 0)
+    Color := TPTCColor.Create(0, 0, 0, 0)
   else
   else
-    tmp := TPTCColor.Create(0);
-  try
-    clear(tmp);
-  finally
-    tmp.Free;
-  end;
+    Color := TPTCColor.Create(0);
+  Clear(Color);
 end;
 end;
 
 
-procedure TTextFX2Console.clear(const color: TPTCColor);
-
-var
-  tmp: TPTCArea;
-
+procedure TTextFX2Console.Clear(AColor: IPTCColor);
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
-  tmp := TPTCArea.Create;
-  try
-    clear(color, tmp);
-  finally
-    tmp.Free;
-  end;
+  Clear(AColor, TPTCArea.Create);
 end;
 end;
 
 
-procedure TTextFX2Console.clear(const color: TPTCColor;
-                                const _area: TPTCArea);
-
+procedure TTextFX2Console.clear(color: IPTCColor;
+                                _area: IPTCArea);
 var
 var
   pixels: Pointer;
   pixels: Pointer;
-  clipped_area: TPTCArea;
-
+  clipped_area: IPTCArea;
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
   try
   try
-    clipped_area := nil;
     pixels := lock;
     pixels := lock;
     try
     try
       clipped_area := TPTCClipper.clip(_area, clip);
       clipped_area := TPTCClipper.clip(_area, clip);
-      m_clear.request(format);
-      m_clear.clear(pixels, clipped_area.left, clipped_area.right, clipped_area.width, clipped_area.height, pitch, color);
+      FClear.request(format);
+      FClear.clear(pixels, clipped_area.left, clipped_area.right, clipped_area.width, clipped_area.height, pitch, color);
     finally
     finally
       unlock;
       unlock;
-      clipped_area.Free;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do
@@ -575,176 +462,145 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure TTextFX2Console.Palette(const _palette: TPTCPalette);
-
+procedure TTextFX2Console.Palette(_palette: IPTCPalette);
 begin
 begin
   check_open;
   check_open;
-  m_primary.palette(_palette);
+  FPrimary.palette(_palette);
 end;
 end;
 
 
-function TTextFX2Console.Palette: TPTCPalette;
-
+function TTextFX2Console.Palette: IPTCPalette;
 begin
 begin
   check_open;
   check_open;
-  Result := m_primary.palette;
+  Result := FPrimary.palette;
 end;
 end;
 
 
-procedure TTextFX2Console.Clip(const _area: TPTCArea);
-
+procedure TTextFX2Console.Clip(_area: IPTCArea);
 begin
 begin
   check_open;
   check_open;
-  m_primary.clip(_area);
+  FPrimary.clip(_area);
 end;
 end;
 
 
 function TTextFX2Console.GetWidth: Integer;
 function TTextFX2Console.GetWidth: Integer;
-
 begin
 begin
   check_open;
   check_open;
-  Result := m_primary.width;
+  Result := FPrimary.width;
 end;
 end;
 
 
 function TTextFX2Console.GetHeight: Integer;
 function TTextFX2Console.GetHeight: Integer;
-
 begin
 begin
   check_open;
   check_open;
-  Result := m_primary.height;
+  Result := FPrimary.height;
 end;
 end;
 
 
 function TTextFX2Console.GetPitch: Integer;
 function TTextFX2Console.GetPitch: Integer;
-
 begin
 begin
   check_open;
   check_open;
-  Result := m_primary.pitch;
+  Result := FPrimary.pitch;
 end;
 end;
 
 
 function TTextFX2Console.GetPages: Integer;
 function TTextFX2Console.GetPages: Integer;
-
 begin
 begin
   check_open;
   check_open;
-  Result := 2;{m_primary.pages;}
+  Result := 2;{FPrimary.pages;}
 end;
 end;
 
 
-function TTextFX2Console.GetArea: TPTCArea;
-
+function TTextFX2Console.GetArea: IPTCArea;
 begin
 begin
   check_open;
   check_open;
-  Result := m_primary.area;
+  Result := FPrimary.area;
 end;
 end;
 
 
-function TTextFX2Console.Clip: TPTCArea;
-
+function TTextFX2Console.Clip: IPTCArea;
 begin
 begin
   check_open;
   check_open;
-  Result := m_primary.clip;
+  Result := FPrimary.clip;
 end;
 end;
 
 
-function TTextFX2Console.GetFormat: TPTCFormat;
-
+function TTextFX2Console.GetFormat: IPTCFormat;
 begin
 begin
   check_open;
   check_open;
-  Result := m_primary.format;
+  Result := FPrimary.format;
 end;
 end;
 
 
 function TTextFX2Console.GetName: string;
 function TTextFX2Console.GetName: string;
-
 begin
 begin
   Result := 'TextFX2';
   Result := 'TextFX2';
 end;
 end;
 
 
 function TTextFX2Console.GetTitle: string;
 function TTextFX2Console.GetTitle: string;
-
 begin
 begin
-  Result := m_title;
+  Result := FTitle;
 end;
 end;
 
 
 function TTextFX2Console.GetInformation: string;
 function TTextFX2Console.GetInformation: string;
-
 begin
 begin
-  Result := m_information;
+  Result := FInformation;
 end;
 end;
 
 
-procedure TTextFX2Console.internal_pre_open_setup(const _title: String);
-
+procedure TTextFX2Console.internal_pre_open_setup(const _title: string);
 begin
 begin
-  m_title := _title;
+  FTitle := _title;
 end;
 end;
 
 
 procedure TTextFX2Console.internal_open_fullscreen_start;
 procedure TTextFX2Console.internal_open_fullscreen_start;
-
-var
-  f: TPTCFormat;
-
 begin
 begin
-  f := TPTCFormat.Create(32, $0000FF, $00FF00, $FF0000);
-  try
-    m_160x100buffer := TPTCSurface.Create(160, 100, f);
-  finally
-    f.Free;
-  end;
+  F160x100buffer := TPTCSurface.Create(160, 100, TPTCFormat.Create(32, $0000FF, $00FF00, $FF0000));
   set80x50;
   set80x50;
 end;
 end;
 
 
-procedure TTextFX2Console.internal_open_fullscreen(_width, _height: Integer; const _format: TPTCFormat);
-
+procedure TTextFX2Console.internal_open_fullscreen(_width, _height: Integer; _format: IPTCFormat);
 begin
 begin
-  m_primary := TPTCSurface.Create(_width, _height, _format);
+  FPrimary := TPTCSurface.Create(_width, _height, _format);
 end;
 end;
 
 
 procedure TTextFX2Console.internal_open_fullscreen_finish(_pages: Integer);
 procedure TTextFX2Console.internal_open_fullscreen_finish(_pages: Integer);
-
 begin
 begin
 end;
 end;
 
 
 procedure TTextFX2Console.internal_post_open_setup;
 procedure TTextFX2Console.internal_post_open_setup;
-
 begin
 begin
-  FreeAndNil(m_keyboard);
+  FreeAndNil(FKeyboard);
   FreeAndNil(FMouse);
   FreeAndNil(FMouse);
   FreeAndNil(FEventQueue);
   FreeAndNil(FEventQueue);
-  m_keyboard := TDosKeyboard.Create;
-  FMouse := TDosMouse.Create(m_primary.width, m_primary.height);
+  FKeyboard := TDosKeyboard.Create;
+  FMouse := TDosMouse.Create(FPrimary.width, FPrimary.height);
   FEventQueue := TEventQueue.Create;
   FEventQueue := TEventQueue.Create;
 
 
   { temporary platform dependent information fudge }
   { temporary platform dependent information fudge }
-  m_information := 'dos version x.xx.x, TextFX2, ...';
+  FInformation := 'dos version x.xx.x, TextFX2, ...';
 
 
   { set open flag }
   { set open flag }
-  m_open := True;
+  FOpen := True;
 end;
 end;
 
 
 procedure TTextFX2Console.internal_reset;
 procedure TTextFX2Console.internal_reset;
-
 begin
 begin
-  FreeAndNil(m_primary);
-  FreeAndNil(m_keyboard);
+  FreeAndNil(FPrimary);
+  FreeAndNil(FKeyboard);
   FreeAndNil(FMouse);
   FreeAndNil(FMouse);
   FreeAndNil(FEventQueue);
   FreeAndNil(FEventQueue);
 end;
 end;
 
 
 procedure TTextFX2Console.internal_close;
 procedure TTextFX2Console.internal_close;
-
 begin
 begin
-  FreeAndNil(m_primary);
-  FreeAndNil(m_160x100buffer);
-  FreeAndNil(m_keyboard);
+  FreeAndNil(FPrimary);
+  FreeAndNil(F160x100buffer);
+  FreeAndNil(FKeyboard);
   FreeAndNil(FMouse);
   FreeAndNil(FMouse);
   FreeAndNil(FEventQueue);
   FreeAndNil(FEventQueue);
   set80x25;
   set80x25;
 end;
 end;
 
 
 procedure TTextFX2Console.HandleEvents;
 procedure TTextFX2Console.HandleEvents;
-
 begin
 begin
-  m_keyboard.GetPendingEvents(FEventQueue);
+  FKeyboard.GetPendingEvents(FEventQueue);
   FMouse.GetPendingEvents(FEventQueue);
   FMouse.GetPendingEvents(FEventQueue);
 end;
 end;
 
 
-function TTextFX2Console.NextEvent(var event: TPTCEvent; wait: Boolean; const EventMask: TPTCEventMask): Boolean;
-
+function TTextFX2Console.NextEvent(out event: IPTCEvent; wait: Boolean; const EventMask: TPTCEventMask): Boolean;
 begin
 begin
   check_open;
   check_open;
 
 
-  FreeAndNil(event);
   repeat
   repeat
     { get events }
     { get events }
     HandleEvents;
     HandleEvents;
@@ -755,8 +611,7 @@ begin
   Result := event <> nil;
   Result := event <> nil;
 end;
 end;
 
 
-function TTextFX2Console.PeekEvent(wait: Boolean; const EventMask: TPTCEventMask): TPTCEvent;
-
+function TTextFX2Console.PeekEvent(wait: Boolean; const EventMask: TPTCEventMask): IPTCEvent;
 begin
 begin
   check_open;
   check_open;
 
 
@@ -770,15 +625,13 @@ begin
 end;
 end;
 
 
 procedure TTextFX2Console.check_open;
 procedure TTextFX2Console.check_open;
-
 begin
 begin
-  if not m_open then
+  if not FOpen then
     raise TPTCError.Create('console is not open');
     raise TPTCError.Create('console is not open');
 end;
 end;
 
 
 procedure TTextFX2Console.check_unlocked;
 procedure TTextFX2Console.check_unlocked;
-
 begin
 begin
-  if m_locked then
+  if FLocked then
     raise TPTCError.Create('console is not unlocked');
     raise TPTCError.Create('console is not unlocked');
 end;
 end;

+ 38 - 38
packages/ptc/src/dos/vesa/vesaconsoled.inc

@@ -33,7 +33,7 @@ type
   TVESAConsole = class(TPTCBaseConsole)
   TVESAConsole = class(TPTCBaseConsole)
   private
   private
     { data }
     { data }
-    FModes: array of TPTCMode;
+    FModes: array of IPTCMode;
     FModesLast: Integer;
     FModesLast: Integer;
     FModesN: array of record
     FModesN: array of record
       Index: Integer;
       Index: Integer;
@@ -66,16 +66,16 @@ type
     FDefaultWidth: Integer;
     FDefaultWidth: Integer;
     FDefaultHeight: Integer;
     FDefaultHeight: Integer;
 //    FDefaultPages: Integer;
 //    FDefaultPages: Integer;
-    FDefaultFormat: TPTCFormat;
+    FDefaultFormat: IPTCFormat;
 
 
     { objects }
     { objects }
     FCopy: TPTCCopy;
     FCopy: TPTCCopy;
-    FArea: TPTCArea;
-    FClip: TPTCArea;
-//    FFormat: TPTCFormat;
+    FArea: IPTCArea;
+    FClip: IPTCArea;
+//    FFormat: IPTCFormat;
 
 
 //    FClear: TPTCClear;
 //    FClear: TPTCClear;
-    FPalette: TPTCPalette;
+    FPalette: IPTCPalette;
 
 
     FEventQueue: TEventQueue;
     FEventQueue: TEventQueue;
 
 
@@ -85,7 +85,7 @@ type
 
 
     { internal console management routines }
     { internal console management routines }
     procedure internal_close;
     procedure internal_close;
-    function FindBestMode(const AMode: TPTCMode): Integer;
+    function FindBestMode(const AMode: IPTCMode): Integer;
     
     
     procedure UpdateModeList;
     procedure UpdateModeList;
     procedure EnableLFB;
     procedure EnableLFB;
@@ -101,61 +101,61 @@ type
   public
   public
     constructor Create; override;
     constructor Create; override;
     destructor Destroy; override;
     destructor Destroy; override;
-    procedure Configure(const AFileName: String); override;
-    function Option(const AOption: String): Boolean; override;
-    function Modes: PPTCMode; override;
+    procedure Configure(const AFileName: string); override;
+    function Option(const AOption: string): Boolean; override;
+    function Modes: TPTCModeList; override;
     procedure Open(const ATitle: string; APages: Integer); overload; override;
     procedure Open(const ATitle: string; APages: Integer); overload; override;
-    procedure Open(const ATitle: string; const AFormat: TPTCFormat;
+    procedure Open(const ATitle: string; AFormat: IPTCFormat;
                    APages: Integer); overload; override;
                    APages: Integer); overload; override;
     procedure Open(const ATitle: string; AWidth, AHeight: Integer;
     procedure Open(const ATitle: string; AWidth, AHeight: Integer;
-                   const AFormat: TPTCFormat; APages: Integer); overload; override;
-    procedure Open(const ATitle: string; const AMode: TPTCMode;
+                   AFormat: IPTCFormat; APages: Integer); overload; override;
+    procedure Open(const ATitle: string; AMode: IPTCMode;
                    APages: Integer); overload; override;
                    APages: Integer); overload; override;
     procedure Close; override;
     procedure Close; override;
     procedure Flush; override;
     procedure Flush; override;
     procedure Finish; override;
     procedure Finish; override;
     procedure Update; override;
     procedure Update; override;
-    procedure Update(const AArea: TPTCArea); override;
-    procedure Copy(ASurface: TPTCBaseSurface); override;
-    procedure Copy(ASurface: TPTCBaseSurface;
-                   const ASource, ADestination: TPTCArea); override;
+    procedure Update(AArea: IPTCArea); override;
+    procedure Copy(ASurface: IPTCSurface); override;
+    procedure Copy(ASurface: IPTCSurface;
+                   ASource, ADestination: IPTCArea); override;
     function Lock: Pointer; override;
     function Lock: Pointer; override;
     procedure Unlock; override;
     procedure Unlock; override;
     procedure Load(const APixels: Pointer;
     procedure Load(const APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette); override;
     procedure Load(const APixels: Pointer;
     procedure Load(const APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea); override;
     procedure Save(APixels: Pointer;
     procedure Save(APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette); override;
     procedure Save(APixels: Pointer;
     procedure Save(APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea); override;
     procedure Clear; override;
     procedure Clear; override;
-    procedure Clear(const AColor: TPTCColor); override;
-    procedure Clear(const AColor: TPTCColor;
-                    const AArea: TPTCArea); override;
-    procedure Palette(const APalette: TPTCPalette); override;
-    function Palette: TPTCPalette; override;
-    procedure Clip(const AArea: TPTCArea); override;
+    procedure Clear(AColor: IPTCColor); override;
+    procedure Clear(AColor: IPTCColor;
+                    AArea: IPTCArea); override;
+    procedure Palette(APalette: IPTCPalette); override;
+    function Palette: IPTCPalette; override;
+    procedure Clip(AArea: IPTCArea); override;
     function GetWidth: Integer; override;
     function GetWidth: Integer; override;
     function GetHeight: Integer; override;
     function GetHeight: Integer; override;
     function GetPitch: Integer; override;
     function GetPitch: Integer; override;
     function GetPages: Integer; override;
     function GetPages: Integer; override;
-    function GetArea: TPTCArea; override;
-    function Clip: TPTCArea; override;
-    function GetFormat: TPTCFormat; override;
+    function GetArea: IPTCArea; override;
+    function Clip: IPTCArea; override;
+    function GetFormat: IPTCFormat; override;
     function GetName: string; override;
     function GetName: string; override;
     function GetTitle: string; override;
     function GetTitle: string; override;
     function GetInformation: string; override;
     function GetInformation: string; override;
-    function NextEvent(var AEvent: TPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; override;
-    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): TPTCEvent; override;
+    function NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; override;
+    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent; override;
   end;
   end;

+ 95 - 201
packages/ptc/src/dos/vesa/vesaconsolei.inc

@@ -73,24 +73,13 @@ begin
 end;
 end;
 
 
 destructor TVESAConsole.Destroy;
 destructor TVESAConsole.Destroy;
-var
-  I: Integer;
 begin
 begin
   Close;
   Close;
   
   
-  for I := Low(FModes) to High(FModes) do
-    FreeAndNil(FModes[I]);
-  SetLength(FModes, 0);
-  SetLength(FModesN, 0);
-  
   FKeyboard.Free;
   FKeyboard.Free;
   FMouse.Free;
   FMouse.Free;
   FEventQueue.Free;
   FEventQueue.Free;
   FCopy.Free;
   FCopy.Free;
-  FDefaultFormat.Free;
-  FPalette.Free;
-  FArea.Free;
-  FClip.Free;
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
@@ -99,10 +88,7 @@ var
   I, J: Integer;
   I, J: Integer;
   r, g, b, a: DWord;
   r, g, b, a: DWord;
   tmpbpp: Integer;
   tmpbpp: Integer;
-  tmp: TPTCFormat;
 begin
 begin
-  for I := Low(FModes) to High(FModes) do
-    FreeAndNil(FModes[I]);
   SetLength(FModes, 0);
   SetLength(FModes, 0);
   SetLength(FModesN, 0);
   SetLength(FModesN, 0);
 
 
@@ -134,8 +120,8 @@ begin
             (BitsPerPixel = 24) or
             (BitsPerPixel = 24) or
             (BitsPerPixel = 32)) then
             (BitsPerPixel = 32)) then
         begin
         begin
-	  if FTryWindowed and SupportsWindowed then
-	  begin
+          if FTryWindowed and SupportsWindowed then
+          begin
             Inc(J);
             Inc(J);
             r := MakeMask(WindowedRedMaskSize, WindowedRedFieldPosition);
             r := MakeMask(WindowedRedMaskSize, WindowedRedFieldPosition);
             g := MakeMask(WindowedGreenMaskSize, WindowedGreenFieldPosition);
             g := MakeMask(WindowedGreenMaskSize, WindowedGreenFieldPosition);
@@ -146,17 +132,12 @@ begin
               tmpbpp := 16
               tmpbpp := 16
             else
             else
               tmpbpp := BitsPerPixel;
               tmpbpp := BitsPerPixel;
-            tmp := TPTCFormat.Create(tmpbpp, r, g, b, a);
-            try
-	      SetLength(FModes, J + 1);
-	      SetLength(FModesN, J + 1);
-              FModes[J] := TPTCMode.Create(XResolution, YResolution, tmp);
-              FModesN[J].Index := I;
-	      FModesN[J].SupportsWindowed := true;
-            finally
-              tmp.Free;
-            end;
-	  end;
+            SetLength(FModes, J + 1);
+            SetLength(FModesN, J + 1);
+            FModes[J] := TPTCMode.Create(XResolution, YResolution, TPTCFormat.Create(tmpbpp, r, g, b, a));
+            FModesN[J].Index := I;
+            FModesN[J].SupportsWindowed := true;
+          end;
 	  
 	  
 	  if FTryLFB and SupportsLFB then
 	  if FTryLFB and SupportsLFB then
 	  begin
 	  begin
@@ -184,16 +165,11 @@ begin
                 tmpbpp := 16
                 tmpbpp := 16
               else
               else
                 tmpbpp := BitsPerPixel;
                 tmpbpp := BitsPerPixel;
-              tmp := TPTCFormat.Create(tmpbpp, r, g, b, a);
-              try
-	        SetLength(FModes, J + 1);
-	        SetLength(FModesN, J + 1);
-                FModes[J] := TPTCMode.Create(XResolution, YResolution, tmp);
-                FModesN[J].Index := I;
-  	        FModesN[J].SupportsLFB := true;
-              finally
-                tmp.Free;
-              end;
+              SetLength(FModes, J + 1);
+              SetLength(FModesN, J + 1);
+              FModes[J] := TPTCMode.Create(XResolution, YResolution, TPTCFormat.Create(tmpbpp, r, g, b, a));
+              FModesN[J].Index := I;
+              FModesN[J].SupportsLFB := true;
 	    end;
 	    end;
 	  end;
 	  end;
 {          Inc(FModesLast)}
 {          Inc(FModesLast)}
@@ -202,38 +178,28 @@ begin
           if (MemoryModel = vmmmPackedPixel) and (BitsPerPixel = 8) then
           if (MemoryModel = vmmmPackedPixel) and (BitsPerPixel = 8) then
           begin
           begin
             Inc(J);
             Inc(J);
-            tmp := TPTCFormat.Create(8);
-            try
-              SetLength(FModes, J + 1);
-              SetLength(FModesN, J + 1);
-              FModes[J] := TPTCMode.Create(XResolution, YResolution, tmp);
-              FModesN[J].Index := I;
-	      FModesN[J].SupportsWindowed := FTryWindowed and SupportsWindowed;
-	      FModesN[J].SupportsLFB := FTryLFB and SupportsLFB;
-            finally
-              tmp.Free;
-            end;
+            SetLength(FModes, J + 1);
+            SetLength(FModesN, J + 1);
+            FModes[J] := TPTCMode.Create(XResolution, YResolution, TPTCFormat.Create(8));
+            FModesN[J].Index := I;
+            FModesN[J].SupportsWindowed := FTryWindowed and SupportsWindowed;
+            FModesN[J].SupportsLFB := FTryLFB and SupportsLFB;
             Inc(J);
             Inc(J);
-            tmp := TPTCFormat.Create(8, $E0, $1C, $03); {RGB 332}
-            try
-              SetLength(FModes, J + 1);
-              SetLength(FModesN, J + 1);
-              FModes[J] := TPTCMode.Create(XResolution, YResolution, tmp);
-              FModesN[J].Index := I;
-	      FModesN[J].SupportsWindowed := FTryWindowed and SupportsWindowed;
-	      FModesN[J].SupportsLFB := FTryLFB and SupportsLFB;
-            finally
-              tmp.Free;
-            end;
+			
+            {RGB 332}
+            SetLength(FModes, J + 1);
+            SetLength(FModesN, J + 1);
+            FModes[J] := TPTCMode.Create(XResolution, YResolution, TPTCFormat.Create(8, $E0, $1C, $03));
+            FModesN[J].Index := I;
+            FModesN[J].SupportsWindowed := FTryWindowed and SupportsWindowed;
+            FModesN[J].SupportsLFB := FTryLFB and SupportsLFB;
 {           Inc(FModesLast, 2);}
 {           Inc(FModesLast, 2);}
           end;
           end;
 
 
   FModesLast := J;
   FModesLast := J;
-  SetLength(FModes, FModesLast + 2);
-  FModes[FModesLast + 1] := TPTCMode.Create; {mark end of list!}
 end;
 end;
 
 
-procedure TVESAConsole.Configure(const AFileName: String);
+procedure TVESAConsole.Configure(const AFileName: string);
 var
 var
   F: TextFile;
   F: TextFile;
   S: string;
   S: string;
@@ -394,12 +360,12 @@ begin
   Result := FCopy.Option(AOption);
   Result := FCopy.Option(AOption);
 end;
 end;
 
 
-function TVESAConsole.Modes: PPTCMode;
+function TVESAConsole.Modes: TPTCModeList;
 begin
 begin
-  Result := @FModes[0];
+  Result := FModes;
 end;
 end;
 
 
-function TVESAConsole.FindBestMode(const AMode: TPTCMode): Integer;
+function TVESAConsole.FindBestMode(const AMode: IPTCMode): Integer;
 var
 var
   I: Integer;
   I: Integer;
   modefound, bestmodefound: Integer;
   modefound, bestmodefound: Integer;
@@ -491,26 +457,19 @@ begin
   Open(ATitle, FDefaultFormat, APages);
   Open(ATitle, FDefaultFormat, APages);
 end;
 end;
 
 
-procedure TVESAConsole.Open(const ATitle: string; const AFormat: TPTCFormat;
+procedure TVESAConsole.Open(const ATitle: string; AFormat: IPTCFormat;
                             APages: Integer); overload;
                             APages: Integer); overload;
 begin
 begin
   Open(ATitle, FDefaultWidth, FDefaultHeight, AFormat, APages);
   Open(ATitle, FDefaultWidth, FDefaultHeight, AFormat, APages);
 end;
 end;
 
 
 procedure TVESAConsole.Open(const ATitle: string; AWidth, AHeight: Integer;
 procedure TVESAConsole.Open(const ATitle: string; AWidth, AHeight: Integer;
-                            const AFormat: TPTCFormat; APages: Integer); overload;
-var
-  m: TPTCMode;
+                            AFormat: IPTCFormat; APages: Integer); overload;
 begin
 begin
-  m := TPTCMode.Create(AWidth, AHeight, AFormat);
-  try
-    Open(ATitle, m, APages);
-  finally
-    m.Free;
-  end;
+  Open(ATitle, TPTCMode.Create(AWidth, AHeight, AFormat), APages);
 end;
 end;
 
 
-procedure TVESAConsole.Open(const ATitle: string; const AMode: TPTCMode;
+procedure TVESAConsole.Open(const ATitle: string; AMode: IPTCMode;
                             APages: Integer); overload;
                             APages: Integer); overload;
 
 
   procedure SetRGB332Palette;
   procedure SetRGB332Palette;
@@ -556,7 +515,6 @@ procedure TVESAConsole.Open(const ATitle: string; const AMode: TPTCMode;
 
 
 var
 var
   ModeFound: Integer;
   ModeFound: Integer;
-  tmpa: TPTCArea;
 begin
 begin
   ModeFound := FindBestMode(AMode);
   ModeFound := FindBestMode(AMode);
 
 
@@ -592,7 +550,7 @@ begin
   
   
   FVESACurrentMode := FModesN[ModeFound].Index;
   FVESACurrentMode := FModesN[ModeFound].Index;
 
 
-  with FModes[FCurrentMode].FFormat do
+  with FModes[FCurrentMode].Format do
     if (Bits = 8) and Direct and (R = $E0) and (G = $1C) and (B = $03) then
     if (Bits = 8) and Direct and (R = $E0) and (G = $1C) and (B = $03) then
       SetRGB332Palette;
       SetRGB332Palette;
 
 
@@ -622,13 +580,8 @@ begin
     else
     else
       FNextVideoPage := 0;
       FNextVideoPage := 0;
   end;
   end;
-  tmpa := TPTCArea.Create(0, 0, FWidth, FHeight);
-  try
-    FArea.Assign(tmpa);
-    FClip.Assign(tmpa);
-  finally
-    tmpa.Free;
-  end;
+  FArea := TPTCArea.Create(0, 0, FWidth, FHeight);
+  FClip := FArea;
 
 
   FLFBNearPtrAccessAvailable := LFBNearPtrAccessAvailable;
   FLFBNearPtrAccessAvailable := LFBNearPtrAccessAvailable;
   if not FLFBNearPtrAccessAvailable then
   if not FLFBNearPtrAccessAvailable then
@@ -710,12 +663,12 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure TVESAConsole.Update(const AArea: TPTCArea);
+procedure TVESAConsole.Update(AArea: IPTCArea);
 begin
 begin
   Update;
   Update;
 end;
 end;
 
 
-procedure TVESAConsole.Copy(ASurface: TPTCBaseSurface);
+procedure TVESAConsole.Copy(ASurface: IPTCSurface);
 var
 var
   Pixels: Pointer;
   Pixels: Pointer;
 begin
 begin
@@ -734,8 +687,8 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure TVESAConsole.Copy(ASurface: TPTCBaseSurface;
-                            const ASource, ADestination: TPTCArea);
+procedure TVESAConsole.Copy(ASurface: IPTCSurface;
+                            ASource, ADestination: IPTCArea);
 var
 var
   pixels: Pointer;
   pixels: Pointer;
 begin
 begin
@@ -780,10 +733,9 @@ end;
 
 
 procedure TVESAConsole.Load(const APixels: Pointer;
 procedure TVESAConsole.Load(const APixels: Pointer;
                             AWidth, AHeight, APitch: Integer;
                             AWidth, AHeight, APitch: Integer;
-                            const AFormat: TPTCFormat;
-                            const APalette: TPTCPalette);
+                            AFormat: IPTCFormat;
+                            APalette: IPTCPalette);
 var
 var
-  Area_: TPTCArea;
   ConsolePixels: Pointer;
   ConsolePixels: Pointer;
 begin
 begin
   check_open;
   check_open;
@@ -808,66 +760,44 @@ begin
     end;
     end;
   end
   end
   else
   else
-  begin
-    Area_ := TPTCArea.Create(0, 0, Width, Height);
-    try
-      Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, Area_, Area);
-    finally
-      Area_.Free;
-    end;
-  end;
+    Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, TPTCArea.Create(0, 0, Width, Height), Area);
 end;
 end;
 
 
 procedure TVESAConsole.Load(const APixels: Pointer;
 procedure TVESAConsole.Load(const APixels: Pointer;
                             AWidth, AHeight, APitch: Integer;
                             AWidth, AHeight, APitch: Integer;
-                            const AFormat: TPTCFormat;
-                            const APalette: TPTCPalette;
-                            const ASource, ADestination: TPTCArea);
+                            AFormat: IPTCFormat;
+                            APalette: IPTCPalette;
+                            ASource, ADestination: IPTCArea);
 var
 var
   ConsolePixels: Pointer;
   ConsolePixels: Pointer;
-  ClippedSource: TPTCArea = nil;
-  ClippedDestination: TPTCArea = nil;
-  tmp: TPTCArea;
+  ClippedSource, ClippedDestination: IPTCArea;
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
+  ConsolePixels := Lock;
   try
   try
-    ClippedSource := TPTCArea.Create;
-    ClippedDestination := TPTCArea.Create;
-    ConsolePixels := Lock;
     try
     try
-      try
-        tmp := TPTCArea.Create(0, 0, AWidth, AHeight);
-        try
-          TPTCClipper.Clip(ASource, tmp, ClippedSource, ADestination, Clip, ClippedDestination);
-        finally
-          tmp.Free;
-        end;
-        FCopy.Request(AFormat, Format);
-        FCopy.Palette(APalette, Palette);
-        FCopy.Copy(APixels, ClippedSource.Left, ClippedSource.Top, ClippedSource.Width, ClippedSource.Height, APitch,
-                    ConsolePixels, ClippedDestination.Left, ClippedDestination.Top, ClippedDestination.Width, ClippedDestination.Height, Pitch);
-      except
-        on error:TPTCError do
-        begin
-          raise TPTCError.Create('failed to load pixels to console area', error);
-        end;
+      TPTCClipper.Clip(ASource, TPTCArea.Create(0, 0, AWidth, AHeight), ClippedSource, ADestination, Clip, ClippedDestination);
+      FCopy.Request(AFormat, Format);
+      FCopy.Palette(APalette, Palette);
+      FCopy.Copy(APixels, ClippedSource.Left, ClippedSource.Top, ClippedSource.Width, ClippedSource.Height, APitch,
+                 ConsolePixels, ClippedDestination.Left, ClippedDestination.Top, ClippedDestination.Width, ClippedDestination.Height, Pitch);
+    except
+      on error:TPTCError do
+      begin
+        raise TPTCError.Create('failed to load pixels to console area', error);
       end;
       end;
-    finally
-      Unlock;
     end;
     end;
   finally
   finally
-    ClippedSource.Free;
-    ClippedDestination.Free;
+    Unlock;
   end;
   end;
 end;
 end;
 
 
 procedure TVESAConsole.Save(APixels: Pointer;
 procedure TVESAConsole.Save(APixels: Pointer;
                             AWidth, AHeight, APitch: Integer;
                             AWidth, AHeight, APitch: Integer;
-                            const AFormat: TPTCFormat;
-                            const APalette: TPTCPalette);
+                            AFormat: IPTCFormat;
+                            APalette: IPTCPalette);
 var
 var
-  Area_: TPTCArea;
   ConsolePixels: Pointer;
   ConsolePixels: Pointer;
 begin
 begin
   check_open;
   check_open;
@@ -892,100 +822,70 @@ begin
     end;
     end;
   end
   end
   else
   else
-  begin
-    Area_ := TPTCArea.Create(0, 0, Width, Height);
-    try
-      Save(APixels, AWidth, AHeight, APitch, AFormat, APalette, Area, Area_);
-    finally
-      Area_.Free;
-    end;
-  end;
+    Save(APixels, AWidth, AHeight, APitch, AFormat, APalette, Area, TPTCArea.Create(0, 0, Width, Height));
 end;
 end;
 
 
 procedure TVESAConsole.Save(APixels: Pointer;
 procedure TVESAConsole.Save(APixels: Pointer;
                             AWidth, AHeight, APitch: Integer;
                             AWidth, AHeight, APitch: Integer;
-                            const AFormat: TPTCFormat;
-                            const APalette: TPTCPalette;
-                            const ASource, ADestination: TPTCArea);
+                            AFormat: IPTCFormat;
+                            APalette: IPTCPalette;
+                            ASource, ADestination: IPTCArea);
 var
 var
   ConsolePixels: Pointer;
   ConsolePixels: Pointer;
-  ClippedSource: TPTCArea = nil;
-  ClippedDestination: TPTCArea = nil;
-  tmp: TPTCArea;
+  ClippedSource, ClippedDestination: IPTCArea;
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
+  ConsolePixels := Lock;
   try
   try
-    ClippedSource := TPTCArea.Create;
-    ClippedDestination := TPTCArea.Create;
-    ConsolePixels := Lock;
     try
     try
-      try
-        tmp := TPTCArea.Create(0, 0, AWidth, AHeight);
-        try
-          TPTCClipper.Clip(ASource, Clip, ClippedSource, ADestination, tmp, ClippedDestination);
-        finally
-          tmp.Free;
-        end;
-        FCopy.Request(Format, AFormat);
-        FCopy.Palette(Palette, APalette);
-        FCopy.Copy(ConsolePixels, ClippedSource.Left, ClippedSource.Top, ClippedSource.Width, ClippedSource.Height, Pitch,
-                    APixels, ClippedDestination.Left, ClippedDestination.Top, ClippedDestination.Width, ClippedDestination.Height, APitch);
-      except
-        on error:TPTCError do
-        begin
-          raise TPTCError.Create('failed to save console area pixels', error);
-        end;
+      TPTCClipper.Clip(ASource, Clip, ClippedSource, ADestination, TPTCArea.Create(0, 0, AWidth, AHeight), ClippedDestination);
+      FCopy.Request(Format, AFormat);
+      FCopy.Palette(Palette, APalette);
+      FCopy.Copy(ConsolePixels, ClippedSource.Left, ClippedSource.Top, ClippedSource.Width, ClippedSource.Height, Pitch,
+                 APixels, ClippedDestination.Left, ClippedDestination.Top, ClippedDestination.Width, ClippedDestination.Height, APitch);
+    except
+      on error:TPTCError do
+      begin
+        raise TPTCError.Create('failed to save console area pixels', error);
       end;
       end;
-    finally
-      Unlock;
     end;
     end;
   finally
   finally
-    ClippedSource.Free;
-    ClippedDestination.Free;
+    Unlock;
   end;
   end;
 end;
 end;
 
 
 procedure TVESAConsole.Clear;
 procedure TVESAConsole.Clear;
 var
 var
-  tmp: TPTCColor;
+  Color: IPTCColor;
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
   if Format.Direct then
   if Format.Direct then
-    tmp := TPTCColor.Create(0, 0, 0, 0)
+    Color := TPTCColor.Create(0, 0, 0, 0)
   else
   else
-    tmp := TPTCColor.Create(0);
-  try
-    Clear(tmp);
-  finally
-    tmp.Free;
-  end;
+    Color := TPTCColor.Create(0);
+  Clear(Color);
 end;
 end;
 
 
-procedure TVESAConsole.Clear(const AColor: TPTCColor);
+procedure TVESAConsole.Clear(AColor: IPTCColor);
 var
 var
   tmp: TPTCArea;
   tmp: TPTCArea;
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
-  tmp := TPTCArea.Create;
-  try
-    Clear(AColor, tmp);
-  finally
-    tmp.Free;
-  end;
+  Clear(AColor, TPTCArea.Create);
 end;
 end;
 
 
-procedure TVESAConsole.Clear(const AColor: TPTCColor;
-                             const AArea: TPTCArea);
+procedure TVESAConsole.Clear(AColor: IPTCColor;
+                             AArea: IPTCArea);
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
   {...}
   {...}
 end;
 end;
 
 
-procedure TVESAConsole.Palette(const APalette: TPTCPalette);
+procedure TVESAConsole.Palette(APalette: IPTCPalette);
 begin
 begin
   check_open;
   check_open;
 
 
@@ -996,23 +896,18 @@ begin
   end;
   end;
 end;
 end;
 
 
-function TVESAConsole.Palette: TPTCPalette;
+function TVESAConsole.Palette: IPTCPalette;
 begin
 begin
   check_open;
   check_open;
   Result := FPalette;
   Result := FPalette;
 end;
 end;
 
 
-procedure TVESAConsole.Clip(const AArea: TPTCArea);
+procedure TVESAConsole.Clip(AArea: IPTCArea);
 var
 var
   tmp: TPTCArea;
   tmp: TPTCArea;
 begin
 begin
   check_open;
   check_open;
-  tmp := TPTCClipper.Clip(AArea, FArea);
-  try
-    FClip.Assign(tmp);
-  finally
-    tmp.Free;
-  end;
+  FClip := TPTCClipper.Clip(AArea, FArea);
 end;
 end;
 
 
 function TVESAConsole.GetWidth: Integer;
 function TVESAConsole.GetWidth: Integer;
@@ -1039,19 +934,19 @@ begin
   Result := 2;{FPrimary.pages;}
   Result := 2;{FPrimary.pages;}
 end;
 end;
 
 
-function TVESAConsole.GetArea: TPTCArea;
+function TVESAConsole.GetArea: IPTCArea;
 begin
 begin
   check_open;
   check_open;
   Result := FArea;
   Result := FArea;
 end;
 end;
 
 
-function TVESAConsole.Clip: TPTCArea;
+function TVESAConsole.Clip: IPTCArea;
 begin
 begin
   check_open;
   check_open;
   Result := FClip;
   Result := FClip;
 end;
 end;
 
 
-function TVESAConsole.GetFormat: TPTCFormat;
+function TVESAConsole.GetFormat: IPTCFormat;
 begin
 begin
   check_open;
   check_open;
   Result := FModes[FCurrentMode].Format;
   Result := FModes[FCurrentMode].Format;
@@ -1087,11 +982,10 @@ begin
   FMouse.GetPendingEvents(FEventQueue);
   FMouse.GetPendingEvents(FEventQueue);
 end;
 end;
 
 
-function TVESAConsole.NextEvent(var AEvent: TPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
+function TVESAConsole.NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
 begin
 begin
   check_open;
   check_open;
 
 
-  FreeAndNil(AEvent);
   repeat
   repeat
     { get events }
     { get events }
     HandleEvents;
     HandleEvents;
@@ -1102,7 +996,7 @@ begin
   Result := AEvent <> nil;
   Result := AEvent <> nil;
 end;
 end;
 
 
-function TVESAConsole.PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): TPTCEvent;
+function TVESAConsole.PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent;
 begin
 begin
   check_open;
   check_open;
 
 

+ 38 - 38
packages/ptc/src/dos/vga/vgaconsoled.inc

@@ -30,10 +30,10 @@
 }
 }
 
 
 type
 type
-  TVGAConsole = Class(TPTCBaseConsole)
+  TVGAConsole = class(TPTCBaseConsole)
   private
   private
     { data }
     { data }
-    m_modes: array [0..31{255}] of TPTCMode;
+    m_modes: array of IPTCMode;
     m_title: string;
     m_title: string;
     m_information: string;
     m_information: string;
     m_CurrentMode: Integer;
     m_CurrentMode: Integer;
@@ -48,15 +48,15 @@ type
     { option data }
     { option data }
     m_default_width: Integer;
     m_default_width: Integer;
     m_default_height: Integer;
     m_default_height: Integer;
-    m_default_format: TPTCFormat;
+    m_default_format: IPTCFormat;
 
 
     { objects }
     { objects }
     m_copy: TPTCCopy;
     m_copy: TPTCCopy;
-    m_area: TPTCArea;
-    m_clip: TPTCArea;
+    m_area: IPTCArea;
+    m_clip: IPTCArea;
 
 
     m_clear: TPTCClear;
     m_clear: TPTCClear;
-    m_palette: TPTCPalette;
+    m_palette: IPTCPalette;
 
 
     FEventQueue: TEventQueue;
     FEventQueue: TEventQueue;
 
 
@@ -65,7 +65,7 @@ type
     FMouse: TDosMouse;
     FMouse: TDosMouse;
 
 
     { internal console management routines }
     { internal console management routines }
-    procedure internal_pre_open_setup(const _title: String);
+    procedure internal_pre_open_setup(const _title: string);
     procedure internal_open_fullscreen_start;
     procedure internal_open_fullscreen_start;
     procedure internal_open_fullscreen(ModeType: Integer);
     procedure internal_open_fullscreen(ModeType: Integer);
     procedure internal_open_fullscreen_finish(_pages: Integer);
     procedure internal_open_fullscreen_finish(_pages: Integer);
@@ -85,61 +85,61 @@ type
   public
   public
     constructor Create; override;
     constructor Create; override;
     destructor Destroy; override;
     destructor Destroy; override;
-    procedure Configure(const AFileName: String); override;
-    function option(const _option: String): Boolean; override;
-    function modes: PPTCMode; override;
+    procedure Configure(const AFileName: string); override;
+    function Option(const _option: string): Boolean; override;
+    function modes: TPTCModeList; override;
     procedure open(const _title: string; _pages: Integer); overload; override;
     procedure open(const _title: string; _pages: Integer); overload; override;
-    procedure open(const _title: string; const _format: TPTCFormat;
+    procedure open(const _title: string; _format: IPTCFormat;
                    _pages: Integer); overload; override;
                    _pages: Integer); overload; override;
     procedure open(const _title: string; _width, _height: Integer;
     procedure open(const _title: string; _width, _height: Integer;
-                   const _format: TPTCFormat; _pages: Integer); overload; override;
-    procedure open(const _title: string; const _mode: TPTCMode;
+                   _format: IPTCFormat; _pages: Integer); overload; override;
+    procedure open(const _title: string; _mode: IPTCMode;
                    _pages: Integer); overload; override;
                    _pages: Integer); overload; override;
     procedure close; override;
     procedure close; override;
     procedure flush; override;
     procedure flush; override;
     procedure finish; override;
     procedure finish; override;
     procedure update; override;
     procedure update; override;
-    procedure update(const _area: TPTCArea); override;
-    procedure copy(surface: TPTCBaseSurface); override;
-    procedure copy(surface: TPTCBaseSurface;
-                   const source, destination: TPTCArea); override;
+    procedure update(_area: IPTCArea); override;
+    procedure copy(surface: IPTCSurface); override;
+    procedure copy(surface: IPTCSurface;
+                   source, destination: IPTCArea); override;
     function lock: Pointer; override;
     function lock: Pointer; override;
     procedure unlock; override;
     procedure unlock; override;
     procedure load(const pixels: Pointer;
     procedure load(const pixels: Pointer;
                    _width, _height, _pitch: Integer;
                    _width, _height, _pitch: Integer;
-                   const _format: TPTCFormat;
-                   const _palette: TPTCPalette); override;
+                   _format: IPTCFormat;
+                   _palette: IPTCPalette); override;
     procedure load(const pixels: Pointer;
     procedure load(const pixels: Pointer;
                    _width, _height, _pitch: Integer;
                    _width, _height, _pitch: Integer;
-                   const _format: TPTCFormat;
-                   const _palette: TPTCPalette;
-                   const source, destination: TPTCArea); override;
+                   _format: IPTCFormat;
+                   _palette: IPTCPalette;
+                   source, destination: IPTCArea); override;
     procedure save(pixels: Pointer;
     procedure save(pixels: Pointer;
                    _width, _height, _pitch: Integer;
                    _width, _height, _pitch: Integer;
-                   const _format: TPTCFormat;
-                   const _palette: TPTCPalette); override;
+                   _format: IPTCFormat;
+                   _palette: IPTCPalette); override;
     procedure save(pixels: Pointer;
     procedure save(pixels: Pointer;
                    _width, _height, _pitch: Integer;
                    _width, _height, _pitch: Integer;
-                   const _format: TPTCFormat;
-                   const _palette: TPTCPalette;
-                   const source, destination: TPTCArea); override;
+                   _format: IPTCFormat;
+                   _palette: IPTCPalette;
+                   source, destination: IPTCArea); override;
     procedure clear; override;
     procedure clear; override;
-    procedure clear(const color: TPTCColor); override;
-    procedure clear(const color: TPTCColor;
-                    const _area: TPTCArea); override;
-    procedure Palette(const _palette: TPTCPalette); override;
-    function Palette: TPTCPalette; override;
-    procedure Clip(const _area: TPTCArea); override;
+    procedure Clear(AColor: IPTCColor); override;
+    procedure clear(color: IPTCColor;
+                    _area: IPTCArea); override;
+    procedure Palette(_palette: IPTCPalette); override;
+    function Palette: IPTCPalette; override;
+    procedure Clip(_area: IPTCArea); override;
     function GetWidth: Integer; override;
     function GetWidth: Integer; override;
     function GetHeight: Integer; override;
     function GetHeight: Integer; override;
     function GetPitch: Integer; override;
     function GetPitch: Integer; override;
     function GetPages: Integer; override;
     function GetPages: Integer; override;
-    function GetArea: TPTCArea; override;
-    function Clip: TPTCArea; override;
-    function GetFormat: TPTCFormat; override;
+    function GetArea: IPTCArea; override;
+    function Clip: IPTCArea; override;
+    function GetFormat: IPTCFormat; override;
     function GetName: string; override;
     function GetName: string; override;
     function GetTitle: string; override;
     function GetTitle: string; override;
     function GetInformation: string; override;
     function GetInformation: string; override;
-    function NextEvent(var event: TPTCEvent; wait: Boolean; const EventMask: TPTCEventMask): Boolean; override;
-    function PeekEvent(wait: Boolean; const EventMask: TPTCEventMask): TPTCEvent; override;
+    function NextEvent(out event: IPTCEvent; wait: Boolean; const EventMask: TPTCEventMask): Boolean; override;
+    function PeekEvent(wait: Boolean; const EventMask: TPTCEventMask): IPTCEvent; override;
   end;
   end;

+ 60 - 234
packages/ptc/src/dos/vga/vgaconsolei.inc

@@ -38,10 +38,6 @@
 {$ASMMODE intel}
 {$ASMMODE intel}
 
 
 constructor TVGAConsole.Create;
 constructor TVGAConsole.Create;
-
-var
-  fmt1, fmt2, fmt3: TPTCFormat;
-
 begin
 begin
   inherited Create;
   inherited Create;
 
 
@@ -61,29 +57,17 @@ begin
   m_clear := TPTCClear.Create;
   m_clear := TPTCClear.Create;
   m_palette := TPTCPalette.Create;
   m_palette := TPTCPalette.Create;
 
 
-  fmt1 := nil;
-  fmt2 := nil;
-  fmt3 := nil;
-  try
-    fmt1 := TPTCFormat.Create(8);
-    fmt2 := TPTCFormat.Create(8, $E0, $1C, $03);
-    fmt3 := TPTCFormat.Create(16, $F800, $7E0, $1F);
-    m_modes[0] := TPTCMode.Create(320, 200, fmt1);
-    m_modes[1] := TPTCMode.Create(320, 200, fmt2);
-    m_modes[2] := TPTCMode.Create(320, 200, fmt3);
-    m_modes[3] := TPTCMode.Create;
-  finally
-    fmt1.Free;
-    fmt2.Free;
-    fmt3.Free;
-  end;
+  SetLength(m_modes, 3);
+  m_modes[0] := TPTCMode.Create(320, 200, TPTCFormat.Create(8));
+  m_modes[1] := TPTCMode.Create(320, 200, TPTCFormat.Create(8, $E0, $1C, $03));
+  m_modes[2] := TPTCMode.Create(320, 200, TPTCFormat.Create(16, $F800, $7E0, $1F));
+
   m_faketype := FAKEMODE2A;
   m_faketype := FAKEMODE2A;
 
 
   configure('ptcpas.cfg');
   configure('ptcpas.cfg');
 end;
 end;
 
 
 destructor TVGAConsole.Destroy;
 destructor TVGAConsole.Destroy;
-
 begin
 begin
   close;
   close;
   internal_clear_mode_list;
   internal_clear_mode_list;
@@ -92,19 +76,13 @@ begin
   FEventQueue.Free;
   FEventQueue.Free;
   m_copy.Free;
   m_copy.Free;
   m_clear.Free;
   m_clear.Free;
-  m_default_format.Free;
-  m_palette.Free;
-  m_clip.Free;
-  m_area.Free;
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
-procedure TVGAConsole.Configure(const AFileName: String);
-
+procedure TVGAConsole.Configure(const AFileName: string);
 var
 var
-  F: Text;
+  F: TextFile;
   S: string;
   S: string;
-
 begin
 begin
   AssignFile(F, AFileName);
   AssignFile(F, AFileName);
   {$push}{$I-}
   {$push}{$I-}
@@ -124,8 +102,7 @@ begin
   CloseFile(F);
   CloseFile(F);
 end;
 end;
 
 
-function TVGAConsole.option(const _option: String): Boolean;
-
+function TVGAConsole.option(const _option: string): Boolean;
 begin
 begin
   {...}
   {...}
   if (System.Copy(_option, 1, 8) = 'FAKEMODE') and (Length(_option) = 10) and
   if (System.Copy(_option, 1, 8) = 'FAKEMODE') and (Length(_option) = 10) and
@@ -169,62 +146,37 @@ begin
 end;
 end;
 
 
 procedure TVGAConsole.internal_clear_mode_list;
 procedure TVGAConsole.internal_clear_mode_list;
-
-var
-  I: Integer;
-  Done: Boolean;
-
 begin
 begin
-  I := 0;
-  Done := False;
-  repeat
-    Done := not m_modes[I].valid;
-    m_modes[I].Free;
-    Inc(I);
-  until Done;
+  SetLength(m_modes, 0);
 end;
 end;
 
 
-function TVGAConsole.modes: PPTCMode;
-
+function TVGAConsole.modes: TPTCModeList;
 begin
 begin
   Result := m_modes;
   Result := m_modes;
 end;
 end;
 
 
 procedure TVGAConsole.open(const _title: string; _pages: Integer); overload;
 procedure TVGAConsole.open(const _title: string; _pages: Integer); overload;
-
 begin
 begin
   open(_title, m_default_format, _pages);
   open(_title, m_default_format, _pages);
 end;
 end;
 
 
-procedure TVGAConsole.open(const _title: string; const _format: TPTCFormat;
+procedure TVGAConsole.open(const _title: string; _format: IPTCFormat;
                            _pages: Integer); overload;
                            _pages: Integer); overload;
-
 begin
 begin
   open(_title, m_default_width, m_default_height, _format, _pages);
   open(_title, m_default_width, m_default_height, _format, _pages);
 end;
 end;
 
 
 procedure TVGAConsole.open(const _title: string; _width, _height: Integer;
 procedure TVGAConsole.open(const _title: string; _width, _height: Integer;
-                           const _format: TPTCFormat; _pages: Integer); overload;
-
-var
-  m: TPTCMode;
-
+                           _format: IPTCFormat; _pages: Integer); overload;
 begin
 begin
-  m := TPTCMode.Create(_width, _height, _format);
-  try
-    open(_title, m, _pages);
-  finally
-    m.Free;
-  end;
+  open(_title, TPTCMode.Create(_width, _height, _format), _pages);
 end;
 end;
 
 
-procedure TVGAConsole.open(const _title: string; const _mode: TPTCMode;
+procedure TVGAConsole.open(const _title: string; _mode: IPTCMode;
                            _pages: Integer); overload;
                            _pages: Integer); overload;
-
 var
 var
   I: Integer;
   I: Integer;
   modetype: Integer;
   modetype: Integer;
-
 begin
 begin
   if not _mode.valid then
   if not _mode.valid then
     raise TPTCError.Create('invalid mode');
     raise TPTCError.Create('invalid mode');
@@ -243,7 +195,6 @@ begin
 end;
 end;
 
 
 procedure TVGAConsole.close;
 procedure TVGAConsole.close;
-
 begin
 begin
   if m_open then
   if m_open then
   begin
   begin
@@ -257,22 +208,19 @@ begin
 end;
 end;
 
 
 procedure TVGAConsole.flush;
 procedure TVGAConsole.flush;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
 end;
 end;
 
 
 procedure TVGAConsole.finish;
 procedure TVGAConsole.finish;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
 end;
 end;
 
 
-procedure TVGAConsole.vga_load(data: Pointer); ASSembler; Register;
-
-Asm
+procedure TVGAConsole.vga_load(data: Pointer); ASSembler; register;
+asm
   push es
   push es
   mov esi, data
   mov esi, data
   mov ax, fs
   mov ax, fs
@@ -285,7 +233,6 @@ Asm
 end;
 end;
 
 
 procedure TVGAConsole.update;
 procedure TVGAConsole.update;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
@@ -299,17 +246,14 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure TVGAConsole.update(const _area: TPTCArea);
-
+procedure TVGAConsole.update(_area: IPTCArea);
 begin
 begin
   update;
   update;
 end;
 end;
 
 
-procedure TVGAConsole.copy(surface: TPTCBaseSurface);
-
+procedure TVGAConsole.copy(surface: IPTCSurface);
 var
 var
   pixels: Pointer;
   pixels: Pointer;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
@@ -323,16 +267,13 @@ begin
   except
   except
     on error: TPTCError do
     on error: TPTCError do
       raise TPTCError.Create('failed to copy console to surface', error);
       raise TPTCError.Create('failed to copy console to surface', error);
-
   end;
   end;
 end;
 end;
 
 
-procedure TVGAConsole.copy(surface: TPTCBaseSurface;
-                           const source, destination: TPTCArea);
-
+procedure TVGAConsole.copy(surface: IPTCSurface;
+                           source, destination: IPTCArea);
 var
 var
   pixels: Pointer;
   pixels: Pointer;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
@@ -346,12 +287,10 @@ begin
   except
   except
     on error: TPTCError do
     on error: TPTCError do
       raise TPTCError.Create('failed to copy console to surface', error);
       raise TPTCError.Create('failed to copy console to surface', error);
-
   end;
   end;
 end;
 end;
 
 
 function TVGAConsole.lock: Pointer;
 function TVGAConsole.lock: Pointer;
-
 begin
 begin
   check_open;
   check_open;
   if m_locked then
   if m_locked then
@@ -362,7 +301,6 @@ begin
 end;
 end;
 
 
 procedure TVGAConsole.unlock;
 procedure TVGAConsole.unlock;
-
 begin
 begin
   check_open;
   check_open;
   if not m_locked then
   if not m_locked then
@@ -371,14 +309,12 @@ begin
   m_locked := False;
   m_locked := False;
 end;
 end;
 
 
-procedure TVGAConsole.load(const pixels: Pointer;
+procedure TVGAConsole.Load(const pixels: Pointer;
                            _width, _height, _pitch: Integer;
                            _width, _height, _pitch: Integer;
-                           const _format: TPTCFormat;
-                           const _palette: TPTCPalette);
+                           _format: IPTCFormat;
+                           _palette: IPTCPalette);
 var
 var
-  Area_: TPTCArea;
   console_pixels: Pointer;
   console_pixels: Pointer;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
@@ -397,70 +333,46 @@ begin
     except
     except
       on error: TPTCError do
       on error: TPTCError do
         raise TPTCError.Create('failed to load pixels to console', error);
         raise TPTCError.Create('failed to load pixels to console', error);
-
     end;
     end;
   end
   end
   else
   else
-  begin
-    Area_ := TPTCArea.Create(0, 0, width, height);
-    try
-      load(pixels, _width, _height, _pitch, _format, _palette, Area_, area);
-    finally
-      Area_.Free;
-    end;
-  end;
+    Load(pixels, _width, _height, _pitch, _format, _palette, TPTCArea.Create(0, 0, width, height), area);
 end;
 end;
 
 
-procedure TVGAConsole.load(const pixels: Pointer;
+procedure TVGAConsole.Load(const pixels: Pointer;
                            _width, _height, _pitch: Integer;
                            _width, _height, _pitch: Integer;
-                           const _format: TPTCFormat;
-                           const _palette: TPTCPalette;
-                           const source, destination: TPTCArea);
+                           _format: IPTCFormat;
+                           _palette: IPTCPalette;
+                           source, destination: IPTCArea);
 var
 var
   console_pixels: Pointer;
   console_pixels: Pointer;
-  clipped_source, clipped_destination: TPTCArea;
-  tmp: TPTCArea;
-
+  clipped_source, clipped_destination: IPTCArea;
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
-  clipped_source := nil;
-  clipped_destination := nil;
   try
   try
     console_pixels := lock;
     console_pixels := lock;
     try
     try
-      clipped_source := TPTCArea.Create;
-      clipped_destination := TPTCArea.Create;
-      tmp := TPTCArea.Create(0, 0, _width, _height);
-      try
-        TPTCClipper.clip(source, tmp, clipped_source, destination, clip, clipped_destination);
-      finally
-        tmp.Free;
-      end;
+      TPTCClipper.clip(source, TPTCArea.Create(0, 0, _width, _height), clipped_source, destination, clip, clipped_destination);
       m_copy.request(_format, format);
       m_copy.request(_format, format);
       m_copy.palette(_palette, palette);
       m_copy.palette(_palette, palette);
       m_copy.copy(pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, _pitch,
       m_copy.copy(pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, _pitch,
                   console_pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, pitch);
                   console_pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, pitch);
     finally
     finally
       unlock;
       unlock;
-      clipped_source.Free;
-      clipped_destination.Free;
     end;
     end;
   except
   except
     on error:TPTCError do
     on error:TPTCError do
       raise TPTCError.Create('failed to load pixels to console area', error);
       raise TPTCError.Create('failed to load pixels to console area', error);
-
   end;
   end;
 end;
 end;
 
 
 procedure TVGAConsole.save(pixels: Pointer;
 procedure TVGAConsole.save(pixels: Pointer;
                            _width, _height, _pitch: Integer;
                            _width, _height, _pitch: Integer;
-                           const _format: TPTCFormat;
-                           const _palette: TPTCPalette);
+                           _format: IPTCFormat;
+                           _palette: IPTCPalette);
 var
 var
-  Area_: TPTCArea;
   console_pixels: Pointer;
   console_pixels: Pointer;
-
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
@@ -479,109 +391,69 @@ begin
     except
     except
       on error: TPTCError do
       on error: TPTCError do
         raise TPTCError.Create('failed to save console pixels', error);
         raise TPTCError.Create('failed to save console pixels', error);
-
     end;
     end;
   end
   end
   else
   else
-  begin
-    Area_ := TPTCArea.Create(0, 0, width, height);
-    try
-      save(pixels, _width, _height, _pitch, _format, _palette, area, Area_);
-    finally
-      Area_.Free;
-    end;
-  end;
+    Save(pixels, _width, _height, _pitch, _format, _palette, area, TPTCArea.Create(0, 0, width, height));
 end;
 end;
 
 
-procedure TVGAConsole.save(pixels: Pointer;
+procedure TVGAConsole.Save(pixels: Pointer;
                            _width, _height, _pitch: Integer;
                            _width, _height, _pitch: Integer;
-                           const _format: TPTCFormat;
-                           const _palette: TPTCPalette;
-                           const source, destination: TPTCArea);
+                           _format: IPTCFormat;
+                           _palette: IPTCPalette;
+                           source, destination: IPTCArea);
 var
 var
   console_pixels: Pointer;
   console_pixels: Pointer;
-  clipped_source, clipped_destination: TPTCArea;
-  tmp: TPTCArea;
-
+  clipped_source, clipped_destination: IPTCArea;
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
-  clipped_source := nil;
-  clipped_destination := nil;
   try
   try
     console_pixels := lock;
     console_pixels := lock;
     try
     try
-      clipped_source := TPTCArea.Create;
-      clipped_destination := TPTCArea.Create;
-      tmp := TPTCArea.Create(0, 0, _width, _height);
-      try
-        TPTCClipper.clip(source, clip, clipped_source, destination, tmp, clipped_destination);
-      finally
-        tmp.Free;
-      end;
+      TPTCClipper.clip(source, clip, clipped_source, destination, TPTCArea.Create(0, 0, _width, _height), clipped_destination);
       m_copy.request(format, _format);
       m_copy.request(format, _format);
       m_copy.palette(palette, _palette);
       m_copy.palette(palette, _palette);
       m_copy.copy(console_pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, pitch,
       m_copy.copy(console_pixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, pitch,
                   pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, _pitch);
                   pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, _pitch);
     finally
     finally
       unlock;
       unlock;
-      clipped_source.Free;
-      clipped_destination.Free;
     end;
     end;
   except
   except
     on error:TPTCError do
     on error:TPTCError do
       raise TPTCError.Create('failed to save console area pixels', error);
       raise TPTCError.Create('failed to save console area pixels', error);
-
   end;
   end;
 end;
 end;
 
 
 procedure TVGAConsole.clear;
 procedure TVGAConsole.clear;
-
 var
 var
-  tmp: TPTCColor;
-
+  Color: IPTCColor;
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
   if format.direct then
   if format.direct then
-    tmp := TPTCColor.Create(0, 0, 0, 0)
+    Color := TPTCColor.Create(0, 0, 0, 0)
   else
   else
-    tmp := TPTCColor.Create(0);
-  try
-    clear(tmp);
-  finally
-    tmp.Free;
-  end;
+    Color := TPTCColor.Create(0);
+  Clear(Color);
 end;
 end;
 
 
-procedure TVGAConsole.clear(const color: TPTCColor);
-
-var
-  tmp: TPTCArea;
-
+procedure TVGAConsole.clear(AColor: IPTCColor);
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
-  tmp := TPTCArea.Create;
-  try
-    clear(color, tmp);
-  finally
-    tmp.Free;
-  end;
+  Clear(AColor, TPTCArea.Create);
 end;
 end;
 
 
-procedure TVGAConsole.clear(const color: TPTCColor;
-                            const _area: TPTCArea);
-
+procedure TVGAConsole.clear(color: IPTCColor;
+                            _area: IPTCArea);
 var
 var
   pixels: Pointer;
   pixels: Pointer;
-  clipped_area: TPTCArea;
-
+  clipped_area: IPTCArea;
 begin
 begin
   check_open;
   check_open;
   check_unlocked;
   check_unlocked;
   try
   try
-    clipped_area := nil;
     pixels := lock;
     pixels := lock;
     try
     try
       clipped_area := TPTCClipper.clip(_area, clip);
       clipped_area := TPTCClipper.clip(_area, clip);
@@ -589,17 +461,14 @@ begin
       m_clear.clear(pixels, clipped_area.left, clipped_area.right, clipped_area.width, clipped_area.height, pitch, color);
       m_clear.clear(pixels, clipped_area.left, clipped_area.right, clipped_area.width, clipped_area.height, pitch, color);
     finally
     finally
       unlock;
       unlock;
-      clipped_area.Free;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do
       raise TPTCError.Create('failed to clear console area', error);
       raise TPTCError.Create('failed to clear console area', error);
-
   end;
   end;
 end;
 end;
 
 
-procedure TVGAConsole.Palette(const _palette: TPTCPalette);
-
+procedure TVGAConsole.Palette(_palette: IPTCPalette);
 begin
 begin
   check_open;
   check_open;
   if format.indexed then
   if format.indexed then
@@ -609,111 +478,85 @@ begin
   end;
   end;
 end;
 end;
 
 
-function TVGAConsole.Palette: TPTCPalette;
-
+function TVGAConsole.Palette: IPTCPalette;
 begin
 begin
   check_open;
   check_open;
   Result := m_palette;
   Result := m_palette;
 end;
 end;
 
 
-procedure TVGAConsole.Clip(const _area: TPTCArea);
-
-var
-  tmp: TPTCArea;
-
+procedure TVGAConsole.Clip(_area: IPTCArea);
 begin
 begin
   check_open;
   check_open;
-  tmp := TPTCClipper.clip(_area, m_area);
-  try
-    m_clip.Assign(tmp);
-  finally
-    tmp.Free;
-  end;
+  m_clip := TPTCClipper.clip(_area, m_area);
 end;
 end;
 
 
 function TVGAConsole.GetWidth: Integer;
 function TVGAConsole.GetWidth: Integer;
-
 begin
 begin
   check_open;
   check_open;
   Result := m_width;
   Result := m_width;
 end;
 end;
 
 
 function TVGAConsole.GetHeight: Integer;
 function TVGAConsole.GetHeight: Integer;
-
 begin
 begin
   check_open;
   check_open;
   Result := m_height;
   Result := m_height;
 end;
 end;
 
 
 function TVGAConsole.GetPitch: Integer;
 function TVGAConsole.GetPitch: Integer;
-
 begin
 begin
   check_open;
   check_open;
   Result := m_pitch;
   Result := m_pitch;
 end;
 end;
 
 
 function TVGAConsole.GetPages: Integer;
 function TVGAConsole.GetPages: Integer;
-
 begin
 begin
   check_open;
   check_open;
   Result := 2;
   Result := 2;
 end;
 end;
 
 
-function TVGAConsole.GetArea: TPTCArea;
-
+function TVGAConsole.GetArea: IPTCArea;
 begin
 begin
   check_open;
   check_open;
   Result := m_area;
   Result := m_area;
 end;
 end;
 
 
-function TVGAConsole.Clip: TPTCArea;
-
+function TVGAConsole.Clip: IPTCArea;
 begin
 begin
   check_open;
   check_open;
   Result := m_clip;
   Result := m_clip;
 end;
 end;
 
 
-function TVGAConsole.GetFormat: TPTCFormat;
-
+function TVGAConsole.GetFormat: IPTCFormat;
 begin
 begin
   check_open;
   check_open;
   Result := m_modes[m_CurrentMode].format;
   Result := m_modes[m_CurrentMode].format;
 end;
 end;
 
 
 function TVGAConsole.GetName: string;
 function TVGAConsole.GetName: string;
-
 begin
 begin
   Result := 'VGA';
   Result := 'VGA';
 end;
 end;
 
 
 function TVGAConsole.GetTitle: string;
 function TVGAConsole.GetTitle: string;
-
 begin
 begin
   Result := m_title;
   Result := m_title;
 end;
 end;
 
 
 function TVGAConsole.GetInformation: string;
 function TVGAConsole.GetInformation: string;
-
 begin
 begin
   Result := m_information;
   Result := m_information;
 end;
 end;
 
 
-procedure TVGAConsole.internal_pre_open_setup(const _title: String);
-
+procedure TVGAConsole.internal_pre_open_setup(const _title: string);
 begin
 begin
   m_title := _title;
   m_title := _title;
 end;
 end;
 
 
 procedure TVGAConsole.internal_open_fullscreen_start;
 procedure TVGAConsole.internal_open_fullscreen_start;
-
 begin
 begin
 end;
 end;
 
 
 procedure TVGAConsole.internal_open_fullscreen(ModeType: Integer);
 procedure TVGAConsole.internal_open_fullscreen(ModeType: Integer);
-
-var
-  tmp: TPTCArea;
-
 begin
 begin
   VGASetMode(320, 200, ModeType, m_faketype);
   VGASetMode(320, 200, ModeType, m_faketype);
   case ModeType of
   case ModeType of
@@ -733,17 +576,11 @@ begin
   m_width := 320;
   m_width := 320;
   m_height := 200;
   m_height := 200;
 
 
-  tmp := TPTCArea.Create(0, 0, m_width, m_height);
-  try
-    m_area.Assign(tmp);
-    m_clip.Assign(tmp);
-  finally
-    tmp.Free;
-  end;
+  m_area := TPTCArea.Create(0, 0, m_width, m_height);
+  m_clip := m_area;
 end;
 end;
 
 
 procedure TVGAConsole.internal_open_fullscreen_finish(_pages: Integer);
 procedure TVGAConsole.internal_open_fullscreen_finish(_pages: Integer);
-
 begin
 begin
   FreeMemAndNil(m_primary);
   FreeMemAndNil(m_primary);
   m_primary := GetMem(m_height * m_pitch);
   m_primary := GetMem(m_height * m_pitch);
@@ -751,7 +588,6 @@ begin
 end;
 end;
 
 
 procedure TVGAConsole.internal_post_open_setup;
 procedure TVGAConsole.internal_post_open_setup;
-
 begin
 begin
   FreeAndNil(m_keyboard);
   FreeAndNil(m_keyboard);
   FreeAndNil(FMouse);
   FreeAndNil(FMouse);
@@ -768,7 +604,6 @@ begin
 end;
 end;
 
 
 procedure TVGAConsole.internal_reset;
 procedure TVGAConsole.internal_reset;
-
 begin
 begin
   FreeMemAndNil(m_primary);
   FreeMemAndNil(m_primary);
   FreeAndNil(m_keyboard);
   FreeAndNil(m_keyboard);
@@ -777,7 +612,6 @@ begin
 end;
 end;
 
 
 procedure TVGAConsole.internal_close;
 procedure TVGAConsole.internal_close;
-
 begin
 begin
   FreeMemAndNil(m_primary);
   FreeMemAndNil(m_primary);
   FreeAndNil(m_keyboard);
   FreeAndNil(m_keyboard);
@@ -788,11 +622,9 @@ begin
 end;
 end;
 
 
 procedure TVGAConsole.internal_SetPalette(data: PUint32);
 procedure TVGAConsole.internal_SetPalette(data: PUint32);
-
 var
 var
   i: Integer;
   i: Integer;
   c: DWord;
   c: DWord;
-
 begin
 begin
   outportb($3C8, 0);
   outportb($3C8, 0);
   for i := 0 to 255 do
   for i := 0 to 255 do
@@ -806,18 +638,15 @@ begin
 end;
 end;
 
 
 procedure TVGAConsole.HandleEvents;
 procedure TVGAConsole.HandleEvents;
-
 begin
 begin
   m_keyboard.GetPendingEvents(FEventQueue);
   m_keyboard.GetPendingEvents(FEventQueue);
   FMouse.GetPendingEvents(FEventQueue);
   FMouse.GetPendingEvents(FEventQueue);
 end;
 end;
 
 
-function TVGAConsole.NextEvent(var event: TPTCEvent; wait: Boolean; const EventMask: TPTCEventMask): Boolean;
-
+function TVGAConsole.NextEvent(out event: IPTCEvent; wait: Boolean; const EventMask: TPTCEventMask): Boolean;
 begin
 begin
   check_open;
   check_open;
 
 
-  FreeAndNil(event);
   repeat
   repeat
     { get events }
     { get events }
     HandleEvents;
     HandleEvents;
@@ -828,8 +657,7 @@ begin
   Result := event <> nil;
   Result := event <> nil;
 end;
 end;
 
 
-function TVGAConsole.PeekEvent(wait: Boolean; const EventMask: TPTCEventMask): TPTCEvent;
-
+function TVGAConsole.PeekEvent(wait: Boolean; const EventMask: TPTCEventMask): IPTCEvent;
 begin
 begin
   check_open;
   check_open;
 
 
@@ -843,14 +671,12 @@ begin
 end;
 end;
 
 
 procedure TVGAConsole.check_open;
 procedure TVGAConsole.check_open;
-
 begin
 begin
   if not m_open then
   if not m_open then
     raise TPTCError.Create('console is not open');
     raise TPTCError.Create('console is not open');
 end;
 end;
 
 
 procedure TVGAConsole.check_unlocked;
 procedure TVGAConsole.check_unlocked;
-
 begin
 begin
   if m_locked then
   if m_locked then
     raise TPTCError.Create('console is not unlocked');
     raise TPTCError.Create('console is not unlocked');

+ 1 - 1
packages/ptc/src/ptc.pp

@@ -60,7 +60,7 @@ uses
 {$ENDIF FPDOC}
 {$ENDIF FPDOC}
 
 
 const
 const
-  PTCPAS_VERSION = 'PTCPas 0.99.11';
+  PTCPAS_VERSION = 'PTCPas 0.99.12';
 
 
 type
 type
   PUint8  = ^Uint8;
   PUint8  = ^Uint8;

+ 9 - 8
packages/ptc/src/ptcwrapper/ptceventqueue.pp

@@ -42,7 +42,7 @@ uses
 type
 type
   PEventLinkedList = ^TEventLinkedList;
   PEventLinkedList = ^TEventLinkedList;
   TEventLinkedList = record
   TEventLinkedList = record
-    Event: TPTCEvent;
+    Event: IPTCEvent;
     Next: PEventLinkedList;
     Next: PEventLinkedList;
   end;
   end;
   TEventQueue = class
   TEventQueue = class
@@ -51,9 +51,9 @@ type
   public
   public
     constructor Create;
     constructor Create;
     destructor Destroy; override;
     destructor Destroy; override;
-    procedure AddEvent(event: TPTCEvent);
-    function PeekEvent(const EventMask: TPTCEventMask): TPTCEvent;
-    function NextEvent(const EventMask: TPTCEventMask): TPTCEvent;
+    procedure AddEvent(const event: IPTCEvent);
+    function PeekEvent(const EventMask: TPTCEventMask): IPTCEvent;
+    function NextEvent(const EventMask: TPTCEventMask): IPTCEvent;
   end;
   end;
 
 
 implementation
 implementation
@@ -71,7 +71,7 @@ begin
   p := FHead;
   p := FHead;
   while p <> nil do
   while p <> nil do
   begin
   begin
-    FreeAndNil(p^.Event);
+    p^.Event := nil;
     pnext := p^.Next;
     pnext := p^.Next;
     Dispose(p);
     Dispose(p);
     p := pnext;
     p := pnext;
@@ -79,7 +79,7 @@ begin
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
-procedure TEventQueue.AddEvent(event: TPTCEvent);
+procedure TEventQueue.AddEvent(const event: IPTCEvent);
 var
 var
   tmp: PEventLinkedList;
   tmp: PEventLinkedList;
 begin
 begin
@@ -100,7 +100,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-function TEventQueue.PeekEvent(const EventMask: TPTCEventMask): TPTCEvent;
+function TEventQueue.PeekEvent(const EventMask: TPTCEventMask): IPTCEvent;
 var
 var
   p: PEventLinkedList;
   p: PEventLinkedList;
 begin
 begin
@@ -118,7 +118,7 @@ begin
   Result := nil;
   Result := nil;
 end;
 end;
 
 
-function TEventQueue.NextEvent(const EventMask: TPTCEventMask): TPTCEvent;
+function TEventQueue.NextEvent(const EventMask: TPTCEventMask): IPTCEvent;
 var
 var
   prev, p: PEventLinkedList;
   prev, p: PEventLinkedList;
 begin
 begin
@@ -129,6 +129,7 @@ begin
     if p^.Event.EventType In EventMask then
     if p^.Event.EventType In EventMask then
     begin
     begin
       Result := p^.Event;
       Result := p^.Event;
+      p^.Event := nil;
 
 
       { delete the element from the linked list }
       { delete the element from the linked list }
       if prev <> nil then
       if prev <> nil then

+ 28 - 35
packages/ptc/src/ptcwrapper/ptcwrapper.pp

@@ -60,8 +60,8 @@ type
     Title: string;
     Title: string;
     SurfaceWidth, SurfaceHeight: Integer;
     SurfaceWidth, SurfaceHeight: Integer;
     Width, Height: Integer;
     Width, Height: Integer;
-    Format: TPTCFormat;
-    Mode: TPTCMode;
+    Format: IPTCFormat;
+    Mode: IPTCMode;
     VirtualPages: Integer;
     VirtualPages: Integer;
     Pages: Integer;
     Pages: Integer;
 
 
@@ -84,14 +84,14 @@ type
   TPTCWrapperGetModesRequest = record
   TPTCWrapperGetModesRequest = record
     Processed: Boolean;
     Processed: Boolean;
 
 
-    Result: PPTCMode;
+    Result: TPTCModeList;
   end;
   end;
 
 
   TPTCWrapperThread = class(TThread)
   TPTCWrapperThread = class(TThread)
   private
   private
-    FConsole: TPTCConsole;
-    FSurface: array of TPTCSurface;
-    FPalette: TPTCPalette;
+    FConsole: IPTCConsole;
+    FSurface: array of IPTCSurface;
+    FPalette: IPTCPalette;
     FSurfaceCriticalSection: TCriticalSection;
     FSurfaceCriticalSection: TCriticalSection;
     FNeedsUpdate: Boolean;
     FNeedsUpdate: Boolean;
     FPaletteNeedsUpdate: Boolean;
     FPaletteNeedsUpdate: Boolean;
@@ -116,14 +116,14 @@ type
     destructor Destroy; override;
     destructor Destroy; override;
 
 
     procedure Open(const ATitle: string; AVirtualPages: Integer; APages: Integer = 0);
     procedure Open(const ATitle: string; AVirtualPages: Integer; APages: Integer = 0);
-    procedure Open(const ATitle: string; AFormat: TPTCFormat; AVirtualPages: Integer; APages: Integer = 0);
-    procedure Open(const ATitle: string; ASurfaceWidth, ASurfaceHeight, AWidth, AHeight: Integer; AFormat: TPTCFormat; AVirtualPages: Integer; APages: Integer = 0);
-    procedure Open(const ATitle: string; ASurfaceWidth, ASurfaceHeight: Integer; AMode: TPTCMode; AVirtualPages: Integer; APages: Integer = 0);
+    procedure Open(const ATitle: string; AFormat: IPTCFormat; AVirtualPages: Integer; APages: Integer = 0);
+    procedure Open(const ATitle: string; ASurfaceWidth, ASurfaceHeight, AWidth, AHeight: Integer; AFormat: IPTCFormat; AVirtualPages: Integer; APages: Integer = 0);
+    procedure Open(const ATitle: string; ASurfaceWidth, ASurfaceHeight: Integer; AMode: IPTCMode; AVirtualPages: Integer; APages: Integer = 0);
     procedure Close;
     procedure Close;
 
 
     function Option(const AOption: string): Boolean;
     function Option(const AOption: string): Boolean;
 
 
-    function Modes: PPTCMode;
+    function Modes: TPTCModeList;
 
 
     procedure SetVisualPage(AVisualPage: Integer);
     procedure SetVisualPage(AVisualPage: Integer);
 
 
@@ -133,8 +133,8 @@ type
     function PaletteLock: Pointer;
     function PaletteLock: Pointer;
     procedure PaletteUnlock;
     procedure PaletteUnlock;
 
 
-    function NextEvent(var AEvent: TPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
-    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): TPTCEvent;
+    function NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
+    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent;
 
 
     property IsOpen: Boolean read FOpen;
     property IsOpen: Boolean read FOpen;
   end;
   end;
@@ -174,16 +174,13 @@ end;
 procedure TPTCWrapperThread.Execute;
 procedure TPTCWrapperThread.Execute;
   procedure GetEvents;
   procedure GetEvents;
   var
   var
-    Event: TPTCEvent = nil;
+    Event: IPTCEvent;
     NextEventAvailable: Boolean;
     NextEventAvailable: Boolean;
   begin
   begin
     repeat
     repeat
       NextEventAvailable := FConsole.NextEvent(Event, False, PTCAnyEvent);
       NextEventAvailable := FConsole.NextEvent(Event, False, PTCAnyEvent);
       if NextEventAvailable then
       if NextEventAvailable then
-      begin
         FEventQueue.AddEvent(Event);
         FEventQueue.AddEvent(Event);
-        Event := nil;
-      end;
     until not NextEventAvailable;
     until not NextEventAvailable;
   end;
   end;
 
 
@@ -194,7 +191,7 @@ procedure TPTCWrapperThread.Execute;
     if not FOpenRequest.Processed then
     if not FOpenRequest.Processed then
     begin
     begin
       for I := Low(FSurface) to High(FSurface) do
       for I := Low(FSurface) to High(FSurface) do
-        FreeAndNil(FSurface[I]);
+        FSurface[I] := nil;
       with FOpenRequest do
       with FOpenRequest do
       begin
       begin
         SetLength(FSurface, VirtualPages);
         SetLength(FSurface, VirtualPages);
@@ -203,25 +200,25 @@ procedure TPTCWrapperThread.Execute;
             begin
             begin
               FConsole.Open(Title, Pages);
               FConsole.Open(Title, Pages);
               for I := Low(FSurface) to High(FSurface) do
               for I := Low(FSurface) to High(FSurface) do
-                FSurface[I] := TPTCSurface.Create(FConsole.Width, FConsole.Height, FConsole.Format);
+                FSurface[I] := TPTCSurfaceFactory.CreateNew(FConsole.Width, FConsole.Height, FConsole.Format);
             end;
             end;
           pwotFormat:
           pwotFormat:
             begin
             begin
               FConsole.Open(Title, Format, Pages);
               FConsole.Open(Title, Format, Pages);
               for I := Low(FSurface) to High(FSurface) do
               for I := Low(FSurface) to High(FSurface) do
-                FSurface[I] := TPTCSurface.Create(FConsole.Width, FConsole.Height, Format);
+                FSurface[I] := TPTCSurfaceFactory.CreateNew(FConsole.Width, FConsole.Height, Format);
             end;
             end;
           pwotWidthHeightFormat:
           pwotWidthHeightFormat:
             begin
             begin
               FConsole.Open(Title, Width, Height, Format, Pages);
               FConsole.Open(Title, Width, Height, Format, Pages);
               for I := Low(FSurface) to High(FSurface) do
               for I := Low(FSurface) to High(FSurface) do
-                FSurface[I] := TPTCSurface.Create(SurfaceWidth, SurfaceHeight, Format);
+                FSurface[I] := TPTCSurfaceFactory.CreateNew(SurfaceWidth, SurfaceHeight, Format);
             end;
             end;
           pwotMode:
           pwotMode:
             begin
             begin
               FConsole.Open(Title, Mode, Pages);
               FConsole.Open(Title, Mode, Pages);
               for I := Low(FSurface) to High(FSurface) do
               for I := Low(FSurface) to High(FSurface) do
-                FSurface[I] := TPTCSurface.Create(SurfaceWidth, SurfaceHeight, Mode.Format);
+                FSurface[I] := TPTCSurfaceFactory.CreateNew(SurfaceWidth, SurfaceHeight, Mode.Format);
             end;
             end;
         end;
         end;
       end;
       end;
@@ -241,7 +238,7 @@ procedure TPTCWrapperThread.Execute;
     begin
     begin
       FConsole.Close;
       FConsole.Close;
       for I := Low(FSurface) to High(FSurface) do
       for I := Low(FSurface) to High(FSurface) do
-        FreeAndNil(FSurface[I]);
+        FSurface[I] := nil;
       SetLength(FSurface, 0);
       SetLength(FSurface, 0);
       SetLength(FPixels, 0);
       SetLength(FPixels, 0);
       FOpen := False;
       FOpen := False;
@@ -266,10 +263,10 @@ var
   I: Integer;
   I: Integer;
 begin
 begin
   try
   try
-    FConsole := TPTCConsole.Create;
+    FConsole := TPTCConsoleFactory.CreateNew;
 
 
     FEventQueue := TEventQueue.Create;
     FEventQueue := TEventQueue.Create;
-    FPalette := TPTCPalette.Create;
+    FPalette := TPTCPaletteFactory.CreateNew;
     FPaletteData := FPalette.Data;
     FPaletteData := FPalette.Data;
 
 
     FOpen := False;
     FOpen := False;
@@ -312,11 +309,8 @@ begin
     if Assigned(FConsole) then
     if Assigned(FConsole) then
       FConsole.Close;
       FConsole.Close;
 
 
-    for I := Low(FSurface) to High(FSurface) do
-      FreeAndNil(FSurface[I]);
     SetLength(FSurface, 0);
     SetLength(FSurface, 0);
-    FreeAndNil(FPalette);
-    FreeAndNil(FConsole);
+    FConsole := nil;
   end;
   end;
 end;
 end;
 
 
@@ -341,7 +335,7 @@ begin
   until FOpenRequest.Processed;
   until FOpenRequest.Processed;
 end;
 end;
 
 
-procedure TPTCWrapperThread.Open(const ATitle: string; AFormat: TPTCFormat; AVirtualPages: Integer; APages: Integer = 0);
+procedure TPTCWrapperThread.Open(const ATitle: string; AFormat: IPTCFormat; AVirtualPages: Integer; APages: Integer = 0);
 begin
 begin
   FSurfaceCriticalSection.Acquire;
   FSurfaceCriticalSection.Acquire;
   try
   try
@@ -363,7 +357,7 @@ begin
   until FOpenRequest.Processed;
   until FOpenRequest.Processed;
 end;
 end;
 
 
-procedure TPTCWrapperThread.Open(const ATitle: string; ASurfaceWidth, ASurfaceHeight, AWidth, AHeight: Integer; AFormat: TPTCFormat; AVirtualPages: Integer; APages: Integer = 0);
+procedure TPTCWrapperThread.Open(const ATitle: string; ASurfaceWidth, ASurfaceHeight, AWidth, AHeight: Integer; AFormat: IPTCFormat; AVirtualPages: Integer; APages: Integer = 0);
 begin
 begin
   FSurfaceCriticalSection.Acquire;
   FSurfaceCriticalSection.Acquire;
   try
   try
@@ -389,7 +383,7 @@ begin
   until FOpenRequest.Processed;
   until FOpenRequest.Processed;
 end;
 end;
 
 
-procedure TPTCWrapperThread.Open(const ATitle: string; ASurfaceWidth, ASurfaceHeight: Integer; AMode: TPTCMode; AVirtualPages: Integer; APages: Integer = 0);
+procedure TPTCWrapperThread.Open(const ATitle: string; ASurfaceWidth, ASurfaceHeight: Integer; AMode: IPTCMode; AVirtualPages: Integer; APages: Integer = 0);
 begin
 begin
   FSurfaceCriticalSection.Acquire;
   FSurfaceCriticalSection.Acquire;
   try
   try
@@ -449,7 +443,7 @@ begin
   Result := FOptionRequest.Result;
   Result := FOptionRequest.Result;
 end;
 end;
 
 
-function TPTCWrapperThread.Modes: PPTCMode;
+function TPTCWrapperThread.Modes: TPTCModeList;
 begin
 begin
   FSurfaceCriticalSection.Acquire;
   FSurfaceCriticalSection.Acquire;
   try
   try
@@ -507,9 +501,8 @@ begin
   FSurfaceCriticalSection.Release;
   FSurfaceCriticalSection.Release;
 end;
 end;
 
 
-function TPTCWrapperThread.NextEvent(var AEvent: TPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
+function TPTCWrapperThread.NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
 begin
 begin
-  FreeAndNil(AEvent);
   repeat
   repeat
     ThreadSwitch;
     ThreadSwitch;
 
 
@@ -520,7 +513,7 @@ begin
   Result := AEvent <> nil;
   Result := AEvent <> nil;
 end;
 end;
 
 
-function TPTCWrapperThread.PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): TPTCEvent;
+function TPTCWrapperThread.PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent;
 begin
 begin
   repeat
   repeat
     ThreadSwitch;
     ThreadSwitch;

+ 2 - 5
packages/ptc/src/win32/base/kbd.inc

@@ -88,12 +88,9 @@ begin
     exit;
     exit;
 
 
   { process key message }
   { process key message }
-  if (message = WM_KEYDOWN) or (message = WM_KEYUP) {Or ((message = WM_SYSKEYDOWN) and ((lParam and (1 shl 29)) <> 0))} then
+  if (message = WM_KEYDOWN) or (message = WM_KEYUP) or (message = WM_SYSKEYDOWN) or (message = WM_SYSKEYUP) then
   begin
   begin
-    if message = WM_KEYUP then
-      press := False
-    else
-      press := True;
+    press := (message = WM_KEYDOWN) or (message = WM_SYSKEYDOWN);
 
 
     { update modifiers }
     { update modifiers }
     if wParam = VK_MENU then
     if wParam = VK_MENU then

+ 16 - 0
packages/ptc/src/win32/base/window.inc

@@ -165,6 +165,14 @@ end;
 function WndProcSingleThreaded(hWnd: HWND; message: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
 function WndProcSingleThreaded(hWnd: HWND; message: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
 begin
 begin
   case message of
   case message of
+    WM_SYSCOMMAND:
+      begin
+        { this fixes the pausing of the application when the Alt or F10 key is pressed }
+        if wParam = SC_KEYMENU then
+	  Result := 0
+	else
+          Result := DefWindowProc(hWnd, message, wParam, lParam);
+      end;
     WM_SETCURSOR: begin
     WM_SETCURSOR: begin
       {$WARNING GCLP_HCURSOR not defined in windows unit}
       {$WARNING GCLP_HCURSOR not defined in windows unit}
       if (LOWORD(lParam) = HTCLIENT) and (GetClassLongPtr(hWnd, {GCLP_HCURSOR}GCL_HCURSOR) = 0) then
       if (LOWORD(lParam) = HTCLIENT) and (GetClassLongPtr(hWnd, {GCLP_HCURSOR}GCL_HCURSOR) = 0) then
@@ -188,6 +196,14 @@ function WndProcMultiThreaded(hWnd: HWND; message: UINT; wParam: WPARAM; lParam:
 begin
 begin
   Result := 0;
   Result := 0;
   case message of
   case message of
+    WM_SYSCOMMAND:
+      begin
+        { this fixes the pausing of the application when the Alt or F10 key is pressed }
+        if wParam = SC_KEYMENU then
+	  Result := 0
+	else
+          Result := DefWindowProc(hWnd, message, wParam, lParam);
+      end;
     WM_SETCURSOR: begin
     WM_SETCURSOR: begin
       {$WARNING GCLP_HCURSOR not defined in windows unit}
       {$WARNING GCLP_HCURSOR not defined in windows unit}
       if (LOWORD(lParam) = HTCLIENT) and (GetClassLongPtr(hWnd, {GCLP_HCURSOR}GCL_HCURSOR) = 0) then
       if (LOWORD(lParam) = HTCLIENT) and (GetClassLongPtr(hWnd, {GCLP_HCURSOR}GCL_HCURSOR) = 0) then

+ 40 - 40
packages/ptc/src/win32/directx/directxconsoled.inc

@@ -51,7 +51,7 @@ type
 //    FDefaultPages: Integer;
 //    FDefaultPages: Integer;
     FCenterWindow: Boolean;
     FCenterWindow: Boolean;
     FSynchronizedUpdate: Boolean;
     FSynchronizedUpdate: Boolean;
-    FDefaultFormat: TPTCFormat;
+    FDefaultFormat: IPTCFormat;
     FOutputMode: (DEFAULT, WINDOWED, FULLSCREEN); {Output}
     FOutputMode: (DEFAULT, WINDOWED, FULLSCREEN); {Output}
     FWindowMode: (RESIZABLE, FIXED); {Window}
     FWindowMode: (RESIZABLE, FIXED); {Window}
     FPrimaryModeWindowed: TPrimaryModeEnum; {Primary}
     FPrimaryModeWindowed: TPrimaryModeEnum; {Primary}
@@ -77,8 +77,8 @@ type
     FPrimary: TDirectXPrimary;
     FPrimary: TDirectXPrimary;
 
 
     { internal console management routines }
     { internal console management routines }
-    procedure internal_open(const _title: string; window: HWND; const mode: TPTCMode; _pages: Integer; exact: Boolean);
-    procedure internal_recycle(const _title: string; window: HWND; const mode: TPTCMode; _pages: Integer; exact: Boolean);
+    procedure internal_open(const _title: string; window: HWND; const mode: IPTCMode; _pages: Integer; exact: Boolean);
+    procedure internal_recycle(const _title: string; window: HWND; const mode: IPTCMode; _pages: Integer; exact: Boolean);
     procedure internal_close;
     procedure internal_close;
     procedure internal_shutdown;
     procedure internal_shutdown;
 
 
@@ -88,20 +88,20 @@ type
     procedure internal_open_reset;
     procedure internal_open_reset;
 
 
     { internal fullscreen open routines }
     { internal fullscreen open routines }
-    procedure internal_open_fullscreen_start(window: HWND; const mode: TPTCMode; exact: Boolean);
-    procedure internal_open_fullscreen_change(const mode: TPTCMode; exact: Boolean);
-    procedure internal_open_fullscreen_surface(const mode: TPTCMode; _pages: Integer);
+    procedure internal_open_fullscreen_start(window: HWND; const mode: IPTCMode; exact: Boolean);
+    procedure internal_open_fullscreen_change(const mode: IPTCMode; exact: Boolean);
+    procedure internal_open_fullscreen_surface(const mode: IPTCMode; _pages: Integer);
     procedure internal_open_fullscreen_finish;
     procedure internal_open_fullscreen_finish;
 
 
     { internal windowed open routines }
     { internal windowed open routines }
-    procedure internal_open_windowed_start(window: HWND; const mode: TPTCMode; exact: Boolean);
-    procedure internal_open_windowed_change(const mode: TPTCMode; exact: Boolean);
-    procedure internal_open_windowed_surface(const mode: TPTCMode; _pages: Integer);
+    procedure internal_open_windowed_start(window: HWND; const mode: IPTCMode; exact: Boolean);
+    procedure internal_open_windowed_change(const mode: IPTCMode; exact: Boolean);
+    procedure internal_open_windowed_surface(const mode: IPTCMode; _pages: Integer);
     procedure internal_open_windowed_finish;
     procedure internal_open_windowed_finish;
 
 
     { internal console open recycling routines }
     { internal console open recycling routines }
-    procedure internal_recycle_fullscreen(const _title: string; window: HWND; const mode: TPTCMode; _pages: Integer; exact: Boolean);
-    procedure internal_recycle_windowed(const _title: string; window: HWND; const mode: TPTCMode; _pages: Integer; exact: Boolean);
+    procedure internal_recycle_fullscreen(const _title: string; window: HWND; const mode: IPTCMode; _pages: Integer; exact: Boolean);
+    procedure internal_recycle_windowed(const _title: string; window: HWND; const mode: IPTCMode; _pages: Integer; exact: Boolean);
 
 
 {$IFDEF DEBUG}
 {$IFDEF DEBUG}
     { debug }
     { debug }
@@ -119,59 +119,59 @@ type
     destructor Destroy; override;
     destructor Destroy; override;
     procedure Configure(const AFileName: String); override;
     procedure Configure(const AFileName: String); override;
     function Option(const AOption: String): Boolean; override;
     function Option(const AOption: String): Boolean; override;
-    function Modes: PPTCMode; override;
+    function Modes: TPTCModeList; override;
     procedure Open(const ATitle: string; APages: Integer = 0); overload; override;
     procedure Open(const ATitle: string; APages: Integer = 0); overload; override;
-    procedure Open(const ATitle: string; const AFormat: TPTCFormat;
+    procedure Open(const ATitle: string; AFormat: IPTCFormat;
                    APages: Integer = 0); overload; override;
                    APages: Integer = 0); overload; override;
     procedure Open(const ATitle: string; AWidth, AHeight: Integer;
     procedure Open(const ATitle: string; AWidth, AHeight: Integer;
-                   const AFormat: TPTCFormat; APages: Integer = 0); overload; override;
-    procedure Open(const ATitle: string; const AMode: TPTCMode;
+                   AFormat: IPTCFormat; APages: Integer = 0); overload; override;
+    procedure Open(const ATitle: string; AMode: IPTCMode;
                    APages: Integer = 0); overload; override;
                    APages: Integer = 0); overload; override;
     procedure Close; override;
     procedure Close; override;
     procedure Flush; override;
     procedure Flush; override;
     procedure Finish; override;
     procedure Finish; override;
     procedure Update; override;
     procedure Update; override;
-    procedure Update(const AArea: TPTCArea); override;
-    procedure Copy(ASurface: TPTCBaseSurface); override;
-    procedure Copy(ASurface: TPTCBaseSurface;
-                   const ASource, ADestination: TPTCArea); override;
+    procedure Update(AArea: IPTCArea); override;
+    procedure Copy(ASurface: IPTCSurface); override;
+    procedure Copy(ASurface: IPTCSurface;
+                   ASource, ADestination: IPTCArea); override;
     function Lock: Pointer; override;
     function Lock: Pointer; override;
     procedure Unlock; override;
     procedure Unlock; override;
     procedure Load(const APixels: Pointer;
     procedure Load(const APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette); override;
     procedure Load(const APixels: Pointer;
     procedure Load(const APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea); override;
     procedure Save(APixels: Pointer;
     procedure Save(APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette); override;
     procedure Save(APixels: Pointer;
     procedure Save(APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea); override;
     procedure Clear; override;
     procedure Clear; override;
-    procedure Clear(const AColor: TPTCColor); override;
-    procedure Clear(const AColor: TPTCColor;
-                    const AArea: TPTCArea); override;
-    procedure Palette(const APalette: TPTCPalette); override;
-    function Palette: TPTCPalette; override;
-    procedure Clip(const AArea: TPTCArea); override;
+    procedure Clear(AColor: IPTCColor); override;
+    procedure Clear(AColor: IPTCColor;
+                    AArea: IPTCArea); override;
+    procedure Palette(APalette: IPTCPalette); override;
+    function Palette: IPTCPalette; override;
+    procedure Clip(AArea: IPTCArea); override;
     function GetWidth: Integer; override;
     function GetWidth: Integer; override;
     function GetHeight: Integer; override;
     function GetHeight: Integer; override;
     function GetPitch: Integer; override;
     function GetPitch: Integer; override;
     function GetPages: Integer; override;
     function GetPages: Integer; override;
-    function GetArea: TPTCArea; override;
-    function Clip: TPTCArea; override;
-    function GetFormat: TPTCFormat; override;
+    function GetArea: IPTCArea; override;
+    function Clip: IPTCArea; override;
+    function GetFormat: IPTCFormat; override;
     function GetName: string; override;
     function GetName: string; override;
     function GetTitle: string; override;
     function GetTitle: string; override;
     function GetInformation: string; override;
     function GetInformation: string; override;
-    function NextEvent(var AEvent: TPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; override;
-    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): TPTCEvent; override;
+    function NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; override;
+    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent; override;
   end;
   end;

+ 81 - 151
packages/ptc/src/win32/directx/directxconsolei.inc

@@ -135,7 +135,6 @@ begin
   FEventQueue.Free;
   FEventQueue.Free;
   FWin32Cursor.Free;
   FWin32Cursor.Free;
   FCopy.Free;
   FCopy.Free;
-  FDefaultFormat.Free;
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
@@ -165,7 +164,6 @@ end;
 function TDirectXConsole.Option(const AOption: String): Boolean;
 function TDirectXConsole.Option(const AOption: String): Boolean;
 var
 var
   tmp, tmp2: Integer;
   tmp, tmp2: Integer;
-  tmpformat: TPTCFormat;
 begin
 begin
   LOG('console option', AOption);
   LOG('console option', AOption);
   Result := True;
   Result := True;
@@ -216,27 +214,17 @@ begin
     begin
     begin
       Val(System.Copy(AOption, 13, Length(AOption)-12), tmp, tmp2);
       Val(System.Copy(AOption, 13, Length(AOption)-12), tmp, tmp2);
       case tmp of
       case tmp of
-        8: tmpformat := TPTCFormat.Create(8);
-        16: tmpformat := TPTCFormat.Create(16, $F800, $07E0, $001F);
-        24: tmpformat := TPTCFormat.Create(24, $00FF0000, $0000FF00, $000000FF);
-        32: tmpformat := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
+        8: FDefaultFormat := TPTCFormat.Create(8);
+        16: FDefaultFormat := TPTCFormat.Create(16, $F800, $07E0, $001F);
+        24: FDefaultFormat := TPTCFormat.Create(24, $00FF0000, $0000FF00, $000000FF);
+        32: FDefaultFormat := TPTCFormat.Create(32, $00FF0000, $0000FF00, $000000FF);
         else
         else
           exit(False);
           exit(False);
       end;
       end;
-      try
-        FDefaultFormat.Assign(tmpformat);
-      finally
-        tmpformat.Free;
-      end;
     end
     end
     else
     else
     begin
     begin
-      tmpformat := DEFAULT_FORMAT;
-      try
-        FDefaultFormat.Assign(tmpformat);
-      finally
-        tmpformat.Free;
-      end;
+      FDefaultFormat := DEFAULT_FORMAT;
     end;
     end;
   end;
   end;
   if AOption = 'resizable window' then
   if AOption = 'resizable window' then
@@ -393,7 +381,7 @@ begin
   Result := FCopy.Option(AOption);
   Result := FCopy.Option(AOption);
 end;
 end;
 
 
-function TDirectXConsole.Modes: PPTCMode;
+function TDirectXConsole.Modes: TPTCModeList;
 begin
 begin
   Result := FDisplay.Modes;
   Result := FDisplay.Modes;
 end;
 end;
@@ -403,27 +391,23 @@ begin
   Open(ATitle, FDefaultFormat, APages);
   Open(ATitle, FDefaultFormat, APages);
 end;
 end;
 
 
-procedure TDirectXConsole.Open(const ATitle: string; const AFormat: TPTCFormat;
+procedure TDirectXConsole.Open(const ATitle: string; AFormat: IPTCFormat;
                            APages: Integer = 0);
                            APages: Integer = 0);
 begin
 begin
   Open(ATitle, FDefaultWidth, FDefaultHeight, AFormat, APages);
   Open(ATitle, FDefaultWidth, FDefaultHeight, AFormat, APages);
 end;
 end;
 
 
 procedure TDirectXConsole.Open(const ATitle: string; AWidth, AHeight: Integer;
 procedure TDirectXConsole.Open(const ATitle: string; AWidth, AHeight: Integer;
-                           const AFormat: TPTCFormat; APages: Integer = 0);
+                           AFormat: IPTCFormat; APages: Integer = 0);
 var
 var
-  m: TPTCMode;
+  mode: IPTCMode;
 begin
 begin
   { internal open nearest mode }
   { internal open nearest mode }
-  m := TPTCMode.Create(AWidth, AHeight, AFormat);
-  try
-    internal_open(ATitle, 0, m, APages, False);
-  finally
-    m.Free;
-  end;
+  mode := TPTCMode.Create(AWidth, AHeight, AFormat);
+  internal_open(ATitle, 0, mode, APages, False);
 end;
 end;
 
 
-procedure TDirectXConsole.Open(const ATitle: string; const AMode: TPTCMode;
+procedure TDirectXConsole.Open(const ATitle: string; AMode: IPTCMode;
                            APages: Integer = 0);
                            APages: Integer = 0);
 begin
 begin
   { internal open exact mode }
   { internal open exact mode }
@@ -489,20 +473,19 @@ begin
   FWindow.Update;
   FWindow.Update;
 end;
 end;
 
 
-procedure TDirectXConsole.Update(const AArea: TPTCArea);
+procedure TDirectXConsole.Update(AArea: IPTCArea);
 begin
 begin
   { update }
   { update }
   Update;
   Update;
 end;
 end;
 
 
-function TDirectXConsole.NextEvent(var AEvent: TPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
+function TDirectXConsole.NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
 var
 var
   UseGetMessage: Boolean;
   UseGetMessage: Boolean;
 begin
 begin
   CHECK_OPEN('TDirectXConsole.NextEvent');
   CHECK_OPEN('TDirectXConsole.NextEvent');
 //  CHECK_LOCK('TDirectXConsole.NextEvent');
 //  CHECK_LOCK('TDirectXConsole.NextEvent');
 
 
-  FreeAndNil(AEvent);
   UseGetMessage := False;
   UseGetMessage := False;
   repeat
   repeat
     FPrimary.Block;
     FPrimary.Block;
@@ -518,7 +501,7 @@ begin
   Result := AEvent <> nil;
   Result := AEvent <> nil;
 end;
 end;
 
 
-function TDirectXConsole.PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): TPTCEvent;
+function TDirectXConsole.PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent;
 var
 var
   UseGetMessage: Boolean;
   UseGetMessage: Boolean;
 begin
 begin
@@ -539,7 +522,7 @@ begin
   until (not AWait) or (Result <> nil);
   until (not AWait) or (Result <> nil);
 end;
 end;
 
 
-procedure TDirectXConsole.Copy(ASurface: TPTCBaseSurface);
+procedure TDirectXConsole.Copy(ASurface: IPTCSurface);
 var
 var
   pixels: Pointer;
   pixels: Pointer;
 begin
 begin
@@ -558,8 +541,8 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure TDirectXConsole.Copy(ASurface: TPTCBaseSurface;
-                           const ASource, ADestination: TPTCArea);
+procedure TDirectXConsole.Copy(ASurface: IPTCSurface;
+                               ASource, ADestination: IPTCArea);
 var
 var
   pixels: Pointer;
   pixels: Pointer;
 begin
 begin
@@ -608,10 +591,9 @@ end;
 
 
 procedure TDirectXConsole.Load(const APixels: Pointer;
 procedure TDirectXConsole.Load(const APixels: Pointer;
                            AWidth, AHeight, APitch: Integer;
                            AWidth, AHeight, APitch: Integer;
-                           const AFormat: TPTCFormat;
-                           const APalette: TPTCPalette);
+                           AFormat: IPTCFormat;
+                           APalette: IPTCPalette);
 var
 var
-  Area_: TPTCArea;
   console_pixels: Pointer;
   console_pixels: Pointer;
 begin
 begin
   CHECK_OPEN('TDirectXConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette)');
   CHECK_OPEN('TDirectXConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette)');
@@ -636,66 +618,44 @@ begin
     end;
     end;
   end
   end
   else
   else
-  begin
-    Area_ := TPTCArea.Create(0, 0, Width, Height);
-    try
-      Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, Area_, area);
-    finally
-      Area_.Free;
-    end;
-  end;
+    Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, TPTCArea.Create(0, 0, Width, Height), area);
 end;
 end;
 
 
 procedure TDirectXConsole.Load(const APixels: Pointer;
 procedure TDirectXConsole.Load(const APixels: Pointer;
                                AWidth, AHeight, APitch: Integer;
                                AWidth, AHeight, APitch: Integer;
-                               const AFormat: TPTCFormat;
-                               const APalette: TPTCPalette;
-                               const ASource, ADestination: TPTCArea);
+                               AFormat: IPTCFormat;
+                               APalette: IPTCPalette;
+                               ASource, ADestination: IPTCArea);
 var
 var
   console_pixels: Pointer;
   console_pixels: Pointer;
-  clipped_source, clipped_destination: TPTCArea;
-  tmp: TPTCArea;
+  clipped_source, clipped_destination: IPTCArea;
 begin
 begin
   CHECK_OPEN('TDirectXConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
   CHECK_OPEN('TDirectXConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
   CHECK_LOCK('TDirectXConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
   CHECK_LOCK('TDirectXConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
-  clipped_destination := nil;
-  clipped_source := TPTCArea.Create;
+  console_pixels := Lock;
   try
   try
-    clipped_destination := TPTCArea.Create;
-    console_pixels := Lock;
     try
     try
-      try
-        tmp := TPTCArea.Create(0, 0, AWidth, AHeight);
-        try
-          TPTCClipper.clip(ASource, tmp, clipped_source, ADestination, Clip, clipped_destination);
-        finally
-          tmp.Free;
-        end;
-        FCopy.Request(AFormat, Format);
-        FCopy.Palette(APalette, Palette);
-        FCopy.Copy(APixels, clipped_source.Left, clipped_source.Top, clipped_source.Width, clipped_source.Height, APitch,
-                    console_pixels, clipped_destination.Left, clipped_destination.Top, clipped_destination.Width, clipped_destination.Height, Pitch);
-      except
-        on error:TPTCError do
-        begin
-          raise TPTCError.Create('failed to load pixels to console area', error);
-        end;
+      TPTCClipper.Clip(ASource, TPTCArea.Create(0, 0, AWidth, AHeight), clipped_source, ADestination, Clip, clipped_destination);
+      FCopy.Request(AFormat, Format);
+      FCopy.Palette(APalette, Palette);
+      FCopy.Copy(APixels, clipped_source.Left, clipped_source.Top, clipped_source.Width, clipped_source.Height, APitch,
+                 console_pixels, clipped_destination.Left, clipped_destination.Top, clipped_destination.Width, clipped_destination.Height, Pitch);
+    except
+      on error:TPTCError do
+      begin
+        raise TPTCError.Create('failed to load pixels to console area', error);
       end;
       end;
-    finally
-      Unlock;
     end;
     end;
   finally
   finally
-    clipped_source.Free;
-    clipped_destination.Free;
+    Unlock;
   end;
   end;
 end;
 end;
 
 
 procedure TDirectXConsole.Save(APixels: Pointer;
 procedure TDirectXConsole.Save(APixels: Pointer;
                                AWidth, AHeight, APitch: Integer;
                                AWidth, AHeight, APitch: Integer;
-                               const AFormat: TPTCFormat;
-                               const APalette: TPTCPalette);
+                               AFormat: IPTCFormat;
+                               APalette: IPTCPalette);
 var
 var
-  Area_: TPTCArea;
   console_pixels: Pointer;
   console_pixels: Pointer;
 begin
 begin
   CHECK_OPEN('TDirectXConsole.Save(APixels, AWidth, AHeight, APitch, AFormat, APalette)');
   CHECK_OPEN('TDirectXConsole.Save(APixels, AWidth, AHeight, APitch, AFormat, APalette)');
@@ -720,112 +680,82 @@ begin
     end;
     end;
   end
   end
   else
   else
-  begin
-    Area_ := TPTCArea.Create(0, 0, Width, Height);
-    try
-      Save(APixels, AWidth, AHeight, APitch, AFormat, APalette, Area, Area_);
-    finally
-      Area_.Free;
-    end;
-  end;
+    Save(APixels, AWidth, AHeight, APitch, AFormat, APalette, Area, TPTCArea.Create(0, 0, Width, Height));
 end;
 end;
 
 
 procedure TDirectXConsole.Save(APixels: Pointer;
 procedure TDirectXConsole.Save(APixels: Pointer;
                            AWidth, AHeight, APitch: Integer;
                            AWidth, AHeight, APitch: Integer;
-                           const AFormat: TPTCFormat;
-                           const APalette: TPTCPalette;
-                           const ASource, ADestination: TPTCArea);
+                           AFormat: IPTCFormat;
+                           APalette: IPTCPalette;
+                           ASource, ADestination: IPTCArea);
 var
 var
   console_pixels: Pointer;
   console_pixels: Pointer;
-  clipped_source, clipped_destination: TPTCArea;
-  tmp: TPTCArea;
+  clipped_source, clipped_destination: IPTCArea;
 begin
 begin
   CHECK_OPEN('TDirectXConsole.Save(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
   CHECK_OPEN('TDirectXConsole.Save(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
   CHECK_LOCK('TDirectXConsole.Save(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
   CHECK_LOCK('TDirectXConsole.Save(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
-  clipped_destination := nil;
-  clipped_source := TPTCArea.Create;
+  console_pixels := Lock;
   try
   try
-    clipped_destination := TPTCArea.Create;
-    console_pixels := Lock;
     try
     try
-      try
-        tmp := TPTCArea.Create(0, 0, AWidth, AHeight);
-        try
-          TPTCClipper.Clip(ASource, Clip, clipped_source, ADestination, tmp, clipped_destination);
-        finally
-          tmp.Free;
-        end;
-        FCopy.Request(Format, AFormat);
-        FCopy.Palette(Palette, APalette);
-        FCopy.Copy(console_pixels, clipped_source.Left, clipped_source.Top, clipped_source.Width, clipped_source.Height, Pitch,
-                    APixels, clipped_destination.Left, clipped_destination.Top, clipped_destination.Width, clipped_destination.Height, APitch);
-      except
-        on error:TPTCError do
-        begin
-          raise TPTCError.Create('failed to save console area pixels', error);
-        end;
+      TPTCClipper.Clip(ASource, Clip, clipped_source, ADestination, TPTCArea.Create(0, 0, AWidth, AHeight), clipped_destination);
+      FCopy.Request(Format, AFormat);
+      FCopy.Palette(Palette, APalette);
+      FCopy.Copy(console_pixels, clipped_source.Left, clipped_source.Top, clipped_source.Width, clipped_source.Height, Pitch,
+                 APixels, clipped_destination.Left, clipped_destination.Top, clipped_destination.Width, clipped_destination.Height, APitch);
+    except
+      on error:TPTCError do
+      begin
+        raise TPTCError.Create('failed to save console area pixels', error);
       end;
       end;
-    finally
-      Unlock;
     end;
     end;
   finally
   finally
-    clipped_source.Free;
-    clipped_destination.Free;
+    Unlock;
   end;
   end;
 end;
 end;
 
 
 procedure TDirectXConsole.Clear;
 procedure TDirectXConsole.Clear;
 var
 var
-  tmp: TPTCColor;
+  Color: IPTCColor;
 begin
 begin
   CHECK_OPEN('TDirectXConsole.Clear');
   CHECK_OPEN('TDirectXConsole.Clear');
   CHECK_LOCK('TDirectXConsole.Clear');
   CHECK_LOCK('TDirectXConsole.Clear');
   if format.direct then
   if format.direct then
-    tmp := TPTCColor.Create(0, 0, 0, 0)
+    Color := TPTCColor.Create(0, 0, 0, 0)
   else
   else
-    tmp := TPTCColor.Create(0);
-  try
-    Clear(tmp);
-  finally
-    tmp.Free;
-  end;
+    Color := TPTCColor.Create(0);
+  Clear(Color);
 end;
 end;
 
 
-procedure TDirectXConsole.Clear(const AColor: TPTCColor);
+procedure TDirectXConsole.Clear(AColor: IPTCColor);
 var
 var
   tmp: TPTCArea;
   tmp: TPTCArea;
 begin
 begin
   CHECK_OPEN('TDirectXConsole.Clear(AColor)');
   CHECK_OPEN('TDirectXConsole.Clear(AColor)');
   CHECK_LOCK('TDirectXConsole.Clear(AColor)');
   CHECK_LOCK('TDirectXConsole.Clear(AColor)');
-  tmp := TPTCArea.Create;
-  try
-    Clear(AColor, tmp);
-  finally
-    tmp.Free;
-  end;
+  Clear(AColor, TPTCArea.Create);
 end;
 end;
 
 
-procedure TDirectXConsole.Clear(const AColor: TPTCColor;
-                                const AArea: TPTCArea);
+procedure TDirectXConsole.Clear(AColor: IPTCColor;
+                                AArea: IPTCArea);
 begin
 begin
   CHECK_OPEN('TDirectXConsole.Clear(AColor, AArea)');
   CHECK_OPEN('TDirectXConsole.Clear(AColor, AArea)');
   CHECK_LOCK('TDirectXConsole.Clear(AColor, AArea)');
   CHECK_LOCK('TDirectXConsole.Clear(AColor, AArea)');
   FPrimary.Clear(AColor, AArea);
   FPrimary.Clear(AColor, AArea);
 end;
 end;
 
 
-procedure TDirectXConsole.palette(const APalette: TPTCPalette);
+procedure TDirectXConsole.palette(APalette: IPTCPalette);
 begin
 begin
   CHECK_OPEN('TDirectXConsole.Palette(APalette)');
   CHECK_OPEN('TDirectXConsole.Palette(APalette)');
   FPrimary.Palette(APalette);
   FPrimary.Palette(APalette);
 end;
 end;
 
 
-function TDirectXConsole.Palette: TPTCPalette;
+function TDirectXConsole.Palette: IPTCPalette;
 begin
 begin
   CHECK_OPEN('TDirectXConsole.Palette');
   CHECK_OPEN('TDirectXConsole.Palette');
   Result := FPrimary.palette;
   Result := FPrimary.palette;
 end;
 end;
 
 
-procedure TDirectXConsole.Clip(const AArea: TPTCArea);
+procedure TDirectXConsole.Clip(AArea: IPTCArea);
 begin
 begin
   CHECK_OPEN('TDirectXConsole.Clip(AArea)');
   CHECK_OPEN('TDirectXConsole.Clip(AArea)');
   FPrimary.Clip(AArea);
   FPrimary.Clip(AArea);
@@ -855,19 +785,19 @@ begin
   Result := FPrimary.pages;
   Result := FPrimary.pages;
 end;
 end;
 
 
-function TDirectXConsole.GetArea: TPTCArea;
+function TDirectXConsole.GetArea: IPTCArea;
 begin
 begin
   CHECK_OPEN('TDirectXConsole.GetArea');
   CHECK_OPEN('TDirectXConsole.GetArea');
-  Result := FPrimary.area;
+  Result := FPrimary.Area;
 end;
 end;
 
 
-function TDirectXConsole.Clip: TPTCArea;
+function TDirectXConsole.Clip: IPTCArea;
 begin
 begin
   CHECK_OPEN('TDirectXConsole.Clip');
   CHECK_OPEN('TDirectXConsole.Clip');
-  Result := FPrimary.clip;
+  Result := FPrimary.Clip;
 end;
 end;
 
 
-function TDirectXConsole.GetFormat: TPTCFormat;
+function TDirectXConsole.GetFormat: IPTCFormat;
 begin
 begin
   CHECK_OPEN('TDirectXConsole.GetFormat');
   CHECK_OPEN('TDirectXConsole.GetFormat');
   Result := FPrimary.format;
   Result := FPrimary.format;
@@ -890,10 +820,10 @@ begin
   Result := FDisplay.information;
   Result := FDisplay.information;
 end;
 end;
 
 
-procedure TDirectXConsole.internal_open(const _title: string; window: HWND; const mode: TPTCMode; _pages: Integer; exact: Boolean);
+procedure TDirectXConsole.internal_open(const _title: string; window: HWND; const mode: IPTCMode; _pages: Integer; exact: Boolean);
 var
 var
   _width, _height: Integer;
   _width, _height: Integer;
-  _format: TPTCFormat;
+  _format: IPTCFormat;
 begin
 begin
   try
   try
     { recycle an already open console }
     { recycle an already open console }
@@ -982,7 +912,7 @@ begin
   internal_open_finish;
   internal_open_finish;
 end;
 end;
 
 
-procedure TDirectXConsole.internal_recycle(const _title: string; window: HWND; const mode: TPTCMode; _pages: Integer; exact: Boolean);
+procedure TDirectXConsole.internal_recycle(const _title: string; window: HWND; const mode: IPTCMode; _pages: Integer; exact: Boolean);
 begin
 begin
   { Check if the console is open }
   { Check if the console is open }
   if not FOpen then
   if not FOpen then
@@ -1075,7 +1005,7 @@ begin
   FDisplay.restore;
   FDisplay.restore;
 end;
 end;
 
 
-procedure TDirectXConsole.internal_open_fullscreen_start(window: HWND; const mode: TPTCMode; exact: Boolean);
+procedure TDirectXConsole.internal_open_fullscreen_start(window: HWND; const mode: IPTCMode; exact: Boolean);
 begin
 begin
   FFullscreen := True;
   FFullscreen := True;
 
 
@@ -1118,13 +1048,13 @@ begin
   FDisplay.cooperative(FWindow.handle, True);
   FDisplay.cooperative(FWindow.handle, True);
 end;
 end;
 
 
-procedure TDirectXConsole.internal_open_fullscreen_change(const mode: TPTCMode; exact: Boolean);
+procedure TDirectXConsole.internal_open_fullscreen_change(const mode: IPTCMode; exact: Boolean);
 begin
 begin
   FDisplay.open(mode, exact, FFrequency);
   FDisplay.open(mode, exact, FFrequency);
   FPrimary.blocking(True);
   FPrimary.blocking(True);
 end;
 end;
 
 
-procedure TDirectXConsole.internal_open_fullscreen_surface(const mode: TPTCMode; _pages: Integer);
+procedure TDirectXConsole.internal_open_fullscreen_surface(const mode: IPTCMode; _pages: Integer);
 var
 var
   primary: Boolean;
   primary: Boolean;
   _secondary: Boolean;
   _secondary: Boolean;
@@ -1196,7 +1126,7 @@ begin
   FHook := TDirectXHook.Create(Self, FWindow.handle, GetCurrentThreadId, FCursor, FWindow.managed, True);
   FHook := TDirectXHook.Create(Self, FWindow.handle, GetCurrentThreadId, FCursor, FWindow.managed, True);
 end;
 end;
 
 
-procedure TDirectXConsole.internal_open_windowed_start(window: HWND; const mode: TPTCMode; exact: Boolean);
+procedure TDirectXConsole.internal_open_windowed_start(window: HWND; const mode: IPTCMode; exact: Boolean);
 var
 var
   extended: Integer;
   extended: Integer;
 begin
 begin
@@ -1226,7 +1156,7 @@ begin
   FDisplay.cooperative(FWindow.handle, False);
   FDisplay.cooperative(FWindow.handle, False);
 end;
 end;
 
 
-procedure TDirectXConsole.internal_open_windowed_change(const mode: TPTCMode; exact: Boolean);
+procedure TDirectXConsole.internal_open_windowed_change(const mode: IPTCMode; exact: Boolean);
 begin
 begin
   FDisplay.open;
   FDisplay.open;
   if FPrimaryModeWindowed = DIRECT then
   if FPrimaryModeWindowed = DIRECT then
@@ -1235,7 +1165,7 @@ begin
     FPrimary.blocking(False);
     FPrimary.blocking(False);
 end;
 end;
 
 
-procedure TDirectXConsole.internal_open_windowed_surface(const mode: TPTCMode; _pages: Integer);
+procedure TDirectXConsole.internal_open_windowed_surface(const mode: IPTCMode; _pages: Integer);
 begin
 begin
   FPrimary.initialize(FWindow, FLibrary.lpDD2);
   FPrimary.initialize(FWindow, FLibrary.lpDD2);
   FPrimary.primary(1, False, False, False, False);
   FPrimary.primary(1, False, False, False, False);
@@ -1251,7 +1181,7 @@ begin
   FHook := TDirectXHook.Create(Self, FWindow.handle, GetCurrentThreadId, FCursor, FWindow.managed, False);
   FHook := TDirectXHook.Create(Self, FWindow.handle, GetCurrentThreadId, FCursor, FWindow.managed, False);
 end;
 end;
 
 
-procedure TDirectXConsole.internal_recycle_fullscreen(const _title: string; window: HWND; const mode: TPTCMode; _pages: Integer; exact: Boolean);
+procedure TDirectXConsole.internal_recycle_fullscreen(const _title: string; window: HWND; const mode: IPTCMode; _pages: Integer; exact: Boolean);
 begin
 begin
   LOG('fullscreen open recycle');
   LOG('fullscreen open recycle');
   FPrimary.close;
   FPrimary.close;
@@ -1259,7 +1189,7 @@ begin
   internal_open_fullscreen_surface(mode, _pages);
   internal_open_fullscreen_surface(mode, _pages);
 end;
 end;
 
 
-procedure TDirectXConsole.internal_recycle_windowed(const _title: string; window: HWND; const mode: TPTCMode; _pages: Integer; exact: Boolean);
+procedure TDirectXConsole.internal_recycle_windowed(const _title: string; window: HWND; const mode: IPTCMode; _pages: Integer; exact: Boolean);
 begin
 begin
   LOG('windowed open recycle');
   LOG('windowed open recycle');
   FPrimary.close;
   FPrimary.close;

+ 89 - 143
packages/ptc/src/win32/directx/display.inc

@@ -33,7 +33,6 @@
 constructor TDirectXDisplay.Create;
 constructor TDirectXDisplay.Create;
 begin
 begin
   FInformation := '';
   FInformation := '';
-  FMode := nil;
   FCursorsaved := False;
   FCursorsaved := False;
   FOpen := False;
   FOpen := False;
   FFullscreen := False;
   FFullscreen := False;
@@ -42,43 +41,31 @@ begin
 //  FForeground := 0;
 //  FForeground := 0;
 //  FillChar(FModes, SizeOf(FModes), 0);
 //  FillChar(FModes, SizeOf(FModes), 0);
 //  FillChar(FResolutions, SizeOf(FResolutions), 0);
 //  FillChar(FResolutions, SizeOf(FResolutions), 0);
-  FMode := TPTCMode.Create;
 end;
 end;
 
 
 destructor TDirectXDisplay.Destroy;
 destructor TDirectXDisplay.Destroy;
 begin
 begin
   close;
   close;
-  FMode.Free;
   internal_dispose_modes;
   internal_dispose_modes;
   internal_dispose_resolutions;
   internal_dispose_resolutions;
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
 procedure TDirectXDisplay.internal_dispose_modes;
 procedure TDirectXDisplay.internal_dispose_modes;
-var
-  i: Integer;
 begin
 begin
-  for i := Low(FModes) to High(FModes) do
-    FreeAndNil(FModes[i]);
-
   SetLength(FModes, 0);
   SetLength(FModes, 0);
   FModesCount := 0;
   FModesCount := 0;
 end;
 end;
 
 
 procedure TDirectXDisplay.internal_dispose_resolutions;
 procedure TDirectXDisplay.internal_dispose_resolutions;
-var
-  i: Integer;
 begin
 begin
-  for i := Low(FResolutions) to High(FResolutions) do
-    FreeAndNil(FResolutions[i]);
-
   SetLength(FResolutions, 0);
   SetLength(FResolutions, 0);
 end;
 end;
 
 
 function TDirectXDisplay_callback(descriptor: PDDSurfaceDesc {TODO: TDDSurfaceDesc vs. TDDSurfaceDesc2???}; Context: Pointer): HRESULT; stdcall;
 function TDirectXDisplay_callback(descriptor: PDDSurfaceDesc {TODO: TDDSurfaceDesc vs. TDDSurfaceDesc2???}; Context: Pointer): HRESULT; stdcall;
 var
 var
   display: TDirectXDisplay;
   display: TDirectXDisplay;
-  tmp: TPTCFormat;
+  format: IPTCFormat;
 begin
 begin
   if (descriptor = nil) or (Context = nil) then
   if (descriptor = nil) or (Context = nil) then
   begin
   begin
@@ -90,15 +77,11 @@ begin
      ((descriptor^.dwFlags and DDSD_HEIGHT) <> 0) and
      ((descriptor^.dwFlags and DDSD_HEIGHT) <> 0) and
      ((descriptor^.dwFlags and DDSD_PIXELFORMAT) <> 0) then
      ((descriptor^.dwFlags and DDSD_PIXELFORMAT) <> 0) then
   begin
   begin
-    tmp := DirectXTranslate(descriptor^.ddpfPixelFormat);
-    try
-      Inc(display.FModesCount);
-      SetLength(display.FModes, display.FModesCount);
-      display.FModes[display.FModesCount - 1] :=
-        TPTCMode.Create(descriptor^.dwWidth, descriptor^.dwHeight, tmp);
-    finally
-      tmp.Free;
-    end;
+    format := DirectXTranslate(descriptor^.ddpfPixelFormat);
+    Inc(display.FModesCount);
+    SetLength(display.FModes, display.FModesCount);
+    display.FModes[display.FModesCount - 1] :=
+      TPTCMode.Create(descriptor^.dwWidth, descriptor^.dwHeight, format);
   end
   end
   else
   else
   begin
   begin
@@ -112,8 +95,8 @@ var
   version: TOSVERSIONINFO;
   version: TOSVERSIONINFO;
   match, found: Boolean;
   match, found: Boolean;
   i, j: Integer;
   i, j: Integer;
-  temp: TPTCMode;
-  temp2: TPTCFormat;
+  tempMode: IPTCMode;
+  format8: IPTCFormat;
 begin
 begin
   LOG('setting up display lpDD2');
   LOG('setting up display lpDD2');
   FDDraw := ADDraw;
   FDDraw := ADDraw;
@@ -127,36 +110,32 @@ begin
     if version.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS then
     if version.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS then
     begin
     begin
       LOG('detected windows 95/98');
       LOG('detected windows 95/98');
-      temp2 := TPTCFormat.Create(8);
-      try
-        found := False;
-        for i := 0 to FModesCount - 1 do
-          if (FModes[i].Width = 320) and (FModes[i].Height = 200) and
-              FModes[i].Format.Equals(temp2) then
-            found := True;
-        if not found then
-        begin
-          LOG('adding 320x200x8 to mode list');
-	  
-	  Inc(FModesCount);
-          SetLength(FModes, FModesCount);
-          FModes[FModesCount - 1] := TPTCMode.Create(320, 200, temp2);
-        end;
-        found := False;
-        for i := 0 to FModesCount - 1 do
-          if (FModes[i].Width = 320) and (FModes[i].Height = 240) and
-              FModes[i].Format.Equals(temp2) then
-            found := True;
-        if not found then
-        begin
-          LOG('adding 320x240x8 to mode list');
+      format8 := TPTCFormat.Create(8);
+      found := False;
+      for i := 0 to FModesCount - 1 do
+        if (FModes[i].Width = 320) and (FModes[i].Height = 200) and
+            FModes[i].Format.Equals(format8) then
+          found := True;
+      if not found then
+      begin
+        LOG('adding 320x200x8 to mode list');
+	
+	Inc(FModesCount);
+        SetLength(FModes, FModesCount);
+        FModes[FModesCount - 1] := TPTCMode.Create(320, 200, format8);
+      end;
+      found := False;
+      for i := 0 to FModesCount - 1 do
+        if (FModes[i].Width = 320) and (FModes[i].Height = 240) and
+            FModes[i].Format.Equals(format8) then
+          found := True;
+      if not found then
+      begin
+        LOG('adding 320x240x8 to mode list');
 
 
-	  Inc(FModesCount);
-          SetLength(FModes, FModesCount);
-          FModes[FModesCount - 1] := TPTCMode.Create(320, 240, temp2);
-        end;
-      finally
-        temp2.Free;
+	Inc(FModesCount);
+        SetLength(FModes, FModesCount);
+        FModes[FModesCount - 1] := TPTCMode.Create(320, 240, format8);
       end;
       end;
     end
     end
     else
     else
@@ -167,9 +146,6 @@ begin
   end;
   end;
   LOG('number of display modes', FModesCount);
   LOG('number of display modes', FModesCount);
 
 
-  SetLength(FModes, FModesCount + 1);
-  FModes[FModesCount] := TPTCMode.Create;
-  
   internal_dispose_resolutions;
   internal_dispose_resolutions;
   for i := 0 to FModesCount - 1 do
   for i := 0 to FModesCount - 1 do
   begin
   begin
@@ -185,11 +161,9 @@ begin
     begin
     begin
       Inc(FResolutionsCount);
       Inc(FResolutionsCount);
       SetLength(FResolutions, FResolutionsCount);
       SetLength(FResolutions, FResolutionsCount);
-      FResolutions[FResolutionsCount - 1] := TPTCMode.Create(FModes[i]);
+      FResolutions[FResolutionsCount - 1] := FModes[i];
     end;
     end;
   end;
   end;
-  SetLength(FResolutions, FResolutionsCount + 1);
-  FResolutions[FResolutionsCount] := TPTCMode.Create;
 
 
   { kludge sort... :) }
   { kludge sort... :) }
   for i := 0 to FResolutionsCount - 1 do
   for i := 0 to FResolutionsCount - 1 do
@@ -197,9 +171,9 @@ begin
       if (FResolutions[i].Width > FResolutions[j].Width) or
       if (FResolutions[i].Width > FResolutions[j].Width) or
          (FResolutions[i].Height > FResolutions[j].Height) then
          (FResolutions[i].Height > FResolutions[j].Height) then
       begin
       begin
-        temp := FResolutions[i];
+        tempMode := FResolutions[i];
         FResolutions[i] := FResolutions[j];
         FResolutions[i] := FResolutions[j];
-        FResolutions[j] := temp;
+        FResolutions[j] := tempMode;
       end;
       end;
   LOG('number of unique resolutions', FResolutionsCount);
   LOG('number of unique resolutions', FResolutionsCount);
   for i := 0 to FResolutionsCount - 1 do
   for i := 0 to FResolutionsCount - 1 do
@@ -208,12 +182,12 @@ begin
   end;
   end;
 end;
 end;
 
 
-function TDirectXDisplay.GetModes: PPTCMode;
+function TDirectXDisplay.GetModes: TPTCModeList;
 begin
 begin
-  Result := @FModes[0];
+  Result := FModes;
 end;
 end;
 
 
-function TDirectXDisplay.Test(const AMode: TPTCMode; AExact: Boolean): Boolean;
+function TDirectXDisplay.Test(const AMode: IPTCMode; AExact: Boolean): Boolean;
 var
 var
   i: Integer;
   i: Integer;
 begin
 begin
@@ -271,7 +245,7 @@ begin
   LOG('opening windowed display');
   LOG('opening windowed display');
 end;
 end;
 
 
-procedure TDirectXDisplay.Open(const AMode: TPTCMode; AExact: Boolean; AFrequency: Integer);
+procedure TDirectXDisplay.Open(const AMode: IPTCMode; AExact: Boolean; AFrequency: Integer);
 begin
 begin
   if AExact then
   if AExact then
   begin
   begin
@@ -338,7 +312,7 @@ begin
   End;}
   End;}
 end;
 end;
 
 
-procedure TDirectXDisplay.internal_open(const AMode: TPTCMode; AExact: Boolean; AFrequency: Integer);
+procedure TDirectXDisplay.internal_open(const AMode: IPTCMode; AExact: Boolean; AFrequency: Integer);
 begin
 begin
   LOG('internal display open');
   LOG('internal display open');
   LOG('mode width', AMode.Width);
   LOG('mode width', AMode.Width);
@@ -381,25 +355,20 @@ begin
         raise TPTCError.Create('unsupported pixel format');
         raise TPTCError.Create('unsupported pixel format');
     end;
     end;
   LOG('internal display open success');
   LOG('internal display open success');
-  FreeAndNil(FMode);
   FMode := TPTCMode.Create(AMode);
   FMode := TPTCMode.Create(AMode);
   FOpen := True;
   FOpen := True;
 end;
 end;
 
 
-procedure TDirectXDisplay.internal_open_nearest(const AMode: TPTCMode; AExact: Boolean; AFrequency: Integer);
+procedure TDirectXDisplay.internal_open_nearest(const AMode: IPTCMode; AExact: Boolean; AFrequency: Integer);
 
 
   function Pass2TryMode(TryWidth, TryHeight: Integer): Boolean;
   function Pass2TryMode(TryWidth, TryHeight: Integer): Boolean;
   var
   var
-    tmp: TPTCMode;
+    tmpMode: IPTCMode;
   begin
   begin
     if (AMode.Width <= TryWidth) and (AMode.Height <= TryHeight) then
     if (AMode.Width <= TryWidth) and (AMode.Height <= TryHeight) then
     try
     try
-      tmp := TPTCMode.Create(TryWidth, TryHeight, AMode.Format);
-      try
-        internal_open(tmp, AExact, AFrequency);
-      finally
-        tmp.Free;
-      end;
+      tmpMode := TPTCMode.Create(TryWidth, TryHeight, AMode.Format);
+      internal_open(tmpMode, AExact, AFrequency);
       exit(true);
       exit(true);
     except
     except
       on TPTCError do;
       on TPTCError do;
@@ -409,8 +378,7 @@ procedure TDirectXDisplay.internal_open_nearest(const AMode: TPTCMode; AExact: B
 
 
 var
 var
   index: Integer;
   index: Integer;
-  match, match_exact: TPTCMode;
-  tmp: TPTCMode;
+  match, match_exact: IPTCMode;
   i: Integer;
   i: Integer;
   width, height: Integer;
   width, height: Integer;
   dx1, dy1, dx2, dy2: Integer;
   dx1, dy1, dx2, dy2: Integer;
@@ -420,87 +388,65 @@ begin
     LOG('searching for nearest mode in resolutions list');
     LOG('searching for nearest mode in resolutions list');
     index := 0;
     index := 0;
     match_exact := nil;
     match_exact := nil;
-    match := TPTCMode.Create;
-    try
-      match_exact := TPTCMode.Create;
-      for i := 0 to FResolutionsCount - 1 do
+    match := nil;
+    for i := 0 to FResolutionsCount - 1 do
+    begin
+      width := FResolutions[i].Width;
+      height := FResolutions[i].Height;
+      if (AMode.Width <= width) and (AMode.Height <= height) then
       begin
       begin
-        width := FResolutions[i].Width;
-        height := FResolutions[i].Height;
-        if (AMode.Width <= width) and (AMode.Height <= height) then
+        if (width = AMode.Width) and (height = AMode.Height) then
         begin
         begin
-          if (width = AMode.Width) and (height = AMode.Height) then
-          begin
-            LOG('found an exact match');
-            tmp := TPTCMode.Create(width, height, AMode.Format);
-            try
-              match_exact.Assign(tmp);
-            finally
-              tmp.Free;
-            end;
-          end;
-          if match.valid then
-          begin
-            dx1 := match.Width - AMode.Width;
-            dy1 := match.Height - AMode.Height;
-            dx2 := width - AMode.Width;
-            dy2 := height - AMode.Height;
-            if (dx2 <= dx1) and (dy2 <= dy1) then
-            begin
-              LOG('found a better nearest match');
-              tmp := TPTCMode.Create(width, height, AMode.Format);
-              try
-                match.Assign(tmp);
-              finally
-                tmp.Free;
-              end;
-            end;
-          end
-          else
+          LOG('found an exact match');
+          match_exact := TPTCMode.Create(width, height, AMode.Format);
+        end;
+        if match <> nil then
+        begin
+          dx1 := match.Width - AMode.Width;
+          dy1 := match.Height - AMode.Height;
+          dx2 := width - AMode.Width;
+          dy2 := height - AMode.Height;
+          if (dx2 <= dx1) and (dy2 <= dy1) then
           begin
           begin
-            LOG('found first nearest match');
-            tmp := TPTCMode.Create(width, height, AMode.Format);
-            try
-              match.Assign(tmp);
-            finally
-              tmp.Free;
-            end;
+            LOG('found a better nearest match');
+            match := TPTCMode.Create(width, height, AMode.Format);
           end;
           end;
         end
         end
         else
         else
         begin
         begin
-{          LOG('stopping nearest mode search');
-          Break;}
+          LOG('found first nearest match');
+          match := TPTCMode.Create(width, height, AMode.Format);
         end;
         end;
+      end
+      else
+      begin
+{        LOG('stopping nearest mode search');
+        Break;}
       end;
       end;
+    end;
 
 
-      if match_exact.valid then
-      try
-        LOG('trying an exact match');
-        internal_open(match_exact, AExact, AFrequency);
-        exit;
-      except
-        on TPTCError do;
-      end;
-      if match.valid then
-      try
-        LOG('trying nearest match');
-        internal_open(match, AExact, AFrequency);
-        exit;
-      except
-        on TPTCError do;
-      end;
-    finally
-      match.Free;
-      match_exact.Free;
+    if match_exact <> nil then
+    try
+      LOG('trying an exact match');
+      internal_open(match_exact, AExact, AFrequency);
+      exit;
+    except
+      on TPTCError do;
+    end;
+    if match <> nil then
+    try
+      LOG('trying nearest match');
+      internal_open(match, AExact, AFrequency);
+      exit;
+    except
+      on TPTCError do;
     end;
     end;
   end
   end
   else
   else
   begin
   begin
     LOG('no resolutions list for nearest mode search');
     LOG('no resolutions list for nearest mode search');
   end;
   end;
-{  match.Free;
-  match_exact.Free;}
+
   LOG('could not find a nearest match in first pass');
   LOG('could not find a nearest match in first pass');
   try
   try
     LOG('trying requested mode first');
     LOG('trying requested mode first');

+ 10 - 10
packages/ptc/src/win32/directx/displayd.inc

@@ -35,13 +35,13 @@ type
   private
   private
     FOpen: Boolean;
     FOpen: Boolean;
     FFullscreen: Boolean;
     FFullscreen: Boolean;
-    FMode: TPTCMode;
+    FMode: IPTCMode;
     FWindow: HWND;
     FWindow: HWND;
     FDDraw: IDirectDraw2;
     FDDraw: IDirectDraw2;
     FModesCount: Integer;
     FModesCount: Integer;
     FResolutionsCount: Integer;
     FResolutionsCount: Integer;
-    FModes: array of TPTCMode;
-    FResolutions: array of TPTCMode;
+    FModes: array of IPTCMode;
+    FResolutions: array of IPTCMode;
     FInformation: string;
     FInformation: string;
 
 
     FCursorSaved: Boolean;
     FCursorSaved: Boolean;
@@ -50,25 +50,25 @@ type
     FForegroundRect: RECT;
     FForegroundRect: RECT;
     FForegroundPlacement: WINDOWPLACEMENT;}
     FForegroundPlacement: WINDOWPLACEMENT;}
 
 
-    procedure internal_open(const AMode: TPTCMode; AExact: Boolean; AFrequency: Integer);
-    procedure internal_open_nearest(const AMode: TPTCMode; AExact: Boolean; AFrequency: Integer);
+    procedure internal_open(const AMode: IPTCMode; AExact: Boolean; AFrequency: Integer);
+    procedure internal_open_nearest(const AMode: IPTCMode; AExact: Boolean; AFrequency: Integer);
     procedure internal_dispose_modes;
     procedure internal_dispose_modes;
     procedure internal_dispose_resolutions;
     procedure internal_dispose_resolutions;
 
 
-    function GetModes: PPTCMode;
+    function GetModes: TPTCModeList;
   public
   public
     constructor Create;
     constructor Create;
     destructor Destroy; override;
     destructor Destroy; override;
     procedure Setup(const ADDraw: IDirectDraw2);
     procedure Setup(const ADDraw: IDirectDraw2);
-    function Test(const AMode: TPTCMode; AExact: Boolean): Boolean;
+    function Test(const AMode: IPTCMode; AExact: Boolean): Boolean;
     procedure Cooperative(AWindow: HWND; AFullscreen: Boolean);
     procedure Cooperative(AWindow: HWND; AFullscreen: Boolean);
     procedure Open;
     procedure Open;
-    procedure Open(const AMode: TPTCMode; AExact: Boolean; AFrequency: Integer);
+    procedure Open(const AMode: IPTCMode; AExact: Boolean; AFrequency: Integer);
     procedure Close;
     procedure Close;
     procedure Save;
     procedure Save;
     procedure Restore;
     procedure Restore;
-    property Modes: PPTCMode read GetModes;
-    property Mode: TPTCMode read FMode;
+    property Modes: TPTCModeList read GetModes;
+    property Mode: IPTCMode read FMode;
     property Fullscreen: Boolean read FFullscreen;
     property Fullscreen: Boolean read FFullscreen;
     property Information: string read FInformation;
     property Information: string read FInformation;
   end;
   end;

+ 1 - 1
packages/ptc/src/win32/directx/hook.inc

@@ -73,7 +73,7 @@ begin
 
 
       { get window message data }
       { get window message data }
       active := wParam <> 0;
       active := wParam <> 0;
-      thread := lParam;
+      thread := DWord(lParam);
 
 
       { check active flag }
       { check active flag }
       if active = False then
       if active = False then

+ 30 - 83
packages/ptc/src/win32/directx/primary.inc

@@ -49,11 +49,7 @@ destructor TDirectXPrimary.Destroy;
 begin
 begin
   { close }
   { close }
   Close;
   Close;
-  FArea.Free;
-  FClip.Free;
-  FFormat.Free;
   FClear.Free;
   FClear.Free;
-  FPalette.Free;
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
@@ -71,7 +67,6 @@ var
   descriptor: TDDSURFACEDESC;
   descriptor: TDDSURFACEDESC;
   ddpf: TDDPIXELFORMAT;
   ddpf: TDDPIXELFORMAT;
   capabilities: TDDSCAPS;
   capabilities: TDDSCAPS;
-  tmp: TPTCPalette;
   I: Integer;
   I: Integer;
   rectangle: TRECT;
   rectangle: TRECT;
 begin
 begin
@@ -132,7 +127,6 @@ begin
     FPages := APages;
     FPages := APages;
     FWidth := descriptor.dwWidth;
     FWidth := descriptor.dwWidth;
     FHeight := descriptor.dwHeight;
     FHeight := descriptor.dwHeight;
-    FreeAndNil(FFormat);
     FFormat := DirectXTranslate(ddpf);
     FFormat := DirectXTranslate(ddpf);
     LOG('primary width', FWidth);
     LOG('primary width', FWidth);
     LOG('primary height', FHeight);
     LOG('primary height', FHeight);
@@ -141,12 +135,7 @@ begin
     if APalette then
     if APalette then
     begin
     begin
       LOG('clearing primary palette');
       LOG('clearing primary palette');
-      tmp := TPTCPalette.Create;
-      try
-        palette(tmp);
-      finally
-        tmp.Free;
-      end;
+      palette(TPTCPalette.Create);
     end;
     end;
     if attach_primary_pages then
     if attach_primary_pages then
     begin
     begin
@@ -189,9 +178,7 @@ begin
       FWidth := rectangle.right;
       FWidth := rectangle.right;
       FHeight := rectangle.bottom;
       FHeight := rectangle.bottom;
     end;
     end;
-    FreeAndNil(FArea);
     FArea := TPTCArea.Create(0, 0, FWidth, FHeight);
     FArea := TPTCArea.Create(0, 0, FWidth, FHeight);
-    FreeAndNil(FClip);
     FClip := TPTCArea.Create(FArea);
     FClip := TPTCArea.Create(FArea);
     if APages > 1 then
     if APages > 1 then
     begin
     begin
@@ -275,9 +262,7 @@ begin
   end;
   end;
   FWidth := AWidth;
   FWidth := AWidth;
   FHeight := AHeight;
   FHeight := AHeight;
-  FreeAndNil(FArea);
   FArea := TPTCArea.Create(0, 0, FWidth, FHeight);
   FArea := TPTCArea.Create(0, 0, FWidth, FHeight);
-  FreeAndNil(FClip);
   FClip := TPTCArea.Create(FArea);
   FClip := TPTCArea.Create(FArea);
   FSecondaryWidth := FWidth;
   FSecondaryWidth := FWidth;
   FSecondaryHeight := FHeight;
   FSecondaryHeight := FHeight;
@@ -334,7 +319,6 @@ procedure TDirectXPrimary.Close;
 var
 var
   i: Integer;
   i: Integer;
   lost: Boolean;
   lost: Boolean;
-  tmp: TPTCPalette;
 begin
 begin
   try
   try
     LOG('closing primary surface');
     LOG('closing primary surface');
@@ -345,13 +329,7 @@ begin
       lost := True;
       lost := True;
     if (FBack <> nil) and (FDDSPrimary <> nil) and FFullscreen and (not lost) then
     if (FBack <> nil) and (FDDSPrimary <> nil) and FFullscreen and (not lost) then
     begin
     begin
-      tmp := TPTCPalette.Create;
-      try
-        LOG('clearing primary palette');
-        palette(tmp);
-      finally
-        tmp.Free;
-      end;
+      palette(TPTCPalette.Create);
       LOG('clearing primary pages');
       LOG('clearing primary pages');
       for i := 0 to FPages - 1 do
       for i := 0 to FPages - 1 do
       begin
       begin
@@ -443,7 +421,6 @@ end;
 procedure TDirectXPrimary.Clear;
 procedure TDirectXPrimary.Clear;
 var
 var
   fx: TDDBLTFX;
   fx: TDDBLTFX;
-  tmp: TPTCColor;
 begin
 begin
   Block;
   Block;
   if FFullscreen or (FBack = FDDSSecondary) then
   if FFullscreen or (FBack = FDDSSecondary) then
@@ -456,29 +433,15 @@ begin
   begin
   begin
     { todo: replace with hardware clear! }
     { todo: replace with hardware clear! }
     if Format.Direct then
     if Format.Direct then
-    begin
-      tmp := TPTCColor.Create(0, 0, 0, 0);
-      try
-        Clear(tmp, FArea);
-      finally
-        tmp.Free;
-      end;
-    end
+      Clear(TPTCColor.Create(0, 0, 0, 0), FArea)
     else
     else
-    begin
-      tmp := TPTCColor.Create(0);
-      try
-        Clear(tmp, FArea);
-      finally
-        tmp.Free;
-      end;
-    end;
+      Clear(TPTCColor.Create(0), FArea);
   end;
   end;
 end;
 end;
 
 
-procedure TDirectXPrimary.Clear(const AColor: TPTCColor; const AArea: TPTCArea);
+procedure TDirectXPrimary.Clear(AColor: IPTCColor; const AArea: IPTCArea);
 var
 var
-  clipped, clipped_area: TPTCArea;
+  clipped, clipped_area: IPTCArea;
   clear_color: DWord;
   clear_color: DWord;
   rct: RECT;
   rct: RECT;
   fx: TDDBLTFX;
   fx: TDDBLTFX;
@@ -488,47 +451,38 @@ begin
   if FFullscreen or (FBack = FDDSSecondary) then
   if FFullscreen or (FBack = FDDSSecondary) then
   begin
   begin
     clipped := TPTCClipper.clip(AArea, FClip);
     clipped := TPTCClipper.clip(AArea, FClip);
-    try
-      clear_color := Pack(AColor, FFormat);
-      with rct do
-      begin
-        left := clipped.left;
-        top := clipped.top;
-        right := clipped.right;
-        bottom := clipped.bottom;
-      end;
-      fx.dwSize := SizeOf(fx);
-      fx.dwFillColor := clear_color;
-      DirectXCheck(FBack.Blt(@rct, nil, nil, DDBLT_COLORFILL or DDBLT_WAIT, @fx), 'FBack.Blt(rect) failed in TDirectXPrimary.Clear');
-    finally
-      clipped.Free;
+    clear_color := Pack(AColor, FFormat);
+    with rct do
+    begin
+      left := clipped.left;
+      top := clipped.top;
+      right := clipped.right;
+      bottom := clipped.bottom;
     end;
     end;
+    fx.dwSize := SizeOf(fx);
+    fx.dwFillColor := clear_color;
+    DirectXCheck(FBack.Blt(@rct, nil, nil, DDBLT_COLORFILL or DDBLT_WAIT, @fx), 'FBack.Blt(rect) failed in TDirectXPrimary.Clear');
   end
   end
   else
   else
   begin
   begin
     { todo: replace with accelerated clearing code! }
     { todo: replace with accelerated clearing code! }
     pixels := Lock;
     pixels := Lock;
-    clipped_area := nil;
     try
     try
-      try
-        clipped_area := TPTCClipper.clip(AArea, Clip);
-        FClear.Request(Format);
-        FClear.Clear(pixels, clipped_area.left, clipped_area.right, clipped_area.width, clipped_area.height, Pitch, AColor);
+      clipped_area := TPTCClipper.clip(AArea, Clip);
+      FClear.Request(Format);
+      FClear.Clear(pixels, clipped_area.left, clipped_area.right, clipped_area.width, clipped_area.height, Pitch, AColor);
+      Unlock;
+    except
+      on error: TPTCError do
+      begin
         Unlock;
         Unlock;
-      except
-        on error: TPTCError do
-        begin
-          Unlock;
-          raise TPTCError.Create('failed to clear console area', error);
-        end;
+        raise TPTCError.Create('failed to clear console area', error);
       end;
       end;
-    finally
-      clipped_area.Free;
     end;
     end;
   end;
   end;
 end;
 end;
 
 
-procedure TDirectXPrimary.Palette(const APalette: TPTCPalette);
+procedure TDirectXPrimary.Palette(APalette: IPTCPalette);
 var
 var
   data: PUint32;
   data: PUint32;
   temp: array [0..255] of PALETTEENTRY;
   temp: array [0..255] of PALETTEENTRY;
@@ -562,16 +516,9 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure TDirectXPrimary.Clip(const AArea: TPTCArea);
-var
-  tmp: TPTCArea;
+procedure TDirectXPrimary.Clip(const AArea: IPTCArea);
 begin
 begin
-  tmp := TPTCClipper.clip(AArea, FArea);
-  try
-    FClip.Assign(tmp);
-  finally
-    tmp.Free;
-  end;
+  FClip := TPTCClipper.clip(AArea, FArea);
 end;
 end;
 
 
 function TDirectXPrimary.GetPitch: Integer;
 function TDirectXPrimary.GetPitch: Integer;
@@ -799,7 +746,7 @@ begin
   FBlocking := ABlocking;
   FBlocking := ABlocking;
 end;
 end;
 
 
-function TDirectXPrimary.Pack(const AColor: TPTCColor; const AFormat: TPTCFormat): Uint32;
+function TDirectXPrimary.Pack(const AColor: IPTCColor; const AFormat: IPTCFormat): Uint32;
 var
 var
   r_base, g_base, b_base, a_base: Integer;
   r_base, g_base, b_base, a_base: Integer;
   r_size, g_size, b_size, a_size: Integer;
   r_size, g_size, b_size, a_size: Integer;
@@ -845,12 +792,12 @@ begin
   end;
   end;
 end;
 end;
 
 
-function TDirectXPrimary.Palette: TPTCPalette;
+function TDirectXPrimary.Palette: IPTCPalette;
 begin
 begin
   Result := FPalette;
   Result := FPalette;
 end;
 end;
 
 
-function TDirectXPrimary.Clip: TPTCArea;
+function TDirectXPrimary.Clip: IPTCArea;
 begin
 begin
   Result := FClip;
   Result := FClip;
 end;
 end;

+ 12 - 12
packages/ptc/src/win32/directx/primaryd.inc

@@ -36,9 +36,9 @@ type
     FWidth: Integer;
     FWidth: Integer;
     FHeight: Integer;
     FHeight: Integer;
     FPages: Integer;
     FPages: Integer;
-    FArea: TPTCArea;
-    FClip: TPTCArea;
-    FFormat: TPTCFormat;
+    FArea: IPTCArea;
+    FClip: IPTCArea;
+    FFormat: IPTCFormat;
 
 
     FActive: Boolean;
     FActive: Boolean;
     FBlocking: Boolean;
     FBlocking: Boolean;
@@ -52,7 +52,7 @@ type
 
 
     FLocked: Pointer;
     FLocked: Pointer;
 
 
-    FPalette: TPTCPalette;
+    FPalette: IPTCPalette;
 
 
     FPrimaryWidth: Integer;
     FPrimaryWidth: Integer;
     FPrimaryHeight: Integer;
     FPrimaryHeight: Integer;
@@ -72,7 +72,7 @@ type
 
 
     FBack, FFront: IDirectDrawSurface;
     FBack, FFront: IDirectDrawSurface;
 
 
-    function Pack(const AColor: TPTCColor; const AFormat: TPTCFormat): Uint32;
+    function Pack(const AColor: IPTCColor; const AFormat: IPTCFormat): Uint32;
     procedure Analyse(AMask: Uint32; out ABase, ASize: Integer);
     procedure Analyse(AMask: Uint32; out ABase, ASize: Integer);
     function GetDDS: IDirectDrawSurface;
     function GetDDS: IDirectDrawSurface;
     function GetPitch: Integer;
     function GetPitch: Integer;
@@ -93,20 +93,20 @@ type
     procedure Unlock;
     procedure Unlock;
 
 
     procedure Clear;
     procedure Clear;
-    procedure Clear(const AColor: TPTCColor; const AArea: TPTCArea);
+    procedure Clear(AColor: IPTCColor; const AArea: IPTCArea);
 
 
-    procedure Palette(const APalette: TPTCPalette);
-    function Palette: TPTCPalette;
+    procedure Palette(APalette: IPTCPalette);
+    function Palette: IPTCPalette;
 
 
-    procedure Clip(const AArea: TPTCArea);
+    procedure Clip(const AArea: IPTCArea);
 
 
     property Width: Integer read FWidth;
     property Width: Integer read FWidth;
     property Height: Integer read FHeight;
     property Height: Integer read FHeight;
     property Pages: Integer read FPages;
     property Pages: Integer read FPages;
     property Pitch: Integer read GetPitch;
     property Pitch: Integer read GetPitch;
-    property Area: TPTCArea read FArea;
-    function Clip: TPTCArea;
-    property Format: TPTCFormat read FFormat;
+    property Area: IPTCArea read FArea;
+    function Clip: IPTCArea;
+    property Format: IPTCFormat read FFormat;
 
 
     property DDS: IDirectDrawSurface read GetDDS;
     property DDS: IDirectDrawSurface read GetDDS;
     property DDSPrimary: IDirectDrawSurface read FDDSPrimary;
     property DDSPrimary: IDirectDrawSurface read FDDSPrimary;

+ 1 - 1
packages/ptc/src/win32/directx/translate.inc

@@ -30,7 +30,7 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 }
 }
 
 
-function DirectXTranslate(const ddpf: TDDPIXELFORMAT): TPTCFormat;
+function DirectXTranslate(const ddpf: TDDPIXELFORMAT): IPTCFormat;
 begin
 begin
   if (ddpf.dwFlags and DDPF_PALETTEINDEXED8) <> 0 then
   if (ddpf.dwFlags and DDPF_PALETTEINDEXED8) <> 0 then
     exit(TPTCFormat.Create(8))
     exit(TPTCFormat.Create(8))

+ 34 - 34
packages/ptc/src/win32/gdi/gdiconsoled.inc

@@ -41,10 +41,10 @@ type
     FCopy: TPTCCopy;
     FCopy: TPTCCopy;
     FClear: TPTCClear;
     FClear: TPTCClear;
     FEventQueue: TEventQueue;
     FEventQueue: TEventQueue;
-    FArea: TPTCArea;
-    FClip: TPTCArea;
-    FPalette: TPTCPalette;
-    FModes: array [0..1] of TPTCMode;
+    FArea: IPTCArea;
+    FClip: IPTCArea;
+    FPalette: IPTCPalette;
+    FModes: array of IPTCMode;
 
 
     FOpen: Boolean;
     FOpen: Boolean;
     FLocked: Boolean;
     FLocked: Boolean;
@@ -58,15 +58,15 @@ type
 
 
     FDefaultWidth: Integer;
     FDefaultWidth: Integer;
     FDefaultHeight: Integer;
     FDefaultHeight: Integer;
-    FDefaultFormat: TPTCFormat;
+    FDefaultFormat: IPTCFormat;
 
 
     procedure UpdateCursor;
     procedure UpdateCursor;
 
 
     function GetWidth: Integer; override;
     function GetWidth: Integer; override;
     function GetHeight: Integer; override;
     function GetHeight: Integer; override;
     function GetPitch: Integer; override;
     function GetPitch: Integer; override;
-    function GetArea: TPTCArea; override;
-    function GetFormat: TPTCFormat; override;
+    function GetArea: IPTCArea; override;
+    function GetFormat: IPTCFormat; override;
     function GetPages: Integer; override;
     function GetPages: Integer; override;
     function GetName: string; override;
     function GetName: string; override;
     function GetTitle: string; override;
     function GetTitle: string; override;
@@ -79,59 +79,59 @@ type
     destructor Destroy; override;
     destructor Destroy; override;
 
 
     procedure Open(const ATitle: string; APages: Integer = 0); overload; override;
     procedure Open(const ATitle: string; APages: Integer = 0); overload; override;
-    procedure Open(const ATitle: string; const AFormat: TPTCFormat;
+    procedure Open(const ATitle: string; AFormat: IPTCFormat;
                    APages: Integer = 0); overload; override;
                    APages: Integer = 0); overload; override;
     procedure Open(const ATitle: string; AWidth, AHeight: Integer;
     procedure Open(const ATitle: string; AWidth, AHeight: Integer;
-                   const AFormat: TPTCFormat; APages: Integer = 0); overload; override;
-    procedure Open(const ATitle: string; const AMode: TPTCMode;
+                   AFormat: IPTCFormat; APages: Integer = 0); overload; override;
+    procedure Open(const ATitle: string; AMode: IPTCMode;
                    APages: Integer = 0); overload; override;
                    APages: Integer = 0); overload; override;
     procedure Close; override;
     procedure Close; override;
 
 
-    procedure Copy(ASurface: TPTCBaseSurface); override;
-    procedure Copy(ASurface: TPTCBaseSurface;
-                   const ASource, ADestination: TPTCArea); override;
+    procedure Copy(ASurface: IPTCSurface); override;
+    procedure Copy(ASurface: IPTCSurface;
+                   ASource, ADestination: IPTCArea); override;
 
 
     procedure Load(const APixels: Pointer;
     procedure Load(const APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette); override;
     procedure Load(const APixels: Pointer;
     procedure Load(const APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea); override;
     procedure Save(APixels: Pointer;
     procedure Save(APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette); override;
     procedure Save(APixels: Pointer;
     procedure Save(APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea); override;
 
 
     function Lock: Pointer; override;
     function Lock: Pointer; override;
     procedure Unlock; override;
     procedure Unlock; override;
 
 
     procedure Clear; override;
     procedure Clear; override;
-    procedure Clear(const AColor: TPTCColor); override;
-    procedure Clear(const AColor: TPTCColor;
-                    const AArea: TPTCArea); override;
+    procedure Clear(AColor: IPTCColor); override;
+    procedure Clear(AColor: IPTCColor;
+                    AArea: IPTCArea); override;
 
 
     procedure Configure(const AFileName: String); override;
     procedure Configure(const AFileName: String); override;
     function Option(const AOption: String): Boolean; override;
     function Option(const AOption: String): Boolean; override;
 
 
-    procedure Palette(const APalette: TPTCPalette); override;
-    procedure Clip(const AArea: TPTCArea); override;
-    function Clip: TPTCArea; override;
-    function Palette: TPTCPalette; override;
-    function Modes: PPTCMode; override;
+    procedure Palette(APalette: IPTCPalette); override;
+    procedure Clip(AArea: IPTCArea); override;
+    function Clip: IPTCArea; override;
+    function Palette: IPTCPalette; override;
+    function Modes: TPTCModeList; override;
 
 
     procedure Flush; override;
     procedure Flush; override;
     procedure Finish; override;
     procedure Finish; override;
     procedure Update; override;
     procedure Update; override;
-    procedure Update(const AArea: TPTCArea); override;
+    procedure Update(AArea: IPTCArea); override;
 
 
-    function NextEvent(var AEvent: TPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; override;
-    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): TPTCEvent; override;
+    function NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; override;
+    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent; override;
   end;
   end;

+ 39 - 76
packages/ptc/src/win32/gdi/gdiconsolei.inc

@@ -50,8 +50,8 @@ begin
 
 
   FOpen := False;
   FOpen := False;
 
 
+  SetLength(FModes, 1);
   FModes[0] := TPTCMode.Create(FDisplayWidth, FDisplayHeight, FDefaultFormat);
   FModes[0] := TPTCMode.Create(FDisplayWidth, FDisplayHeight, FDefaultFormat);
-  FModes[1] := TPTCMode.Create;
 
 
   { configure console }
   { configure console }
   Configure('ptcpas.cfg');
   Configure('ptcpas.cfg');
@@ -67,16 +67,9 @@ begin
 
 
   FWin32DIB.Free;
   FWin32DIB.Free;
   FWindow.Free;
   FWindow.Free;
-  FPalette.Free;
   FEventQueue.Free;
   FEventQueue.Free;
   FCopy.Free;
   FCopy.Free;
   FClear.Free;
   FClear.Free;
-  FArea.Free;
-  FClip.Free;
-  FDefaultFormat.Free;
-
-  for I := Low(FModes) to High(FModes) do
-    FModes[I].Free;
 
 
   inherited Destroy;
   inherited Destroy;
 end;
 end;
@@ -86,22 +79,22 @@ begin
   Open(ATitle, FDefaultFormat, APages);
   Open(ATitle, FDefaultFormat, APages);
 end;
 end;
 
 
-procedure TGDIConsole.Open(const ATitle: string; const AFormat: TPTCFormat;
+procedure TGDIConsole.Open(const ATitle: string; AFormat: IPTCFormat;
                APages: Integer = 0);
                APages: Integer = 0);
 begin
 begin
   Open(ATitle, FDefaultWidth, FDefaultHeight, AFormat, APages);
   Open(ATitle, FDefaultWidth, FDefaultHeight, AFormat, APages);
 end;
 end;
 
 
-procedure TGDIConsole.Open(const ATitle: string; const AMode: TPTCMode;
+procedure TGDIConsole.Open(const ATitle: string; AMode: IPTCMode;
                            APages: Integer = 0);
                            APages: Integer = 0);
 begin
 begin
   Open(ATitle, AMode.Width, AMode.Height, AMode.Format, APages);
   Open(ATitle, AMode.Width, AMode.Height, AMode.Format, APages);
 end;
 end;
 
 
 procedure TGDIConsole.Open(const ATitle: string; AWidth, AHeight: Integer;
 procedure TGDIConsole.Open(const ATitle: string; AWidth, AHeight: Integer;
-               const AFormat: TPTCFormat; APages: Integer = 0);
+                           AFormat: IPTCFormat; APages: Integer = 0);
 var
 var
-  tmp: TPTCArea;
+  tmpArea: IPTCArea;
 begin
 begin
   if FOpen then
   if FOpen then
     Close;
     Close;
@@ -145,13 +138,9 @@ begin
   FKeyboard := TWin32Keyboard.Create(FWindow.Handle, FWindow.Thread, False, FEventQueue);
   FKeyboard := TWin32Keyboard.Create(FWindow.Handle, FWindow.Thread, False, FEventQueue);
   FMouse := TWin32Mouse.Create(FWindow.Handle, FWindow.Thread, False, FEventQueue, {FFullScreen}False, AWidth, AHeight);
   FMouse := TWin32Mouse.Create(FWindow.Handle, FWindow.Thread, False, FEventQueue, {FFullScreen}False, AWidth, AHeight);
 
 
-  tmp := TPTCArea.Create(0, 0, AWidth, AHeight);
-  try
-    FArea.Assign(tmp);
-    FClip.Assign(tmp);
-  finally
-    tmp.Free;
-  end;
+  tmpArea := TPTCArea.Create(0, 0, AWidth, AHeight);
+  FArea := tmpArea;
+  FClip := tmpArea;
 
 
   FWindow.Update;
   FWindow.Update;
 
 
@@ -180,23 +169,22 @@ begin
   FOpen := False;
   FOpen := False;
 end;
 end;
 
 
-procedure TGDIConsole.Copy(ASurface: TPTCBaseSurface);
+procedure TGDIConsole.Copy(ASurface: IPTCSurface);
 begin
 begin
   // todo...
   // todo...
 end;
 end;
 
 
-procedure TGDIConsole.Copy(ASurface: TPTCBaseSurface;
-                           const ASource, ADestination: TPTCArea);
+procedure TGDIConsole.Copy(ASurface: IPTCSurface;
+                           ASource, ADestination: IPTCArea);
 begin
 begin
   // todo...
   // todo...
 end;
 end;
 
 
 procedure TGDIConsole.Load(const APixels: Pointer;
 procedure TGDIConsole.Load(const APixels: Pointer;
                            AWidth, AHeight, APitch: Integer;
                            AWidth, AHeight, APitch: Integer;
-                           const AFormat: TPTCFormat;
-                           const APalette: TPTCPalette);
+                           AFormat: IPTCFormat;
+                           APalette: IPTCPalette);
 var
 var
-  Area_: TPTCArea;
   console_pixels: Pointer;
   console_pixels: Pointer;
 begin
 begin
   CheckOpen(    'TGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette)');
   CheckOpen(    'TGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette)');
@@ -219,49 +207,30 @@ begin
     end;
     end;
   end
   end
   else
   else
-  begin
-    Area_ := TPTCArea.Create(0, 0, width, height);
-    try
-      Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, Area_, Area);
-    finally
-      Area_.Free;
-    end;
-  end;
+    Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, TPTCArea.Create(0, 0, width, height), Area);
 end;
 end;
 
 
 procedure TGDIConsole.Load(const APixels: Pointer;
 procedure TGDIConsole.Load(const APixels: Pointer;
                            AWidth, AHeight, APitch: Integer;
                            AWidth, AHeight, APitch: Integer;
-                           const AFormat: TPTCFormat;
-                           const APalette: TPTCPalette;
-                           const ASource, ADestination: TPTCArea);
+                           AFormat: IPTCFormat;
+                           APalette: IPTCPalette;
+                           ASource, ADestination: IPTCArea);
 var
 var
   console_pixels: Pointer;
   console_pixels: Pointer;
-  clipped_source, clipped_destination: TPTCArea;
-  tmp: TPTCArea;
+  clipped_source, clipped_destination: IPTCArea;
 begin
 begin
   CheckOpen(    'TGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
   CheckOpen(    'TGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
   CheckUnlocked('TGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
   CheckUnlocked('TGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
-  clipped_source := nil;
-  clipped_destination := nil;
   try
   try
     console_pixels := Lock;
     console_pixels := Lock;
     try
     try
-      clipped_source := TPTCArea.Create;
-      clipped_destination := TPTCArea.Create;
-      tmp := TPTCArea.Create(0, 0, AWidth, AHeight);
-      try
-        TPTCClipper.Clip(ASource, tmp, clipped_source, ADestination, Clip, clipped_destination);
-      finally
-        tmp.Free;
-      end;
+      TPTCClipper.Clip(ASource, TPTCArea.Create(0, 0, AWidth, AHeight), clipped_source, ADestination, Clip, clipped_destination);
       FCopy.request(AFormat, Format);
       FCopy.request(AFormat, Format);
       FCopy.palette(APalette, Palette);
       FCopy.palette(APalette, Palette);
       FCopy.copy(APixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, APitch,
       FCopy.copy(APixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, APitch,
                  console_pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, Pitch);
                  console_pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, Pitch);
     finally
     finally
       Unlock;
       Unlock;
-      clipped_source.Free;
-      clipped_destination.Free;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do
@@ -271,17 +240,17 @@ end;
 
 
 procedure TGDIConsole.Save(APixels: Pointer;
 procedure TGDIConsole.Save(APixels: Pointer;
                            AWidth, AHeight, APitch: Integer;
                            AWidth, AHeight, APitch: Integer;
-                           const AFormat: TPTCFormat;
-                           const APalette: TPTCPalette);
+                           AFormat: IPTCFormat;
+                           APalette: IPTCPalette);
 begin
 begin
   // todo...
   // todo...
 end;
 end;
 
 
 procedure TGDIConsole.Save(APixels: Pointer;
 procedure TGDIConsole.Save(APixels: Pointer;
                            AWidth, AHeight, APitch: Integer;
                            AWidth, AHeight, APitch: Integer;
-                           const AFormat: TPTCFormat;
-                           const APalette: TPTCPalette;
-                           const ASource, ADestination: TPTCArea);
+                           AFormat: IPTCFormat;
+                           APalette: IPTCPalette;
+                           ASource, ADestination: IPTCArea);
 begin
 begin
   // todo...
   // todo...
 end;
 end;
@@ -327,13 +296,13 @@ begin
   // todo...
   // todo...
 end;
 end;
 
 
-procedure TGDIConsole.Clear(const AColor: TPTCColor);
+procedure TGDIConsole.Clear(AColor: IPTCColor);
 begin
 begin
   // todo...
   // todo...
 end;
 end;
 
 
-procedure TGDIConsole.Clear(const AColor: TPTCColor;
-                            const AArea: TPTCArea);
+procedure TGDIConsole.Clear(AColor: IPTCColor;
+                            AArea: IPTCArea);
 begin
 begin
   // todo...
   // todo...
 end;
 end;
@@ -397,40 +366,35 @@ begin
   Result := FCopy.Option(AOption);
   Result := FCopy.Option(AOption);
 end;
 end;
 
 
-procedure TGDIConsole.Palette(const APalette: TPTCPalette);
+procedure TGDIConsole.Palette(APalette: IPTCPalette);
 begin
 begin
   // todo...
   // todo...
 end;
 end;
 
 
-procedure TGDIConsole.Clip(const AArea: TPTCArea);
+procedure TGDIConsole.Clip(AArea: IPTCArea);
 var
 var
   tmp: TPTCArea;
   tmp: TPTCArea;
 begin
 begin
   CheckOpen('TGDIConsole.Clip(AArea)');
   CheckOpen('TGDIConsole.Clip(AArea)');
 
 
-  tmp := TPTCClipper.Clip(AArea, FArea);
-  try
-    FClip.Assign(tmp);
-  finally
-    tmp.Free;
-  end;
+  FClip := TPTCClipper.Clip(AArea, FArea);
 end;
 end;
 
 
-function TGDIConsole.Clip: TPTCArea;
+function TGDIConsole.Clip: IPTCArea;
 begin
 begin
   CheckOpen('TGDIConsole.Clip');
   CheckOpen('TGDIConsole.Clip');
   Result := FClip;
   Result := FClip;
 end;
 end;
 
 
-function TGDIConsole.Palette: TPTCPalette;
+function TGDIConsole.Palette: IPTCPalette;
 begin
 begin
   CheckOpen('TGDIConsole.Palette');
   CheckOpen('TGDIConsole.Palette');
   Result := FPalette;
   Result := FPalette;
 end;
 end;
 
 
-function TGDIConsole.Modes: PPTCMode;
+function TGDIConsole.Modes: TPTCModeList;
 begin
 begin
-  Result := @FModes[0];
+  Result := FModes;
 end;
 end;
 
 
 procedure TGDIConsole.Flush;
 procedure TGDIConsole.Flush;
@@ -478,19 +442,18 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure TGDIConsole.Update(const AArea: TPTCArea);
+procedure TGDIConsole.Update(AArea: IPTCArea);
 begin
 begin
   Update;
   Update;
 end;
 end;
 
 
-function TGDIConsole.NextEvent(var AEvent: TPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
+function TGDIConsole.NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
 var
 var
   UseGetMessage: Boolean;
   UseGetMessage: Boolean;
 begin
 begin
   CheckOpen('TGDIConsole.NextEvent');
   CheckOpen('TGDIConsole.NextEvent');
 //  CheckUnlocked('TGDIConsole.NextEvent');
 //  CheckUnlocked('TGDIConsole.NextEvent');
 
 
-  FreeAndNil(AEvent);
   UseGetMessage := False;
   UseGetMessage := False;
   repeat
   repeat
     { update window }
     { update window }
@@ -504,7 +467,7 @@ begin
   Result := AEvent <> nil;
   Result := AEvent <> nil;
 end;
 end;
 
 
-function TGDIConsole.PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): TPTCEvent;
+function TGDIConsole.PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent;
 var
 var
   UseGetMessage: Boolean;
   UseGetMessage: Boolean;
 begin
 begin
@@ -541,13 +504,13 @@ begin
   Result := FWin32DIB.Pitch;
   Result := FWin32DIB.Pitch;
 end;
 end;
 
 
-function TGDIConsole.GetArea: TPTCArea;
+function TGDIConsole.GetArea: IPTCArea;
 begin
 begin
   CheckOpen('TGDIConsole.GetArea');
   CheckOpen('TGDIConsole.GetArea');
   Result := FArea;
   Result := FArea;
 end;
 end;
 
 
-function TGDIConsole.GetFormat: TPTCFormat;
+function TGDIConsole.GetFormat: IPTCFormat;
 begin
 begin
   CheckOpen('TGDIConsole.GetFormat');
   CheckOpen('TGDIConsole.GetFormat');
   Result := FWin32DIB.Format;
   Result := FWin32DIB.Format;

+ 2 - 2
packages/ptc/src/win32/gdi/win32dibd.inc

@@ -34,7 +34,7 @@ type
   private
   private
     FBitmapInfo: PBITMAPINFO;
     FBitmapInfo: PBITMAPINFO;
     FPixels: Pointer;
     FPixels: Pointer;
-    FFormat: TPTCFormat;
+    FFormat: IPTCFormat;
     FWidth, FHeight, FPitch: Integer;
     FWidth, FHeight, FPitch: Integer;
   public
   public
     constructor Create(AWidth, AHeight: Integer);
     constructor Create(AWidth, AHeight: Integer);
@@ -43,6 +43,6 @@ type
     property Width: Integer read FWidth;
     property Width: Integer read FWidth;
     property Height: Integer read FHeight;
     property Height: Integer read FHeight;
     property Pitch: Integer read FPitch;
     property Pitch: Integer read FPitch;
-    property Format: TPTCFormat read FFormat;
+    property Format: IPTCFormat read FFormat;
     property Pixels: Pointer read FPixels;
     property Pixels: Pointer read FPixels;
   end;
   end;

+ 0 - 1
packages/ptc/src/win32/gdi/win32dibi.inc

@@ -69,6 +69,5 @@ destructor TWin32DIB.Destroy;
 begin
 begin
   FreeMem(FPixels);
   FreeMem(FPixels);
   FreeMem(FBitmapInfo);
   FreeMem(FBitmapInfo);
-  FFormat.Free;
   inherited Destroy;
   inherited Destroy;
 end;
 end;

+ 38 - 38
packages/ptc/src/wince/gapi/wincegapiconsoled.inc

@@ -30,7 +30,7 @@
 }
 }
 
 
 type
 type
-  TWinCEGAPIConsole = Class(TPTCBaseConsole)
+  TWinCEGAPIConsole = class(TPTCBaseConsole)
   private
   private
     FWindow: TWinCEWindow;
     FWindow: TWinCEWindow;
     FKeyboard: TWinCEKeyboard;
     FKeyboard: TWinCEKeyboard;
@@ -40,10 +40,10 @@ type
 
 
     FCopy: TPTCCopy;
     FCopy: TPTCCopy;
     FClear: TPTCClear;
     FClear: TPTCClear;
-    FArea: TPTCArea;
-    FClip: TPTCArea;
+    FArea: IPTCArea;
+    FClip: IPTCArea;
     FEventQueue: TEventQueue;
     FEventQueue: TEventQueue;
-    FModes: array [0..1] of TPTCMode;
+    FModes: array of IPTCMode;
 
 
     FOpen: Boolean;
     FOpen: Boolean;
     FLocked: Boolean;
     FLocked: Boolean;
@@ -55,80 +55,80 @@ type
     FDisplayWidth: Integer;
     FDisplayWidth: Integer;
     FDisplayHeight: Integer;
     FDisplayHeight: Integer;
     FDisplayPitch: Integer;
     FDisplayPitch: Integer;
-    FDisplayFormat: TPTCFormat;
+    FDisplayFormat: IPTCFormat;
 
 
     function WndProc(Ahwnd: HWND; AuMsg: UINT; AwParam: WPARAM; AlParam: LPARAM): LRESULT;
     function WndProc(Ahwnd: HWND; AuMsg: UINT; AwParam: WPARAM; AlParam: LPARAM): LRESULT;
 
 
     function GetWidth: Integer; override;
     function GetWidth: Integer; override;
     function GetHeight: Integer; override;
     function GetHeight: Integer; override;
     function GetPitch: Integer; override;
     function GetPitch: Integer; override;
-    function GetArea: TPTCArea; override;
-    function GetFormat: TPTCFormat; override;
+    function GetArea: IPTCArea; override;
+    function GetFormat: IPTCFormat; override;
     function GetPages: Integer; override;
     function GetPages: Integer; override;
     function GetName: string; override;
     function GetName: string; override;
     function GetTitle: string; override;
     function GetTitle: string; override;
     function GetInformation: string; override;
     function GetInformation: string; override;
 
 
-    procedure CheckOpen(    AMessage: String);
-    procedure CheckUnlocked(AMessage: String);
+    procedure CheckOpen(    AMessage: string);
+    procedure CheckUnlocked(AMessage: string);
   public
   public
     constructor Create; override;
     constructor Create; override;
     destructor Destroy; override;
     destructor Destroy; override;
 
 
     procedure Open(const ATitle: string; APages: Integer = 0); overload; override;
     procedure Open(const ATitle: string; APages: Integer = 0); overload; override;
-    procedure Open(const ATitle: string; const AFormat: TPTCFormat;
+    procedure Open(const ATitle: string; AFormat: IPTCFormat;
                    APages: Integer = 0); overload; override;
                    APages: Integer = 0); overload; override;
     procedure Open(const ATitle: string; AWidth, AHeight: Integer;
     procedure Open(const ATitle: string; AWidth, AHeight: Integer;
-                   const AFormat: TPTCFormat; APages: Integer = 0); overload; override;
-    procedure Open(const ATitle: string; const AMode: TPTCMode;
+                   AFormat: IPTCFormat; APages: Integer = 0); overload; override;
+    procedure Open(const ATitle: string; AMode: IPTCMode;
                    APages: Integer = 0); overload; override;
                    APages: Integer = 0); overload; override;
     procedure Close; override;
     procedure Close; override;
 
 
-    procedure Copy(ASurface: TPTCBaseSurface); override;
-    procedure Copy(ASurface: TPTCBaseSurface;
-                   const ASource, ADestination: TPTCArea); override;
+    procedure Copy(ASurface: IPTCSurface); override;
+    procedure Copy(ASurface: IPTCSurface;
+                   ASource, ADestination: IPTCArea); override;
 
 
     procedure Load(const APixels: Pointer;
     procedure Load(const APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette); override;
     procedure Load(const APixels: Pointer;
     procedure Load(const APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea); override;
     procedure Save(APixels: Pointer;
     procedure Save(APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette); override;
     procedure Save(APixels: Pointer;
     procedure Save(APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea); override;
 
 
     function Lock: Pointer; override;
     function Lock: Pointer; override;
     procedure Unlock; override;
     procedure Unlock; override;
 
 
     procedure Clear; override;
     procedure Clear; override;
-    procedure Clear(const AColor: TPTCColor); override;
-    procedure Clear(const AColor: TPTCColor;
-                    const AArea: TPTCArea); override;
+    procedure Clear(AColor: IPTCColor); override;
+    procedure Clear(AColor: IPTCColor;
+                    AArea: IPTCArea); override;
 
 
-    procedure Configure(const AFileName: String); override;
-    function Option(const AOption: String): Boolean; override;
+    procedure Configure(const AFileName: string); override;
+    function Option(const AOption: string): Boolean; override;
 
 
-    procedure Palette(const APalette: TPTCPalette); override;
-    procedure Clip(const AArea: TPTCArea); override;
-    function Clip: TPTCArea; override;
-    function Palette: TPTCPalette; override;
-    function Modes: PPTCMode; override;
+    procedure Palette(APalette: IPTCPalette); override;
+    procedure Clip(AArea: IPTCArea); override;
+    function Clip: IPTCArea; override;
+    function Palette: IPTCPalette; override;
+    function Modes: TPTCModeList; override;
 
 
     procedure Flush; override;
     procedure Flush; override;
     procedure Finish; override;
     procedure Finish; override;
     procedure Update; override;
     procedure Update; override;
-    procedure Update(const AArea: TPTCArea); override;
+    procedure Update(AArea: IPTCArea); override;
 
 
-    function NextEvent(var AEvent: TPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; override;
-    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): TPTCEvent; override;
+    function NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; override;
+    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent; override;
   end;
   end;

+ 41 - 130
packages/ptc/src/wince/gapi/wincegapiconsolei.inc

@@ -30,7 +30,6 @@
 }
 }
 
 
 constructor TWinCEGAPIConsole.Create;
 constructor TWinCEGAPIConsole.Create;
-
 begin
 begin
   inherited Create;
   inherited Create;
 
 
@@ -51,7 +50,6 @@ begin
   FDisplayWidth := FGXDisplayProperties.cxWidth;
   FDisplayWidth := FGXDisplayProperties.cxWidth;
   FDisplayHeight := FGXDisplayProperties.cyHeight;
   FDisplayHeight := FGXDisplayProperties.cyHeight;
   FDisplayPitch := FGXDisplayProperties.cbyPitch;
   FDisplayPitch := FGXDisplayProperties.cbyPitch;
-  FDisplayFormat := nil;
 
 
   if (FGXDisplayProperties.ffFormat and kfDirect565) <> 0 then
   if (FGXDisplayProperties.ffFormat and kfDirect565) <> 0 then
     FDisplayFormat := TPTCFormat.Create(FGXDisplayProperties.cBPP,
     FDisplayFormat := TPTCFormat.Create(FGXDisplayProperties.cBPP,
@@ -72,56 +70,39 @@ begin
   if FDisplayFormat = nil then
   if FDisplayFormat = nil then
     raise TPTCError.Create('GAPI: Unknown/unsupported pixel format');
     raise TPTCError.Create('GAPI: Unknown/unsupported pixel format');
 
 
+  SetLength(FModes, 1);
   FModes[0] := TPTCMode.Create(FDisplayWidth, FDisplayHeight, FDisplayFormat);
   FModes[0] := TPTCMode.Create(FDisplayWidth, FDisplayHeight, FDisplayFormat);
-  FModes[1] := TPTCMode.Create;
 end;
 end;
 
 
 destructor TWinCEGAPIConsole.Destroy;
 destructor TWinCEGAPIConsole.Destroy;
-
-var
-  I: Integer;
-
 begin
 begin
   Close;
   Close;
 
 
   FCopy.Free;
   FCopy.Free;
   FClear.Free;
   FClear.Free;
-  FArea.Free;
-  FClip.Free;
-  FDisplayFormat.Free;
-
-  for I := Low(FModes) to High(FModes) do
-    FModes[I].Free;
 
 
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
 procedure TWinCEGAPIConsole.Open(const ATitle: string; APages: Integer = 0);
 procedure TWinCEGAPIConsole.Open(const ATitle: string; APages: Integer = 0);
-
 begin
 begin
   Open(ATitle, FDisplayFormat, APages);
   Open(ATitle, FDisplayFormat, APages);
 end;
 end;
 
 
-procedure TWinCEGAPIConsole.Open(const ATitle: string; const AFormat: TPTCFormat;
+procedure TWinCEGAPIConsole.Open(const ATitle: string; AFormat: IPTCFormat;
                                  APages: Integer = 0);
                                  APages: Integer = 0);
-
 begin
 begin
   Open(ATitle, FDisplayWidth, FDisplayHeight, AFormat, APages);
   Open(ATitle, FDisplayWidth, FDisplayHeight, AFormat, APages);
 end;
 end;
 
 
-procedure TWinCEGAPIConsole.Open(const ATitle: string; const AMode: TPTCMode;
+procedure TWinCEGAPIConsole.Open(const ATitle: string; AMode: IPTCMode;
                                  APages: Integer = 0);
                                  APages: Integer = 0);
-
 begin
 begin
   Open(ATitle, AMode.Width, AMode.Height, AMode.Format, APages);
   Open(ATitle, AMode.Width, AMode.Height, AMode.Format, APages);
 end;
 end;
 
 
 procedure TWinCEGAPIConsole.Open(const ATitle: string; AWidth, AHeight: Integer;
 procedure TWinCEGAPIConsole.Open(const ATitle: string; AWidth, AHeight: Integer;
-                                 const AFormat: TPTCFormat; APages: Integer = 0);
-
-var
-  tmp: TPTCArea;
-
+                                 AFormat: IPTCFormat; APages: Integer = 0);
 begin
 begin
   LOG('TWinCEGAPIConsole.Open');
   LOG('TWinCEGAPIConsole.Open');
 
 
@@ -146,13 +127,8 @@ begin
     else
     else
       raise TPTCError.Create('could not open display');
       raise TPTCError.Create('could not open display');
 
 
-    tmp := TPTCArea.Create(0, 0, FDisplayWidth, FDisplayHeight);
-    try
-      FArea.Assign(tmp);
-      FClip.Assign(tmp);
-    finally
-      tmp.Free;
-    end;
+	FArea := TPTCArea.Create(0, 0, FDisplayWidth, FDisplayHeight);
+	FClip := FArea;
 
 
     FEventQueue := TEventQueue.Create;
     FEventQueue := TEventQueue.Create;
     FKeyboard := TWinCEKeyboard.Create(FEventQueue);
     FKeyboard := TWinCEKeyboard.Create(FEventQueue);
@@ -168,13 +144,12 @@ begin
     on error: TObject do
     on error: TObject do
     begin
     begin
       Close;
       Close;
-      Raise;
+      raise;
     end;
     end;
   end;
   end;
 end;
 end;
 
 
 procedure TWinCEGAPIConsole.Close;
 procedure TWinCEGAPIConsole.Close;
-
 begin
 begin
   LOG('TWinCEGAPIConsole.Close');
   LOG('TWinCEGAPIConsole.Close');
 
 
@@ -190,25 +165,21 @@ begin
   FOpen := False;
   FOpen := False;
 end;
 end;
 
 
-procedure TWinCEGAPIConsole.Copy(ASurface: TPTCBaseSurface);
-
+procedure TWinCEGAPIConsole.Copy(ASurface: IPTCSurface);
 begin
 begin
 end;
 end;
 
 
-procedure TWinCEGAPIConsole.Copy(ASurface: TPTCBaseSurface;
-                                 const ASource, ADestination: TPTCArea);
-
+procedure TWinCEGAPIConsole.Copy(ASurface: IPTCSurface;
+                                 ASource, ADestination: IPTCArea);
 begin
 begin
 end;
 end;
 
 
 procedure TWinCEGAPIConsole.Load(const APixels: Pointer;
 procedure TWinCEGAPIConsole.Load(const APixels: Pointer;
                                  AWidth, AHeight, APitch: Integer;
                                  AWidth, AHeight, APitch: Integer;
-                                 const AFormat: TPTCFormat;
-                                 const APalette: TPTCPalette);
+                                 AFormat: IPTCFormat;
+                                 APalette: IPTCPalette);
 var
 var
-  Area_: TPTCArea;
   console_pixels: Pointer;
   console_pixels: Pointer;
-
 begin
 begin
   CheckOpen(    'TWinCEGAPIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette)');
   CheckOpen(    'TWinCEGAPIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette)');
   CheckUnlocked('TWinCEGAPIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette)');
   CheckUnlocked('TWinCEGAPIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette)');
@@ -230,26 +201,17 @@ begin
     end;
     end;
   end
   end
   else
   else
-  begin
-    Area_ := TPTCArea.Create(0, 0, width, height);
-    try
-      Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, Area_, Area);
-    finally
-      Area_.Free;
-    end;
-  end;
+    Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, TPTCArea.Create(0, 0, width, height), Area);
 end;
 end;
 
 
 procedure TWinCEGAPIConsole.Load(const APixels: Pointer;
 procedure TWinCEGAPIConsole.Load(const APixels: Pointer;
                                  AWidth, AHeight, APitch: Integer;
                                  AWidth, AHeight, APitch: Integer;
-                                 const AFormat: TPTCFormat;
-                                 const APalette: TPTCPalette;
-                                 const ASource, ADestination: TPTCArea);
+                                 AFormat: IPTCFormat;
+                                 APalette: IPTCPalette;
+                                 ASource, ADestination: IPTCArea);
 var
 var
   console_pixels: Pointer;
   console_pixels: Pointer;
-  clipped_source, clipped_destination: TPTCArea;
-  tmp: TPTCArea;
-
+  clipped_source, clipped_destination: IPTCArea;
 begin
 begin
   CheckOpen(    'TWinCEGAPIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
   CheckOpen(    'TWinCEGAPIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
   CheckUnlocked('TWinCEGAPIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
   CheckUnlocked('TWinCEGAPIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
@@ -258,22 +220,13 @@ begin
   try
   try
     console_pixels := Lock;
     console_pixels := Lock;
     try
     try
-      clipped_source := TPTCArea.Create;
-      clipped_destination := TPTCArea.Create;
-      tmp := TPTCArea.Create(0, 0, AWidth, AHeight);
-      try
-        TPTCClipper.Clip(ASource, tmp, clipped_source, ADestination, Clip, clipped_destination);
-      finally
-        tmp.Free;
-      end;
+      TPTCClipper.Clip(ASource, TPTCArea.Create(0, 0, AWidth, AHeight), clipped_source, ADestination, Clip, clipped_destination);
       FCopy.request(AFormat, Format);
       FCopy.request(AFormat, Format);
       FCopy.palette(APalette, Palette);
       FCopy.palette(APalette, Palette);
       FCopy.copy(APixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, APitch,
       FCopy.copy(APixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, APitch,
                  console_pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, Pitch);
                  console_pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, Pitch);
     finally
     finally
       Unlock;
       Unlock;
-      clipped_source.Free;
-      clipped_destination.Free;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do
@@ -283,23 +236,20 @@ end;
 
 
 procedure TWinCEGAPIConsole.Save(APixels: Pointer;
 procedure TWinCEGAPIConsole.Save(APixels: Pointer;
                                  AWidth, AHeight, APitch: Integer;
                                  AWidth, AHeight, APitch: Integer;
-                                 const AFormat: TPTCFormat;
-                                 const APalette: TPTCPalette);
-
+                                 AFormat: IPTCFormat;
+                                 APalette: IPTCPalette);
 begin
 begin
 end;
 end;
 
 
 procedure TWinCEGAPIConsole.Save(APixels: Pointer;
 procedure TWinCEGAPIConsole.Save(APixels: Pointer;
                                  AWidth, AHeight, APitch: Integer;
                                  AWidth, AHeight, APitch: Integer;
-                                 const AFormat: TPTCFormat;
-                                 const APalette: TPTCPalette;
-                                 const ASource, ADestination: TPTCArea);
-
+                                 AFormat: IPTCFormat;
+                                 APalette: IPTCPalette;
+                                 ASource, ADestination: IPTCArea);
 begin
 begin
 end;
 end;
 
 
 function TWinCEGAPIConsole.Lock: Pointer;
 function TWinCEGAPIConsole.Lock: Pointer;
-
 begin
 begin
   CheckUnlocked('display already locked');
   CheckUnlocked('display already locked');
   Result := GXBeginDraw;
   Result := GXBeginDraw;
@@ -311,7 +261,6 @@ begin
 end;
 end;
 
 
 procedure TWinCEGAPIConsole.Unlock;
 procedure TWinCEGAPIConsole.Unlock;
-
 begin
 begin
   if not FLocked then
   if not FLocked then
     raise TPTCError.Create('display is not locked');
     raise TPTCError.Create('display is not locked');
@@ -323,27 +272,22 @@ begin
 end;
 end;
 
 
 procedure TWinCEGAPIConsole.Clear;
 procedure TWinCEGAPIConsole.Clear;
-
 begin
 begin
 end;
 end;
 
 
-procedure TWinCEGAPIConsole.Clear(const AColor: TPTCColor);
-
+procedure TWinCEGAPIConsole.Clear(AColor: IPTCColor);
 begin
 begin
 end;
 end;
 
 
-procedure TWinCEGAPIConsole.Clear(const AColor: TPTCColor;
-                    const AArea: TPTCArea);
-
+procedure TWinCEGAPIConsole.Clear(AColor: IPTCColor;
+                                  AArea: IPTCArea);
 begin
 begin
 end;
 end;
 
 
-procedure TWinCEGAPIConsole.Configure(const AFileName: String);
-
+procedure TWinCEGAPIConsole.Configure(const AFileName: string);
 var
 var
   F: Text;
   F: Text;
   S: string;
   S: string;
-
 begin
 begin
   AssignFile(F, AFileName);
   AssignFile(F, AFileName);
   {$push}{$I-}
   {$push}{$I-}
@@ -357,14 +301,13 @@ begin
     Readln(F, S);
     Readln(F, S);
     {$pop}
     {$pop}
     if IOResult <> 0 then
     if IOResult <> 0 then
-      Break;
+      break;
     Option(S);
     Option(S);
   end;
   end;
   CloseFile(F);
   CloseFile(F);
 end;
 end;
 
 
-function TWinCEGAPIConsole.Option(const AOption: String): Boolean;
-
+function TWinCEGAPIConsole.Option(const AOption: string): Boolean;
 begin
 begin
   LOG('console option', AOption);
   LOG('console option', AOption);
 
 
@@ -373,47 +316,33 @@ begin
   Result := FCopy.Option(AOption);
   Result := FCopy.Option(AOption);
 end;
 end;
 
 
-procedure TWinCEGAPIConsole.Palette(const APalette: TPTCPalette);
-
+procedure TWinCEGAPIConsole.Palette(APalette: IPTCPalette);
 begin
 begin
 end;
 end;
 
 
-procedure TWinCEGAPIConsole.Clip(const AArea: TPTCArea);
-
-var
-  tmp: TPTCArea;
-
+procedure TWinCEGAPIConsole.Clip(AArea: IPTCArea);
 begin
 begin
   CheckOpen('TWinCEGAPIConsole.Clip(AArea)');
   CheckOpen('TWinCEGAPIConsole.Clip(AArea)');
 
 
-  tmp := TPTCClipper.Clip(AArea, FArea);
-  try
-    FClip.Assign(tmp);
-  finally
-    tmp.Free;
-  end;
+  FClip := TPTCClipper.Clip(AArea, FArea);
 end;
 end;
 
 
-function TWinCEGAPIConsole.Clip: TPTCArea;
-
+function TWinCEGAPIConsole.Clip: IPTCArea;
 begin
 begin
   CheckOpen('TWinCEGAPIConsole.Clip');
   CheckOpen('TWinCEGAPIConsole.Clip');
   Result := FClip;
   Result := FClip;
 end;
 end;
 
 
-function TWinCEGAPIConsole.Palette: TPTCPalette;
-
+function TWinCEGAPIConsole.Palette: IPTCPalette;
 begin
 begin
 end;
 end;
 
 
-function TWinCEGAPIConsole.Modes: PPTCMode;
-
+function TWinCEGAPIConsole.Modes: TPTCModeList;
 begin
 begin
-  Result := @FModes[0];
+  Result := FModes;
 end;
 end;
 
 
 function TWinCEGAPIConsole.WndProc(Ahwnd: HWND; AuMsg: UINT; AwParam: WPARAM; AlParam: LPARAM): LRESULT;
 function TWinCEGAPIConsole.WndProc(Ahwnd: HWND; AuMsg: UINT; AwParam: WPARAM; AlParam: LPARAM): LRESULT;
-
 begin
 begin
   case AuMsg of
   case AuMsg of
   WM_CLOSE: begin
   WM_CLOSE: begin
@@ -458,7 +387,6 @@ begin
 end;
 end;
 
 
 procedure TWinCEGAPIConsole.Flush;
 procedure TWinCEGAPIConsole.Flush;
-
 begin
 begin
   CheckOpen    ('TWinCEGAPIConsole.Flush');
   CheckOpen    ('TWinCEGAPIConsole.Flush');
   CheckUnlocked('TWinCEGAPIConsole.Flush');
   CheckUnlocked('TWinCEGAPIConsole.Flush');
@@ -467,7 +395,6 @@ begin
 end;
 end;
 
 
 procedure TWinCEGAPIConsole.Finish;
 procedure TWinCEGAPIConsole.Finish;
-
 begin
 begin
   CheckOpen    ('TWinCEGAPIConsole.Finish');
   CheckOpen    ('TWinCEGAPIConsole.Finish');
   CheckUnlocked('TWinCEGAPIConsole.Finish');
   CheckUnlocked('TWinCEGAPIConsole.Finish');
@@ -476,7 +403,6 @@ begin
 end;
 end;
 
 
 procedure TWinCEGAPIConsole.Update;
 procedure TWinCEGAPIConsole.Update;
-
 begin
 begin
   CheckOpen    ('TWinCEGAPIConsole.Update');
   CheckOpen    ('TWinCEGAPIConsole.Update');
   CheckUnlocked('TWinCEGAPIConsole.Update');
   CheckUnlocked('TWinCEGAPIConsole.Update');
@@ -484,19 +410,16 @@ begin
   FWindow.Update;
   FWindow.Update;
 end;
 end;
 
 
-procedure TWinCEGAPIConsole.Update(const AArea: TPTCArea);
-
+procedure TWinCEGAPIConsole.Update(AArea: IPTCArea);
 begin
 begin
   Update;
   Update;
 end;
 end;
 
 
-function TWinCEGAPIConsole.NextEvent(var AEvent: TPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
-
+function TWinCEGAPIConsole.NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
 begin
 begin
   CheckOpen('TWinCEGAPIConsole.NextEvent');
   CheckOpen('TWinCEGAPIConsole.NextEvent');
 //  CheckUnlocked('TWinCEGAPIConsole.NextEvent');
 //  CheckUnlocked('TWinCEGAPIConsole.NextEvent');
 
 
-  FreeAndNil(AEvent);
   repeat
   repeat
     { update window }
     { update window }
     FWindow.Update;
     FWindow.Update;
@@ -507,8 +430,7 @@ begin
   Result := AEvent <> nil;
   Result := AEvent <> nil;
 end;
 end;
 
 
-function TWinCEGAPIConsole.PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): TPTCEvent;
-
+function TWinCEGAPIConsole.PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent;
 begin
 begin
   CheckOpen('TWinCEGAPIConsole.PeekEvent');
   CheckOpen('TWinCEGAPIConsole.PeekEvent');
 //  CheckUnlocked('TWinCEGAPIConsole.PeekEvent');
 //  CheckUnlocked('TWinCEGAPIConsole.PeekEvent');
@@ -523,68 +445,58 @@ begin
 end;
 end;
 
 
 function TWinCEGAPIConsole.GetWidth: Integer;
 function TWinCEGAPIConsole.GetWidth: Integer;
-
 begin
 begin
   CheckOpen('TWinCEGAPIConsole.GetWidth');
   CheckOpen('TWinCEGAPIConsole.GetWidth');
   Result := FDisplayWidth;
   Result := FDisplayWidth;
 end;
 end;
 
 
 function TWinCEGAPIConsole.GetHeight: Integer;
 function TWinCEGAPIConsole.GetHeight: Integer;
-
 begin
 begin
   CheckOpen('TWinCEGAPIConsole.GetHeight');
   CheckOpen('TWinCEGAPIConsole.GetHeight');
   Result := FDisplayHeight;
   Result := FDisplayHeight;
 end;
 end;
 
 
 function TWinCEGAPIConsole.GetPitch: Integer;
 function TWinCEGAPIConsole.GetPitch: Integer;
-
 begin
 begin
   CheckOpen('TWinCEGAPIConsole.GetPitch');
   CheckOpen('TWinCEGAPIConsole.GetPitch');
   Result := FDisplayPitch;
   Result := FDisplayPitch;
 end;
 end;
 
 
-function TWinCEGAPIConsole.GetArea: TPTCArea;
-
+function TWinCEGAPIConsole.GetArea: IPTCArea;
 begin
 begin
   CheckOpen('TWinCEGAPIConsole.GetArea');
   CheckOpen('TWinCEGAPIConsole.GetArea');
   Result := FArea;
   Result := FArea;
 end;
 end;
 
 
-function TWinCEGAPIConsole.GetFormat: TPTCFormat;
-
+function TWinCEGAPIConsole.GetFormat: IPTCFormat;
 begin
 begin
   CheckOpen('TWinCEGAPIConsole.GetFormat');
   CheckOpen('TWinCEGAPIConsole.GetFormat');
   Result := FDisplayFormat;
   Result := FDisplayFormat;
 end;
 end;
 
 
 function TWinCEGAPIConsole.GetPages: Integer;
 function TWinCEGAPIConsole.GetPages: Integer;
-
 begin
 begin
   CheckOpen('TWinCEGAPIConsole.GetPages');
   CheckOpen('TWinCEGAPIConsole.GetPages');
   Result := 1; {???}
   Result := 1; {???}
 end;
 end;
 
 
 function TWinCEGAPIConsole.GetName: string;
 function TWinCEGAPIConsole.GetName: string;
-
 begin
 begin
   Result := 'GAPI';
   Result := 'GAPI';
 end;
 end;
 
 
 function TWinCEGAPIConsole.GetTitle: string;
 function TWinCEGAPIConsole.GetTitle: string;
-
 begin
 begin
   CheckOpen('TWinCEGAPIConsole.GetTitle');
   CheckOpen('TWinCEGAPIConsole.GetTitle');
   Result := FTitle;
   Result := FTitle;
 end;
 end;
 
 
 function TWinCEGAPIConsole.GetInformation: string;
 function TWinCEGAPIConsole.GetInformation: string;
-
 begin
 begin
   Result := ''; // todo...
   Result := ''; // todo...
 end;
 end;
 
 
 procedure TWinCEGAPIConsole.CheckOpen(    AMessage: String);
 procedure TWinCEGAPIConsole.CheckOpen(    AMessage: String);
-
 begin
 begin
   if not FOpen then
   if not FOpen then
   try
   try
@@ -596,7 +508,6 @@ begin
 end;
 end;
 
 
 procedure TWinCEGAPIConsole.CheckUnlocked(AMessage: String);
 procedure TWinCEGAPIConsole.CheckUnlocked(AMessage: String);
-
 begin
 begin
   if FLocked then
   if FLocked then
   try
   try

+ 3 - 3
packages/ptc/src/wince/gdi/wincebitmapinfod.inc

@@ -30,11 +30,11 @@
 }
 }
 
 
 type
 type
-  TWinCEBitmapInfo = Class(TObject)
+  TWinCEBitmapInfo = class(TObject)
   private
   private
     FBitmapInfo: PBITMAPINFO;
     FBitmapInfo: PBITMAPINFO;
 //    FPixels: Pointer;
 //    FPixels: Pointer;
-    FFormat: TPTCFormat;
+    FFormat: IPTCFormat;
     FWidth, FHeight, FPitch: Integer;
     FWidth, FHeight, FPitch: Integer;
   public
   public
     constructor Create(AWidth, AHeight: Integer);
     constructor Create(AWidth, AHeight: Integer);
@@ -43,6 +43,6 @@ type
     property Width: Integer read FWidth;
     property Width: Integer read FWidth;
     property Height: Integer read FHeight;
     property Height: Integer read FHeight;
     property Pitch: Integer read FPitch;
     property Pitch: Integer read FPitch;
-    property Format: TPTCFormat read FFormat;
+    property Format: IPTCFormat read FFormat;
 //    property Pixels: Pointer read FPixels;
 //    property Pixels: Pointer read FPixels;
   end;
   end;

+ 0 - 3
packages/ptc/src/wince/gdi/wincebitmapinfoi.inc

@@ -33,7 +33,6 @@
 {TODO: create DIBs with the same color depth as the desktop}
 {TODO: create DIBs with the same color depth as the desktop}
 
 
 constructor TWinCEBitmapInfo.Create(AWidth, AHeight: Integer);
 constructor TWinCEBitmapInfo.Create(AWidth, AHeight: Integer);
-
 begin
 begin
   FBitmapInfo := GetMem(SizeOf(BITMAPINFOHEADER) + 12);
   FBitmapInfo := GetMem(SizeOf(BITMAPINFOHEADER) + 12);
 
 
@@ -67,10 +66,8 @@ begin
 end;
 end;
 
 
 destructor TWinCEBitmapInfo.Destroy;
 destructor TWinCEBitmapInfo.Destroy;
-
 begin
 begin
 //  FreeMem(FPixels);
 //  FreeMem(FPixels);
   FreeMem(FBitmapInfo);
   FreeMem(FBitmapInfo);
-  FFormat.Free;
   inherited Destroy;
   inherited Destroy;
 end;
 end;

+ 38 - 38
packages/ptc/src/wince/gdi/wincegdiconsoled.inc

@@ -30,7 +30,7 @@
 }
 }
 
 
 type
 type
-  TWinCEGDIConsole = Class(TPTCBaseConsole)
+  TWinCEGDIConsole = class(TPTCBaseConsole)
   private
   private
     FWindow: TWinCEWindow;
     FWindow: TWinCEWindow;
     FBitmap: HBitmap;
     FBitmap: HBitmap;
@@ -41,10 +41,10 @@ type
 
 
     FCopy: TPTCCopy;
     FCopy: TPTCCopy;
     FClear: TPTCClear;
     FClear: TPTCClear;
-    FArea: TPTCArea;
-    FClip: TPTCArea;
+    FArea: IPTCArea;
+    FClip: IPTCArea;
     FEventQueue: TEventQueue;
     FEventQueue: TEventQueue;
-    FModes: array [0..1] of TPTCMode;
+    FModes: array of IPTCMode;
 
 
     FOpen: Boolean;
     FOpen: Boolean;
     FLocked: Boolean;
     FLocked: Boolean;
@@ -53,80 +53,80 @@ type
 
 
     FDisplayWidth: Integer;
     FDisplayWidth: Integer;
     FDisplayHeight: Integer;
     FDisplayHeight: Integer;
-    FDefaultFormat: TPTCFormat;
+    FDefaultFormat: IPTCFormat;
 
 
     function WndProc(Ahwnd: HWND; AuMsg: UINT; AwParam: WPARAM; AlParam: LPARAM): LRESULT;
     function WndProc(Ahwnd: HWND; AuMsg: UINT; AwParam: WPARAM; AlParam: LPARAM): LRESULT;
 
 
     function GetWidth: Integer; override;
     function GetWidth: Integer; override;
     function GetHeight: Integer; override;
     function GetHeight: Integer; override;
     function GetPitch: Integer; override;
     function GetPitch: Integer; override;
-    function GetArea: TPTCArea; override;
-    function GetFormat: TPTCFormat; override;
+    function GetArea: IPTCArea; override;
+    function GetFormat: IPTCFormat; override;
     function GetPages: Integer; override;
     function GetPages: Integer; override;
     function GetName: string; override;
     function GetName: string; override;
     function GetTitle: string; override;
     function GetTitle: string; override;
     function GetInformation: string; override;
     function GetInformation: string; override;
 
 
-    procedure CheckOpen(    AMessage: String);
-    procedure CheckUnlocked(AMessage: String);
+    procedure CheckOpen(    AMessage: string);
+    procedure CheckUnlocked(AMessage: string);
   public
   public
     constructor Create; override;
     constructor Create; override;
     destructor Destroy; override;
     destructor Destroy; override;
 
 
     procedure Open(const ATitle: string; APages: Integer = 0); overload; override;
     procedure Open(const ATitle: string; APages: Integer = 0); overload; override;
-    procedure Open(const ATitle: string; const AFormat: TPTCFormat;
+    procedure Open(const ATitle: string; AFormat: IPTCFormat;
                    APages: Integer = 0); overload; override;
                    APages: Integer = 0); overload; override;
     procedure Open(const ATitle: string; AWidth, AHeight: Integer;
     procedure Open(const ATitle: string; AWidth, AHeight: Integer;
-                   const AFormat: TPTCFormat; APages: Integer = 0); overload; override;
-    procedure Open(const ATitle: string; const AMode: TPTCMode;
+                   AFormat: IPTCFormat; APages: Integer = 0); overload; override;
+    procedure Open(const ATitle: string; AMode: IPTCMode;
                    APages: Integer = 0); overload; override;
                    APages: Integer = 0); overload; override;
     procedure Close; override;
     procedure Close; override;
 
 
-    procedure Copy(ASurface: TPTCBaseSurface); override;
-    procedure Copy(ASurface: TPTCBaseSurface;
-                   const ASource, ADestination: TPTCArea); override;
+    procedure Copy(ASurface: IPTCSurface); override;
+    procedure Copy(ASurface: IPTCSurface;
+                   ASource, ADestination: IPTCArea); override;
 
 
     procedure Load(const APixels: Pointer;
     procedure Load(const APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette); override;
     procedure Load(const APixels: Pointer;
     procedure Load(const APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea); override;
     procedure Save(APixels: Pointer;
     procedure Save(APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette); override;
     procedure Save(APixels: Pointer;
     procedure Save(APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea); override;
 
 
     function Lock: Pointer; override;
     function Lock: Pointer; override;
     procedure Unlock; override;
     procedure Unlock; override;
 
 
     procedure Clear; override;
     procedure Clear; override;
-    procedure Clear(const AColor: TPTCColor); override;
-    procedure Clear(const AColor: TPTCColor;
-                    const AArea: TPTCArea); override;
+    procedure Clear(AColor: IPTCColor); override;
+    procedure Clear(AColor: IPTCColor;
+                    AArea: IPTCArea); override;
 
 
-    procedure Configure(const AFileName: String); override;
-    function Option(const AOption: String): Boolean; override;
+    procedure Configure(const AFileName: string); override;
+    function Option(const AOption: string): Boolean; override;
 
 
-    procedure Palette(const APalette: TPTCPalette); override;
-    procedure Clip(const AArea: TPTCArea); override;
-    function Clip: TPTCArea; override;
-    function Palette: TPTCPalette; override;
-    function Modes: PPTCMode; override;
+    procedure Palette(APalette: IPTCPalette); override;
+    procedure Clip(AArea: IPTCArea); override;
+    function Clip: IPTCArea; override;
+    function Palette: IPTCPalette; override;
+    function Modes: TPTCModeList; override;
 
 
     procedure Flush; override;
     procedure Flush; override;
     procedure Finish; override;
     procedure Finish; override;
     procedure Update; override;
     procedure Update; override;
-    procedure Update(const AArea: TPTCArea); override;
+    procedure Update(AArea: IPTCArea); override;
 
 
-    function NextEvent(var AEvent: TPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; override;
-    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): TPTCEvent; override;
+    function NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; override;
+    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent; override;
   end;
   end;

+ 46 - 136
packages/ptc/src/wince/gdi/wincegdiconsolei.inc

@@ -30,7 +30,6 @@
 }
 }
 
 
 constructor TWinCEGDIConsole.Create;
 constructor TWinCEGDIConsole.Create;
-
 begin
 begin
   inherited Create;
   inherited Create;
 
 
@@ -43,15 +42,11 @@ begin
   FArea := TPTCArea.Create;
   FArea := TPTCArea.Create;
   FClip := TPTCArea.Create;
   FClip := TPTCArea.Create;
 
 
+  SetLength(FModes, 1);
   FModes[0] := TPTCMode.Create(FDisplayWidth, FDisplayHeight, FDefaultFormat);
   FModes[0] := TPTCMode.Create(FDisplayWidth, FDisplayHeight, FDefaultFormat);
-  FModes[1] := TPTCMode.Create;
 end;
 end;
 
 
 destructor TWinCEGDIConsole.Destroy;
 destructor TWinCEGDIConsole.Destroy;
-
-var
-  I: Integer;
-
 begin
 begin
   Close;
   Close;
 
 
@@ -60,43 +55,31 @@ begin
   FEventQueue.Free;
   FEventQueue.Free;
   FCopy.Free;
   FCopy.Free;
   FClear.Free;
   FClear.Free;
-  FArea.Free;
-  FClip.Free;
-  FDefaultFormat.Free;
-
-  for I := Low(FModes) to High(FModes) do
-    FModes[I].Free;
 
 
   inherited Destroy;
   inherited Destroy;
 end;
 end;
 
 
 procedure TWinCEGDIConsole.Open(const ATitle: string; APages: Integer = 0);
 procedure TWinCEGDIConsole.Open(const ATitle: string; APages: Integer = 0);
-
 begin
 begin
   Open(ATitle, FDefaultFormat, APages);
   Open(ATitle, FDefaultFormat, APages);
 end;
 end;
 
 
-procedure TWinCEGDIConsole.Open(const ATitle: string; const AFormat: TPTCFormat;
+procedure TWinCEGDIConsole.Open(const ATitle: string; AFormat: IPTCFormat;
                                 APages: Integer = 0);
                                 APages: Integer = 0);
-
 begin
 begin
   Open(ATitle, FDisplayWidth, FDisplayHeight, AFormat, APages);
   Open(ATitle, FDisplayWidth, FDisplayHeight, AFormat, APages);
 end;
 end;
 
 
-procedure TWinCEGDIConsole.Open(const ATitle: string; const AMode: TPTCMode;
+procedure TWinCEGDIConsole.Open(const ATitle: string; AMode: IPTCMode;
                                 APages: Integer = 0);
                                 APages: Integer = 0);
-
 begin
 begin
   Open(ATitle, AMode.Width, AMode.Height, AMode.Format, APages);
   Open(ATitle, AMode.Width, AMode.Height, AMode.Format, APages);
 end;
 end;
 
 
 procedure TWinCEGDIConsole.Open(const ATitle: string; AWidth, AHeight: Integer;
 procedure TWinCEGDIConsole.Open(const ATitle: string; AWidth, AHeight: Integer;
-                                const AFormat: TPTCFormat; APages: Integer = 0);
-
+                                AFormat: IPTCFormat; APages: Integer = 0);
 var
 var
   DeviceContext: HDC;
   DeviceContext: HDC;
-  tmp: TPTCArea;
-
 begin
 begin
   LOG('TWinCEGDIConsole.Open');
   LOG('TWinCEGDIConsole.Open');
 
 
@@ -137,13 +120,8 @@ begin
   if FBitmap = 0 then
   if FBitmap = 0 then
     raise TPTCError.Create('could not create dib section');
     raise TPTCError.Create('could not create dib section');
 
 
-  tmp := TPTCArea.Create(0, 0, FDisplayWidth, FDisplayHeight);
-  try
-    FArea.Assign(tmp);
-    FClip.Assign(tmp);
-  finally
-    tmp.Free;
-  end;
+  FArea := TPTCArea.Create(0, 0, FDisplayWidth, FDisplayHeight);
+  FClip := FArea;
 
 
   FEventQueue := TEventQueue.Create;
   FEventQueue := TEventQueue.Create;
   FKeyboard := TWinCEKeyboard.Create(FEventQueue);
   FKeyboard := TWinCEKeyboard.Create(FEventQueue);
@@ -157,7 +135,6 @@ begin
 end;
 end;
 
 
 procedure TWinCEGDIConsole.Close;
 procedure TWinCEGDIConsole.Close;
-
 begin
 begin
   LOG('TWinCEGDIConsole.Close');
   LOG('TWinCEGDIConsole.Close');
 
 
@@ -179,27 +156,23 @@ begin
   FOpen := False;
   FOpen := False;
 end;
 end;
 
 
-procedure TWinCEGDIConsole.Copy(ASurface: TPTCBaseSurface);
-
+procedure TWinCEGDIConsole.Copy(ASurface: IPTCSurface);
 begin
 begin
   {todo...}
   {todo...}
 end;
 end;
 
 
-procedure TWinCEGDIConsole.Copy(ASurface: TPTCBaseSurface;
-                                const ASource, ADestination: TPTCArea);
-
+procedure TWinCEGDIConsole.Copy(ASurface: IPTCSurface;
+                                ASource, ADestination: IPTCArea);
 begin
 begin
   {todo...}
   {todo...}
 end;
 end;
 
 
 procedure TWinCEGDIConsole.Load(const APixels: Pointer;
 procedure TWinCEGDIConsole.Load(const APixels: Pointer;
                                 AWidth, AHeight, APitch: Integer;
                                 AWidth, AHeight, APitch: Integer;
-                                const AFormat: TPTCFormat;
-                                const APalette: TPTCPalette);
+                                AFormat: IPTCFormat;
+                                APalette: IPTCPalette);
 var
 var
-  Area_: TPTCArea;
   console_pixels: Pointer;
   console_pixels: Pointer;
-
 begin
 begin
   CheckOpen(    'TWinCEGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette)');
   CheckOpen(    'TWinCEGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette)');
   CheckUnlocked('TWinCEGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette)');
   CheckUnlocked('TWinCEGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette)');
@@ -221,50 +194,30 @@ begin
     end;
     end;
   end
   end
   else
   else
-  begin
-    Area_ := TPTCArea.Create(0, 0, width, height);
-    try
-      Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, Area_, Area);
-    finally
-      Area_.Free;
-    end;
-  end;
+    Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, TPTCArea.Create(0, 0, width, height), Area);
 end;
 end;
 
 
 procedure TWinCEGDIConsole.Load(const APixels: Pointer;
 procedure TWinCEGDIConsole.Load(const APixels: Pointer;
                                 AWidth, AHeight, APitch: Integer;
                                 AWidth, AHeight, APitch: Integer;
-                                const AFormat: TPTCFormat;
-                                const APalette: TPTCPalette;
-                                const ASource, ADestination: TPTCArea);
+                                AFormat: IPTCFormat;
+                                APalette: IPTCPalette;
+                                ASource, ADestination: IPTCArea);
 var
 var
   console_pixels: Pointer;
   console_pixels: Pointer;
-  clipped_source, clipped_destination: TPTCArea;
-  tmp: TPTCArea;
-
+  clipped_source, clipped_destination: IPTCArea;
 begin
 begin
   CheckOpen(    'TWinCEGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
   CheckOpen(    'TWinCEGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
   CheckUnlocked('TWinCEGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
   CheckUnlocked('TWinCEGDIConsole.Load(APixels, AWidth, AHeight, APitch, AFormat, APalette, ASource, ADestination)');
-  clipped_source := nil;
-  clipped_destination := nil;
   try
   try
     console_pixels := Lock;
     console_pixels := Lock;
     try
     try
-      clipped_source := TPTCArea.Create;
-      clipped_destination := TPTCArea.Create;
-      tmp := TPTCArea.Create(0, 0, AWidth, AHeight);
-      try
-        TPTCClipper.Clip(ASource, tmp, clipped_source, ADestination, Clip, clipped_destination);
-      finally
-        tmp.Free;
-      end;
+      TPTCClipper.Clip(ASource, TPTCArea.Create(0, 0, AWidth, AHeight), clipped_source, ADestination, Clip, clipped_destination);
       FCopy.request(AFormat, Format);
       FCopy.request(AFormat, Format);
       FCopy.palette(APalette, Palette);
       FCopy.palette(APalette, Palette);
       FCopy.copy(APixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, APitch,
       FCopy.copy(APixels, clipped_source.left, clipped_source.top, clipped_source.width, clipped_source.height, APitch,
                  console_pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, Pitch);
                  console_pixels, clipped_destination.left, clipped_destination.top, clipped_destination.width, clipped_destination.height, Pitch);
     finally
     finally
       Unlock;
       Unlock;
-      clipped_source.Free;
-      clipped_destination.Free;
     end;
     end;
   except
   except
     on error: TPTCError do
     on error: TPTCError do
@@ -274,61 +227,52 @@ end;
 
 
 procedure TWinCEGDIConsole.Save(APixels: Pointer;
 procedure TWinCEGDIConsole.Save(APixels: Pointer;
                                 AWidth, AHeight, APitch: Integer;
                                 AWidth, AHeight, APitch: Integer;
-                                const AFormat: TPTCFormat;
-                                const APalette: TPTCPalette);
-
+                                AFormat: IPTCFormat;
+                                APalette: IPTCPalette);
 begin
 begin
   {todo...}
   {todo...}
 end;
 end;
 
 
 procedure TWinCEGDIConsole.Save(APixels: Pointer;
 procedure TWinCEGDIConsole.Save(APixels: Pointer;
                                 AWidth, AHeight, APitch: Integer;
                                 AWidth, AHeight, APitch: Integer;
-                                const AFormat: TPTCFormat;
-                                const APalette: TPTCPalette;
-                                const ASource, ADestination: TPTCArea);
-
+                                AFormat: IPTCFormat;
+                                APalette: IPTCPalette;
+                                ASource, ADestination: IPTCArea);
 begin
 begin
   {todo...}
   {todo...}
 end;
 end;
 
 
 function TWinCEGDIConsole.Lock: Pointer;
 function TWinCEGDIConsole.Lock: Pointer;
-
 begin
 begin
   Result := FBitmapPixels; // todo...
   Result := FBitmapPixels; // todo...
   FLocked := True;
   FLocked := True;
 end;
 end;
 
 
 procedure TWinCEGDIConsole.Unlock;
 procedure TWinCEGDIConsole.Unlock;
-
 begin
 begin
   FLocked := False;
   FLocked := False;
 end;
 end;
 
 
 procedure TWinCEGDIConsole.Clear;
 procedure TWinCEGDIConsole.Clear;
-
 begin
 begin
   {todo...}
   {todo...}
 end;
 end;
 
 
-procedure TWinCEGDIConsole.Clear(const AColor: TPTCColor);
-
+procedure TWinCEGDIConsole.Clear(AColor: IPTCColor);
 begin
 begin
   {todo...}
   {todo...}
 end;
 end;
 
 
-procedure TWinCEGDIConsole.Clear(const AColor: TPTCColor;
-                                 const AArea: TPTCArea);
-
+procedure TWinCEGDIConsole.Clear(AColor: IPTCColor;
+                                 AArea: IPTCArea);
 begin
 begin
   {todo...}
   {todo...}
 end;
 end;
 
 
-procedure TWinCEGDIConsole.Configure(const AFileName: String);
-
+procedure TWinCEGDIConsole.Configure(const AFileName: string);
 var
 var
   F: Text;
   F: Text;
   S: string;
   S: string;
-
 begin
 begin
   AssignFile(F, AFileName);
   AssignFile(F, AFileName);
   {$push}{$I-}
   {$push}{$I-}
@@ -348,8 +292,7 @@ begin
   CloseFile(F);
   CloseFile(F);
 end;
 end;
 
 
-function TWinCEGDIConsole.Option(const AOption: String): Boolean;
-
+function TWinCEGDIConsole.Option(const AOption: string): Boolean;
 begin
 begin
   LOG('console option', AOption);
   LOG('console option', AOption);
 
 
@@ -358,61 +301,45 @@ begin
   Result := FCopy.Option(AOption);
   Result := FCopy.Option(AOption);
 end;
 end;
 
 
-procedure TWinCEGDIConsole.Palette(const APalette: TPTCPalette);
-
+procedure TWinCEGDIConsole.Palette(APalette: IPTCPalette);
 begin
 begin
   {todo...}
   {todo...}
 end;
 end;
 
 
-procedure TWinCEGDIConsole.Clip(const AArea: TPTCArea);
-
-var
-  tmp: TPTCArea;
-
+procedure TWinCEGDIConsole.Clip(AArea: IPTCArea);
 begin
 begin
   CheckOpen('TWinCEGDIConsole.Clip(AArea)');
   CheckOpen('TWinCEGDIConsole.Clip(AArea)');
 
 
-  tmp := TPTCClipper.Clip(AArea, FArea);
-  try
-    FClip.Assign(tmp);
-  finally
-    tmp.Free;
-  end;
+  FClip := TPTCClipper.Clip(AArea, FArea);
 end;
 end;
 
 
-function TWinCEGDIConsole.Clip: TPTCArea;
-
+function TWinCEGDIConsole.Clip: IPTCArea;
 begin
 begin
   CheckOpen('TWinCEGDIConsole.Clip');
   CheckOpen('TWinCEGDIConsole.Clip');
   Result := FClip;
   Result := FClip;
 end;
 end;
 
 
-function TWinCEGDIConsole.Palette: TPTCPalette;
-
+function TWinCEGDIConsole.Palette: IPTCPalette;
 begin
 begin
   {todo...}
   {todo...}
 end;
 end;
 
 
-function TWinCEGDIConsole.Modes: PPTCMode;
-
+function TWinCEGDIConsole.Modes: TPTCModeList;
 begin
 begin
-  Result := @FModes[0];
+  Result := FModes;
 end;
 end;
 
 
 procedure TWinCEGDIConsole.Flush;
 procedure TWinCEGDIConsole.Flush;
-
 begin
 begin
   {todo...}
   {todo...}
 end;
 end;
 
 
 procedure TWinCEGDIConsole.Finish;
 procedure TWinCEGDIConsole.Finish;
-
 begin
 begin
   {todo...}
   {todo...}
 end;
 end;
 
 
 function TWinCEGDIConsole.WndProc(Ahwnd: HWND; AuMsg: UINT; AwParam: WPARAM; AlParam: LPARAM): LRESULT;
 function TWinCEGDIConsole.WndProc(Ahwnd: HWND; AuMsg: UINT; AwParam: WPARAM; AlParam: LPARAM): LRESULT;
-
 begin
 begin
   case AuMsg of
   case AuMsg of
   WM_CLOSE: begin
   WM_CLOSE: begin
@@ -442,11 +369,9 @@ begin
 end;
 end;
 
 
 procedure TWinCEGDIConsole.Update;
 procedure TWinCEGDIConsole.Update;
-
 var
 var
   ClientRect: RECT;
   ClientRect: RECT;
   DeviceContext, DeviceContext2: HDC;
   DeviceContext, DeviceContext2: HDC;
-
 begin
 begin
   CheckOpen(    'TWinCEGDIConsole.Update');
   CheckOpen(    'TWinCEGDIConsole.Update');
   CheckUnlocked('TWinCEGDIConsole.Update');
   CheckUnlocked('TWinCEGDIConsole.Update');
@@ -464,11 +389,11 @@ begin
       begin
       begin
         SelectObject(DeviceContext2, FBitmap);
         SelectObject(DeviceContext2, FBitmap);
 
 
-	StretchBlt(DeviceContext,
-	           0, 0, ClientRect.right, ClientRect.bottom,
-		   DeviceContext2,
-		   0, 0, FBitmapInfo.Width, FBitmapInfo.Height,
-		   SRCCOPY);
+        StretchBlt(DeviceContext,
+                   0, 0, ClientRect.right, ClientRect.bottom,
+                   DeviceContext2,
+                   0, 0, FBitmapInfo.Width, FBitmapInfo.Height,
+                   SRCCOPY);
 
 
         DeleteDC(DeviceContext2);
         DeleteDC(DeviceContext2);
       end;
       end;
@@ -478,20 +403,17 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure TWinCEGDIConsole.Update(const AArea: TPTCArea);
-
+procedure TWinCEGDIConsole.Update(AArea: IPTCArea);
 begin
 begin
   {todo...}
   {todo...}
   Update;
   Update;
 end;
 end;
 
 
-function TWinCEGDIConsole.NextEvent(var AEvent: TPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
-
+function TWinCEGDIConsole.NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean;
 begin
 begin
   CheckOpen('TWinCEGDIConsole.NextEvent');
   CheckOpen('TWinCEGDIConsole.NextEvent');
 //  CheckUnlocked('TWinCEGDIConsole.NextEvent');
 //  CheckUnlocked('TWinCEGDIConsole.NextEvent');
 
 
-  FreeAndNil(AEvent);
   repeat
   repeat
     { update window }
     { update window }
     FWindow.Update;
     FWindow.Update;
@@ -502,8 +424,7 @@ begin
   Result := AEvent <> nil;
   Result := AEvent <> nil;
 end;
 end;
 
 
-function TWinCEGDIConsole.PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): TPTCEvent;
-
+function TWinCEGDIConsole.PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent;
 begin
 begin
   CheckOpen('TWinCEGDIConsole.PeekEvent');
   CheckOpen('TWinCEGDIConsole.PeekEvent');
 //  CheckUnlocked('TWinCEGDIConsole.PeekEvent');
 //  CheckUnlocked('TWinCEGDIConsole.PeekEvent');
@@ -518,69 +439,59 @@ begin
 end;
 end;
 
 
 function TWinCEGDIConsole.GetWidth: Integer;
 function TWinCEGDIConsole.GetWidth: Integer;
-
 begin
 begin
   CheckOpen('TWinCEGDIConsole.GetWidth');
   CheckOpen('TWinCEGDIConsole.GetWidth');
   Result := FBitmapInfo.Width;
   Result := FBitmapInfo.Width;
 end;
 end;
 
 
 function TWinCEGDIConsole.GetHeight: Integer;
 function TWinCEGDIConsole.GetHeight: Integer;
-
 begin
 begin
   CheckOpen('TWinCEGDIConsole.GetHeight');
   CheckOpen('TWinCEGDIConsole.GetHeight');
   Result := FBitmapInfo.Height;
   Result := FBitmapInfo.Height;
 end;
 end;
 
 
 function TWinCEGDIConsole.GetPitch: Integer;
 function TWinCEGDIConsole.GetPitch: Integer;
-
 begin
 begin
   CheckOpen('TWinCEGDIConsole.GetPitch');
   CheckOpen('TWinCEGDIConsole.GetPitch');
   Result := FBitmapInfo.Pitch;
   Result := FBitmapInfo.Pitch;
 end;
 end;
 
 
-function TWinCEGDIConsole.GetFormat: TPTCFormat;
-
+function TWinCEGDIConsole.GetFormat: IPTCFormat;
 begin
 begin
   CheckOpen('TWinCEGDIConsole.GetFormat');
   CheckOpen('TWinCEGDIConsole.GetFormat');
   Result := FBitmapInfo.Format;
   Result := FBitmapInfo.Format;
 end;
 end;
 
 
-function TWinCEGDIConsole.GetArea: TPTCArea;
-
+function TWinCEGDIConsole.GetArea: IPTCArea;
 begin
 begin
   CheckOpen('TWinCEGDIConsole.GetArea');
   CheckOpen('TWinCEGDIConsole.GetArea');
   Result := FArea;
   Result := FArea;
 end;
 end;
 
 
 function TWinCEGDIConsole.GetPages: Integer;
 function TWinCEGDIConsole.GetPages: Integer;
-
 begin
 begin
   CheckOpen('TWinCEGDIConsole.GetPages');
   CheckOpen('TWinCEGDIConsole.GetPages');
   Result := 2;
   Result := 2;
 end;
 end;
 
 
 function TWinCEGDIConsole.GetName: string;
 function TWinCEGDIConsole.GetName: string;
-
 begin
 begin
   Result := 'WinCE';
   Result := 'WinCE';
 end;
 end;
 
 
 function TWinCEGDIConsole.GetTitle: string;
 function TWinCEGDIConsole.GetTitle: string;
-
 begin
 begin
   CheckOpen('TWinCEGDIConsole.GetTitle');
   CheckOpen('TWinCEGDIConsole.GetTitle');
   Result := FTitle;
   Result := FTitle;
 end;
 end;
 
 
 function TWinCEGDIConsole.GetInformation: string;
 function TWinCEGDIConsole.GetInformation: string;
-
 begin
 begin
   CheckOpen('TWinCEGDIConsole.GetInformation');
   CheckOpen('TWinCEGDIConsole.GetInformation');
   Result := ''; // todo...
   Result := ''; // todo...
 end;
 end;
 
 
-procedure TWinCEGDIConsole.CheckOpen(AMessage: String);
-
+procedure TWinCEGDIConsole.CheckOpen(AMessage: string);
 begin
 begin
   if not FOpen then
   if not FOpen then
   try
   try
@@ -591,8 +502,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure TWinCEGDIConsole.CheckUnlocked(AMessage: String);
-
+procedure TWinCEGDIConsole.CheckUnlocked(AMessage: string);
 begin
 begin
   if FLocked then
   if FLocked then
   try
   try

+ 30 - 30
packages/ptc/src/x11/x11consoled.inc

@@ -36,7 +36,7 @@ type
     FX11Display: TX11Display;
     FX11Display: TX11Display;
     FTitle: string;
     FTitle: string;
     FFlags: TX11Flags;
     FFlags: TX11Flags;
-    FModes: array of TPTCMode;
+    FModes: array of IPTCMode;
 
 
     procedure UpdateCursor;
     procedure UpdateCursor;
     procedure UpdateMouseGrab;
     procedure UpdateMouseGrab;
@@ -46,8 +46,8 @@ type
     function GetWidth: Integer; override;
     function GetWidth: Integer; override;
     function GetHeight: Integer; override;
     function GetHeight: Integer; override;
     function GetPitch: Integer; override;
     function GetPitch: Integer; override;
-    function GetArea: TPTCArea; override;
-    function GetFormat: TPTCFormat; override;
+    function GetArea: IPTCArea; override;
+    function GetFormat: IPTCFormat; override;
     function GetPages: Integer; override;
     function GetPages: Integer; override;
     function GetName: string; override;
     function GetName: string; override;
     function GetTitle: string; override;
     function GetTitle: string; override;
@@ -57,59 +57,59 @@ type
     destructor Destroy; override;
     destructor Destroy; override;
 
 
     procedure Open(const ATitle: string; APages: Integer = 0); overload; override;
     procedure Open(const ATitle: string; APages: Integer = 0); overload; override;
-    procedure Open(const ATitle: string; const AFormat: TPTCFormat;
+    procedure Open(const ATitle: string; AFormat: IPTCFormat;
                    APages: Integer = 0); overload; override;
                    APages: Integer = 0); overload; override;
     procedure Open(const ATitle: string; AWidth, AHeight: Integer;
     procedure Open(const ATitle: string; AWidth, AHeight: Integer;
-                   const AFormat: TPTCFormat; APages: Integer = 0); overload; override;
-    procedure Open(const ATitle: string; const AMode: TPTCMode;
+                   AFormat: IPTCFormat; APages: Integer = 0); overload; override;
+    procedure Open(const ATitle: string; AMode: IPTCMode;
                    APages: Integer = 0); overload; override;
                    APages: Integer = 0); overload; override;
     procedure Close; override;
     procedure Close; override;
 
 
-    procedure Copy(ASurface: TPTCBaseSurface); override;
-    procedure Copy(ASurface: TPTCBaseSurface;
-                   const ASource, ADestination: TPTCArea); override;
+    procedure Copy(ASurface: IPTCSurface); override;
+    procedure Copy(ASurface: IPTCSurface;
+                   ASource, ADestination: IPTCArea); override;
 
 
     procedure Load(const APixels: Pointer;
     procedure Load(const APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette); override;
     procedure Load(const APixels: Pointer;
     procedure Load(const APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea); override;
     procedure Save(APixels: Pointer;
     procedure Save(APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette); override;
     procedure Save(APixels: Pointer;
     procedure Save(APixels: Pointer;
                    AWidth, AHeight, APitch: Integer;
                    AWidth, AHeight, APitch: Integer;
-                   const AFormat: TPTCFormat;
-                   const APalette: TPTCPalette;
-                   const ASource, ADestination: TPTCArea); override;
+                   AFormat: IPTCFormat;
+                   APalette: IPTCPalette;
+                   ASource, ADestination: IPTCArea); override;
 
 
     function Lock: Pointer; override;
     function Lock: Pointer; override;
     procedure Unlock; override;
     procedure Unlock; override;
 
 
     procedure Clear; override;
     procedure Clear; override;
-    procedure Clear(const AColor: TPTCColor); override;
-    procedure Clear(const AColor: TPTCColor;
-                    const AArea: TPTCArea); override;
+    procedure Clear(AColor: IPTCColor); override;
+    procedure Clear(AColor: IPTCColor;
+                    AArea: IPTCArea); override;
 
 
     procedure Configure(const AFileName: String); override;
     procedure Configure(const AFileName: String); override;
     function Option(const AOption: String): Boolean; override;
     function Option(const AOption: String): Boolean; override;
 
 
-    procedure Palette(const APalette: TPTCPalette); override;
-    procedure Clip(const AArea: TPTCArea); override;
-    function Clip: TPTCArea; override;
-    function Palette: TPTCPalette; override;
-    function Modes: PPTCMode; override;
+    procedure Palette(APalette: IPTCPalette); override;
+    procedure Clip(AArea: IPTCArea); override;
+    function Clip: IPTCArea; override;
+    function Palette: IPTCPalette; override;
+    function Modes: TPTCModeList; override;
 
 
     procedure Flush; override;
     procedure Flush; override;
     procedure Finish; override;
     procedure Finish; override;
     procedure Update; override;
     procedure Update; override;
-    procedure Update(const AArea: TPTCArea); override;
+    procedure Update(AArea: IPTCArea); override;
 
 
-    function NextEvent(var AEvent: TPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; override;
-    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): TPTCEvent; override;
+    function NextEvent(out AEvent: IPTCEvent; AWait: Boolean; const AEventMask: TPTCEventMask): Boolean; override;
+    function PeekEvent(AWait: Boolean; const AEventMask: TPTCEventMask): IPTCEvent; override;
   end;
   end;

Some files were not shown because too many files changed in this diff